1 SPDX-License-Identifier: GPL-2.0
2 aufs5.10.82 kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index da524c4d7b7e0..50ab89368c2b5 100644
8 @@ -288,6 +288,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 999d1a23f036c..0cd76857ca764 100644
20 @@ -136,3 +136,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs5.10.82 base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 4fef10dd29753..e013880d69f33 100644
32 @@ -3009,6 +3009,19 @@ F: include/linux/audit.h
33 F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
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 Sandonis <miguel.ojeda.sandonis@gmail.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index ee537a9f1d1a4..d09b1ef4a2b56 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -752,6 +752,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 ea0485861d937..ddca6240e0db4 100644
85 @@ -1285,7 +1285,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 71b43538fa44c..7cd57fb4e8646 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/namespace.c b/fs/namespace.c
117 index 046b084136c51..a256f0f9c6c09 100644
120 @@ -792,6 +792,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 866d5c2367b23..55b5356262085 100644
137 @@ -756,8 +756,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 @@ -767,9 +767,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)
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 42d246a942283..2cc1a02e444c4 100644
176 --- a/include/linux/fs.h
177 +++ b/include/linux/fs.h
178 @@ -1332,6 +1332,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 @@ -1843,6 +1844,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 @@ -2330,6 +2332,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 @@ -2566,6 +2569,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 20b6797babe2c..7888c04c3ffaf 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 @@ -384,6 +386,7 @@ static inline void lockdep_unregister_key(struct lock_class_key *key)
225 #define lockdep_depth(tsk) (0)
227 +#define lockdep_is_held(lock) (1)
228 #define lockdep_is_held_type(l, r) (1)
230 #define lockdep_assert_held(l) do { (void)(l); } while (0)
231 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
232 index 8f882f5881e87..6b9808f098435 100644
233 --- a/include/linux/mnt_namespace.h
234 +++ b/include/linux/mnt_namespace.h
235 @@ -7,12 +7,15 @@ struct mnt_namespace;
237 struct user_namespace;
241 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
242 struct user_namespace *, struct fs_struct *);
243 extern void put_mnt_ns(struct mnt_namespace *ns);
244 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
246 +extern int is_current_mnt_ns(struct vfsmount *mnt);
248 extern const struct file_operations proc_mounts_operations;
249 extern const struct file_operations proc_mountinfo_operations;
250 extern const struct file_operations proc_mountstats_operations;
251 diff --git a/include/linux/splice.h b/include/linux/splice.h
252 index a55179fd60fc3..8e21c53cf8831 100644
253 --- a/include/linux/splice.h
254 +++ b/include/linux/splice.h
255 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
257 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
258 extern const struct pipe_buf_operations default_pipe_buf_ops;
260 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
261 + loff_t *ppos, size_t len, unsigned int flags);
262 +extern long do_splice_to(struct file *in, loff_t *ppos,
263 + struct pipe_inode_info *pipe, size_t len,
264 + unsigned int flags);
266 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
267 index 1f6a2f1226fa9..4550f7a021178 100644
268 --- a/kernel/locking/lockdep.c
269 +++ b/kernel/locking/lockdep.c
270 @@ -188,7 +188,7 @@ static
271 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
272 static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
274 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
275 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
277 unsigned int class_idx = hlock->class_idx;
279 @@ -209,6 +209,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
281 return lock_classes + class_idx;
283 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
285 #ifdef CONFIG_LOCK_STAT
286 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
287 SPDX-License-Identifier: GPL-2.0
288 aufs5.10.82 mmap patch
290 diff --git a/fs/proc/base.c b/fs/proc/base.c
291 index 5d52aea8d7e7d..2fbf0ad30eaa9 100644
294 @@ -2184,7 +2184,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
296 vma = find_exact_vma(mm, vm_start, vm_end);
297 if (vma && vma->vm_file) {
298 - *path = vma->vm_file->f_path;
299 + *path = vma_pr_or_file(vma)->f_path;
303 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
304 index 13452b32e2bd5..38acccfef9d49 100644
305 --- a/fs/proc/nommu.c
306 +++ b/fs/proc/nommu.c
307 @@ -40,7 +40,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
308 file = region->vm_file;
311 - struct inode *inode = file_inode(region->vm_file);
312 + struct inode *inode;
314 + file = vmr_pr_or_file(region);
315 + inode = file_inode(file);
316 dev = inode->i_sb->s_dev;
319 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
320 index 3931f60e421f7..e5bf27de3f0bc 100644
321 --- a/fs/proc/task_mmu.c
322 +++ b/fs/proc/task_mmu.c
323 @@ -280,7 +280,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
324 const char *name = NULL;
327 - struct inode *inode = file_inode(vma->vm_file);
328 + struct inode *inode;
330 + file = vma_pr_or_file(vma);
331 + inode = file_inode(file);
332 dev = inode->i_sb->s_dev;
334 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
335 @@ -1863,7 +1866,7 @@ static int show_numa_map(struct seq_file *m, void *v)
336 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
337 struct vm_area_struct *vma = v;
338 struct numa_maps *md = &numa_priv->md;
339 - struct file *file = vma->vm_file;
340 + struct file *file = vma_pr_or_file(vma);
341 struct mm_struct *mm = vma->vm_mm;
342 struct mempolicy *pol;
344 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
345 index a6d21fc0033c6..02c2de31196e0 100644
346 --- a/fs/proc/task_nommu.c
347 +++ b/fs/proc/task_nommu.c
348 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
352 - struct inode *inode = file_inode(vma->vm_file);
353 + struct inode *inode;
355 + file = vma_pr_or_file(vma);
356 + inode = file_inode(file);
357 dev = inode->i_sb->s_dev;
359 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
360 diff --git a/include/linux/mm.h b/include/linux/mm.h
361 index 289c26f055cdd..63f3dca76b2eb 100644
362 --- a/include/linux/mm.h
363 +++ b/include/linux/mm.h
364 @@ -1730,6 +1730,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
365 unmap_mapping_range(mapping, holebegin, holelen, 0);
368 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
369 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
371 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
372 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
374 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
376 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
378 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
379 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
382 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
383 +extern void vmr_do_fput(struct vm_region *, const char[], int);
385 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
387 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
388 +#endif /* !CONFIG_MMU */
390 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
391 void *buf, int len, unsigned int gup_flags);
392 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
393 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
394 index 4eb38918da8f8..facc9741d5701 100644
395 --- a/include/linux/mm_types.h
396 +++ b/include/linux/mm_types.h
397 @@ -282,6 +282,7 @@ struct vm_region {
398 unsigned long vm_top; /* region allocated to here */
399 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
400 struct file *vm_file; /* the backing file or NULL */
401 + struct file *vm_prfile; /* the virtual backing file or NULL */
403 int vm_usage; /* region usage count (access under nommu_region_sem) */
404 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
405 @@ -361,6 +362,7 @@ struct vm_area_struct {
406 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
408 struct file * vm_file; /* File we map to (can be NULL). */
409 + struct file *vm_prfile; /* shadow of vm_file */
410 void * vm_private_data; /* was vm_pte (shared mem) */
413 diff --git a/kernel/fork.c b/kernel/fork.c
414 index e465903abed9e..d1f00eaf675af 100644
417 @@ -554,7 +554,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
418 struct inode *inode = file_inode(file);
419 struct address_space *mapping = file->f_mapping;
423 if (tmp->vm_flags & VM_DENYWRITE)
424 put_write_access(inode);
425 i_mmap_lock_write(mapping);
426 diff --git a/mm/Makefile b/mm/Makefile
427 index d73aed0fc99c1..93076a66ad6a5 100644
430 @@ -52,7 +52,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
431 mm_init.o percpu.o slab_common.o \
432 compaction.o vmacache.o \
433 interval_tree.o list_lru.o workingset.o \
434 - debug.o gup.o $(mmu-y)
435 + prfile.o debug.o gup.o $(mmu-y)
437 # Give 'page_alloc' its own module-parameter namespace
438 page-alloc-y := page_alloc.o
439 diff --git a/mm/filemap.c b/mm/filemap.c
440 index 125b69f59caad..00bfb23c599fd 100644
443 @@ -2913,7 +2913,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
444 vm_fault_t ret = VM_FAULT_LOCKED;
446 sb_start_pagefault(inode->i_sb);
447 - file_update_time(vmf->vma->vm_file);
448 + vma_file_update_time(vmf->vma);
450 if (page->mapping != inode->i_mapping) {
452 diff --git a/mm/mmap.c b/mm/mmap.c
453 index 5c8b4485860de..59f2f758d77e5 100644
456 @@ -179,7 +179,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
457 if (vma->vm_ops && vma->vm_ops->close)
458 vma->vm_ops->close(vma);
460 - fput(vma->vm_file);
462 mpol_put(vma_policy(vma));
465 @@ -951,7 +951,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
468 uprobe_munmap(next, next->vm_start, next->vm_end);
473 anon_vma_merge(vma, next);
474 @@ -1897,8 +1897,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
482 /* Undo any partial mapping done by a device driver. */
483 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
484 @@ -2757,7 +2757,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
488 - get_file(new->vm_file);
491 if (new->vm_ops && new->vm_ops->open)
492 new->vm_ops->open(new);
493 @@ -2776,7 +2776,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
494 if (new->vm_ops && new->vm_ops->close)
495 new->vm_ops->close(new);
497 - fput(new->vm_file);
499 unlink_anon_vmas(new);
501 mpol_put(vma_policy(new));
502 @@ -2969,7 +2969,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
503 struct vm_area_struct *vma;
504 unsigned long populate = 0;
505 unsigned long ret = -EINVAL;
507 + struct file *file, *prfile;
509 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n",
510 current->comm, current->pid);
511 @@ -3044,10 +3044,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
515 - file = get_file(vma->vm_file);
517 + file = vma->vm_file;
518 + prfile = vma->vm_prfile;
519 ret = do_mmap(vma->vm_file, start, size,
520 prot, flags, pgoff, &populate, NULL);
521 + if (!IS_ERR_VALUE(ret) && file && prfile) {
522 + struct vm_area_struct *new_vma;
524 + new_vma = find_vma(mm, ret);
525 + if (!new_vma->vm_prfile)
526 + new_vma->vm_prfile = prfile;
527 + if (new_vma != vma)
531 + * two fput()s instead of vma_fput(vma),
532 + * coz vma may not be available anymore.
538 mmap_write_unlock(mm);
540 @@ -3334,7 +3351,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
541 if (anon_vma_clone(new_vma, vma))
542 goto out_free_mempol;
543 if (new_vma->vm_file)
544 - get_file(new_vma->vm_file);
545 + vma_get_file(new_vma);
546 if (new_vma->vm_ops && new_vma->vm_ops->open)
547 new_vma->vm_ops->open(new_vma);
548 vma_link(mm, new_vma, prev, rb_link, rb_parent);
549 diff --git a/mm/nommu.c b/mm/nommu.c
550 index 0faf39b32cdb9..78ecad7204c86 100644
553 @@ -533,7 +533,7 @@ static void __put_nommu_region(struct vm_region *region)
554 up_write(&nommu_region_sem);
557 - fput(region->vm_file);
560 /* IO memory and memory shared directly out of the pagecache
561 * from ramfs/tmpfs mustn't be released here */
562 @@ -665,7 +665,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
563 if (vma->vm_ops && vma->vm_ops->close)
564 vma->vm_ops->close(vma);
566 - fput(vma->vm_file);
568 put_nommu_region(vma->vm_region);
571 @@ -1188,7 +1188,7 @@ unsigned long do_mmap(struct file *file,
572 goto error_just_free;
575 - fput(region->vm_file);
577 kmem_cache_free(vm_region_jar, region);
580 @@ -1265,10 +1265,10 @@ unsigned long do_mmap(struct file *file,
581 up_write(&nommu_region_sem);
584 - fput(region->vm_file);
586 kmem_cache_free(vm_region_jar, region);
588 - fput(vma->vm_file);
593 diff --git a/mm/prfile.c b/mm/prfile.c
595 index 0000000000000..511543ab1b418
599 +// SPDX-License-Identifier: GPL-2.0
601 + * Mainly for aufs which mmap(2) different file and wants to print different
602 + * path in /proc/PID/maps.
603 + * Call these functions via macros defined in linux/mm.h.
605 + * See Documentation/filesystems/aufs/design/06mmap.txt
607 + * Copyright (c) 2014-2021 Junjro R. Okajima
608 + * Copyright (c) 2014 Ian Campbell
611 +#include <linux/mm.h>
612 +#include <linux/file.h>
613 +#include <linux/fs.h>
615 +/* #define PRFILE_TRACE */
616 +static inline void prfile_trace(struct file *f, struct file *pr,
617 + const char func[], int line, const char func2[])
621 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
625 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
628 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
630 + prfile_trace(f, pr, func, line, __func__);
631 + file_update_time(f);
633 + file_update_time(pr);
636 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
639 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
641 + prfile_trace(f, pr, func, line, __func__);
642 + return (f && pr) ? pr : f;
645 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
647 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
649 + prfile_trace(f, pr, func, line, __func__);
655 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
657 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
659 + prfile_trace(f, pr, func, line, __func__);
666 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
669 + struct file *f = region->vm_file, *pr = region->vm_prfile;
671 + prfile_trace(f, pr, func, line, __func__);
672 + return (f && pr) ? pr : f;
675 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
677 + struct file *f = region->vm_file, *pr = region->vm_prfile;
679 + prfile_trace(f, pr, func, line, __func__);
684 +#endif /* !CONFIG_MMU */
685 SPDX-License-Identifier: GPL-2.0
686 aufs5.10.82 standalone patch
688 diff --git a/fs/dcache.c b/fs/dcache.c
689 index ddca6240e0db4..30dec552278dc 100644
692 @@ -1390,6 +1390,7 @@ void d_walk(struct dentry *parent, void *data,
696 +EXPORT_SYMBOL_GPL(d_walk);
699 struct vfsmount *mnt;
700 @@ -2935,6 +2936,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
702 write_sequnlock(&rename_lock);
704 +EXPORT_SYMBOL_GPL(d_exchange);
707 * d_ancestor - search for an ancestor
708 diff --git a/fs/exec.c b/fs/exec.c
709 index ca89e0e3ef10f..666565bb411f6 100644
712 @@ -113,6 +113,7 @@ bool path_noexec(const struct path *path)
713 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
714 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
716 +EXPORT_SYMBOL_GPL(path_noexec);
720 diff --git a/fs/fcntl.c b/fs/fcntl.c
721 index 7cd57fb4e8646..96bc0e48b7467 100644
724 @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
728 +EXPORT_SYMBOL_GPL(setfl);
730 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
732 diff --git a/fs/file_table.c b/fs/file_table.c
733 index 709ada3151da5..27a3e3c9f2a82 100644
734 --- a/fs/file_table.c
735 +++ b/fs/file_table.c
736 @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
738 return ERR_PTR(-ENFILE);
740 +EXPORT_SYMBOL_GPL(alloc_empty_file);
743 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
744 @@ -376,6 +377,7 @@ void __fput_sync(struct file *file)
748 +EXPORT_SYMBOL_GPL(__fput_sync);
750 void __init files_init(void)
752 diff --git a/fs/namespace.c b/fs/namespace.c
753 index a256f0f9c6c09..5d6b3e723e913 100644
756 @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
757 mnt_dec_writers(real_mount(mnt));
760 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
763 * mnt_drop_write - give up write access to a mount
764 @@ -797,6 +798,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
766 return check_mnt(real_mount(mnt));
768 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
771 * vfsmount lock must be held for write
772 @@ -1998,6 +2000,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
776 +EXPORT_SYMBOL_GPL(iterate_mounts);
778 static void lock_mnt_tree(struct mount *mnt)
780 diff --git a/fs/notify/group.c b/fs/notify/group.c
781 index a4a4b1c64d32a..86dc2efb1850c 100644
782 --- a/fs/notify/group.c
783 +++ b/fs/notify/group.c
784 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
786 refcount_inc(&group->refcnt);
788 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
791 * Drop a reference to a group. Free it if it's through.
792 diff --git a/fs/open.c b/fs/open.c
793 index 3aaaad47d9cac..60ae17e35e125 100644
796 @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
797 inode_unlock(dentry->d_inode);
800 +EXPORT_SYMBOL_GPL(do_truncate);
802 long vfs_truncate(const struct path *path, loff_t length)
804 diff --git a/fs/read_write.c b/fs/read_write.c
805 index 75f764b434184..7582bb3fb634b 100644
806 --- a/fs/read_write.c
807 +++ b/fs/read_write.c
808 @@ -503,6 +503,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
812 +EXPORT_SYMBOL_GPL(vfs_read);
814 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
816 @@ -613,6 +614,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
817 file_end_write(file);
820 +EXPORT_SYMBOL_GPL(vfs_write);
822 /* file_ppos returns &file->f_pos or NULL if file is stream */
823 static inline loff_t *file_ppos(struct file *file)
824 diff --git a/fs/splice.c b/fs/splice.c
825 index 55b5356262085..c13ac0fbac318 100644
828 @@ -763,6 +763,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
829 return warn_unsupported(out, "write");
830 return out->f_op->splice_write(pipe, out, ppos, len, flags);
832 +EXPORT_SYMBOL_GPL(do_splice_from);
835 * Attempt to initiate a splice from a file to a pipe.
836 @@ -787,6 +788,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
837 return warn_unsupported(in, "read");
838 return in->f_op->splice_read(in, ppos, pipe, len, flags);
840 +EXPORT_SYMBOL_GPL(do_splice_to);
843 * splice_direct_to_actor - splices data directly between two non-pipes
844 diff --git a/fs/sync.c b/fs/sync.c
845 index b7b5a0a0df6ff..fa5c7fba7f1ba 100644
848 @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait)
849 sb->s_op->sync_fs(sb, wait);
850 return __sync_blockdev(sb->s_bdev, wait);
852 +EXPORT_SYMBOL_GPL(__sync_filesystem);
855 * Write out and wait upon all dirty data associated with this
856 diff --git a/fs/xattr.c b/fs/xattr.c
857 index cd7a563e8bcd4..7d989d57b0f0d 100644
860 @@ -360,6 +360,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
861 *xattr_value = value;
864 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
867 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
868 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
869 index 4550f7a021178..efc579b9a36d9 100644
870 --- a/kernel/locking/lockdep.c
871 +++ b/kernel/locking/lockdep.c
872 @@ -209,6 +209,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
874 return lock_classes + class_idx;
876 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
877 #define hlock_class(hlock) lockdep_hlock_class(hlock)
879 #ifdef CONFIG_LOCK_STAT
880 diff --git a/kernel/task_work.c b/kernel/task_work.c
881 index 8d6e1217c451c..0e73637adda86 100644
882 --- a/kernel/task_work.c
883 +++ b/kernel/task_work.c
884 @@ -154,3 +154,4 @@ void task_work_run(void)
888 +EXPORT_SYMBOL_GPL(task_work_run);
889 diff --git a/security/security.c b/security/security.c
890 index a864ff824dd3b..d919d763ade5a 100644
891 --- a/security/security.c
892 +++ b/security/security.c
893 @@ -1094,6 +1094,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
895 return call_int_hook(path_rmdir, 0, dir, dentry);
897 +EXPORT_SYMBOL_GPL(security_path_rmdir);
899 int security_path_unlink(const struct path *dir, struct dentry *dentry)
901 @@ -1110,6 +1111,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
903 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
905 +EXPORT_SYMBOL_GPL(security_path_symlink);
907 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
908 struct dentry *new_dentry)
909 @@ -1118,6 +1120,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
911 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
913 +EXPORT_SYMBOL_GPL(security_path_link);
915 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
916 const struct path *new_dir, struct dentry *new_dentry,
917 @@ -1145,6 +1148,7 @@ int security_path_truncate(const struct path *path)
919 return call_int_hook(path_truncate, 0, path);
921 +EXPORT_SYMBOL_GPL(security_path_truncate);
923 int security_path_chmod(const struct path *path, umode_t mode)
925 @@ -1152,6 +1156,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
927 return call_int_hook(path_chmod, 0, path, mode);
929 +EXPORT_SYMBOL_GPL(security_path_chmod);
931 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
933 @@ -1159,6 +1164,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
935 return call_int_hook(path_chown, 0, path, uid, gid);
937 +EXPORT_SYMBOL_GPL(security_path_chown);
939 int security_path_chroot(const struct path *path)
941 @@ -1259,6 +1265,7 @@ int security_inode_permission(struct inode *inode, int mask)
943 return call_int_hook(inode_permission, 0, inode, mask);
945 +EXPORT_SYMBOL_GPL(security_inode_permission);
947 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
949 @@ -1451,6 +1458,7 @@ int security_file_permission(struct file *file, int mask)
951 return fsnotify_perm(file, mask);
953 +EXPORT_SYMBOL_GPL(security_file_permission);
955 int security_file_alloc(struct file *file)
957 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
958 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
959 +++ linux/Documentation/ABI/testing/debugfs-aufs 2021-12-03 15:38:59.926647310 +0100
961 +What: /debug/aufs/si_<id>/
963 +Contact: J. R. Okajima <hooanon05g@gmail.com>
965 + Under /debug/aufs, a directory named si_<id> is created
966 + per aufs mount, where <id> is a unique id generated
969 +What: /debug/aufs/si_<id>/plink
971 +Contact: J. R. Okajima <hooanon05g@gmail.com>
973 + It has three lines and shows the information about the
974 + pseudo-link. The first line is a single number
975 + representing a number of buckets. The second line is a
976 + number of pseudo-links per buckets (separated by a
977 + blank). The last line is a single number representing a
978 + total number of psedo-links.
979 + When the aufs mount option 'noplink' is specified, it
980 + will show "1\n0\n0\n".
982 +What: /debug/aufs/si_<id>/xib
984 +Contact: J. R. Okajima <hooanon05g@gmail.com>
986 + It shows the consumed blocks by xib (External Inode Number
987 + Bitmap), its block size and file size.
988 + When the aufs mount option 'noxino' is specified, it
989 + will be empty. About XINO files, see the aufs manual.
991 +What: /debug/aufs/si_<id>/xi<branch-index>
993 +Contact: J. R. Okajima <hooanon05g@gmail.com>
995 + It shows the consumed blocks by xino (External Inode Number
996 + Translation Table), its link count, block size and file
998 + Due to the file size limit, there may exist multiple
999 + xino files per branch. In this case, "-N" is added to
1000 + the filename and it corresponds to the index of the
1001 + internal xino array. "-0" is omitted.
1002 + When the aufs mount option 'noxino' is specified, Those
1003 + entries won't exist. About XINO files, see the aufs
1006 +What: /debug/aufs/si_<id>/xigen
1008 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1010 + It shows the consumed blocks by xigen (External Inode
1011 + Generation Table), its block size and file size.
1012 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1014 + When the aufs mount option 'noxino' is specified, it
1015 + will be empty. About XINO files, see the aufs manual.
1016 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1017 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1018 +++ linux/Documentation/ABI/testing/sysfs-aufs 2021-12-03 15:38:59.926647310 +0100
1020 +What: /sys/fs/aufs/si_<id>/
1022 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1024 + Under /sys/fs/aufs, a directory named si_<id> is created
1025 + per aufs mount, where <id> is a unique id generated
1028 +What: /sys/fs/aufs/si_<id>/br<idx>
1030 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1032 + It shows the abolute path of a member directory (which
1033 + is called branch) in aufs, and its permission.
1035 +What: /sys/fs/aufs/si_<id>/brid<idx>
1037 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1039 + It shows the id of a member directory (which is called
1042 +What: /sys/fs/aufs/si_<id>/xi_path
1044 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1046 + It shows the abolute path of XINO (External Inode Number
1047 + Bitmap, Translation Table and Generation Table) file
1048 + even if it is the default path.
1049 + When the aufs mount option 'noxino' is specified, it
1050 + will be empty. About XINO files, see the aufs manual.
1051 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1052 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1053 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2021-12-03 15:38:59.929980643 +0100
1056 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1058 +# This program is free software; you can redistribute it and/or modify
1059 +# it under the terms of the GNU General Public License as published by
1060 +# the Free Software Foundation; either version 2 of the License, or
1061 +# (at your option) any later version.
1063 +# This program is distributed in the hope that it will be useful,
1064 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1065 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1066 +# GNU General Public License for more details.
1068 +# You should have received a copy of the GNU General Public License
1069 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1072 +----------------------------------------
1074 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1075 +1. abbrev. for "advanced multi-layered unification filesystem".
1076 +2. abbrev. for "another unionfs".
1077 +3. abbrev. for "auf das" in German which means "on the" in English.
1078 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1079 + But "Filesystem aufs Filesystem" is hard to understand.
1080 +4. abbrev. for "African Urban Fashion Show".
1082 +AUFS is a filesystem with features:
1083 +- multi layered stackable unification filesystem, the member directory
1084 + is called as a branch.
1085 +- branch permission and attribute, 'readonly', 'real-readonly',
1086 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1088 +- internal "file copy-on-write".
1089 +- logical deletion, whiteout.
1090 +- dynamic branch manipulation, adding, deleting and changing permission.
1091 +- allow bypassing aufs, user's direct branch access.
1092 +- external inode number translation table and bitmap which maintains the
1093 + persistent aufs inode number.
1094 +- seekable directory, including NFS readdir.
1095 +- file mapping, mmap and sharing pages.
1096 +- pseudo-link, hardlink over branches.
1097 +- loopback mounted filesystem as a branch.
1098 +- several policies to select one among multiple writable branches.
1099 +- revert a single systemcall when an error occurs in aufs.
1103 +Multi Layered Stackable Unification Filesystem
1104 +----------------------------------------------------------------------
1105 +Most people already knows what it is.
1106 +It is a filesystem which unifies several directories and provides a
1107 +merged single directory. When users access a file, the access will be
1108 +passed/re-directed/converted (sorry, I am not sure which English word is
1109 +correct) to the real file on the member filesystem. The member
1110 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1111 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1112 +readonly branch is handled by creating 'whiteout' on the upper writable
1115 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1116 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1117 +different approaches to implement the merged-view.
1118 +The former tries putting it into VFS, and the latter implements as a
1119 +separate filesystem.
1120 +(If I misunderstand about these implementations, please let me know and
1121 +I shall correct it. Because it is a long time ago when I read their
1122 +source files last time).
1124 +UnionMount's approach will be able to small, but may be hard to share
1125 +branches between several UnionMount since the whiteout in it is
1126 +implemented in the inode on branch filesystem and always
1127 +shared. According to Bharata's post, readdir does not seems to be
1129 +There are several missing features known in this implementations such as
1130 +- for users, the inode number may change silently. eg. copy-up.
1131 +- link(2) may break by copy-up.
1132 +- read(2) may get an obsoleted filedata (fstat(2) too).
1133 +- fcntl(F_SETLK) may be broken by copy-up.
1134 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1137 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1138 +merged into mainline. This is another implementation of UnionMount as a
1139 +separated filesystem. All the limitations and known problems which
1140 +UnionMount are equally inherited to "overlay" filesystem.
1142 +Unionfs has a longer history. When I started implementing a stackable
1143 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1144 +inode, dentry and file objects and they have an array pointing lower
1145 +same kind objects. After contributing many patches for Unionfs, I
1146 +re-started my project AUFS (Jun 2006).
1148 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1149 +implemented my own ideas, approaches and enhancements and it became
1150 +totally different one.
1152 +Comparing DM snapshot and fs based implementation
1153 +- the number of bytes to be copied between devices is much smaller.
1154 +- the type of filesystem must be one and only.
1155 +- the fs must be writable, no readonly fs, even for the lower original
1156 + device. so the compression fs will not be usable. but if we use
1157 + loopback mount, we may address this issue.
1159 + mount /cdrom/squashfs.img /sq
1160 + losetup /sq/ext2.img
1161 + losetup /somewhere/cow
1162 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1163 +- it will be difficult (or needs more operations) to extract the
1164 + difference between the original device and COW.
1165 +- DM snapshot-merge may help a lot when users try merging. in the
1166 + fs-layer union, users will use rsync(1).
1168 +You may want to read my old paper "Filesystems in LiveCD"
1169 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1172 +Several characters/aspects/persona of aufs
1173 +----------------------------------------------------------------------
1175 +Aufs has several characters, aspects or persona.
1176 +1. a filesystem, callee of VFS helper
1177 +2. sub-VFS, caller of VFS helper for branches
1178 +3. a virtual filesystem which maintains persistent inode number
1179 +4. reader/writer of files on branches such like an application
1181 +1. Callee of VFS Helper
1182 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1183 +unlink(2) from an application reaches sys_unlink() kernel function and
1184 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1185 +calls filesystem specific unlink operation. Actually aufs implements the
1186 +unlink operation but it behaves like a redirector.
1188 +2. Caller of VFS Helper for Branches
1189 +aufs_unlink() passes the unlink request to the branch filesystem as if
1190 +it were called from VFS. So the called unlink operation of the branch
1191 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1192 +every necessary pre/post operation for the branch filesystem.
1193 +- acquire the lock for the parent dir on a branch
1194 +- lookup in a branch
1195 +- revalidate dentry on a branch
1196 +- mnt_want_write() for a branch
1197 +- vfs_unlink() for a branch
1198 +- mnt_drop_write() for a branch
1199 +- release the lock on a branch
1201 +3. Persistent Inode Number
1202 +One of the most important issue for a filesystem is to maintain inode
1203 +numbers. This is particularly important to support exporting a
1204 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1205 +backend block device for its own. But some storage is necessary to
1206 +keep and maintain the inode numbers. It may be a large space and may not
1207 +suit to keep in memory. Aufs rents some space from its first writable
1208 +branch filesystem (by default) and creates file(s) on it. These files
1209 +are created by aufs internally and removed soon (currently) keeping
1211 +Note: Because these files are removed, they are totally gone after
1212 + unmounting aufs. It means the inode numbers are not persistent
1213 + across unmount or reboot. I have a plan to make them really
1214 + persistent which will be important for aufs on NFS server.
1216 +4. Read/Write Files Internally (copy-on-write)
1217 +Because a branch can be readonly, when you write a file on it, aufs will
1218 +"copy-up" it to the upper writable branch internally. And then write the
1219 +originally requested thing to the file. Generally kernel doesn't
1220 +open/read/write file actively. In aufs, even a single write may cause a
1221 +internal "file copy". This behaviour is very similar to cp(1) command.
1223 +Some people may think it is better to pass such work to user space
1224 +helper, instead of doing in kernel space. Actually I am still thinking
1225 +about it. But currently I have implemented it in kernel space.
1226 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1227 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1228 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2021-12-03 15:38:59.929980643 +0100
1231 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1233 +# This program is free software; you can redistribute it and/or modify
1234 +# it under the terms of the GNU General Public License as published by
1235 +# the Free Software Foundation; either version 2 of the License, or
1236 +# (at your option) any later version.
1238 +# This program is distributed in the hope that it will be useful,
1239 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1240 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1241 +# GNU General Public License for more details.
1243 +# You should have received a copy of the GNU General Public License
1244 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1246 +Basic Aufs Internal Structure
1248 +Superblock/Inode/Dentry/File Objects
1249 +----------------------------------------------------------------------
1250 +As like an ordinary filesystem, aufs has its own
1251 +superblock/inode/dentry/file objects. All these objects have a
1252 +dynamically allocated array and store the same kind of pointers to the
1253 +lower filesystem, branch.
1254 +For example, when you build a union with one readwrite branch and one
1255 +readonly, mounted /au, /rw and /ro respectively.
1257 +- /ro/fileA exists but /rw/fileA
1259 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1260 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1261 +- [0] = NULL (because /rw/fileA doesn't exist)
1264 +This style of an array is essentially same to the aufs
1265 +superblock/inode/dentry/file objects.
1267 +Because aufs supports manipulating branches, ie. add/delete/change
1268 +branches dynamically, these objects has its own generation. When
1269 +branches are changed, the generation in aufs superblock is
1270 +incremented. And a generation in other object are compared when it is
1271 +accessed. When a generation in other objects are obsoleted, aufs
1272 +refreshes the internal array.
1276 +----------------------------------------------------------------------
1277 +Additionally aufs superblock has some data for policies to select one
1278 +among multiple writable branches, XIB files, pseudo-links and kobject.
1279 +See below in detail.
1280 +About the policies which supports copy-down a directory, see
1281 +wbr_policy.txt too.
1284 +Branch and XINO(External Inode Number Translation Table)
1285 +----------------------------------------------------------------------
1286 +Every branch has its own xino (external inode number translation table)
1287 +file. The xino file is created and unlinked by aufs internally. When two
1288 +members of a union exist on the same filesystem, they share the single
1290 +The struct of a xino file is simple, just a sequence of aufs inode
1291 +numbers which is indexed by the lower inode number.
1292 +In the above sample, assume the inode number of /ro/fileA is i111 and
1293 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1294 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1296 +When the inode numbers are not contiguous, the xino file will be sparse
1297 +which has a hole in it and doesn't consume as much disk space as it
1298 +might appear. If your branch filesystem consumes disk space for such
1299 +holes, then you should specify 'xino=' option at mounting aufs.
1301 +Aufs has a mount option to free the disk blocks for such holes in XINO
1302 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1303 +meet a problem of disk shortage due to XINO files, then you should try
1304 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1305 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1306 +the holes in XINO files.
1308 +Also a writable branch has three kinds of "whiteout bases". All these
1309 +are existed when the branch is joined to aufs, and their names are
1310 +whiteout-ed doubly, so that users will never see their names in aufs
1312 +1. a regular file which will be hardlinked to all whiteouts.
1313 +2. a directory to store a pseudo-link.
1314 +3. a directory to store an "orphan"-ed file temporary.
1317 + When you remove a file on a readonly branch, aufs handles it as a
1318 + logical deletion and creates a whiteout on the upper writable branch
1319 + as a hardlink of this file in order not to consume inode on the
1322 + See below, Pseudo-link.
1324 + When "fileC" exists on the lower readonly branch only and it is
1325 + opened and removed with its parent dir, and then user writes
1326 + something into it, then aufs copies-up fileC to this
1327 + directory. Because there is no other dir to store fileC. After
1328 + creating a file under this dir, the file is unlinked.
1330 +Because aufs supports manipulating branches, ie. add/delete/change
1331 +dynamically, a branch has its own id. When the branch order changes,
1332 +aufs finds the new index by searching the branch id.
1336 +----------------------------------------------------------------------
1337 +Assume "fileA" exists on the lower readonly branch only and it is
1338 +hardlinked to "fileB" on the branch. When you write something to fileA,
1339 +aufs copies-up it to the upper writable branch. Additionally aufs
1340 +creates a hardlink under the Pseudo-link Directory of the writable
1341 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1342 +simple list. If fileB is read after unlinking fileA, aufs returns
1343 +filedata from the pseudo-link instead of the lower readonly
1344 +branch. Because the pseudo-link is based upon the inode, to keep the
1345 +inode number by xino (see above) is essentially necessary.
1347 +All the hardlinks under the Pseudo-link Directory of the writable branch
1348 +should be restored in a proper location later. Aufs provides a utility
1349 +to do this. The userspace helpers executed at remounting and unmounting
1351 +During this utility is running, it puts aufs into the pseudo-link
1352 +maintenance mode. In this mode, only the process which began the
1353 +maintenance mode (and its child processes) is allowed to operate in
1354 +aufs. Some other processes which are not related to the pseudo-link will
1355 +be allowed to run too, but the rest have to return an error or wait
1356 +until the maintenance mode ends. If a process already acquires an inode
1357 +mutex (in VFS), it has to return an error.
1360 +XIB(external inode number bitmap)
1361 +----------------------------------------------------------------------
1362 +Addition to the xino file per a branch, aufs has an external inode number
1363 +bitmap in a superblock object. It is also an internal file such like a
1365 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1367 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1369 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1370 +reduce the number of consumed disk blocks for these files.
1373 +Virtual or Vertical Dir, and Readdir in Userspace
1374 +----------------------------------------------------------------------
1375 +In order to support multiple layers (branches), aufs readdir operation
1376 +constructs a virtual dir block on memory. For readdir, aufs calls
1377 +vfs_readdir() internally for each dir on branches, merges their entries
1378 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1379 +object. So the file object has its entry list until it is closed. The
1380 +entry list will be updated when the file position is zero and becomes
1381 +obsoleted. This decision is made in aufs automatically.
1383 +The dynamically allocated memory block for the name of entries has a
1384 +unit of 512 bytes (by default) and stores the names contiguously (no
1385 +padding). Another block for each entry is handled by kmem_cache too.
1386 +During building dir blocks, aufs creates hash list and judging whether
1387 +the entry is whiteouted by its upper branch or already listed.
1388 +The merged result is cached in the corresponding inode object and
1389 +maintained by a customizable life-time option.
1391 +Some people may call it can be a security hole or invite DoS attack
1392 +since the opened and once readdir-ed dir (file object) holds its entry
1393 +list and becomes a pressure for system memory. But I'd say it is similar
1394 +to files under /proc or /sys. The virtual files in them also holds a
1395 +memory page (generally) while they are opened. When an idea to reduce
1396 +memory for them is introduced, it will be applied to aufs too.
1397 +For those who really hate this situation, I've developed readdir(3)
1398 +library which operates this merging in userspace. You just need to set
1399 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1400 +kernel space for readdir(3).
1404 +----------------------------------------------------------------------
1405 +Aufs sometimes requires privilege access to a branch. For instance,
1406 +in copy-up/down operation. When a user process is going to make changes
1407 +to a file which exists in the lower readonly branch only, and the mode
1408 +of one of ancestor directories may not be writable by a user
1409 +process. Here aufs copy-up the file with its ancestors and they may
1410 +require privilege to set its owner/group/mode/etc.
1411 +This is a typical case of a application character of aufs (see
1414 +Aufs uses workqueue synchronously for this case. It creates its own
1415 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1416 +passes the request to call mkdir or write (for example), and wait for
1417 +its completion. This approach solves a problem of a signal handler
1419 +If aufs didn't adopt the workqueue and changed the privilege of the
1420 +process, then the process may receive the unexpected SIGXFSZ or other
1423 +Also aufs uses the system global workqueue ("events" kernel thread) too
1424 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1425 +whiteout base and etc. This is unrelated to a privilege.
1426 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1427 +superblock at the beginning, at the same time waits for the completion
1428 +of all queued asynchronous tasks.
1432 +----------------------------------------------------------------------
1433 +The whiteout in aufs is very similar to Unionfs's. That is represented
1434 +by its filename. UnionMount takes an approach of a file mode, but I am
1435 +afraid several utilities (find(1) or something) will have to support it.
1437 +Basically the whiteout represents "logical deletion" which stops aufs to
1438 +lookup further, but also it represents "dir is opaque" which also stop
1441 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1442 +In order to make several functions in a single systemcall to be
1443 +revertible, aufs adopts an approach to rename a directory to a temporary
1444 +unique whiteouted name.
1445 +For example, in rename(2) dir where the target dir already existed, aufs
1446 +renames the target dir to a temporary unique whiteouted name before the
1447 +actual rename on a branch, and then handles other actions (make it opaque,
1448 +update the attributes, etc). If an error happens in these actions, aufs
1449 +simply renames the whiteouted name back and returns an error. If all are
1450 +succeeded, aufs registers a function to remove the whiteouted unique
1451 +temporary name completely and asynchronously to the system global
1456 +----------------------------------------------------------------------
1457 +It is a well-known feature or concept.
1458 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1459 +internally and makes change to the new file on the upper writable branch.
1460 +When the trigger systemcall does not update the timestamps of the parent
1461 +dir, aufs reverts it after copy-up.
1464 +Move-down (aufs3.9 and later)
1465 +----------------------------------------------------------------------
1466 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1467 +the lower readonly branch to the upper writable branch when a user
1468 +changes something about the file.
1469 +"Move-down" is an opposite action of copy-up. Basically this action is
1470 +ran manually instead of automatically and internally.
1471 +For desgin and implementation, aufs has to consider these issues.
1472 +- whiteout for the file may exist on the lower branch.
1473 +- ancestor directories may not exist on the lower branch.
1474 +- diropq for the ancestor directories may exist on the upper branch.
1475 +- free space on the lower branch will reduce.
1476 +- another access to the file may happen during moving-down, including
1477 + UDBA (see "Revalidate Dentry and UDBA").
1478 +- the file should not be hard-linked nor pseudo-linked. they should be
1479 + handled by auplink utility later.
1481 +Sometimes users want to move-down a file from the upper writable branch
1482 +to the lower readonly or writable branch. For instance,
1483 +- the free space of the upper writable branch is going to run out.
1484 +- create a new intermediate branch between the upper and lower branch.
1487 +For this purpose, use "aumvdown" command in aufs-util.git.
1488 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1489 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1490 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-12-03 15:38:59.929980643 +0100
1493 +# Copyright (C) 2015-2021 Junjiro R. Okajima
1495 +# This program is free software; you can redistribute it and/or modify
1496 +# it under the terms of the GNU General Public License as published by
1497 +# the Free Software Foundation; either version 2 of the License, or
1498 +# (at your option) any later version.
1500 +# This program is distributed in the hope that it will be useful,
1501 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1502 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1503 +# GNU General Public License for more details.
1505 +# You should have received a copy of the GNU General Public License
1506 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1508 +Support for a branch who has its ->atomic_open()
1509 +----------------------------------------------------------------------
1510 +The filesystems who implement its ->atomic_open() are not majority. For
1511 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1512 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1513 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1514 +sure whether all filesystems who have ->atomic_open() behave like this,
1515 +but NFSv4 surely returns the error.
1517 +In order to support ->atomic_open() for aufs, there are a few
1520 +A. Introduce aufs_atomic_open()
1521 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1523 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1524 + an aufs user Pip Cet's approach
1525 + - calls aufs_create(), VFS finish_open() and notify_change().
1526 + - pass fake-mode to finish_open(), and then correct the mode by
1528 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1529 + - no aufs_atomic_open().
1530 + - aufs_lookup() registers the TID to an aufs internal object.
1531 + - aufs_create() does nothing when the matching TID is registered, but
1532 + registers the mode.
1533 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1534 + TID is registered.
1535 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1537 + - no aufs_atomic_open().
1538 + - aufs_create() registers the TID to an internal object. this info
1539 + represents "this process created this file just now."
1540 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1541 + registered TID and re-try open() with superuser's credential.
1543 +Pros and cons for each approach.
1546 + - straightforward but highly depends upon VFS internal.
1547 + - the atomic behavaiour is kept.
1548 + - some of parameters such as nameidata are hard to reproduce for
1552 + - easy to implement.
1553 + - the atomic behavaiour is lost.
1555 + - the atomic behavaiour is kept.
1556 + - dirty and tricky.
1557 + - VFS checks whether the file is created correctly after calling
1558 + ->create(), which means this approach doesn't work.
1560 + - easy to implement.
1561 + - the atomic behavaiour is lost.
1562 + - to open a file with superuser's credential and give it to a user
1563 + process is a bad idea, since the file object keeps the credential
1564 + in it. It may affect LSM or something. This approach doesn't work
1567 +The approach A is ideal, but it hard to implement. So here is a
1568 +variation of A, which is to be implemented.
1570 +A-1. Introduce aufs_atomic_open()
1571 + - calls branch fs ->atomic_open() if exists. otherwise calls
1572 + vfs_create() and finish_open().
1573 + - the demerit is that the several checks after branch fs
1574 + ->atomic_open() are lost. in the ordinary case, the checks are
1575 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1576 + be implemented in aufs, but not all I am afraid.
1577 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1578 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1579 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2021-12-03 15:38:59.929980643 +0100
1582 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1584 +# This program is free software; you can redistribute it and/or modify
1585 +# it under the terms of the GNU General Public License as published by
1586 +# the Free Software Foundation; either version 2 of the License, or
1587 +# (at your option) any later version.
1589 +# This program is distributed in the hope that it will be useful,
1590 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1591 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1592 +# GNU General Public License for more details.
1594 +# You should have received a copy of the GNU General Public License
1595 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1598 +----------------------------------------------------------------------
1599 +Since aufs has a character of sub-VFS (see Introduction), it operates
1600 +lookup for branches as VFS does. It may be a heavy work. But almost all
1601 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1602 +directly connected to its parent. Digging down the directory hierarchy
1603 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1606 +When a branch is a remote filesystem, aufs basically relies upon its
1607 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1609 +For d_revalidate, aufs implements three levels of revalidate tests. See
1610 +"Revalidate Dentry and UDBA" in detail.
1613 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1614 +----------------------------------------------------------------------
1615 +Let's try case study.
1616 +- aufs has two branches, upper readwrite and lower readonly.
1618 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1619 +- user invoked "chmod a+rx /au/dirA"
1620 +- the internal copy-up is activated and "/rw/dirA" is created and its
1621 + permission bits are set to world readable.
1622 +- then "/au/dirA" becomes world readable?
1624 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1625 +or it may be a natively readonly filesystem. If aufs respects the lower
1626 +branch, it should not respond readdir request from other users. But user
1627 +allowed it by chmod. Should really aufs rejects showing the entries
1630 +To be honest, I don't have a good solution for this case. So aufs
1631 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1633 +When dirperm1 is specified, aufs checks only the highest one for the
1634 +directory permission, and shows the entries. Otherwise, as usual, checks
1635 +every dir existing on all branches and rejects the request.
1637 +As a side effect, dirperm1 option improves the performance of aufs
1638 +because the number of permission check is reduced when the number of
1642 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1643 +----------------------------------------------------------------------
1644 +Generally VFS helpers re-validate a dentry as a part of lookup.
1645 +0. digging down the directory hierarchy.
1646 +1. lock the parent dir by its i_mutex.
1647 +2. lookup the final (child) entry.
1649 +4. call the actual operation (create, unlink, etc.)
1650 +5. unlock the parent dir
1652 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1653 +called. Actually aufs implements it and checks the dentry on a branch is
1655 +But it is not enough. Because aufs has to release the lock for the
1656 +parent dir on a branch at the end of ->lookup() (step 2) and
1657 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1659 +If the file on a branch is changed directly, eg. bypassing aufs, after
1660 +aufs released the lock, then the subsequent operation may cause
1661 +something unpleasant result.
1663 +This situation is a result of VFS architecture, ->lookup() and
1664 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1665 +design from VFS's point of view. It is just not suitable for sub-VFS
1668 +Aufs supports such case by three level of revalidation which is
1669 +selectable by user.
1670 +1. Simple Revalidate
1671 + Addition to the native flow in VFS's, confirm the child-parent
1672 + relationship on the branch just after locking the parent dir on the
1673 + branch in the "actual operation" (step 4). When this validation
1674 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1675 + checks the validation of the dentry on branches.
1676 +2. Monitor Changes Internally by Inotify/Fsnotify
1677 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1678 + the dentry on the branch, and returns EBUSY if it finds different
1680 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1681 + during it is in cache. When the event is notified, aufs registers a
1682 + function to kernel 'events' thread by schedule_work(). And the
1683 + function sets some special status to the cached aufs dentry and inode
1684 + private data. If they are not cached, then aufs has nothing to
1685 + do. When the same file is accessed through aufs (step 0-3) later,
1686 + aufs will detect the status and refresh all necessary data.
1687 + In this mode, aufs has to ignore the event which is fired by aufs
1689 +3. No Extra Validation
1690 + This is the simplest test and doesn't add any additional revalidation
1691 + test, and skip the revalidation in step 4. It is useful and improves
1692 + aufs performance when system surely hide the aufs branches from user,
1693 + by over-mounting something (or another method).
1694 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1695 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1696 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2021-12-03 15:38:59.929980643 +0100
1699 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1701 +# This program is free software; you can redistribute it and/or modify
1702 +# it under the terms of the GNU General Public License as published by
1703 +# the Free Software Foundation; either version 2 of the License, or
1704 +# (at your option) any later version.
1706 +# This program is distributed in the hope that it will be useful,
1707 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1708 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1709 +# GNU General Public License for more details.
1711 +# You should have received a copy of the GNU General Public License
1712 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1714 +Branch Manipulation
1716 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1717 +and changing its permission/attribute, there are a lot of works to do.
1721 +----------------------------------------------------------------------
1722 +o Confirm the adding dir exists outside of aufs, including loopback
1723 + mount, and its various attributes.
1724 +o Initialize the xino file and whiteout bases if necessary.
1727 +o Check the owner/group/mode of the directory
1728 + When the owner/group/mode of the adding directory differs from the
1729 + existing branch, aufs issues a warning because it may impose a
1731 + For example, when a upper writable branch has a world writable empty
1732 + top directory, a malicious user can create any files on the writable
1733 + branch directly, like copy-up and modify manually. If something like
1734 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1735 + writable branch, and the writable branch is world-writable, then a
1736 + malicious guy may create /etc/passwd on the writable branch directly
1737 + and the infected file will be valid in aufs.
1738 + I am afraid it can be a security issue, but aufs can do nothing except
1739 + producing a warning.
1743 +----------------------------------------------------------------------
1744 +o Confirm the deleting branch is not busy
1745 + To be general, there is one merit to adopt "remount" interface to
1746 + manipulate branches. It is to discard caches. At deleting a branch,
1747 + aufs checks the still cached (and connected) dentries and inodes. If
1748 + there are any, then they are all in-use. An inode without its
1749 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1751 + For the cached one, aufs checks whether the same named entry exists on
1753 + If the cached one is a directory, because aufs provides a merged view
1754 + to users, as long as one dir is left on any branch aufs can show the
1755 + dir to users. In this case, the branch can be removed from aufs.
1756 + Otherwise aufs rejects deleting the branch.
1758 + If any file on the deleting branch is opened by aufs, then aufs
1762 +Modify the Permission of a Branch
1763 +----------------------------------------------------------------------
1764 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1767 +o rw --> ro: Confirm the modifying branch is not busy
1768 + Aufs rejects the request if any of these conditions are true.
1769 + - a file on the branch is mmap-ed.
1770 + - a regular file on the branch is opened for write and there is no
1771 + same named entry on the upper branch.
1772 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1773 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1774 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-12-03 15:38:59.929980643 +0100
1777 +# Copyright (C) 2005-2021 Junjiro R. Okajima
1779 +# This program is free software; you can redistribute it and/or modify
1780 +# it under the terms of the GNU General Public License as published by
1781 +# the Free Software Foundation; either version 2 of the License, or
1782 +# (at your option) any later version.
1784 +# This program is distributed in the hope that it will be useful,
1785 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1786 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1787 +# GNU General Public License for more details.
1789 +# You should have received a copy of the GNU General Public License
1790 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1792 +Policies to Select One among Multiple Writable Branches
1793 +----------------------------------------------------------------------
1794 +When the number of writable branch is more than one, aufs has to decide
1795 +the target branch for file creation or copy-up. By default, the highest
1796 +writable branch which has the parent (or ancestor) dir of the target
1797 +file is chosen (top-down-parent policy).
1798 +By user's request, aufs implements some other policies to select the
1799 +writable branch, for file creation several policies, round-robin,
1800 +most-free-space, and other policies. For copy-up, top-down-parent,
1801 +bottom-up-parent, bottom-up and others.
1803 +As expected, the round-robin policy selects the branch in circular. When
1804 +you have two writable branches and creates 10 new files, 5 files will be
1805 +created for each branch. mkdir(2) systemcall is an exception. When you
1806 +create 10 new directories, all will be created on the same branch.
1807 +And the most-free-space policy selects the one which has most free
1808 +space among the writable branches. The amount of free space will be
1809 +checked by aufs internally, and users can specify its time interval.
1811 +The policies for copy-up is more simple,
1812 +top-down-parent is equivalent to the same named on in create policy,
1813 +bottom-up-parent selects the writable branch where the parent dir
1814 +exists and the nearest upper one from the copyup-source,
1815 +bottom-up selects the nearest upper writable branch from the
1816 +copyup-source, regardless the existence of the parent dir.
1818 +There are some rules or exceptions to apply these policies.
1819 +- If there is a readonly branch above the policy-selected branch and
1820 + the parent dir is marked as opaque (a variation of whiteout), or the
1821 + target (creating) file is whiteout-ed on the upper readonly branch,
1822 + then the result of the policy is ignored and the target file will be
1823 + created on the nearest upper writable branch than the readonly branch.
1824 +- If there is a writable branch above the policy-selected branch and
1825 + the parent dir is marked as opaque or the target file is whiteouted
1826 + on the branch, then the result of the policy is ignored and the target
1827 + file will be created on the highest one among the upper writable
1828 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1830 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1831 + They try selecting the branch where the source exists as possible
1832 + since copyup a large file will take long time. If it can't be,
1833 + ie. the branch where the source exists is readonly, then they will
1834 + follow the copyup policy.
1835 +- There is an exception for rename(2) when the target exists.
1836 + If the rename target exists, aufs compares the index of the branches
1837 + where the source and the target exists and selects the higher
1838 + one. If the selected branch is readonly, then aufs follows the
1840 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1841 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1842 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2021-12-03 15:38:59.929980643 +0100
1845 +// to view this graph, run dot(1) command in GRAPHVIZ.
1849 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1853 +aufs_rename -> whinfo [label="store/remove"];
1856 +inode_list [label="h_inum list in branch\ncache"];
1859 +whinode [label="h_inum list file"];
1862 +brmgmt [label="br_add/del/mod/umount"];
1864 +brmgmt -> inode_list [label="create/remove"];
1865 +brmgmt -> whinode [label="load/store"];
1867 +inode_list -> whinode [style=dashed,dir=both];
1869 +aufs_rename -> inode_list [label="add/del"];
1871 +aufs_lookup -> inode_list [label="search"];
1873 +aufs_lookup -> whinfo [label="load/remove"];
1875 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1876 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1877 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2021-12-03 15:38:59.929980643 +0100
1880 +# Copyright (C) 2017-2021 Junjiro R. Okajima
1882 +# This program is free software; you can redistribute it and/or modify
1883 +# it under the terms of the GNU General Public License as published by
1884 +# the Free Software Foundation; either version 2 of the License, or
1885 +# (at your option) any later version.
1887 +# This program is distributed in the hope that it will be useful,
1888 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1889 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1890 +# GNU General Public License for more details.
1892 +# You should have received a copy of the GNU General Public License
1893 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1895 +Special handling for renaming a directory (DIRREN)
1896 +----------------------------------------------------------------------
1897 +First, let's assume we have a simple usecase.
1901 +- /ro/dirA and /ro/dirA/file exist too
1902 +- there is no dirB on both branches
1903 +- a user issues rename("dirA", "dirB")
1905 +Now, what should aufs behave against this rename(2)?
1906 +There are a few possible cases.
1909 + since dirA exists on a readonly branch which cannot be renamed.
1911 + it is possible to copy-up dirA (only the dir itself), but the child
1912 + entries ("file" in this case) should not be. it must be a bad
1913 + approach to copy-up recursively.
1914 +C. returns a success.
1915 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1916 + is a violation of aufs' policy.
1917 +D. construct an extra information which indicates that /ro/dirA should
1918 + be handled as the name of dirB.
1919 + overlayfs has a similar feature called REDIRECT.
1921 +Until now, aufs implements the case B only which returns EXDEV, and
1922 +expects the userspace application behaves like mv(1) which tries
1923 +issueing rename(2) recursively.
1925 +A new aufs feature called DIRREN is introduced which implements the case
1926 +D. There are several "extra information" added.
1928 +1. detailed info per renamed directory
1929 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1930 +2. the inode-number list of directories on a branch
1931 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1933 +The filename of "detailed info per directory" represents the lower
1934 +branch, and its format is
1935 +- a type of the branch id
1937 + + uuid (not implemented yet)
1940 +- the inode-number of the branch root dir
1942 +And it contains these info in a single regular file.
1944 +- branch's inode-number of the logically renamed dir
1945 +- the name of the before-renamed dir
1947 +The "detailed info per directory" file is created in aufs rename(2), and
1948 +loaded in any lookup.
1949 +The info is considered in lookup for the matching case only. Here
1950 +"matching" means that the root of branch (in the info filename) is same
1951 +to the current looking-up branch. After looking-up the before-renamed
1952 +name, the inode-number is compared. And the matched dentry is used.
1954 +The "inode-number list of directories" is a regular file which contains
1955 +simply the inode-numbers on the branch. The file is created or updated
1956 +in removing the branch, and loaded in adding the branch. Its lifetime is
1957 +equal to the branch.
1958 +The list is refered in lookup, and when the current target inode is
1959 +found in the list, the aufs tries loading the "detailed info per
1960 +directory" and get the changed and valid name of the dir.
1962 +Theoretically these "extra informaiton" may be able to be put into XATTR
1963 +in the dir inode. But aufs doesn't choose this way because
1964 +1. XATTR may not be supported by the branch (or its configuration)
1965 +2. XATTR may have its size limit.
1966 +3. XATTR may be less easy to convert than a regular file, when the
1967 + format of the info is changed in the future.
1968 +At the same time, I agree that the regular file approach is much slower
1969 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1972 +This DIRREN feature is enabled by aufs configuration, and is activated
1973 +by a new mount option.
1975 +For the more complicated case, there is a work with UDBA option, which
1976 +is to dected the direct access to the branches (by-passing aufs) and to
1977 +maintain the cashes in aufs. Since a single cached aufs dentry may
1978 +contains two names, before- and after-rename, the name comparision in
1979 +UDBA handler may not work correctly. In this case, the behaviour will be
1980 +equivalen to udba=reval case.
1981 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1982 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1983 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2021-12-03 15:38:59.929980643 +0100
1986 +# Copyright (C) 2011-2021 Junjiro R. Okajima
1988 +# This program is free software; you can redistribute it and/or modify
1989 +# it under the terms of the GNU General Public License as published by
1990 +# the Free Software Foundation; either version 2 of the License, or
1991 +# (at your option) any later version.
1993 +# This program is distributed in the hope that it will be useful,
1994 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1995 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1996 +# GNU General Public License for more details.
1998 +# You should have received a copy of the GNU General Public License
1999 +# along with this program; if not, write to the Free Software
2000 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2003 +File-based Hierarchical Storage Management (FHSM)
2004 +----------------------------------------------------------------------
2005 +Hierarchical Storage Management (or HSM) is a well-known feature in the
2006 +storage world. Aufs provides this feature as file-based with multiple
2007 +writable branches, based upon the principle of "Colder, the Lower".
2008 +Here the word "colder" means that the less used files, and "lower" means
2009 +that the position in the order of the stacked branches vertically.
2010 +These multiple writable branches are prioritized, ie. the topmost one
2011 +should be the fastest drive and be used heavily.
2013 +o Characters in aufs FHSM story
2014 +- aufs itself and a new branch attribute.
2015 +- a new ioctl interface to move-down and to establish a connection with
2016 + the daemon ("move-down" is a converse of "copy-up").
2017 +- userspace tool and daemon.
2019 +The userspace daemon establishes a connection with aufs and waits for
2020 +the notification. The notified information is very similar to struct
2021 +statfs containing the number of consumed blocks and inodes.
2022 +When the consumed blocks/inodes of a branch exceeds the user-specified
2023 +upper watermark, the daemon activates its move-down process until the
2024 +consumed blocks/inodes reaches the user-specified lower watermark.
2026 +The actual move-down is done by aufs based upon the request from
2027 +user-space since we need to maintain the inode number and the internal
2028 +pointer arrays in aufs.
2030 +Currently aufs FHSM handles the regular files only. Additionally they
2031 +must not be hard-linked nor pseudo-linked.
2034 +o Cowork of aufs and the user-space daemon
2035 + During the userspace daemon established the connection, aufs sends a
2036 + small notification to it whenever aufs writes something into the
2037 + writable branch. But it may cost high since aufs issues statfs(2)
2038 + internally. So user can specify a new option to cache the
2039 + info. Actually the notification is controlled by these factors.
2040 + + the specified cache time.
2041 + + classified as "force" by aufs internally.
2042 + Until the specified time expires, aufs doesn't send the info
2043 + except the forced cases. When aufs decide forcing, the info is always
2044 + notified to userspace.
2045 + For example, the number of free inodes is generally large enough and
2046 + the shortage of it happens rarely. So aufs doesn't force the
2047 + notification when creating a new file, directory and others. This is
2048 + the typical case which aufs doesn't force.
2049 + When aufs writes the actual filedata and the files consumes any of new
2050 + blocks, the aufs forces notifying.
2053 +o Interfaces in aufs
2054 +- New branch attribute.
2056 + Specifies that the branch is managed by FHSM feature. In other word,
2057 + participant in the FHSM.
2058 + When nofhsm is set to the branch, it will not be the source/target
2059 + branch of the move-down operation. This attribute is set
2060 + independently from coo and moo attributes, and if you want full
2061 + FHSM, you should specify them as well.
2062 +- New mount option.
2064 + Specifies a second to suppress many less important info to be
2067 + + AUFS_CTL_FHSM_FD
2068 + create a new file descriptor which userspace can read the notification
2069 + (a subset of struct statfs) from aufs.
2070 +- Module parameter 'brs'
2071 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2073 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2074 + When there are two or more branches with fhsm attributes,
2075 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2076 + terminates it. As a result of remounting and branch-manipulation, the
2077 + number of branches with fhsm attribute can be one. In this case,
2078 + /sbin/mount.aufs will terminate the user-space daemon.
2081 +Finally the operation is done as these steps in kernel-space.
2083 + + no one else is using the file.
2084 + + the file is not hard-linked.
2085 + + the file is not pseudo-linked.
2086 + + the file is a regular file.
2087 + + the parent dir is not opaqued.
2088 +- find the target writable branch.
2089 +- make sure the file is not whiteout-ed by the upper (than the target)
2091 +- make the parent dir on the target branch.
2092 +- mutex lock the inode on the branch.
2093 +- unlink the whiteout on the target branch (if exists).
2094 +- lookup and create the whiteout-ed temporary name on the target branch.
2095 +- copy the file as the whiteout-ed temporary name on the target branch.
2096 +- rename the whiteout-ed temporary name to the original name.
2097 +- unlink the file on the source branch.
2098 +- maintain the internal pointer array and the external inode number
2100 +- maintain the timestamps and other attributes of the parent dir and the
2103 +And of course, in every step, an error may happen. So the operation
2104 +should restore the original file state after an error happens.
2105 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2106 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2107 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2021-12-03 15:38:59.929980643 +0100
2110 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2112 +# This program is free software; you can redistribute it and/or modify
2113 +# it under the terms of the GNU General Public License as published by
2114 +# the Free Software Foundation; either version 2 of the License, or
2115 +# (at your option) any later version.
2117 +# This program is distributed in the hope that it will be useful,
2118 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2119 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2120 +# GNU General Public License for more details.
2122 +# You should have received a copy of the GNU General Public License
2123 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2125 +mmap(2) -- File Memory Mapping
2126 +----------------------------------------------------------------------
2127 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2128 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2130 +This approach is simple and good, but there is one problem.
2131 +Under /proc, several entries show the mmapped files by its path (with
2132 +device and inode number), and the printed path will be the path on the
2133 +branch fs's instead of virtual aufs's.
2134 +This is not a problem in most cases, but some utilities lsof(1) (and its
2135 +user) may expect the path on aufs.
2137 +To address this issue, aufs adds a new member called vm_prfile in struct
2138 +vm_area_struct (and struct vm_region). The original vm_file points to
2139 +the file on the branch fs in order to handle everything correctly as
2140 +usual. The new vm_prfile points to a virtual file in aufs, and the
2141 +show-functions in procfs refers to vm_prfile if it is set.
2142 +Also we need to maintain several other places where touching vm_file
2144 +- fork()/clone() copies vma and the reference count of vm_file is
2146 +- merging vma maintains the ref count too.
2148 +This is not a good approach. It just fakes the printed path. But it
2149 +leaves all behaviour around f_mapping unchanged. This is surely an
2151 +Actually aufs had adopted another complicated approach which calls
2152 +generic_file_mmap() and handles struct vm_operations_struct. In this
2153 +approach, aufs met a hard problem and I could not solve it without
2154 +switching the approach.
2156 +There may be one more another approach which is
2157 +- bind-mount the branch-root onto the aufs-root internally
2158 +- grab the new vfsmount (ie. struct mount)
2159 +- lazy-umount the branch-root internally
2160 +- in open(2) the aufs-file, open the branch-file with the hidden
2161 + vfsmount (instead of the original branch's vfsmount)
2162 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2163 + but it may be possible from userspace by the mount helper.
2165 +Adding the internal hidden vfsmount and using it in opening a file, the
2166 +file path under /proc will be printed correctly. This approach looks
2167 +smarter, but is not possible I am afraid.
2168 +- aufs-root may be bind-mount later. when it happens, another hidden
2169 + vfsmount will be required.
2170 +- it is hard to get the chance to bind-mount and lazy-umount
2171 + + in kernel-space, FS can have vfsmount in open(2) via
2172 + file->f_path, and aufs can know its vfsmount. But several locks are
2173 + already acquired, and if aufs tries to bind-mount and lazy-umount
2174 + here, then it may cause a deadlock.
2175 + + in user-space, bind-mount doesn't invoke the mount helper.
2176 +- since /proc shows dev and ino, aufs has to give vma these info. it
2177 + means a new member vm_prinode will be necessary. this is essentially
2178 + equivalent to vm_prfile described above.
2180 +I have to give up this "looks-smater" approach.
2181 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2182 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2183 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2021-12-03 15:38:59.929980643 +0100
2186 +# Copyright (C) 2014-2021 Junjiro R. Okajima
2188 +# This program is free software; you can redistribute it and/or modify
2189 +# it under the terms of the GNU General Public License as published by
2190 +# the Free Software Foundation; either version 2 of the License, or
2191 +# (at your option) any later version.
2193 +# This program is distributed in the hope that it will be useful,
2194 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2195 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2196 +# GNU General Public License for more details.
2198 +# You should have received a copy of the GNU General Public License
2199 +# along with this program; if not, write to the Free Software
2200 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2203 +Listing XATTR/EA and getting the value
2204 +----------------------------------------------------------------------
2205 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2206 +shows the values from the topmost existing file. This behaviour is good
2207 +for the non-dir entries since the bahaviour exactly matches the shown
2208 +information. But for the directories, aufs considers all the same named
2209 +entries on the lower branches. Which means, if one of the lower entry
2210 +rejects readdir call, then aufs returns an error even if the topmost
2211 +entry allows it. This behaviour is necessary to respect the branch fs's
2212 +security, but can make users confused since the user-visible standard
2213 +attributes don't match the behaviour.
2214 +To address this issue, aufs has a mount option called dirperm1 which
2215 +checks the permission for the topmost entry only, and ignores the lower
2216 +entry's permission.
2218 +A similar issue can happen around XATTR.
2219 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2220 +always set. Otherwise these very unpleasant situation would happen.
2221 +- listxattr(2) may return the duplicated entries.
2222 +- users may not be able to remove or reset the XATTR forever,
2225 +XATTR/EA support in the internal (copy,move)-(up,down)
2226 +----------------------------------------------------------------------
2227 +Generally the extended attributes of inode are categorized as these.
2228 +- "security" for LSM and capability.
2229 +- "system" for posix ACL, 'acl' mount option is required for the branch
2231 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2232 +- "user" for userspace, 'user_xattr' mount option is required for the
2233 + branch fs generally.
2235 +Moreover there are some other categories. Aufs handles these rather
2236 +unpopular categories as the ordinary ones, ie. there is no special
2237 +condition nor exception.
2239 +In copy-up, the support for XATTR on the dst branch may differ from the
2240 +src branch. In this case, the copy-up operation will get an error and
2241 +the original user operation which triggered the copy-up will fail. It
2242 +can happen that even all copy-up will fail.
2243 +When both of src and dst branches support XATTR and if an error occurs
2244 +during copying XATTR, then the copy-up should fail obviously. That is a
2245 +good reason and aufs should return an error to userspace. But when only
2246 +the src branch support that XATTR, aufs should not return an error.
2247 +For example, the src branch supports ACL but the dst branch doesn't
2248 +because the dst branch may natively un-support it or temporary
2249 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2250 +may NOT return an error even if the XATTR is not supported. It is
2251 +totally up to the branch fs.
2253 +Anyway when the aufs internal copy-up gets an error from the dst branch
2254 +fs, then aufs tries removing the just copied entry and returns the error
2255 +to the userspace. The worst case of this situation will be all copy-up
2258 +For the copy-up operation, there two basic approaches.
2259 +- copy the specified XATTR only (by category above), and return the
2260 + error unconditionally if it happens.
2261 +- copy all XATTR, and ignore the error on the specified category only.
2263 +In order to support XATTR and to implement the correct behaviour, aufs
2264 +chooses the latter approach and introduces some new branch attributes,
2265 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2266 +They correspond to the XATTR namespaces (see above). Additionally, to be
2267 +convenient, "icex" is also provided which means all "icex*" attributes
2268 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2270 +The meaning of these attributes is to ignore the error from setting
2271 +XATTR on that branch.
2272 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2273 +error from the dst branch according to the specified attributes.
2275 +Some XATTR may have its default value. The default value may come from
2276 +the parent dir or the environment. If the default value is set at the
2277 +file creating-time, it will be overwritten by copy-up.
2278 +Some contradiction may happen I am afraid.
2279 +Do we need another attribute to stop copying XATTR? I am unsure. For
2280 +now, aufs implements the branch attributes to ignore the error.
2281 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2282 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2283 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2021-12-03 15:38:59.929980643 +0100
2286 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2288 +# This program is free software; you can redistribute it and/or modify
2289 +# it under the terms of the GNU General Public License as published by
2290 +# the Free Software Foundation; either version 2 of the License, or
2291 +# (at your option) any later version.
2293 +# This program is distributed in the hope that it will be useful,
2294 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2295 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2296 +# GNU General Public License for more details.
2298 +# You should have received a copy of the GNU General Public License
2299 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2301 +Export Aufs via NFS
2302 +----------------------------------------------------------------------
2303 +Here is an approach.
2304 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2306 +- iget_locked(): initialize aufs inode generation for a new inode, and
2307 + store it in xigen file.
2308 +- destroy_inode(): increment aufs inode generation and store it in xigen
2309 + file. it is necessary even if it is not unlinked, because any data of
2310 + inode may be changed by UDBA.
2311 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2312 + build file handle by
2313 + + branch id (4 bytes)
2314 + + superblock generation (4 bytes)
2315 + + inode number (4 or 8 bytes)
2316 + + parent dir inode number (4 or 8 bytes)
2317 + + inode generation (4 bytes))
2318 + + return value of exportfs_encode_fh() for the parent on a branch (4
2320 + + file handle for a branch (by exportfs_encode_fh())
2322 + + find the index of a branch from its id in handle, and check it is
2323 + still exist in aufs.
2324 + + 1st level: get the inode number from handle and search it in cache.
2325 + + 2nd level: if not found in cache, get the parent inode number from
2326 + the handle and search it in cache. and then open the found parent
2327 + dir, find the matching inode number by vfs_readdir() and get its
2328 + name, and call lookup_one_len() for the target dentry.
2329 + + 3rd level: if the parent dir is not cached, call
2330 + exportfs_decode_fh() for a branch and get the parent on a branch,
2331 + build a pathname of it, convert it a pathname in aufs, call
2332 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2334 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2335 + for every branch, but not itself. to get this, (currently) aufs
2336 + searches in current->nsproxy->mnt_ns list. it may not be a good
2337 + idea, but I didn't get other approach.
2338 + + test the generation of the gotten inode.
2339 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2340 + convert it into ESTALE for NFSD.
2341 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2342 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2343 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2344 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2345 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2021-12-03 15:38:59.929980643 +0100
2348 +# Copyright (C) 2005-2021 Junjiro R. Okajima
2350 +# This program is free software; you can redistribute it and/or modify
2351 +# it under the terms of the GNU General Public License as published by
2352 +# the Free Software Foundation; either version 2 of the License, or
2353 +# (at your option) any later version.
2355 +# This program is distributed in the hope that it will be useful,
2356 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2357 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2358 +# GNU General Public License for more details.
2360 +# You should have received a copy of the GNU General Public License
2361 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2363 +Show Whiteout Mode (shwh)
2364 +----------------------------------------------------------------------
2365 +Generally aufs hides the name of whiteouts. But in some cases, to show
2366 +them is very useful for users. For instance, creating a new middle layer
2367 +(branch) by merging existing layers.
2369 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2370 +When you have three branches,
2371 +- Bottom: 'system', squashfs (underlying base system), read-only
2372 +- Middle: 'mods', squashfs, read-only
2373 +- Top: 'overlay', ram (tmpfs), read-write
2375 +The top layer is loaded at boot time and saved at shutdown, to preserve
2376 +the changes made to the system during the session.
2377 +When larger changes have been made, or smaller changes have accumulated,
2378 +the size of the saved top layer data grows. At this point, it would be
2379 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2380 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2381 +restoring save and load speed.
2383 +This merging is simplified by the use of another aufs mount, of just the
2384 +two overlay branches using the 'shwh' option.
2385 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2386 + aufs /livesys/merge_union
2388 +A merged view of these two branches is then available at
2389 +/livesys/merge_union, and the new feature is that the whiteouts are
2391 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2392 +writing to all branches. Also the default mode for all branches is 'ro'.
2393 +It is now possible to save the combined contents of the two overlay
2394 +branches to a new squashfs, e.g.:
2395 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2397 +This new squashfs archive can be stored on the boot device and the
2398 +initramfs will use it to replace the old one at the next boot.
2399 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2400 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2401 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2021-12-03 15:38:59.929980643 +0100
2404 +# Copyright (C) 2010-2021 Junjiro R. Okajima
2406 +# This program is free software; you can redistribute it and/or modify
2407 +# it under the terms of the GNU General Public License as published by
2408 +# the Free Software Foundation; either version 2 of the License, or
2409 +# (at your option) any later version.
2411 +# This program is distributed in the hope that it will be useful,
2412 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2413 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2414 +# GNU General Public License for more details.
2416 +# You should have received a copy of the GNU General Public License
2417 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2419 +Dynamically customizable FS operations
2420 +----------------------------------------------------------------------
2421 +Generally FS operations (struct inode_operations, struct
2422 +address_space_operations, struct file_operations, etc.) are defined as
2423 +"static const", but it never means that FS have only one set of
2424 +operation. Some FS have multiple sets of them. For instance, ext2 has
2425 +three sets, one for XIP, for NOBH, and for normal.
2426 +Since aufs overrides and redirects these operations, sometimes aufs has
2427 +to change its behaviour according to the branch FS type. More importantly
2428 +VFS acts differently if a function (member in the struct) is set or
2429 +not. It means aufs should have several sets of operations and select one
2430 +among them according to the branch FS definition.
2432 +In order to solve this problem and not to affect the behaviour of VFS,
2433 +aufs defines these operations dynamically. For instance, aufs defines
2434 +dummy direct_IO function for struct address_space_operations, but it may
2435 +not be set to the address_space_operations actually. When the branch FS
2436 +doesn't have it, aufs doesn't set it to its address_space_operations
2437 +while the function definition itself is still alive. So the behaviour
2438 +itself will not change, and it will return an error when direct_IO is
2441 +The lifetime of these dynamically generated operation object is
2442 +maintained by aufs branch object. When the branch is removed from aufs,
2443 +the reference counter of the object is decremented. When it reaches
2444 +zero, the dynamically generated operation object will be freed.
2446 +This approach is designed to support AIO (io_submit), Direct I/O and
2448 +Currently this approach is applied to address_space_operations for
2449 +regular files only.
2450 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2451 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2452 +++ linux/Documentation/filesystems/aufs/README 2021-12-03 15:38:59.929980643 +0100
2455 +Aufs5 -- advanced multi layered unification filesystem version 5.x
2461 +----------------------------------------
2462 +In the early days, aufs was entirely re-designed and re-implemented
2463 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2464 +improvements and implementations, it became totally different from
2465 +Unionfs while keeping the basic features.
2466 +Later, Unionfs Version 2.x series began taking some of the same
2467 +approaches to aufs1's.
2468 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2469 +University and his team.
2471 +Aufs5 supports linux-v5.0 and later, If you want older kernel version
2473 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2474 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2475 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2476 + or aufs1 from CVS on SourceForge.
2478 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2479 + According to Christoph Hellwig, linux rejects all union-type
2480 + filesystems but UnionMount.
2481 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2483 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2484 + UnionMount, and he pointed out an issue around a directory mutex
2485 + lock and aufs addressed it. But it is still unsure whether aufs will
2486 + be merged (or any other union solution).
2487 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2491 +----------------------------------------
2492 +- unite several directories into a single virtual filesystem. The member
2493 + directory is called as a branch.
2494 +- you can specify the permission flags to the branch, which are 'readonly',
2495 + 'readwrite' and 'whiteout-able.'
2496 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2497 + readonly branch are modifiable logically.
2498 +- dynamic branch manipulation, add, del.
2501 +Also there are many enhancements in aufs, such as:
2502 +- test only the highest one for the directory permission (dirperm1)
2503 +- copyup on open (coo=)
2504 +- 'move' policy for copy-up between two writable branches, after
2505 + checking free space.
2507 +- readdir(3) in userspace.
2508 +- keep inode number by external inode number table
2509 +- keep the timestamps of file/dir in internal copyup operation
2510 +- seekable directory, supporting NFS readdir.
2511 +- whiteout is hardlinked in order to reduce the consumption of inodes
2513 +- do not copyup, nor create a whiteout when it is unnecessary
2514 +- revert a single systemcall when an error occurs in aufs
2515 +- remount interface instead of ioctl
2516 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2517 +- loopback mounted filesystem as a branch
2518 +- kernel thread for removing the dir who has a plenty of whiteouts
2519 +- support copyup sparse file (a file which has a 'hole' in it)
2520 +- default permission flags for branches
2521 +- selectable permission flags for ro branch, whether whiteout can
2524 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2525 +- support multiple writable branches, some policies to select one
2526 + among multiple writable branches.
2527 +- a new semantics for link(2) and rename(2) to support multiple
2528 + writable branches.
2529 +- no glibc changes are required.
2530 +- pseudo hardlink (hardlink over branches)
2531 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2532 + including NFS or remote filesystem branch.
2533 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2536 +Currently these features are dropped temporary from aufs5.
2537 +See design/08plan.txt in detail.
2538 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2540 +- statistics of aufs thread (/sys/fs/aufs/stat)
2542 +Features or just an idea in the future (see also design/*.txt),
2543 +- reorder the branch index without del/re-add.
2544 +- permanent xino files for NFSD
2545 +- an option for refreshing the opened files after add/del branches
2546 +- light version, without branch manipulation. (unnecessary?)
2547 +- copyup in userspace
2548 +- inotify in userspace
2553 +----------------------------------------
2554 +There are three GIT trees for aufs5, aufs5-linux.git,
2555 +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in
2557 +While the aufs-util is always necessary, you need either of aufs5-linux
2558 +or aufs5-standalone.
2560 +The aufs5-linux tree includes the whole linux mainline GIT tree,
2561 +git://git.kernel.org/.../torvalds/linux.git.
2562 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2563 +build aufs5 as an external kernel module.
2564 +Several extra patches are not included in this tree. Only
2565 +aufs5-standalone tree contains them. They are described in the later
2566 +section "Configuration and Compilation."
2568 +On the other hand, the aufs5-standalone tree has only aufs source files
2569 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2570 +But you need to apply all aufs patches manually.
2572 +You will find GIT branches whose name is in form of "aufs5.x" where "x"
2573 +represents the linux kernel version, "linux-5.x". For instance,
2574 +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use
2575 +"aufs5.x-rcN" branch.
2578 +$ git clone --reference /your/linux/git/tree \
2579 + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git
2580 +- if you don't have linux GIT tree, then remove "--reference ..."
2581 +$ cd aufs5-linux.git
2582 +$ git checkout origin/aufs5.0
2584 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2585 +leave the patch-work to GIT.
2586 +$ cd /your/linux/git/tree
2587 +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git
2589 +$ git checkout -b my5.0 v5.0
2590 +$ (add your local change...)
2591 +$ git pull aufs5 aufs5.0
2592 +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch.
2593 +- you may need to solve some conflicts between your_changes and
2594 + aufs5.0. in this case, git-rerere is recommended so that you can
2595 + solve the similar conflicts automatically when you upgrade to 5.1 or
2596 + later in the future.
2598 +o aufs5-standalone tree
2599 +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git
2600 +$ cd aufs5-standalone.git
2601 +$ git checkout origin/aufs5.0
2604 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2605 +- note that the public aufs-util.git is on SourceForge instead of
2608 +$ git checkout origin/aufs5.0
2610 +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY.
2611 +The minor version number, 'x' in '5.x', of aufs may not always
2612 +follow the minor version number of the kernel.
2613 +Because changes in the kernel that cause the use of a new
2614 +minor version number do not always require changes to aufs-util.
2616 +Since aufs-util has its own minor version number, you may not be
2617 +able to find a GIT branch in aufs-util for your kernel's
2618 +exact minor version number.
2619 +In this case, you should git-checkout the branch for the
2620 +nearest lower number.
2622 +For (an unreleased) example:
2623 +If you are using "linux-5.10" and the "aufs5.10" branch
2624 +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8"
2625 +or something numerically smaller is the branch for your kernel.
2627 +Also you can view all branches by
2631 +3. Configuration and Compilation
2632 +----------------------------------------
2633 +Make sure you have git-checkout'ed the correct branch.
2635 +For aufs5-linux tree,
2636 +- enable CONFIG_AUFS_FS.
2637 +- set other aufs configurations if necessary.
2639 +For aufs5-standalone tree,
2640 +There are several ways to build.
2643 +- apply ./aufs5-kbuild.patch to your kernel source files.
2644 +- apply ./aufs5-base.patch too.
2645 +- apply ./aufs5-mmap.patch too.
2646 +- apply ./aufs5-standalone.patch too, if you have a plan to set
2647 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch.
2648 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2649 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2650 +- enable CONFIG_AUFS_FS, you can select either
2652 +- and build your kernel as usual.
2653 +- install the built kernel.
2654 +- install the header files too by "make headers_install" to the
2655 + directory where you specify. By default, it is $PWD/usr.
2656 + "make help" shows a brief note for headers_install.
2657 +- and reboot your system.
2660 +- module only (CONFIG_AUFS_FS=m).
2661 +- apply ./aufs5-base.patch to your kernel source files.
2662 +- apply ./aufs5-mmap.patch too.
2663 +- apply ./aufs5-standalone.patch too.
2664 +- build your kernel, don't forget "make headers_install", and reboot.
2665 +- edit ./config.mk and set other aufs configurations if necessary.
2666 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2667 + every aufs configurations.
2668 +- build the module by simple "make".
2669 +- you can specify ${KDIR} make variable which points to your kernel
2671 +- install the files
2672 + + run "make install" to install the aufs module, or copy the built
2673 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2674 + + run "make install_headers" (instead of headers_install) to install
2675 + the modified aufs header file (you can specify DESTDIR which is
2676 + available in aufs standalone version's Makefile only), or copy
2677 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2678 + you like manually. By default, the target directory is $PWD/usr.
2679 +- no need to apply aufs5-kbuild.patch, nor copying source files to your
2680 + kernel source tree.
2682 +Note: The header file aufs_type.h is necessary to build aufs-util
2683 + as well as "make headers_install" in the kernel source tree.
2684 + headers_install is subject to be forgotten, but it is essentially
2685 + necessary, not only for building aufs-util.
2686 + You may not meet problems without headers_install in some older
2690 +- read README in aufs-util, build and install it
2691 +- note that your distribution may contain an obsoleted version of
2692 + aufs_type.h in /usr/include/linux or something. When you build aufs
2693 + utilities, make sure that your compiler refers the correct aufs header
2694 + file which is built by "make headers_install."
2695 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2696 + then run "make install_ulib" too. And refer to the aufs manual in
2699 +There several other patches in aufs5-standalone.git. They are all
2700 +optional. When you meet some problems, they will help you.
2701 +- aufs5-loopback.patch
2702 + Supports a nested loopback mount in a branch-fs. This patch is
2703 + unnecessary until aufs produces a message like "you may want to try
2704 + another patch for loopback file".
2706 + Modifies a system global kernel internal function get_next_ino() in
2707 + order to stop assigning 0 for an inode-number. Not directly related to
2708 + aufs, but recommended generally.
2710 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2711 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2712 + duplication of inode number, which is important for backup tools and
2713 + other utilities. When you find aufs XINO files for tmpfs branch
2714 + growing too much, try this patch.
2715 +- lockdep-debug.patch
2716 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2717 + also a caller of VFS functions for branch filesystems, subclassing of
2718 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2719 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2720 + need to apply this debug patch to expand several constant values.
2721 + If you don't know what LOCKDEP is, then you don't have apply this
2726 +----------------------------------------
2727 +At first, make sure aufs-util are installed, and please read the aufs
2728 +manual, aufs.5 in aufs-util.git tree.
2732 +$ mkdir /tmp/rw /tmp/aufs
2733 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2735 +Here is another example. The result is equivalent.
2736 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2738 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2739 +# mount -o remount,append:${HOME} /tmp/aufs
2741 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2742 +you modify a file under /tmp/aufs, the one on your home directory is
2743 +not affected, instead the same named file will be newly created under
2744 +/tmp/rw. And all of your modification to a file will be applied to
2745 +the one under /tmp/rw. This is called the file based Copy on Write
2747 +Aufs mount options are described in aufs.5.
2748 +If you run chroot or something and make your aufs as a root directory,
2749 +then you need to customize the shutdown script. See the aufs manual in
2752 +Additionally, there are some sample usages of aufs which are a
2753 +diskless system with network booting, and LiveCD over NFS.
2754 +See sample dir in CVS tree on SourceForge.
2758 +----------------------------------------
2759 +When you have any problems or strange behaviour in aufs, please let me
2761 +- /proc/mounts (instead of the output of mount(8))
2762 +- /sys/module/aufs/*
2763 +- /sys/fs/aufs/* (if you have them)
2764 +- /debug/aufs/* (if you have them)
2765 +- linux kernel version
2766 + if your kernel is not plain, for example modified by distributor,
2767 + the url where i can download its source is necessary too.
2768 +- aufs version which was printed at loading the module or booting the
2769 + system, instead of the date you downloaded.
2770 +- configuration (define/undefine CONFIG_AUFS_xxx)
2771 +- kernel configuration or /proc/config.gz (if you have it)
2772 +- LSM (linux security module, if you are using)
2773 +- behaviour which you think to be incorrect
2774 +- actual operation, reproducible one is better
2775 +- mailto: aufs-users at lists.sourceforge.net
2777 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2778 +and Feature Requests) on SourceForge. Please join and write to
2782 +6. Acknowledgements
2783 +----------------------------------------
2784 +Thanks to everyone who have tried and are using aufs, whoever
2785 +have reported a bug or any feedback.
2787 +Especially donators:
2788 +Tomas Matejicek(slax.org) made a donation (much more than once).
2789 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2790 + scripts) is making "doubling" donations.
2791 + Unfortunately I cannot list all of the donators, but I really
2793 + It ends Aug 2010, but the ordinary donation URL is still available.
2794 + <http://sourceforge.net/donate/index.php?group_id=167503>
2795 +Dai Itasaka made a donation (2007/8).
2796 +Chuck Smith made a donation (2008/4, 10 and 12).
2797 +Henk Schoneveld made a donation (2008/9).
2798 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2799 +Francois Dupoux made a donation (2008/11).
2800 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2801 + aufs2 GIT tree (2009/2).
2802 +William Grant made a donation (2009/3).
2803 +Patrick Lane made a donation (2009/4).
2804 +The Mail Archive (mail-archive.com) made donations (2009/5).
2805 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2806 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2807 +Pavel Pronskiy made a donation (2011/2).
2808 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2809 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2810 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2812 +Sam Liddicott made a donation (2011/9).
2813 +Era Scarecrow made a donation (2013/4).
2814 +Bor Ratajc made a donation (2013/4).
2815 +Alessandro Gorreta made a donation (2013/4).
2816 +POIRETTE Marc made a donation (2013/4).
2817 +Alessandro Gorreta made a donation (2013/4).
2818 +lauri kasvandik made a donation (2013/5).
2819 +"pemasu from Finland" made a donation (2013/7).
2820 +The Parted Magic Project made a donation (2013/9 and 11).
2821 +Pavel Barta made a donation (2013/10).
2822 +Nikolay Pertsev made a donation (2014/5).
2823 +James B made a donation (2014/7 and 2015/7).
2824 +Stefano Di Biase made a donation (2014/8).
2825 +Daniel Epellei made a donation (2015/1).
2826 +OmegaPhil made a donation (2016/1, 2018/4).
2827 +Tomasz Szewczyk made a donation (2016/4).
2828 +James Burry made a donation (2016/12).
2829 +Carsten Rose made a donation (2018/9).
2830 +Porteus Kiosk made a donation (2018/10).
2832 +Thank you very much.
2833 +Donations are always, including future donations, very important and
2834 +helpful for me to keep on developing aufs.
2838 +----------------------------------------
2839 +If you are an experienced user, no explanation is needed. Aufs is
2840 +just a linux filesystem.
2845 +# Local variables: ;
2848 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2849 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2850 +++ linux/fs/aufs/aufs.h 2021-12-03 15:38:59.929980643 +0100
2852 +/* SPDX-License-Identifier: GPL-2.0 */
2854 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2856 + * This program, aufs is free software; you can redistribute it and/or modify
2857 + * it under the terms of the GNU General Public License as published by
2858 + * the Free Software Foundation; either version 2 of the License, or
2859 + * (at your option) any later version.
2861 + * This program is distributed in the hope that it will be useful,
2862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2864 + * GNU General Public License for more details.
2866 + * You should have received a copy of the GNU General Public License
2867 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2871 + * all header files
2879 +#define AuStub(type, name, body, ...) \
2880 + static inline type name(__VA_ARGS__) { body; }
2882 +#define AuStubVoid(name, ...) \
2883 + AuStub(void, name, , __VA_ARGS__)
2884 +#define AuStubInt0(name, ...) \
2885 + AuStub(int, name, return 0, __VA_ARGS__)
2889 +#include "branch.h"
2892 +#include "dbgaufs.h"
2893 +#include "dentry.h"
2895 +#include "dirren.h"
2898 +#include "fstype.h"
2903 +#include "module.h"
2907 +#include "sysaufs.h"
2912 +#endif /* __KERNEL__ */
2913 +#endif /* __AUFS_H__ */
2914 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2915 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2916 +++ linux/fs/aufs/branch.c 2021-12-03 15:38:59.933313976 +0100
2918 +// SPDX-License-Identifier: GPL-2.0
2920 + * Copyright (C) 2005-2021 Junjiro R. Okajima
2922 + * This program, aufs is free software; you can redistribute it and/or modify
2923 + * it under the terms of the GNU General Public License as published by
2924 + * the Free Software Foundation; either version 2 of the License, or
2925 + * (at your option) any later version.
2927 + * This program is distributed in the hope that it will be useful,
2928 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2929 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2930 + * GNU General Public License for more details.
2932 + * You should have received a copy of the GNU General Public License
2933 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2937 + * branch management
2940 +#include <linux/compat.h>
2941 +#include <linux/statfs.h>
2945 + * free a single branch
2947 +static void au_br_do_free(struct au_branch *br)
2950 + struct au_wbr *wbr;
2951 + struct au_dykey **key;
2953 + au_hnotify_fin_br(br);
2954 + /* always, regardless the mount option */
2955 + au_dr_hino_free(&br->br_dirren);
2958 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2959 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2960 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2961 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2965 + for (i = 0; i < AuBrWh_Last; i++)
2966 + dput(wbr->wbr_wh[i]);
2967 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2968 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2971 + if (br->br_fhsm) {
2972 + au_br_fhsm_fin(br->br_fhsm);
2973 + au_kfree_try_rcu(br->br_fhsm);
2976 + key = br->br_dykey;
2977 + for (i = 0; i < AuBrDynOp; i++, key++)
2983 + /* recursive lock, s_umount of branch's */
2984 + /* synchronize_rcu(); */ /* why? */
2986 + path_put(&br->br_path);
2988 + au_kfree_rcu(wbr);
2989 + au_lcnt_wait_for_fin(&br->br_nfiles);
2990 + au_lcnt_wait_for_fin(&br->br_count);
2991 + /* I don't know why, but percpu_refcount requires this */
2992 + /* synchronize_rcu(); */
2997 + * frees all branches
2999 +void au_br_free(struct au_sbinfo *sbinfo)
3001 + aufs_bindex_t bmax;
3002 + struct au_branch **br;
3004 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3006 + bmax = sbinfo->si_bbot + 1;
3007 + br = sbinfo->si_branch;
3009 + au_br_do_free(*br++);
3013 + * find the index of a branch which is specified by @br_id.
3015 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3017 + aufs_bindex_t bindex, bbot;
3019 + bbot = au_sbbot(sb);
3020 + for (bindex = 0; bindex <= bbot; bindex++)
3021 + if (au_sbr_id(sb, bindex) == br_id)
3026 +/* ---------------------------------------------------------------------- */
3032 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3033 + struct dentry *h_root)
3035 + if (unlikely(h_adding == h_root
3036 + || au_test_loopback_overlap(sb, h_adding)))
3038 + if (h_adding->d_sb != h_root->d_sb)
3040 + return au_test_subdir(h_adding, h_root)
3041 + || au_test_subdir(h_root, h_adding);
3045 + * returns a newly allocated branch. @new_nbranch is a number of branches
3046 + * after adding a branch.
3048 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3051 + struct au_branch *add_branch;
3052 + struct dentry *root;
3053 + struct inode *inode;
3057 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3058 + if (unlikely(!add_branch))
3060 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3061 + if (unlikely(!add_branch->br_xino))
3063 + err = au_hnotify_init_br(add_branch, perm);
3064 + if (unlikely(err))
3067 + if (au_br_writable(perm)) {
3068 + /* may be freed separately at changing the branch permission */
3069 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3071 + if (unlikely(!add_branch->br_wbr))
3075 + if (au_br_fhsm(perm)) {
3076 + err = au_fhsm_br_alloc(add_branch);
3077 + if (unlikely(err))
3081 + root = sb->s_root;
3082 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3084 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3086 + inode = d_inode(root);
3087 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3091 + return add_branch; /* success */
3094 + au_kfree_rcu(add_branch->br_wbr);
3096 + au_hnotify_fin_br(add_branch);
3098 + au_xino_put(add_branch);
3100 + au_kfree_rcu(add_branch);
3102 + return ERR_PTR(err);
3106 + * test if the branch permission is legal or not.
3108 +static int test_br(struct inode *inode, int brperm, char *path)
3112 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3117 + pr_err("write permission for readonly mount or inode, %s\n", path);
3125 + * 0: success, the caller will add it
3126 + * plus: success, it is already unified, the caller should ignore it
3129 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3132 + aufs_bindex_t bbot, bindex;
3133 + struct dentry *root, *h_dentry;
3134 + struct inode *inode, *h_inode;
3136 + root = sb->s_root;
3137 + bbot = au_sbbot(sb);
3138 + if (unlikely(bbot >= 0
3139 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3143 + pr_err("%s duplicated\n", add->pathname);
3148 + err = -ENOSPC; /* -E2BIG; */
3149 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3150 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3151 + pr_err("number of branches exceeded %s\n", add->pathname);
3156 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3157 + pr_err("bad index %d\n", add->bindex);
3161 + inode = d_inode(add->path.dentry);
3163 + if (unlikely(!inode->i_nlink)) {
3164 + pr_err("no existence %s\n", add->pathname);
3169 + if (unlikely(inode->i_sb == sb)) {
3170 + pr_err("%s must be outside\n", add->pathname);
3174 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3175 + pr_err("unsupported filesystem, %s (%s)\n",
3176 + add->pathname, au_sbtype(inode->i_sb));
3180 + if (unlikely(inode->i_sb->s_stack_depth)) {
3181 + pr_err("already stacked, %s (%s)\n",
3182 + add->pathname, au_sbtype(inode->i_sb));
3186 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3187 + if (unlikely(err))
3191 + return 0; /* success */
3194 + for (bindex = 0; bindex <= bbot; bindex++)
3195 + if (unlikely(test_overlap(sb, add->path.dentry,
3196 + au_h_dptr(root, bindex)))) {
3197 + pr_err("%s is overlapped\n", add->pathname);
3202 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3203 + h_dentry = au_h_dptr(root, 0);
3204 + h_inode = d_inode(h_dentry);
3205 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3206 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3207 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3208 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3210 + i_uid_read(inode), i_gid_read(inode),
3211 + (inode->i_mode & S_IALLUGO),
3212 + i_uid_read(h_inode), i_gid_read(h_inode),
3213 + (h_inode->i_mode & S_IALLUGO));
3221 + * initialize or clean the whiteouts for an adding branch
3223 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3226 + int err, old_perm;
3227 + aufs_bindex_t bindex;
3228 + struct inode *h_inode;
3229 + struct au_wbr *wbr;
3230 + struct au_hinode *hdir;
3231 + struct dentry *h_dentry;
3233 + err = vfsub_mnt_want_write(au_br_mnt(br));
3234 + if (unlikely(err))
3238 + old_perm = br->br_perm;
3239 + br->br_perm = new_perm;
3242 + bindex = au_br_index(sb, br->br_id);
3243 + if (0 <= bindex) {
3244 + hdir = au_hi(d_inode(sb->s_root), bindex);
3245 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3247 + h_dentry = au_br_dentry(br);
3248 + h_inode = d_inode(h_dentry);
3249 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3252 + err = au_wh_init(br, sb);
3254 + wbr_wh_write_lock(wbr);
3255 + err = au_wh_init(br, sb);
3256 + wbr_wh_write_unlock(wbr);
3259 + au_hn_inode_unlock(hdir);
3261 + inode_unlock(h_inode);
3262 + vfsub_mnt_drop_write(au_br_mnt(br));
3263 + br->br_perm = old_perm;
3265 + if (!err && wbr && !au_br_writable(new_perm)) {
3266 + au_kfree_rcu(wbr);
3267 + br->br_wbr = NULL;
3274 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3278 + struct kstatfs kst;
3279 + struct au_wbr *wbr;
3282 + au_rw_init(&wbr->wbr_wh_rwsem);
3283 + atomic_set(&wbr->wbr_wh_running, 0);
3286 + * a limit for rmdir/rename a dir
3287 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3289 + err = vfs_statfs(&br->br_path, &kst);
3290 + if (unlikely(err))
3293 + if (kst.f_namelen >= NAME_MAX)
3294 + err = au_br_init_wh(sb, br, perm);
3296 + pr_err("%pd(%s), unsupported namelen %ld\n",
3298 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3304 +/* initialize a new branch */
3305 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3306 + struct au_opt_add *add)
3309 + struct au_branch *brbase;
3311 + struct inode *h_inode;
3314 + br->br_perm = add->perm;
3315 + br->br_path = add->path; /* set first, path_get() later */
3316 + spin_lock_init(&br->br_dykey_lock);
3317 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3318 + au_lcnt_init(&br->br_count, /*release*/NULL);
3319 + br->br_id = au_new_br_id(sb);
3320 + AuDebugOn(br->br_id < 0);
3322 + /* always, regardless the given option */
3323 + err = au_dr_br_init(sb, br, &add->path);
3324 + if (unlikely(err))
3327 + if (au_br_writable(add->perm)) {
3328 + err = au_wbr_init(br, sb, add->perm);
3329 + if (unlikely(err))
3333 + if (au_opt_test(au_mntflags(sb), XINO)) {
3334 + brbase = au_sbr(sb, 0);
3335 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3337 + h_inode = d_inode(add->path.dentry);
3338 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3339 + if (unlikely(err)) {
3340 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3345 + sysaufs_br_init(br);
3346 + path_get(&br->br_path);
3347 + goto out; /* success */
3350 + memset(&br->br_path, 0, sizeof(br->br_path));
3355 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3356 + struct au_branch *br, aufs_bindex_t bbot,
3357 + aufs_bindex_t amount)
3359 + struct au_branch **brp;
3361 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3363 + brp = sbinfo->si_branch + bindex;
3364 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3366 + sbinfo->si_bbot++;
3367 + if (unlikely(bbot < 0))
3368 + sbinfo->si_bbot = 0;
3371 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3372 + aufs_bindex_t bbot, aufs_bindex_t amount)
3374 + struct au_hdentry *hdp;
3376 + AuRwMustWriteLock(&dinfo->di_rwsem);
3378 + hdp = au_hdentry(dinfo, bindex);
3379 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3380 + au_h_dentry_init(hdp);
3382 + if (unlikely(bbot < 0))
3383 + dinfo->di_btop = 0;
3386 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3387 + aufs_bindex_t bbot, aufs_bindex_t amount)
3389 + struct au_hinode *hip;
3391 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3393 + hip = au_hinode(iinfo, bindex);
3394 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3395 + au_hinode_init(hip);
3397 + if (unlikely(bbot < 0))
3398 + iinfo->ii_btop = 0;
3401 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3402 + aufs_bindex_t bindex)
3404 + struct dentry *root, *h_dentry;
3405 + struct inode *root_inode, *h_inode;
3406 + aufs_bindex_t bbot, amount;
3408 + root = sb->s_root;
3409 + root_inode = d_inode(root);
3410 + bbot = au_sbbot(sb);
3411 + amount = bbot + 1 - bindex;
3412 + h_dentry = au_br_dentry(br);
3413 + au_sbilist_lock();
3414 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3415 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3416 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3417 + au_set_h_dptr(root, bindex, dget(h_dentry));
3418 + h_inode = d_inode(h_dentry);
3419 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3420 + au_sbilist_unlock();
3423 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3426 + aufs_bindex_t bbot, add_bindex;
3427 + struct dentry *root, *h_dentry;
3428 + struct inode *root_inode;
3429 + struct au_branch *add_branch;
3431 + root = sb->s_root;
3432 + root_inode = d_inode(root);
3433 + IMustLock(root_inode);
3434 + IiMustWriteLock(root_inode);
3435 + err = test_add(sb, add, remount);
3436 + if (unlikely(err < 0))
3440 + goto out; /* success */
3443 + bbot = au_sbbot(sb);
3444 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3445 + err = PTR_ERR(add_branch);
3446 + if (IS_ERR(add_branch))
3449 + err = au_br_init(add_branch, sb, add);
3450 + if (unlikely(err)) {
3451 + au_br_do_free(add_branch);
3455 + add_bindex = add->bindex;
3456 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3457 + au_br_do_add(sb, add_branch, add_bindex);
3458 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3459 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3461 + h_dentry = add->path.dentry;
3462 + if (!add_bindex) {
3463 + au_cpup_attr_all(root_inode, /*force*/1);
3464 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3466 + au_add_nlink(root_inode, d_inode(h_dentry));
3472 +/* ---------------------------------------------------------------------- */
3474 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3475 + unsigned long long max __maybe_unused,
3478 + unsigned long long n;
3479 + struct file **p, *f;
3480 + struct hlist_bl_head *files;
3481 + struct hlist_bl_node *pos;
3482 + struct au_finfo *finfo;
3486 + files = &au_sbi(sb)->si_files;
3487 + hlist_bl_lock(files);
3488 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3489 + f = finfo->fi_file;
3491 + && !special_file(file_inode(f)->i_mode)) {
3495 + AuDebugOn(n > max);
3498 + hlist_bl_unlock(files);
3503 +static struct file **au_farray_alloc(struct super_block *sb,
3504 + unsigned long long *max)
3506 + struct au_sbinfo *sbi;
3509 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3510 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3513 +static void au_farray_free(struct file **a, unsigned long long max)
3515 + unsigned long long ull;
3517 + for (ull = 0; ull < max; ull++)
3523 +/* ---------------------------------------------------------------------- */
3529 +/* to show the line number, do not make it inlined function */
3530 +#define AuVerbose(do_info, fmt, ...) do { \
3532 + pr_info(fmt, ##__VA_ARGS__); \
3535 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3536 + aufs_bindex_t bbot)
3538 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3541 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3542 + aufs_bindex_t bbot)
3544 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3548 + * test if the branch is deletable or not.
3550 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3551 + unsigned int sigen, const unsigned int verbose)
3553 + int err, i, j, ndentry;
3554 + aufs_bindex_t btop, bbot;
3555 + struct au_dcsub_pages dpages;
3556 + struct au_dpage *dpage;
3559 + err = au_dpages_init(&dpages, GFP_NOFS);
3560 + if (unlikely(err))
3562 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3563 + if (unlikely(err))
3566 + for (i = 0; !err && i < dpages.ndpage; i++) {
3567 + dpage = dpages.dpages + i;
3568 + ndentry = dpage->ndentry;
3569 + for (j = 0; !err && j < ndentry; j++) {
3570 + d = dpage->dentries[j];
3571 + AuDebugOn(au_dcount(d) <= 0);
3572 + if (!au_digen_test(d, sigen)) {
3573 + di_read_lock_child(d, AuLock_IR);
3574 + if (unlikely(au_dbrange_test(d))) {
3575 + di_read_unlock(d, AuLock_IR);
3579 + di_write_lock_child(d);
3580 + if (unlikely(au_dbrange_test(d))) {
3581 + di_write_unlock(d);
3584 + err = au_reval_dpath(d, sigen);
3586 + di_downgrade_lock(d, AuLock_IR);
3588 + di_write_unlock(d);
3593 + /* AuDbgDentry(d); */
3594 + btop = au_dbtop(d);
3595 + bbot = au_dbbot(d);
3596 + if (btop <= bindex
3598 + && au_h_dptr(d, bindex)
3599 + && au_test_dbusy(d, btop, bbot)) {
3601 + AuVerbose(verbose, "busy %pd\n", d);
3604 + di_read_unlock(d, AuLock_IR);
3609 + au_dpages_free(&dpages);
3614 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3615 + unsigned int sigen, const unsigned int verbose)
3618 + unsigned long long max, ull;
3619 + struct inode *i, **array;
3620 + aufs_bindex_t btop, bbot;
3622 + array = au_iarray_alloc(sb, &max);
3623 + err = PTR_ERR(array);
3624 + if (IS_ERR(array))
3628 + AuDbg("b%d\n", bindex);
3629 + for (ull = 0; !err && ull < max; ull++) {
3633 + if (i->i_ino == AUFS_ROOT_INO)
3636 + /* AuDbgInode(i); */
3637 + if (au_iigen(i, NULL) == sigen)
3638 + ii_read_lock_child(i);
3640 + ii_write_lock_child(i);
3641 + err = au_refresh_hinode_self(i);
3644 + ii_downgrade_lock(i);
3646 + ii_write_unlock(i);
3651 + btop = au_ibtop(i);
3652 + bbot = au_ibbot(i);
3653 + if (btop <= bindex
3655 + && au_h_iptr(i, bindex)
3656 + && au_test_ibusy(i, btop, bbot)) {
3658 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3661 + ii_read_unlock(i);
3663 + au_iarray_free(array, max);
3669 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3670 + const unsigned int verbose)
3673 + unsigned int sigen;
3675 + sigen = au_sigen(root->d_sb);
3676 + DiMustNoWaiters(root);
3677 + IiMustNoWaiters(d_inode(root));
3678 + di_write_unlock(root);
3679 + err = test_dentry_busy(root, bindex, sigen, verbose);
3681 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3682 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3687 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3688 + struct file **to_free, int *idx)
3691 + unsigned char matched, root;
3692 + aufs_bindex_t bindex, bbot;
3693 + struct au_fidir *fidir;
3694 + struct au_hfile *hfile;
3697 + root = IS_ROOT(file->f_path.dentry);
3700 + to_free[*idx] = file;
3706 + fidir = au_fi(file)->fi_hdir;
3707 + AuDebugOn(!fidir);
3708 + bbot = au_fbbot_dir(file);
3709 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3710 + hfile = fidir->fd_hfile + bindex;
3711 + if (!hfile->hf_file)
3714 + if (hfile->hf_br->br_id == br_id) {
3726 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3727 + struct file **to_free, int opened)
3730 + unsigned long long ull, max;
3731 + aufs_bindex_t btop;
3732 + struct file *file, **array;
3733 + struct dentry *root;
3734 + struct au_hfile *hfile;
3736 + array = au_farray_alloc(sb, &max);
3737 + err = PTR_ERR(array);
3738 + if (IS_ERR(array))
3743 + root = sb->s_root;
3744 + di_write_unlock(root);
3745 + for (ull = 0; ull < max; ull++) {
3746 + file = array[ull];
3747 + if (unlikely(!file))
3750 + /* AuDbg("%pD\n", file); */
3751 + fi_read_lock(file);
3752 + btop = au_fbtop(file);
3753 + if (!d_is_dir(file->f_path.dentry)) {
3754 + hfile = &au_fi(file)->fi_htop;
3755 + if (hfile->hf_br->br_id == br_id)
3758 + err = test_dir_busy(file, br_id, to_free, &idx);
3759 + fi_read_unlock(file);
3760 + if (unlikely(err))
3763 + di_write_lock_child(root);
3764 + au_farray_free(array, max);
3765 + AuDebugOn(idx > opened);
3771 +static void br_del_file(struct file **to_free, unsigned long long opened,
3772 + aufs_bindex_t br_id)
3774 + unsigned long long ull;
3775 + aufs_bindex_t bindex, btop, bbot, bfound;
3776 + struct file *file;
3777 + struct au_fidir *fidir;
3778 + struct au_hfile *hfile;
3780 + for (ull = 0; ull < opened; ull++) {
3781 + file = to_free[ull];
3782 + if (unlikely(!file))
3785 + /* AuDbg("%pD\n", file); */
3786 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3788 + fidir = au_fi(file)->fi_hdir;
3789 + AuDebugOn(!fidir);
3790 + fi_write_lock(file);
3791 + btop = au_fbtop(file);
3792 + bbot = au_fbbot_dir(file);
3793 + for (bindex = btop; bindex <= bbot; bindex++) {
3794 + hfile = fidir->fd_hfile + bindex;
3795 + if (!hfile->hf_file)
3798 + if (hfile->hf_br->br_id == br_id) {
3803 + AuDebugOn(bfound < 0);
3804 + au_set_h_fptr(file, bfound, NULL);
3805 + if (bfound == btop) {
3806 + for (btop++; btop <= bbot; btop++)
3807 + if (au_hf_dir(file, btop)) {
3808 + au_set_fbtop(file, btop);
3812 + fi_write_unlock(file);
3816 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3817 + const aufs_bindex_t bindex,
3818 + const aufs_bindex_t bbot)
3820 + struct au_branch **brp, **p;
3822 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3824 + brp = sbinfo->si_branch + bindex;
3825 + if (bindex < bbot)
3826 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3827 + sbinfo->si_branch[0 + bbot] = NULL;
3828 + sbinfo->si_bbot--;
3830 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3833 + sbinfo->si_branch = p;
3834 + /* harmless error */
3837 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3838 + const aufs_bindex_t bbot)
3840 + struct au_hdentry *hdp, *p;
3842 + AuRwMustWriteLock(&dinfo->di_rwsem);
3844 + hdp = au_hdentry(dinfo, bindex);
3845 + if (bindex < bbot)
3846 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3847 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3850 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3853 + dinfo->di_hdentry = p;
3854 + /* harmless error */
3857 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3858 + const aufs_bindex_t bbot)
3860 + struct au_hinode *hip, *p;
3862 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3864 + hip = au_hinode(iinfo, bindex);
3865 + if (bindex < bbot)
3866 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3867 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3870 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3873 + iinfo->ii_hinode = p;
3874 + /* harmless error */
3877 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3878 + struct au_branch *br)
3880 + aufs_bindex_t bbot;
3881 + struct au_sbinfo *sbinfo;
3882 + struct dentry *root, *h_root;
3883 + struct inode *inode, *h_inode;
3884 + struct au_hinode *hinode;
3886 + SiMustWriteLock(sb);
3888 + root = sb->s_root;
3889 + inode = d_inode(root);
3890 + sbinfo = au_sbi(sb);
3891 + bbot = sbinfo->si_bbot;
3893 + h_root = au_h_dptr(root, bindex);
3894 + hinode = au_hi(inode, bindex);
3895 + h_inode = au_igrab(hinode->hi_inode);
3898 + au_sbilist_lock();
3899 + au_br_do_del_brp(sbinfo, bindex, bbot);
3900 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3901 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3902 + au_sbilist_unlock();
3904 + /* ignore an error */
3905 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3909 + au_br_do_free(br);
3912 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3913 + unsigned long long max, void *arg)
3918 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3921 + unsigned long long opened;
3922 + unsigned int mnt_flags;
3923 + aufs_bindex_t bindex, bbot, br_id;
3924 + unsigned char do_wh, verbose;
3925 + struct au_branch *br;
3926 + struct au_wbr *wbr;
3927 + struct dentry *root;
3928 + struct file **to_free;
3933 + root = sb->s_root;
3934 + bindex = au_find_dbindex(root, del->h_path.dentry);
3937 + goto out; /* success */
3939 + pr_err("%s no such branch\n", del->pathname);
3942 + AuDbg("bindex b%d\n", bindex);
3945 + mnt_flags = au_mntflags(sb);
3946 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3947 + bbot = au_sbbot(sb);
3948 + if (unlikely(!bbot)) {
3949 + AuVerbose(verbose, "no more branches left\n");
3953 + br = au_sbr(sb, bindex);
3954 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3955 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3956 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3960 + br_id = br->br_id;
3961 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3962 + if (unlikely(opened)) {
3963 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3964 + err = PTR_ERR(to_free);
3965 + if (IS_ERR(to_free))
3968 + err = test_file_busy(sb, br_id, to_free, opened);
3969 + if (unlikely(err)) {
3970 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3976 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3978 + /* instead of WbrWhMustWriteLock(wbr) */
3979 + SiMustWriteLock(sb);
3980 + for (i = 0; i < AuBrWh_Last; i++) {
3981 + dput(wbr->wbr_wh[i]);
3982 + wbr->wbr_wh[i] = NULL;
3986 + err = test_children_busy(root, bindex, verbose);
3987 + if (unlikely(err)) {
3996 + * now we confirmed the branch is deletable.
3997 + * let's free the remaining opened dirs on the branch.
3999 + di_write_unlock(root);
4000 + br_del_file(to_free, opened, br_id);
4001 + di_write_lock_child(root);
4004 + sysaufs_brs_del(sb, bindex); /* remove successors */
4005 + dbgaufs_xino_del(br); /* remove one */
4006 + au_br_do_del(sb, bindex, br);
4007 + sysaufs_brs_add(sb, bindex); /* append successors */
4008 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4011 + au_cpup_attr_all(d_inode(root), /*force*/1);
4012 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4014 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4015 + if (au_opt_test(mnt_flags, PLINK))
4016 + au_plink_half_refresh(sb, br_id);
4018 + goto out; /* success */
4022 + rerr = au_br_init_wh(sb, br, br->br_perm);
4024 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4025 + del->pathname, rerr);
4028 + au_farray_free(to_free, opened);
4032 +/* ---------------------------------------------------------------------- */
4034 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4037 + aufs_bindex_t btop, bbot;
4038 + struct aufs_ibusy ibusy;
4039 + struct inode *inode, *h_inode;
4042 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4045 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4047 + /* VERIFY_WRITE */
4048 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4049 + if (unlikely(err)) {
4056 + si_read_lock(sb, AuLock_FLUSH);
4057 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4061 + ibusy.h_ino = 0; /* invalid */
4062 + inode = ilookup(sb, ibusy.ino);
4064 + || inode->i_ino == AUFS_ROOT_INO
4065 + || au_is_bad_inode(inode))
4068 + ii_read_lock_child(inode);
4069 + btop = au_ibtop(inode);
4070 + bbot = au_ibbot(inode);
4071 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4072 + h_inode = au_h_iptr(inode, ibusy.bindex);
4073 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4074 + ibusy.h_ino = h_inode->i_ino;
4076 + ii_read_unlock(inode);
4080 + si_read_unlock(sb);
4082 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4083 + if (unlikely(err)) {
4092 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4094 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4097 +#ifdef CONFIG_COMPAT
4098 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4100 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4104 +/* ---------------------------------------------------------------------- */
4107 + * change a branch permission
4110 +static void au_warn_ima(void)
4113 + /* since it doesn't support mark_files_ro() */
4114 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4118 +static int do_need_sigen_inc(int a, int b)
4120 + return au_br_whable(a) && !au_br_whable(b);
4123 +static int need_sigen_inc(int old, int new)
4125 + return do_need_sigen_inc(old, new)
4126 + || do_need_sigen_inc(new, old);
4129 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4132 + unsigned int mnt_flags;
4133 + unsigned long long ull, max;
4134 + aufs_bindex_t br_id;
4135 + unsigned char verbose, writer;
4136 + struct file *file, *hf, **array;
4137 + struct au_hfile *hfile;
4138 + struct inode *h_inode;
4140 + mnt_flags = au_mntflags(sb);
4141 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4143 + array = au_farray_alloc(sb, &max);
4144 + err = PTR_ERR(array);
4145 + if (IS_ERR(array))
4149 + br_id = au_sbr_id(sb, bindex);
4150 + for (ull = 0; ull < max; ull++) {
4151 + file = array[ull];
4152 + if (unlikely(!file))
4155 + /* AuDbg("%pD\n", file); */
4156 + fi_read_lock(file);
4157 + if (unlikely(au_test_mmapped(file))) {
4159 + AuVerbose(verbose, "mmapped %pD\n", file);
4161 + FiMustNoWaiters(file);
4162 + fi_read_unlock(file);
4166 + hfile = &au_fi(file)->fi_htop;
4167 + hf = hfile->hf_file;
4168 + if (!d_is_reg(file->f_path.dentry)
4169 + || !(file->f_mode & FMODE_WRITE)
4170 + || hfile->hf_br->br_id != br_id
4171 + || !(hf->f_mode & FMODE_WRITE))
4172 + array[ull] = NULL;
4178 + FiMustNoWaiters(file);
4179 + fi_read_unlock(file);
4187 + for (ull = 0; ull < max; ull++) {
4188 + file = array[ull];
4192 + /* todo: already flushed? */
4194 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4195 + * approach which resets f_mode and calls mnt_drop_write() and
4196 + * file_release_write() for each file, because the branch
4197 + * attribute in aufs world is totally different from the native
4200 + /* fi_read_lock(file); */
4201 + hfile = &au_fi(file)->fi_htop;
4202 + hf = hfile->hf_file;
4203 + /* fi_read_unlock(file); */
4204 + spin_lock(&hf->f_lock);
4205 + writer = !!(hf->f_mode & FMODE_WRITER);
4206 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4207 + spin_unlock(&hf->f_lock);
4209 + h_inode = file_inode(hf);
4210 + if (hf->f_mode & FMODE_READ)
4211 + i_readcount_inc(h_inode);
4212 + put_write_access(h_inode);
4213 + __mnt_drop_write(hf->f_path.mnt);
4218 + au_farray_free(array, max);
4224 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4228 + aufs_bindex_t bindex;
4229 + struct dentry *root;
4230 + struct au_branch *br;
4231 + struct au_br_fhsm *bf;
4233 + root = sb->s_root;
4234 + bindex = au_find_dbindex(root, mod->h_root);
4237 + return 0; /* success */
4239 + pr_err("%s no such branch\n", mod->path);
4242 + AuDbg("bindex b%d\n", bindex);
4244 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4245 + if (unlikely(err))
4248 + br = au_sbr(sb, bindex);
4249 + AuDebugOn(mod->h_root != au_br_dentry(br));
4250 + if (br->br_perm == mod->perm)
4251 + return 0; /* success */
4253 + /* pre-allocate for non-fhsm --> fhsm */
4255 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4256 + err = au_fhsm_br_alloc(br);
4257 + if (unlikely(err))
4260 + br->br_fhsm = NULL;
4263 + if (au_br_writable(br->br_perm)) {
4264 + /* remove whiteout base */
4265 + err = au_br_init_wh(sb, br, mod->perm);
4266 + if (unlikely(err))
4269 + if (!au_br_writable(mod->perm)) {
4270 + /* rw --> ro, file might be mmapped */
4271 + DiMustNoWaiters(root);
4272 + IiMustNoWaiters(d_inode(root));
4273 + di_write_unlock(root);
4274 + err = au_br_mod_files_ro(sb, bindex);
4275 + /* aufs_write_lock() calls ..._child() */
4276 + di_write_lock_child(root);
4278 + if (unlikely(err)) {
4280 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4283 + rerr = au_wbr_init(br, sb, br->br_perm);
4284 + if (unlikely(rerr)) {
4285 + AuIOErr("nested error %d (%d)\n",
4287 + br->br_perm = mod->perm;
4291 + } else if (au_br_writable(mod->perm)) {
4294 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4296 + err = au_wbr_init(br, sb, mod->perm);
4297 + if (unlikely(err)) {
4298 + au_kfree_rcu(br->br_wbr);
4299 + br->br_wbr = NULL;
4303 + if (unlikely(err))
4306 + if (au_br_fhsm(br->br_perm)) {
4307 + if (!au_br_fhsm(mod->perm)) {
4308 + /* fhsm --> non-fhsm */
4309 + au_br_fhsm_fin(br->br_fhsm);
4310 + au_kfree_rcu(br->br_fhsm);
4311 + br->br_fhsm = NULL;
4313 + } else if (au_br_fhsm(mod->perm))
4314 + /* non-fhsm --> fhsm */
4317 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4318 + br->br_perm = mod->perm;
4319 + goto out; /* success */
4322 + au_kfree_try_rcu(bf);
4328 +/* ---------------------------------------------------------------------- */
4330 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4333 + struct kstatfs kstfs;
4335 + err = vfs_statfs(&br->br_path, &kstfs);
4337 + stfs->f_blocks = kstfs.f_blocks;
4338 + stfs->f_bavail = kstfs.f_bavail;
4339 + stfs->f_files = kstfs.f_files;
4340 + stfs->f_ffree = kstfs.f_ffree;
4345 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4346 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4347 +++ linux/fs/aufs/branch.h 2021-12-03 15:38:59.933313976 +0100
4349 +/* SPDX-License-Identifier: GPL-2.0 */
4351 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4353 + * This program, aufs is free software; you can redistribute it and/or modify
4354 + * it under the terms of the GNU General Public License as published by
4355 + * the Free Software Foundation; either version 2 of the License, or
4356 + * (at your option) any later version.
4358 + * This program is distributed in the hope that it will be useful,
4359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4361 + * GNU General Public License for more details.
4363 + * You should have received a copy of the GNU General Public License
4364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4368 + * branch filesystems and xino for them
4371 +#ifndef __AUFS_BRANCH_H__
4372 +#define __AUFS_BRANCH_H__
4376 +#include <linux/mount.h>
4377 +#include "dirren.h"
4383 +/* ---------------------------------------------------------------------- */
4387 + struct file **xi_file;
4388 + unsigned int xi_nfile;
4394 + /* reserved for future use */
4395 + /* unsigned long *bitmap; */
4396 + wait_queue_head_t wqh;
4399 + struct mutex xi_mtx; /* protects xi_file array */
4400 + struct hlist_bl_head xi_writing;
4402 + atomic_t xi_truncating;
4404 + struct kref xi_kref;
4407 +/* File-based Hierarchical Storage Management */
4408 +struct au_br_fhsm {
4409 +#ifdef CONFIG_AUFS_FHSM
4410 + struct mutex bf_lock;
4411 + unsigned long bf_jiffy;
4412 + struct aufs_stfs bf_stfs;
4417 +/* members for writable branch only */
4418 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4420 + struct au_rwsem wbr_wh_rwsem;
4421 + struct dentry *wbr_wh[AuBrWh_Last];
4422 + atomic_t wbr_wh_running;
4423 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4424 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4425 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4428 + unsigned long long wbr_bytes;
4431 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4432 +#define AuBrDynOp (AuDyLast * 4)
4434 +#ifdef CONFIG_AUFS_HFSNOTIFY
4435 +/* support for asynchronous destruction */
4436 +struct au_br_hfsnotify {
4437 + struct fsnotify_group *hfsn_group;
4441 +/* sysfs entries */
4442 +struct au_brsysfs {
4444 + struct attribute attr;
4453 +/* protected by superblock rwsem */
4455 + struct au_xino *br_xino;
4457 + aufs_bindex_t br_id;
4460 + struct path br_path;
4461 + spinlock_t br_dykey_lock;
4462 + struct au_dykey *br_dykey[AuBrDynOp];
4463 + au_lcnt_t br_nfiles; /* opened files */
4464 + au_lcnt_t br_count; /* in-use for other */
4466 + struct au_wbr *br_wbr;
4467 + struct au_br_fhsm *br_fhsm;
4469 +#ifdef CONFIG_AUFS_HFSNOTIFY
4470 + struct au_br_hfsnotify *br_hfsn;
4473 +#ifdef CONFIG_SYSFS
4474 + /* entries under sysfs per mount-point */
4475 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4478 +#ifdef CONFIG_DEBUG_FS
4479 + struct dentry *br_dbgaufs; /* xino */
4482 + struct au_dr_br br_dirren;
4485 +/* ---------------------------------------------------------------------- */
4487 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4489 + return br->br_path.mnt;
4492 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4494 + return br->br_path.dentry;
4497 +static inline struct super_block *au_br_sb(struct au_branch *br)
4499 + return au_br_mnt(br)->mnt_sb;
4502 +static inline int au_br_rdonly(struct au_branch *br)
4504 + return (sb_rdonly(au_br_sb(br))
4505 + || !au_br_writable(br->br_perm))
4509 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4511 +#ifdef CONFIG_AUFS_HNOTIFY
4512 + return !(brperm & AuBrPerm_RR);
4518 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4520 + int err, exec_flag;
4523 + exec_flag = oflag & __FMODE_EXEC;
4524 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4530 +static inline void au_xino_get(struct au_branch *br)
4532 + struct au_xino *xi;
4536 + kref_get(&xi->xi_kref);
4539 +static inline int au_xino_count(struct au_branch *br)
4542 + struct au_xino *xi;
4547 + v = kref_read(&xi->xi_kref);
4552 +/* ---------------------------------------------------------------------- */
4556 +void au_br_free(struct au_sbinfo *sinfo);
4557 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4559 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4561 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4562 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4563 +#ifdef CONFIG_COMPAT
4564 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4567 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4570 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4573 +static const loff_t au_loff_max = LLONG_MAX;
4575 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4576 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4578 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4579 + struct file *copy_src);
4581 + struct au_xino *xi; /* switch between xino and xigen */
4583 + struct path *base;
4584 + struct file *copy_src;
4586 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4588 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4590 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4592 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4593 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4595 +int au_xib_trunc(struct super_block *sb);
4596 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4598 +struct au_xino *au_xino_alloc(unsigned int nfile);
4599 +int au_xino_put(struct au_branch *br);
4600 +struct file *au_xino_file1(struct au_xino *xi);
4602 +struct au_opt_xino;
4603 +void au_xino_clr(struct super_block *sb);
4604 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4605 +struct file *au_xino_def(struct super_block *sb);
4606 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4607 + struct path *base);
4609 +ino_t au_xino_new_ino(struct super_block *sb);
4610 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4612 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4613 + ino_t h_ino, int idx);
4614 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4617 +int au_xino_path(struct seq_file *seq, struct file *file);
4619 +/* ---------------------------------------------------------------------- */
4621 +/* @idx is signed to accept -1 meaning the first file */
4622 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4624 + struct file *file;
4631 + if (idx < xi->xi_nfile)
4632 + file = xi->xi_file[idx];
4634 + file = au_xino_file1(xi);
4640 +/* ---------------------------------------------------------------------- */
4642 +/* Superblock to branch */
4644 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4646 + return au_sbr(sb, bindex)->br_id;
4650 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4652 + return au_br_mnt(au_sbr(sb, bindex));
4656 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4658 + return au_br_sb(au_sbr(sb, bindex));
4661 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4663 + return au_sbr(sb, bindex)->br_perm;
4666 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4668 + return au_br_whable(au_sbr_perm(sb, bindex));
4671 +/* ---------------------------------------------------------------------- */
4673 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4674 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4675 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4676 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4678 +#define wbr_wh_read_trylock_nested(wbr) \
4679 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4680 +#define wbr_wh_write_trylock_nested(wbr) \
4681 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4684 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4685 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4686 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4688 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4689 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4690 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4692 +/* ---------------------------------------------------------------------- */
4694 +#ifdef CONFIG_AUFS_FHSM
4695 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4697 + mutex_init(&brfhsm->bf_lock);
4698 + brfhsm->bf_jiffy = 0;
4699 + brfhsm->bf_readable = 0;
4702 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4704 + mutex_destroy(&brfhsm->bf_lock);
4707 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4708 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4711 +#endif /* __KERNEL__ */
4712 +#endif /* __AUFS_BRANCH_H__ */
4713 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4714 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4715 +++ linux/fs/aufs/conf.mk 2021-12-03 15:38:59.933313976 +0100
4717 +# SPDX-License-Identifier: GPL-2.0
4719 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4723 +AuConfStr += ${1}=${${1}}
4727 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4729 + HNOTIFY HFSNOTIFY \
4741 +$(foreach i, ${AuConfAll}, \
4742 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4744 +AuConfName = ${obj}/conf.str
4745 +${AuConfName}.tmp: FORCE
4746 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4747 +${AuConfName}: ${AuConfName}.tmp
4748 + @diff -q $< $@ > /dev/null 2>&1 || { \
4749 + echo ' GEN ' $@; \
4753 +clean-files += ${AuConfName} ${AuConfName}.tmp
4754 +${obj}/sysfs.o: ${AuConfName}
4756 +-include ${srctree}/${src}/conf_priv.mk
4757 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4758 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4759 +++ linux/fs/aufs/cpup.c 2021-12-03 15:38:59.933313976 +0100
4761 +// SPDX-License-Identifier: GPL-2.0
4763 + * Copyright (C) 2005-2021 Junjiro R. Okajima
4765 + * This program, aufs is free software; you can redistribute it and/or modify
4766 + * it under the terms of the GNU General Public License as published by
4767 + * the Free Software Foundation; either version 2 of the License, or
4768 + * (at your option) any later version.
4770 + * This program is distributed in the hope that it will be useful,
4771 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4772 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4773 + * GNU General Public License for more details.
4775 + * You should have received a copy of the GNU General Public License
4776 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4780 + * copy-up functions, see wbr_policy.c for copy-down
4783 +#include <linux/fs_stack.h>
4784 +#include <linux/mm.h>
4785 +#include <linux/task_work.h>
4788 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4790 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4791 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4793 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4795 + dst->i_flags |= iflags & ~mask;
4796 + if (au_test_fs_notime(dst->i_sb))
4797 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4800 +void au_cpup_attr_timesizes(struct inode *inode)
4802 + struct inode *h_inode;
4804 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4805 + fsstack_copy_attr_times(inode, h_inode);
4806 + fsstack_copy_inode_size(inode, h_inode);
4809 +void au_cpup_attr_nlink(struct inode *inode, int force)
4811 + struct inode *h_inode;
4812 + struct super_block *sb;
4813 + aufs_bindex_t bindex, bbot;
4816 + bindex = au_ibtop(inode);
4817 + h_inode = au_h_iptr(inode, bindex);
4819 + && !S_ISDIR(h_inode->i_mode)
4820 + && au_opt_test(au_mntflags(sb), PLINK)
4821 + && au_plink_test(inode))
4825 + * 0 can happen in revalidating.
4826 + * h_inode->i_mutex may not be held here, but it is harmless since once
4827 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4829 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4830 + * the incorrect link count.
4832 + set_nlink(inode, h_inode->i_nlink);
4835 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4836 + * it may includes whplink directory.
4838 + if (S_ISDIR(h_inode->i_mode)) {
4839 + bbot = au_ibbot(inode);
4840 + for (bindex++; bindex <= bbot; bindex++) {
4841 + h_inode = au_h_iptr(inode, bindex);
4843 + au_add_nlink(inode, h_inode);
4848 +void au_cpup_attr_changeable(struct inode *inode)
4850 + struct inode *h_inode;
4852 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4853 + inode->i_mode = h_inode->i_mode;
4854 + inode->i_uid = h_inode->i_uid;
4855 + inode->i_gid = h_inode->i_gid;
4856 + au_cpup_attr_timesizes(inode);
4857 + au_cpup_attr_flags(inode, h_inode->i_flags);
4860 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4862 + struct au_iinfo *iinfo = au_ii(inode);
4864 + IiMustWriteLock(inode);
4866 + iinfo->ii_higen = h_inode->i_generation;
4867 + iinfo->ii_hsb1 = h_inode->i_sb;
4870 +void au_cpup_attr_all(struct inode *inode, int force)
4872 + struct inode *h_inode;
4874 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4875 + au_cpup_attr_changeable(inode);
4876 + if (inode->i_nlink > 0)
4877 + au_cpup_attr_nlink(inode, force);
4878 + inode->i_rdev = h_inode->i_rdev;
4879 + inode->i_blkbits = h_inode->i_blkbits;
4880 + au_cpup_igen(inode, h_inode);
4883 +/* ---------------------------------------------------------------------- */
4885 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4887 +/* keep the timestamps of the parent dir when cpup */
4888 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4889 + struct path *h_path)
4891 + struct inode *h_inode;
4893 + dt->dt_dentry = dentry;
4894 + dt->dt_h_path = *h_path;
4895 + h_inode = d_inode(h_path->dentry);
4896 + dt->dt_atime = h_inode->i_atime;
4897 + dt->dt_mtime = h_inode->i_mtime;
4901 +void au_dtime_revert(struct au_dtime *dt)
4903 + struct iattr attr;
4906 + attr.ia_atime = dt->dt_atime;
4907 + attr.ia_mtime = dt->dt_mtime;
4908 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4909 + | ATTR_ATIME | ATTR_ATIME_SET;
4911 + /* no delegation since this is a directory */
4912 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4913 + if (unlikely(err))
4914 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4917 +/* ---------------------------------------------------------------------- */
4919 +/* internal use only */
4920 +struct au_cpup_reg_attr {
4923 + unsigned int iflags; /* inode->i_flags */
4926 +static noinline_for_stack
4927 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4928 + struct au_cpup_reg_attr *h_src_attr)
4930 + int err, sbits, icex;
4931 + unsigned int mnt_flags;
4932 + unsigned char verbose;
4934 + struct path h_path;
4935 + struct inode *h_isrc, *h_idst;
4936 + struct kstat *h_st;
4937 + struct au_branch *br;
4939 + h_path.dentry = au_h_dptr(dst, bindex);
4940 + h_idst = d_inode(h_path.dentry);
4941 + br = au_sbr(dst->d_sb, bindex);
4942 + h_path.mnt = au_br_mnt(br);
4943 + h_isrc = d_inode(h_src);
4944 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4945 + | ATTR_ATIME | ATTR_MTIME
4946 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4947 + if (h_src_attr && h_src_attr->valid) {
4948 + h_st = &h_src_attr->st;
4949 + ia.ia_uid = h_st->uid;
4950 + ia.ia_gid = h_st->gid;
4951 + ia.ia_atime = h_st->atime;
4952 + ia.ia_mtime = h_st->mtime;
4953 + if (h_idst->i_mode != h_st->mode
4954 + && !S_ISLNK(h_idst->i_mode)) {
4955 + ia.ia_valid |= ATTR_MODE;
4956 + ia.ia_mode = h_st->mode;
4958 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4959 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4961 + ia.ia_uid = h_isrc->i_uid;
4962 + ia.ia_gid = h_isrc->i_gid;
4963 + ia.ia_atime = h_isrc->i_atime;
4964 + ia.ia_mtime = h_isrc->i_mtime;
4965 + if (h_idst->i_mode != h_isrc->i_mode
4966 + && !S_ISLNK(h_idst->i_mode)) {
4967 + ia.ia_valid |= ATTR_MODE;
4968 + ia.ia_mode = h_isrc->i_mode;
4970 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4971 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4973 + /* no delegation since it is just created */
4974 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4976 + /* is this nfs only? */
4977 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4978 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4979 + ia.ia_mode = h_isrc->i_mode;
4980 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4983 + icex = br->br_perm & AuBrAttr_ICEX;
4985 + mnt_flags = au_mntflags(dst->d_sb);
4986 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4987 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4993 +/* ---------------------------------------------------------------------- */
4995 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4996 + char *buf, unsigned long blksize)
4999 + size_t sz, rbytes, wbytes;
5000 + unsigned char all_zero;
5002 + struct inode *h_inode;
5003 + /* reduce stack usage */
5006 + zp = page_address(ZERO_PAGE(0));
5007 + if (unlikely(!zp))
5008 + return -ENOMEM; /* possible? */
5013 + AuDbg("len %lld\n", len);
5015 + if (len < blksize)
5019 + /* todo: signal_pending? */
5020 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5021 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5024 + if (unlikely(err < 0))
5028 + if (len >= rbytes && rbytes == blksize)
5029 + all_zero = !memcmp(buf, zp, rbytes);
5036 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5038 + /* todo: signal_pending? */
5039 + if (unlikely(err == -EAGAIN || err == -EINTR))
5041 + if (unlikely(err < 0))
5046 + if (unlikely(err < 0))
5052 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5054 + if (unlikely(res < 0))
5061 + /* the last block may be a hole */
5062 + if (!err && all_zero) {
5063 + AuLabel(last hole);
5066 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5067 + /* nfs requires this step to make last hole */
5068 + /* is this only nfs? */
5070 + /* todo: signal_pending? */
5071 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5072 + } while (err == -EAGAIN || err == -EINTR);
5079 + ia->ia_size = dst->f_pos;
5080 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5081 + ia->ia_file = dst;
5082 + h_inode = file_inode(dst);
5083 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5084 + /* no delegation since it is just created */
5085 + err = vfsub_notify_change(&dst->f_path, ia,
5086 + /*delegated*/NULL);
5087 + inode_unlock(h_inode);
5094 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5097 + unsigned long blksize;
5098 + unsigned char do_kfree;
5100 + struct super_block *h_sb;
5103 + h_sb = file_inode(dst)->i_sb;
5104 + blksize = h_sb->s_blocksize;
5105 + if (!blksize || PAGE_SIZE < blksize)
5106 + blksize = PAGE_SIZE;
5107 + AuDbg("blksize %lu\n", blksize);
5108 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5110 + buf = kmalloc(blksize, GFP_NOFS);
5112 + buf = (void *)__get_free_page(GFP_NOFS);
5113 + if (unlikely(!buf))
5116 + if (len > (1 << 22))
5117 + AuDbg("copying a large file %lld\n", (long long)len);
5121 + err = au_do_copy_file(dst, src, len, buf, blksize);
5123 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5124 + au_kfree_do_rcu(buf);
5126 + free_page((unsigned long)buf);
5132 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5135 + struct super_block *h_src_sb;
5136 + struct inode *h_src_inode;
5138 + h_src_inode = file_inode(src);
5139 + h_src_sb = h_src_inode->i_sb;
5141 + /* XFS acquires inode_lock */
5142 + if (!au_test_xfs(h_src_sb))
5143 + err = au_copy_file(dst, src, len);
5145 + inode_unlock_shared(h_src_inode);
5146 + err = au_copy_file(dst, src, len);
5147 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5153 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5157 + struct super_block *h_src_sb;
5158 + struct inode *h_src_inode;
5160 + h_src_inode = file_inode(src);
5161 + h_src_sb = h_src_inode->i_sb;
5162 + if (h_src_sb != file_inode(dst)->i_sb
5163 + || !dst->f_op->remap_file_range) {
5164 + err = au_do_copy(dst, src, len);
5168 + if (!au_test_nfs(h_src_sb)) {
5169 + inode_unlock_shared(h_src_inode);
5170 + lo = vfsub_clone_file_range(src, dst, len);
5171 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5173 + lo = vfsub_clone_file_range(src, dst, len);
5176 + goto out; /* success */
5177 + } else if (lo >= 0)
5178 + /* todo: possible? */
5179 + /* paritially succeeded */
5180 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5181 + else if (lo != -EOPNOTSUPP) {
5182 + /* older XFS has a condition in cloning */
5187 + /* the backend fs on NFS may not support cloning */
5188 + err = au_do_copy(dst, src, len);
5196 + * to support a sparse file which is opened with O_APPEND,
5197 + * we need to close the file.
5199 +static int au_cp_regular(struct au_cp_generic *cpg)
5202 + enum { SRC, DST };
5204 + aufs_bindex_t bindex;
5205 + unsigned int flags;
5206 + struct dentry *dentry;
5208 + struct file *file;
5211 + .bindex = cpg->bsrc,
5212 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5215 + .bindex = cpg->bdst,
5216 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5217 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5220 + struct au_branch *br;
5221 + struct super_block *sb, *h_src_sb;
5222 + struct inode *h_src_inode;
5223 + struct task_struct *tsk = current;
5225 + /* bsrc branch can be ro/rw. */
5226 + sb = cpg->dentry->d_sb;
5228 + for (i = 0; i < 2; i++, f++) {
5229 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5230 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5231 + /*file*/NULL, f->force_wr);
5232 + if (IS_ERR(f->file)) {
5233 + err = PTR_ERR(f->file);
5241 + /* try stopping to update while we copyup */
5242 + h_src_inode = d_inode(file[SRC].dentry);
5243 + h_src_sb = h_src_inode->i_sb;
5244 + if (!au_test_nfs(h_src_sb))
5245 + IMustLock(h_src_inode);
5246 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5248 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5249 + if (tsk->flags & PF_KTHREAD)
5250 + __fput_sync(file[DST].file);
5252 + /* it happened actually */
5253 + fput(file[DST].file);
5256 + * we have to call both since we don't know which place the file
5260 + flush_delayed_fput();
5262 + br = au_sbr(sb, file[DST].bindex);
5263 + au_lcnt_dec(&br->br_nfiles);
5266 + fput(file[SRC].file);
5267 + br = au_sbr(sb, file[SRC].bindex);
5268 + au_lcnt_dec(&br->br_nfiles);
5273 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5274 + struct au_cpup_reg_attr *h_src_attr)
5278 + struct path h_path;
5279 + struct inode *h_src_inode, *h_dst_inode;
5282 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5283 + l = i_size_read(h_src_inode);
5284 + if (cpg->len == -1 || l < cpg->len)
5287 + /* try stopping to update while we are referencing */
5288 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5289 + au_pin_hdir_unlock(cpg->pin);
5291 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5292 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5293 + h_src_attr->iflags = h_src_inode->i_flags;
5294 + if (!au_test_nfs(h_src_inode->i_sb))
5295 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5297 + inode_unlock_shared(h_src_inode);
5298 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5299 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5301 + if (unlikely(err)) {
5302 + inode_unlock_shared(h_src_inode);
5305 + h_src_attr->valid = 1;
5306 + if (!au_test_nfs(h_src_inode->i_sb)) {
5307 + err = au_cp_regular(cpg);
5308 + inode_unlock_shared(h_src_inode);
5310 + inode_unlock_shared(h_src_inode);
5311 + err = au_cp_regular(cpg);
5313 + rerr = au_pin_hdir_relock(cpg->pin);
5317 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5318 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5319 + h_dst_inode = d_inode(h_path.dentry);
5320 + spin_lock(&h_dst_inode->i_lock);
5321 + h_dst_inode->i_state |= I_LINKABLE;
5322 + spin_unlock(&h_dst_inode->i_lock);
5329 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5330 + struct inode *h_dir)
5333 + DEFINE_DELAYED_CALL(done);
5336 + sym = vfs_get_link(h_src, &done);
5337 + err = PTR_ERR(sym);
5341 + err = vfsub_symlink(h_dir, h_path, sym);
5344 + do_delayed_call(&done);
5349 + * regardless 'acl' option, reset all ACL.
5350 + * All ACL will be copied up later from the original entry on the lower branch.
5352 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5355 + struct dentry *h_dentry;
5356 + struct inode *h_inode;
5358 + h_dentry = h_path->dentry;
5359 + h_inode = d_inode(h_dentry);
5360 + /* forget_all_cached_acls(h_inode)); */
5361 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5363 + if (err == -EOPNOTSUPP)
5366 + err = vfsub_acl_chmod(h_inode, mode);
5372 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5373 + struct inode *h_dir, struct path *h_path)
5376 + struct inode *dir, *inode;
5378 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5380 + if (err == -EOPNOTSUPP)
5382 + if (unlikely(err))
5386 + * strange behaviour from the users view,
5387 + * particularly setattr case
5389 + dir = d_inode(dst_parent);
5390 + if (au_ibtop(dir) == cpg->bdst)
5391 + au_cpup_attr_nlink(dir, /*force*/1);
5392 + inode = d_inode(cpg->dentry);
5393 + au_cpup_attr_nlink(inode, /*force*/1);
5399 +static noinline_for_stack
5400 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5401 + struct au_cpup_reg_attr *h_src_attr)
5405 + unsigned int mnt_flags;
5406 + unsigned char isdir, isreg, force;
5407 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5408 + struct au_dtime dt;
5409 + struct path h_path;
5410 + struct dentry *h_src, *h_dst, *h_parent;
5411 + struct inode *h_inode, *h_dir;
5412 + struct super_block *sb;
5414 + /* bsrc branch can be ro/rw. */
5415 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5416 + h_inode = d_inode(h_src);
5417 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5419 + /* try stopping to be referenced while we are creating */
5420 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5421 + if (au_ftest_cpup(cpg->flags, RENAME))
5422 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5423 + AUFS_WH_PFX_LEN));
5424 + h_parent = h_dst->d_parent; /* dir inode is locked */
5425 + h_dir = d_inode(h_parent);
5427 + AuDebugOn(h_parent != h_dst->d_parent);
5429 + sb = cpg->dentry->d_sb;
5430 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5432 + h_path.dentry = h_parent;
5433 + au_dtime_store(&dt, dst_parent, &h_path);
5435 + h_path.dentry = h_dst;
5439 + mode = h_inode->i_mode;
5440 + switch (mode & S_IFMT) {
5443 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5445 + err = au_do_cpup_regular(cpg, h_src_attr);
5449 + err = vfsub_mkdir(h_dir, &h_path, mode);
5451 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5454 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5458 + AuDebugOn(!capable(CAP_MKNOD));
5462 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5465 + AuIOErr("Unknown inode type 0%o\n", mode);
5469 + err = au_reset_acl(h_dir, &h_path, mode);
5471 + mnt_flags = au_mntflags(sb);
5472 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5474 + && au_opt_test(mnt_flags, XINO)
5475 + && (h_inode->i_nlink == 1
5476 + || (h_inode->i_state & I_LINKABLE))
5477 + /* todo: unnecessary? */
5478 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5479 + && cpg->bdst < cpg->bsrc
5480 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5481 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5482 + /* ignore this error */
5487 + force = !!cpg->len;
5488 + if (cpg->len == -1)
5489 + force = !!i_size_read(h_inode);
5491 + au_fhsm_wrote(sb, cpg->bdst, force);
5495 + au_dtime_revert(&dt);
5499 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5502 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5503 + struct path h_ppath;
5504 + struct inode *h_dir;
5505 + aufs_bindex_t bdst;
5507 + dentry = cpg->dentry;
5509 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5510 + h_dentry = au_h_dptr(dentry, bdst);
5511 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5513 + au_set_h_dptr(dentry, bdst, NULL);
5514 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5516 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5517 + au_set_h_dptr(dentry, bdst, h_dentry);
5520 + parent = dget_parent(dentry);
5521 + h_ppath.dentry = au_h_dptr(parent, bdst);
5523 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5524 + if (IS_ERR(h_path->dentry))
5525 + err = PTR_ERR(h_path->dentry);
5527 + if (unlikely(err))
5530 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5531 + h_dir = d_inode(h_parent);
5533 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5534 + /* no delegation since it is just created */
5535 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5537 + dput(h_path->dentry);
5544 + * copyup the @dentry from @bsrc to @bdst.
5545 + * the caller must set the both of lower dentries.
5546 + * @len is for truncating when it is -1 copyup the entire file.
5547 + * in link/rename cases, @dst_parent may be different from the real one.
5548 + * basic->bsrc can be larger than basic->bdst.
5549 + * aufs doesn't touch the credential so
5550 + * security_inode_copy_up{,_xattr}() are unnecessary.
5552 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5555 + aufs_bindex_t old_ibtop;
5556 + unsigned char isdir, plink;
5557 + struct dentry *h_src, *h_dst, *h_parent;
5558 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5559 + struct super_block *sb;
5560 + struct au_branch *br;
5561 + /* to reduce stack size */
5563 + struct au_dtime dt;
5564 + struct path h_path;
5565 + struct au_cpup_reg_attr h_src_attr;
5569 + a = kmalloc(sizeof(*a), GFP_NOFS);
5572 + a->h_src_attr.valid = 0;
5574 + sb = cpg->dentry->d_sb;
5575 + br = au_sbr(sb, cpg->bdst);
5576 + a->h_path.mnt = au_br_mnt(br);
5577 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5578 + h_parent = h_dst->d_parent; /* dir inode is locked */
5579 + h_dir = d_inode(h_parent);
5582 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5583 + inode = d_inode(cpg->dentry);
5586 + dst_parent = dget_parent(cpg->dentry);
5590 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5591 + dst_inode = au_h_iptr(inode, cpg->bdst);
5593 + if (unlikely(!plink)) {
5595 + AuIOErr("hi%lu(i%lu) exists on b%d "
5596 + "but plink is disabled\n",
5597 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5601 + if (dst_inode->i_nlink) {
5602 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5604 + h_src = au_plink_lkup(inode, cpg->bdst);
5605 + err = PTR_ERR(h_src);
5606 + if (IS_ERR(h_src))
5608 + if (unlikely(d_is_negative(h_src))) {
5610 + AuIOErr("i%lu exists on b%d "
5611 + "but not pseudo-linked\n",
5612 + inode->i_ino, cpg->bdst);
5618 + a->h_path.dentry = h_parent;
5619 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5622 + a->h_path.dentry = h_dst;
5624 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5625 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5626 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5628 + au_dtime_revert(&a->dt);
5629 + if (unlikely(err == -EWOULDBLOCK)) {
5630 + pr_warn("cannot retry for NFSv4 delegation"
5631 + " for an internal link\n");
5637 + /* todo: cpup_wh_file? */
5639 + au_update_ibrange(inode, /*do_put_zero*/1);
5642 + isdir = S_ISDIR(inode->i_mode);
5643 + old_ibtop = au_ibtop(inode);
5644 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5645 + if (unlikely(err))
5647 + dst_inode = d_inode(h_dst);
5648 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5649 + /* todo: necessary? */
5650 + /* au_pin_hdir_unlock(cpg->pin); */
5652 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5653 + if (unlikely(err)) {
5654 + /* todo: necessary? */
5655 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5656 + inode_unlock(dst_inode);
5660 + if (cpg->bdst < old_ibtop) {
5661 + if (S_ISREG(inode->i_mode)) {
5662 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5663 + if (unlikely(err)) {
5664 + /* ignore an error */
5665 + /* au_pin_hdir_relock(cpg->pin); */
5666 + inode_unlock(dst_inode);
5670 + au_set_ibtop(inode, cpg->bdst);
5672 + au_set_ibbot(inode, cpg->bdst);
5673 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5674 + au_hi_flags(inode, isdir));
5676 + /* todo: necessary? */
5677 + /* err = au_pin_hdir_relock(cpg->pin); */
5678 + inode_unlock(dst_inode);
5679 + if (unlikely(err))
5682 + src_inode = d_inode(h_src);
5684 + && (src_inode->i_nlink > 1
5685 + || src_inode->i_state & I_LINKABLE)
5687 + au_plink_append(inode, cpg->bdst, h_dst);
5689 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5690 + a->h_path.dentry = h_dst;
5691 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5694 + goto out_parent; /* success */
5698 + a->h_path.dentry = h_parent;
5699 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5700 + a->h_path.dentry = h_dst;
5702 + if (d_is_positive(h_dst)) {
5704 + /* no delegation since it is just created */
5705 + rerr = vfsub_unlink(h_dir, &a->h_path,
5706 + /*delegated*/NULL, /*force*/0);
5708 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5710 + au_dtime_revert(&a->dt);
5712 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5722 +#if 0 /* reserved */
5723 +struct au_cpup_single_args {
5725 + struct au_cp_generic *cpg;
5726 + struct dentry *dst_parent;
5729 +static void au_call_cpup_single(void *args)
5731 + struct au_cpup_single_args *a = args;
5733 + au_pin_hdir_acquire_nest(a->cpg->pin);
5734 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5735 + au_pin_hdir_release(a->cpg->pin);
5740 + * prevent SIGXFSZ in copy-up.
5741 + * testing CAP_MKNOD is for generic fs,
5742 + * but CAP_FSETID is for xfs only, currently.
5744 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5747 + struct super_block *sb;
5748 + struct inode *h_dir;
5751 + sb = au_pinned_parent(pin)->d_sb;
5752 + if (!au_wkq_test()
5753 + && (!au_sbi(sb)->si_plink_maint_pid
5754 + || au_plink_maint(sb, AuLock_NOPLM))) {
5755 + switch (mode & S_IFMT) {
5757 + /* no condition about RLIMIT_FSIZE and the file size */
5762 + do_sio = !capable(CAP_MKNOD);
5766 + do_sio = ((mode & (S_ISUID | S_ISGID))
5767 + && !capable(CAP_FSETID));
5768 + /* this workaround may be removed in the future */
5770 + h_dir = au_pinned_h_dir(pin);
5771 + do_sio = h_dir->i_mode & S_ISVTX;
5778 +#if 0 /* reserved */
5779 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5782 + struct dentry *h_dentry;
5784 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5785 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5786 + err = au_cpup_single(cpg, dst_parent);
5788 + struct au_cpup_single_args args = {
5791 + .dst_parent = dst_parent
5793 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5794 + if (unlikely(wkq_err))
5803 + * copyup the @dentry from the first active lower branch to @bdst,
5804 + * using au_cpup_single().
5806 +static int au_cpup_simple(struct au_cp_generic *cpg)
5809 + unsigned int flags_orig;
5810 + struct dentry *dentry;
5812 + AuDebugOn(cpg->bsrc < 0);
5814 + dentry = cpg->dentry;
5815 + DiMustWriteLock(dentry);
5817 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5819 + flags_orig = cpg->flags;
5820 + au_fset_cpup(cpg->flags, RENAME);
5821 + err = au_cpup_single(cpg, NULL);
5822 + cpg->flags = flags_orig;
5824 + return 0; /* success */
5827 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5828 + au_set_dbtop(dentry, cpg->bsrc);
5834 +struct au_cpup_simple_args {
5836 + struct au_cp_generic *cpg;
5839 +static void au_call_cpup_simple(void *args)
5841 + struct au_cpup_simple_args *a = args;
5843 + au_pin_hdir_acquire_nest(a->cpg->pin);
5844 + *a->errp = au_cpup_simple(a->cpg);
5845 + au_pin_hdir_release(a->cpg->pin);
5848 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5851 + struct dentry *dentry, *parent;
5852 + struct file *h_file;
5853 + struct inode *h_dir;
5855 + dentry = cpg->dentry;
5857 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5858 + AuDebugOn(cpg->bsrc < 0);
5859 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5860 + err = PTR_ERR(h_file);
5861 + if (IS_ERR(h_file))
5865 + parent = dget_parent(dentry);
5866 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5867 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5868 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5869 + err = au_cpup_simple(cpg);
5871 + struct au_cpup_simple_args args = {
5875 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5876 + if (unlikely(wkq_err))
5882 + au_h_open_post(dentry, cpg->bsrc, h_file);
5888 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5890 + aufs_bindex_t bsrc, bbot;
5891 + struct dentry *dentry, *h_dentry;
5893 + if (cpg->bsrc < 0) {
5894 + dentry = cpg->dentry;
5895 + bbot = au_dbbot(dentry);
5896 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5897 + h_dentry = au_h_dptr(dentry, bsrc);
5899 + AuDebugOn(d_is_negative(h_dentry));
5903 + AuDebugOn(bsrc > bbot);
5906 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5907 + return au_do_sio_cpup_simple(cpg);
5910 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5912 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5913 + return au_do_sio_cpup_simple(cpg);
5916 +/* ---------------------------------------------------------------------- */
5919 + * copyup the deleted file for writing.
5921 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5922 + struct file *file)
5925 + unsigned int flags_orig;
5926 + aufs_bindex_t bsrc_orig;
5927 + struct au_dinfo *dinfo;
5929 + struct au_hdentry *hd;
5930 + struct dentry *h_dentry;
5933 + dinfo = au_di(cpg->dentry);
5934 + AuRwMustWriteLock(&dinfo->di_rwsem);
5936 + bsrc_orig = cpg->bsrc;
5937 + cpg->bsrc = dinfo->di_btop;
5938 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5939 + hdst.h_dentry = hdst.hd->hd_dentry;
5940 + hdst.hd->hd_dentry = wh_dentry;
5941 + dinfo->di_btop = cpg->bdst;
5943 + hsrc.h_dentry = NULL;
5945 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5946 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5947 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5949 + flags_orig = cpg->flags;
5950 + cpg->flags = !AuCpup_DTIME;
5951 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5952 + cpg->flags = flags_orig;
5955 + err = au_reopen_nondir(file);
5956 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5958 + hdst.hd->hd_dentry = hdst.h_dentry;
5959 + dinfo->di_btop = cpg->bsrc;
5960 + cpg->bsrc = bsrc_orig;
5965 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5968 + aufs_bindex_t bdst;
5969 + struct au_dtime dt;
5970 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5971 + struct au_branch *br;
5972 + struct path h_path;
5974 + dentry = cpg->dentry;
5976 + br = au_sbr(dentry->d_sb, bdst);
5977 + parent = dget_parent(dentry);
5978 + h_parent = au_h_dptr(parent, bdst);
5979 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5980 + err = PTR_ERR(wh_dentry);
5981 + if (IS_ERR(wh_dentry))
5984 + h_path.dentry = h_parent;
5985 + h_path.mnt = au_br_mnt(br);
5986 + au_dtime_store(&dt, parent, &h_path);
5987 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5988 + if (unlikely(err))
5992 + h_path.dentry = wh_dentry;
5993 + if (!d_is_dir(wh_dentry)) {
5994 + /* no delegation since it is just created */
5995 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5996 + /*delegated*/NULL, /*force*/0);
5998 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5999 + if (unlikely(err)) {
6000 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6004 + au_dtime_revert(&dt);
6005 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6014 +struct au_cpup_wh_args {
6016 + struct au_cp_generic *cpg;
6017 + struct file *file;
6020 +static void au_call_cpup_wh(void *args)
6022 + struct au_cpup_wh_args *a = args;
6024 + au_pin_hdir_acquire_nest(a->cpg->pin);
6025 + *a->errp = au_cpup_wh(a->cpg, a->file);
6026 + au_pin_hdir_release(a->cpg->pin);
6029 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6032 + aufs_bindex_t bdst;
6033 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6034 + struct inode *dir, *h_dir, *h_tmpdir;
6035 + struct au_wbr *wbr;
6036 + struct au_pin wh_pin, *pin_orig;
6038 + dentry = cpg->dentry;
6040 + parent = dget_parent(dentry);
6041 + dir = d_inode(parent);
6044 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6047 + if (!h_dir->i_nlink) {
6048 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6049 + h_orph = wbr->wbr_orph;
6051 + h_parent = dget(au_h_dptr(parent, bdst));
6052 + au_set_h_dptr(parent, bdst, dget(h_orph));
6053 + h_tmpdir = d_inode(h_orph);
6054 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6056 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6057 + /* todo: au_h_open_pre()? */
6059 + pin_orig = cpg->pin;
6060 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6061 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6062 + cpg->pin = &wh_pin;
6065 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
6066 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6067 + err = au_cpup_wh(cpg, file);
6069 + struct au_cpup_wh_args args = {
6074 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6075 + if (unlikely(wkq_err))
6080 + inode_unlock(h_tmpdir);
6081 + /* todo: au_h_open_post()? */
6082 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6083 + au_set_h_dptr(parent, bdst, h_parent);
6084 + AuDebugOn(!pin_orig);
6085 + cpg->pin = pin_orig;
6093 +/* ---------------------------------------------------------------------- */
6096 + * generic routine for both of copy-up and copy-down.
6098 +/* cf. revalidate function in file.c */
6099 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6100 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6101 + struct au_pin *pin,
6102 + struct dentry *h_parent, void *arg),
6106 + struct au_pin pin;
6107 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6110 + parent = dget_parent(dentry);
6111 + if (IS_ROOT(parent))
6114 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6115 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6117 + /* do not use au_dpage */
6118 + real_parent = parent;
6121 + parent = dget_parent(dentry);
6122 + h_parent = au_h_dptr(parent, bdst);
6124 + goto out; /* success */
6126 + /* find top dir which is necessary to cpup */
6130 + parent = dget_parent(d);
6131 + di_read_lock_parent3(parent, !AuLock_IR);
6132 + h_parent = au_h_dptr(parent, bdst);
6133 + di_read_unlock(parent, !AuLock_IR);
6134 + } while (!h_parent);
6136 + if (d != real_parent)
6137 + di_write_lock_child3(d);
6139 + /* somebody else might create while we were sleeping */
6140 + h_dentry = au_h_dptr(d, bdst);
6141 + if (!h_dentry || d_is_negative(h_dentry)) {
6143 + au_update_dbtop(d);
6145 + au_pin_set_dentry(&pin, d);
6146 + err = au_do_pin(&pin);
6148 + err = cp(d, bdst, &pin, h_parent, arg);
6153 + if (d != real_parent)
6154 + di_write_unlock(d);
6155 + if (unlikely(err))
6164 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6165 + struct au_pin *pin,
6166 + struct dentry *h_parent __maybe_unused,
6167 + void *arg __maybe_unused)
6169 + struct au_cp_generic cpg = {
6175 + .flags = AuCpup_DTIME
6177 + return au_sio_cpup_simple(&cpg);
6180 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6182 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6185 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6188 + struct dentry *parent;
6189 + struct inode *dir;
6191 + parent = dget_parent(dentry);
6192 + dir = d_inode(parent);
6194 + if (au_h_iptr(dir, bdst))
6197 + di_read_unlock(parent, AuLock_IR);
6198 + di_write_lock_parent(parent);
6199 + /* someone else might change our inode while we were sleeping */
6200 + if (!au_h_iptr(dir, bdst))
6201 + err = au_cpup_dirs(dentry, bdst);
6202 + di_downgrade_lock(parent, AuLock_IR);
6208 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6209 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6210 +++ linux/fs/aufs/cpup.h 2021-12-03 15:38:59.933313976 +0100
6212 +/* SPDX-License-Identifier: GPL-2.0 */
6214 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6216 + * This program, aufs is free software; you can redistribute it and/or modify
6217 + * it under the terms of the GNU General Public License as published by
6218 + * the Free Software Foundation; either version 2 of the License, or
6219 + * (at your option) any later version.
6221 + * This program is distributed in the hope that it will be useful,
6222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6224 + * GNU General Public License for more details.
6226 + * You should have received a copy of the GNU General Public License
6227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6231 + * copy-up/down functions
6234 +#ifndef __AUFS_CPUP_H__
6235 +#define __AUFS_CPUP_H__
6239 +#include <linux/path.h>
6245 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6246 +void au_cpup_attr_timesizes(struct inode *inode);
6247 +void au_cpup_attr_nlink(struct inode *inode, int force);
6248 +void au_cpup_attr_changeable(struct inode *inode);
6249 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6250 +void au_cpup_attr_all(struct inode *inode, int force);
6252 +/* ---------------------------------------------------------------------- */
6254 +struct au_cp_generic {
6255 + struct dentry *dentry;
6256 + aufs_bindex_t bdst, bsrc;
6258 + struct au_pin *pin;
6259 + unsigned int flags;
6263 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6264 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6266 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6267 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6269 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6271 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6272 + the branch is marked as RO */
6274 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6275 +#undef AuCpup_HOPEN
6276 +#define AuCpup_HOPEN 0
6279 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6280 +#define au_fset_cpup(flags, name) \
6281 + do { (flags) |= AuCpup_##name; } while (0)
6282 +#define au_fclr_cpup(flags, name) \
6283 + do { (flags) &= ~AuCpup_##name; } while (0)
6285 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6286 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6287 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6288 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6290 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6291 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6292 + struct au_pin *pin,
6293 + struct dentry *h_parent, void *arg),
6295 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6296 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6298 +/* ---------------------------------------------------------------------- */
6300 +/* keep timestamps when copyup */
6302 + struct dentry *dt_dentry;
6303 + struct path dt_h_path;
6304 + struct timespec64 dt_atime, dt_mtime;
6306 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6307 + struct path *h_path);
6308 +void au_dtime_revert(struct au_dtime *dt);
6310 +#endif /* __KERNEL__ */
6311 +#endif /* __AUFS_CPUP_H__ */
6312 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6313 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6314 +++ linux/fs/aufs/dbgaufs.c 2021-12-03 15:38:59.933313976 +0100
6316 +// SPDX-License-Identifier: GPL-2.0
6318 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6320 + * This program, aufs is free software; you can redistribute it and/or modify
6321 + * it under the terms of the GNU General Public License as published by
6322 + * the Free Software Foundation; either version 2 of the License, or
6323 + * (at your option) any later version.
6325 + * This program is distributed in the hope that it will be useful,
6326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6328 + * GNU General Public License for more details.
6330 + * You should have received a copy of the GNU General Public License
6331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6335 + * debugfs interface
6338 +#include <linux/debugfs.h>
6341 +#ifndef CONFIG_SYSFS
6342 +#error DEBUG_FS depends upon SYSFS
6345 +static struct dentry *dbgaufs;
6346 +static const mode_t dbgaufs_mode = 0444;
6348 +/* 20 is max digits length of ulong 64 */
6349 +struct dbgaufs_arg {
6355 + * common function for all XINO files
6357 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6358 + struct file *file)
6362 + p = file->private_data;
6364 + /* this is struct dbgaufs_arg */
6365 + AuDebugOn(!au_kfree_sz_test(p));
6366 + au_kfree_do_rcu(p);
6371 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6376 + struct dbgaufs_arg *p;
6379 + p = kmalloc(sizeof(*p), GFP_NOFS);
6385 + file->private_data = p;
6389 + err = vfsub_getattr(&xf->f_path, &st);
6393 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6394 + cnt, st.blocks, st.blksize,
6395 + (long long)st.size);
6397 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6398 + st.blocks, st.blksize,
6399 + (long long)st.size);
6400 + AuDebugOn(p->n >= sizeof(p->a));
6402 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6410 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6411 + size_t count, loff_t *ppos)
6413 + struct dbgaufs_arg *p;
6415 + p = file->private_data;
6416 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6419 +/* ---------------------------------------------------------------------- */
6421 +struct dbgaufs_plink_arg {
6426 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6427 + struct file *file)
6429 + free_page((unsigned long)file->private_data);
6433 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6435 + int err, i, limit;
6436 + unsigned long n, sum;
6437 + struct dbgaufs_plink_arg *p;
6438 + struct au_sbinfo *sbinfo;
6439 + struct super_block *sb;
6440 + struct hlist_bl_head *hbl;
6443 + p = (void *)get_zeroed_page(GFP_NOFS);
6448 + sbinfo = inode->i_private;
6449 + sb = sbinfo->si_sb;
6450 + si_noflush_read_lock(sb);
6451 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6452 + limit = PAGE_SIZE - sizeof(p->n);
6454 + /* the number of buckets */
6455 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6460 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6462 + n = au_hbl_count(hbl);
6465 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6468 + if (unlikely(limit <= 0))
6471 + p->a[p->n - 1] = '\n';
6473 + /* the sum of plinks */
6474 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6477 + if (unlikely(limit <= 0))
6480 +#define str "1\n0\n0\n"
6481 + p->n = sizeof(str) - 1;
6482 + strcpy(p->a, str);
6485 + si_read_unlock(sb);
6488 + file->private_data = p;
6489 + goto out; /* success */
6492 + free_page((unsigned long)p);
6497 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6498 + size_t count, loff_t *ppos)
6500 + struct dbgaufs_plink_arg *p;
6502 + p = file->private_data;
6503 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6506 +static const struct file_operations dbgaufs_plink_fop = {
6507 + .owner = THIS_MODULE,
6508 + .open = dbgaufs_plink_open,
6509 + .release = dbgaufs_plink_release,
6510 + .read = dbgaufs_plink_read
6513 +/* ---------------------------------------------------------------------- */
6515 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6518 + struct au_sbinfo *sbinfo;
6519 + struct super_block *sb;
6521 + sbinfo = inode->i_private;
6522 + sb = sbinfo->si_sb;
6523 + si_noflush_read_lock(sb);
6524 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6525 + si_read_unlock(sb);
6529 +static const struct file_operations dbgaufs_xib_fop = {
6530 + .owner = THIS_MODULE,
6531 + .open = dbgaufs_xib_open,
6532 + .release = dbgaufs_xi_release,
6533 + .read = dbgaufs_xi_read
6536 +/* ---------------------------------------------------------------------- */
6538 +#define DbgaufsXi_PREFIX "xi"
6540 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6544 + aufs_bindex_t bindex;
6545 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6546 + struct au_sbinfo *sbinfo;
6547 + struct super_block *sb;
6548 + struct au_xino *xi;
6550 + struct qstr *name;
6551 + struct au_branch *br;
6554 + name = &file->f_path.dentry->d_name;
6555 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6556 + || memcmp(name->name, DbgaufsXi_PREFIX,
6557 + sizeof(DbgaufsXi_PREFIX) - 1)))
6560 + AuDebugOn(name->len >= sizeof(a));
6561 + memcpy(a, name->name, name->len);
6562 + a[name->len] = '\0';
6563 + p = strchr(a, '-');
6566 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6567 + if (unlikely(err))
6572 + err = kstrtol(p + 1, 10, &l);
6573 + if (unlikely(err))
6579 + sbinfo = inode->i_private;
6580 + sb = sbinfo->si_sb;
6581 + si_noflush_read_lock(sb);
6582 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6584 + br = au_sbr(sb, bindex);
6586 + if (unlikely(idx >= xi->xi_nfile))
6588 + xf = au_xino_file(xi, idx);
6590 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6591 + au_xino_count(br));
6594 + si_read_unlock(sb);
6600 +static const struct file_operations dbgaufs_xino_fop = {
6601 + .owner = THIS_MODULE,
6602 + .open = dbgaufs_xino_open,
6603 + .release = dbgaufs_xi_release,
6604 + .read = dbgaufs_xi_read
6607 +void dbgaufs_xino_del(struct au_branch *br)
6609 + struct dentry *dbgaufs;
6611 + dbgaufs = br->br_dbgaufs;
6615 + br->br_dbgaufs = NULL;
6616 + /* debugfs acquires the parent i_mutex */
6618 + debugfs_remove(dbgaufs);
6622 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6624 + aufs_bindex_t bbot;
6625 + struct au_branch *br;
6627 + if (!au_sbi(sb)->si_dbgaufs)
6630 + bbot = au_sbbot(sb);
6631 + for (; bindex <= bbot; bindex++) {
6632 + br = au_sbr(sb, bindex);
6633 + dbgaufs_xino_del(br);
6637 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6638 + unsigned int idx, struct dentry *parent,
6639 + struct au_sbinfo *sbinfo)
6641 + struct au_branch *br;
6643 + /* "xi" bindex(5) "-" idx(2) NULL */
6644 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6647 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6649 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6651 + br = au_sbr(sb, bindex);
6652 + if (br->br_dbgaufs) {
6653 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6655 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6656 + /* debugfs acquires the parent i_mutex */
6658 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6662 + pr_warn("failed renaming %pd/%s, ignored.\n",
6667 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6668 + sbinfo, &dbgaufs_xino_fop);
6670 + if (unlikely(!br->br_dbgaufs))
6671 + pr_warn("failed creating %pd/%s, ignored.\n",
6676 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6677 + struct dentry *parent, struct au_sbinfo *sbinfo)
6679 + struct au_branch *br;
6680 + struct au_xino *xi;
6683 + br = au_sbr(sb, bindex);
6685 + for (u = 0; u < xi->xi_nfile; u++)
6686 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6689 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6691 + struct au_sbinfo *sbinfo;
6692 + struct dentry *parent;
6693 + aufs_bindex_t bbot;
6695 + if (!au_opt_test(au_mntflags(sb), XINO))
6698 + sbinfo = au_sbi(sb);
6699 + parent = sbinfo->si_dbgaufs;
6703 + bbot = au_sbbot(sb);
6705 + for (; bindex <= bbot; bindex++)
6706 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6708 + for (; bbot >= bindex; bbot--)
6709 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6712 +/* ---------------------------------------------------------------------- */
6714 +#ifdef CONFIG_AUFS_EXPORT
6715 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6718 + struct au_sbinfo *sbinfo;
6719 + struct super_block *sb;
6721 + sbinfo = inode->i_private;
6722 + sb = sbinfo->si_sb;
6723 + si_noflush_read_lock(sb);
6724 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6725 + si_read_unlock(sb);
6729 +static const struct file_operations dbgaufs_xigen_fop = {
6730 + .owner = THIS_MODULE,
6731 + .open = dbgaufs_xigen_open,
6732 + .release = dbgaufs_xi_release,
6733 + .read = dbgaufs_xi_read
6736 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6741 + * This function is a dynamic '__init' function actually,
6742 + * so the tiny check for si_rwsem is unnecessary.
6744 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6747 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6748 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6749 + &dbgaufs_xigen_fop);
6750 + if (sbinfo->si_dbgaufs_xigen)
6756 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6760 +#endif /* CONFIG_AUFS_EXPORT */
6762 +/* ---------------------------------------------------------------------- */
6764 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6767 + * This function is a dynamic '__fin' function actually,
6768 + * so the tiny check for si_rwsem is unnecessary.
6770 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6772 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6773 + sbinfo->si_dbgaufs = NULL;
6776 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6779 + char name[SysaufsSiNameLen];
6782 + * This function is a dynamic '__init' function actually,
6783 + * so the tiny check for si_rwsem is unnecessary.
6785 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6789 + AuErr1("/debug/aufs is uninitialized\n");
6794 + sysaufs_name(sbinfo, name);
6795 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6796 + if (unlikely(!sbinfo->si_dbgaufs))
6799 + /* regardless plink/noplink option */
6800 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6801 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6802 + &dbgaufs_plink_fop);
6803 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6806 + /* regardless xino/noxino option */
6807 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6808 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6809 + &dbgaufs_xib_fop);
6810 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6813 + err = dbgaufs_xigen_init(sbinfo);
6815 + goto out; /* success */
6818 + dbgaufs_si_fin(sbinfo);
6820 + if (unlikely(err))
6821 + pr_err("debugfs/aufs failed\n");
6825 +/* ---------------------------------------------------------------------- */
6827 +void dbgaufs_fin(void)
6829 + debugfs_remove(dbgaufs);
6832 +int __init dbgaufs_init(void)
6837 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6842 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6843 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6844 +++ linux/fs/aufs/dbgaufs.h 2021-12-03 15:38:59.933313976 +0100
6846 +/* SPDX-License-Identifier: GPL-2.0 */
6848 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6850 + * This program, aufs is free software; you can redistribute it and/or modify
6851 + * it under the terms of the GNU General Public License as published by
6852 + * the Free Software Foundation; either version 2 of the License, or
6853 + * (at your option) any later version.
6855 + * This program is distributed in the hope that it will be useful,
6856 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6857 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6858 + * GNU General Public License for more details.
6860 + * You should have received a copy of the GNU General Public License
6861 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6865 + * debugfs interface
6868 +#ifndef __DBGAUFS_H__
6869 +#define __DBGAUFS_H__
6873 +struct super_block;
6877 +#ifdef CONFIG_DEBUG_FS
6879 +void dbgaufs_xino_del(struct au_branch *br);
6880 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6881 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6882 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6883 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6884 +void dbgaufs_fin(void);
6885 +int __init dbgaufs_init(void);
6887 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6888 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6889 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6891 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6892 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6893 +AuStubVoid(dbgaufs_fin, void)
6894 +AuStubInt0(__init dbgaufs_init, void)
6895 +#endif /* CONFIG_DEBUG_FS */
6897 +#endif /* __KERNEL__ */
6898 +#endif /* __DBGAUFS_H__ */
6899 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6900 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6901 +++ linux/fs/aufs/dcsub.c 2021-12-03 15:38:59.933313976 +0100
6903 +// SPDX-License-Identifier: GPL-2.0
6905 + * Copyright (C) 2005-2021 Junjiro R. Okajima
6907 + * This program, aufs is free software; you can redistribute it and/or modify
6908 + * it under the terms of the GNU General Public License as published by
6909 + * the Free Software Foundation; either version 2 of the License, or
6910 + * (at your option) any later version.
6912 + * This program is distributed in the hope that it will be useful,
6913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6915 + * GNU General Public License for more details.
6917 + * You should have received a copy of the GNU General Public License
6918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6922 + * sub-routines for dentry cache
6927 +static void au_dpage_free(struct au_dpage *dpage)
6930 + struct dentry **p;
6932 + p = dpage->dentries;
6933 + for (i = 0; i < dpage->ndentry; i++)
6935 + free_page((unsigned long)dpage->dentries);
6938 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6944 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6945 + if (unlikely(!dpages->dpages))
6948 + p = (void *)__get_free_page(gfp);
6952 + dpages->dpages[0].ndentry = 0;
6953 + dpages->dpages[0].dentries = p;
6954 + dpages->ndpage = 1;
6955 + return 0; /* success */
6958 + au_kfree_try_rcu(dpages->dpages);
6963 +void au_dpages_free(struct au_dcsub_pages *dpages)
6966 + struct au_dpage *p;
6968 + p = dpages->dpages;
6969 + for (i = 0; i < dpages->ndpage; i++)
6970 + au_dpage_free(p++);
6971 + au_kfree_try_rcu(dpages->dpages);
6974 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6975 + struct dentry *dentry, gfp_t gfp)
6978 + struct au_dpage *dpage;
6981 + dpage = dpages->dpages + dpages->ndpage - 1;
6982 + sz = PAGE_SIZE / sizeof(dentry);
6983 + if (unlikely(dpage->ndentry >= sz)) {
6984 + AuLabel(new dpage);
6986 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6987 + p = au_kzrealloc(dpages->dpages, sz,
6988 + sz + sizeof(*dpages->dpages), gfp,
6993 + dpages->dpages = p;
6994 + dpage = dpages->dpages + dpages->ndpage;
6995 + p = (void *)__get_free_page(gfp);
6999 + dpage->ndentry = 0;
7000 + dpage->dentries = p;
7004 + AuDebugOn(au_dcount(dentry) <= 0);
7005 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7006 + return 0; /* success */
7012 +/* todo: BAD approach */
7013 +/* copied from linux/fs/dcache.c */
7021 +extern void d_walk(struct dentry *parent, void *data,
7022 + enum d_walk_ret (*enter)(void *, struct dentry *));
7024 +struct ac_dpages_arg {
7026 + struct au_dcsub_pages *dpages;
7027 + struct super_block *sb;
7028 + au_dpages_test test;
7032 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7034 + enum d_walk_ret ret;
7035 + struct ac_dpages_arg *arg = _arg;
7037 + ret = D_WALK_CONTINUE;
7038 + if (dentry->d_sb == arg->sb
7039 + && !IS_ROOT(dentry)
7040 + && au_dcount(dentry) > 0
7042 + && (!arg->test || arg->test(dentry, arg->arg))) {
7043 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7044 + if (unlikely(arg->err))
7045 + ret = D_WALK_QUIT;
7051 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7052 + au_dpages_test test, void *arg)
7054 + struct ac_dpages_arg args = {
7062 + d_walk(root, &args, au_call_dpages_append);
7067 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7068 + int do_include, au_dpages_test test, void *arg)
7073 + write_seqlock(&rename_lock);
7074 + spin_lock(&dentry->d_lock);
7076 + && au_dcount(dentry) > 0
7077 + && (!test || test(dentry, arg)))
7078 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7079 + spin_unlock(&dentry->d_lock);
7080 + if (unlikely(err))
7084 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7087 + while (!IS_ROOT(dentry)) {
7088 + dentry = dentry->d_parent; /* rename_lock is locked */
7089 + spin_lock(&dentry->d_lock);
7090 + if (au_dcount(dentry) > 0
7091 + && (!test || test(dentry, arg)))
7092 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7093 + spin_unlock(&dentry->d_lock);
7094 + if (unlikely(err))
7099 + write_sequnlock(&rename_lock);
7103 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7105 + return au_di(dentry) && dentry->d_sb == arg;
7108 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7109 + struct dentry *dentry, int do_include)
7111 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7112 + au_dcsub_dpages_aufs, dentry->d_sb);
7115 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7117 + struct path path[2] = {
7126 + return path_is_under(path + 0, path + 1);
7128 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7129 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7130 +++ linux/fs/aufs/dcsub.h 2021-12-03 15:38:59.933313976 +0100
7132 +/* SPDX-License-Identifier: GPL-2.0 */
7134 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7136 + * This program, aufs is free software; you can redistribute it and/or modify
7137 + * it under the terms of the GNU General Public License as published by
7138 + * the Free Software Foundation; either version 2 of the License, or
7139 + * (at your option) any later version.
7141 + * This program is distributed in the hope that it will be useful,
7142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7144 + * GNU General Public License for more details.
7146 + * You should have received a copy of the GNU General Public License
7147 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7151 + * sub-routines for dentry cache
7154 +#ifndef __AUFS_DCSUB_H__
7155 +#define __AUFS_DCSUB_H__
7159 +#include <linux/dcache.h>
7160 +#include <linux/fs.h>
7164 + struct dentry **dentries;
7167 +struct au_dcsub_pages {
7169 + struct au_dpage *dpages;
7172 +/* ---------------------------------------------------------------------- */
7175 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7176 +void au_dpages_free(struct au_dcsub_pages *dpages);
7177 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7178 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7179 + au_dpages_test test, void *arg);
7180 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7181 + int do_include, au_dpages_test test, void *arg);
7182 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7183 + struct dentry *dentry, int do_include);
7184 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7186 +/* ---------------------------------------------------------------------- */
7189 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7190 + * include/linux/dcache.h. Try them (in the future).
7193 +static inline int au_d_hashed_positive(struct dentry *d)
7196 + struct inode *inode = d_inode(d);
7199 + if (unlikely(d_unhashed(d)
7200 + || d_is_negative(d)
7201 + || !inode->i_nlink))
7206 +static inline int au_d_linkable(struct dentry *d)
7209 + struct inode *inode = d_inode(d);
7211 + err = au_d_hashed_positive(d);
7213 + && d_is_positive(d)
7214 + && (inode->i_state & I_LINKABLE))
7219 +static inline int au_d_alive(struct dentry *d)
7222 + struct inode *inode;
7226 + err = au_d_hashed_positive(d);
7228 + inode = d_inode(d);
7229 + if (unlikely(d_unlinked(d)
7230 + || d_is_negative(d)
7231 + || !inode->i_nlink))
7237 +static inline int au_alive_dir(struct dentry *d)
7241 + err = au_d_alive(d);
7242 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7247 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7249 + return a->len == b->len
7250 + && !memcmp(a->name, b->name, a->len);
7255 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7257 + * the type of d_lockref.count became int, but the inlined function d_count()
7258 + * still returns unsigned int.
7259 + * I don't know why. Maybe it is for every d_count() users?
7260 + * Anyway au_dcount() lives on.
7262 +static inline int au_dcount(struct dentry *d)
7264 + return (int)d_count(d);
7267 +#endif /* __KERNEL__ */
7268 +#endif /* __AUFS_DCSUB_H__ */
7269 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7270 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7271 +++ linux/fs/aufs/debug.c 2021-12-03 15:38:59.933313976 +0100
7273 +// SPDX-License-Identifier: GPL-2.0
7275 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7277 + * This program, aufs is free software; you can redistribute it and/or modify
7278 + * it under the terms of the GNU General Public License as published by
7279 + * the Free Software Foundation; either version 2 of the License, or
7280 + * (at your option) any later version.
7282 + * This program is distributed in the hope that it will be useful,
7283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7285 + * GNU General Public License for more details.
7287 + * You should have received a copy of the GNU General Public License
7288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7292 + * debug print functions
7295 +#include <linux/iversion.h>
7298 +/* Returns 0, or -errno. arg is in kp->arg. */
7299 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7303 + err = kstrtoint(val, 0, &n);
7313 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7314 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7319 + return sprintf(buffer, "%d", atomic_read(a));
7322 +static struct kernel_param_ops param_ops_atomic_t = {
7323 + .set = param_atomic_t_set,
7324 + .get = param_atomic_t_get
7325 + /* void (*free)(void *arg) */
7328 +atomic_t aufs_debug = ATOMIC_INIT(0);
7329 +MODULE_PARM_DESC(debug, "debug print");
7330 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7332 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7333 +char *au_plevel = KERN_DEBUG;
7334 +#define dpri(fmt, ...) do { \
7336 + && strcmp(au_plevel, KERN_DEBUG)) \
7337 + || au_debug_test()) \
7338 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7341 +/* ---------------------------------------------------------------------- */
7343 +void au_dpri_whlist(struct au_nhash *whlist)
7345 + unsigned long ul, n;
7346 + struct hlist_head *head;
7347 + struct au_vdir_wh *pos;
7349 + n = whlist->nh_num;
7350 + head = whlist->nh_head;
7351 + for (ul = 0; ul < n; ul++) {
7352 + hlist_for_each_entry(pos, head, wh_hash)
7353 + dpri("b%d, %.*s, %d\n",
7355 + pos->wh_str.len, pos->wh_str.name,
7361 +void au_dpri_vdir(struct au_vdir *vdir)
7364 + union au_vdir_deblk_p p;
7367 + if (!vdir || IS_ERR(vdir)) {
7368 + dpri("err %ld\n", PTR_ERR(vdir));
7372 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7373 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7374 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7375 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7376 + p.deblk = vdir->vd_deblk[ul];
7378 + dpri("[%lu]: %p\n", ul, o);
7382 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7383 + struct dentry *wh)
7388 + if (!inode || IS_ERR(inode)) {
7389 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7393 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7394 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7395 + && sizeof(inode->i_blocks) != sizeof(u64));
7397 + n = (void *)wh->d_name.name;
7398 + l = wh->d_name.len;
7401 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7402 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7404 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7405 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7406 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7407 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7408 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7409 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7410 + inode->i_generation,
7411 + l ? ", wh " : "", l, n);
7415 +void au_dpri_inode(struct inode *inode)
7417 + struct au_iinfo *iinfo;
7418 + struct au_hinode *hi;
7419 + aufs_bindex_t bindex;
7422 + err = do_pri_inode(-1, inode, -1, NULL);
7423 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7426 + iinfo = au_ii(inode);
7427 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7428 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7429 + if (iinfo->ii_btop < 0)
7432 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7433 + hi = au_hinode(iinfo, bindex);
7435 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7439 +void au_dpri_dalias(struct inode *inode)
7443 + spin_lock(&inode->i_lock);
7444 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7445 + au_dpri_dentry(d);
7446 + spin_unlock(&inode->i_lock);
7449 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7451 + struct dentry *wh = NULL;
7453 + struct inode *inode;
7454 + struct au_iinfo *iinfo;
7455 + struct au_hinode *hi;
7457 + if (!dentry || IS_ERR(dentry)) {
7458 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7461 + /* do not call dget_parent() here */
7462 + /* note: access d_xxx without d_lock */
7463 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7464 + bindex, dentry, dentry,
7465 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7466 + au_dcount(dentry), dentry->d_flags,
7467 + d_unhashed(dentry) ? "un" : "");
7470 + if (d_is_positive(dentry))
7471 + inode = d_inode(dentry);
7473 + && au_test_aufs(dentry->d_sb)
7475 + && !au_is_bad_inode(inode)) {
7476 + iinfo = au_ii(inode);
7477 + hi = au_hinode(iinfo, bindex);
7479 + wh = hi->hi_whdentry;
7481 + do_pri_inode(bindex, inode, hn, wh);
7485 +void au_dpri_dentry(struct dentry *dentry)
7487 + struct au_dinfo *dinfo;
7488 + aufs_bindex_t bindex;
7491 + err = do_pri_dentry(-1, dentry);
7492 + if (err || !au_test_aufs(dentry->d_sb))
7495 + dinfo = au_di(dentry);
7498 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7499 + dinfo->di_btop, dinfo->di_bbot,
7500 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7501 + dinfo->di_tmpfile);
7502 + if (dinfo->di_btop < 0)
7504 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7505 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7508 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7512 + if (!file || IS_ERR(file)) {
7513 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7518 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7519 + && au_test_aufs(file->f_path.dentry->d_sb)
7521 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7522 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7523 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7524 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7525 + file->f_version, file->f_pos, a);
7526 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7527 + do_pri_dentry(bindex, file->f_path.dentry);
7531 +void au_dpri_file(struct file *file)
7533 + struct au_finfo *finfo;
7534 + struct au_fidir *fidir;
7535 + struct au_hfile *hfile;
7536 + aufs_bindex_t bindex;
7539 + err = do_pri_file(-1, file);
7541 + || IS_ERR_OR_NULL(file->f_path.dentry)
7542 + || !au_test_aufs(file->f_path.dentry->d_sb))
7545 + finfo = au_fi(file);
7548 + if (finfo->fi_btop < 0)
7550 + fidir = finfo->fi_hdir;
7552 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7554 + for (bindex = finfo->fi_btop;
7555 + bindex >= 0 && bindex <= fidir->fd_bbot;
7557 + hfile = fidir->fd_hfile + bindex;
7558 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7562 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7564 + struct vfsmount *mnt;
7565 + struct super_block *sb;
7567 + if (!br || IS_ERR(br))
7569 + mnt = au_br_mnt(br);
7570 + if (!mnt || IS_ERR(mnt))
7573 + if (!sb || IS_ERR(sb))
7576 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7577 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7579 + bindex, br->br_perm, br->br_id, br->br_wbr,
7580 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7581 + sb->s_flags, sb->s_count,
7582 + atomic_read(&sb->s_active),
7583 + !!au_xino_file(br->br_xino, /*idx*/-1));
7587 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7591 +void au_dpri_sb(struct super_block *sb)
7593 + struct au_sbinfo *sbinfo;
7594 + aufs_bindex_t bindex;
7596 + /* to reduce stack size */
7598 + struct vfsmount mnt;
7599 + struct au_branch fake;
7602 + /* this function can be called from magic sysrq */
7603 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7604 + if (unlikely(!a)) {
7605 + dpri("no memory\n");
7609 + a->mnt.mnt_sb = sb;
7610 + a->fake.br_path.mnt = &a->mnt;
7611 + err = do_pri_br(-1, &a->fake);
7613 + dpri("dev 0x%x\n", sb->s_dev);
7614 + if (err || !au_test_aufs(sb))
7617 + sbinfo = au_sbi(sb);
7620 + dpri("nw %d, gen %u, kobj %d\n",
7621 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7622 + kref_read(&sbinfo->si_kobj.kref));
7623 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7624 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7627 +/* ---------------------------------------------------------------------- */
7629 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7631 + struct inode *h_inode, *inode = d_inode(dentry);
7632 + struct dentry *h_dentry;
7633 + aufs_bindex_t bindex, bbot, bi;
7635 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7638 + bbot = au_dbbot(dentry);
7639 + bi = au_ibbot(inode);
7642 + bindex = au_dbtop(dentry);
7643 + bi = au_ibtop(inode);
7647 + for (; bindex <= bbot; bindex++) {
7648 + h_dentry = au_h_dptr(dentry, bindex);
7651 + h_inode = au_h_iptr(inode, bindex);
7652 + if (unlikely(h_inode != d_inode(h_dentry))) {
7654 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7655 + AuDbgDentry(dentry);
7656 + AuDbgInode(inode);
7658 + if (au_test_fuse(h_inode->i_sb))
7666 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7669 + struct au_dcsub_pages dpages;
7670 + struct au_dpage *dpage;
7671 + struct dentry **dentries;
7673 + err = au_dpages_init(&dpages, GFP_NOFS);
7675 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7677 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7678 + dpage = dpages.dpages + i;
7679 + dentries = dpage->dentries;
7680 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7681 + AuDebugOn(au_digen_test(dentries[j], sigen));
7683 + au_dpages_free(&dpages);
7686 +void au_dbg_verify_kthread(void)
7688 + if (au_wkq_test()) {
7691 + * It may be recursive, but udba=notify between two aufs mounts,
7692 + * where a single ro branch is shared, is not a problem.
7698 +/* ---------------------------------------------------------------------- */
7700 +int __init au_debug_init(void)
7702 + aufs_bindex_t bindex;
7703 + struct au_vdir_destr destr;
7706 + AuDebugOn(bindex >= 0);
7709 + AuDebugOn(destr.len < NAME_MAX);
7711 +#ifdef CONFIG_4KSTACKS
7712 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7717 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7718 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7719 +++ linux/fs/aufs/debug.h 2021-12-03 15:38:59.933313976 +0100
7721 +/* SPDX-License-Identifier: GPL-2.0 */
7723 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7725 + * This program, aufs is free software; you can redistribute it and/or modify
7726 + * it under the terms of the GNU General Public License as published by
7727 + * the Free Software Foundation; either version 2 of the License, or
7728 + * (at your option) any later version.
7730 + * This program is distributed in the hope that it will be useful,
7731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7733 + * GNU General Public License for more details.
7735 + * You should have received a copy of the GNU General Public License
7736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7740 + * debug print functions
7743 +#ifndef __AUFS_DEBUG_H__
7744 +#define __AUFS_DEBUG_H__
7748 +#include <linux/atomic.h>
7749 +#include <linux/module.h>
7750 +#include <linux/kallsyms.h>
7751 +#include <linux/sysrq.h>
7753 +#ifdef CONFIG_AUFS_DEBUG
7754 +#define AuDebugOn(a) BUG_ON(a)
7756 +/* module parameter */
7757 +extern atomic_t aufs_debug;
7758 +static inline void au_debug_on(void)
7760 + atomic_inc(&aufs_debug);
7762 +static inline void au_debug_off(void)
7764 + atomic_dec_if_positive(&aufs_debug);
7767 +static inline int au_debug_test(void)
7769 + return atomic_read(&aufs_debug) > 0;
7772 +#define AuDebugOn(a) do {} while (0)
7773 +AuStubVoid(au_debug_on, void)
7774 +AuStubVoid(au_debug_off, void)
7775 +AuStubInt0(au_debug_test, void)
7776 +#endif /* CONFIG_AUFS_DEBUG */
7778 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7780 +/* ---------------------------------------------------------------------- */
7784 +#define AuDbg(fmt, ...) do { \
7785 + if (au_debug_test()) \
7786 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7788 +#define AuLabel(l) AuDbg(#l "\n")
7789 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7790 +#define AuWarn1(fmt, ...) do { \
7791 + static unsigned char _c; \
7793 + pr_warn(fmt, ##__VA_ARGS__); \
7796 +#define AuErr1(fmt, ...) do { \
7797 + static unsigned char _c; \
7799 + pr_err(fmt, ##__VA_ARGS__); \
7802 +#define AuIOErr1(fmt, ...) do { \
7803 + static unsigned char _c; \
7805 + AuIOErr(fmt, ##__VA_ARGS__); \
7808 +#define AuUnsupportMsg "This operation is not supported." \
7809 + " Please report this application to aufs-users ML."
7810 +#define AuUnsupport(fmt, ...) do { \
7811 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7815 +#define AuTraceErr(e) do { \
7816 + if (unlikely((e) < 0)) \
7817 + AuDbg("err %d\n", (int)(e)); \
7820 +#define AuTraceErrPtr(p) do { \
7822 + AuDbg("err %ld\n", PTR_ERR(p)); \
7825 +/* dirty macros for debug print, use with "%.*s" and caution */
7826 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7828 +/* ---------------------------------------------------------------------- */
7831 +#ifdef CONFIG_AUFS_DEBUG
7832 +extern struct mutex au_dbg_mtx;
7833 +extern char *au_plevel;
7835 +void au_dpri_whlist(struct au_nhash *whlist);
7837 +void au_dpri_vdir(struct au_vdir *vdir);
7839 +void au_dpri_inode(struct inode *inode);
7840 +void au_dpri_dalias(struct inode *inode);
7841 +void au_dpri_dentry(struct dentry *dentry);
7843 +void au_dpri_file(struct file *filp);
7844 +struct super_block;
7845 +void au_dpri_sb(struct super_block *sb);
7847 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7848 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7849 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7850 +void au_dbg_verify_kthread(void);
7852 +int __init au_debug_init(void);
7854 +#define AuDbgWhlist(w) do { \
7855 + mutex_lock(&au_dbg_mtx); \
7857 + au_dpri_whlist(w); \
7858 + mutex_unlock(&au_dbg_mtx); \
7861 +#define AuDbgVdir(v) do { \
7862 + mutex_lock(&au_dbg_mtx); \
7864 + au_dpri_vdir(v); \
7865 + mutex_unlock(&au_dbg_mtx); \
7868 +#define AuDbgInode(i) do { \
7869 + mutex_lock(&au_dbg_mtx); \
7871 + au_dpri_inode(i); \
7872 + mutex_unlock(&au_dbg_mtx); \
7875 +#define AuDbgDAlias(i) do { \
7876 + mutex_lock(&au_dbg_mtx); \
7878 + au_dpri_dalias(i); \
7879 + mutex_unlock(&au_dbg_mtx); \
7882 +#define AuDbgDentry(d) do { \
7883 + mutex_lock(&au_dbg_mtx); \
7885 + au_dpri_dentry(d); \
7886 + mutex_unlock(&au_dbg_mtx); \
7889 +#define AuDbgFile(f) do { \
7890 + mutex_lock(&au_dbg_mtx); \
7892 + au_dpri_file(f); \
7893 + mutex_unlock(&au_dbg_mtx); \
7896 +#define AuDbgSb(sb) do { \
7897 + mutex_lock(&au_dbg_mtx); \
7898 + AuDbg(#sb "\n"); \
7900 + mutex_unlock(&au_dbg_mtx); \
7903 +#define AuDbgSym(addr) do { \
7904 + char sym[KSYM_SYMBOL_LEN]; \
7905 + sprint_symbol(sym, (unsigned long)addr); \
7906 + AuDbg("%s\n", sym); \
7909 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7910 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7911 +AuStubVoid(au_dbg_verify_kthread, void)
7912 +AuStubInt0(__init au_debug_init, void)
7914 +#define AuDbgWhlist(w) do {} while (0)
7915 +#define AuDbgVdir(v) do {} while (0)
7916 +#define AuDbgInode(i) do {} while (0)
7917 +#define AuDbgDAlias(i) do {} while (0)
7918 +#define AuDbgDentry(d) do {} while (0)
7919 +#define AuDbgFile(f) do {} while (0)
7920 +#define AuDbgSb(sb) do {} while (0)
7921 +#define AuDbgSym(addr) do {} while (0)
7922 +#endif /* CONFIG_AUFS_DEBUG */
7924 +/* ---------------------------------------------------------------------- */
7926 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7927 +int __init au_sysrq_init(void);
7928 +void au_sysrq_fin(void);
7930 +#ifdef CONFIG_HW_CONSOLE
7931 +#define au_dbg_blocked() do { \
7933 + handle_sysrq('w'); \
7936 +AuStubVoid(au_dbg_blocked, void)
7940 +AuStubInt0(__init au_sysrq_init, void)
7941 +AuStubVoid(au_sysrq_fin, void)
7942 +AuStubVoid(au_dbg_blocked, void)
7943 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7945 +#endif /* __KERNEL__ */
7946 +#endif /* __AUFS_DEBUG_H__ */
7947 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7948 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7949 +++ linux/fs/aufs/dentry.c 2021-12-03 15:38:59.933313976 +0100
7951 +// SPDX-License-Identifier: GPL-2.0
7953 + * Copyright (C) 2005-2021 Junjiro R. Okajima
7955 + * This program, aufs is free software; you can redistribute it and/or modify
7956 + * it under the terms of the GNU General Public License as published by
7957 + * the Free Software Foundation; either version 2 of the License, or
7958 + * (at your option) any later version.
7960 + * This program is distributed in the hope that it will be useful,
7961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7963 + * GNU General Public License for more details.
7965 + * You should have received a copy of the GNU General Public License
7966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7970 + * lookup and dentry operations
7973 +#include <linux/iversion.h>
7974 +#include <linux/namei.h>
7978 + * returns positive/negative dentry, NULL or an error.
7979 + * NULL means whiteout-ed or not-found.
7981 +static struct dentry*
7982 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7983 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7985 + struct dentry *h_dentry;
7986 + struct inode *h_inode;
7987 + struct au_branch *br;
7988 + struct path h_path;
7989 + int wh_found, opq;
7990 + unsigned char wh_able;
7991 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7992 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7996 + br = au_sbr(dentry->d_sb, bindex);
7997 + h_path.dentry = h_parent;
7998 + h_path.mnt = au_br_mnt(br);
7999 + wh_able = !!au_br_whable(br->br_perm);
8001 + wh_found = au_wh_test(&h_path, &args->whname, ignore_perm);
8002 + h_dentry = ERR_PTR(wh_found);
8005 + if (unlikely(wh_found < 0))
8008 + /* We found a whiteout */
8009 + /* au_set_dbbot(dentry, bindex); */
8010 + au_set_dbwh(dentry, bindex);
8012 + return NULL; /* success */
8016 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8018 + h_dentry = au_sio_lkup_one(args->name, &h_path);
8019 + if (IS_ERR(h_dentry)) {
8020 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8026 + h_inode = d_inode(h_dentry);
8027 + if (d_is_negative(h_dentry)) {
8030 + } else if (wh_found
8031 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8033 + else if (au_ftest_lkup(args->flags, DIRREN)
8035 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8036 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8037 + (unsigned long long)h_inode->i_ino);
8041 + if (au_dbbot(dentry) <= bindex)
8042 + au_set_dbbot(dentry, bindex);
8043 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8044 + au_set_dbtop(dentry, bindex);
8045 + au_set_h_dptr(dentry, bindex, h_dentry);
8047 + if (!d_is_dir(h_dentry)
8049 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8050 + goto out; /* success */
8052 + h_path.dentry = h_dentry;
8053 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8054 + opq = au_diropq_test(&h_path);
8055 + inode_unlock_shared(h_inode);
8057 + au_set_dbdiropq(dentry, bindex);
8058 + else if (unlikely(opq < 0)) {
8059 + au_set_h_dptr(dentry, bindex, NULL);
8060 + h_dentry = ERR_PTR(opq);
8071 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8073 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8074 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8080 + * returns the number of lower positive dentries,
8081 + * otherwise an error.
8082 + * can be called at unlinking with @type is zero.
8084 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8085 + unsigned int flags)
8087 + int npositive, err;
8088 + aufs_bindex_t bindex, btail, bdiropq;
8089 + unsigned char isdir, dirperm1, dirren;
8090 + struct au_do_lookup_args args = {
8092 + .name = &dentry->d_name
8094 + struct dentry *parent;
8095 + struct super_block *sb;
8097 + sb = dentry->d_sb;
8098 + err = au_test_shwh(sb, args.name);
8099 + if (unlikely(err))
8102 + err = au_wh_name_alloc(&args.whname, args.name);
8103 + if (unlikely(err))
8106 + isdir = !!d_is_dir(dentry);
8107 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8108 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8110 + au_fset_lkup(args.flags, DIRREN);
8113 + parent = dget_parent(dentry);
8114 + btail = au_dbtaildir(parent);
8115 + for (bindex = btop; bindex <= btail; bindex++) {
8116 + struct dentry *h_parent, *h_dentry;
8117 + struct inode *h_inode, *h_dir;
8118 + struct au_branch *br;
8120 + h_dentry = au_h_dptr(dentry, bindex);
8122 + if (d_is_positive(h_dentry))
8126 + h_parent = au_h_dptr(parent, bindex);
8127 + if (!h_parent || !d_is_dir(h_parent))
8131 + /* if the inum matches, then use the prepared name */
8132 + err = au_dr_lkup_name(&args, bindex);
8133 + if (unlikely(err))
8137 + h_dir = d_inode(h_parent);
8138 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8139 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8140 + inode_unlock_shared(h_dir);
8141 + err = PTR_ERR(h_dentry);
8142 + if (IS_ERR(h_dentry))
8145 + au_fclr_lkup(args.flags, ALLOW_NEG);
8147 + au_fset_lkup(args.flags, IGNORE_PERM);
8149 + if (au_dbwh(dentry) == bindex)
8153 + if (d_is_negative(h_dentry))
8155 + h_inode = d_inode(h_dentry);
8158 + args.type = h_inode->i_mode & S_IFMT;
8159 + if (args.type != S_IFDIR)
8162 + /* the type of lower may be different */
8163 + bdiropq = au_dbdiropq(dentry);
8164 + if (bdiropq >= 0 && bdiropq <= bindex)
8167 + br = au_sbr(sb, bindex);
8169 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8170 + /*add_ent*/NULL)) {
8171 + /* prepare next name to lookup */
8172 + err = au_dr_lkup(&args, dentry, bindex);
8173 + if (unlikely(err))
8179 + AuLabel(positive);
8180 + au_update_dbtop(dentry);
8183 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8184 + && au_dbtop(dentry) < 0)) {
8186 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8192 + au_kfree_try_rcu(args.whname.name);
8194 + au_dr_lkup_fin(&args);
8199 +struct dentry *au_sio_lkup_one(struct qstr *name, struct path *ppath)
8201 + struct dentry *dentry;
8204 + if (!au_test_h_perm_sio(d_inode(ppath->dentry), MAY_EXEC))
8205 + dentry = vfsub_lkup_one(name, ppath);
8207 + struct vfsub_lkup_one_args args = {
8213 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8214 + if (unlikely(wkq_err))
8215 + dentry = ERR_PTR(wkq_err);
8222 + * lookup @dentry on @bindex which should be negative.
8224 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8227 + struct dentry *parent, *h_dentry;
8228 + struct au_branch *br;
8229 + struct path h_ppath;
8231 + parent = dget_parent(dentry);
8232 + br = au_sbr(dentry->d_sb, bindex);
8233 + h_ppath.dentry = au_h_dptr(parent, bindex);
8234 + h_ppath.mnt = au_br_mnt(br);
8236 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8238 + h_dentry = au_sio_lkup_one(&dentry->d_name, &h_ppath);
8239 + err = PTR_ERR(h_dentry);
8240 + if (IS_ERR(h_dentry))
8242 + if (unlikely(d_is_positive(h_dentry))) {
8244 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8250 + if (bindex < au_dbtop(dentry))
8251 + au_set_dbtop(dentry, bindex);
8252 + if (au_dbbot(dentry) < bindex)
8253 + au_set_dbbot(dentry, bindex);
8254 + au_set_h_dptr(dentry, bindex, h_dentry);
8261 +/* ---------------------------------------------------------------------- */
8263 +/* subset of struct inode */
8265 + unsigned long i_ino;
8266 + /* unsigned int i_nlink; */
8272 + blkcnt_t i_blocks;
8277 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8279 + ia->i_ino = h_inode->i_ino;
8280 + /* ia->i_nlink = h_inode->i_nlink; */
8281 + ia->i_uid = h_inode->i_uid;
8282 + ia->i_gid = h_inode->i_gid;
8283 + ia->i_version = inode_query_iversion(h_inode);
8285 + ia->i_size = h_inode->i_size;
8286 + ia->i_blocks = h_inode->i_blocks;
8288 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8291 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8293 + return ia->i_ino != h_inode->i_ino
8294 + /* || ia->i_nlink != h_inode->i_nlink */
8295 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8296 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8297 + || !inode_eq_iversion(h_inode, ia->i_version)
8299 + || ia->i_size != h_inode->i_size
8300 + || ia->i_blocks != h_inode->i_blocks
8302 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8305 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8306 + struct au_branch *br)
8309 + struct au_iattr ia;
8310 + struct inode *h_inode;
8311 + struct dentry *h_d;
8312 + struct super_block *h_sb;
8313 + struct path h_ppath;
8316 + memset(&ia, -1, sizeof(ia));
8317 + h_sb = h_dentry->d_sb;
8319 + if (d_is_positive(h_dentry)) {
8320 + h_inode = d_inode(h_dentry);
8321 + au_iattr_save(&ia, h_inode);
8322 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8323 + /* nfs d_revalidate may return 0 for negative dentry */
8324 + /* fuse d_revalidate always return 0 for negative dentry */
8327 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8328 + h_ppath.dentry = h_parent;
8329 + h_ppath.mnt = au_br_mnt(br);
8330 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8331 + err = PTR_ERR(h_d);
8336 + if (unlikely(h_d != h_dentry
8337 + || d_inode(h_d) != h_inode
8338 + || (h_inode && au_iattr_test(&ia, h_inode))))
8339 + err = au_busy_or_stale();
8347 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8348 + struct dentry *h_parent, struct au_branch *br)
8353 + if (udba == AuOpt_UDBA_REVAL
8354 + && !au_test_fs_remote(h_dentry->d_sb)) {
8356 + err = (d_inode(h_dentry->d_parent) != h_dir);
8357 + } else if (udba != AuOpt_UDBA_NONE)
8358 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8363 +/* ---------------------------------------------------------------------- */
8365 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8368 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8369 + struct au_hdentry tmp, *p, *q;
8370 + struct au_dinfo *dinfo;
8371 + struct super_block *sb;
8373 + DiMustWriteLock(dentry);
8375 + sb = dentry->d_sb;
8376 + dinfo = au_di(dentry);
8377 + bbot = dinfo->di_bbot;
8378 + bwh = dinfo->di_bwh;
8379 + bdiropq = dinfo->di_bdiropq;
8380 + bindex = dinfo->di_btop;
8381 + p = au_hdentry(dinfo, bindex);
8382 + for (; bindex <= bbot; bindex++, p++) {
8383 + if (!p->hd_dentry)
8386 + new_bindex = au_br_index(sb, p->hd_id);
8387 + if (new_bindex == bindex)
8390 + if (dinfo->di_bwh == bindex)
8392 + if (dinfo->di_bdiropq == bindex)
8393 + bdiropq = new_bindex;
8394 + if (new_bindex < 0) {
8396 + p->hd_dentry = NULL;
8400 + /* swap two lower dentries, and loop again */
8401 + q = au_hdentry(dinfo, new_bindex);
8405 + if (tmp.hd_dentry) {
8411 + dinfo->di_bwh = -1;
8412 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8413 + dinfo->di_bwh = bwh;
8415 + dinfo->di_bdiropq = -1;
8417 + && bdiropq <= au_sbbot(sb)
8418 + && au_sbr_whable(sb, bdiropq))
8419 + dinfo->di_bdiropq = bdiropq;
8422 + dinfo->di_btop = -1;
8423 + dinfo->di_bbot = -1;
8424 + bbot = au_dbbot(parent);
8426 + p = au_hdentry(dinfo, bindex);
8427 + for (; bindex <= bbot; bindex++, p++)
8428 + if (p->hd_dentry) {
8429 + dinfo->di_btop = bindex;
8433 + if (dinfo->di_btop >= 0) {
8435 + p = au_hdentry(dinfo, bindex);
8436 + for (; bindex >= 0; bindex--, p--)
8437 + if (p->hd_dentry) {
8438 + dinfo->di_bbot = bindex;
8447 +static void au_do_hide(struct dentry *dentry)
8449 + struct inode *inode;
8451 + if (d_really_is_positive(dentry)) {
8452 + inode = d_inode(dentry);
8453 + if (!d_is_dir(dentry)) {
8454 + if (inode->i_nlink && !d_unhashed(dentry))
8455 + drop_nlink(inode);
8457 + clear_nlink(inode);
8458 + /* stop next lookup */
8459 + inode->i_flags |= S_DEAD;
8461 + smp_mb(); /* necessary? */
8466 +static int au_hide_children(struct dentry *parent)
8468 + int err, i, j, ndentry;
8469 + struct au_dcsub_pages dpages;
8470 + struct au_dpage *dpage;
8471 + struct dentry *dentry;
8473 + err = au_dpages_init(&dpages, GFP_NOFS);
8474 + if (unlikely(err))
8476 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8477 + if (unlikely(err))
8480 + /* in reverse order */
8481 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8482 + dpage = dpages.dpages + i;
8483 + ndentry = dpage->ndentry;
8484 + for (j = ndentry - 1; j >= 0; j--) {
8485 + dentry = dpage->dentries[j];
8486 + if (dentry != parent)
8487 + au_do_hide(dentry);
8492 + au_dpages_free(&dpages);
8497 +static void au_hide(struct dentry *dentry)
8501 + AuDbgDentry(dentry);
8502 + if (d_is_dir(dentry)) {
8503 + /* shrink_dcache_parent(dentry); */
8504 + err = au_hide_children(dentry);
8505 + if (unlikely(err))
8506 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8509 + au_do_hide(dentry);
8513 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8515 + * a dirty branch is added
8516 + * - on the top of layers
8517 + * - in the middle of layers
8518 + * - to the bottom of layers
8520 + * on the added branch there exists
8523 + * - a same named entry
8525 + * * negative --> positive
8526 + * * positive --> positive
8527 + * - type is unchanged
8528 + * - type is changed
8530 + * * negative --> negative
8531 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8534 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8535 + struct au_dinfo *tmp)
8538 + aufs_bindex_t bindex, bbot;
8540 + struct dentry *dentry;
8541 + struct inode *inode;
8543 + } orig_h, tmp_h = {
8546 + struct au_hdentry *hd;
8547 + struct inode *inode, *h_inode;
8548 + struct dentry *h_dentry;
8551 + AuDebugOn(dinfo->di_btop < 0);
8553 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8554 + orig_h.inode = NULL;
8555 + if (d_is_positive(orig_h.dentry)) {
8556 + orig_h.inode = d_inode(orig_h.dentry);
8557 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8559 + if (tmp->di_btop >= 0) {
8560 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8561 + if (d_is_positive(tmp_h.dentry)) {
8562 + tmp_h.inode = d_inode(tmp_h.dentry);
8563 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8568 + if (d_really_is_positive(dentry))
8569 + inode = d_inode(dentry);
8570 + if (!orig_h.inode) {
8571 + AuDbg("negative originally\n");
8577 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8578 + AuDebugOn(dinfo->di_bdiropq != -1);
8580 + if (!tmp_h.inode) {
8581 + AuDbg("negative --> negative\n");
8582 + /* should have only one negative lower */
8583 + if (tmp->di_btop >= 0
8584 + && tmp->di_btop < dinfo->di_btop) {
8585 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8586 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8587 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8588 + au_di_cp(dinfo, tmp);
8589 + hd = au_hdentry(tmp, tmp->di_btop);
8590 + au_set_h_dptr(dentry, tmp->di_btop,
8591 + dget(hd->hd_dentry));
8593 + au_dbg_verify_dinode(dentry);
8595 + AuDbg("negative --> positive\n");
8597 + * similar to the behaviour of creating with bypassing
8599 + * unhash it in order to force an error in the
8600 + * succeeding create operation.
8601 + * we should not set S_DEAD here.
8604 + /* au_di_swap(tmp, dinfo); */
8605 + au_dbg_verify_dinode(dentry);
8608 + AuDbg("positive originally\n");
8609 + /* inode may be NULL */
8610 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8611 + if (!tmp_h.inode) {
8612 + AuDbg("positive --> negative\n");
8613 + /* or bypassing aufs */
8615 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8616 + dinfo->di_bwh = tmp->di_bwh;
8618 + err = au_refresh_hinode_self(inode);
8619 + au_dbg_verify_dinode(dentry);
8620 + } else if (orig_h.mode == tmp_h.mode) {
8621 + AuDbg("positive --> positive, same type\n");
8622 + if (!S_ISDIR(orig_h.mode)
8623 + && dinfo->di_btop > tmp->di_btop) {
8625 + * similar to the behaviour of removing and
8630 + err = au_refresh_hinode_self(inode);
8631 + au_dbg_verify_dinode(dentry);
8633 + /* fill empty slots */
8634 + if (dinfo->di_btop > tmp->di_btop)
8635 + dinfo->di_btop = tmp->di_btop;
8636 + if (dinfo->di_bbot < tmp->di_bbot)
8637 + dinfo->di_bbot = tmp->di_bbot;
8638 + dinfo->di_bwh = tmp->di_bwh;
8639 + dinfo->di_bdiropq = tmp->di_bdiropq;
8640 + bbot = dinfo->di_bbot;
8641 + bindex = tmp->di_btop;
8642 + hd = au_hdentry(tmp, bindex);
8643 + for (; bindex <= bbot; bindex++, hd++) {
8644 + if (au_h_dptr(dentry, bindex))
8646 + h_dentry = hd->hd_dentry;
8649 + AuDebugOn(d_is_negative(h_dentry));
8650 + h_inode = d_inode(h_dentry);
8651 + AuDebugOn(orig_h.mode
8652 + != (h_inode->i_mode
8654 + au_set_h_dptr(dentry, bindex,
8658 + err = au_refresh_hinode(inode, dentry);
8659 + au_dbg_verify_dinode(dentry);
8662 + AuDbg("positive --> positive, different type\n");
8663 + /* similar to the behaviour of removing and creating */
8666 + err = au_refresh_hinode_self(inode);
8667 + au_dbg_verify_dinode(dentry);
8675 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8677 + const struct dentry_operations *dop
8678 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8679 + static const unsigned int mask
8680 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8682 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8684 + if (dentry->d_op == dop)
8687 + AuDbg("%pd\n", dentry);
8688 + spin_lock(&dentry->d_lock);
8689 + if (dop == &aufs_dop)
8690 + dentry->d_flags |= mask;
8692 + dentry->d_flags &= ~mask;
8693 + dentry->d_op = dop;
8694 + spin_unlock(&dentry->d_lock);
8697 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8699 + int err, ebrange, nbr;
8700 + unsigned int sigen;
8701 + struct au_dinfo *dinfo, *tmp;
8702 + struct super_block *sb;
8703 + struct inode *inode;
8705 + DiMustWriteLock(dentry);
8706 + AuDebugOn(IS_ROOT(dentry));
8707 + AuDebugOn(d_really_is_negative(parent));
8709 + sb = dentry->d_sb;
8710 + sigen = au_sigen(sb);
8711 + err = au_digen_test(parent, sigen);
8712 + if (unlikely(err))
8715 + nbr = au_sbbot(sb) + 1;
8716 + dinfo = au_di(dentry);
8717 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8718 + if (unlikely(err))
8720 + ebrange = au_dbrange_test(dentry);
8722 + ebrange = au_do_refresh_hdentry(dentry, parent);
8724 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8725 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8726 + if (d_really_is_positive(dentry)) {
8727 + inode = d_inode(dentry);
8728 + err = au_refresh_hinode_self(inode);
8730 + au_dbg_verify_dinode(dentry);
8732 + goto out_dgen; /* success */
8736 + /* temporary dinfo */
8737 + AuDbgDentry(dentry);
8739 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8740 + if (unlikely(!tmp))
8742 + au_di_swap(tmp, dinfo);
8743 + /* returns the number of positive dentries */
8745 + * if current working dir is removed, it returns an error.
8746 + * but the dentry is legal.
8748 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8749 + AuDbgDentry(dentry);
8750 + au_di_swap(tmp, dinfo);
8751 + if (err == -ENOENT)
8754 + /* compare/refresh by dinfo */
8755 + AuDbgDentry(dentry);
8756 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8757 + au_dbg_verify_dinode(dentry);
8760 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8761 + au_rw_write_unlock(&tmp->di_rwsem);
8763 + if (unlikely(err))
8767 + au_update_digen(dentry);
8769 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8770 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8771 + AuDbgDentry(dentry);
8777 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8778 + struct dentry *dentry, aufs_bindex_t bindex)
8783 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8786 + AuDbg("b%d\n", bindex);
8788 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8789 + * due to whiteout and branch permission.
8791 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8792 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8793 + /* it may return tri-state */
8794 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8796 + if (unlikely(valid < 0))
8806 +/* todo: remove this */
8807 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8808 + unsigned int flags, int do_udba, int dirren)
8811 + umode_t mode, h_mode;
8812 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8813 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8814 + struct inode *h_inode, *h_cached_inode;
8815 + struct dentry *h_dentry;
8816 + struct qstr *name, *h_name;
8823 + unhashed = !!d_unhashed(dentry);
8824 + is_root = !!IS_ROOT(dentry);
8825 + name = &dentry->d_name;
8826 + tmpfile = au_di(dentry)->di_tmpfile;
8829 + * Theoretically, REVAL test should be unnecessary in case of
8831 + * But {fs,i}notify doesn't fire some necessary events,
8832 + * IN_ATTRIB for atime/nlink/pageio
8833 + * Let's do REVAL test too.
8835 + if (do_udba && inode) {
8836 + mode = (inode->i_mode & S_IFMT);
8837 + plus = (inode->i_nlink > 0);
8838 + ibs = au_ibtop(inode);
8839 + ibe = au_ibbot(inode);
8842 + btop = au_dbtop(dentry);
8844 + if (inode && S_ISDIR(inode->i_mode))
8845 + btail = au_dbtaildir(dentry);
8846 + for (bindex = btop; bindex <= btail; bindex++) {
8847 + h_dentry = au_h_dptr(dentry, bindex);
8851 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8852 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8853 + spin_lock(&h_dentry->d_lock);
8854 + h_name = &h_dentry->d_name;
8855 + if (unlikely(do_udba
8858 + && (unhashed != !!d_unhashed(h_dentry)
8859 + || (!tmpfile && !dirren
8860 + && !au_qstreq(name, h_name))
8863 + && !(flags & LOOKUP_OPEN)
8864 + && (h_dentry->d_flags
8865 + & DCACHE_NFSFS_RENAMED)))
8869 + h_unhashed = d_unhashed(h_dentry);
8870 + spin_unlock(&h_dentry->d_lock);
8871 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8872 + unhashed, h_unhashed, dentry, h_dentry);
8875 + spin_unlock(&h_dentry->d_lock);
8877 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8878 + if (unlikely(err))
8879 + /* do not goto err, to keep the errno */
8882 + /* todo: plink too? */
8887 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8891 + if (d_is_positive(h_dentry))
8892 + h_inode = d_inode(h_dentry);
8895 + h_cached_inode = h_inode;
8897 + h_mode = (h_inode->i_mode & S_IFMT);
8898 + h_plus = (h_inode->i_nlink > 0);
8900 + if (inode && ibs <= bindex && bindex <= ibe)
8901 + h_cached_inode = au_h_iptr(inode, bindex);
8904 + if (unlikely(plus != h_plus && !tmpfile))
8907 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8909 + && !IS_ROOT(h_dentry)
8910 + && unhashed != d_unhashed(h_dentry)))
8913 + if (unlikely(mode != h_mode
8914 + || h_cached_inode != h_inode))
8927 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8928 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8931 + struct dentry *parent;
8933 + if (!au_digen_test(dentry, sigen))
8936 + parent = dget_parent(dentry);
8937 + di_read_lock_parent(parent, AuLock_IR);
8938 + AuDebugOn(au_digen_test(parent, sigen));
8939 + au_dbg_verify_gen(parent, sigen);
8940 + err = au_refresh_dentry(dentry, parent);
8941 + di_read_unlock(parent, AuLock_IR);
8947 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8950 + struct dentry *d, *parent;
8952 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8953 + return simple_reval_dpath(dentry, sigen);
8955 + /* slow loop, keep it simple and stupid */
8956 + /* cf: au_cpup_dirs() */
8959 + while (au_digen_test(dentry, sigen)) {
8963 + parent = dget_parent(d);
8964 + if (!au_digen_test(parent, sigen))
8970 + di_write_lock_child2(d);
8972 + /* someone might update our dentry while we were sleeping */
8973 + if (au_digen_test(d, sigen)) {
8975 + * todo: consolidate with simple_reval_dpath(),
8976 + * do_refresh() and au_reval_for_attr().
8978 + di_read_lock_parent(parent, AuLock_IR);
8979 + err = au_refresh_dentry(d, parent);
8980 + di_read_unlock(parent, AuLock_IR);
8984 + di_write_unlock(d);
8986 + if (unlikely(err))
8994 + * if valid returns 1, otherwise 0.
8996 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8999 + unsigned int sigen;
9000 + unsigned char do_udba, dirren;
9001 + struct super_block *sb;
9002 + struct inode *inode;
9004 + /* todo: support rcu-walk? */
9005 + if (flags & LOOKUP_RCU)
9009 + if (unlikely(!au_di(dentry)))
9013 + sb = dentry->d_sb;
9016 + * i_mutex of parent dir may be held,
9017 + * but we should not return 'invalid' due to busy.
9019 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9020 + if (unlikely(err)) {
9026 + if (d_really_is_positive(dentry))
9027 + inode = d_inode(dentry);
9028 + if (unlikely(inode && au_is_bad_inode(inode))) {
9033 + if (unlikely(au_dbrange_test(dentry))) {
9039 + sigen = au_sigen(sb);
9040 + if (au_digen_test(dentry, sigen)) {
9041 + AuDebugOn(IS_ROOT(dentry));
9042 + err = au_reval_dpath(dentry, sigen);
9043 + if (unlikely(err)) {
9048 + di_downgrade_lock(dentry, AuLock_IR);
9051 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9053 + && !(inode->i_state && I_LINKABLE)
9054 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9059 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9060 + if (do_udba && inode) {
9061 + aufs_bindex_t btop = au_ibtop(inode);
9062 + struct inode *h_inode;
9065 + h_inode = au_h_iptr(inode, btop);
9066 + if (h_inode && au_test_higen(inode, h_inode)) {
9073 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9074 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9075 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9077 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9083 + di_downgrade_lock(dentry, AuLock_IR);
9085 + aufs_read_unlock(dentry, AuLock_IR);
9090 + AuDbg("%pd invalid, %d\n", dentry, valid);
9096 +static void aufs_d_release(struct dentry *dentry)
9098 + if (au_di(dentry)) {
9099 + au_di_fin(dentry);
9100 + au_hn_di_reinit(dentry);
9104 +const struct dentry_operations aufs_dop = {
9105 + .d_revalidate = aufs_d_revalidate,
9106 + .d_weak_revalidate = aufs_d_revalidate,
9107 + .d_release = aufs_d_release
9110 +/* aufs_dop without d_revalidate */
9111 +const struct dentry_operations aufs_dop_noreval = {
9112 + .d_release = aufs_d_release
9114 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9115 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9116 +++ linux/fs/aufs/dentry.h 2021-12-03 15:38:59.933313976 +0100
9118 +/* SPDX-License-Identifier: GPL-2.0 */
9120 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9122 + * This program, aufs is free software; you can redistribute it and/or modify
9123 + * it under the terms of the GNU General Public License as published by
9124 + * the Free Software Foundation; either version 2 of the License, or
9125 + * (at your option) any later version.
9127 + * This program is distributed in the hope that it will be useful,
9128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9130 + * GNU General Public License for more details.
9132 + * You should have received a copy of the GNU General Public License
9133 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9137 + * lookup and dentry operations
9140 +#ifndef __AUFS_DENTRY_H__
9141 +#define __AUFS_DENTRY_H__
9145 +#include <linux/dcache.h>
9146 +#include "dirren.h"
9149 +struct au_hdentry {
9150 + struct dentry *hd_dentry;
9151 + aufs_bindex_t hd_id;
9155 + atomic_t di_generation;
9157 + struct au_rwsem di_rwsem;
9158 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9159 + unsigned char di_tmpfile; /* to allow the different name */
9160 + struct au_hdentry *di_hdentry;
9161 + struct rcu_head rcu;
9162 +} ____cacheline_aligned_in_smp;
9164 +/* ---------------------------------------------------------------------- */
9166 +/* flags for au_lkup_dentry() */
9167 +#define AuLkup_ALLOW_NEG 1
9168 +#define AuLkup_IGNORE_PERM (1 << 1)
9169 +#define AuLkup_DIRREN (1 << 2)
9170 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9171 +#define au_fset_lkup(flags, name) \
9172 + do { (flags) |= AuLkup_##name; } while (0)
9173 +#define au_fclr_lkup(flags, name) \
9174 + do { (flags) &= ~AuLkup_##name; } while (0)
9176 +#ifndef CONFIG_AUFS_DIRREN
9177 +#undef AuLkup_DIRREN
9178 +#define AuLkup_DIRREN 0
9181 +struct au_do_lookup_args {
9182 + unsigned int flags;
9184 + struct qstr whname, *name;
9185 + struct au_dr_lookup dirren;
9188 +/* ---------------------------------------------------------------------- */
9191 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9193 +struct dentry *au_sio_lkup_one(struct qstr *name, struct path *ppath);
9194 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9195 + struct dentry *h_parent, struct au_branch *br);
9197 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9198 + unsigned int flags);
9199 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9200 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9201 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9202 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9205 +void au_di_init_once(void *_di);
9206 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9207 +void au_di_free(struct au_dinfo *dinfo);
9208 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9209 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9210 +int au_di_init(struct dentry *dentry);
9211 +void au_di_fin(struct dentry *dentry);
9212 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9214 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9215 +void di_read_unlock(struct dentry *d, int flags);
9216 +void di_downgrade_lock(struct dentry *d, int flags);
9217 +void di_write_lock(struct dentry *d, unsigned int lsc);
9218 +void di_write_unlock(struct dentry *d);
9219 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9220 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9221 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9223 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9224 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9225 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9226 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9228 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9229 + struct dentry *h_dentry);
9230 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9231 +int au_dbrange_test(struct dentry *dentry);
9232 +void au_update_digen(struct dentry *dentry);
9233 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9234 +void au_update_dbtop(struct dentry *dentry);
9235 +void au_update_dbbot(struct dentry *dentry);
9236 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9238 +/* ---------------------------------------------------------------------- */
9240 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9242 + return dentry->d_fsdata;
9245 +/* ---------------------------------------------------------------------- */
9247 +/* lock subclass for dinfo */
9249 + AuLsc_DI_CHILD, /* child first */
9250 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9251 + AuLsc_DI_CHILD3, /* copyup dirs */
9255 + AuLsc_DI_TMP /* temp for replacing dinfo */
9259 + * di_read_lock_child, di_write_lock_child,
9260 + * di_read_lock_child2, di_write_lock_child2,
9261 + * di_read_lock_child3, di_write_lock_child3,
9262 + * di_read_lock_parent, di_write_lock_parent,
9263 + * di_read_lock_parent2, di_write_lock_parent2,
9264 + * di_read_lock_parent3, di_write_lock_parent3,
9266 +#define AuReadLockFunc(name, lsc) \
9267 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9268 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9270 +#define AuWriteLockFunc(name, lsc) \
9271 +static inline void di_write_lock_##name(struct dentry *d) \
9272 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9274 +#define AuRWLockFuncs(name, lsc) \
9275 + AuReadLockFunc(name, lsc) \
9276 + AuWriteLockFunc(name, lsc)
9278 +AuRWLockFuncs(child, CHILD);
9279 +AuRWLockFuncs(child2, CHILD2);
9280 +AuRWLockFuncs(child3, CHILD3);
9281 +AuRWLockFuncs(parent, PARENT);
9282 +AuRWLockFuncs(parent2, PARENT2);
9283 +AuRWLockFuncs(parent3, PARENT3);
9285 +#undef AuReadLockFunc
9286 +#undef AuWriteLockFunc
9287 +#undef AuRWLockFuncs
9289 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9290 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9291 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9293 +/* ---------------------------------------------------------------------- */
9295 +/* todo: memory barrier? */
9296 +static inline unsigned int au_digen(struct dentry *d)
9298 + return atomic_read(&au_di(d)->di_generation);
9301 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9303 + hdentry->hd_dentry = NULL;
9306 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9307 + aufs_bindex_t bindex)
9309 + return di->di_hdentry + bindex;
9312 +static inline void au_hdput(struct au_hdentry *hd)
9315 + dput(hd->hd_dentry);
9318 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9320 + DiMustAnyLock(dentry);
9321 + return au_di(dentry)->di_btop;
9324 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9326 + DiMustAnyLock(dentry);
9327 + return au_di(dentry)->di_bbot;
9330 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9332 + DiMustAnyLock(dentry);
9333 + return au_di(dentry)->di_bwh;
9336 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9338 + DiMustAnyLock(dentry);
9339 + return au_di(dentry)->di_bdiropq;
9342 +/* todo: hard/soft set? */
9343 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9345 + DiMustWriteLock(dentry);
9346 + au_di(dentry)->di_btop = bindex;
9349 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9351 + DiMustWriteLock(dentry);
9352 + au_di(dentry)->di_bbot = bindex;
9355 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9357 + DiMustWriteLock(dentry);
9358 + /* dbwh can be outside of btop - bbot range */
9359 + au_di(dentry)->di_bwh = bindex;
9362 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9364 + DiMustWriteLock(dentry);
9365 + au_di(dentry)->di_bdiropq = bindex;
9368 +/* ---------------------------------------------------------------------- */
9370 +#ifdef CONFIG_AUFS_HNOTIFY
9371 +static inline void au_digen_dec(struct dentry *d)
9373 + atomic_dec(&au_di(d)->di_generation);
9376 +static inline void au_hn_di_reinit(struct dentry *dentry)
9378 + dentry->d_fsdata = NULL;
9381 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9382 +#endif /* CONFIG_AUFS_HNOTIFY */
9384 +#endif /* __KERNEL__ */
9385 +#endif /* __AUFS_DENTRY_H__ */
9386 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9387 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9388 +++ linux/fs/aufs/dinfo.c 2021-12-03 15:38:59.933313976 +0100
9390 +// SPDX-License-Identifier: GPL-2.0
9392 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9394 + * This program, aufs is free software; you can redistribute it and/or modify
9395 + * it under the terms of the GNU General Public License as published by
9396 + * the Free Software Foundation; either version 2 of the License, or
9397 + * (at your option) any later version.
9399 + * This program is distributed in the hope that it will be useful,
9400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9402 + * GNU General Public License for more details.
9404 + * You should have received a copy of the GNU General Public License
9405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9409 + * dentry private data
9414 +void au_di_init_once(void *_dinfo)
9416 + struct au_dinfo *dinfo = _dinfo;
9418 + au_rw_init(&dinfo->di_rwsem);
9421 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9423 + struct au_dinfo *dinfo;
9426 + dinfo = au_cache_alloc_dinfo();
9427 + if (unlikely(!dinfo))
9430 + nbr = au_sbbot(sb) + 1;
9433 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9434 + if (dinfo->di_hdentry) {
9435 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9436 + dinfo->di_btop = -1;
9437 + dinfo->di_bbot = -1;
9438 + dinfo->di_bwh = -1;
9439 + dinfo->di_bdiropq = -1;
9440 + dinfo->di_tmpfile = 0;
9441 + for (i = 0; i < nbr; i++)
9442 + dinfo->di_hdentry[i].hd_id = -1;
9446 + au_cache_free_dinfo(dinfo);
9453 +void au_di_free(struct au_dinfo *dinfo)
9455 + struct au_hdentry *p;
9456 + aufs_bindex_t bbot, bindex;
9458 + /* dentry may not be revalidated */
9459 + bindex = dinfo->di_btop;
9460 + if (bindex >= 0) {
9461 + bbot = dinfo->di_bbot;
9462 + p = au_hdentry(dinfo, bindex);
9463 + while (bindex++ <= bbot)
9466 + au_kfree_try_rcu(dinfo->di_hdentry);
9467 + au_cache_free_dinfo(dinfo);
9470 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9472 + struct au_hdentry *p;
9475 + AuRwMustWriteLock(&a->di_rwsem);
9476 + AuRwMustWriteLock(&b->di_rwsem);
9478 +#define DiSwap(v, name) \
9480 + v = a->di_##name; \
9481 + a->di_##name = b->di_##name; \
9482 + b->di_##name = v; \
9485 + DiSwap(p, hdentry);
9489 + DiSwap(bi, bdiropq);
9495 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9497 + AuRwMustWriteLock(&dst->di_rwsem);
9498 + AuRwMustWriteLock(&src->di_rwsem);
9500 + dst->di_btop = src->di_btop;
9501 + dst->di_bbot = src->di_bbot;
9502 + dst->di_bwh = src->di_bwh;
9503 + dst->di_bdiropq = src->di_bdiropq;
9507 +int au_di_init(struct dentry *dentry)
9510 + struct super_block *sb;
9511 + struct au_dinfo *dinfo;
9514 + sb = dentry->d_sb;
9515 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9517 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9518 + /* smp_mb(); */ /* atomic_set */
9519 + dentry->d_fsdata = dinfo;
9526 +void au_di_fin(struct dentry *dentry)
9528 + struct au_dinfo *dinfo;
9530 + dinfo = au_di(dentry);
9531 + AuRwDestroy(&dinfo->di_rwsem);
9532 + au_di_free(dinfo);
9535 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9538 + struct au_hdentry *hdp;
9540 + AuRwMustWriteLock(&dinfo->di_rwsem);
9543 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9545 + sz = sizeof(*hdp);
9546 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9549 + dinfo->di_hdentry = hdp;
9556 +/* ---------------------------------------------------------------------- */
9558 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9561 + case AuLsc_DI_CHILD:
9562 + ii_write_lock_child(inode);
9564 + case AuLsc_DI_CHILD2:
9565 + ii_write_lock_child2(inode);
9567 + case AuLsc_DI_CHILD3:
9568 + ii_write_lock_child3(inode);
9570 + case AuLsc_DI_PARENT:
9571 + ii_write_lock_parent(inode);
9573 + case AuLsc_DI_PARENT2:
9574 + ii_write_lock_parent2(inode);
9576 + case AuLsc_DI_PARENT3:
9577 + ii_write_lock_parent3(inode);
9584 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9587 + case AuLsc_DI_CHILD:
9588 + ii_read_lock_child(inode);
9590 + case AuLsc_DI_CHILD2:
9591 + ii_read_lock_child2(inode);
9593 + case AuLsc_DI_CHILD3:
9594 + ii_read_lock_child3(inode);
9596 + case AuLsc_DI_PARENT:
9597 + ii_read_lock_parent(inode);
9599 + case AuLsc_DI_PARENT2:
9600 + ii_read_lock_parent2(inode);
9602 + case AuLsc_DI_PARENT3:
9603 + ii_read_lock_parent3(inode);
9610 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9612 + struct inode *inode;
9614 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9615 + if (d_really_is_positive(d)) {
9616 + inode = d_inode(d);
9617 + if (au_ftest_lock(flags, IW))
9618 + do_ii_write_lock(inode, lsc);
9619 + else if (au_ftest_lock(flags, IR))
9620 + do_ii_read_lock(inode, lsc);
9624 +void di_read_unlock(struct dentry *d, int flags)
9626 + struct inode *inode;
9628 + if (d_really_is_positive(d)) {
9629 + inode = d_inode(d);
9630 + if (au_ftest_lock(flags, IW)) {
9631 + au_dbg_verify_dinode(d);
9632 + ii_write_unlock(inode);
9633 + } else if (au_ftest_lock(flags, IR)) {
9634 + au_dbg_verify_dinode(d);
9635 + ii_read_unlock(inode);
9638 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9641 +void di_downgrade_lock(struct dentry *d, int flags)
9643 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9644 + ii_downgrade_lock(d_inode(d));
9645 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9648 +void di_write_lock(struct dentry *d, unsigned int lsc)
9650 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9651 + if (d_really_is_positive(d))
9652 + do_ii_write_lock(d_inode(d), lsc);
9655 +void di_write_unlock(struct dentry *d)
9657 + au_dbg_verify_dinode(d);
9658 + if (d_really_is_positive(d))
9659 + ii_write_unlock(d_inode(d));
9660 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9663 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9665 + AuDebugOn(d1 == d2
9666 + || d_inode(d1) == d_inode(d2)
9667 + || d1->d_sb != d2->d_sb);
9669 + if ((isdir && au_test_subdir(d1, d2))
9671 + di_write_lock_child(d1);
9672 + di_write_lock_child2(d2);
9674 + di_write_lock_child(d2);
9675 + di_write_lock_child2(d1);
9679 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9681 + AuDebugOn(d1 == d2
9682 + || d_inode(d1) == d_inode(d2)
9683 + || d1->d_sb != d2->d_sb);
9685 + if ((isdir && au_test_subdir(d1, d2))
9687 + di_write_lock_parent(d1);
9688 + di_write_lock_parent2(d2);
9690 + di_write_lock_parent(d2);
9691 + di_write_lock_parent2(d1);
9695 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9697 + di_write_unlock(d1);
9698 + if (d_inode(d1) == d_inode(d2))
9699 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9701 + di_write_unlock(d2);
9704 +/* ---------------------------------------------------------------------- */
9706 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9710 + DiMustAnyLock(dentry);
9712 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9714 + AuDebugOn(bindex < 0);
9715 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9716 + AuDebugOn(d && au_dcount(d) <= 0);
9721 + * extended version of au_h_dptr().
9722 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9725 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9727 + struct dentry *h_dentry;
9728 + struct inode *inode, *h_inode;
9730 + AuDebugOn(d_really_is_negative(dentry));
9733 + if (au_dbtop(dentry) <= bindex
9734 + && bindex <= au_dbbot(dentry))
9735 + h_dentry = au_h_dptr(dentry, bindex);
9736 + if (h_dentry && !au_d_linkable(h_dentry)) {
9738 + goto out; /* success */
9741 + inode = d_inode(dentry);
9742 + AuDebugOn(bindex < au_ibtop(inode));
9743 + AuDebugOn(au_ibbot(inode) < bindex);
9744 + h_inode = au_h_iptr(inode, bindex);
9745 + h_dentry = d_find_alias(h_inode);
9747 + if (!IS_ERR(h_dentry)) {
9748 + if (!au_d_linkable(h_dentry))
9749 + goto out; /* success */
9755 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9756 + h_dentry = au_plink_lkup(inode, bindex);
9757 + AuDebugOn(!h_dentry);
9758 + if (!IS_ERR(h_dentry)) {
9759 + if (!au_d_hashed_positive(h_dentry))
9760 + goto out; /* success */
9767 + AuDbgDentry(h_dentry);
9771 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9773 + aufs_bindex_t bbot, bwh;
9775 + bbot = au_dbbot(dentry);
9777 + bwh = au_dbwh(dentry);
9780 + if (0 < bwh && bwh < bbot)
9786 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9788 + aufs_bindex_t bbot, bopq;
9790 + bbot = au_dbtail(dentry);
9792 + bopq = au_dbdiropq(dentry);
9793 + if (0 <= bopq && bopq < bbot)
9799 +/* ---------------------------------------------------------------------- */
9801 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9802 + struct dentry *h_dentry)
9804 + struct au_dinfo *dinfo;
9805 + struct au_hdentry *hd;
9806 + struct au_branch *br;
9808 + DiMustWriteLock(dentry);
9810 + dinfo = au_di(dentry);
9811 + hd = au_hdentry(dinfo, bindex);
9813 + hd->hd_dentry = h_dentry;
9815 + br = au_sbr(dentry->d_sb, bindex);
9816 + hd->hd_id = br->br_id;
9820 +int au_dbrange_test(struct dentry *dentry)
9823 + aufs_bindex_t btop, bbot;
9826 + btop = au_dbtop(dentry);
9827 + bbot = au_dbbot(dentry);
9829 + AuDebugOn(bbot < 0 && btop > bbot);
9832 + AuDebugOn(bbot >= 0);
9838 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9843 + if (unlikely(au_digen(dentry) != sigen
9844 + || au_iigen_test(d_inode(dentry), sigen)))
9850 +void au_update_digen(struct dentry *dentry)
9852 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9853 + /* smp_mb(); */ /* atomic_set */
9856 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9858 + struct au_dinfo *dinfo;
9859 + struct dentry *h_d;
9860 + struct au_hdentry *hdp;
9861 + aufs_bindex_t bindex, bbot;
9863 + DiMustWriteLock(dentry);
9865 + dinfo = au_di(dentry);
9866 + if (!dinfo || dinfo->di_btop < 0)
9869 + if (do_put_zero) {
9870 + bbot = dinfo->di_bbot;
9871 + bindex = dinfo->di_btop;
9872 + hdp = au_hdentry(dinfo, bindex);
9873 + for (; bindex <= bbot; bindex++, hdp++) {
9874 + h_d = hdp->hd_dentry;
9875 + if (h_d && d_is_negative(h_d))
9876 + au_set_h_dptr(dentry, bindex, NULL);
9880 + dinfo->di_btop = 0;
9881 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9882 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9883 + if (hdp->hd_dentry)
9885 + if (dinfo->di_btop > dinfo->di_bbot) {
9886 + dinfo->di_btop = -1;
9887 + dinfo->di_bbot = -1;
9891 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9892 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9893 + if (hdp->hd_dentry)
9895 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9898 +void au_update_dbtop(struct dentry *dentry)
9900 + aufs_bindex_t bindex, bbot;
9901 + struct dentry *h_dentry;
9903 + bbot = au_dbbot(dentry);
9904 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9905 + h_dentry = au_h_dptr(dentry, bindex);
9908 + if (d_is_positive(h_dentry)) {
9909 + au_set_dbtop(dentry, bindex);
9912 + au_set_h_dptr(dentry, bindex, NULL);
9916 +void au_update_dbbot(struct dentry *dentry)
9918 + aufs_bindex_t bindex, btop;
9919 + struct dentry *h_dentry;
9921 + btop = au_dbtop(dentry);
9922 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9923 + h_dentry = au_h_dptr(dentry, bindex);
9926 + if (d_is_positive(h_dentry)) {
9927 + au_set_dbbot(dentry, bindex);
9930 + au_set_h_dptr(dentry, bindex, NULL);
9934 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9936 + aufs_bindex_t bindex, bbot;
9938 + bbot = au_dbbot(dentry);
9939 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9940 + if (au_h_dptr(dentry, bindex) == h_dentry)
9944 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9945 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9946 +++ linux/fs/aufs/dir.c 2021-12-03 15:38:59.933313976 +0100
9948 +// SPDX-License-Identifier: GPL-2.0
9950 + * Copyright (C) 2005-2021 Junjiro R. Okajima
9952 + * This program, aufs is free software; you can redistribute it and/or modify
9953 + * it under the terms of the GNU General Public License as published by
9954 + * the Free Software Foundation; either version 2 of the License, or
9955 + * (at your option) any later version.
9957 + * This program is distributed in the hope that it will be useful,
9958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9960 + * GNU General Public License for more details.
9962 + * You should have received a copy of the GNU General Public License
9963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9967 + * directory operations
9970 +#include <linux/fs_stack.h>
9971 +#include <linux/iversion.h>
9974 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9976 + unsigned int nlink;
9978 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9980 + nlink = dir->i_nlink;
9981 + nlink += h_dir->i_nlink - 2;
9982 + if (h_dir->i_nlink < 2)
9984 + smp_mb(); /* for i_nlink */
9985 + /* 0 can happen in revaliding */
9986 + set_nlink(dir, nlink);
9989 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9991 + unsigned int nlink;
9993 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9995 + nlink = dir->i_nlink;
9996 + nlink -= h_dir->i_nlink - 2;
9997 + if (h_dir->i_nlink < 2)
9999 + smp_mb(); /* for i_nlink */
10000 + /* nlink == 0 means the branch-fs is broken */
10001 + set_nlink(dir, nlink);
10004 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10007 + aufs_bindex_t bindex, bbot;
10008 + struct file *h_file;
10009 + struct dentry *h_dentry;
10013 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10015 + bbot = au_fbbot_dir(file);
10016 + for (bindex = au_fbtop(file);
10017 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10019 + h_file = au_hf_dir(file, bindex);
10020 + if (h_file && file_inode(h_file))
10021 + sz += vfsub_f_size_read(h_file);
10024 + AuDebugOn(!dentry);
10025 + AuDebugOn(!d_is_dir(dentry));
10027 + bbot = au_dbtaildir(dentry);
10028 + for (bindex = au_dbtop(dentry);
10029 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10031 + h_dentry = au_h_dptr(dentry, bindex);
10032 + if (h_dentry && d_is_positive(h_dentry))
10033 + sz += i_size_read(d_inode(h_dentry));
10036 + if (sz < KMALLOC_MAX_SIZE)
10037 + sz = roundup_pow_of_two(sz);
10038 + if (sz > KMALLOC_MAX_SIZE)
10039 + sz = KMALLOC_MAX_SIZE;
10040 + else if (sz < NAME_MAX) {
10041 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10042 + sz = AUFS_RDBLK_DEF;
10047 +struct au_dir_ts_arg {
10048 + struct dentry *dentry;
10049 + aufs_bindex_t brid;
10052 +static void au_do_dir_ts(void *arg)
10054 + struct au_dir_ts_arg *a = arg;
10055 + struct au_dtime dt;
10056 + struct path h_path;
10057 + struct inode *dir, *h_dir;
10058 + struct super_block *sb;
10059 + struct au_branch *br;
10060 + struct au_hinode *hdir;
10062 + aufs_bindex_t btop, bindex;
10064 + sb = a->dentry->d_sb;
10065 + if (d_really_is_negative(a->dentry))
10067 + /* no dir->i_mutex lock */
10068 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10070 + dir = d_inode(a->dentry);
10071 + btop = au_ibtop(dir);
10072 + bindex = au_br_index(sb, a->brid);
10073 + if (bindex < btop)
10076 + br = au_sbr(sb, bindex);
10077 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10078 + if (!h_path.dentry)
10080 + h_path.mnt = au_br_mnt(br);
10081 + au_dtime_store(&dt, a->dentry, &h_path);
10083 + br = au_sbr(sb, btop);
10084 + if (!au_br_writable(br->br_perm))
10086 + h_path.dentry = au_h_dptr(a->dentry, btop);
10087 + h_path.mnt = au_br_mnt(br);
10088 + err = vfsub_mnt_want_write(h_path.mnt);
10091 + hdir = au_hi(dir, btop);
10092 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10093 + h_dir = au_h_iptr(dir, btop);
10094 + if (h_dir->i_nlink
10095 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10096 + dt.dt_h_path = h_path;
10097 + au_dtime_revert(&dt);
10099 + au_hn_inode_unlock(hdir);
10100 + vfsub_mnt_drop_write(h_path.mnt);
10101 + au_cpup_attr_timesizes(dir);
10104 + aufs_read_unlock(a->dentry, AuLock_DW);
10107 + au_nwt_done(&au_sbi(sb)->si_nowait);
10108 + au_kfree_try_rcu(arg);
10111 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10113 + int perm, wkq_err;
10114 + aufs_bindex_t btop;
10115 + struct au_dir_ts_arg *arg;
10116 + struct dentry *dentry;
10117 + struct super_block *sb;
10121 + dentry = d_find_any_alias(dir);
10122 + AuDebugOn(!dentry);
10123 + sb = dentry->d_sb;
10124 + btop = au_ibtop(dir);
10125 + if (btop == bindex) {
10126 + au_cpup_attr_timesizes(dir);
10130 + perm = au_sbr_perm(sb, btop);
10131 + if (!au_br_writable(perm))
10134 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10138 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10139 + arg->brid = au_sbr_id(sb, bindex);
10140 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10141 + if (unlikely(wkq_err)) {
10142 + pr_err("wkq %d\n", wkq_err);
10144 + au_kfree_try_rcu(arg);
10151 +/* ---------------------------------------------------------------------- */
10153 +static int reopen_dir(struct file *file)
10156 + unsigned int flags;
10157 + aufs_bindex_t bindex, btail, btop;
10158 + struct dentry *dentry, *h_dentry;
10159 + struct file *h_file;
10161 + /* open all lower dirs */
10162 + dentry = file->f_path.dentry;
10163 + btop = au_dbtop(dentry);
10164 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10165 + au_set_h_fptr(file, bindex, NULL);
10166 + au_set_fbtop(file, btop);
10168 + btail = au_dbtaildir(dentry);
10169 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10170 + au_set_h_fptr(file, bindex, NULL);
10171 + au_set_fbbot_dir(file, btail);
10173 + flags = vfsub_file_flags(file);
10174 + for (bindex = btop; bindex <= btail; bindex++) {
10175 + h_dentry = au_h_dptr(dentry, bindex);
10178 + h_file = au_hf_dir(file, bindex);
10182 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10183 + err = PTR_ERR(h_file);
10184 + if (IS_ERR(h_file))
10185 + goto out; /* close all? */
10186 + au_set_h_fptr(file, bindex, h_file);
10188 + au_update_figen(file);
10189 + /* todo: necessary? */
10190 + /* file->f_ra = h_file->f_ra; */
10197 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10200 + aufs_bindex_t bindex, btail;
10201 + struct dentry *dentry, *h_dentry;
10202 + struct vfsmount *mnt;
10204 + FiMustWriteLock(file);
10205 + AuDebugOn(h_file);
10208 + mnt = file->f_path.mnt;
10209 + dentry = file->f_path.dentry;
10210 + file->f_version = inode_query_iversion(d_inode(dentry));
10211 + bindex = au_dbtop(dentry);
10212 + au_set_fbtop(file, bindex);
10213 + btail = au_dbtaildir(dentry);
10214 + au_set_fbbot_dir(file, btail);
10215 + for (; !err && bindex <= btail; bindex++) {
10216 + h_dentry = au_h_dptr(dentry, bindex);
10220 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10221 + if (unlikely(err))
10223 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10224 + if (IS_ERR(h_file)) {
10225 + err = PTR_ERR(h_file);
10228 + au_set_h_fptr(file, bindex, h_file);
10230 + au_update_figen(file);
10231 + /* todo: necessary? */
10232 + /* file->f_ra = h_file->f_ra; */
10234 + return 0; /* success */
10237 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10238 + au_set_h_fptr(file, bindex, NULL);
10239 + au_set_fbtop(file, -1);
10240 + au_set_fbbot_dir(file, -1);
10245 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10246 + struct file *file)
10249 + struct super_block *sb;
10250 + struct au_fidir *fidir;
10253 + sb = file->f_path.dentry->d_sb;
10254 + si_read_lock(sb, AuLock_FLUSH);
10255 + fidir = au_fidir_alloc(sb);
10257 + struct au_do_open_args args = {
10258 + .open = do_open_dir,
10261 + err = au_do_open(file, &args);
10262 + if (unlikely(err))
10263 + au_kfree_rcu(fidir);
10265 + si_read_unlock(sb);
10269 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10270 + struct file *file)
10272 + struct au_vdir *vdir_cache;
10273 + struct au_finfo *finfo;
10274 + struct au_fidir *fidir;
10275 + struct au_hfile *hf;
10276 + aufs_bindex_t bindex, bbot;
10278 + finfo = au_fi(file);
10279 + fidir = finfo->fi_hdir;
10281 + au_hbl_del(&finfo->fi_hlist,
10282 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10283 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10285 + au_vdir_free(vdir_cache);
10287 + bindex = finfo->fi_btop;
10288 + if (bindex >= 0) {
10289 + hf = fidir->fd_hfile + bindex;
10291 + * calls fput() instead of filp_close(),
10292 + * since no dnotify or lock for the lower file.
10294 + bbot = fidir->fd_bbot;
10295 + for (; bindex <= bbot; bindex++, hf++)
10297 + au_hfput(hf, /*execed*/0);
10299 + au_kfree_rcu(fidir);
10300 + finfo->fi_hdir = NULL;
10302 + au_finfo_fin(file);
10306 +/* ---------------------------------------------------------------------- */
10308 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10311 + aufs_bindex_t bindex, bbot;
10312 + struct file *h_file;
10315 + bbot = au_fbbot_dir(file);
10316 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10317 + h_file = au_hf_dir(file, bindex);
10319 + err = vfsub_flush(h_file, id);
10324 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10326 + return au_do_flush(file, id, au_do_flush_dir);
10329 +/* ---------------------------------------------------------------------- */
10331 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10334 + aufs_bindex_t bbot, bindex;
10335 + struct inode *inode;
10336 + struct super_block *sb;
10339 + sb = dentry->d_sb;
10340 + inode = d_inode(dentry);
10341 + IMustLock(inode);
10342 + bbot = au_dbbot(dentry);
10343 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10344 + struct path h_path;
10346 + if (au_test_ro(sb, bindex, inode))
10348 + h_path.dentry = au_h_dptr(dentry, bindex);
10349 + if (!h_path.dentry)
10352 + h_path.mnt = au_sbr_mnt(sb, bindex);
10353 + err = vfsub_fsync(NULL, &h_path, datasync);
10359 +static int au_do_fsync_dir(struct file *file, int datasync)
10362 + aufs_bindex_t bbot, bindex;
10363 + struct file *h_file;
10364 + struct super_block *sb;
10365 + struct inode *inode;
10367 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10368 + if (unlikely(err))
10371 + inode = file_inode(file);
10372 + sb = inode->i_sb;
10373 + bbot = au_fbbot_dir(file);
10374 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10375 + h_file = au_hf_dir(file, bindex);
10376 + if (!h_file || au_test_ro(sb, bindex, inode))
10379 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10387 + * @file may be NULL
10389 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10393 + struct dentry *dentry;
10394 + struct inode *inode;
10395 + struct super_block *sb;
10398 + dentry = file->f_path.dentry;
10399 + inode = d_inode(dentry);
10400 + inode_lock(inode);
10401 + sb = dentry->d_sb;
10402 + si_noflush_read_lock(sb);
10404 + err = au_do_fsync_dir(file, datasync);
10406 + di_write_lock_child(dentry);
10407 + err = au_do_fsync_dir_no_file(dentry, datasync);
10409 + au_cpup_attr_timesizes(inode);
10410 + di_write_unlock(dentry);
10412 + fi_write_unlock(file);
10414 + si_read_unlock(sb);
10415 + inode_unlock(inode);
10419 +/* ---------------------------------------------------------------------- */
10421 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10424 + struct dentry *dentry;
10425 + struct inode *inode, *h_inode;
10426 + struct super_block *sb;
10428 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10430 + dentry = file->f_path.dentry;
10431 + inode = d_inode(dentry);
10432 + IMustLock(inode);
10434 + sb = dentry->d_sb;
10435 + si_read_lock(sb, AuLock_FLUSH);
10436 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10437 + if (unlikely(err))
10439 + err = au_alive_dir(dentry);
10441 + err = au_vdir_init(file);
10442 + di_downgrade_lock(dentry, AuLock_IR);
10443 + if (unlikely(err))
10446 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10447 + if (!au_test_nfsd()) {
10448 + err = au_vdir_fill_de(file, ctx);
10449 + fsstack_copy_attr_atime(inode, h_inode);
10452 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10453 + * encode_fh() and others.
10455 + atomic_inc(&h_inode->i_count);
10456 + di_read_unlock(dentry, AuLock_IR);
10457 + si_read_unlock(sb);
10458 + err = au_vdir_fill_de(file, ctx);
10459 + fsstack_copy_attr_atime(inode, h_inode);
10460 + fi_write_unlock(file);
10468 + di_read_unlock(dentry, AuLock_IR);
10469 + fi_write_unlock(file);
10471 + si_read_unlock(sb);
10475 +/* ---------------------------------------------------------------------- */
10477 +#define AuTestEmpty_WHONLY 1
10478 +#define AuTestEmpty_CALLED (1 << 1)
10479 +#define AuTestEmpty_SHWH (1 << 2)
10480 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10481 +#define au_fset_testempty(flags, name) \
10482 + do { (flags) |= AuTestEmpty_##name; } while (0)
10483 +#define au_fclr_testempty(flags, name) \
10484 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10486 +#ifndef CONFIG_AUFS_SHWH
10487 +#undef AuTestEmpty_SHWH
10488 +#define AuTestEmpty_SHWH 0
10491 +struct test_empty_arg {
10492 + struct dir_context ctx;
10493 + struct au_nhash *whlist;
10494 + unsigned int flags;
10496 + aufs_bindex_t bindex;
10499 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10500 + int namelen, loff_t offset __maybe_unused, u64 ino,
10501 + unsigned int d_type)
10503 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10505 + char *name = (void *)__name;
10508 + au_fset_testempty(arg->flags, CALLED);
10510 + if (name[0] == '.'
10511 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10512 + goto out; /* success */
10514 + if (namelen <= AUFS_WH_PFX_LEN
10515 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10516 + if (au_ftest_testempty(arg->flags, WHONLY)
10517 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10518 + arg->err = -ENOTEMPTY;
10522 + name += AUFS_WH_PFX_LEN;
10523 + namelen -= AUFS_WH_PFX_LEN;
10524 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10525 + arg->err = au_nhash_append_wh
10526 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10527 + au_ftest_testempty(arg->flags, SHWH));
10531 + AuTraceErr(arg->err);
10535 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10538 + struct file *h_file;
10539 + struct au_branch *br;
10541 + h_file = au_h_open(dentry, arg->bindex,
10542 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10543 + /*file*/NULL, /*force_wr*/0);
10544 + err = PTR_ERR(h_file);
10545 + if (IS_ERR(h_file))
10549 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10550 + && !file_inode(h_file)->i_nlink)
10555 + au_fclr_testempty(arg->flags, CALLED);
10557 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10560 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10564 + br = au_sbr(dentry->d_sb, arg->bindex);
10565 + au_lcnt_dec(&br->br_nfiles);
10570 +struct do_test_empty_args {
10572 + struct dentry *dentry;
10573 + struct test_empty_arg *arg;
10576 +static void call_do_test_empty(void *args)
10578 + struct do_test_empty_args *a = args;
10579 + *a->errp = do_test_empty(a->dentry, a->arg);
10582 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10584 + int err, wkq_err;
10585 + struct dentry *h_dentry;
10586 + struct inode *h_inode;
10588 + h_dentry = au_h_dptr(dentry, arg->bindex);
10589 + h_inode = d_inode(h_dentry);
10590 + /* todo: i_mode changes anytime? */
10591 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10592 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10593 + inode_unlock_shared(h_inode);
10595 + err = do_test_empty(dentry, arg);
10597 + struct do_test_empty_args args = {
10599 + .dentry = dentry,
10602 + unsigned int flags = arg->flags;
10604 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10605 + if (unlikely(wkq_err))
10607 + arg->flags = flags;
10613 +int au_test_empty_lower(struct dentry *dentry)
10616 + unsigned int rdhash;
10617 + aufs_bindex_t bindex, btop, btail;
10618 + struct au_nhash whlist;
10619 + struct test_empty_arg arg = {
10621 + .actor = test_empty_cb
10624 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10626 + SiMustAnyLock(dentry->d_sb);
10628 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10630 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10631 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10632 + if (unlikely(err))
10636 + arg.whlist = &whlist;
10637 + btop = au_dbtop(dentry);
10638 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10639 + au_fset_testempty(arg.flags, SHWH);
10640 + test_empty = do_test_empty;
10641 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10642 + test_empty = sio_test_empty;
10643 + arg.bindex = btop;
10644 + err = test_empty(dentry, &arg);
10645 + if (unlikely(err))
10648 + au_fset_testempty(arg.flags, WHONLY);
10649 + btail = au_dbtaildir(dentry);
10650 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10651 + struct dentry *h_dentry;
10653 + h_dentry = au_h_dptr(dentry, bindex);
10654 + if (h_dentry && d_is_positive(h_dentry)) {
10655 + arg.bindex = bindex;
10656 + err = test_empty(dentry, &arg);
10661 + au_nhash_wh_free(&whlist);
10666 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10669 + struct test_empty_arg arg = {
10671 + .actor = test_empty_cb
10674 + aufs_bindex_t bindex, btail;
10677 + arg.whlist = whlist;
10678 + arg.flags = AuTestEmpty_WHONLY;
10679 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10680 + au_fset_testempty(arg.flags, SHWH);
10681 + btail = au_dbtaildir(dentry);
10682 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10683 + struct dentry *h_dentry;
10685 + h_dentry = au_h_dptr(dentry, bindex);
10686 + if (h_dentry && d_is_positive(h_dentry)) {
10687 + arg.bindex = bindex;
10688 + err = sio_test_empty(dentry, &arg);
10695 +/* ---------------------------------------------------------------------- */
10697 +const struct file_operations aufs_dir_fop = {
10698 + .owner = THIS_MODULE,
10699 + .llseek = default_llseek,
10700 + .read = generic_read_dir,
10701 + .iterate_shared = aufs_iterate_shared,
10702 + .unlocked_ioctl = aufs_ioctl_dir,
10703 +#ifdef CONFIG_COMPAT
10704 + .compat_ioctl = aufs_compat_ioctl_dir,
10706 + .open = aufs_open_dir,
10707 + .release = aufs_release_dir,
10708 + .flush = aufs_flush_dir,
10709 + .fsync = aufs_fsync_dir
10711 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10712 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10713 +++ linux/fs/aufs/dir.h 2021-12-03 15:38:59.933313976 +0100
10715 +/* SPDX-License-Identifier: GPL-2.0 */
10717 + * Copyright (C) 2005-2021 Junjiro R. Okajima
10719 + * This program, aufs is free software; you can redistribute it and/or modify
10720 + * it under the terms of the GNU General Public License as published by
10721 + * the Free Software Foundation; either version 2 of the License, or
10722 + * (at your option) any later version.
10724 + * This program is distributed in the hope that it will be useful,
10725 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10726 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10727 + * GNU General Public License for more details.
10729 + * You should have received a copy of the GNU General Public License
10730 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10734 + * directory operations
10737 +#ifndef __AUFS_DIR_H__
10738 +#define __AUFS_DIR_H__
10742 +#include <linux/fs.h>
10744 +/* ---------------------------------------------------------------------- */
10746 +/* need to be faster and smaller */
10749 + unsigned int nh_num;
10750 + struct hlist_head *nh_head;
10753 +struct au_vdir_destr {
10754 + unsigned char len;
10755 + unsigned char name[];
10758 +struct au_vdir_dehstr {
10759 + struct hlist_node hash;
10760 + struct au_vdir_destr *str;
10761 + struct rcu_head rcu;
10762 +} ____cacheline_aligned_in_smp;
10764 +struct au_vdir_de {
10766 + unsigned char de_type;
10767 + /* caution: packed */
10768 + struct au_vdir_destr de_str;
10771 +struct au_vdir_wh {
10772 + struct hlist_node wh_hash;
10773 +#ifdef CONFIG_AUFS_SHWH
10775 + aufs_bindex_t wh_bindex;
10776 + unsigned char wh_type;
10778 + aufs_bindex_t wh_bindex;
10780 + /* caution: packed */
10781 + struct au_vdir_destr wh_str;
10784 +union au_vdir_deblk_p {
10785 + unsigned char *deblk;
10786 + struct au_vdir_de *de;
10790 + unsigned char **vd_deblk;
10791 + unsigned long vd_nblk;
10793 + unsigned long ul;
10794 + union au_vdir_deblk_p p;
10798 + unsigned int vd_deblk_sz;
10799 + unsigned long vd_jiffy;
10800 + struct rcu_head rcu;
10801 +} ____cacheline_aligned_in_smp;
10803 +/* ---------------------------------------------------------------------- */
10806 +extern const struct file_operations aufs_dir_fop;
10807 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10808 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10809 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10810 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10811 +int au_test_empty_lower(struct dentry *dentry);
10812 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10815 +unsigned int au_rdhash_est(loff_t sz);
10816 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10817 +void au_nhash_wh_free(struct au_nhash *whlist);
10818 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10820 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10821 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10822 + unsigned int d_type, aufs_bindex_t bindex,
10823 + unsigned char shwh);
10824 +void au_vdir_free(struct au_vdir *vdir);
10825 +int au_vdir_init(struct file *file);
10826 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10829 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10831 +#ifdef CONFIG_AUFS_RDU
10833 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10834 +#ifdef CONFIG_COMPAT
10835 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10836 + unsigned long arg);
10839 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10840 + unsigned int cmd, unsigned long arg)
10841 +#ifdef CONFIG_COMPAT
10842 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10843 + unsigned int cmd, unsigned long arg)
10847 +#endif /* __KERNEL__ */
10848 +#endif /* __AUFS_DIR_H__ */
10849 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10850 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10851 +++ linux/fs/aufs/dirren.c 2021-12-03 15:38:59.933313976 +0100
10853 +// SPDX-License-Identifier: GPL-2.0
10855 + * Copyright (C) 2017-2021 Junjiro R. Okajima
10857 + * This program, aufs is free software; you can redistribute it and/or modify
10858 + * it under the terms of the GNU General Public License as published by
10859 + * the Free Software Foundation; either version 2 of the License, or
10860 + * (at your option) any later version.
10862 + * This program is distributed in the hope that it will be useful,
10863 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10864 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10865 + * GNU General Public License for more details.
10867 + * You should have received a copy of the GNU General Public License
10868 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10872 + * special handling in renaming a directory
10873 + * in order to support looking-up the before-renamed name on the lower readonly
10877 +#include <linux/byteorder/generic.h>
10880 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10884 + idx = au_dr_ihash(ent->dr_h_ino);
10885 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10888 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10891 + struct hlist_bl_head *hbl;
10894 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10895 + hbl = dr->dr_h_ino + i;
10896 + hlist_bl_lock(hbl);
10897 + ret &= hlist_bl_empty(hbl);
10898 + hlist_bl_unlock(hbl);
10904 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10906 + struct au_dr_hino *found, *ent;
10907 + struct hlist_bl_head *hbl;
10908 + struct hlist_bl_node *pos;
10912 + idx = au_dr_ihash(ino);
10913 + hbl = dr->dr_h_ino + idx;
10914 + hlist_bl_lock(hbl);
10915 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10916 + if (ent->dr_h_ino == ino) {
10920 + hlist_bl_unlock(hbl);
10925 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10926 + struct au_dr_hino *add_ent)
10929 + struct hlist_bl_head *hbl;
10930 + struct hlist_bl_node *pos;
10931 + struct au_dr_hino *ent;
10934 + idx = au_dr_ihash(ino);
10935 + hbl = dr->dr_h_ino + idx;
10936 +#if 0 /* debug print */
10938 + struct hlist_bl_node *tmp;
10940 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10941 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10944 + hlist_bl_lock(hbl);
10945 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10946 + if (ent->dr_h_ino == ino) {
10950 + if (!found && add_ent)
10951 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10952 + hlist_bl_unlock(hbl);
10954 + if (!found && add_ent)
10955 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10960 +void au_dr_hino_free(struct au_dr_br *dr)
10963 + struct hlist_bl_head *hbl;
10964 + struct hlist_bl_node *pos, *tmp;
10965 + struct au_dr_hino *ent;
10967 + /* SiMustWriteLock(sb); */
10969 + for (i = 0; i < AuDirren_NHASH; i++) {
10970 + hbl = dr->dr_h_ino + i;
10971 + /* no spinlock since sbinfo must be write-locked */
10972 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10973 + au_kfree_rcu(ent);
10974 + INIT_HLIST_BL_HEAD(hbl);
10978 +/* returns the number of inodes or an error */
10979 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10980 + struct file *hinofile)
10984 + loff_t pos, oldsize;
10986 + struct inode *hinoinode;
10987 + struct hlist_bl_head *hbl;
10988 + struct hlist_bl_node *n1, *n2;
10989 + struct au_dr_hino *ent;
10991 + SiMustWriteLock(sb);
10992 + AuDebugOn(!au_br_writable(br->br_perm));
10994 + hinoinode = file_inode(hinofile);
10995 + oldsize = i_size_read(hinoinode);
10999 + hbl = br->br_dirren.dr_h_ino;
11000 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11001 + /* no bit-lock since sbinfo must be write-locked */
11002 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11003 + AuDbg("hi%llu, %pD2\n",
11004 + (unsigned long long)ent->dr_h_ino, hinofile);
11005 + u64 = cpu_to_be64(ent->dr_h_ino);
11006 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11007 + if (ssz == sizeof(u64))
11010 + /* write error */
11011 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11018 + /* regardless the error */
11019 + if (pos < oldsize) {
11020 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11028 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11035 + struct au_dr_hino *ent;
11036 + struct inode *hinoinode;
11037 + struct hlist_bl_head *hbl;
11041 + hbl = dr->dr_h_ino;
11042 + hinoinode = file_inode(hinofile);
11043 + sz = i_size_read(hinoinode);
11044 + AuDebugOn(sz % sizeof(u64));
11045 + n = sz / sizeof(u64);
11047 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11048 + if (unlikely(ssz != sizeof(u64))) {
11049 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11056 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11062 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11063 + AuDbg("hi%llu, %pD2\n",
11064 + (unsigned long long)ent->dr_h_ino, hinofile);
11065 + hidx = au_dr_ihash(ent->dr_h_ino);
11066 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11068 + goto out; /* success */
11071 + au_dr_hino_free(dr);
11078 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11079 + * @path is a switch to distinguish load and store.
11081 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11082 + struct au_branch *br, const struct path *path)
11085 + unsigned char load, suspend;
11086 + struct file *hinofile;
11087 + struct au_hinode *hdir;
11088 + struct inode *dir, *delegated;
11089 + struct path hinopath;
11090 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11091 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11093 + AuDebugOn(bindex < 0 && !br);
11094 + AuDebugOn(bindex >= 0 && br);
11099 + br = au_sbr(sb, bindex);
11102 + path = &br->br_path;
11103 + AuDebugOn(!au_br_writable(br->br_perm));
11104 + if (unlikely(!au_br_writable(br->br_perm)))
11110 + dir = d_inode(sb->s_root);
11111 + hdir = au_hinode(au_ii(dir), bindex);
11112 + dir = hdir->hi_inode;
11113 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11115 + dir = d_inode(path->dentry);
11116 + inode_lock_nested(dir, AuLsc_I_CHILD);
11118 + hinopath.mnt = path->mnt;
11119 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11120 + err = PTR_ERR(hinopath.dentry);
11121 + if (IS_ERR(hinopath.dentry))
11125 + flags = O_RDONLY;
11127 + if (d_is_negative(hinopath.dentry))
11128 + goto out_dput; /* success */
11130 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11131 + if (d_is_positive(hinopath.dentry)) {
11132 + delegated = NULL;
11133 + err = vfsub_unlink(dir, &hinopath, &delegated,
11136 + if (unlikely(err))
11137 + pr_err("ignored err %d, %pd2\n",
11138 + err, hinopath.dentry);
11139 + if (unlikely(err == -EWOULDBLOCK))
11144 + } else if (!d_is_positive(hinopath.dentry)) {
11145 + err = vfsub_create(dir, &hinopath, 0600,
11146 + /*want_excl*/false);
11148 + if (unlikely(err))
11151 + flags = O_WRONLY;
11153 + hinofile = vfsub_dentry_open(&hinopath, flags);
11155 + au_hn_inode_unlock(hdir);
11157 + inode_unlock(dir);
11158 + dput(hinopath.dentry);
11159 + AuTraceErrPtr(hinofile);
11160 + if (IS_ERR(hinofile)) {
11161 + err = PTR_ERR(hinofile);
11166 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11168 + err = au_dr_hino_store(sb, br, hinofile);
11173 + dput(hinopath.dentry);
11176 + au_hn_inode_unlock(hdir);
11178 + inode_unlock(dir);
11184 +/* ---------------------------------------------------------------------- */
11186 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11189 + struct kstatfs kstfs;
11191 + struct dentry *dentry;
11192 + struct super_block *sb;
11194 + err = vfs_statfs((void *)path, &kstfs);
11196 + if (unlikely(err))
11199 + /* todo: support for UUID */
11201 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11202 + brid->type = AuBrid_FSID;
11203 + brid->fsid = kstfs.f_fsid;
11205 + dentry = path->dentry;
11206 + sb = dentry->d_sb;
11209 + brid->type = AuBrid_DEV;
11218 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11219 + const struct path *path)
11222 + struct au_dr_br *dr;
11223 + struct hlist_bl_head *hbl;
11225 + dr = &br->br_dirren;
11226 + hbl = dr->dr_h_ino;
11227 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11228 + INIT_HLIST_BL_HEAD(hbl);
11230 + err = au_dr_brid_init(&dr->dr_brid, path);
11231 + if (unlikely(err))
11234 + if (au_opt_test(au_mntflags(sb), DIRREN))
11235 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11242 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11247 + if (au_br_writable(br->br_perm))
11248 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11250 + au_dr_hino_free(&br->br_dirren);
11255 +/* ---------------------------------------------------------------------- */
11257 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11258 + char *buf, size_t sz)
11261 + unsigned int major, minor;
11265 + err = snprintf(p, sz, "%d_", brid->type);
11266 + AuDebugOn(err > sz);
11269 + switch (brid->type) {
11270 + case AuBrid_Unset:
11272 + case AuBrid_UUID:
11273 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11275 + case AuBrid_FSID:
11276 + err = snprintf(p, sz, "%08x-%08x",
11277 + brid->fsid.val[0], brid->fsid.val[1]);
11280 + major = MAJOR(brid->dev);
11281 + minor = MINOR(brid->dev);
11282 + if (major <= 0xff && minor <= 0xff)
11283 + err = snprintf(p, sz, "%02x%02x", major, minor);
11285 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11288 + AuDebugOn(err > sz);
11291 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11292 + AuDebugOn(err > sz);
11299 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11302 + struct dentry *br_dentry;
11303 + struct inode *br_inode;
11305 + br_dentry = au_br_dentry(br);
11306 + br_inode = d_inode(br_dentry);
11307 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11308 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11309 + AuDebugOn(rlen > len);
11314 +/* ---------------------------------------------------------------------- */
11317 + * from the given @h_dentry, construct drinfo at @*fdata.
11318 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11321 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11322 + struct dentry *h_dentry,
11323 + unsigned char *allocated)
11326 + struct au_drinfo_fdata *f, *p;
11327 + struct au_drinfo *drinfo;
11328 + struct inode *h_inode;
11329 + struct qstr *qname;
11333 + h_inode = d_inode(h_dentry);
11334 + qname = &h_dentry->d_name;
11335 + drinfo = &f->drinfo;
11336 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11337 + drinfo->oldnamelen = qname->len;
11338 + if (*allocated < sizeof(*f) + qname->len) {
11339 + v = roundup_pow_of_two(*allocated + qname->len);
11340 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11341 + if (unlikely(!p)) {
11349 + drinfo = &f->drinfo;
11351 + memcpy(drinfo->oldname, qname->name, qname->len);
11352 + AuDbg("i%llu, %.*s\n",
11353 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11354 + drinfo->oldname);
11361 +/* callers have to free the return value */
11362 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11364 + struct au_drinfo *ret, *drinfo;
11365 + struct au_drinfo_fdata fdata;
11370 + ret = ERR_PTR(-EIO);
11372 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11373 + if (unlikely(ssz != sizeof(fdata))) {
11374 + AuIOErr("ssz %zd, %u, %pD2\n",
11375 + ssz, (unsigned int)sizeof(fdata), file);
11379 + fdata.magic = ntohl((__force __be32)fdata.magic);
11380 + switch (fdata.magic) {
11381 + case AUFS_DRINFO_MAGIC_V1:
11384 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11385 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11389 + drinfo = &fdata.drinfo;
11390 + len = drinfo->oldnamelen;
11392 + AuIOErr("broken drinfo %pD2\n", file);
11397 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11398 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11399 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11400 + (unsigned long long)drinfo->ino,
11401 + (unsigned long long)h_ino, file);
11402 + goto out; /* success */
11405 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11406 + if (unlikely(!ret)) {
11407 + ret = ERR_PTR(-ENOMEM);
11408 + AuTraceErrPtr(ret);
11413 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11414 + if (unlikely(ssz != len)) {
11415 + au_kfree_rcu(ret);
11416 + ret = ERR_PTR(-EIO);
11417 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11421 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11427 +/* ---------------------------------------------------------------------- */
11429 +/* in order to be revertible */
11430 +struct au_drinfo_rev_elm {
11432 + struct dentry *info_dentry;
11433 + struct au_drinfo *info_last;
11436 +struct au_drinfo_rev {
11437 + unsigned char already;
11438 + aufs_bindex_t nelm;
11439 + struct au_drinfo_rev_elm elm[];
11442 +/* todo: isn't it too large? */
11443 +struct au_drinfo_store {
11444 + struct path h_ppath;
11445 + struct dentry *h_dentry;
11446 + struct au_drinfo_fdata *fdata;
11447 + char *infoname; /* inside of whname, just after PFX */
11448 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11449 + aufs_bindex_t btgt, btail;
11450 + unsigned char no_sio,
11451 + allocated, /* current size of *fdata */
11452 + infonamelen, /* room size for p */
11453 + whnamelen, /* length of the generated name */
11454 + renameback; /* renamed back */
11457 +/* on rename(2) error, the caller should revert it using @elm */
11458 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11459 + struct au_drinfo_rev_elm *elm)
11464 + struct path infopath = {
11465 + .mnt = w->h_ppath.mnt
11467 + struct inode *h_dir, *h_inode, *delegated;
11468 + struct file *infofile;
11469 + struct qstr *qname;
11472 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11474 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11476 + AuTraceErrPtr(infopath.dentry);
11477 + if (IS_ERR(infopath.dentry)) {
11478 + err = PTR_ERR(infopath.dentry);
11483 + h_dir = d_inode(w->h_ppath.dentry);
11484 + if (elm && d_is_negative(infopath.dentry)) {
11485 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11487 + if (unlikely(err))
11489 + elm->created = 1;
11490 + elm->info_dentry = dget(infopath.dentry);
11493 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11494 + AuTraceErrPtr(infofile);
11495 + if (IS_ERR(infofile)) {
11496 + err = PTR_ERR(infofile);
11500 + h_inode = d_inode(infopath.dentry);
11501 + if (elm && i_size_read(h_inode)) {
11502 + h_inode = d_inode(w->h_dentry);
11503 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11504 + AuTraceErrPtr(elm->info_last);
11505 + if (IS_ERR(elm->info_last)) {
11506 + err = PTR_ERR(elm->info_last);
11507 + elm->info_last = NULL;
11508 + AuDebugOn(elm->info_dentry);
11513 + if (elm && w->renameback) {
11514 + delegated = NULL;
11515 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11517 + if (unlikely(err == -EWOULDBLOCK))
11523 + qname = &w->h_dentry->d_name;
11524 + len = sizeof(*w->fdata) + qname->len;
11526 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11527 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11528 + if (ssz == len) {
11529 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11530 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11531 + goto out_fput; /* success */
11536 + /* the caller should revert it using @elm */
11542 + dput(infopath.dentry);
11548 +struct au_call_drinfo_do_store_args {
11550 + struct au_drinfo_store *w;
11551 + struct au_drinfo_rev_elm *elm;
11554 +static void au_call_drinfo_do_store(void *args)
11556 + struct au_call_drinfo_do_store_args *a = args;
11558 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11561 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11562 + struct au_drinfo_rev_elm *elm)
11564 + int err, wkq_err;
11567 + err = au_drinfo_do_store(w, elm);
11569 + struct au_call_drinfo_do_store_args a = {
11574 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11575 + if (unlikely(wkq_err))
11583 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11584 + aufs_bindex_t btgt)
11588 + memset(w, 0, sizeof(*w));
11589 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11590 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11591 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11592 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11594 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11597 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11598 + if (unlikely(!w->fdata)) {
11602 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11609 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11611 + au_kfree_rcu(w->fdata);
11614 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11615 + struct au_drinfo_store *w)
11617 + struct au_drinfo_rev_elm *elm;
11618 + struct inode *h_dir, *delegated;
11620 + struct path infopath = {
11621 + .mnt = w->h_ppath.mnt
11624 + h_dir = d_inode(w->h_ppath.dentry);
11625 + IMustLock(h_dir);
11629 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11630 + AuDebugOn(elm->created && elm->info_last);
11631 + if (elm->created) {
11633 + delegated = NULL;
11634 + infopath.dentry = elm->info_dentry;
11635 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11638 + if (unlikely(err == -EWOULDBLOCK))
11640 + dput(elm->info_dentry);
11641 + } else if (elm->info_last) {
11643 + w->fdata->drinfo = *elm->info_last;
11644 + memcpy(w->fdata->drinfo.oldname,
11645 + elm->info_last->oldname,
11646 + elm->info_last->oldnamelen);
11647 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11648 + au_kfree_rcu(elm->info_last);
11650 + if (unlikely(err))
11651 + AuIOErr("%d, %s\n", err, w->whname);
11652 + /* go on even if err */
11656 +/* caller has to call au_dr_rename_fin() later */
11657 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11658 + struct qstr *dst_name, void *_rev)
11660 + int err, sz, nelm;
11661 + aufs_bindex_t bindex, btail;
11662 + struct au_drinfo_store work;
11663 + struct au_drinfo_rev *rev, **p;
11664 + struct au_drinfo_rev_elm *elm;
11665 + struct super_block *sb;
11666 + struct au_branch *br;
11667 + struct au_hinode *hdir;
11669 + err = au_drinfo_store_work_init(&work, btgt);
11671 + if (unlikely(err))
11675 + btail = au_dbtaildir(dentry);
11676 + nelm = btail - btgt;
11677 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11678 + rev = kcalloc(1, sz, GFP_NOFS);
11679 + if (unlikely(!rev)) {
11683 + rev->nelm = nelm;
11689 + sb = dentry->d_sb;
11690 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11691 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11692 + hdir = au_hi(d_inode(dentry), btgt);
11693 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11694 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11695 + work.h_dentry = au_h_dptr(dentry, bindex);
11696 + if (!work.h_dentry)
11699 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11700 + &work.allocated);
11702 + if (unlikely(err))
11705 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11706 + br = au_sbr(sb, bindex);
11707 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11708 + work.whnamelen += au_drinfo_name(br, work.infoname,
11709 + work.infonamelen);
11710 + AuDbg("whname %.*s, i%llu, %.*s\n",
11711 + work.whnamelen, work.whname,
11712 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11713 + work.fdata->drinfo.oldnamelen,
11714 + work.fdata->drinfo.oldname);
11716 + err = au_drinfo_store_sio(&work, elm);
11718 + if (unlikely(err))
11721 + if (unlikely(err)) {
11722 + /* revert all drinfo */
11723 + au_drinfo_store_rev(rev, &work);
11724 + au_kfree_try_rcu(rev);
11727 + au_hn_inode_unlock(hdir);
11730 + au_drinfo_store_work_fin(&work);
11735 +/* ---------------------------------------------------------------------- */
11737 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11738 + struct qstr *dst_name, void *_rev)
11740 + int err, already;
11742 + struct super_block *sb;
11743 + struct au_branch *br;
11744 + struct au_dr_br *dr;
11745 + struct dentry *h_dentry;
11746 + struct inode *h_inode;
11747 + struct au_dr_hino *ent;
11748 + struct au_drinfo_rev *rev, **p;
11750 + AuDbg("bindex %d\n", bindex);
11753 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11754 + if (unlikely(!ent))
11758 + br = au_sbr(sb, bindex);
11759 + dr = &br->br_dirren;
11760 + h_dentry = au_h_dptr(src, bindex);
11761 + h_inode = d_inode(h_dentry);
11762 + ino = h_inode->i_ino;
11763 + ent->dr_h_ino = ino;
11764 + already = au_dr_hino_test_add(dr, ino, ent);
11765 + AuDbg("b%d, hi%llu, already %d\n",
11766 + bindex, (unsigned long long)ino, already);
11768 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11773 + rev->already = already;
11774 + goto out; /* success */
11779 + au_dr_hino_del(dr, ent);
11780 + au_kfree_rcu(ent);
11787 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11789 + struct au_drinfo_rev *rev;
11790 + struct au_drinfo_rev_elm *elm;
11795 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11796 + dput(elm->info_dentry);
11797 + au_kfree_rcu(elm->info_last);
11799 + au_kfree_try_rcu(rev);
11802 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11805 + struct au_drinfo_store work;
11806 + struct au_drinfo_rev *rev = _rev;
11807 + struct super_block *sb;
11808 + struct au_branch *br;
11809 + struct inode *h_inode;
11810 + struct au_dr_br *dr;
11811 + struct au_dr_hino *ent;
11813 + err = au_drinfo_store_work_init(&work, btgt);
11814 + if (unlikely(err))
11818 + br = au_sbr(sb, btgt);
11819 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11820 + work.h_ppath.mnt = au_br_mnt(br);
11821 + au_drinfo_store_rev(rev, &work);
11822 + au_drinfo_store_work_fin(&work);
11823 + if (rev->already)
11826 + dr = &br->br_dirren;
11827 + h_inode = d_inode(work.h_ppath.dentry);
11828 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11830 + au_dr_hino_del(dr, ent);
11831 + au_kfree_rcu(ent);
11834 + au_kfree_try_rcu(rev);
11835 + if (unlikely(err))
11836 + pr_err("failed to remove dirren info\n");
11839 +/* ---------------------------------------------------------------------- */
11841 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11842 + char *whname, int whnamelen,
11843 + struct dentry **info_dentry)
11845 + struct au_drinfo *drinfo;
11847 + struct inode *h_dir;
11848 + struct path infopath;
11851 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11853 + *info_dentry = NULL;
11856 + h_dir = d_inode(h_ppath->dentry);
11857 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11858 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11859 + if (IS_ERR(infopath.dentry)) {
11860 + drinfo = (void *)infopath.dentry;
11864 + if (d_is_negative(infopath.dentry))
11865 + goto out_dput; /* success */
11867 + infopath.mnt = h_ppath->mnt;
11868 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11869 + inode_unlock_shared(h_dir);
11872 + drinfo = (void *)f;
11876 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11877 + if (IS_ERR_OR_NULL(drinfo))
11880 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11881 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11886 + dput(infopath.dentry);
11889 + inode_unlock_shared(h_dir);
11890 + AuTraceErrPtr(drinfo);
11894 +struct au_drinfo_do_load_args {
11895 + struct au_drinfo **drinfop;
11896 + struct path *h_ppath;
11899 + struct dentry **info_dentry;
11902 +static void au_call_drinfo_do_load(void *args)
11904 + struct au_drinfo_do_load_args *a = args;
11906 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11910 +struct au_drinfo_load {
11911 + struct path h_ppath;
11912 + struct qstr *qname;
11913 + unsigned char no_sio;
11915 + aufs_bindex_t ninfo;
11916 + struct au_drinfo **drinfo;
11919 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11920 + struct au_branch *br)
11922 + int err, wkq_err, whnamelen, e;
11923 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11924 + = AUFS_WH_DR_INFO_PFX;
11925 + struct au_drinfo *drinfo;
11926 + struct qstr oldname;
11927 + struct inode *h_dir, *delegated;
11928 + struct dentry *info_dentry;
11929 + struct path infopath;
11931 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11932 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11933 + sizeof(whname) - whnamelen);
11935 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11938 + struct au_drinfo_do_load_args args = {
11939 + .drinfop = &drinfo,
11940 + .h_ppath = &w->h_ppath,
11941 + .whname = whname,
11942 + .whnamelen = whnamelen,
11943 + .info_dentry = &info_dentry
11945 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11946 + if (unlikely(wkq_err))
11947 + drinfo = ERR_PTR(wkq_err);
11949 + err = PTR_ERR(drinfo);
11950 + if (IS_ERR_OR_NULL(drinfo))
11954 + oldname.len = drinfo->oldnamelen;
11955 + oldname.name = drinfo->oldname;
11956 + if (au_qstreq(w->qname, &oldname)) {
11957 + /* the name is renamed back */
11958 + au_kfree_rcu(drinfo);
11961 + infopath.dentry = info_dentry;
11962 + infopath.mnt = w->h_ppath.mnt;
11963 + h_dir = d_inode(w->h_ppath.dentry);
11964 + delegated = NULL;
11965 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11966 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11967 + inode_unlock(h_dir);
11969 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11970 + if (unlikely(e == -EWOULDBLOCK))
11973 + au_kfree_rcu(w->drinfo[bindex]);
11974 + w->drinfo[bindex] = drinfo;
11975 + dput(info_dentry);
11982 +/* ---------------------------------------------------------------------- */
11984 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11986 + struct au_drinfo **p = drinfo;
11989 + au_kfree_rcu(*drinfo++);
11990 + au_kfree_try_rcu(p);
11993 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
11994 + aufs_bindex_t btgt)
11997 + struct au_drinfo_load w;
11998 + aufs_bindex_t bindex, bbot;
11999 + struct au_branch *br;
12000 + struct inode *h_dir;
12001 + struct au_dr_hino *ent;
12002 + struct super_block *sb;
12004 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12005 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12006 + AuLNPair(&lkup->whname), btgt);
12008 + sb = dentry->d_sb;
12009 + bbot = au_sbbot(sb);
12010 + w.ninfo = bbot + 1;
12011 + if (!lkup->dirren.drinfo) {
12012 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12013 + sizeof(*lkup->dirren.drinfo),
12015 + if (unlikely(!lkup->dirren.drinfo)) {
12019 + lkup->dirren.ninfo = w.ninfo;
12021 + w.drinfo = lkup->dirren.drinfo;
12022 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12023 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12024 + AuDebugOn(!w.h_ppath.dentry);
12025 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12026 + w.qname = &dentry->d_name;
12029 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12030 + br = au_sbr(sb, bindex);
12031 + err = au_drinfo_load(&w, bindex, br);
12032 + if (unlikely(err))
12034 + if (w.drinfo[bindex])
12038 + br = au_sbr(sb, btgt);
12039 + h_dir = d_inode(w.h_ppath.dentry);
12040 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12042 + au_dr_hino_del(&br->br_dirren, ent);
12043 + au_kfree_rcu(ent);
12045 + goto out; /* success */
12048 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12049 + lkup->dirren.ninfo = 0;
12050 + lkup->dirren.drinfo = NULL;
12056 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12058 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12061 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12064 + struct au_drinfo *drinfo;
12067 + if (!lkup->dirren.drinfo)
12069 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12070 + drinfo = lkup->dirren.drinfo[btgt];
12074 + au_kfree_try_rcu(lkup->whname.name);
12075 + lkup->whname.name = NULL;
12076 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12077 + lkup->dirren.dr_name.name = drinfo->oldname;
12078 + lkup->name = &lkup->dirren.dr_name;
12079 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12081 + AuDbg("name %.*s, whname %.*s, b%d\n",
12082 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12090 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12094 + struct au_drinfo *drinfo;
12097 + if (!lkup->dirren.drinfo)
12099 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12100 + drinfo = lkup->dirren.drinfo[bindex];
12104 + match = (drinfo->ino == h_ino);
12105 + AuDbg("match %d\n", match);
12111 +/* ---------------------------------------------------------------------- */
12113 +int au_dr_opt_set(struct super_block *sb)
12116 + aufs_bindex_t bindex, bbot;
12117 + struct au_branch *br;
12120 + bbot = au_sbbot(sb);
12121 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12122 + br = au_sbr(sb, bindex);
12123 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12129 +int au_dr_opt_flush(struct super_block *sb)
12132 + aufs_bindex_t bindex, bbot;
12133 + struct au_branch *br;
12136 + bbot = au_sbbot(sb);
12137 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12138 + br = au_sbr(sb, bindex);
12139 + if (au_br_writable(br->br_perm))
12140 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12146 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12149 + aufs_bindex_t bindex, bbot;
12150 + struct au_branch *br;
12154 + err = au_dr_opt_flush(sb);
12155 + if (unlikely(err))
12159 + bbot = au_sbbot(sb);
12160 + for (bindex = 0; bindex <= bbot; bindex++) {
12161 + br = au_sbr(sb, bindex);
12162 + au_dr_hino_free(&br->br_dirren);
12168 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12169 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12170 +++ linux/fs/aufs/dirren.h 2021-12-03 15:38:59.933313976 +0100
12172 +/* SPDX-License-Identifier: GPL-2.0 */
12174 + * Copyright (C) 2017-2021 Junjiro R. Okajima
12176 + * This program, aufs is free software; you can redistribute it and/or modify
12177 + * it under the terms of the GNU General Public License as published by
12178 + * the Free Software Foundation; either version 2 of the License, or
12179 + * (at your option) any later version.
12181 + * This program is distributed in the hope that it will be useful,
12182 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12183 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12184 + * GNU General Public License for more details.
12186 + * You should have received a copy of the GNU General Public License
12187 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12191 + * renamed dir info
12194 +#ifndef __AUFS_DIRREN_H__
12195 +#define __AUFS_DIRREN_H__
12199 +#include <linux/dcache.h>
12200 +#include <linux/statfs.h>
12201 +#include <linux/uuid.h>
12204 +#define AuDirren_NHASH 100
12206 +#ifdef CONFIG_AUFS_DIRREN
12207 +enum au_brid_type {
12214 +struct au_dr_brid {
12215 + enum au_brid_type type;
12217 + uuid_t uuid; /* unimplemented yet */
12223 +/* 20 is the max digits length of ulong 64 */
12224 +/* brid-type "_" uuid "_" inum */
12225 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12226 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12228 +struct au_dr_hino {
12229 + struct hlist_bl_node dr_hnode;
12234 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12235 + struct au_dr_brid dr_brid;
12238 +struct au_dr_lookup {
12239 + /* dr_name is pointed by struct au_do_lookup_args.name */
12240 + struct qstr dr_name; /* subset of dr_info */
12241 + aufs_bindex_t ninfo;
12242 + struct au_drinfo **drinfo;
12245 +struct au_dr_hino;
12247 +struct au_dr_br { };
12248 +struct au_dr_lookup { };
12251 +/* ---------------------------------------------------------------------- */
12254 +struct au_do_lookup_args;
12256 +#ifdef CONFIG_AUFS_DIRREN
12257 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12258 + struct au_dr_hino *add_ent);
12259 +void au_dr_hino_free(struct au_dr_br *dr);
12260 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12261 + const struct path *path);
12262 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12263 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12264 + struct qstr *dst_name, void *_rev);
12265 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12266 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12267 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12268 + aufs_bindex_t bindex);
12269 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12270 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12272 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12273 +int au_dr_opt_set(struct super_block *sb);
12274 +int au_dr_opt_flush(struct super_block *sb);
12275 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12277 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12278 + struct au_dr_hino *add_ent);
12279 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12280 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12281 + const struct path *path);
12282 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12283 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12284 + struct qstr *dst_name, void *_rev);
12285 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12286 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12288 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12289 + aufs_bindex_t bindex);
12290 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12291 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12292 + aufs_bindex_t bindex, ino_t h_ino);
12293 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12294 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12295 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12296 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12299 +/* ---------------------------------------------------------------------- */
12301 +#ifdef CONFIG_AUFS_DIRREN
12302 +static inline int au_dr_ihash(ino_t h_ino)
12304 + return h_ino % AuDirren_NHASH;
12307 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12310 +#endif /* __KERNEL__ */
12311 +#endif /* __AUFS_DIRREN_H__ */
12312 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12313 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12314 +++ linux/fs/aufs/dynop.c 2021-12-03 15:38:59.933313976 +0100
12316 +// SPDX-License-Identifier: GPL-2.0
12318 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12320 + * This program, aufs is free software; you can redistribute it and/or modify
12321 + * it under the terms of the GNU General Public License as published by
12322 + * the Free Software Foundation; either version 2 of the License, or
12323 + * (at your option) any later version.
12325 + * This program is distributed in the hope that it will be useful,
12326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12328 + * GNU General Public License for more details.
12330 + * You should have received a copy of the GNU General Public License
12331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12335 + * dynamically customizable operations for regular files
12340 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12343 + * How large will these lists be?
12344 + * Usually just a few elements, 20-30 at most for each, I guess.
12346 +static struct hlist_bl_head dynop[AuDyLast];
12348 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12349 + const void *h_op)
12351 + struct au_dykey *key, *tmp;
12352 + struct hlist_bl_node *pos;
12355 + hlist_bl_lock(hbl);
12356 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12357 + if (tmp->dk_op.dy_hop == h_op) {
12358 + if (kref_get_unless_zero(&tmp->dk_kref))
12362 + hlist_bl_unlock(hbl);
12367 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12369 + struct au_dykey **k, *found;
12370 + const void *h_op = key->dk_op.dy_hop;
12374 + k = br->br_dykey;
12375 + for (i = 0; i < AuBrDynOp; i++)
12377 + if (k[i]->dk_op.dy_hop == h_op) {
12384 + spin_lock(&br->br_dykey_lock);
12385 + for (; i < AuBrDynOp; i++)
12387 + if (k[i]->dk_op.dy_hop == h_op) {
12395 + spin_unlock(&br->br_dykey_lock);
12396 + BUG_ON(i == AuBrDynOp); /* expand the array */
12402 +/* kref_get() if @key is already added */
12403 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12405 + struct au_dykey *tmp, *found;
12406 + struct hlist_bl_node *pos;
12407 + const void *h_op = key->dk_op.dy_hop;
12410 + hlist_bl_lock(hbl);
12411 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12412 + if (tmp->dk_op.dy_hop == h_op) {
12413 + if (kref_get_unless_zero(&tmp->dk_kref))
12418 + hlist_bl_add_head(&key->dk_hnode, hbl);
12419 + hlist_bl_unlock(hbl);
12426 +static void dy_free_rcu(struct rcu_head *rcu)
12428 + struct au_dykey *key;
12430 + key = container_of(rcu, struct au_dykey, dk_rcu);
12435 +static void dy_free(struct kref *kref)
12437 + struct au_dykey *key;
12438 + struct hlist_bl_head *hbl;
12440 + key = container_of(kref, struct au_dykey, dk_kref);
12441 + hbl = dynop + key->dk_op.dy_type;
12442 + au_hbl_del(&key->dk_hnode, hbl);
12443 + call_rcu(&key->dk_rcu, dy_free_rcu);
12446 +void au_dy_put(struct au_dykey *key)
12448 + kref_put(&key->dk_kref, dy_free);
12451 +/* ---------------------------------------------------------------------- */
12453 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12455 +#ifdef CONFIG_AUFS_DEBUG
12456 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12457 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12459 +#define DyDbgDeclare(cnt) do {} while (0)
12460 +#define DyDbgInc(cnt) do {} while (0)
12463 +#define DySet(func, dst, src, h_op, h_sb) do { \
12465 + if (h_op->func) { \
12467 + dst.func = src.func; \
12469 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12473 +#define DySetForce(func, dst, src) do { \
12474 + AuDebugOn(!src.func); \
12476 + dst.func = src.func; \
12479 +#define DySetAop(func) \
12480 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12481 +#define DySetAopForce(func) \
12482 + DySetForce(func, dyaop->da_op, aufs_aop)
12484 +static void dy_aop(struct au_dykey *key, const void *h_op,
12485 + struct super_block *h_sb __maybe_unused)
12487 + struct au_dyaop *dyaop = (void *)key;
12488 + const struct address_space_operations *h_aop = h_op;
12489 + DyDbgDeclare(cnt);
12491 + AuDbg("%s\n", au_sbtype(h_sb));
12493 + DySetAop(writepage);
12494 + DySetAopForce(readpage); /* force */
12495 + DySetAop(writepages);
12496 + DySetAop(set_page_dirty);
12497 + DySetAop(readpages);
12498 + DySetAop(readahead);
12499 + DySetAop(write_begin);
12500 + DySetAop(write_end);
12502 + DySetAop(invalidatepage);
12503 + DySetAop(releasepage);
12504 + DySetAop(freepage);
12505 + /* this one will be changed according to an aufs mount option */
12506 + DySetAop(direct_IO);
12507 + DySetAop(migratepage);
12508 + DySetAop(isolate_page);
12509 + DySetAop(putback_page);
12510 + DySetAop(launder_page);
12511 + DySetAop(is_partially_uptodate);
12512 + DySetAop(is_dirty_writeback);
12513 + DySetAop(error_remove_page);
12514 + DySetAop(swap_activate);
12515 + DySetAop(swap_deactivate);
12517 + DyDbgSize(cnt, *h_aop);
12520 +/* ---------------------------------------------------------------------- */
12522 +static void dy_bug(struct kref *kref)
12527 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12529 + struct au_dykey *key, *old;
12530 + struct hlist_bl_head *hbl;
12533 + void (*set)(struct au_dykey *key, const void *h_op,
12534 + struct super_block *h_sb __maybe_unused);
12536 + static const struct op a[] = {
12538 + .sz = sizeof(struct au_dyaop),
12542 + const struct op *p;
12544 + hbl = dynop + op->dy_type;
12545 + key = dy_gfind_get(hbl, op->dy_hop);
12547 + goto out_add; /* success */
12549 + p = a + op->dy_type;
12550 + key = kzalloc(p->sz, GFP_NOFS);
12551 + if (unlikely(!key)) {
12552 + key = ERR_PTR(-ENOMEM);
12556 + key->dk_op.dy_hop = op->dy_hop;
12557 + kref_init(&key->dk_kref);
12558 + p->set(key, op->dy_hop, au_br_sb(br));
12559 + old = dy_gadd(hbl, key);
12561 + au_kfree_rcu(key);
12566 + old = dy_bradd(br, key);
12568 + /* its ref-count should never be zero here */
12569 + kref_put(&key->dk_kref, dy_bug);
12574 +/* ---------------------------------------------------------------------- */
12576 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12577 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12578 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12579 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12580 + * See the aufs manual in detail.
12582 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12585 + dyaop->da_op.direct_IO = NULL;
12587 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12590 +static struct au_dyaop *dy_aget(struct au_branch *br,
12591 + const struct address_space_operations *h_aop,
12594 + struct au_dyaop *dyaop;
12595 + struct au_dynop op;
12597 + op.dy_type = AuDy_AOP;
12598 + op.dy_haop = h_aop;
12599 + dyaop = (void *)dy_get(&op, br);
12600 + if (IS_ERR(dyaop))
12602 + dy_adx(dyaop, do_dx);
12608 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12609 + struct inode *h_inode)
12612 + struct super_block *sb;
12613 + struct au_branch *br;
12614 + struct au_dyaop *dyaop;
12616 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12617 + IiMustWriteLock(inode);
12619 + sb = inode->i_sb;
12620 + br = au_sbr(sb, bindex);
12621 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12622 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12623 + err = PTR_ERR(dyaop);
12624 + if (IS_ERR(dyaop))
12625 + /* unnecessary to call dy_fput() */
12629 + inode->i_mapping->a_ops = &dyaop->da_op;
12636 + * Is it safe to replace a_ops during the inode/file is in operation?
12637 + * Yes, I hope so.
12639 +int au_dy_irefresh(struct inode *inode)
12642 + aufs_bindex_t btop;
12643 + struct inode *h_inode;
12646 + if (S_ISREG(inode->i_mode)) {
12647 + btop = au_ibtop(inode);
12648 + h_inode = au_h_iptr(inode, btop);
12649 + err = au_dy_iaop(inode, btop, h_inode);
12654 +void au_dy_arefresh(int do_dx)
12656 + struct hlist_bl_head *hbl;
12657 + struct hlist_bl_node *pos;
12658 + struct au_dykey *key;
12660 + hbl = dynop + AuDy_AOP;
12661 + hlist_bl_lock(hbl);
12662 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12663 + dy_adx((void *)key, do_dx);
12664 + hlist_bl_unlock(hbl);
12667 +/* ---------------------------------------------------------------------- */
12669 +void __init au_dy_init(void)
12673 + for (i = 0; i < AuDyLast; i++)
12674 + INIT_HLIST_BL_HEAD(dynop + i);
12677 +void au_dy_fin(void)
12681 + for (i = 0; i < AuDyLast; i++)
12682 + WARN_ON(!hlist_bl_empty(dynop + i));
12684 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12685 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12686 +++ linux/fs/aufs/dynop.h 2021-12-03 15:38:59.933313976 +0100
12688 +/* SPDX-License-Identifier: GPL-2.0 */
12690 + * Copyright (C) 2010-2021 Junjiro R. Okajima
12692 + * This program, aufs is free software; you can redistribute it and/or modify
12693 + * it under the terms of the GNU General Public License as published by
12694 + * the Free Software Foundation; either version 2 of the License, or
12695 + * (at your option) any later version.
12697 + * This program is distributed in the hope that it will be useful,
12698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12700 + * GNU General Public License for more details.
12702 + * You should have received a copy of the GNU General Public License
12703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12707 + * dynamically customizable operations (for regular files only)
12710 +#ifndef __AUFS_DYNOP_H__
12711 +#define __AUFS_DYNOP_H__
12715 +#include <linux/fs.h>
12716 +#include <linux/kref.h>
12718 +enum {AuDy_AOP, AuDyLast};
12723 + const void *dy_hop;
12724 + const struct address_space_operations *dy_haop;
12730 + struct hlist_bl_node dk_hnode;
12731 + struct rcu_head dk_rcu;
12733 + struct au_dynop dk_op;
12736 + * during I am in the branch local array, kref is gotten. when the
12737 + * branch is removed, kref is put.
12739 + struct kref dk_kref;
12742 +/* stop unioning since their sizes are very different from each other */
12744 + struct au_dykey da_key;
12745 + struct address_space_operations da_op; /* not const */
12747 +/* make sure that 'struct au_dykey *' can be any type */
12748 +static_assert(!offsetof(struct au_dyaop, da_key));
12750 +/* ---------------------------------------------------------------------- */
12754 +void au_dy_put(struct au_dykey *key);
12755 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12756 + struct inode *h_inode);
12757 +int au_dy_irefresh(struct inode *inode);
12758 +void au_dy_arefresh(int do_dio);
12760 +void __init au_dy_init(void);
12761 +void au_dy_fin(void);
12763 +#endif /* __KERNEL__ */
12764 +#endif /* __AUFS_DYNOP_H__ */
12765 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12766 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12767 +++ linux/fs/aufs/export.c 2021-12-03 15:38:59.933313976 +0100
12769 +// SPDX-License-Identifier: GPL-2.0
12771 + * Copyright (C) 2005-2021 Junjiro R. Okajima
12773 + * This program, aufs is free software; you can redistribute it and/or modify
12774 + * it under the terms of the GNU General Public License as published by
12775 + * the Free Software Foundation; either version 2 of the License, or
12776 + * (at your option) any later version.
12778 + * This program is distributed in the hope that it will be useful,
12779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12781 + * GNU General Public License for more details.
12783 + * You should have received a copy of the GNU General Public License
12784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12791 +#include <linux/exportfs.h>
12792 +#include <linux/fs_struct.h>
12793 +#include <linux/namei.h>
12794 +#include <linux/nsproxy.h>
12795 +#include <linux/random.h>
12796 +#include <linux/writeback.h>
12800 +#ifdef CONFIG_AUFS_INO_T_64
12808 +static ino_t decode_ino(__u32 *a)
12812 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12814 +#ifdef CONFIG_AUFS_INO_T_64
12820 +static void encode_ino(__u32 *a, ino_t ino)
12826 +#ifdef CONFIG_AUFS_INO_T_64
12831 +/* NFS file handle */
12835 +#ifdef CONFIG_AUFS_INO_T_64
12836 + /* support 64bit inode number */
12849 + Fh_ino = Fh_ino1,
12850 + Fh_dir_ino = Fh_dir_ino1
12853 +static int au_test_anon(struct dentry *dentry)
12855 + /* note: read d_flags without d_lock */
12856 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12859 +int au_test_nfsd(void)
12862 + struct task_struct *tsk = current;
12863 + char comm[sizeof(tsk->comm)];
12866 + if (tsk->flags & PF_KTHREAD) {
12867 + get_task_comm(comm, tsk);
12868 + ret = !strcmp(comm, "nfsd");
12874 +/* ---------------------------------------------------------------------- */
12875 +/* inode generation external table */
12877 +void au_xigen_inc(struct inode *inode)
12882 + struct super_block *sb;
12883 + struct au_sbinfo *sbinfo;
12885 + sb = inode->i_sb;
12886 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12888 + sbinfo = au_sbi(sb);
12889 + pos = inode->i_ino;
12890 + pos *= sizeof(igen);
12891 + igen = inode->i_generation + 1;
12892 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12893 + if (sz == sizeof(igen))
12894 + return; /* success */
12896 + if (unlikely(sz >= 0))
12897 + AuIOErr("xigen error (%zd)\n", sz);
12900 +int au_xigen_new(struct inode *inode)
12905 + struct super_block *sb;
12906 + struct au_sbinfo *sbinfo;
12907 + struct file *file;
12910 + /* todo: dirty, at mount time */
12911 + if (inode->i_ino == AUFS_ROOT_INO)
12913 + sb = inode->i_sb;
12914 + SiMustAnyLock(sb);
12915 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12919 + pos = inode->i_ino;
12920 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12921 + AuIOErr1("too large i%lld\n", pos);
12924 + pos *= sizeof(inode->i_generation);
12927 + sbinfo = au_sbi(sb);
12928 + file = sbinfo->si_xigen;
12931 + if (vfsub_f_size_read(file)
12932 + < pos + sizeof(inode->i_generation)) {
12933 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12934 + sz = xino_fwrite(file, &inode->i_generation,
12935 + sizeof(inode->i_generation), &pos);
12937 + sz = xino_fread(file, &inode->i_generation,
12938 + sizeof(inode->i_generation), &pos);
12939 + if (sz == sizeof(inode->i_generation))
12940 + goto out; /* success */
12943 + if (unlikely(sz >= 0)) {
12945 + AuIOErr("xigen error (%zd)\n", sz);
12952 +int au_xigen_set(struct super_block *sb, struct path *path)
12955 + struct au_sbinfo *sbinfo;
12956 + struct file *file;
12958 + SiMustWriteLock(sb);
12960 + sbinfo = au_sbi(sb);
12961 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12962 + err = PTR_ERR(file);
12963 + if (IS_ERR(file))
12966 + if (sbinfo->si_xigen)
12967 + fput(sbinfo->si_xigen);
12968 + sbinfo->si_xigen = file;
12975 +void au_xigen_clr(struct super_block *sb)
12977 + struct au_sbinfo *sbinfo;
12979 + SiMustWriteLock(sb);
12981 + sbinfo = au_sbi(sb);
12982 + if (sbinfo->si_xigen) {
12983 + fput(sbinfo->si_xigen);
12984 + sbinfo->si_xigen = NULL;
12988 +/* ---------------------------------------------------------------------- */
12990 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12993 + struct dentry *dentry, *d;
12994 + struct inode *inode;
12995 + unsigned int sigen;
12998 + inode = ilookup(sb, ino);
13002 + dentry = ERR_PTR(-ESTALE);
13003 + sigen = au_sigen(sb);
13004 + if (unlikely(au_is_bad_inode(inode)
13005 + || IS_DEADDIR(inode)
13006 + || sigen != au_iigen(inode, NULL)))
13010 + if (!dir_ino || S_ISDIR(inode->i_mode))
13011 + dentry = d_find_alias(inode);
13013 + spin_lock(&inode->i_lock);
13014 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13015 + spin_lock(&d->d_lock);
13016 + if (!au_test_anon(d)
13017 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13018 + dentry = dget_dlock(d);
13019 + spin_unlock(&d->d_lock);
13022 + spin_unlock(&d->d_lock);
13024 + spin_unlock(&inode->i_lock);
13026 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13027 + /* need to refresh */
13035 + AuTraceErrPtr(dentry);
13039 +/* ---------------------------------------------------------------------- */
13041 +/* todo: dirty? */
13042 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13044 +struct au_compare_mnt_args {
13046 + struct super_block *sb;
13049 + struct vfsmount *mnt;
13052 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13054 + struct au_compare_mnt_args *a = arg;
13056 + if (mnt->mnt_sb != a->sb)
13058 + a->mnt = mntget(mnt);
13062 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13065 + struct path root;
13066 + struct au_compare_mnt_args args = {
13070 + get_fs_root(current->fs, &root);
13072 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13073 + rcu_read_unlock();
13076 + AuDebugOn(!args.mnt);
13080 +struct au_nfsd_si_lock {
13081 + unsigned int sigen;
13082 + aufs_bindex_t bindex, br_id;
13083 + unsigned char force_lock;
13086 +static int si_nfsd_read_lock(struct super_block *sb,
13087 + struct au_nfsd_si_lock *nsi_lock)
13090 + aufs_bindex_t bindex;
13092 + si_read_lock(sb, AuLock_FLUSH);
13094 + /* branch id may be wrapped around */
13096 + bindex = au_br_index(sb, nsi_lock->br_id);
13097 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13098 + goto out; /* success */
13102 + if (!nsi_lock->force_lock)
13103 + si_read_unlock(sb);
13106 + nsi_lock->bindex = bindex;
13110 +struct find_name_by_ino {
13111 + struct dir_context ctx;
13112 + int called, found;
13119 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13120 + loff_t offset, u64 ino, unsigned int d_type)
13122 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13126 + if (a->ino != ino)
13129 + memcpy(a->name, name, namelen);
13130 + a->namelen = namelen;
13135 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13136 + struct au_nfsd_si_lock *nsi_lock)
13138 + struct dentry *dentry, *parent;
13139 + struct file *file;
13140 + struct inode *dir;
13141 + struct find_name_by_ino arg = {
13143 + .actor = find_name_by_ino
13148 + parent = path->dentry;
13150 + si_read_unlock(parent->d_sb);
13151 + file = vfsub_dentry_open(path, au_dir_roflags);
13152 + dentry = (void *)file;
13153 + if (IS_ERR(file))
13156 + dentry = ERR_PTR(-ENOMEM);
13157 + arg.name = (void *)__get_free_page(GFP_NOFS);
13158 + if (unlikely(!arg.name))
13165 + err = vfsub_iterate_dir(file, &arg.ctx);
13166 + } while (!err && !arg.found && arg.called);
13167 + dentry = ERR_PTR(err);
13168 + if (unlikely(err))
13170 + /* instead of ENOENT */
13171 + dentry = ERR_PTR(-ESTALE);
13175 + /* do not call vfsub_lkup_one() */
13176 + dir = d_inode(parent);
13177 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13178 + AuTraceErrPtr(dentry);
13179 + if (IS_ERR(dentry))
13181 + AuDebugOn(au_test_anon(dentry));
13182 + if (unlikely(d_really_is_negative(dentry))) {
13184 + dentry = ERR_PTR(-ENOENT);
13188 + free_page((unsigned long)arg.name);
13192 + if (unlikely(nsi_lock
13193 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13194 + if (!IS_ERR(dentry)) {
13196 + dentry = ERR_PTR(-ESTALE);
13198 + AuTraceErrPtr(dentry);
13202 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13204 + struct au_nfsd_si_lock *nsi_lock)
13206 + struct dentry *dentry;
13207 + struct path path;
13209 + if (dir_ino != AUFS_ROOT_INO) {
13210 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13211 + dentry = path.dentry;
13212 + if (!path.dentry || IS_ERR(path.dentry))
13214 + AuDebugOn(au_test_anon(path.dentry));
13216 + path.dentry = dget(sb->s_root);
13218 + path.mnt = au_mnt_get(sb);
13219 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13223 + AuTraceErrPtr(dentry);
13227 +/* ---------------------------------------------------------------------- */
13229 +static int h_acceptable(void *expv, struct dentry *dentry)
13234 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13235 + char *buf, int len, struct super_block *sb)
13239 + struct path path;
13241 + p = d_path(h_rootpath, buf, len);
13246 + path.mnt = h_rootpath->mnt;
13247 + path.dentry = h_parent;
13248 + p = d_path(&path, buf, len);
13254 + path.mnt = au_mnt_get(sb);
13255 + path.dentry = sb->s_root;
13256 + p = d_path(&path, buf, len - strlen(p));
13257 + mntput(path.mnt);
13261 + p[strlen(p)] = '/';
13264 + AuTraceErrPtr(p);
13269 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13270 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13272 + struct dentry *dentry, *h_parent, *root;
13273 + struct super_block *h_sb;
13274 + char *pathname, *p;
13275 + struct vfsmount *h_mnt;
13276 + struct au_branch *br;
13278 + struct path path;
13280 + br = au_sbr(sb, nsi_lock->bindex);
13281 + h_mnt = au_br_mnt(br);
13282 + h_sb = h_mnt->mnt_sb;
13283 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13285 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13286 + fh_len - Fh_tail, fh[Fh_h_type],
13287 + h_acceptable, /*context*/NULL);
13289 + dentry = h_parent;
13290 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13291 + AuWarn1("%s decode_fh failed, %ld\n",
13292 + au_sbtype(h_sb), PTR_ERR(h_parent));
13296 + if (unlikely(au_test_anon(h_parent))) {
13297 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13298 + au_sbtype(h_sb));
13299 + goto out_h_parent;
13302 + dentry = ERR_PTR(-ENOMEM);
13303 + pathname = (void *)__get_free_page(GFP_NOFS);
13304 + if (unlikely(!pathname))
13305 + goto out_h_parent;
13307 + root = sb->s_root;
13308 + path.mnt = h_mnt;
13309 + di_read_lock_parent(root, !AuLock_IR);
13310 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13311 + di_read_unlock(root, !AuLock_IR);
13312 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13313 + dentry = (void *)p;
13315 + goto out_pathname;
13317 + si_read_unlock(sb);
13318 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13319 + dentry = ERR_PTR(err);
13320 + if (unlikely(err))
13323 + dentry = ERR_PTR(-ENOENT);
13324 + AuDebugOn(au_test_anon(path.dentry));
13325 + if (unlikely(d_really_is_negative(path.dentry)))
13328 + if (ino != d_inode(path.dentry)->i_ino)
13329 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13331 + dentry = dget(path.dentry);
13336 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13337 + if (!IS_ERR(dentry)) {
13339 + dentry = ERR_PTR(-ESTALE);
13342 + free_page((unsigned long)pathname);
13346 + AuTraceErrPtr(dentry);
13350 +/* ---------------------------------------------------------------------- */
13352 +static struct dentry *
13353 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13356 + struct dentry *dentry;
13357 + __u32 *fh = fid->raw;
13358 + struct au_branch *br;
13359 + ino_t ino, dir_ino;
13360 + struct au_nfsd_si_lock nsi_lock = {
13364 + dentry = ERR_PTR(-ESTALE);
13365 + /* it should never happen, but the file handle is unreliable */
13366 + if (unlikely(fh_len < Fh_tail))
13368 + nsi_lock.sigen = fh[Fh_sigen];
13369 + nsi_lock.br_id = fh[Fh_br_id];
13371 + /* branch id may be wrapped around */
13373 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13375 + nsi_lock.force_lock = 1;
13377 + /* is this inode still cached? */
13378 + ino = decode_ino(fh + Fh_ino);
13379 + /* it should never happen */
13380 + if (unlikely(ino == AUFS_ROOT_INO))
13383 + dir_ino = decode_ino(fh + Fh_dir_ino);
13384 + dentry = decode_by_ino(sb, ino, dir_ino);
13385 + if (IS_ERR(dentry))
13390 + /* is the parent dir cached? */
13391 + br = au_sbr(sb, nsi_lock.bindex);
13392 + au_lcnt_inc(&br->br_nfiles);
13393 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13394 + if (IS_ERR(dentry))
13399 + /* lookup path */
13400 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13401 + if (IS_ERR(dentry))
13403 + if (unlikely(!dentry))
13404 + /* todo?: make it ESTALE */
13408 + if (!au_digen_test(dentry, au_sigen(sb))
13409 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13410 + goto out_unlock; /* success */
13413 + dentry = ERR_PTR(-ESTALE);
13416 + au_lcnt_dec(&br->br_nfiles);
13417 + si_read_unlock(sb);
13419 + AuTraceErrPtr(dentry);
13423 +#if 0 /* reserved for future use */
13424 +/* support subtreecheck option */
13425 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13426 + int fh_len, int fh_type)
13428 + struct dentry *parent;
13429 + __u32 *fh = fid->raw;
13432 + dir_ino = decode_ino(fh + Fh_dir_ino);
13433 + parent = decode_by_ino(sb, dir_ino, 0);
13434 + if (IS_ERR(parent))
13437 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13438 + dir_ino, fh, fh_len);
13441 + AuTraceErrPtr(parent);
13446 +/* ---------------------------------------------------------------------- */
13448 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13449 + struct inode *dir)
13452 + aufs_bindex_t bindex;
13453 + struct super_block *sb, *h_sb;
13454 + struct dentry *dentry, *parent, *h_parent;
13455 + struct inode *h_dir;
13456 + struct au_branch *br;
13459 + if (unlikely(*max_len <= Fh_tail)) {
13460 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13464 + err = FILEID_ROOT;
13465 + if (inode->i_ino == AUFS_ROOT_INO) {
13466 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13471 + sb = inode->i_sb;
13472 + err = si_read_lock(sb, AuLock_FLUSH);
13473 + if (unlikely(err))
13476 +#ifdef CONFIG_AUFS_DEBUG
13477 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13478 + AuWarn1("NFS-exporting requires xino\n");
13482 + ii_read_lock_child(inode);
13483 + bindex = au_ibtop(inode);
13485 + dentry = d_find_any_alias(inode);
13486 + if (unlikely(!dentry))
13488 + AuDebugOn(au_test_anon(dentry));
13489 + parent = dget_parent(dentry);
13491 + if (unlikely(!parent))
13493 + if (d_really_is_positive(parent))
13494 + dir = d_inode(parent);
13497 + ii_read_lock_parent(dir);
13498 + h_dir = au_h_iptr(dir, bindex);
13499 + ii_read_unlock(dir);
13500 + if (unlikely(!h_dir))
13502 + h_parent = d_find_any_alias(h_dir);
13503 + if (unlikely(!h_parent))
13504 + goto out_hparent;
13507 + br = au_sbr(sb, bindex);
13508 + h_sb = au_br_sb(br);
13509 + if (unlikely(!h_sb->s_export_op)) {
13510 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13511 + goto out_hparent;
13514 + fh[Fh_br_id] = br->br_id;
13515 + fh[Fh_sigen] = au_sigen(sb);
13516 + encode_ino(fh + Fh_ino, inode->i_ino);
13517 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13518 + fh[Fh_igen] = inode->i_generation;
13520 + *max_len -= Fh_tail;
13521 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13523 + /*connectable or subtreecheck*/0);
13524 + err = fh[Fh_h_type];
13525 + *max_len += Fh_tail;
13526 + /* todo: macros? */
13527 + if (err != FILEID_INVALID)
13530 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13537 + ii_read_unlock(inode);
13538 + si_read_unlock(sb);
13540 + if (unlikely(err < 0))
13541 + err = FILEID_INVALID;
13545 +/* ---------------------------------------------------------------------- */
13547 +static int aufs_commit_metadata(struct inode *inode)
13550 + aufs_bindex_t bindex;
13551 + struct super_block *sb;
13552 + struct inode *h_inode;
13553 + int (*f)(struct inode *inode);
13555 + sb = inode->i_sb;
13556 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13557 + ii_write_lock_child(inode);
13558 + bindex = au_ibtop(inode);
13559 + AuDebugOn(bindex < 0);
13560 + h_inode = au_h_iptr(inode, bindex);
13562 + f = h_inode->i_sb->s_export_op->commit_metadata;
13564 + err = f(h_inode);
13566 + struct writeback_control wbc = {
13567 + .sync_mode = WB_SYNC_ALL,
13568 + .nr_to_write = 0 /* metadata only */
13571 + err = sync_inode(h_inode, &wbc);
13574 + au_cpup_attr_timesizes(inode);
13575 + ii_write_unlock(inode);
13576 + si_read_unlock(sb);
13580 +/* ---------------------------------------------------------------------- */
13582 +static struct export_operations aufs_export_op = {
13583 + .fh_to_dentry = aufs_fh_to_dentry,
13584 + /* .fh_to_parent = aufs_fh_to_parent, */
13585 + .encode_fh = aufs_encode_fh,
13586 + .commit_metadata = aufs_commit_metadata
13589 +void au_export_init(struct super_block *sb)
13591 + struct au_sbinfo *sbinfo;
13594 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13595 + && IS_MODULE(CONFIG_EXPORTFS),
13596 + AUFS_NAME ": unsupported configuration "
13597 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13599 + sb->s_export_op = &aufs_export_op;
13600 + sbinfo = au_sbi(sb);
13601 + sbinfo->si_xigen = NULL;
13602 + get_random_bytes(&u, sizeof(u));
13603 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13604 + atomic_set(&sbinfo->si_xigen_next, u);
13606 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13607 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13608 +++ linux/fs/aufs/fhsm.c 2021-12-03 15:38:59.933313976 +0100
13610 +// SPDX-License-Identifier: GPL-2.0
13612 + * Copyright (C) 2011-2021 Junjiro R. Okajima
13614 + * This program, aufs is free software; you can redistribute it and/or modify
13615 + * it under the terms of the GNU General Public License as published by
13616 + * the Free Software Foundation; either version 2 of the License, or
13617 + * (at your option) any later version.
13619 + * This program is distributed in the hope that it will be useful,
13620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13622 + * GNU General Public License for more details.
13624 + * You should have received a copy of the GNU General Public License
13625 + * along with this program; if not, write to the Free Software
13626 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
13630 + * File-based Hierarchy Storage Management
13633 +#include <linux/anon_inodes.h>
13634 +#include <linux/poll.h>
13635 +#include <linux/seq_file.h>
13636 +#include <linux/statfs.h>
13639 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13641 + struct au_sbinfo *sbinfo;
13642 + struct au_fhsm *fhsm;
13644 + SiMustAnyLock(sb);
13646 + sbinfo = au_sbi(sb);
13647 + fhsm = &sbinfo->si_fhsm;
13648 + AuDebugOn(!fhsm);
13649 + return fhsm->fhsm_bottom;
13652 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13654 + struct au_sbinfo *sbinfo;
13655 + struct au_fhsm *fhsm;
13657 + SiMustWriteLock(sb);
13659 + sbinfo = au_sbi(sb);
13660 + fhsm = &sbinfo->si_fhsm;
13661 + AuDebugOn(!fhsm);
13662 + fhsm->fhsm_bottom = bindex;
13665 +/* ---------------------------------------------------------------------- */
13667 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13669 + struct au_br_fhsm *bf;
13671 + bf = br->br_fhsm;
13672 + MtxMustLock(&bf->bf_lock);
13674 + return !bf->bf_readable
13675 + || time_after(jiffies,
13676 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13679 +/* ---------------------------------------------------------------------- */
13681 +static void au_fhsm_notify(struct super_block *sb, int val)
13683 + struct au_sbinfo *sbinfo;
13684 + struct au_fhsm *fhsm;
13686 + SiMustAnyLock(sb);
13688 + sbinfo = au_sbi(sb);
13689 + fhsm = &sbinfo->si_fhsm;
13690 + if (au_fhsm_pid(fhsm)
13691 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13692 + atomic_set(&fhsm->fhsm_readable, val);
13694 + wake_up(&fhsm->fhsm_wqh);
13698 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13699 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13702 + struct au_branch *br;
13703 + struct au_br_fhsm *bf;
13705 + br = au_sbr(sb, bindex);
13706 + AuDebugOn(au_br_rdonly(br));
13707 + bf = br->br_fhsm;
13711 + mutex_lock(&bf->bf_lock);
13713 + MtxMustLock(&bf->bf_lock);
13715 + /* sb->s_root for NFS is unreliable */
13716 + err = au_br_stfs(br, &bf->bf_stfs);
13717 + if (unlikely(err)) {
13718 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13722 + bf->bf_jiffy = jiffies;
13723 + bf->bf_readable = 1;
13725 + au_fhsm_notify(sb, /*val*/1);
13727 + *rstfs = bf->bf_stfs;
13731 + mutex_unlock(&bf->bf_lock);
13732 + au_fhsm_notify(sb, /*val*/1);
13737 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13740 + struct au_sbinfo *sbinfo;
13741 + struct au_fhsm *fhsm;
13742 + struct au_branch *br;
13743 + struct au_br_fhsm *bf;
13745 + AuDbg("b%d, force %d\n", bindex, force);
13746 + SiMustAnyLock(sb);
13748 + sbinfo = au_sbi(sb);
13749 + fhsm = &sbinfo->si_fhsm;
13750 + if (!au_ftest_si(sbinfo, FHSM)
13751 + || fhsm->fhsm_bottom == bindex)
13754 + br = au_sbr(sb, bindex);
13755 + bf = br->br_fhsm;
13757 + mutex_lock(&bf->bf_lock);
13759 + || au_fhsm_pid(fhsm)
13760 + || au_fhsm_test_jiffy(sbinfo, br))
13761 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13763 + mutex_unlock(&bf->bf_lock);
13766 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13768 + aufs_bindex_t bindex, bbot;
13769 + struct au_branch *br;
13771 + /* exclude the bottom */
13772 + bbot = au_fhsm_bottom(sb);
13773 + for (bindex = 0; bindex < bbot; bindex++) {
13774 + br = au_sbr(sb, bindex);
13775 + if (au_br_fhsm(br->br_perm))
13776 + au_fhsm_wrote(sb, bindex, force);
13780 +/* ---------------------------------------------------------------------- */
13782 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13785 + struct au_sbinfo *sbinfo;
13786 + struct au_fhsm *fhsm;
13789 + sbinfo = file->private_data;
13790 + fhsm = &sbinfo->si_fhsm;
13791 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13792 + if (atomic_read(&fhsm->fhsm_readable))
13793 + mask = EPOLLIN /* | EPOLLRDNORM */;
13796 + AuDbg("mask 0x%x\n", mask);
13800 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13801 + struct aufs_stfs *stfs, __s16 brid)
13805 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13807 + err = __put_user(brid, &stbr->brid);
13808 + if (unlikely(err))
13814 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13815 + struct aufs_stbr __user *stbr, size_t count)
13819 + aufs_bindex_t bindex, bbot;
13820 + struct au_branch *br;
13821 + struct au_br_fhsm *bf;
13823 + /* except the bottom branch */
13826 + bbot = au_fhsm_bottom(sb);
13827 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13828 + br = au_sbr(sb, bindex);
13829 + if (!au_br_fhsm(br->br_perm))
13832 + bf = br->br_fhsm;
13833 + mutex_lock(&bf->bf_lock);
13834 + if (bf->bf_readable) {
13836 + if (count >= sizeof(*stbr))
13837 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13840 + bf->bf_readable = 0;
13841 + count -= sizeof(*stbr);
13845 + mutex_unlock(&bf->bf_lock);
13848 + err = sizeof(*stbr) * nstbr;
13853 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13858 + aufs_bindex_t nfhsm, bindex, bbot;
13859 + struct au_sbinfo *sbinfo;
13860 + struct au_fhsm *fhsm;
13861 + struct au_branch *br;
13862 + struct super_block *sb;
13865 + sbinfo = file->private_data;
13866 + fhsm = &sbinfo->si_fhsm;
13868 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13869 + if (!atomic_read(&fhsm->fhsm_readable)) {
13870 + if (vfsub_file_flags(file) & O_NONBLOCK)
13873 + err = wait_event_interruptible_locked_irq
13875 + atomic_read(&fhsm->fhsm_readable));
13877 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13878 + if (unlikely(err))
13881 + /* sb may already be dead */
13882 + au_rw_read_lock(&sbinfo->si_rwsem);
13883 + readable = atomic_read(&fhsm->fhsm_readable);
13884 + if (readable > 0) {
13885 + sb = sbinfo->si_sb;
13887 + /* exclude the bottom branch */
13889 + bbot = au_fhsm_bottom(sb);
13890 + for (bindex = 0; bindex < bbot; bindex++) {
13891 + br = au_sbr(sb, bindex);
13892 + if (au_br_fhsm(br->br_perm))
13896 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13897 + atomic_set(&fhsm->fhsm_readable, 0);
13898 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13902 + au_rw_read_unlock(&sbinfo->si_rwsem);
13910 +static int au_fhsm_release(struct inode *inode, struct file *file)
13912 + struct au_sbinfo *sbinfo;
13913 + struct au_fhsm *fhsm;
13915 + /* sb may already be dead */
13916 + sbinfo = file->private_data;
13917 + fhsm = &sbinfo->si_fhsm;
13918 + spin_lock(&fhsm->fhsm_spin);
13919 + fhsm->fhsm_pid = 0;
13920 + spin_unlock(&fhsm->fhsm_spin);
13921 + kobject_put(&sbinfo->si_kobj);
13926 +static const struct file_operations au_fhsm_fops = {
13927 + .owner = THIS_MODULE,
13928 + .llseek = noop_llseek,
13929 + .read = au_fhsm_read,
13930 + .poll = au_fhsm_poll,
13931 + .release = au_fhsm_release
13934 +int au_fhsm_fd(struct super_block *sb, int oflags)
13937 + struct au_sbinfo *sbinfo;
13938 + struct au_fhsm *fhsm;
13941 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13945 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13949 + sbinfo = au_sbi(sb);
13950 + fhsm = &sbinfo->si_fhsm;
13951 + spin_lock(&fhsm->fhsm_spin);
13952 + if (!fhsm->fhsm_pid)
13953 + fhsm->fhsm_pid = current->pid;
13956 + spin_unlock(&fhsm->fhsm_spin);
13957 + if (unlikely(err))
13960 + oflags |= O_RDONLY;
13961 + /* oflags |= FMODE_NONOTIFY; */
13962 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13964 + if (unlikely(fd < 0))
13967 + /* succeed regardless 'fhsm' status */
13968 + kobject_get(&sbinfo->si_kobj);
13969 + si_noflush_read_lock(sb);
13970 + if (au_ftest_si(sbinfo, FHSM))
13971 + au_fhsm_wrote_all(sb, /*force*/0);
13972 + si_read_unlock(sb);
13973 + goto out; /* success */
13976 + spin_lock(&fhsm->fhsm_spin);
13977 + fhsm->fhsm_pid = 0;
13978 + spin_unlock(&fhsm->fhsm_spin);
13984 +/* ---------------------------------------------------------------------- */
13986 +int au_fhsm_br_alloc(struct au_branch *br)
13991 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13993 + au_br_fhsm_init(br->br_fhsm);
14000 +/* ---------------------------------------------------------------------- */
14002 +void au_fhsm_fin(struct super_block *sb)
14004 + au_fhsm_notify(sb, /*val*/-1);
14007 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14009 + struct au_fhsm *fhsm;
14011 + fhsm = &sbinfo->si_fhsm;
14012 + spin_lock_init(&fhsm->fhsm_spin);
14013 + init_waitqueue_head(&fhsm->fhsm_wqh);
14014 + atomic_set(&fhsm->fhsm_readable, 0);
14015 + fhsm->fhsm_expire
14016 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14017 + fhsm->fhsm_bottom = -1;
14020 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14022 + sbinfo->si_fhsm.fhsm_expire
14023 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14026 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14030 + if (!au_ftest_si(sbinfo, FHSM))
14033 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14034 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14035 + seq_printf(seq, ",fhsm_sec=%u", u);
14037 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14038 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14039 +++ linux/fs/aufs/file.c 2021-12-03 15:38:59.936647310 +0100
14041 +// SPDX-License-Identifier: GPL-2.0
14043 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14045 + * This program, aufs is free software; you can redistribute it and/or modify
14046 + * it under the terms of the GNU General Public License as published by
14047 + * the Free Software Foundation; either version 2 of the License, or
14048 + * (at your option) any later version.
14050 + * This program is distributed in the hope that it will be useful,
14051 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14052 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14053 + * GNU General Public License for more details.
14055 + * You should have received a copy of the GNU General Public License
14056 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14060 + * handling file/dir, and address_space operation
14063 +#ifdef CONFIG_AUFS_DEBUG
14064 +#include <linux/migrate.h>
14066 +#include <linux/pagemap.h>
14069 +/* drop flags for writing */
14070 +unsigned int au_file_roflags(unsigned int flags)
14072 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14073 + flags |= O_RDONLY | O_NOATIME;
14077 +/* common functions to regular file and dir */
14078 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14079 + struct file *file, int force_wr)
14081 + struct file *h_file;
14082 + struct dentry *h_dentry;
14083 + struct inode *h_inode;
14084 + struct super_block *sb;
14085 + struct au_branch *br;
14086 + struct path h_path;
14089 + /* a race condition can happen between open and unlink/rmdir */
14090 + h_file = ERR_PTR(-ENOENT);
14091 + h_dentry = au_h_dptr(dentry, bindex);
14092 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14094 + h_inode = d_inode(h_dentry);
14095 + spin_lock(&h_dentry->d_lock);
14096 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14097 + /* || !d_inode(dentry)->i_nlink */
14099 + spin_unlock(&h_dentry->d_lock);
14100 + if (unlikely(err))
14103 + sb = dentry->d_sb;
14104 + br = au_sbr(sb, bindex);
14105 + err = au_br_test_oflag(flags, br);
14106 + h_file = ERR_PTR(err);
14107 + if (unlikely(err))
14110 + /* drop flags for writing */
14111 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14112 + if (force_wr && !(flags & O_WRONLY))
14114 + flags = au_file_roflags(flags);
14116 + h_file = ERR_PTR(-EROFS);
14117 + flags = au_file_roflags(flags);
14118 + if (unlikely(vfsub_native_ro(h_inode)
14119 + || IS_APPEND(h_inode)))
14121 + flags &= ~O_ACCMODE;
14122 + flags |= O_WRONLY;
14125 + flags &= ~O_CREAT;
14126 + au_lcnt_inc(&br->br_nfiles);
14127 + h_path.dentry = h_dentry;
14128 + h_path.mnt = au_br_mnt(br);
14129 + h_file = vfsub_dentry_open(&h_path, flags);
14130 + if (IS_ERR(h_file))
14133 + if (flags & __FMODE_EXEC) {
14134 + err = deny_write_access(h_file);
14135 + if (unlikely(err)) {
14137 + h_file = ERR_PTR(err);
14141 + fsnotify_open(h_file);
14142 + goto out; /* success */
14145 + au_lcnt_dec(&br->br_nfiles);
14150 +static int au_cmoo(struct dentry *dentry)
14152 + int err, cmoo, matched;
14153 + unsigned int udba;
14154 + struct path h_path;
14155 + struct au_pin pin;
14156 + struct au_cp_generic cpg = {
14157 + .dentry = dentry,
14162 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14164 + struct inode *delegated;
14165 + struct super_block *sb;
14166 + struct au_sbinfo *sbinfo;
14167 + struct au_fhsm *fhsm;
14169 + struct au_branch *br;
14170 + struct dentry *parent;
14171 + struct au_hinode *hdir;
14173 + DiMustWriteLock(dentry);
14174 + IiMustWriteLock(d_inode(dentry));
14177 + if (IS_ROOT(dentry))
14179 + cpg.bsrc = au_dbtop(dentry);
14183 + sb = dentry->d_sb;
14184 + sbinfo = au_sbi(sb);
14185 + fhsm = &sbinfo->si_fhsm;
14186 + pid = au_fhsm_pid(fhsm);
14189 + && (current->pid == pid
14190 + || rcu_dereference(current->real_parent)->pid == pid));
14191 + rcu_read_unlock();
14195 + br = au_sbr(sb, cpg.bsrc);
14196 + cmoo = au_br_cmoo(br->br_perm);
14199 + if (!d_is_reg(dentry))
14200 + cmoo &= AuBrAttr_COO_ALL;
14204 + parent = dget_parent(dentry);
14205 + di_write_lock_parent(parent);
14206 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14208 + if (unlikely(err < 0)) {
14209 + err = 0; /* there is no upper writable branch */
14212 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14214 + /* do not respect the coo attrib for the target branch */
14215 + err = au_cpup_dirs(dentry, cpg.bdst);
14216 + if (unlikely(err))
14219 + di_downgrade_lock(parent, AuLock_IR);
14220 + udba = au_opt_udba(sb);
14221 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14222 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14223 + if (unlikely(err))
14226 + err = au_sio_cpup_simple(&cpg);
14228 + if (unlikely(err))
14230 + if (!(cmoo & AuBrWAttr_MOO))
14231 + goto out_parent; /* success */
14233 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14234 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14235 + if (unlikely(err))
14238 + h_path.mnt = au_br_mnt(br);
14239 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14240 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14241 + delegated = NULL;
14242 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14244 + /* todo: keep h_dentry or not? */
14245 + if (unlikely(err == -EWOULDBLOCK)) {
14246 + pr_warn("cannot retry for NFSv4 delegation"
14247 + " for an internal unlink\n");
14250 + if (unlikely(err)) {
14251 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14255 + goto out_parent; /* success */
14258 + di_downgrade_lock(parent, AuLock_IR);
14260 + di_read_unlock(parent, AuLock_IR);
14267 +int au_do_open(struct file *file, struct au_do_open_args *args)
14269 + int err, aopen = args->aopen;
14270 + struct dentry *dentry;
14271 + struct au_finfo *finfo;
14274 + err = au_finfo_init(file, args->fidir);
14277 + err = au_finfo_init(file, args->fidir);
14280 + if (unlikely(err))
14283 + dentry = file->f_path.dentry;
14284 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14285 + di_write_lock_child(dentry);
14286 + err = au_cmoo(dentry);
14287 + di_downgrade_lock(dentry, AuLock_IR);
14290 + err = args->open(file, vfsub_file_flags(file), NULL);
14293 + err = args->open(file, vfsub_file_flags(file),
14298 + di_read_unlock(dentry, AuLock_IR);
14300 + finfo = au_fi(file);
14302 + finfo->fi_file = file;
14303 + au_hbl_add(&finfo->fi_hlist,
14304 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14307 + fi_write_unlock(file);
14310 + fi_write_unlock(file);
14313 + if (unlikely(err)) {
14314 + finfo->fi_hdir = NULL;
14315 + au_finfo_fin(file);
14323 +int au_reopen_nondir(struct file *file)
14326 + aufs_bindex_t btop;
14327 + struct dentry *dentry;
14328 + struct au_branch *br;
14329 + struct file *h_file, *h_file_tmp;
14331 + dentry = file->f_path.dentry;
14332 + btop = au_dbtop(dentry);
14333 + br = au_sbr(dentry->d_sb, btop);
14334 + h_file_tmp = NULL;
14335 + if (au_fbtop(file) == btop) {
14336 + h_file = au_hf_top(file);
14337 + if (file->f_mode == h_file->f_mode)
14338 + return 0; /* success */
14339 + h_file_tmp = h_file;
14340 + get_file(h_file_tmp);
14341 + au_lcnt_inc(&br->br_nfiles);
14342 + au_set_h_fptr(file, btop, NULL);
14344 + AuDebugOn(au_fi(file)->fi_hdir);
14347 + * file exists on both of rw and ro
14348 + * open --> dbtop and fbtop are both 0
14349 + * prepend a branch as rw, "rw" become ro
14351 + * delete the top branch, "rw" becomes rw again
14352 + * --> dbtop is 1, fbtop is still 0
14353 + * write --> fbtop is 0 but dbtop is 1
14355 + /* AuDebugOn(au_fbtop(file) < btop); */
14357 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14358 + file, /*force_wr*/0);
14359 + err = PTR_ERR(h_file);
14360 + if (IS_ERR(h_file)) {
14361 + if (h_file_tmp) {
14363 + au_set_h_fptr(file, btop, h_file_tmp);
14364 + h_file_tmp = NULL;
14366 + goto out; /* todo: close all? */
14370 + au_set_fbtop(file, btop);
14371 + au_set_h_fptr(file, btop, h_file);
14372 + au_update_figen(file);
14373 + /* todo: necessary? */
14374 + /* file->f_ra = h_file->f_ra; */
14377 + if (h_file_tmp) {
14378 + fput(h_file_tmp);
14379 + au_lcnt_dec(&br->br_nfiles);
14384 +/* ---------------------------------------------------------------------- */
14386 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14387 + struct dentry *hi_wh)
14390 + aufs_bindex_t btop;
14391 + struct au_dinfo *dinfo;
14392 + struct dentry *h_dentry;
14393 + struct au_hdentry *hdp;
14395 + dinfo = au_di(file->f_path.dentry);
14396 + AuRwMustWriteLock(&dinfo->di_rwsem);
14398 + btop = dinfo->di_btop;
14399 + dinfo->di_btop = btgt;
14400 + hdp = au_hdentry(dinfo, btgt);
14401 + h_dentry = hdp->hd_dentry;
14402 + hdp->hd_dentry = hi_wh;
14403 + err = au_reopen_nondir(file);
14404 + hdp->hd_dentry = h_dentry;
14405 + dinfo->di_btop = btop;
14410 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14411 + aufs_bindex_t bcpup, struct au_pin *pin)
14414 + struct inode *inode, *h_inode;
14415 + struct dentry *h_dentry, *hi_wh;
14416 + struct au_cp_generic cpg = {
14417 + .dentry = file->f_path.dentry,
14424 + au_update_dbtop(cpg.dentry);
14425 + inode = d_inode(cpg.dentry);
14427 + if (au_dbtop(cpg.dentry) <= bcpup
14428 + && au_dbbot(cpg.dentry) >= bcpup) {
14429 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14430 + if (h_dentry && d_is_positive(h_dentry))
14431 + h_inode = d_inode(h_dentry);
14433 + hi_wh = au_hi_wh(inode, bcpup);
14434 + if (!hi_wh && !h_inode)
14435 + err = au_sio_cpup_wh(&cpg, file);
14437 + /* already copied-up after unlink */
14438 + err = au_reopen_wh(file, bcpup, hi_wh);
14441 + && (inode->i_nlink > 1
14442 + || (inode->i_state & I_LINKABLE))
14443 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14444 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14450 + * prepare the @file for writing.
14452 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14455 + aufs_bindex_t dbtop;
14456 + struct dentry *parent;
14457 + struct inode *inode;
14458 + struct super_block *sb;
14459 + struct file *h_file;
14460 + struct au_cp_generic cpg = {
14461 + .dentry = file->f_path.dentry,
14466 + .flags = AuCpup_DTIME
14469 + sb = cpg.dentry->d_sb;
14470 + inode = d_inode(cpg.dentry);
14471 + cpg.bsrc = au_fbtop(file);
14472 + err = au_test_ro(sb, cpg.bsrc, inode);
14473 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14474 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14479 + /* need to cpup or reopen */
14480 + parent = dget_parent(cpg.dentry);
14481 + di_write_lock_parent(parent);
14482 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14484 + if (unlikely(err < 0))
14488 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14489 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14490 + if (unlikely(err))
14494 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14495 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14496 + if (unlikely(err))
14499 + dbtop = au_dbtop(cpg.dentry);
14500 + if (dbtop <= cpg.bdst)
14501 + cpg.bsrc = cpg.bdst;
14503 + if (dbtop <= cpg.bdst /* just reopen */
14504 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14506 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14507 + if (IS_ERR(h_file))
14508 + err = PTR_ERR(h_file);
14510 + di_downgrade_lock(parent, AuLock_IR);
14511 + if (dbtop > cpg.bdst)
14512 + err = au_sio_cpup_simple(&cpg);
14514 + err = au_reopen_nondir(file);
14515 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14517 + } else { /* copyup as wh and reopen */
14519 + * since writable hfsplus branch is not supported,
14520 + * h_open_pre/post() are unnecessary.
14522 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14523 + di_downgrade_lock(parent, AuLock_IR);
14527 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14528 + goto out_dput; /* success */
14534 + di_downgrade_lock(parent, AuLock_IR);
14536 + di_read_unlock(parent, AuLock_IR);
14543 +/* ---------------------------------------------------------------------- */
14545 +int au_do_flush(struct file *file, fl_owner_t id,
14546 + int (*flush)(struct file *file, fl_owner_t id))
14549 + struct super_block *sb;
14550 + struct inode *inode;
14552 + inode = file_inode(file);
14553 + sb = inode->i_sb;
14554 + si_noflush_read_lock(sb);
14555 + fi_read_lock(file);
14556 + ii_read_lock_child(inode);
14558 + err = flush(file, id);
14559 + au_cpup_attr_timesizes(inode);
14561 + ii_read_unlock(inode);
14562 + fi_read_unlock(file);
14563 + si_read_unlock(sb);
14567 +/* ---------------------------------------------------------------------- */
14569 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14572 + struct au_pin pin;
14573 + struct au_finfo *finfo;
14574 + struct dentry *parent, *hi_wh;
14575 + struct inode *inode;
14576 + struct super_block *sb;
14577 + struct au_cp_generic cpg = {
14578 + .dentry = file->f_path.dentry,
14583 + .flags = AuCpup_DTIME
14586 + FiMustWriteLock(file);
14589 + finfo = au_fi(file);
14590 + sb = cpg.dentry->d_sb;
14591 + inode = d_inode(cpg.dentry);
14592 + cpg.bdst = au_ibtop(inode);
14593 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14596 + parent = dget_parent(cpg.dentry);
14597 + if (au_test_ro(sb, cpg.bdst, inode)) {
14598 + di_read_lock_parent(parent, !AuLock_IR);
14599 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14601 + di_read_unlock(parent, !AuLock_IR);
14602 + if (unlikely(err < 0))
14607 + di_read_lock_parent(parent, AuLock_IR);
14608 + hi_wh = au_hi_wh(inode, cpg.bdst);
14609 + if (!S_ISDIR(inode->i_mode)
14610 + && au_opt_test(au_mntflags(sb), PLINK)
14611 + && au_plink_test(inode)
14612 + && !d_unhashed(cpg.dentry)
14613 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14614 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14615 + if (unlikely(err))
14618 + /* always superio. */
14619 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14620 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14622 + err = au_sio_cpup_simple(&cpg);
14625 + } else if (hi_wh) {
14626 + /* already copied-up after unlink */
14627 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14628 + *need_reopen = 0;
14632 + di_read_unlock(parent, AuLock_IR);
14639 +static void au_do_refresh_dir(struct file *file)
14641 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14642 + struct au_hfile *p, tmp, *q;
14643 + struct au_finfo *finfo;
14644 + struct super_block *sb;
14645 + struct au_fidir *fidir;
14647 + FiMustWriteLock(file);
14649 + sb = file->f_path.dentry->d_sb;
14650 + finfo = au_fi(file);
14651 + fidir = finfo->fi_hdir;
14652 + AuDebugOn(!fidir);
14653 + p = fidir->fd_hfile + finfo->fi_btop;
14654 + brid = p->hf_br->br_id;
14655 + bbot = fidir->fd_bbot;
14656 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14660 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14661 + if (new_bindex == bindex)
14663 + if (new_bindex < 0) {
14664 + au_set_h_fptr(file, bindex, NULL);
14668 + /* swap two lower inode, and loop again */
14669 + q = fidir->fd_hfile + new_bindex;
14673 + if (tmp.hf_file) {
14679 + p = fidir->fd_hfile;
14680 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14681 + bbot = au_sbbot(sb);
14682 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14683 + finfo->fi_btop++, p++)
14684 + if (p->hf_file) {
14685 + if (file_inode(p->hf_file))
14687 + au_hfput(p, /*execed*/0);
14690 + bbot = au_br_index(sb, brid);
14691 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14692 + finfo->fi_btop++, p++)
14694 + au_hfput(p, /*execed*/0);
14695 + bbot = au_sbbot(sb);
14698 + p = fidir->fd_hfile + bbot;
14699 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14700 + fidir->fd_bbot--, p--)
14701 + if (p->hf_file) {
14702 + if (file_inode(p->hf_file))
14704 + au_hfput(p, /*execed*/0);
14706 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14710 + * after branch manipulating, refresh the file.
14712 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14714 + int err, need_reopen, nbr;
14715 + aufs_bindex_t bbot, bindex;
14716 + struct dentry *dentry;
14717 + struct super_block *sb;
14718 + struct au_finfo *finfo;
14719 + struct au_hfile *hfile;
14721 + dentry = file->f_path.dentry;
14722 + sb = dentry->d_sb;
14723 + nbr = au_sbbot(sb) + 1;
14724 + finfo = au_fi(file);
14725 + if (!finfo->fi_hdir) {
14726 + hfile = &finfo->fi_htop;
14727 + AuDebugOn(!hfile->hf_file);
14728 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14729 + AuDebugOn(bindex < 0);
14730 + if (bindex != finfo->fi_btop)
14731 + au_set_fbtop(file, bindex);
14733 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14734 + if (unlikely(err))
14736 + au_do_refresh_dir(file);
14741 + if (!au_test_mmapped(file))
14742 + err = au_file_refresh_by_inode(file, &need_reopen);
14743 + if (finfo->fi_hdir)
14744 + /* harmless if err */
14745 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14746 + if (!err && need_reopen && !d_unlinked(dentry))
14747 + err = reopen(file);
14749 + au_update_figen(file);
14750 + goto out; /* success */
14753 + /* error, close all lower files */
14754 + if (finfo->fi_hdir) {
14755 + bbot = au_fbbot_dir(file);
14756 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14757 + au_set_h_fptr(file, bindex, NULL);
14764 +/* common function to regular file and dir */
14765 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14766 + int wlock, unsigned int fi_lsc)
14769 + unsigned int sigen, figen;
14770 + aufs_bindex_t btop;
14771 + unsigned char pseudo_link;
14772 + struct dentry *dentry;
14773 + struct inode *inode;
14776 + dentry = file->f_path.dentry;
14777 + inode = d_inode(dentry);
14778 + sigen = au_sigen(dentry->d_sb);
14779 + fi_write_lock_nested(file, fi_lsc);
14780 + figen = au_figen(file);
14782 + di_write_lock_child(dentry);
14784 + di_write_lock_child2(dentry);
14785 + btop = au_dbtop(dentry);
14786 + pseudo_link = (btop != au_ibtop(inode));
14787 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14789 + di_downgrade_lock(dentry, AuLock_IR);
14790 + fi_downgrade_lock(file);
14792 + goto out; /* success */
14795 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14796 + if (au_digen_test(dentry, sigen)) {
14797 + err = au_reval_dpath(dentry, sigen);
14798 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14802 + err = refresh_file(file, reopen);
14805 + di_downgrade_lock(dentry, AuLock_IR);
14806 + fi_downgrade_lock(file);
14809 + di_write_unlock(dentry);
14810 + fi_write_unlock(file);
14817 +/* ---------------------------------------------------------------------- */
14819 +/* cf. aufs_nopage() */
14820 +/* for madvise(2) */
14821 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
14823 + unlock_page(page);
14827 +/* it will never be called, but necessary to support O_DIRECT */
14828 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14829 +{ BUG(); return 0; }
14831 +/* they will never be called. */
14832 +#ifdef CONFIG_AUFS_DEBUG
14833 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14834 + loff_t pos, unsigned len, unsigned flags,
14835 + struct page **pagep, void **fsdata)
14836 +{ AuUnsupport(); return 0; }
14837 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14838 + loff_t pos, unsigned len, unsigned copied,
14839 + struct page *page, void *fsdata)
14840 +{ AuUnsupport(); return 0; }
14841 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14842 +{ AuUnsupport(); return 0; }
14844 +static int aufs_set_page_dirty(struct page *page)
14845 +{ AuUnsupport(); return 0; }
14846 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
14847 + unsigned int length)
14848 +{ AuUnsupport(); }
14849 +static int aufs_releasepage(struct page *page, gfp_t gfp)
14850 +{ AuUnsupport(); return 0; }
14851 +#if 0 /* called by memory compaction regardless file */
14852 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
14853 + struct page *page, enum migrate_mode mode)
14854 +{ AuUnsupport(); return 0; }
14856 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
14857 +{ AuUnsupport(); return true; }
14858 +static void aufs_putback_page(struct page *page)
14859 +{ AuUnsupport(); }
14860 +static int aufs_launder_page(struct page *page)
14861 +{ AuUnsupport(); return 0; }
14862 +static int aufs_is_partially_uptodate(struct page *page,
14863 + unsigned long from,
14864 + unsigned long count)
14865 +{ AuUnsupport(); return 0; }
14866 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
14868 +{ AuUnsupport(); }
14869 +static int aufs_error_remove_page(struct address_space *mapping,
14870 + struct page *page)
14871 +{ AuUnsupport(); return 0; }
14872 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14874 +{ AuUnsupport(); return 0; }
14875 +static void aufs_swap_deactivate(struct file *file)
14876 +{ AuUnsupport(); }
14877 +#endif /* CONFIG_AUFS_DEBUG */
14879 +const struct address_space_operations aufs_aop = {
14880 + .readpage = aufs_readpage,
14881 + .direct_IO = aufs_direct_IO,
14882 +#ifdef CONFIG_AUFS_DEBUG
14883 + .writepage = aufs_writepage,
14884 + /* no writepages, because of writepage */
14885 + .set_page_dirty = aufs_set_page_dirty,
14886 + /* no readpages, because of readpage */
14887 + .write_begin = aufs_write_begin,
14888 + .write_end = aufs_write_end,
14889 + /* no bmap, no block device */
14890 + .invalidatepage = aufs_invalidatepage,
14891 + .releasepage = aufs_releasepage,
14892 + /* is fallback_migrate_page ok? */
14893 + /* .migratepage = aufs_migratepage, */
14894 + .isolate_page = aufs_isolate_page,
14895 + .putback_page = aufs_putback_page,
14896 + .launder_page = aufs_launder_page,
14897 + .is_partially_uptodate = aufs_is_partially_uptodate,
14898 + .is_dirty_writeback = aufs_is_dirty_writeback,
14899 + .error_remove_page = aufs_error_remove_page,
14900 + .swap_activate = aufs_swap_activate,
14901 + .swap_deactivate = aufs_swap_deactivate
14902 +#endif /* CONFIG_AUFS_DEBUG */
14904 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14905 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14906 +++ linux/fs/aufs/file.h 2021-12-03 15:38:59.936647310 +0100
14908 +/* SPDX-License-Identifier: GPL-2.0 */
14910 + * Copyright (C) 2005-2021 Junjiro R. Okajima
14912 + * This program, aufs is free software; you can redistribute it and/or modify
14913 + * it under the terms of the GNU General Public License as published by
14914 + * the Free Software Foundation; either version 2 of the License, or
14915 + * (at your option) any later version.
14917 + * This program is distributed in the hope that it will be useful,
14918 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14919 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14920 + * GNU General Public License for more details.
14922 + * You should have received a copy of the GNU General Public License
14923 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14927 + * file operations
14930 +#ifndef __AUFS_FILE_H__
14931 +#define __AUFS_FILE_H__
14935 +#include <linux/file.h>
14936 +#include <linux/fs.h>
14937 +#include <linux/mm_types.h>
14938 +#include <linux/poll.h>
14939 +#include "rwsem.h"
14943 + struct file *hf_file;
14944 + struct au_branch *hf_br;
14949 + aufs_bindex_t fd_bbot;
14950 + aufs_bindex_t fd_nent;
14951 + struct au_vdir *fd_vdir_cache;
14952 + struct au_hfile fd_hfile[];
14955 +static inline int au_fidir_sz(int nent)
14957 + AuDebugOn(nent < 0);
14958 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14962 + atomic_t fi_generation;
14964 + struct au_rwsem fi_rwsem;
14965 + aufs_bindex_t fi_btop;
14967 + /* do not union them */
14968 + struct { /* for non-dir */
14969 + struct au_hfile fi_htop;
14970 + atomic_t fi_mmapped;
14972 + struct au_fidir *fi_hdir; /* for dir only */
14974 + struct hlist_bl_node fi_hlist;
14975 + struct file *fi_file; /* very ugly */
14976 + struct rcu_head rcu;
14977 +} ____cacheline_aligned_in_smp;
14979 +/* ---------------------------------------------------------------------- */
14982 +extern const struct address_space_operations aufs_aop;
14983 +unsigned int au_file_roflags(unsigned int flags);
14984 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14985 + struct file *file, int force_wr);
14986 +struct au_do_open_args {
14988 + int (*open)(struct file *file, int flags,
14989 + struct file *h_file);
14990 + struct au_fidir *fidir;
14991 + struct file *h_file;
14993 +int au_do_open(struct file *file, struct au_do_open_args *args);
14994 +int au_reopen_nondir(struct file *file);
14996 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14997 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14998 + int wlock, unsigned int fi_lsc);
14999 +int au_do_flush(struct file *file, fl_owner_t id,
15000 + int (*flush)(struct file *file, fl_owner_t id));
15003 +#ifdef CONFIG_AUFS_POLL
15004 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15007 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15009 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15011 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15012 + struct file *h_file);
15014 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15015 + aufs_bindex_t bindex, int force_wr)
15016 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15017 + struct file *h_file);
15021 +extern const struct file_operations aufs_file_fop;
15022 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15023 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15024 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15027 +void au_hfput(struct au_hfile *hf, int execed);
15028 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15029 + struct file *h_file);
15031 +void au_update_figen(struct file *file);
15032 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15033 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15035 +void au_fi_init_once(void *_fi);
15036 +void au_finfo_fin(struct file *file);
15037 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15040 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15041 +#ifdef CONFIG_COMPAT
15042 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15043 + unsigned long arg);
15044 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15045 + unsigned long arg);
15048 +/* ---------------------------------------------------------------------- */
15050 +static inline struct au_finfo *au_fi(struct file *file)
15052 + return file->private_data;
15055 +/* ---------------------------------------------------------------------- */
15057 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15058 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15059 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15060 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15062 +#define fi_read_trylock_nested(f) \
15063 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15064 +#define fi_write_trylock_nested(f) \
15065 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15068 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15069 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15070 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15072 +/* lock subclass for finfo */
15078 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15080 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15083 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15085 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15089 + * fi_read_lock_1, fi_write_lock_1,
15090 + * fi_read_lock_2, fi_write_lock_2
15092 +#define AuReadLockFunc(name) \
15093 +static inline void fi_read_lock_##name(struct file *f) \
15094 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15096 +#define AuWriteLockFunc(name) \
15097 +static inline void fi_write_lock_##name(struct file *f) \
15098 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15100 +#define AuRWLockFuncs(name) \
15101 + AuReadLockFunc(name) \
15102 + AuWriteLockFunc(name)
15107 +#undef AuReadLockFunc
15108 +#undef AuWriteLockFunc
15109 +#undef AuRWLockFuncs
15111 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15112 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15113 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15115 +/* ---------------------------------------------------------------------- */
15117 +/* todo: hard/soft set? */
15118 +static inline aufs_bindex_t au_fbtop(struct file *file)
15120 + FiMustAnyLock(file);
15121 + return au_fi(file)->fi_btop;
15124 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15126 + FiMustAnyLock(file);
15127 + AuDebugOn(!au_fi(file)->fi_hdir);
15128 + return au_fi(file)->fi_hdir->fd_bbot;
15131 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15133 + FiMustAnyLock(file);
15134 + AuDebugOn(!au_fi(file)->fi_hdir);
15135 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15138 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15140 + FiMustWriteLock(file);
15141 + au_fi(file)->fi_btop = bindex;
15144 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15146 + FiMustWriteLock(file);
15147 + AuDebugOn(!au_fi(file)->fi_hdir);
15148 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15151 +static inline void au_set_fvdir_cache(struct file *file,
15152 + struct au_vdir *vdir_cache)
15154 + FiMustWriteLock(file);
15155 + AuDebugOn(!au_fi(file)->fi_hdir);
15156 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15159 +static inline struct file *au_hf_top(struct file *file)
15161 + FiMustAnyLock(file);
15162 + AuDebugOn(au_fi(file)->fi_hdir);
15163 + return au_fi(file)->fi_htop.hf_file;
15166 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15168 + FiMustAnyLock(file);
15169 + AuDebugOn(!au_fi(file)->fi_hdir);
15170 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15173 +/* todo: memory barrier? */
15174 +static inline unsigned int au_figen(struct file *f)
15176 + return atomic_read(&au_fi(f)->fi_generation);
15179 +static inline void au_set_mmapped(struct file *f)
15181 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15183 + pr_warn("fi_mmapped wrapped around\n");
15184 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15188 +static inline void au_unset_mmapped(struct file *f)
15190 + atomic_dec(&au_fi(f)->fi_mmapped);
15193 +static inline int au_test_mmapped(struct file *f)
15195 + return atomic_read(&au_fi(f)->fi_mmapped);
15198 +/* customize vma->vm_file */
15200 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15201 + struct file *file)
15205 + f = vma->vm_file;
15207 + vma->vm_file = file;
15212 +#define AuDbgVmRegion(file, vma) do {} while (0)
15214 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15215 + struct file *file)
15217 + au_do_vm_file_reset(vma, file);
15220 +#define AuDbgVmRegion(file, vma) \
15221 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15223 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15224 + struct file *file)
15228 + au_do_vm_file_reset(vma, file);
15229 + f = vma->vm_region->vm_file;
15231 + vma->vm_region->vm_file = file;
15234 +#endif /* CONFIG_MMU */
15236 +/* handle vma->vm_prfile */
15237 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15238 + struct file *file)
15241 + vma->vm_prfile = file;
15242 +#ifndef CONFIG_MMU
15244 + vma->vm_region->vm_prfile = file;
15248 +#endif /* __KERNEL__ */
15249 +#endif /* __AUFS_FILE_H__ */
15250 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15251 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15252 +++ linux/fs/aufs/finfo.c 2021-12-03 15:38:59.936647310 +0100
15254 +// SPDX-License-Identifier: GPL-2.0
15256 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15258 + * This program, aufs is free software; you can redistribute it and/or modify
15259 + * it under the terms of the GNU General Public License as published by
15260 + * the Free Software Foundation; either version 2 of the License, or
15261 + * (at your option) any later version.
15263 + * This program is distributed in the hope that it will be useful,
15264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15266 + * GNU General Public License for more details.
15268 + * You should have received a copy of the GNU General Public License
15269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15273 + * file private data
15278 +void au_hfput(struct au_hfile *hf, int execed)
15281 + allow_write_access(hf->hf_file);
15282 + fput(hf->hf_file);
15283 + hf->hf_file = NULL;
15284 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15285 + hf->hf_br = NULL;
15288 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15290 + struct au_finfo *finfo = au_fi(file);
15291 + struct au_hfile *hf;
15292 + struct au_fidir *fidir;
15294 + fidir = finfo->fi_hdir;
15296 + AuDebugOn(finfo->fi_btop != bindex);
15297 + hf = &finfo->fi_htop;
15299 + hf = fidir->fd_hfile + bindex;
15301 + if (hf && hf->hf_file)
15302 + au_hfput(hf, vfsub_file_execed(file));
15304 + FiMustWriteLock(file);
15305 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15306 + hf->hf_file = val;
15307 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15311 +void au_update_figen(struct file *file)
15313 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15314 + /* smp_mb(); */ /* atomic_set */
15317 +/* ---------------------------------------------------------------------- */
15319 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15321 + struct au_fidir *fidir;
15324 + nbr = au_sbbot(sb) + 1;
15326 + nbr = 2; /* initial allocate for 2 branches */
15327 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15329 + fidir->fd_bbot = -1;
15330 + fidir->fd_nent = nbr;
15336 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15339 + struct au_fidir *fidir, *p;
15341 + AuRwMustWriteLock(&finfo->fi_rwsem);
15342 + fidir = finfo->fi_hdir;
15343 + AuDebugOn(!fidir);
15346 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15347 + GFP_NOFS, may_shrink);
15349 + p->fd_nent = nbr;
15350 + finfo->fi_hdir = p;
15357 +/* ---------------------------------------------------------------------- */
15359 +void au_finfo_fin(struct file *file)
15361 + struct au_finfo *finfo;
15363 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15365 + finfo = au_fi(file);
15366 + AuDebugOn(finfo->fi_hdir);
15367 + AuRwDestroy(&finfo->fi_rwsem);
15368 + au_cache_free_finfo(finfo);
15371 +void au_fi_init_once(void *_finfo)
15373 + struct au_finfo *finfo = _finfo;
15375 + au_rw_init(&finfo->fi_rwsem);
15378 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15381 + struct au_finfo *finfo;
15382 + struct dentry *dentry;
15385 + dentry = file->f_path.dentry;
15386 + finfo = au_cache_alloc_finfo();
15387 + if (unlikely(!finfo))
15391 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15392 + au_rw_write_lock(&finfo->fi_rwsem);
15393 + finfo->fi_btop = -1;
15394 + finfo->fi_hdir = fidir;
15395 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15396 + /* smp_mb(); */ /* atomic_set */
15398 + file->private_data = finfo;
15403 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15404 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15405 +++ linux/fs/aufs/f_op.c 2021-12-03 15:38:59.933313976 +0100
15407 +// SPDX-License-Identifier: GPL-2.0
15409 + * Copyright (C) 2005-2021 Junjiro R. Okajima
15411 + * This program, aufs is free software; you can redistribute it and/or modify
15412 + * it under the terms of the GNU General Public License as published by
15413 + * the Free Software Foundation; either version 2 of the License, or
15414 + * (at your option) any later version.
15416 + * This program is distributed in the hope that it will be useful,
15417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15419 + * GNU General Public License for more details.
15421 + * You should have received a copy of the GNU General Public License
15422 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15426 + * file and vm operations
15429 +#include <linux/aio.h>
15430 +#include <linux/fs_stack.h>
15431 +#include <linux/mman.h>
15432 +#include <linux/security.h>
15435 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15438 + aufs_bindex_t bindex;
15439 + struct dentry *dentry, *h_dentry;
15440 + struct au_finfo *finfo;
15441 + struct inode *h_inode;
15443 + FiMustWriteLock(file);
15446 + dentry = file->f_path.dentry;
15447 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15448 + finfo = au_fi(file);
15449 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15450 + atomic_set(&finfo->fi_mmapped, 0);
15451 + bindex = au_dbtop(dentry);
15453 + h_dentry = au_h_dptr(dentry, bindex);
15454 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15455 + if (unlikely(err))
15457 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15458 + if (IS_ERR(h_file)) {
15459 + err = PTR_ERR(h_file);
15463 + h_dentry = h_file->f_path.dentry;
15464 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15465 + if (unlikely(err))
15467 + /* br ref is already inc-ed */
15470 + if ((flags & __O_TMPFILE)
15471 + && !(flags & O_EXCL)) {
15472 + h_inode = file_inode(h_file);
15473 + spin_lock(&h_inode->i_lock);
15474 + h_inode->i_state |= I_LINKABLE;
15475 + spin_unlock(&h_inode->i_lock);
15477 + au_set_fbtop(file, bindex);
15478 + au_set_h_fptr(file, bindex, h_file);
15479 + au_update_figen(file);
15480 + /* todo: necessary? */
15481 + /* file->f_ra = h_file->f_ra; */
15487 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15488 + struct file *file)
15491 + struct super_block *sb;
15492 + struct au_do_open_args args = {
15493 + .open = au_do_open_nondir
15496 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15497 + file, vfsub_file_flags(file), file->f_mode);
15499 + sb = file->f_path.dentry->d_sb;
15500 + si_read_lock(sb, AuLock_FLUSH);
15501 + err = au_do_open(file, &args);
15502 + si_read_unlock(sb);
15506 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15508 + struct au_finfo *finfo;
15509 + aufs_bindex_t bindex;
15511 + finfo = au_fi(file);
15512 + au_hbl_del(&finfo->fi_hlist,
15513 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15514 + bindex = finfo->fi_btop;
15516 + au_set_h_fptr(file, bindex, NULL);
15518 + au_finfo_fin(file);
15522 +/* ---------------------------------------------------------------------- */
15524 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15527 + struct file *h_file;
15530 + h_file = au_hf_top(file);
15532 + err = vfsub_flush(h_file, id);
15536 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15538 + return au_do_flush(file, id, au_do_flush_nondir);
15541 +/* ---------------------------------------------------------------------- */
15543 + * read and write functions acquire [fdi]_rwsem once, but release before
15544 + * mmap_sem. This is because to stop a race condition between mmap(2).
15545 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15546 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15547 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15550 +/* Callers should call au_read_post() or fput() in the end */
15551 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15553 + struct file *h_file;
15556 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15558 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15559 + h_file = au_hf_top(file);
15560 + get_file(h_file);
15562 + fi_read_unlock(file);
15564 + h_file = ERR_PTR(err);
15569 +static void au_read_post(struct inode *inode, struct file *h_file)
15571 + /* update without lock, I don't think it a problem */
15572 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15576 +struct au_write_pre {
15578 + unsigned int lsc;
15582 + aufs_bindex_t btop;
15586 + * return with iinfo is write-locked
15587 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15590 +static struct file *au_write_pre(struct file *file, int do_ready,
15591 + struct au_write_pre *wpre)
15593 + struct file *h_file;
15594 + struct dentry *dentry;
15596 + unsigned int lsc;
15597 + struct au_pin pin;
15602 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15603 + h_file = ERR_PTR(err);
15604 + if (unlikely(err))
15607 + dentry = file->f_path.dentry;
15609 + err = au_ready_to_write(file, -1, &pin);
15610 + if (unlikely(err)) {
15611 + h_file = ERR_PTR(err);
15612 + di_write_unlock(dentry);
15617 + di_downgrade_lock(dentry, /*flags*/0);
15619 + wpre->btop = au_fbtop(file);
15620 + h_file = au_hf_top(file);
15621 + get_file(h_file);
15623 + wpre->blks = file_inode(h_file)->i_blocks;
15626 + di_read_unlock(dentry, /*flags*/0);
15629 + fi_write_unlock(file);
15634 +static void au_write_post(struct inode *inode, struct file *h_file,
15635 + struct au_write_pre *wpre, ssize_t written)
15637 + struct inode *h_inode;
15639 + au_cpup_attr_timesizes(inode);
15640 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15641 + h_inode = file_inode(h_file);
15642 + inode->i_mode = h_inode->i_mode;
15643 + ii_write_unlock(inode);
15644 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15646 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15647 + /*force*/h_inode->i_blocks > wpre->blks);
15652 + * todo: very ugly
15653 + * it locks both of i_mutex and si_rwsem for read in safe.
15654 + * if the plink maintenance mode continues forever (that is the problem),
15655 + * may loop forever.
15657 +static void au_mtx_and_read_lock(struct inode *inode)
15660 + struct super_block *sb = inode->i_sb;
15663 + inode_lock(inode);
15664 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15667 + inode_unlock(inode);
15668 + si_read_lock(sb, AuLock_NOPLMW);
15669 + si_read_unlock(sb);
15673 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15674 + struct iov_iter *iov_iter)
15677 + struct file *file;
15678 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15680 + err = security_file_permission(h_file, rw);
15681 + if (unlikely(err))
15684 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15686 + if (rw == MAY_READ)
15687 + iter = h_file->f_op->read_iter;
15688 + else if (rw == MAY_WRITE)
15689 + iter = h_file->f_op->write_iter;
15691 + file = kio->ki_filp;
15692 + kio->ki_filp = h_file;
15695 + err = iter(kio, iov_iter);
15698 + /* currently there is no such fs */
15700 + kio->ki_filp = file;
15706 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15709 + struct file *file, *h_file;
15710 + struct inode *inode;
15711 + struct super_block *sb;
15713 + file = kio->ki_filp;
15714 + inode = file_inode(file);
15715 + sb = inode->i_sb;
15716 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15718 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15719 + err = PTR_ERR(h_file);
15720 + if (IS_ERR(h_file))
15723 + if (au_test_loopback_kthread()) {
15724 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15725 + if (file->f_mapping != h_file->f_mapping) {
15726 + file->f_mapping = h_file->f_mapping;
15727 + smp_mb(); /* unnecessary? */
15730 + fi_read_unlock(file);
15732 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15733 + /* todo: necessary? */
15734 + /* file->f_ra = h_file->f_ra; */
15735 + au_read_post(inode, h_file);
15738 + si_read_unlock(sb);
15742 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15745 + struct au_write_pre wpre;
15746 + struct inode *inode;
15747 + struct file *file, *h_file;
15749 + file = kio->ki_filp;
15750 + inode = file_inode(file);
15751 + au_mtx_and_read_lock(inode);
15754 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15755 + err = PTR_ERR(h_file);
15756 + if (IS_ERR(h_file))
15759 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15760 + au_write_post(inode, h_file, &wpre, err);
15763 + si_read_unlock(inode->i_sb);
15764 + inode_unlock(inode);
15769 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15770 + * don't have their own .splice_{read,write} implimentations, and they use
15771 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15772 + * simple converters to f_op->iter_read() and ->iter_write().
15773 + * But we keep our own implementations because some non-mainlined FSes may have
15774 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15775 + * away an opportunity to co-work with aufs from them.
15777 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15778 + struct pipe_inode_info *pipe, size_t len,
15779 + unsigned int flags)
15782 + struct file *h_file;
15783 + struct inode *inode;
15784 + struct super_block *sb;
15786 + inode = file_inode(file);
15787 + sb = inode->i_sb;
15788 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15790 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15791 + err = PTR_ERR(h_file);
15792 + if (IS_ERR(h_file))
15795 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15796 + /* todo: necessary? */
15797 + /* file->f_ra = h_file->f_ra; */
15798 + au_read_post(inode, h_file);
15801 + si_read_unlock(sb);
15806 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15807 + size_t len, unsigned int flags)
15810 + struct au_write_pre wpre;
15811 + struct inode *inode;
15812 + struct file *h_file;
15814 + inode = file_inode(file);
15815 + au_mtx_and_read_lock(inode);
15818 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15819 + err = PTR_ERR(h_file);
15820 + if (IS_ERR(h_file))
15823 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15824 + au_write_post(inode, h_file, &wpre, err);
15827 + si_read_unlock(inode->i_sb);
15828 + inode_unlock(inode);
15832 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15836 + struct au_write_pre wpre;
15837 + struct inode *inode;
15838 + struct file *h_file;
15840 + inode = file_inode(file);
15841 + au_mtx_and_read_lock(inode);
15844 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15845 + err = PTR_ERR(h_file);
15846 + if (IS_ERR(h_file))
15850 + err = vfs_fallocate(h_file, mode, offset, len);
15852 + au_write_post(inode, h_file, &wpre, /*written*/1);
15855 + si_read_unlock(inode->i_sb);
15856 + inode_unlock(inode);
15860 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15861 + struct file *dst, loff_t dst_pos,
15862 + size_t len, unsigned int flags)
15865 + struct au_write_pre wpre;
15866 + enum { SRC, DST };
15868 + struct inode *inode;
15869 + struct file *h_file;
15870 + struct super_block *h_sb;
15872 +#define a_src a[SRC]
15873 +#define a_dst a[DST]
15876 + a_src.inode = file_inode(src);
15877 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15879 + a_dst.inode = file_inode(dst);
15880 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15883 + au_mtx_and_read_lock(a_dst.inode);
15885 + * in order to match the order in di_write_lock2_{child,parent}(),
15886 + * use f_path.dentry for this comparison.
15888 + if (src->f_path.dentry < dst->f_path.dentry) {
15889 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15890 + err = PTR_ERR(a_src.h_file);
15891 + if (IS_ERR(a_src.h_file))
15894 + wpre.lsc = AuLsc_FI_2;
15895 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15896 + err = PTR_ERR(a_dst.h_file);
15897 + if (IS_ERR(a_dst.h_file)) {
15898 + au_read_post(a_src.inode, a_src.h_file);
15902 + wpre.lsc = AuLsc_FI_1;
15903 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15904 + err = PTR_ERR(a_dst.h_file);
15905 + if (IS_ERR(a_dst.h_file))
15908 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15909 + err = PTR_ERR(a_src.h_file);
15910 + if (IS_ERR(a_src.h_file)) {
15911 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15918 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15919 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15920 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15926 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15927 + dst_pos, len, flags);
15930 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15931 + fi_read_unlock(src);
15932 + au_read_post(a_src.inode, a_src.h_file);
15934 + si_read_unlock(a_dst.inode->i_sb);
15935 + inode_unlock(a_dst.inode);
15942 +/* ---------------------------------------------------------------------- */
15945 + * The locking order around current->mmap_sem.
15946 + * - in most and regular cases
15947 + * file I/O syscall -- aufs_read() or something
15948 + * -- si_rwsem for read -- mmap_sem
15949 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15951 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15952 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15953 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15954 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15955 + * It means that when aufs acquires si_rwsem for write, the process should never
15956 + * acquire mmap_sem.
15958 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15959 + * problem either since any directory is not able to be mmap-ed.
15960 + * The similar scenario is applied to aufs_readlink() too.
15963 +#if 0 /* stop calling security_file_mmap() */
15964 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15965 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15967 +static unsigned long au_arch_prot_conv(unsigned long flags)
15969 + /* currently ppc64 only */
15970 +#ifdef CONFIG_PPC64
15971 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15972 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15973 + return AuConv_VM_PROT(flags, SAO);
15975 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15980 +static unsigned long au_prot_conv(unsigned long flags)
15982 + return AuConv_VM_PROT(flags, READ)
15983 + | AuConv_VM_PROT(flags, WRITE)
15984 + | AuConv_VM_PROT(flags, EXEC)
15985 + | au_arch_prot_conv(flags);
15988 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15989 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15991 +static unsigned long au_flag_conv(unsigned long flags)
15993 + return AuConv_VM_MAP(flags, GROWSDOWN)
15994 + | AuConv_VM_MAP(flags, DENYWRITE)
15995 + | AuConv_VM_MAP(flags, LOCKED);
15999 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16002 + const unsigned char wlock
16003 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16004 + struct super_block *sb;
16005 + struct file *h_file;
16006 + struct inode *inode;
16008 + AuDbgVmRegion(file, vma);
16010 + inode = file_inode(file);
16011 + sb = inode->i_sb;
16013 + si_read_lock(sb, AuLock_NOPLMW);
16015 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16017 + err = PTR_ERR(h_file);
16018 + if (IS_ERR(h_file))
16022 + au_set_mmapped(file);
16023 + au_vm_file_reset(vma, h_file);
16025 + * we cannot call security_mmap_file() here since it may acquire
16026 + * mmap_sem or i_mutex.
16028 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16029 + * au_flag_conv(vma->vm_flags));
16032 + err = call_mmap(h_file, vma);
16034 + au_vm_prfile_set(vma, file);
16035 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16036 + goto out_fput; /* success */
16038 + au_unset_mmapped(file);
16039 + au_vm_file_reset(vma, file);
16043 + ii_write_unlock(inode);
16048 + si_read_unlock(sb);
16054 +/* ---------------------------------------------------------------------- */
16056 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16060 + struct au_write_pre wpre;
16061 + struct inode *inode;
16062 + struct file *h_file;
16064 + err = 0; /* -EBADF; */ /* posix? */
16065 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16068 + inode = file_inode(file);
16069 + au_mtx_and_read_lock(inode);
16072 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16073 + err = PTR_ERR(h_file);
16074 + if (IS_ERR(h_file))
16077 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16078 + au_write_post(inode, h_file, &wpre, /*written*/0);
16081 + si_read_unlock(inode->i_sb);
16082 + inode_unlock(inode);
16087 +static int aufs_fasync(int fd, struct file *file, int flag)
16090 + struct file *h_file;
16091 + struct super_block *sb;
16093 + sb = file->f_path.dentry->d_sb;
16094 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16096 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16097 + err = PTR_ERR(h_file);
16098 + if (IS_ERR(h_file))
16101 + if (h_file->f_op->fasync)
16102 + err = h_file->f_op->fasync(fd, h_file, flag);
16103 + fput(h_file); /* instead of au_read_post() */
16106 + si_read_unlock(sb);
16110 +static int aufs_setfl(struct file *file, unsigned long arg)
16113 + struct file *h_file;
16114 + struct super_block *sb;
16116 + sb = file->f_path.dentry->d_sb;
16117 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16119 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16120 + err = PTR_ERR(h_file);
16121 + if (IS_ERR(h_file))
16124 + /* stop calling h_file->fasync */
16125 + arg |= vfsub_file_flags(file) & FASYNC;
16126 + err = setfl(/*unused fd*/-1, h_file, arg);
16127 + fput(h_file); /* instead of au_read_post() */
16130 + si_read_unlock(sb);
16134 +/* ---------------------------------------------------------------------- */
16136 +/* no one supports this operation, currently */
16137 +#if 0 /* reserved for future use */
16138 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16139 + size_t len, loff_t *pos, int more)
16144 +/* ---------------------------------------------------------------------- */
16146 +const struct file_operations aufs_file_fop = {
16147 + .owner = THIS_MODULE,
16149 + .llseek = default_llseek,
16151 + .read_iter = aufs_read_iter,
16152 + .write_iter = aufs_write_iter,
16154 +#ifdef CONFIG_AUFS_POLL
16155 + .poll = aufs_poll,
16157 + .unlocked_ioctl = aufs_ioctl_nondir,
16158 +#ifdef CONFIG_COMPAT
16159 + .compat_ioctl = aufs_compat_ioctl_nondir,
16161 + .mmap = aufs_mmap,
16162 + .open = aufs_open_nondir,
16163 + .flush = aufs_flush_nondir,
16164 + .release = aufs_release_nondir,
16165 + .fsync = aufs_fsync_nondir,
16166 + .fasync = aufs_fasync,
16167 + /* .sendpage = aufs_sendpage, */
16168 + .setfl = aufs_setfl,
16169 + .splice_write = aufs_splice_write,
16170 + .splice_read = aufs_splice_read,
16171 +#if 0 /* reserved for future use */
16172 + .aio_splice_write = aufs_aio_splice_write,
16173 + .aio_splice_read = aufs_aio_splice_read,
16175 + .fallocate = aufs_fallocate,
16176 + .copy_file_range = aufs_copy_file_range
16178 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
16179 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
16180 +++ linux/fs/aufs/fstype.h 2021-12-03 15:38:59.936647310 +0100
16182 +/* SPDX-License-Identifier: GPL-2.0 */
16184 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16186 + * This program, aufs is free software; you can redistribute it and/or modify
16187 + * it under the terms of the GNU General Public License as published by
16188 + * the Free Software Foundation; either version 2 of the License, or
16189 + * (at your option) any later version.
16191 + * This program is distributed in the hope that it will be useful,
16192 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16193 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16194 + * GNU General Public License for more details.
16196 + * You should have received a copy of the GNU General Public License
16197 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16201 + * judging filesystem type
16204 +#ifndef __AUFS_FSTYPE_H__
16205 +#define __AUFS_FSTYPE_H__
16209 +#include <linux/fs.h>
16210 +#include <linux/magic.h>
16211 +#include <linux/nfs_fs.h>
16212 +#include <linux/romfs_fs.h>
16214 +static inline int au_test_aufs(struct super_block *sb)
16216 + return sb->s_magic == AUFS_SUPER_MAGIC;
16219 +static inline const char *au_sbtype(struct super_block *sb)
16221 + return sb->s_type->name;
16224 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
16226 +#if IS_ENABLED(CONFIG_ISO9660_FS)
16227 + return sb->s_magic == ISOFS_SUPER_MAGIC;
16233 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
16235 +#if IS_ENABLED(CONFIG_ROMFS_FS)
16236 + return sb->s_magic == ROMFS_MAGIC;
16242 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
16244 +#if IS_ENABLED(CONFIG_CRAMFS)
16245 + return sb->s_magic == CRAMFS_MAGIC;
16250 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
16252 +#if IS_ENABLED(CONFIG_NFS_FS)
16253 + return sb->s_magic == NFS_SUPER_MAGIC;
16259 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
16261 +#if IS_ENABLED(CONFIG_FUSE_FS)
16262 + return sb->s_magic == FUSE_SUPER_MAGIC;
16268 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
16270 +#if IS_ENABLED(CONFIG_XFS_FS)
16271 + return sb->s_magic == XFS_SB_MAGIC;
16277 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
16279 +#ifdef CONFIG_TMPFS
16280 + return sb->s_magic == TMPFS_MAGIC;
16286 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
16288 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
16289 + return !strcmp(au_sbtype(sb), "ecryptfs");
16295 +static inline int au_test_ramfs(struct super_block *sb)
16297 + return sb->s_magic == RAMFS_MAGIC;
16300 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
16302 +#if IS_ENABLED(CONFIG_UBIFS_FS)
16303 + return sb->s_magic == UBIFS_SUPER_MAGIC;
16309 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
16311 +#ifdef CONFIG_PROC_FS
16312 + return sb->s_magic == PROC_SUPER_MAGIC;
16318 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
16320 +#ifdef CONFIG_SYSFS
16321 + return sb->s_magic == SYSFS_MAGIC;
16327 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
16329 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
16330 + return sb->s_magic == CONFIGFS_MAGIC;
16336 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
16338 +#if IS_ENABLED(CONFIG_MINIX_FS)
16339 + return sb->s_magic == MINIX3_SUPER_MAGIC
16340 + || sb->s_magic == MINIX2_SUPER_MAGIC
16341 + || sb->s_magic == MINIX2_SUPER_MAGIC2
16342 + || sb->s_magic == MINIX_SUPER_MAGIC
16343 + || sb->s_magic == MINIX_SUPER_MAGIC2;
16349 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
16351 +#if IS_ENABLED(CONFIG_FAT_FS)
16352 + return sb->s_magic == MSDOS_SUPER_MAGIC;
16358 +static inline int au_test_msdos(struct super_block *sb)
16360 + return au_test_fat(sb);
16363 +static inline int au_test_vfat(struct super_block *sb)
16365 + return au_test_fat(sb);
16368 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
16370 +#ifdef CONFIG_SECURITYFS
16371 + return sb->s_magic == SECURITYFS_MAGIC;
16377 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
16379 +#if IS_ENABLED(CONFIG_SQUASHFS)
16380 + return sb->s_magic == SQUASHFS_MAGIC;
16386 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
16388 +#if IS_ENABLED(CONFIG_BTRFS_FS)
16389 + return sb->s_magic == BTRFS_SUPER_MAGIC;
16395 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
16397 +#if IS_ENABLED(CONFIG_XENFS)
16398 + return sb->s_magic == XENFS_SUPER_MAGIC;
16404 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
16406 +#ifdef CONFIG_DEBUG_FS
16407 + return sb->s_magic == DEBUGFS_MAGIC;
16413 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
16415 +#if IS_ENABLED(CONFIG_NILFS)
16416 + return sb->s_magic == NILFS_SUPER_MAGIC;
16422 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
16424 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
16425 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
16431 +/* ---------------------------------------------------------------------- */
16433 + * they can't be an aufs branch.
16435 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
16438 +#ifndef CONFIG_AUFS_BR_RAMFS
16439 + au_test_ramfs(sb) ||
16441 + au_test_procfs(sb)
16442 + || au_test_sysfs(sb)
16443 + || au_test_configfs(sb)
16444 + || au_test_debugfs(sb)
16445 + || au_test_securityfs(sb)
16446 + || au_test_xenfs(sb)
16447 + || au_test_ecryptfs(sb)
16448 + /* || !strcmp(au_sbtype(sb), "unionfs") */
16449 + || au_test_aufs(sb); /* will be supported in next version */
16452 +static inline int au_test_fs_remote(struct super_block *sb)
16454 + return !au_test_tmpfs(sb)
16455 +#ifdef CONFIG_AUFS_BR_RAMFS
16456 + && !au_test_ramfs(sb)
16458 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
16461 +/* ---------------------------------------------------------------------- */
16464 + * Note: these functions (below) are created after reading ->getattr() in all
16465 + * filesystems under linux/fs. it means we have to do so in every update...
16469 + * some filesystems require getattr to refresh the inode attributes before
16471 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
16472 + * and leave the work for d_revalidate()
16474 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
16476 + return au_test_nfs(sb)
16477 + || au_test_fuse(sb)
16478 + /* || au_test_btrfs(sb) */ /* untested */
16483 + * filesystems which don't maintain i_size or i_blocks.
16485 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
16487 + return au_test_xfs(sb)
16488 + || au_test_btrfs(sb)
16489 + || au_test_ubifs(sb)
16490 + || au_test_hfsplus(sb) /* maintained, but incorrect */
16491 + /* || au_test_minix(sb) */ /* untested */
16496 + * filesystems which don't store the correct value in some of their inode
16499 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
16501 + return au_test_fs_bad_iattr_size(sb)
16502 + || au_test_fat(sb)
16503 + || au_test_msdos(sb)
16504 + || au_test_vfat(sb);
16507 +/* they don't check i_nlink in link(2) */
16508 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
16510 + return au_test_tmpfs(sb)
16511 +#ifdef CONFIG_AUFS_BR_RAMFS
16512 + || au_test_ramfs(sb)
16514 + || au_test_ubifs(sb)
16515 + || au_test_hfsplus(sb);
16519 + * filesystems which sets S_NOATIME and S_NOCMTIME.
16521 +static inline int au_test_fs_notime(struct super_block *sb)
16523 + return au_test_nfs(sb)
16524 + || au_test_fuse(sb)
16525 + || au_test_ubifs(sb)
16529 +/* temporary support for i#1 in cramfs */
16530 +static inline int au_test_fs_unique_ino(struct inode *inode)
16532 + if (au_test_cramfs(inode->i_sb))
16533 + return inode->i_ino != 1;
16537 +/* ---------------------------------------------------------------------- */
16540 + * the filesystem where the xino files placed must support i/o after unlink and
16541 + * maintain i_size and i_blocks.
16543 +static inline int au_test_fs_bad_xino(struct super_block *sb)
16545 + return au_test_fs_remote(sb)
16546 + || au_test_fs_bad_iattr_size(sb)
16547 + /* don't want unnecessary work for xino */
16548 + || au_test_aufs(sb)
16549 + || au_test_ecryptfs(sb)
16550 + || au_test_nilfs(sb);
16553 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
16555 + return au_test_tmpfs(sb)
16556 + || au_test_ramfs(sb);
16560 + * test if the @sb is real-readonly.
16562 +static inline int au_test_fs_rr(struct super_block *sb)
16564 + return au_test_squashfs(sb)
16565 + || au_test_iso9660(sb)
16566 + || au_test_cramfs(sb)
16567 + || au_test_romfs(sb);
16571 + * test if the @inode is nfs with 'noacl' option
16572 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
16574 +static inline int au_test_nfs_noacl(struct inode *inode)
16576 + return au_test_nfs(inode->i_sb)
16577 + /* && IS_POSIXACL(inode) */
16578 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
16581 +#endif /* __KERNEL__ */
16582 +#endif /* __AUFS_FSTYPE_H__ */
16583 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
16584 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
16585 +++ linux/fs/aufs/hbl.h 2021-12-03 15:38:59.936647310 +0100
16587 +/* SPDX-License-Identifier: GPL-2.0 */
16589 + * Copyright (C) 2017-2021 Junjiro R. Okajima
16591 + * This program, aufs is free software; you can redistribute it and/or modify
16592 + * it under the terms of the GNU General Public License as published by
16593 + * the Free Software Foundation; either version 2 of the License, or
16594 + * (at your option) any later version.
16596 + * This program is distributed in the hope that it will be useful,
16597 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16598 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16599 + * GNU General Public License for more details.
16601 + * You should have received a copy of the GNU General Public License
16602 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16606 + * helpers for hlist_bl.h
16609 +#ifndef __AUFS_HBL_H__
16610 +#define __AUFS_HBL_H__
16614 +#include <linux/list_bl.h>
16616 +static inline void au_hbl_add(struct hlist_bl_node *node,
16617 + struct hlist_bl_head *hbl)
16619 + hlist_bl_lock(hbl);
16620 + hlist_bl_add_head(node, hbl);
16621 + hlist_bl_unlock(hbl);
16624 +static inline void au_hbl_del(struct hlist_bl_node *node,
16625 + struct hlist_bl_head *hbl)
16627 + hlist_bl_lock(hbl);
16628 + hlist_bl_del(node);
16629 + hlist_bl_unlock(hbl);
16632 +#define au_hbl_for_each(pos, head) \
16633 + for (pos = hlist_bl_first(head); \
16637 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
16639 + unsigned long cnt;
16640 + struct hlist_bl_node *pos;
16643 + hlist_bl_lock(hbl);
16644 + au_hbl_for_each(pos, hbl)
16646 + hlist_bl_unlock(hbl);
16650 +#endif /* __KERNEL__ */
16651 +#endif /* __AUFS_HBL_H__ */
16652 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
16653 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
16654 +++ linux/fs/aufs/hfsnotify.c 2021-12-03 15:38:59.936647310 +0100
16656 +// SPDX-License-Identifier: GPL-2.0
16658 + * Copyright (C) 2005-2021 Junjiro R. Okajima
16660 + * This program, aufs is free software; you can redistribute it and/or modify
16661 + * it under the terms of the GNU General Public License as published by
16662 + * the Free Software Foundation; either version 2 of the License, or
16663 + * (at your option) any later version.
16665 + * This program is distributed in the hope that it will be useful,
16666 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16667 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16668 + * GNU General Public License for more details.
16670 + * You should have received a copy of the GNU General Public License
16671 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16675 + * fsnotify for the lower directories
16680 +/* FS_IN_IGNORED is unnecessary */
16681 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
16682 + | FS_CREATE | FS_EVENT_ON_CHILD);
16683 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
16684 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
16686 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
16688 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
16690 + /* AuDbg("here\n"); */
16691 + au_cache_free_hnotify(hn);
16692 + smp_mb__before_atomic(); /* for atomic64_dec */
16693 + if (atomic64_dec_and_test(&au_hfsn_ifree))
16694 + wake_up(&au_hfsn_wq);
16697 +static int au_hfsn_alloc(struct au_hinode *hinode)
16700 + struct au_hnotify *hn;
16701 + struct super_block *sb;
16702 + struct au_branch *br;
16703 + struct fsnotify_mark *mark;
16704 + aufs_bindex_t bindex;
16706 + hn = hinode->hi_notify;
16707 + sb = hn->hn_aufs_inode->i_sb;
16708 + bindex = au_br_index(sb, hinode->hi_id);
16709 + br = au_sbr(sb, bindex);
16710 + AuDebugOn(!br->br_hfsn);
16712 + mark = &hn->hn_mark;
16713 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
16714 + mark->mask = AuHfsnMask;
16716 + * by udba rename or rmdir, aufs assign a new inode to the known
16717 + * h_inode, so specify 1 to allow dups.
16720 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
16726 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
16728 + struct fsnotify_mark *mark;
16729 + unsigned long long ull;
16730 + struct fsnotify_group *group;
16732 + ull = atomic64_inc_return(&au_hfsn_ifree);
16735 + mark = &hn->hn_mark;
16736 + spin_lock(&mark->lock);
16737 + group = mark->group;
16738 + fsnotify_get_group(group);
16739 + spin_unlock(&mark->lock);
16741 + fsnotify_destroy_mark(mark, group);
16742 + fsnotify_put_mark(mark);
16743 + fsnotify_put_group(group);
16746 + /* free hn by myself */
16750 +/* ---------------------------------------------------------------------- */
16752 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
16754 + struct fsnotify_mark *mark;
16756 + mark = &hinode->hi_notify->hn_mark;
16757 + spin_lock(&mark->lock);
16759 + AuDebugOn(mark->mask & AuHfsnMask);
16760 + mark->mask |= AuHfsnMask;
16762 + AuDebugOn(!(mark->mask & AuHfsnMask));
16763 + mark->mask &= ~AuHfsnMask;
16765 + spin_unlock(&mark->lock);
16766 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
16769 +/* ---------------------------------------------------------------------- */
16771 +/* #define AuDbgHnotify */
16772 +#ifdef AuDbgHnotify
16773 +static char *au_hfsn_name(u32 mask)
16775 +#ifdef CONFIG_AUFS_DEBUG
16776 +#define test_ret(flag) \
16778 + if (mask & flag) \
16781 + test_ret(FS_ACCESS);
16782 + test_ret(FS_MODIFY);
16783 + test_ret(FS_ATTRIB);
16784 + test_ret(FS_CLOSE_WRITE);
16785 + test_ret(FS_CLOSE_NOWRITE);
16786 + test_ret(FS_OPEN);
16787 + test_ret(FS_MOVED_FROM);
16788 + test_ret(FS_MOVED_TO);
16789 + test_ret(FS_CREATE);
16790 + test_ret(FS_DELETE);
16791 + test_ret(FS_DELETE_SELF);
16792 + test_ret(FS_MOVE_SELF);
16793 + test_ret(FS_UNMOUNT);
16794 + test_ret(FS_Q_OVERFLOW);
16795 + test_ret(FS_IN_IGNORED);
16796 + test_ret(FS_ISDIR);
16797 + test_ret(FS_IN_ONESHOT);
16798 + test_ret(FS_EVENT_ON_CHILD);
16807 +/* ---------------------------------------------------------------------- */
16809 +static void au_hfsn_free_group(struct fsnotify_group *group)
16811 + struct au_br_hfsnotify *hfsn = group->private;
16813 + /* AuDbg("here\n"); */
16814 + au_kfree_try_rcu(hfsn);
16817 +static int au_hfsn_handle_event(struct fsnotify_group *group,
16818 + u32 mask, const void *data, int data_type,
16819 + struct inode *dir,
16820 + const struct qstr *file_name, u32 cookie,
16821 + struct fsnotify_iter_info *iter_info)
16824 + struct au_hnotify *hnotify;
16825 + struct inode *h_dir, *h_inode;
16826 + struct fsnotify_mark *inode_mark;
16828 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
16831 + /* if FS_UNMOUNT happens, there must be another bug */
16832 + AuDebugOn(mask & FS_UNMOUNT);
16833 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
16838 +#ifdef AuDbgHnotify
16840 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
16841 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
16842 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
16843 + h_dir->i_ino, mask, au_hfsn_name(mask),
16844 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
16845 + /* WARN_ON(1); */
16850 + inode_mark = fsnotify_iter_inode_mark(iter_info);
16851 + AuDebugOn(!inode_mark);
16852 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
16853 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
16859 +static struct fsnotify_ops au_hfsn_ops = {
16860 + .handle_event = au_hfsn_handle_event,
16861 + .free_group_priv = au_hfsn_free_group,
16862 + .free_mark = au_hfsn_free_mark
16865 +/* ---------------------------------------------------------------------- */
16867 +static void au_hfsn_fin_br(struct au_branch *br)
16869 + struct au_br_hfsnotify *hfsn;
16871 + hfsn = br->br_hfsn;
16874 + fsnotify_put_group(hfsn->hfsn_group);
16879 +static int au_hfsn_init_br(struct au_branch *br, int perm)
16882 + struct fsnotify_group *group;
16883 + struct au_br_hfsnotify *hfsn;
16886 + br->br_hfsn = NULL;
16887 + if (!au_br_hnotifyable(perm))
16891 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
16892 + if (unlikely(!hfsn))
16896 + group = fsnotify_alloc_group(&au_hfsn_ops);
16897 + if (IS_ERR(group)) {
16898 + err = PTR_ERR(group);
16899 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
16903 + group->private = hfsn;
16904 + hfsn->hfsn_group = group;
16905 + br->br_hfsn = hfsn;
16906 + goto out; /* success */
16909 + au_kfree_try_rcu(hfsn);
16914 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
16919 + if (!br->br_hfsn)
16920 + err = au_hfsn_init_br(br, perm);
16925 +/* ---------------------------------------------------------------------- */
16927 +static void au_hfsn_fin(void)
16929 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
16930 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
16933 +const struct au_hnotify_op au_hnotify_op = {
16934 + .ctl = au_hfsn_ctl,
16935 + .alloc = au_hfsn_alloc,
16936 + .free = au_hfsn_free,
16938 + .fin = au_hfsn_fin,
16940 + .reset_br = au_hfsn_reset_br,
16941 + .fin_br = au_hfsn_fin_br,
16942 + .init_br = au_hfsn_init_br
16944 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
16945 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
16946 +++ linux/fs/aufs/hfsplus.c 2021-12-03 15:38:59.936647310 +0100
16948 +// SPDX-License-Identifier: GPL-2.0
16950 + * Copyright (C) 2010-2021 Junjiro R. Okajima
16952 + * This program, aufs is free software; you can redistribute it and/or modify
16953 + * it under the terms of the GNU General Public License as published by
16954 + * the Free Software Foundation; either version 2 of the License, or
16955 + * (at your option) any later version.
16957 + * This program is distributed in the hope that it will be useful,
16958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16960 + * GNU General Public License for more details.
16962 + * You should have received a copy of the GNU General Public License
16963 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16967 + * special support for filesystems which acquires an inode mutex
16968 + * at final closing a file, eg, hfsplus.
16970 + * This trick is very simple and stupid, just to open the file before really
16971 + * necessary open to tell hfsplus that this is not the final closing.
16972 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
16973 + * and au_h_open_post() after releasing it.
16978 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
16981 + struct file *h_file;
16982 + struct dentry *h_dentry;
16984 + h_dentry = au_h_dptr(dentry, bindex);
16985 + AuDebugOn(!h_dentry);
16986 + AuDebugOn(d_is_negative(h_dentry));
16989 + if (au_test_hfsplus(h_dentry->d_sb)
16990 + && d_is_reg(h_dentry))
16991 + h_file = au_h_open(dentry, bindex,
16992 + O_RDONLY | O_NOATIME | O_LARGEFILE,
16993 + /*file*/NULL, force_wr);
16997 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
16998 + struct file *h_file)
17000 + struct au_branch *br;
17004 + br = au_sbr(dentry->d_sb, bindex);
17005 + au_lcnt_dec(&br->br_nfiles);
17008 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
17009 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
17010 +++ linux/fs/aufs/hnotify.c 2021-12-03 15:38:59.936647310 +0100
17012 +// SPDX-License-Identifier: GPL-2.0
17014 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17016 + * This program, aufs is free software; you can redistribute it and/or modify
17017 + * it under the terms of the GNU General Public License as published by
17018 + * the Free Software Foundation; either version 2 of the License, or
17019 + * (at your option) any later version.
17021 + * This program is distributed in the hope that it will be useful,
17022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17024 + * GNU General Public License for more details.
17026 + * You should have received a copy of the GNU General Public License
17027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17031 + * abstraction to notify the direct changes on lower directories
17034 +/* #include <linux/iversion.h> */
17037 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
17040 + struct au_hnotify *hn;
17043 + hn = au_cache_alloc_hnotify();
17045 + hn->hn_aufs_inode = inode;
17046 + hinode->hi_notify = hn;
17047 + err = au_hnotify_op.alloc(hinode);
17049 + if (unlikely(err)) {
17050 + hinode->hi_notify = NULL;
17051 + au_cache_free_hnotify(hn);
17053 + * The upper dir was removed by udba, but the same named
17054 + * dir left. In this case, aufs assigns a new inode
17055 + * number and set the monitor again.
17056 + * For the lower dir, the old monitor is still left.
17058 + if (err == -EEXIST)
17067 +void au_hn_free(struct au_hinode *hinode)
17069 + struct au_hnotify *hn;
17071 + hn = hinode->hi_notify;
17073 + hinode->hi_notify = NULL;
17074 + if (au_hnotify_op.free(hinode, hn))
17075 + au_cache_free_hnotify(hn);
17079 +/* ---------------------------------------------------------------------- */
17081 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
17083 + if (hinode->hi_notify)
17084 + au_hnotify_op.ctl(hinode, do_set);
17087 +void au_hn_reset(struct inode *inode, unsigned int flags)
17089 + aufs_bindex_t bindex, bbot;
17090 + struct inode *hi;
17091 + struct dentry *iwhdentry;
17093 + bbot = au_ibbot(inode);
17094 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
17095 + hi = au_h_iptr(inode, bindex);
17099 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
17100 + iwhdentry = au_hi_wh(inode, bindex);
17104 + au_set_h_iptr(inode, bindex, NULL, 0);
17105 + au_set_h_iptr(inode, bindex, au_igrab(hi),
17106 + flags & ~AuHi_XINO);
17109 + /* inode_unlock(hi); */
17113 +/* ---------------------------------------------------------------------- */
17115 +static int hn_xino(struct inode *inode, struct inode *h_inode)
17118 + aufs_bindex_t bindex, bbot, bfound, btop;
17119 + struct inode *h_i;
17122 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17123 + pr_warn("branch root dir was changed\n");
17128 + bbot = au_ibbot(inode);
17129 + btop = au_ibtop(inode);
17130 +#if 0 /* reserved for future use */
17131 + if (bindex == bbot) {
17132 + /* keep this ino in rename case */
17136 + for (bindex = btop; bindex <= bbot; bindex++)
17137 + if (au_h_iptr(inode, bindex) == h_inode) {
17144 + for (bindex = btop; bindex <= bbot; bindex++) {
17145 + h_i = au_h_iptr(inode, bindex);
17149 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
17150 + /* ignore this error */
17151 + /* bad action? */
17154 + /* children inode number will be broken */
17161 +static int hn_gen_tree(struct dentry *dentry)
17163 + int err, i, j, ndentry;
17164 + struct au_dcsub_pages dpages;
17165 + struct au_dpage *dpage;
17166 + struct dentry **dentries;
17168 + err = au_dpages_init(&dpages, GFP_NOFS);
17169 + if (unlikely(err))
17171 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
17172 + if (unlikely(err))
17175 + for (i = 0; i < dpages.ndpage; i++) {
17176 + dpage = dpages.dpages + i;
17177 + dentries = dpage->dentries;
17178 + ndentry = dpage->ndentry;
17179 + for (j = 0; j < ndentry; j++) {
17180 + struct dentry *d;
17187 + if (d_really_is_positive(d))
17188 + /* todo: reset children xino?
17189 + cached children only? */
17190 + au_iigen_dec(d_inode(d));
17195 + au_dpages_free(&dpages);
17201 + * return 0 if processed.
17203 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
17204 + const unsigned int isdir)
17207 + struct dentry *d;
17208 + struct qstr *dname;
17211 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17212 + pr_warn("branch root dir was changed\n");
17218 + AuDebugOn(!name);
17219 + au_iigen_dec(inode);
17220 + spin_lock(&inode->i_lock);
17221 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
17222 + spin_lock(&d->d_lock);
17223 + dname = &d->d_name;
17224 + if (dname->len != nlen
17225 + && memcmp(dname->name, name, nlen)) {
17226 + spin_unlock(&d->d_lock);
17231 + spin_unlock(&d->d_lock);
17234 + spin_unlock(&inode->i_lock);
17236 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
17237 + d = d_find_any_alias(inode);
17239 + au_iigen_dec(inode);
17243 + spin_lock(&d->d_lock);
17244 + dname = &d->d_name;
17245 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
17246 + spin_unlock(&d->d_lock);
17247 + err = hn_gen_tree(d);
17248 + spin_lock(&d->d_lock);
17250 + spin_unlock(&d->d_lock);
17259 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
17263 + if (IS_ROOT(dentry)) {
17264 + pr_warn("branch root dir was changed\n");
17270 + au_digen_dec(dentry);
17271 + if (d_really_is_positive(dentry))
17272 + au_iigen_dec(d_inode(dentry));
17274 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
17275 + if (d_really_is_positive(dentry))
17276 + err = hn_gen_tree(dentry);
17283 +/* ---------------------------------------------------------------------- */
17285 +/* hnotify job flags */
17286 +#define AuHnJob_XINO0 1
17287 +#define AuHnJob_GEN (1 << 1)
17288 +#define AuHnJob_DIRENT (1 << 2)
17289 +#define AuHnJob_ISDIR (1 << 3)
17290 +#define AuHnJob_TRYXINO0 (1 << 4)
17291 +#define AuHnJob_MNTPNT (1 << 5)
17292 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
17293 +#define au_fset_hnjob(flags, name) \
17294 + do { (flags) |= AuHnJob_##name; } while (0)
17295 +#define au_fclr_hnjob(flags, name) \
17296 + do { (flags) &= ~AuHnJob_##name; } while (0)
17304 +struct au_hnotify_args {
17305 + struct inode *h_dir, *dir, *h_child_inode;
17307 + unsigned int flags[AuHnLast];
17308 + unsigned int h_child_nlen;
17309 + char h_child_name[];
17312 +struct hn_job_args {
17313 + unsigned int flags;
17314 + struct inode *inode, *h_inode, *dir, *h_dir;
17315 + struct dentry *dentry;
17320 +static int hn_job(struct hn_job_args *a)
17322 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
17326 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
17327 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17329 + if (au_ftest_hnjob(a->flags, TRYXINO0)
17332 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
17333 + if (!a->h_inode->i_nlink
17334 + && !(a->h_inode->i_state & I_LINKABLE))
17335 + hn_xino(a->inode, a->h_inode); /* ignore this error */
17336 + inode_unlock_shared(a->h_inode);
17339 + /* make the generation obsolete */
17340 + if (au_ftest_hnjob(a->flags, GEN)) {
17343 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
17345 + if (e && a->dentry)
17346 + hn_gen_by_name(a->dentry, isdir);
17347 + /* ignore this error */
17350 + /* make dir entries obsolete */
17351 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
17352 + struct au_vdir *vdir;
17354 + vdir = au_ivdir(a->inode);
17356 + vdir->vd_jiffy = 0;
17357 + /* IMustLock(a->inode); */
17358 + /* inode_inc_iversion(a->inode); */
17361 + /* can do nothing but warn */
17362 + if (au_ftest_hnjob(a->flags, MNTPNT)
17364 + && d_mountpoint(a->dentry))
17365 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
17370 +/* ---------------------------------------------------------------------- */
17372 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
17373 + struct inode *dir)
17375 + struct dentry *dentry, *d, *parent;
17376 + struct qstr *dname;
17378 + parent = d_find_any_alias(dir);
17383 + spin_lock(&parent->d_lock);
17384 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
17385 + /* AuDbg("%pd\n", d); */
17386 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
17387 + dname = &d->d_name;
17388 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
17389 + goto cont_unlock;
17393 + goto cont_unlock;
17394 + if (au_dcount(d) > 0) {
17395 + dentry = dget_dlock(d);
17396 + spin_unlock(&d->d_lock);
17401 + spin_unlock(&d->d_lock);
17403 + spin_unlock(&parent->d_lock);
17407 + di_write_lock_child(dentry);
17412 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
17413 + aufs_bindex_t bindex, ino_t h_ino)
17415 + struct inode *inode;
17420 + err = au_xino_read(sb, bindex, h_ino, &ino);
17422 + inode = ilookup(sb, ino);
17426 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
17427 + pr_warn("wrong root branch\n");
17433 + ii_write_lock_child(inode);
17439 +static void au_hn_bh(void *_args)
17441 + struct au_hnotify_args *a = _args;
17442 + struct super_block *sb;
17443 + aufs_bindex_t bindex, bbot, bfound;
17444 + unsigned char xino, try_iput;
17446 + struct inode *inode;
17448 + struct hn_job_args args;
17449 + struct dentry *dentry;
17450 + struct au_sbinfo *sbinfo;
17452 + AuDebugOn(!_args);
17453 + AuDebugOn(!a->h_dir);
17454 + AuDebugOn(!a->dir);
17455 + AuDebugOn(!a->mask);
17456 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
17457 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
17458 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
17463 + * do not lock a->dir->i_mutex here
17464 + * because of d_revalidate() may cause a deadlock.
17466 + sb = a->dir->i_sb;
17468 + sbinfo = au_sbi(sb);
17469 + AuDebugOn(!sbinfo);
17470 + si_write_lock(sb, AuLock_NOPLMW);
17472 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
17473 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
17474 + case FS_MOVED_FROM:
17475 + case FS_MOVED_TO:
17476 + AuWarn1("DIRREN with UDBA may not work correctly "
17477 + "for the direct rename(2)\n");
17480 + ii_read_lock_parent(a->dir);
17482 + bbot = au_ibbot(a->dir);
17483 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
17484 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
17488 + ii_read_unlock(a->dir);
17489 + if (unlikely(bfound < 0))
17492 + xino = !!au_opt_test(au_mntflags(sb), XINO);
17494 + if (a->h_child_inode)
17495 + h_ino = a->h_child_inode->i_ino;
17497 + if (a->h_child_nlen
17498 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
17499 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
17500 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
17503 + if (dentry && d_really_is_positive(dentry))
17504 + inode = d_inode(dentry);
17505 + if (xino && !inode && h_ino
17506 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
17507 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
17508 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
17509 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
17513 + args.flags = a->flags[AuHn_CHILD];
17514 + args.dentry = dentry;
17515 + args.inode = inode;
17516 + args.h_inode = a->h_child_inode;
17517 + args.dir = a->dir;
17518 + args.h_dir = a->h_dir;
17519 + args.h_name = a->h_child_name;
17520 + args.h_nlen = a->h_child_nlen;
17521 + err = hn_job(&args);
17523 + if (au_di(dentry))
17524 + di_write_unlock(dentry);
17527 + if (inode && try_iput) {
17528 + ii_write_unlock(inode);
17532 + ii_write_lock_parent(a->dir);
17533 + args.flags = a->flags[AuHn_PARENT];
17534 + args.dentry = NULL;
17535 + args.inode = a->dir;
17536 + args.h_inode = a->h_dir;
17538 + args.h_dir = NULL;
17539 + args.h_name = NULL;
17541 + err = hn_job(&args);
17542 + ii_write_unlock(a->dir);
17545 + iput(a->h_child_inode);
17548 + si_write_unlock(sb);
17549 + au_nwt_done(&sbinfo->si_nowait);
17553 +/* ---------------------------------------------------------------------- */
17555 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17556 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
17559 + unsigned int flags[AuHnLast], f;
17560 + unsigned char isdir, isroot, wh;
17561 + struct inode *dir;
17562 + struct au_hnotify_args *args;
17563 + char *p, *h_child_name;
17566 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
17567 + dir = igrab(hnotify->hn_aufs_inode);
17571 + isroot = (dir->i_ino == AUFS_ROOT_INO);
17573 + h_child_name = (void *)h_child_qstr->name;
17574 + len = h_child_qstr->len;
17575 + if (h_child_name) {
17576 + if (len > AUFS_WH_PFX_LEN
17577 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
17578 + h_child_name += AUFS_WH_PFX_LEN;
17579 + len -= AUFS_WH_PFX_LEN;
17585 + if (h_child_inode)
17586 + isdir = !!S_ISDIR(h_child_inode->i_mode);
17587 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
17588 + flags[AuHn_CHILD] = 0;
17590 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
17591 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
17592 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
17593 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
17594 + case FS_MOVED_FROM:
17595 + case FS_MOVED_TO:
17596 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
17597 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17600 + AuDebugOn(!h_child_name);
17605 + * aufs never be able to get this child inode.
17606 + * revalidation should be in d_revalidate()
17607 + * by checking i_nlink, i_generation or d_unhashed().
17609 + AuDebugOn(!h_child_name);
17610 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
17611 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
17619 + h_child_inode = NULL;
17622 + /* iput() and kfree() will be called in au_hnotify() */
17623 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
17624 + if (unlikely(!args)) {
17625 + AuErr1("no memory\n");
17629 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
17630 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
17631 + args->mask = mask;
17633 + args->h_dir = igrab(h_dir);
17634 + if (h_child_inode)
17635 + h_child_inode = igrab(h_child_inode); /* can be NULL */
17636 + args->h_child_inode = h_child_inode;
17637 + args->h_child_nlen = len;
17639 + p = (void *)args;
17640 + p += sizeof(*args);
17641 + memcpy(p, h_child_name, len);
17645 + /* NFS fires the event for silly-renamed one from kworker */
17647 + if (!dir->i_nlink
17648 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
17650 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
17651 + if (unlikely(err)) {
17652 + pr_err("wkq %d\n", err);
17653 + iput(args->h_child_inode);
17654 + iput(args->h_dir);
17656 + au_kfree_rcu(args);
17663 +/* ---------------------------------------------------------------------- */
17665 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
17669 + AuDebugOn(!(udba & AuOptMask_UDBA));
17672 + if (au_hnotify_op.reset_br)
17673 + err = au_hnotify_op.reset_br(udba, br, perm);
17678 +int au_hnotify_init_br(struct au_branch *br, int perm)
17683 + if (au_hnotify_op.init_br)
17684 + err = au_hnotify_op.init_br(br, perm);
17689 +void au_hnotify_fin_br(struct au_branch *br)
17691 + if (au_hnotify_op.fin_br)
17692 + au_hnotify_op.fin_br(br);
17695 +static void au_hn_destroy_cache(void)
17697 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
17698 + au_cache[AuCache_HNOTIFY] = NULL;
17701 +int __init au_hnotify_init(void)
17706 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
17707 + if (au_cache[AuCache_HNOTIFY]) {
17709 + if (au_hnotify_op.init)
17710 + err = au_hnotify_op.init();
17711 + if (unlikely(err))
17712 + au_hn_destroy_cache();
17718 +void au_hnotify_fin(void)
17720 + if (au_hnotify_op.fin)
17721 + au_hnotify_op.fin();
17723 + /* cf. au_cache_fin() */
17724 + if (au_cache[AuCache_HNOTIFY])
17725 + au_hn_destroy_cache();
17727 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
17728 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
17729 +++ linux/fs/aufs/iinfo.c 2021-12-03 15:38:59.936647310 +0100
17731 +// SPDX-License-Identifier: GPL-2.0
17733 + * Copyright (C) 2005-2021 Junjiro R. Okajima
17735 + * This program, aufs is free software; you can redistribute it and/or modify
17736 + * it under the terms of the GNU General Public License as published by
17737 + * the Free Software Foundation; either version 2 of the License, or
17738 + * (at your option) any later version.
17740 + * This program is distributed in the hope that it will be useful,
17741 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17742 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17743 + * GNU General Public License for more details.
17745 + * You should have received a copy of the GNU General Public License
17746 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17750 + * inode private data
17755 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
17757 + struct inode *h_inode;
17758 + struct au_hinode *hinode;
17760 + IiMustAnyLock(inode);
17762 + hinode = au_hinode(au_ii(inode), bindex);
17763 + h_inode = hinode->hi_inode;
17764 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17768 +/* todo: hard/soft set? */
17769 +void au_hiput(struct au_hinode *hinode)
17771 + au_hn_free(hinode);
17772 + dput(hinode->hi_whdentry);
17773 + iput(hinode->hi_inode);
17776 +unsigned int au_hi_flags(struct inode *inode, int isdir)
17778 + unsigned int flags;
17779 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
17782 + if (au_opt_test(mnt_flags, XINO))
17783 + au_fset_hi(flags, XINO);
17784 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
17785 + au_fset_hi(flags, HNOTIFY);
17789 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
17790 + struct inode *h_inode, unsigned int flags)
17792 + struct au_hinode *hinode;
17793 + struct inode *hi;
17794 + struct au_iinfo *iinfo = au_ii(inode);
17796 + IiMustWriteLock(inode);
17798 + hinode = au_hinode(iinfo, bindex);
17799 + hi = hinode->hi_inode;
17800 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
17803 + au_hiput(hinode);
17804 + hinode->hi_inode = h_inode;
17807 + struct super_block *sb = inode->i_sb;
17808 + struct au_branch *br;
17810 + AuDebugOn(inode->i_mode
17811 + && (h_inode->i_mode & S_IFMT)
17812 + != (inode->i_mode & S_IFMT));
17813 + if (bindex == iinfo->ii_btop)
17814 + au_cpup_igen(inode, h_inode);
17815 + br = au_sbr(sb, bindex);
17816 + hinode->hi_id = br->br_id;
17817 + if (au_ftest_hi(flags, XINO)) {
17818 + err = au_xino_write(sb, bindex, h_inode->i_ino,
17820 + if (unlikely(err))
17821 + AuIOErr1("failed au_xino_write() %d\n", err);
17824 + if (au_ftest_hi(flags, HNOTIFY)
17825 + && au_br_hnotifyable(br->br_perm)) {
17826 + err = au_hn_alloc(hinode, inode);
17827 + if (unlikely(err))
17828 + AuIOErr1("au_hn_alloc() %d\n", err);
17833 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
17834 + struct dentry *h_wh)
17836 + struct au_hinode *hinode;
17838 + IiMustWriteLock(inode);
17840 + hinode = au_hinode(au_ii(inode), bindex);
17841 + AuDebugOn(hinode->hi_whdentry);
17842 + hinode->hi_whdentry = h_wh;
17845 +void au_update_iigen(struct inode *inode, int half)
17847 + struct au_iinfo *iinfo;
17848 + struct au_iigen *iigen;
17849 + unsigned int sigen;
17851 + sigen = au_sigen(inode->i_sb);
17852 + iinfo = au_ii(inode);
17853 + iigen = &iinfo->ii_generation;
17854 + spin_lock(&iigen->ig_spin);
17855 + iigen->ig_generation = sigen;
17857 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
17859 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
17860 + spin_unlock(&iigen->ig_spin);
17863 +/* it may be called at remount time, too */
17864 +void au_update_ibrange(struct inode *inode, int do_put_zero)
17866 + struct au_iinfo *iinfo;
17867 + aufs_bindex_t bindex, bbot;
17869 + AuDebugOn(au_is_bad_inode(inode));
17870 + IiMustWriteLock(inode);
17872 + iinfo = au_ii(inode);
17873 + if (do_put_zero && iinfo->ii_btop >= 0) {
17874 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
17876 + struct inode *h_i;
17878 + h_i = au_hinode(iinfo, bindex)->hi_inode;
17881 + && !(h_i->i_state & I_LINKABLE))
17882 + au_set_h_iptr(inode, bindex, NULL, 0);
17886 + iinfo->ii_btop = -1;
17887 + iinfo->ii_bbot = -1;
17888 + bbot = au_sbbot(inode->i_sb);
17889 + for (bindex = 0; bindex <= bbot; bindex++)
17890 + if (au_hinode(iinfo, bindex)->hi_inode) {
17891 + iinfo->ii_btop = bindex;
17894 + if (iinfo->ii_btop >= 0)
17895 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
17896 + if (au_hinode(iinfo, bindex)->hi_inode) {
17897 + iinfo->ii_bbot = bindex;
17900 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
17903 +/* ---------------------------------------------------------------------- */
17905 +void au_icntnr_init_once(void *_c)
17907 + struct au_icntnr *c = _c;
17908 + struct au_iinfo *iinfo = &c->iinfo;
17910 + spin_lock_init(&iinfo->ii_generation.ig_spin);
17911 + au_rw_init(&iinfo->ii_rwsem);
17912 + inode_init_once(&c->vfs_inode);
17915 +void au_hinode_init(struct au_hinode *hinode)
17917 + hinode->hi_inode = NULL;
17918 + hinode->hi_id = -1;
17919 + au_hn_init(hinode);
17920 + hinode->hi_whdentry = NULL;
17923 +int au_iinfo_init(struct inode *inode)
17925 + struct au_iinfo *iinfo;
17926 + struct super_block *sb;
17927 + struct au_hinode *hi;
17930 + sb = inode->i_sb;
17931 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
17932 + nbr = au_sbbot(sb) + 1;
17933 + if (unlikely(nbr <= 0))
17935 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
17937 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
17939 + iinfo->ii_hinode = hi;
17940 + for (i = 0; i < nbr; i++, hi++)
17941 + au_hinode_init(hi);
17943 + iinfo->ii_generation.ig_generation = au_sigen(sb);
17944 + iinfo->ii_btop = -1;
17945 + iinfo->ii_bbot = -1;
17946 + iinfo->ii_vdir = NULL;
17952 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
17955 + struct au_hinode *hip;
17957 + AuRwMustWriteLock(&iinfo->ii_rwsem);
17960 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
17963 + iinfo->ii_hinode = hip;
17964 + i = iinfo->ii_bbot + 1;
17966 + for (; i < nbr; i++, hip++)
17967 + au_hinode_init(hip);
17974 +void au_iinfo_fin(struct inode *inode)
17976 + struct au_iinfo *iinfo;
17977 + struct au_hinode *hi;
17978 + struct super_block *sb;
17979 + aufs_bindex_t bindex, bbot;
17980 + const unsigned char unlinked = !inode->i_nlink;
17982 + AuDebugOn(au_is_bad_inode(inode));
17984 + sb = inode->i_sb;
17985 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
17986 + if (si_pid_test(sb))
17987 + au_xino_delete_inode(inode, unlinked);
17990 + * it is safe to hide the dependency between sbinfo and
17994 + si_noflush_read_lock(sb);
17995 + au_xino_delete_inode(inode, unlinked);
17996 + si_read_unlock(sb);
18000 + iinfo = au_ii(inode);
18001 + if (iinfo->ii_vdir)
18002 + au_vdir_free(iinfo->ii_vdir);
18004 + bindex = iinfo->ii_btop;
18005 + if (bindex >= 0) {
18006 + hi = au_hinode(iinfo, bindex);
18007 + bbot = iinfo->ii_bbot;
18008 + while (bindex++ <= bbot) {
18009 + if (hi->hi_inode)
18014 + au_kfree_rcu(iinfo->ii_hinode);
18015 + AuRwDestroy(&iinfo->ii_rwsem);
18017 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
18018 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
18019 +++ linux/fs/aufs/inode.c 2021-12-03 15:38:59.936647310 +0100
18021 +// SPDX-License-Identifier: GPL-2.0
18023 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18025 + * This program, aufs is free software; you can redistribute it and/or modify
18026 + * it under the terms of the GNU General Public License as published by
18027 + * the Free Software Foundation; either version 2 of the License, or
18028 + * (at your option) any later version.
18030 + * This program is distributed in the hope that it will be useful,
18031 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18032 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18033 + * GNU General Public License for more details.
18035 + * You should have received a copy of the GNU General Public License
18036 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18040 + * inode functions
18043 +#include <linux/iversion.h>
18046 +struct inode *au_igrab(struct inode *inode)
18049 + AuDebugOn(!atomic_read(&inode->i_count));
18055 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
18057 + au_cpup_attr_all(inode, /*force*/0);
18058 + au_update_iigen(inode, /*half*/1);
18060 + inode_inc_iversion(inode);
18063 +static int au_ii_refresh(struct inode *inode, int *update)
18067 + aufs_bindex_t bindex, new_bindex;
18068 + struct super_block *sb;
18069 + struct au_iinfo *iinfo;
18070 + struct au_hinode *p, *q, tmp;
18072 + AuDebugOn(au_is_bad_inode(inode));
18073 + IiMustWriteLock(inode);
18076 + sb = inode->i_sb;
18077 + nbr = au_sbbot(sb) + 1;
18078 + type = inode->i_mode & S_IFMT;
18079 + iinfo = au_ii(inode);
18080 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
18081 + if (unlikely(err))
18084 + AuDebugOn(iinfo->ii_btop < 0);
18085 + p = au_hinode(iinfo, iinfo->ii_btop);
18086 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
18088 + if (!p->hi_inode)
18091 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
18092 + new_bindex = au_br_index(sb, p->hi_id);
18093 + if (new_bindex == bindex)
18096 + if (new_bindex < 0) {
18099 + p->hi_inode = NULL;
18103 + if (new_bindex < iinfo->ii_btop)
18104 + iinfo->ii_btop = new_bindex;
18105 + if (iinfo->ii_bbot < new_bindex)
18106 + iinfo->ii_bbot = new_bindex;
18107 + /* swap two lower inode, and loop again */
18108 + q = au_hinode(iinfo, new_bindex);
18112 + if (tmp.hi_inode) {
18117 + au_update_ibrange(inode, /*do_put_zero*/0);
18118 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
18119 + e = au_dy_irefresh(inode);
18120 + if (unlikely(e && !err))
18128 +void au_refresh_iop(struct inode *inode, int force_getattr)
18131 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
18132 + const struct inode_operations *iop
18133 + = force_getattr ? aufs_iop : sbi->si_iop_array;
18135 + if (inode->i_op == iop)
18138 + switch (inode->i_mode & S_IFMT) {
18140 + type = AuIop_DIR;
18143 + type = AuIop_SYMLINK;
18146 + type = AuIop_OTHER;
18150 + inode->i_op = iop + type;
18151 + /* unnecessary smp_wmb() */
18154 +int au_refresh_hinode_self(struct inode *inode)
18158 + err = au_ii_refresh(inode, &update);
18160 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
18166 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
18168 + int err, e, update;
18169 + unsigned int flags;
18171 + aufs_bindex_t bindex, bbot;
18172 + unsigned char isdir;
18173 + struct au_hinode *p;
18174 + struct au_iinfo *iinfo;
18176 + err = au_ii_refresh(inode, &update);
18177 + if (unlikely(err))
18181 + iinfo = au_ii(inode);
18182 + p = au_hinode(iinfo, iinfo->ii_btop);
18183 + mode = (inode->i_mode & S_IFMT);
18184 + isdir = S_ISDIR(mode);
18185 + flags = au_hi_flags(inode, isdir);
18186 + bbot = au_dbbot(dentry);
18187 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
18188 + struct inode *h_i, *h_inode;
18189 + struct dentry *h_d;
18191 + h_d = au_h_dptr(dentry, bindex);
18192 + if (!h_d || d_is_negative(h_d))
18195 + h_inode = d_inode(h_d);
18196 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
18197 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
18198 + h_i = au_h_iptr(inode, bindex);
18200 + if (h_i == h_inode)
18206 + if (bindex < iinfo->ii_btop)
18207 + iinfo->ii_btop = bindex;
18208 + if (iinfo->ii_bbot < bindex)
18209 + iinfo->ii_bbot = bindex;
18210 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
18213 + au_update_ibrange(inode, /*do_put_zero*/0);
18214 + e = au_dy_irefresh(inode);
18215 + if (unlikely(e && !err))
18218 + au_refresh_hinode_attr(inode, update && isdir);
18225 +static int set_inode(struct inode *inode, struct dentry *dentry)
18228 + unsigned int flags;
18230 + aufs_bindex_t bindex, btop, btail;
18231 + unsigned char isdir;
18232 + struct dentry *h_dentry;
18233 + struct inode *h_inode;
18234 + struct au_iinfo *iinfo;
18235 + const struct inode_operations *iop;
18237 + IiMustWriteLock(inode);
18241 + iop = au_sbi(inode->i_sb)->si_iop_array;
18242 + btop = au_dbtop(dentry);
18243 + h_dentry = au_h_dptr(dentry, btop);
18244 + h_inode = d_inode(h_dentry);
18245 + mode = h_inode->i_mode;
18246 + switch (mode & S_IFMT) {
18248 + btail = au_dbtail(dentry);
18249 + inode->i_op = iop + AuIop_OTHER;
18250 + inode->i_fop = &aufs_file_fop;
18251 + err = au_dy_iaop(inode, btop, h_inode);
18252 + if (unlikely(err))
18257 + btail = au_dbtaildir(dentry);
18258 + inode->i_op = iop + AuIop_DIR;
18259 + inode->i_fop = &aufs_dir_fop;
18262 + btail = au_dbtail(dentry);
18263 + inode->i_op = iop + AuIop_SYMLINK;
18269 + btail = au_dbtail(dentry);
18270 + inode->i_op = iop + AuIop_OTHER;
18271 + init_special_inode(inode, mode, h_inode->i_rdev);
18274 + AuIOErr("Unknown file type 0%o\n", mode);
18279 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
18280 + flags = au_hi_flags(inode, isdir);
18281 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
18282 + && au_ftest_hi(flags, HNOTIFY)
18283 + && dentry->d_name.len > AUFS_WH_PFX_LEN
18284 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
18285 + au_fclr_hi(flags, HNOTIFY);
18286 + iinfo = au_ii(inode);
18287 + iinfo->ii_btop = btop;
18288 + iinfo->ii_bbot = btail;
18289 + for (bindex = btop; bindex <= btail; bindex++) {
18290 + h_dentry = au_h_dptr(dentry, bindex);
18292 + au_set_h_iptr(inode, bindex,
18293 + au_igrab(d_inode(h_dentry)), flags);
18295 + au_cpup_attr_all(inode, /*force*/1);
18297 + * to force calling aufs_get_acl() every time,
18298 + * do not call cache_no_acl() for aufs inode.
18306 + * successful returns with iinfo write_locked
18308 + * zero: success, matched
18309 + * plus: no error, but unmatched
18311 +static int reval_inode(struct inode *inode, struct dentry *dentry)
18314 + unsigned int gen, igflags;
18315 + aufs_bindex_t bindex, bbot;
18316 + struct inode *h_inode, *h_dinode;
18317 + struct dentry *h_dentry;
18320 + * before this function, if aufs got any iinfo lock, it must be only
18321 + * one, the parent dir.
18322 + * it can happen by UDBA and the obsoleted inode number.
18325 + if (unlikely(inode->i_ino == parent_ino(dentry)))
18329 + ii_write_lock_new_child(inode);
18330 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
18331 + h_dinode = d_inode(h_dentry);
18332 + bbot = au_ibbot(inode);
18333 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18334 + h_inode = au_h_iptr(inode, bindex);
18335 + if (!h_inode || h_inode != h_dinode)
18339 + gen = au_iigen(inode, &igflags);
18340 + if (gen == au_digen(dentry)
18341 + && !au_ig_ftest(igflags, HALF_REFRESHED))
18344 + /* fully refresh inode using dentry */
18345 + err = au_refresh_hinode(inode, dentry);
18347 + au_update_iigen(inode, /*half*/0);
18351 + if (unlikely(err))
18352 + ii_write_unlock(inode);
18357 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18358 + unsigned int d_type, ino_t *ino)
18361 + const int isnondir = d_type != DT_DIR;
18363 + /* prevent hardlinked inode number from race condition */
18365 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
18366 + if (unlikely(err))
18370 + err = au_xino_read(sb, bindex, h_ino, ino);
18371 + if (unlikely(err))
18372 + goto out_xinondir;
18376 + *ino = au_xino_new_ino(sb);
18377 + if (unlikely(!*ino))
18378 + goto out_xinondir;
18379 + err = au_xino_write(sb, bindex, h_ino, *ino);
18380 + if (unlikely(err))
18381 + goto out_xinondir;
18385 + if (isnondir && idx >= 0)
18386 + au_xinondir_leave(sb, bindex, h_ino, idx);
18391 +/* successful returns with iinfo write_locked */
18392 +/* todo: return with unlocked? */
18393 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
18395 + struct inode *inode, *h_inode;
18396 + struct dentry *h_dentry;
18397 + struct super_block *sb;
18398 + ino_t h_ino, ino;
18399 + int err, idx, hlinked;
18400 + aufs_bindex_t btop;
18402 + sb = dentry->d_sb;
18403 + btop = au_dbtop(dentry);
18404 + h_dentry = au_h_dptr(dentry, btop);
18405 + h_inode = d_inode(h_dentry);
18406 + h_ino = h_inode->i_ino;
18407 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
18411 + * stop 'race'-ing between hardlinks under different
18415 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18416 + inode = ERR_PTR(err);
18417 + if (unlikely(err))
18421 + err = au_xino_read(sb, btop, h_ino, &ino);
18422 + inode = ERR_PTR(err);
18423 + if (unlikely(err))
18424 + goto out_xinondir;
18427 + ino = au_xino_new_ino(sb);
18428 + if (unlikely(!ino)) {
18429 + inode = ERR_PTR(-EIO);
18430 + goto out_xinondir;
18434 + AuDbg("i%lu\n", (unsigned long)ino);
18435 + inode = au_iget_locked(sb, ino);
18436 + err = PTR_ERR(inode);
18437 + if (IS_ERR(inode))
18438 + goto out_xinondir;
18440 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
18441 + if (inode->i_state & I_NEW) {
18442 + ii_write_lock_new_child(inode);
18443 + err = set_inode(inode, dentry);
18445 + unlock_new_inode(inode);
18446 + goto out_xinondir; /* success */
18450 + * iget_failed() calls iput(), but we need to call
18451 + * ii_write_unlock() after iget_failed(). so dirty hack for
18454 + atomic_inc(&inode->i_count);
18455 + iget_failed(inode);
18456 + ii_write_unlock(inode);
18457 + au_xino_write(sb, btop, h_ino, /*ino*/0);
18458 + /* ignore this error */
18460 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
18462 + * horrible race condition between lookup, readdir and copyup
18463 + * (or something).
18465 + if (hlinked && idx >= 0)
18466 + au_xinondir_leave(sb, btop, h_ino, idx);
18467 + err = reval_inode(inode, dentry);
18468 + if (unlikely(err < 0)) {
18473 + goto out; /* success */
18474 + else if (hlinked && idx >= 0) {
18475 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
18476 + if (unlikely(err)) {
18478 + inode = ERR_PTR(err);
18484 + if (unlikely(au_test_fs_unique_ino(h_inode)))
18485 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
18486 + " b%d, %s, %pd, hi%lu, i%lu.\n",
18487 + btop, au_sbtype(h_dentry->d_sb), dentry,
18488 + (unsigned long)h_ino, (unsigned long)ino);
18490 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
18493 + if (hlinked && idx >= 0)
18494 + au_xinondir_leave(sb, btop, h_ino, idx);
18500 + inode = ERR_PTR(err);
18502 + if (hlinked && idx >= 0)
18503 + au_xinondir_leave(sb, btop, h_ino, idx);
18508 +/* ---------------------------------------------------------------------- */
18510 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18511 + struct inode *inode)
18514 + struct inode *hi;
18516 + err = au_br_rdonly(au_sbr(sb, bindex));
18518 + /* pseudo-link after flushed may happen out of bounds */
18521 + && au_ibtop(inode) <= bindex
18522 + && bindex <= au_ibbot(inode)) {
18524 + * permission check is unnecessary since vfsub routine
18525 + * will be called later
18527 + hi = au_h_iptr(inode, bindex);
18529 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
18535 +int au_test_h_perm(struct inode *h_inode, int mask)
18537 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
18539 + return inode_permission(h_inode, mask);
18542 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
18544 + if (au_test_nfs(h_inode->i_sb)
18545 + && (mask & MAY_WRITE)
18546 + && S_ISDIR(h_inode->i_mode))
18547 + mask |= MAY_READ; /* force permission check */
18548 + return au_test_h_perm(h_inode, mask);
18550 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
18551 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
18552 +++ linux/fs/aufs/inode.h 2021-12-03 15:38:59.936647310 +0100
18554 +/* SPDX-License-Identifier: GPL-2.0 */
18556 + * Copyright (C) 2005-2021 Junjiro R. Okajima
18558 + * This program, aufs is free software; you can redistribute it and/or modify
18559 + * it under the terms of the GNU General Public License as published by
18560 + * the Free Software Foundation; either version 2 of the License, or
18561 + * (at your option) any later version.
18563 + * This program is distributed in the hope that it will be useful,
18564 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18565 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18566 + * GNU General Public License for more details.
18568 + * You should have received a copy of the GNU General Public License
18569 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18573 + * inode operations
18576 +#ifndef __AUFS_INODE_H__
18577 +#define __AUFS_INODE_H__
18581 +#include <linux/fsnotify.h>
18582 +#include "rwsem.h"
18586 +struct au_hnotify {
18587 +#ifdef CONFIG_AUFS_HNOTIFY
18588 +#ifdef CONFIG_AUFS_HFSNOTIFY
18589 + /* never use fsnotify_add_vfsmount_mark() */
18590 + struct fsnotify_mark hn_mark;
18592 + struct inode *hn_aufs_inode; /* no get/put */
18593 + struct rcu_head rcu;
18595 +} ____cacheline_aligned_in_smp;
18597 +struct au_hinode {
18598 + struct inode *hi_inode;
18599 + aufs_bindex_t hi_id;
18600 +#ifdef CONFIG_AUFS_HNOTIFY
18601 + struct au_hnotify *hi_notify;
18604 + /* reference to the copied-up whiteout with get/put */
18605 + struct dentry *hi_whdentry;
18609 +#define AuIG_HALF_REFRESHED 1
18610 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
18611 +#define au_ig_fset(flags, name) \
18612 + do { (flags) |= AuIG_##name; } while (0)
18613 +#define au_ig_fclr(flags, name) \
18614 + do { (flags) &= ~AuIG_##name; } while (0)
18617 + spinlock_t ig_spin;
18618 + __u32 ig_generation, ig_flags;
18623 + struct au_iigen ii_generation;
18624 + struct super_block *ii_hsb1; /* no get/put */
18626 + struct au_rwsem ii_rwsem;
18627 + aufs_bindex_t ii_btop, ii_bbot;
18629 + struct au_hinode *ii_hinode;
18630 + struct au_vdir *ii_vdir;
18633 +struct au_icntnr {
18634 + struct au_iinfo iinfo;
18635 + struct inode vfs_inode;
18636 + struct hlist_bl_node plink;
18637 + struct rcu_head rcu;
18638 +} ____cacheline_aligned_in_smp;
18640 +/* au_pin flags */
18641 +#define AuPin_DI_LOCKED 1
18642 +#define AuPin_MNT_WRITE (1 << 1)
18643 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
18644 +#define au_fset_pin(flags, name) \
18645 + do { (flags) |= AuPin_##name; } while (0)
18646 +#define au_fclr_pin(flags, name) \
18647 + do { (flags) &= ~AuPin_##name; } while (0)
18651 + struct dentry *dentry;
18652 + unsigned int udba;
18653 + unsigned char lsc_di, lsc_hi, flags;
18654 + aufs_bindex_t bindex;
18657 + struct dentry *parent;
18658 + struct au_hinode *hdir;
18659 + struct vfsmount *h_mnt;
18661 + /* temporary unlock/relock for copyup */
18662 + struct dentry *h_dentry, *h_parent;
18663 + struct au_branch *br;
18664 + struct task_struct *task;
18667 +void au_pin_hdir_unlock(struct au_pin *p);
18668 +int au_pin_hdir_lock(struct au_pin *p);
18669 +int au_pin_hdir_relock(struct au_pin *p);
18670 +void au_pin_hdir_acquire_nest(struct au_pin *p);
18671 +void au_pin_hdir_release(struct au_pin *p);
18673 +/* ---------------------------------------------------------------------- */
18675 +static inline struct au_iinfo *au_ii(struct inode *inode)
18677 + BUG_ON(is_bad_inode(inode));
18678 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
18681 +/* ---------------------------------------------------------------------- */
18684 +struct inode *au_igrab(struct inode *inode);
18685 +void au_refresh_iop(struct inode *inode, int force_getattr);
18686 +int au_refresh_hinode_self(struct inode *inode);
18687 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
18688 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
18689 + unsigned int d_type, ino_t *ino);
18690 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
18691 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
18692 + struct inode *inode);
18693 +int au_test_h_perm(struct inode *h_inode, int mask);
18694 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
18696 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
18697 + ino_t h_ino, unsigned int d_type, ino_t *ino)
18699 +#ifdef CONFIG_AUFS_SHWH
18700 + return au_ino(sb, bindex, h_ino, d_type, ino);
18713 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
18714 + aufs_iop_nogetattr[AuIop_Last];
18716 +/* au_wr_dir flags */
18717 +#define AuWrDir_ADD_ENTRY 1
18718 +#define AuWrDir_ISDIR (1 << 1)
18719 +#define AuWrDir_TMPFILE (1 << 2)
18720 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
18721 +#define au_fset_wrdir(flags, name) \
18722 + do { (flags) |= AuWrDir_##name; } while (0)
18723 +#define au_fclr_wrdir(flags, name) \
18724 + do { (flags) &= ~AuWrDir_##name; } while (0)
18726 +struct au_wr_dir_args {
18727 + aufs_bindex_t force_btgt;
18728 + unsigned char flags;
18730 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18731 + struct au_wr_dir_args *args);
18733 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
18734 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
18735 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18736 + unsigned int udba, unsigned char flags);
18737 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18738 + unsigned int udba, unsigned char flags) __must_check;
18739 +int au_do_pin(struct au_pin *pin) __must_check;
18740 +void au_unpin(struct au_pin *pin);
18741 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
18743 +#define AuIcpup_DID_CPUP 1
18744 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18745 +#define au_fset_icpup(flags, name) \
18746 + do { (flags) |= AuIcpup_##name; } while (0)
18747 +#define au_fclr_icpup(flags, name) \
18748 + do { (flags) &= ~AuIcpup_##name; } while (0)
18750 +struct au_icpup_args {
18751 + unsigned char flags;
18752 + unsigned char pin_flags;
18753 + aufs_bindex_t btgt;
18754 + unsigned int udba;
18755 + struct au_pin pin;
18756 + struct path h_path;
18757 + struct inode *h_inode;
18760 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18761 + struct au_icpup_args *a);
18763 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
18764 + struct path *h_path, int locked);
18767 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
18768 + struct dentry *h_parent, int isdir);
18769 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
18771 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
18772 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
18774 +struct vfsub_aopen_args;
18775 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
18776 + struct vfsub_aopen_args *args);
18777 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
18778 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18779 + struct dentry *dentry);
18780 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
18783 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
18784 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
18785 + struct dentry *h_parent, int isdir);
18786 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
18787 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
18790 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
18791 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
18792 + struct inode *dir, struct dentry *dentry,
18793 + unsigned int flags);
18796 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
18797 +void au_hiput(struct au_hinode *hinode);
18798 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
18799 + struct dentry *h_wh);
18800 +unsigned int au_hi_flags(struct inode *inode, int isdir);
18802 +/* hinode flags */
18803 +#define AuHi_XINO 1
18804 +#define AuHi_HNOTIFY (1 << 1)
18805 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
18806 +#define au_fset_hi(flags, name) \
18807 + do { (flags) |= AuHi_##name; } while (0)
18808 +#define au_fclr_hi(flags, name) \
18809 + do { (flags) &= ~AuHi_##name; } while (0)
18811 +#ifndef CONFIG_AUFS_HNOTIFY
18812 +#undef AuHi_HNOTIFY
18813 +#define AuHi_HNOTIFY 0
18816 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
18817 + struct inode *h_inode, unsigned int flags);
18819 +void au_update_iigen(struct inode *inode, int half);
18820 +void au_update_ibrange(struct inode *inode, int do_put_zero);
18822 +void au_icntnr_init_once(void *_c);
18823 +void au_hinode_init(struct au_hinode *hinode);
18824 +int au_iinfo_init(struct inode *inode);
18825 +void au_iinfo_fin(struct inode *inode);
18826 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
18828 +#ifdef CONFIG_PROC_FS
18830 +int au_plink_maint(struct super_block *sb, int flags);
18832 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
18833 +int au_plink_maint_enter(struct super_block *sb);
18834 +#ifdef CONFIG_AUFS_DEBUG
18835 +void au_plink_list(struct super_block *sb);
18837 +AuStubVoid(au_plink_list, struct super_block *sb)
18839 +int au_plink_test(struct inode *inode);
18840 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
18841 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
18842 + struct dentry *h_dentry);
18843 +void au_plink_put(struct super_block *sb, int verbose);
18844 +void au_plink_clean(struct super_block *sb, int verbose);
18845 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
18847 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
18848 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
18849 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
18850 +AuStubVoid(au_plink_list, struct super_block *sb);
18851 +AuStubInt0(au_plink_test, struct inode *inode);
18852 +AuStub(struct dentry *, au_plink_lkup, return NULL,
18853 + struct inode *inode, aufs_bindex_t bindex);
18854 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
18855 + struct dentry *h_dentry);
18856 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
18857 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
18858 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
18859 +#endif /* CONFIG_PROC_FS */
18861 +#ifdef CONFIG_AUFS_XATTR
18863 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
18864 + unsigned int verbose);
18865 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
18866 +void au_xattr_init(struct super_block *sb);
18868 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
18869 + int ignore_flags, unsigned int verbose);
18870 +AuStubVoid(au_xattr_init, struct super_block *sb);
18873 +#ifdef CONFIG_FS_POSIX_ACL
18874 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
18875 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
18878 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
18884 +struct au_sxattr {
18888 + const char *name;
18889 + const void *value;
18894 + struct posix_acl *acl;
18899 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
18900 + struct au_sxattr *arg);
18903 +/* ---------------------------------------------------------------------- */
18905 +/* lock subclass for iinfo */
18907 + AuLsc_II_CHILD, /* child first */
18908 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
18909 + AuLsc_II_CHILD3, /* copyup dirs */
18910 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
18911 + AuLsc_II_PARENT2,
18912 + AuLsc_II_PARENT3, /* copyup dirs */
18913 + AuLsc_II_NEW_CHILD
18917 + * ii_read_lock_child, ii_write_lock_child,
18918 + * ii_read_lock_child2, ii_write_lock_child2,
18919 + * ii_read_lock_child3, ii_write_lock_child3,
18920 + * ii_read_lock_parent, ii_write_lock_parent,
18921 + * ii_read_lock_parent2, ii_write_lock_parent2,
18922 + * ii_read_lock_parent3, ii_write_lock_parent3,
18923 + * ii_read_lock_new_child, ii_write_lock_new_child,
18925 +#define AuReadLockFunc(name, lsc) \
18926 +static inline void ii_read_lock_##name(struct inode *i) \
18928 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18931 +#define AuWriteLockFunc(name, lsc) \
18932 +static inline void ii_write_lock_##name(struct inode *i) \
18934 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
18937 +#define AuRWLockFuncs(name, lsc) \
18938 + AuReadLockFunc(name, lsc) \
18939 + AuWriteLockFunc(name, lsc)
18941 +AuRWLockFuncs(child, CHILD);
18942 +AuRWLockFuncs(child2, CHILD2);
18943 +AuRWLockFuncs(child3, CHILD3);
18944 +AuRWLockFuncs(parent, PARENT);
18945 +AuRWLockFuncs(parent2, PARENT2);
18946 +AuRWLockFuncs(parent3, PARENT3);
18947 +AuRWLockFuncs(new_child, NEW_CHILD);
18949 +#undef AuReadLockFunc
18950 +#undef AuWriteLockFunc
18951 +#undef AuRWLockFuncs
18953 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
18954 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
18955 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
18957 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
18958 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
18959 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
18961 +/* ---------------------------------------------------------------------- */
18963 +static inline void au_icntnr_init(struct au_icntnr *c)
18965 +#ifdef CONFIG_AUFS_DEBUG
18966 + c->vfs_inode.i_mode = 0;
18970 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
18972 + unsigned int gen;
18973 + struct au_iinfo *iinfo;
18974 + struct au_iigen *iigen;
18976 + iinfo = au_ii(inode);
18977 + iigen = &iinfo->ii_generation;
18978 + spin_lock(&iigen->ig_spin);
18980 + *igflags = iigen->ig_flags;
18981 + gen = iigen->ig_generation;
18982 + spin_unlock(&iigen->ig_spin);
18987 +/* tiny test for inode number */
18988 +/* tmpfs generation is too rough */
18989 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
18991 + struct au_iinfo *iinfo;
18993 + iinfo = au_ii(inode);
18994 + AuRwMustAnyLock(&iinfo->ii_rwsem);
18995 + return !(iinfo->ii_hsb1 == h_inode->i_sb
18996 + && iinfo->ii_higen == h_inode->i_generation);
18999 +static inline void au_iigen_dec(struct inode *inode)
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);
19007 + iigen->ig_generation--;
19008 + spin_unlock(&iigen->ig_spin);
19011 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
19016 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
19022 +/* ---------------------------------------------------------------------- */
19024 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
19025 + aufs_bindex_t bindex)
19027 + return iinfo->ii_hinode + bindex;
19030 +static inline int au_is_bad_inode(struct inode *inode)
19032 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
19035 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
19036 + aufs_bindex_t bindex)
19038 + IiMustAnyLock(inode);
19039 + return au_hinode(au_ii(inode), bindex)->hi_id;
19042 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
19044 + IiMustAnyLock(inode);
19045 + return au_ii(inode)->ii_btop;
19048 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
19050 + IiMustAnyLock(inode);
19051 + return au_ii(inode)->ii_bbot;
19054 +static inline struct au_vdir *au_ivdir(struct inode *inode)
19056 + IiMustAnyLock(inode);
19057 + return au_ii(inode)->ii_vdir;
19060 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
19062 + IiMustAnyLock(inode);
19063 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
19066 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
19068 + IiMustWriteLock(inode);
19069 + au_ii(inode)->ii_btop = bindex;
19072 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
19074 + IiMustWriteLock(inode);
19075 + au_ii(inode)->ii_bbot = bindex;
19078 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
19080 + IiMustWriteLock(inode);
19081 + au_ii(inode)->ii_vdir = vdir;
19084 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
19086 + IiMustAnyLock(inode);
19087 + return au_hinode(au_ii(inode), bindex);
19090 +/* ---------------------------------------------------------------------- */
19092 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
19095 + return pin->parent;
19099 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
19101 + if (pin && pin->hdir)
19102 + return pin->hdir->hi_inode;
19106 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
19109 + return pin->hdir;
19113 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
19116 + pin->dentry = dentry;
19119 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
19120 + unsigned char lflag)
19124 + au_fset_pin(pin->flags, DI_LOCKED);
19126 + au_fclr_pin(pin->flags, DI_LOCKED);
19130 +#if 0 /* reserved */
19131 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
19134 + dput(pin->parent);
19135 + pin->parent = dget(parent);
19140 +/* ---------------------------------------------------------------------- */
19143 +#ifdef CONFIG_AUFS_HNOTIFY
19144 +struct au_hnotify_op {
19145 + void (*ctl)(struct au_hinode *hinode, int do_set);
19146 + int (*alloc)(struct au_hinode *hinode);
19149 + * if it returns true, the caller should free hinode->hi_notify,
19150 + * otherwise ->free() frees it.
19152 + int (*free)(struct au_hinode *hinode,
19153 + struct au_hnotify *hn) __must_check;
19155 + void (*fin)(void);
19156 + int (*init)(void);
19158 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
19159 + void (*fin_br)(struct au_branch *br);
19160 + int (*init_br)(struct au_branch *br, int perm);
19164 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
19165 +void au_hn_free(struct au_hinode *hinode);
19166 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
19167 +void au_hn_reset(struct inode *inode, unsigned int flags);
19168 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
19169 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
19170 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
19171 +int au_hnotify_init_br(struct au_branch *br, int perm);
19172 +void au_hnotify_fin_br(struct au_branch *br);
19173 +int __init au_hnotify_init(void);
19174 +void au_hnotify_fin(void);
19177 +extern const struct au_hnotify_op au_hnotify_op;
19180 +void au_hn_init(struct au_hinode *hinode)
19182 + hinode->hi_notify = NULL;
19185 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
19187 + return hinode->hi_notify;
19191 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
19192 + struct au_hinode *hinode __maybe_unused,
19193 + struct inode *inode __maybe_unused)
19194 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
19195 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
19196 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
19197 + int do_set __maybe_unused)
19198 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
19199 + unsigned int flags __maybe_unused)
19200 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
19201 + struct au_branch *br __maybe_unused,
19202 + int perm __maybe_unused)
19203 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
19204 + int perm __maybe_unused)
19205 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
19206 +AuStubInt0(__init au_hnotify_init, void)
19207 +AuStubVoid(au_hnotify_fin, void)
19208 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
19209 +#endif /* CONFIG_AUFS_HNOTIFY */
19211 +static inline void au_hn_suspend(struct au_hinode *hdir)
19213 + au_hn_ctl(hdir, /*do_set*/0);
19216 +static inline void au_hn_resume(struct au_hinode *hdir)
19218 + au_hn_ctl(hdir, /*do_set*/1);
19221 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
19223 + inode_lock(hdir->hi_inode);
19224 + au_hn_suspend(hdir);
19227 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
19228 + unsigned int sc __maybe_unused)
19230 + inode_lock_nested(hdir->hi_inode, sc);
19231 + au_hn_suspend(hdir);
19234 +#if 0 /* unused */
19235 +#include "vfsub.h"
19236 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
19239 + inode_lock_shared_nested(hdir->hi_inode, sc);
19240 + au_hn_suspend(hdir);
19244 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
19246 + au_hn_resume(hdir);
19247 + inode_unlock(hdir->hi_inode);
19250 +#endif /* __KERNEL__ */
19251 +#endif /* __AUFS_INODE_H__ */
19252 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
19253 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
19254 +++ linux/fs/aufs/ioctl.c 2021-12-03 15:38:59.936647310 +0100
19256 +// SPDX-License-Identifier: GPL-2.0
19258 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19260 + * This program, aufs is free software; you can redistribute it and/or modify
19261 + * it under the terms of the GNU General Public License as published by
19262 + * the Free Software Foundation; either version 2 of the License, or
19263 + * (at your option) any later version.
19265 + * This program is distributed in the hope that it will be useful,
19266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19268 + * GNU General Public License for more details.
19270 + * You should have received a copy of the GNU General Public License
19271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19276 + * plink-management and readdir in userspace.
19277 + * assist the pathconf(3) wrapper library.
19279 + * File-based Hierarchical Storage Management.
19282 +#include <linux/compat.h>
19283 +#include <linux/file.h>
19286 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
19289 + aufs_bindex_t wbi, bindex, bbot;
19290 + struct file *h_file;
19291 + struct super_block *sb;
19292 + struct dentry *root;
19293 + struct au_branch *br;
19294 + struct aufs_wbr_fd wbrfd = {
19295 + .oflags = au_dir_roflags,
19298 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
19299 + | O_NOATIME | O_CLOEXEC;
19301 + AuDebugOn(wbrfd.oflags & ~valid);
19304 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
19305 + if (unlikely(err)) {
19311 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
19312 + wbrfd.oflags |= au_dir_roflags;
19313 + AuDbg("0%o\n", wbrfd.oflags);
19314 + if (unlikely(wbrfd.oflags & ~valid))
19318 + fd = get_unused_fd_flags(0);
19320 + if (unlikely(fd < 0))
19323 + h_file = ERR_PTR(-EINVAL);
19326 + sb = path->dentry->d_sb;
19327 + root = sb->s_root;
19328 + aufs_read_lock(root, AuLock_IR);
19329 + bbot = au_sbbot(sb);
19330 + if (wbrfd.brid >= 0) {
19331 + wbi = au_br_index(sb, wbrfd.brid);
19332 + if (unlikely(wbi < 0 || wbi > bbot))
19336 + h_file = ERR_PTR(-ENOENT);
19337 + br = au_sbr(sb, wbi);
19338 + if (!au_br_writable(br->br_perm)) {
19342 + bindex = wbi + 1;
19344 + for (; bindex <= bbot; bindex++) {
19345 + br = au_sbr(sb, bindex);
19346 + if (au_br_writable(br->br_perm)) {
19348 + br = au_sbr(sb, wbi);
19353 + AuDbg("wbi %d\n", wbi);
19355 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
19359 + aufs_read_unlock(root, AuLock_IR);
19360 + err = PTR_ERR(h_file);
19361 + if (IS_ERR(h_file))
19364 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
19365 + fd_install(fd, h_file);
19367 + goto out; /* success */
19370 + put_unused_fd(fd);
19376 +/* ---------------------------------------------------------------------- */
19378 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
19381 + struct dentry *dentry;
19384 + case AUFS_CTL_RDU:
19385 + case AUFS_CTL_RDU_INO:
19386 + err = au_rdu_ioctl(file, cmd, arg);
19389 + case AUFS_CTL_WBR_FD:
19390 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19393 + case AUFS_CTL_IBUSY:
19394 + err = au_ibusy_ioctl(file, arg);
19397 + case AUFS_CTL_BRINFO:
19398 + err = au_brinfo_ioctl(file, arg);
19401 + case AUFS_CTL_FHSM_FD:
19402 + dentry = file->f_path.dentry;
19403 + if (IS_ROOT(dentry))
19404 + err = au_fhsm_fd(dentry->d_sb, arg);
19410 + /* do not call the lower */
19411 + AuDbg("0x%x\n", cmd);
19419 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
19424 + case AUFS_CTL_MVDOWN:
19425 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
19428 + case AUFS_CTL_WBR_FD:
19429 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
19433 + /* do not call the lower */
19434 + AuDbg("0x%x\n", cmd);
19442 +#ifdef CONFIG_COMPAT
19443 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
19444 + unsigned long arg)
19449 + case AUFS_CTL_RDU:
19450 + case AUFS_CTL_RDU_INO:
19451 + err = au_rdu_compat_ioctl(file, cmd, arg);
19454 + case AUFS_CTL_IBUSY:
19455 + err = au_ibusy_compat_ioctl(file, arg);
19458 + case AUFS_CTL_BRINFO:
19459 + err = au_brinfo_compat_ioctl(file, arg);
19463 + err = aufs_ioctl_dir(file, cmd, arg);
19470 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
19471 + unsigned long arg)
19473 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
19476 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
19477 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
19478 +++ linux/fs/aufs/i_op_add.c 2021-12-03 15:38:59.936647310 +0100
19480 +// SPDX-License-Identifier: GPL-2.0
19482 + * Copyright (C) 2005-2021 Junjiro R. Okajima
19484 + * This program, aufs is free software; you can redistribute it and/or modify
19485 + * it under the terms of the GNU General Public License as published by
19486 + * the Free Software Foundation; either version 2 of the License, or
19487 + * (at your option) any later version.
19489 + * This program is distributed in the hope that it will be useful,
19490 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19491 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19492 + * GNU General Public License for more details.
19494 + * You should have received a copy of the GNU General Public License
19495 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19499 + * inode operations (add entry)
19502 +#include <linux/iversion.h>
19506 + * final procedure of adding a new entry, except link(2).
19507 + * remove whiteout, instantiate, copyup the parent dir's times and size
19508 + * and update version.
19509 + * if it failed, re-create the removed whiteout.
19511 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
19512 + struct dentry *wh_dentry, struct dentry *dentry)
19515 + aufs_bindex_t bwh;
19516 + struct path h_path;
19517 + struct super_block *sb;
19518 + struct inode *inode, *h_dir;
19519 + struct dentry *wh;
19524 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
19525 + IMustLock(h_dir);
19526 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
19527 + bwh = au_dbwh(dentry);
19528 + h_path.dentry = wh_dentry;
19529 + h_path.mnt = au_sbr_mnt(sb, bindex);
19530 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
19532 + if (unlikely(err))
19536 + inode = au_new_inode(dentry, /*must_new*/1);
19537 + if (!IS_ERR(inode)) {
19538 + d_instantiate(dentry, inode);
19539 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
19541 + au_dir_ts(dir, bindex);
19542 + inode_inc_iversion(dir);
19543 + au_fhsm_wrote(sb, bindex, /*force*/0);
19544 + return 0; /* success */
19547 + err = PTR_ERR(inode);
19552 + /* dir inode is locked */
19553 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
19554 + rerr = PTR_ERR(wh);
19555 + if (IS_ERR(wh)) {
19556 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
19557 + dentry, err, rerr);
19566 +static int au_d_may_add(struct dentry *dentry)
19571 + if (unlikely(d_unhashed(dentry)))
19573 + if (unlikely(d_really_is_positive(dentry)))
19579 + * simple tests for the adding inode operations.
19580 + * following the checks in vfs, plus the parent-child relationship.
19582 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
19583 + struct dentry *h_parent, int isdir)
19587 + struct dentry *h_dentry;
19588 + struct inode *h_inode;
19590 + err = -ENAMETOOLONG;
19591 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19594 + h_dentry = au_h_dptr(dentry, bindex);
19595 + if (d_really_is_negative(dentry)) {
19597 + if (unlikely(d_is_positive(h_dentry)))
19600 + /* rename(2) case */
19602 + if (unlikely(d_is_negative(h_dentry)))
19604 + h_inode = d_inode(h_dentry);
19605 + if (unlikely(!h_inode->i_nlink))
19608 + h_mode = h_inode->i_mode;
19611 + if (unlikely(S_ISDIR(h_mode)))
19613 + } else if (unlikely(!S_ISDIR(h_mode))) {
19620 + /* expected parent dir is locked */
19621 + if (unlikely(h_parent != h_dentry->d_parent))
19630 + * initial procedure of adding a new entry.
19631 + * prepare writable branch and the parent dir, lock it,
19632 + * and lookup whiteout for the new entry.
19634 +static struct dentry*
19635 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
19636 + struct dentry *src_dentry, struct au_pin *pin,
19637 + struct au_wr_dir_args *wr_dir_args)
19639 + struct dentry *wh_dentry, *h_parent;
19640 + struct super_block *sb;
19641 + struct au_branch *br;
19643 + unsigned int udba;
19644 + aufs_bindex_t bcpup;
19646 + AuDbg("%pd\n", dentry);
19648 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
19650 + wh_dentry = ERR_PTR(err);
19651 + if (unlikely(err < 0))
19654 + sb = dentry->d_sb;
19655 + udba = au_opt_udba(sb);
19656 + err = au_pin(pin, dentry, bcpup, udba,
19657 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19658 + wh_dentry = ERR_PTR(err);
19659 + if (unlikely(err))
19662 + h_parent = au_pinned_h_parent(pin);
19663 + if (udba != AuOpt_UDBA_NONE
19664 + && au_dbtop(dentry) == bcpup)
19665 + err = au_may_add(dentry, bcpup, h_parent,
19666 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
19667 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
19668 + err = -ENAMETOOLONG;
19669 + wh_dentry = ERR_PTR(err);
19670 + if (unlikely(err))
19673 + br = au_sbr(sb, bcpup);
19675 + struct path tmp = {
19676 + .dentry = h_parent,
19677 + .mnt = au_br_mnt(br)
19679 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
19682 + wh_dentry = NULL;
19683 + if (bcpup != au_dbwh(dentry))
19684 + goto out; /* success */
19687 + * ENAMETOOLONG here means that if we allowed create such name, then it
19688 + * would not be able to removed in the future. So we don't allow such
19689 + * name here and we don't handle ENAMETOOLONG differently here.
19691 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
19694 + if (IS_ERR(wh_dentry))
19697 + return wh_dentry;
19700 +/* ---------------------------------------------------------------------- */
19702 +enum { Mknod, Symlink, Creat };
19703 +struct simple_arg {
19710 + struct vfsub_aopen_args *aopen;
19713 + const char *symname;
19722 +static int add_simple(struct inode *dir, struct dentry *dentry,
19723 + struct simple_arg *arg)
19726 + aufs_bindex_t btop;
19727 + unsigned char created;
19728 + const unsigned char try_aopen
19729 + = (arg->type == Creat && arg->u.c.try_aopen);
19730 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
19731 + struct dentry *wh_dentry, *parent;
19732 + struct inode *h_dir;
19733 + struct super_block *sb;
19734 + struct au_branch *br;
19735 + /* to reduce stack size */
19737 + struct au_dtime dt;
19738 + struct au_pin pin;
19739 + struct path h_path;
19740 + struct au_wr_dir_args wr_dir_args;
19743 + AuDbg("%pd\n", dentry);
19747 + a = kmalloc(sizeof(*a), GFP_NOFS);
19748 + if (unlikely(!a))
19750 + a->wr_dir_args.force_btgt = -1;
19751 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
19753 + parent = dentry->d_parent; /* dir inode is locked */
19754 + if (!try_aopen) {
19755 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19756 + if (unlikely(err))
19759 + err = au_d_may_add(dentry);
19760 + if (unlikely(err))
19763 + di_write_lock_parent(parent);
19764 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
19765 + &a->pin, &a->wr_dir_args);
19766 + err = PTR_ERR(wh_dentry);
19767 + if (IS_ERR(wh_dentry))
19770 + btop = au_dbtop(dentry);
19771 + sb = dentry->d_sb;
19772 + br = au_sbr(sb, btop);
19773 + a->h_path.dentry = au_h_dptr(dentry, btop);
19774 + a->h_path.mnt = au_br_mnt(br);
19775 + h_dir = au_pinned_h_dir(&a->pin);
19776 + switch (arg->type) {
19778 + if (!try_aopen || !h_dir->i_op->atomic_open) {
19779 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
19780 + arg->u.c.want_excl);
19782 + if (!err && try_aopen)
19783 + aopen->file->f_mode |= FMODE_CREATED;
19786 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
19787 + AuDbg("err %d\n", err);
19788 + AuDbgFile(aopen->file);
19789 + created = err >= 0
19790 + && !!(aopen->file->f_mode & FMODE_CREATED);
19794 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
19798 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
19805 + if (unlikely(err < 0))
19808 + err = epilog(dir, btop, wh_dentry, dentry);
19810 + goto out_unpin; /* success */
19813 + if (created /* && d_is_positive(a->h_path.dentry) */) {
19814 + /* no delegation since it is just created */
19815 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
19818 + AuIOErr("%pd revert failure(%d, %d)\n",
19819 + dentry, err, rerr);
19822 + au_dtime_revert(&a->dt);
19824 + if (try_aopen && h_dir->i_op->atomic_open
19825 + && (aopen->file->f_mode & FMODE_OPENED))
19826 + /* aopen->file is still opened */
19827 + au_lcnt_dec(&aopen->br->br_nfiles);
19830 + au_unpin(&a->pin);
19834 + di_write_unlock(parent);
19836 + if (unlikely(err)) {
19837 + au_update_dbtop(dentry);
19841 + aufs_read_unlock(dentry, AuLock_DW);
19848 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
19851 + struct simple_arg arg = {
19858 + return add_simple(dir, dentry, &arg);
19861 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
19863 + struct simple_arg arg = {
19865 + .u.s.symname = symname
19867 + return add_simple(dir, dentry, &arg);
19870 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
19873 + struct simple_arg arg = {
19877 + .want_excl = want_excl
19880 + return add_simple(dir, dentry, &arg);
19883 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
19884 + struct vfsub_aopen_args *aopen_args)
19886 + struct simple_arg arg = {
19889 + .mode = aopen_args->create_mode,
19890 + .want_excl = aopen_args->open_flag & O_EXCL,
19891 + .try_aopen = true,
19892 + .aopen = aopen_args
19895 + return add_simple(dir, dentry, &arg);
19898 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
19901 + aufs_bindex_t bindex;
19902 + struct super_block *sb;
19903 + struct dentry *parent, *h_parent, *h_dentry;
19904 + struct inode *h_dir, *inode;
19905 + struct vfsmount *h_mnt;
19906 + struct au_wr_dir_args wr_dir_args = {
19907 + .force_btgt = -1,
19908 + .flags = AuWrDir_TMPFILE
19911 + /* copy-up may happen */
19915 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19916 + if (unlikely(err))
19919 + err = au_di_init(dentry);
19920 + if (unlikely(err))
19924 + parent = d_find_any_alias(dir);
19925 + AuDebugOn(!parent);
19926 + di_write_lock_parent(parent);
19927 + if (unlikely(d_inode(parent) != dir))
19930 + err = au_digen_test(parent, au_sigen(sb));
19931 + if (unlikely(err))
19934 + bindex = au_dbtop(parent);
19935 + au_set_dbtop(dentry, bindex);
19936 + au_set_dbbot(dentry, bindex);
19937 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19939 + if (unlikely(err < 0))
19942 + err = -EOPNOTSUPP;
19943 + h_dir = au_h_iptr(dir, bindex);
19944 + if (unlikely(!h_dir->i_op->tmpfile))
19947 + h_mnt = au_sbr_mnt(sb, bindex);
19948 + err = vfsub_mnt_want_write(h_mnt);
19949 + if (unlikely(err))
19952 + h_parent = au_h_dptr(parent, bindex);
19953 + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0);
19954 + if (IS_ERR(h_dentry)) {
19955 + err = PTR_ERR(h_dentry);
19959 + au_set_dbtop(dentry, bindex);
19960 + au_set_dbbot(dentry, bindex);
19961 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
19962 + inode = au_new_inode(dentry, /*must_new*/1);
19963 + if (IS_ERR(inode)) {
19964 + err = PTR_ERR(inode);
19965 + au_set_h_dptr(dentry, bindex, NULL);
19966 + au_set_dbtop(dentry, -1);
19967 + au_set_dbbot(dentry, -1);
19969 + if (!inode->i_nlink)
19970 + set_nlink(inode, 1);
19971 + d_tmpfile(dentry, inode);
19972 + au_di(dentry)->di_tmpfile = 1;
19974 + /* update without i_mutex */
19975 + if (au_ibtop(dir) == au_dbtop(dentry))
19976 + au_cpup_attr_timesizes(dir);
19981 + vfsub_mnt_drop_write(h_mnt);
19983 + di_write_unlock(parent);
19985 + di_write_unlock(dentry);
19986 + if (unlikely(err)) {
19987 + au_di_fin(dentry);
19988 + dentry->d_fsdata = NULL;
19991 + si_read_unlock(sb);
19993 + inode_unlock(dir);
19997 +/* ---------------------------------------------------------------------- */
19999 +struct au_link_args {
20000 + aufs_bindex_t bdst, bsrc;
20001 + struct au_pin pin;
20002 + struct path h_path;
20003 + struct dentry *src_parent, *parent;
20006 +static int au_cpup_before_link(struct dentry *src_dentry,
20007 + struct au_link_args *a)
20010 + struct dentry *h_src_dentry;
20011 + struct au_cp_generic cpg = {
20012 + .dentry = src_dentry,
20017 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
20020 + di_read_lock_parent(a->src_parent, AuLock_IR);
20021 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
20022 + if (unlikely(err))
20025 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
20026 + err = au_pin(&a->pin, src_dentry, a->bdst,
20027 + au_opt_udba(src_dentry->d_sb),
20028 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20029 + if (unlikely(err))
20032 + err = au_sio_cpup_simple(&cpg);
20033 + au_unpin(&a->pin);
20036 + di_read_unlock(a->src_parent, AuLock_IR);
20040 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
20041 + struct au_link_args *a)
20044 + unsigned char plink;
20045 + aufs_bindex_t bbot;
20046 + struct dentry *h_src_dentry;
20047 + struct inode *h_inode, *inode, *delegated;
20048 + struct super_block *sb;
20049 + struct file *h_file;
20053 + sb = src_dentry->d_sb;
20054 + inode = d_inode(src_dentry);
20055 + if (au_ibtop(inode) <= a->bdst)
20056 + h_inode = au_h_iptr(inode, a->bdst);
20057 + if (!h_inode || !h_inode->i_nlink) {
20058 + /* copyup src_dentry as the name of dentry. */
20059 + bbot = au_dbbot(dentry);
20060 + if (bbot < a->bsrc)
20061 + au_set_dbbot(dentry, a->bsrc);
20062 + au_set_h_dptr(dentry, a->bsrc,
20063 + dget(au_h_dptr(src_dentry, a->bsrc)));
20064 + dget(a->h_path.dentry);
20065 + au_set_h_dptr(dentry, a->bdst, NULL);
20066 + AuDbg("temporary d_inode...\n");
20067 + spin_lock(&dentry->d_lock);
20068 + dentry->d_inode = d_inode(src_dentry); /* tmp */
20069 + spin_unlock(&dentry->d_lock);
20070 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
20071 + if (IS_ERR(h_file))
20072 + err = PTR_ERR(h_file);
20074 + struct au_cp_generic cpg = {
20075 + .dentry = dentry,
20080 + .flags = AuCpup_KEEPLINO
20082 + err = au_sio_cpup_simple(&cpg);
20083 + au_h_open_post(dentry, a->bsrc, h_file);
20085 + dput(a->h_path.dentry);
20086 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20088 + au_set_h_dptr(dentry, a->bdst,
20089 + a->h_path.dentry);
20091 + spin_lock(&dentry->d_lock);
20092 + dentry->d_inode = NULL; /* restore */
20093 + spin_unlock(&dentry->d_lock);
20094 + AuDbg("temporary d_inode...done\n");
20095 + au_set_h_dptr(dentry, a->bsrc, NULL);
20096 + au_set_dbbot(dentry, bbot);
20098 + /* the inode of src_dentry already exists on a.bdst branch */
20099 + h_src_dentry = d_find_alias(h_inode);
20100 + if (!h_src_dentry && au_plink_test(inode)) {
20102 + h_src_dentry = au_plink_lkup(inode, a->bdst);
20103 + err = PTR_ERR(h_src_dentry);
20104 + if (IS_ERR(h_src_dentry))
20107 + if (unlikely(d_is_negative(h_src_dentry))) {
20108 + dput(h_src_dentry);
20109 + h_src_dentry = NULL;
20113 + if (h_src_dentry) {
20114 + delegated = NULL;
20115 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20116 + &a->h_path, &delegated);
20117 + if (unlikely(err == -EWOULDBLOCK)) {
20118 + pr_warn("cannot retry for NFSv4 delegation"
20119 + " for an internal link\n");
20122 + dput(h_src_dentry);
20124 + AuIOErr("no dentry found for hi%lu on b%d\n",
20125 + h_inode->i_ino, a->bdst);
20130 + if (!err && !plink)
20131 + au_plink_append(inode, a->bdst, a->h_path.dentry);
20138 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20139 + struct dentry *dentry)
20142 + struct au_dtime dt;
20143 + struct au_link_args *a;
20144 + struct dentry *wh_dentry, *h_src_dentry;
20145 + struct inode *inode, *delegated;
20146 + struct super_block *sb;
20147 + struct au_wr_dir_args wr_dir_args = {
20148 + /* .force_btgt = -1, */
20149 + .flags = AuWrDir_ADD_ENTRY
20153 + inode = d_inode(src_dentry);
20154 + IMustLock(inode);
20157 + a = kzalloc(sizeof(*a), GFP_NOFS);
20158 + if (unlikely(!a))
20161 + a->parent = dentry->d_parent; /* dir inode is locked */
20162 + err = aufs_read_and_write_lock2(dentry, src_dentry,
20163 + AuLock_NOPLM | AuLock_GEN);
20164 + if (unlikely(err))
20166 + err = au_d_linkable(src_dentry);
20167 + if (unlikely(err))
20169 + err = au_d_may_add(dentry);
20170 + if (unlikely(err))
20173 + a->src_parent = dget_parent(src_dentry);
20174 + wr_dir_args.force_btgt = au_ibtop(inode);
20176 + di_write_lock_parent(a->parent);
20177 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
20178 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
20180 + err = PTR_ERR(wh_dentry);
20181 + if (IS_ERR(wh_dentry))
20185 + sb = dentry->d_sb;
20186 + a->bdst = au_dbtop(dentry);
20187 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
20188 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
20189 + a->bsrc = au_ibtop(inode);
20190 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20191 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
20192 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
20193 + if (!h_src_dentry) {
20194 + a->bsrc = au_dbtop(src_dentry);
20195 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
20196 + AuDebugOn(!h_src_dentry);
20197 + } else if (IS_ERR(h_src_dentry)) {
20198 + err = PTR_ERR(h_src_dentry);
20203 + * aufs doesn't touch the credential so
20204 + * security_dentry_create_files_as() is unnecessary.
20206 + if (au_opt_test(au_mntflags(sb), PLINK)) {
20207 + if (a->bdst < a->bsrc
20208 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
20209 + err = au_cpup_or_link(src_dentry, dentry, a);
20211 + delegated = NULL;
20212 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
20213 + &a->h_path, &delegated);
20214 + if (unlikely(err == -EWOULDBLOCK)) {
20215 + pr_warn("cannot retry for NFSv4 delegation"
20216 + " for an internal link\n");
20220 + dput(h_src_dentry);
20223 + * copyup src_dentry to the branch we process,
20224 + * and then link(2) to it.
20226 + dput(h_src_dentry);
20227 + if (a->bdst < a->bsrc
20228 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
20229 + au_unpin(&a->pin);
20230 + di_write_unlock(a->parent);
20231 + err = au_cpup_before_link(src_dentry, a);
20232 + di_write_lock_parent(a->parent);
20234 + err = au_pin(&a->pin, dentry, a->bdst,
20236 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20237 + if (unlikely(err))
20241 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
20243 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
20244 + delegated = NULL;
20245 + err = vfsub_link(h_src_dentry,
20246 + au_pinned_h_dir(&a->pin),
20247 + &a->h_path, &delegated);
20248 + if (unlikely(err == -EWOULDBLOCK)) {
20249 + pr_warn("cannot retry"
20250 + " for NFSv4 delegation"
20251 + " for an internal link\n");
20257 + if (unlikely(err))
20261 + a->h_path.dentry = wh_dentry;
20262 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
20264 + if (unlikely(err))
20268 + au_dir_ts(dir, a->bdst);
20269 + inode_inc_iversion(dir);
20270 + inc_nlink(inode);
20271 + inode->i_ctime = dir->i_ctime;
20272 + d_instantiate(dentry, au_igrab(inode));
20273 + if (d_unhashed(a->h_path.dentry))
20274 + /* some filesystem calls d_drop() */
20276 + /* some filesystems consume an inode even hardlink */
20277 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
20278 + goto out_unpin; /* success */
20281 + /* no delegation since it is just created */
20282 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
20283 + /*delegated*/NULL, /*force*/0);
20284 + if (unlikely(rerr)) {
20285 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
20288 + au_dtime_revert(&dt);
20290 + au_unpin(&a->pin);
20294 + di_write_unlock(a->parent);
20295 + dput(a->src_parent);
20297 + if (unlikely(err)) {
20298 + au_update_dbtop(dentry);
20301 + aufs_read_and_write_unlock2(dentry, src_dentry);
20309 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
20312 + aufs_bindex_t bindex;
20313 + unsigned char diropq;
20314 + struct path h_path;
20315 + struct dentry *wh_dentry, *parent, *opq_dentry;
20316 + struct inode *h_inode;
20317 + struct super_block *sb;
20319 + struct au_pin pin;
20320 + struct au_dtime dt;
20321 + } *a; /* reduce the stack usage */
20322 + struct au_wr_dir_args wr_dir_args = {
20323 + .force_btgt = -1,
20324 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
20330 + a = kmalloc(sizeof(*a), GFP_NOFS);
20331 + if (unlikely(!a))
20334 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20335 + if (unlikely(err))
20337 + err = au_d_may_add(dentry);
20338 + if (unlikely(err))
20341 + parent = dentry->d_parent; /* dir inode is locked */
20342 + di_write_lock_parent(parent);
20343 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
20344 + &a->pin, &wr_dir_args);
20345 + err = PTR_ERR(wh_dentry);
20346 + if (IS_ERR(wh_dentry))
20349 + sb = dentry->d_sb;
20350 + bindex = au_dbtop(dentry);
20351 + h_path.dentry = au_h_dptr(dentry, bindex);
20352 + h_path.mnt = au_sbr_mnt(sb, bindex);
20353 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
20354 + if (unlikely(err))
20357 + /* make the dir opaque */
20359 + h_inode = d_inode(h_path.dentry);
20361 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
20362 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20363 + opq_dentry = au_diropq_create(dentry, bindex);
20364 + inode_unlock(h_inode);
20365 + err = PTR_ERR(opq_dentry);
20366 + if (IS_ERR(opq_dentry))
20368 + dput(opq_dentry);
20372 + err = epilog(dir, bindex, wh_dentry, dentry);
20375 + goto out_unpin; /* success */
20380 + AuLabel(revert opq);
20381 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
20382 + rerr = au_diropq_remove(dentry, bindex);
20383 + inode_unlock(h_inode);
20385 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
20386 + dentry, err, rerr);
20392 + AuLabel(revert dir);
20393 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
20395 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
20396 + dentry, err, rerr);
20399 + au_dtime_revert(&a->dt);
20401 + au_unpin(&a->pin);
20404 + di_write_unlock(parent);
20406 + if (unlikely(err)) {
20407 + au_update_dbtop(dentry);
20410 + aufs_read_unlock(dentry, AuLock_DW);
20416 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
20417 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
20418 +++ linux/fs/aufs/i_op.c 2021-12-03 15:38:59.936647310 +0100
20420 +// SPDX-License-Identifier: GPL-2.0
20422 + * Copyright (C) 2005-2021 Junjiro R. Okajima
20424 + * This program, aufs is free software; you can redistribute it and/or modify
20425 + * it under the terms of the GNU General Public License as published by
20426 + * the Free Software Foundation; either version 2 of the License, or
20427 + * (at your option) any later version.
20429 + * This program is distributed in the hope that it will be useful,
20430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20432 + * GNU General Public License for more details.
20434 + * You should have received a copy of the GNU General Public License
20435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20439 + * inode operations (except add/del/rename)
20442 +#include <linux/device_cgroup.h>
20443 +#include <linux/fs_stack.h>
20444 +#include <linux/iversion.h>
20445 +#include <linux/namei.h>
20446 +#include <linux/security.h>
20449 +static int h_permission(struct inode *h_inode, int mask,
20450 + struct path *h_path, int brperm)
20453 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20456 + if (write_mask && IS_IMMUTABLE(h_inode))
20460 + if (((mask & MAY_EXEC)
20461 + && S_ISREG(h_inode->i_mode)
20462 + && (path_noexec(h_path)
20463 + || !(h_inode->i_mode & 0111))))
20467 + * - skip the lower fs test in the case of write to ro branch.
20468 + * - nfs dir permission write check is optimized, but a policy for
20469 + * link/rename requires a real check.
20470 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
20471 + * in this case, generic_permission() returns -EOPNOTSUPP.
20473 + if ((write_mask && !au_br_writable(brperm))
20474 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
20475 + && write_mask && !(mask & MAY_READ))
20476 + || !h_inode->i_op->permission) {
20477 + /* AuLabel(generic_permission); */
20478 + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */
20479 + err = generic_permission(h_inode, mask);
20480 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
20481 + err = h_inode->i_op->permission(h_inode, mask);
20484 + /* AuLabel(h_inode->permission); */
20485 + err = h_inode->i_op->permission(h_inode, mask);
20490 + err = devcgroup_inode_permission(h_inode, mask);
20492 + err = security_inode_permission(h_inode, mask);
20498 +static int aufs_permission(struct inode *inode, int mask)
20501 + aufs_bindex_t bindex, bbot;
20502 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
20503 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
20504 + struct inode *h_inode;
20505 + struct super_block *sb;
20506 + struct au_branch *br;
20508 + /* todo: support rcu-walk? */
20509 + if (mask & MAY_NOT_BLOCK)
20512 + sb = inode->i_sb;
20513 + si_read_lock(sb, AuLock_FLUSH);
20514 + ii_read_lock_child(inode);
20515 +#if 0 /* reserved for future use */
20517 + * This test may be rather 'too much' since the test is essentially done
20518 + * in the aufs_lookup(). Theoretically it is possible that the inode
20519 + * generation doesn't match to the superblock's here. But it isn't a
20520 + * big deal I suppose.
20522 + err = au_iigen_test(inode, au_sigen(sb));
20523 + if (unlikely(err))
20529 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
20530 + err = au_busy_or_stale();
20531 + h_inode = au_h_iptr(inode, au_ibtop(inode));
20532 + if (unlikely(!h_inode
20533 + || (h_inode->i_mode & S_IFMT)
20534 + != (inode->i_mode & S_IFMT)))
20538 + bindex = au_ibtop(inode);
20539 + br = au_sbr(sb, bindex);
20540 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
20543 + && !special_file(h_inode->i_mode)) {
20544 + /* test whether the upper writable branch exists */
20546 + for (; bindex >= 0; bindex--)
20547 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
20555 + /* non-write to dir */
20557 + bbot = au_ibbot(inode);
20558 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
20559 + h_inode = au_h_iptr(inode, bindex);
20561 + err = au_busy_or_stale();
20562 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
20565 + br = au_sbr(sb, bindex);
20566 + err = h_permission(h_inode, mask, &br->br_path,
20572 + ii_read_unlock(inode);
20573 + si_read_unlock(sb);
20577 +/* ---------------------------------------------------------------------- */
20579 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
20580 + unsigned int flags)
20582 + struct dentry *ret, *parent;
20583 + struct inode *inode;
20584 + struct super_block *sb;
20585 + int err, npositive;
20589 + /* todo: support rcu-walk? */
20590 + ret = ERR_PTR(-ECHILD);
20591 + if (flags & LOOKUP_RCU)
20594 + ret = ERR_PTR(-ENAMETOOLONG);
20595 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20599 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
20600 + ret = ERR_PTR(err);
20601 + if (unlikely(err))
20604 + err = au_di_init(dentry);
20605 + ret = ERR_PTR(err);
20606 + if (unlikely(err))
20610 + npositive = 0; /* suppress a warning */
20611 + parent = dentry->d_parent; /* dir inode is locked */
20612 + di_read_lock_parent(parent, AuLock_IR);
20613 + err = au_alive_dir(parent);
20615 + err = au_digen_test(parent, au_sigen(sb));
20617 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
20618 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
20619 + AuLkup_ALLOW_NEG);
20622 + di_read_unlock(parent, AuLock_IR);
20623 + ret = ERR_PTR(err);
20624 + if (unlikely(err < 0))
20628 + inode = au_new_inode(dentry, /*must_new*/0);
20629 + if (IS_ERR(inode)) {
20630 + ret = (void *)inode;
20637 + atomic_inc(&inode->i_count);
20638 + ret = d_splice_alias(inode, dentry);
20639 +#if 0 /* reserved for future use */
20640 + if (unlikely(d_need_lookup(dentry))) {
20641 + spin_lock(&dentry->d_lock);
20642 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
20643 + spin_unlock(&dentry->d_lock);
20647 + if (!IS_ERR(ret)) {
20649 + if (ret && ret != dentry)
20650 + ii_write_unlock(inode);
20652 + ii_write_unlock(inode);
20659 + di_write_unlock(dentry);
20661 + si_read_unlock(sb);
20666 +/* ---------------------------------------------------------------------- */
20669 + * very dirty and complicated aufs ->atomic_open().
20670 + * aufs_atomic_open()
20671 + * + au_aopen_or_create()
20673 + * + vfsub_atomic_open()
20674 + * + branch fs ->atomic_open()
20675 + * may call the actual 'open' for h_file
20676 + * + inc br_nfiles only if opened
20677 + * + au_aopen_no_open() or au_aopen_do_open()
20679 + * au_aopen_do_open()
20680 + * + finish_open()
20681 + * + au_do_aopen()
20682 + * + au_do_open() the body of all 'open'
20683 + * + au_do_open_nondir()
20684 + * set the passed h_file
20686 + * au_aopen_no_open()
20687 + * + finish_no_open()
20690 +struct aopen_node {
20691 + struct hlist_bl_node hblist;
20692 + struct file *file, *h_file;
20695 +static int au_do_aopen(struct inode *inode, struct file *file)
20697 + struct hlist_bl_head *aopen;
20698 + struct hlist_bl_node *pos;
20699 + struct aopen_node *node;
20700 + struct au_do_open_args args = {
20702 + .open = au_do_open_nondir
20705 + aopen = &au_sbi(inode->i_sb)->si_aopen;
20706 + hlist_bl_lock(aopen);
20707 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
20708 + if (node->file == file) {
20709 + args.h_file = node->h_file;
20712 + hlist_bl_unlock(aopen);
20713 + /* AuDebugOn(!args.h_file); */
20715 + return au_do_open(file, &args);
20718 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
20719 + struct aopen_node *aopen_node)
20722 + struct hlist_bl_head *aopen;
20725 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
20726 + au_hbl_add(&aopen_node->hblist, aopen);
20727 + err = finish_open(file, dentry, au_do_aopen);
20728 + au_hbl_del(&aopen_node->hblist, aopen);
20729 + /* AuDbgFile(file); */
20730 + AuDbg("%pd%s%s\n", dentry,
20731 + (file->f_mode & FMODE_CREATED) ? " created" : "",
20732 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
20738 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
20744 + err = finish_no_open(file, dentry);
20750 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
20751 + struct file *file, unsigned int open_flag,
20752 + umode_t create_mode)
20754 + int err, did_open;
20755 + unsigned int lkup_flags;
20756 + aufs_bindex_t bindex;
20757 + struct super_block *sb;
20758 + struct dentry *parent, *d;
20759 + struct vfsub_aopen_args args = {
20760 + .open_flag = open_flag,
20761 + .create_mode = create_mode
20763 + struct aopen_node aopen_node = {
20768 + AuDbg("open_flag 0%o\n", open_flag);
20769 + AuDbgDentry(dentry);
20772 + if (!au_di(dentry)) {
20773 + lkup_flags = LOOKUP_OPEN;
20774 + if (open_flag & O_CREAT)
20775 + lkup_flags |= LOOKUP_CREATE;
20776 + d = aufs_lookup(dir, dentry, lkup_flags);
20778 + err = PTR_ERR(d);
20783 + * obsoleted dentry found.
20784 + * another error will be returned later.
20790 + AuDbgDentry(dentry);
20793 + if (d_is_positive(dentry)
20794 + || d_unhashed(dentry)
20795 + || d_unlinked(dentry)
20796 + || !(open_flag & O_CREAT)) {
20797 + err = au_aopen_no_open(file, dentry);
20798 + goto out; /* success */
20801 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20802 + if (unlikely(err))
20805 + sb = dentry->d_sb;
20806 + parent = dentry->d_parent; /* dir is locked */
20807 + di_write_lock_parent(parent);
20808 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
20809 + if (unlikely(err < 0))
20812 + AuDbgDentry(dentry);
20813 + if (d_is_positive(dentry)) {
20814 + err = au_aopen_no_open(file, dentry);
20815 + goto out_parent; /* success */
20818 + args.file = alloc_empty_file(file->f_flags, current_cred());
20819 + err = PTR_ERR(args.file);
20820 + if (IS_ERR(args.file))
20823 + bindex = au_dbtop(dentry);
20824 + err = au_aopen_or_create(dir, dentry, &args);
20826 + AuDbgFile(args.file);
20827 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
20828 + did_open = !!(args.file->f_mode & FMODE_OPENED);
20831 + args.file = NULL;
20833 + di_write_unlock(parent);
20834 + di_write_unlock(dentry);
20835 + if (unlikely(err < 0)) {
20842 + err = au_aopen_no_open(file, dentry);
20844 + aopen_node.h_file = args.file;
20845 + err = au_aopen_do_open(file, dentry, &aopen_node);
20847 + if (unlikely(err < 0)) {
20851 + au_lcnt_dec(&args.br->br_nfiles);
20853 + goto out_sb; /* success */
20856 + di_write_unlock(parent);
20857 + di_write_unlock(dentry);
20859 + si_read_unlock(sb);
20867 +/* ---------------------------------------------------------------------- */
20869 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
20870 + const unsigned char add_entry, aufs_bindex_t bcpup,
20871 + aufs_bindex_t btop)
20874 + struct dentry *h_parent;
20875 + struct inode *h_dir;
20878 + IMustLock(d_inode(parent));
20880 + di_write_lock_parent(parent);
20883 + if (!au_h_dptr(parent, bcpup)) {
20884 + if (btop > bcpup)
20885 + err = au_cpup_dirs(dentry, bcpup);
20886 + else if (btop < bcpup)
20887 + err = au_cpdown_dirs(dentry, bcpup);
20891 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
20892 + h_parent = au_h_dptr(parent, bcpup);
20893 + h_dir = d_inode(h_parent);
20894 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
20895 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
20896 + /* todo: no unlock here */
20897 + inode_unlock_shared(h_dir);
20899 + AuDbg("bcpup %d\n", bcpup);
20901 + if (d_really_is_negative(dentry))
20902 + au_set_h_dptr(dentry, btop, NULL);
20903 + au_update_dbrange(dentry, /*do_put_zero*/0);
20908 + di_write_unlock(parent);
20910 + err = bcpup; /* success */
20917 + * decide the branch and the parent dir where we will create a new entry.
20918 + * returns new bindex or an error.
20919 + * copyup the parent dir if needed.
20921 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20922 + struct au_wr_dir_args *args)
20925 + unsigned int flags;
20926 + aufs_bindex_t bcpup, btop, src_btop;
20927 + const unsigned char add_entry
20928 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
20929 + | au_ftest_wrdir(args->flags, TMPFILE);
20930 + struct super_block *sb;
20931 + struct dentry *parent;
20932 + struct au_sbinfo *sbinfo;
20934 + sb = dentry->d_sb;
20935 + sbinfo = au_sbi(sb);
20936 + parent = dget_parent(dentry);
20937 + btop = au_dbtop(dentry);
20939 + if (args->force_btgt < 0) {
20940 + if (src_dentry) {
20941 + src_btop = au_dbtop(src_dentry);
20942 + if (src_btop < btop)
20943 + bcpup = src_btop;
20944 + } else if (add_entry) {
20946 + if (au_ftest_wrdir(args->flags, ISDIR))
20947 + au_fset_wbr(flags, DIR);
20948 + err = AuWbrCreate(sbinfo, dentry, flags);
20952 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
20954 + err = AuWbrCopyup(sbinfo, dentry);
20956 + if (!IS_ROOT(dentry)) {
20957 + di_read_lock_parent(parent, !AuLock_IR);
20958 + err = AuWbrCopyup(sbinfo, dentry);
20959 + di_read_unlock(parent, !AuLock_IR);
20961 + err = AuWbrCopyup(sbinfo, dentry);
20964 + if (unlikely(err < 0))
20968 + bcpup = args->force_btgt;
20969 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
20972 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
20974 + if (bcpup == btop)
20975 + goto out; /* success */
20977 + /* copyup the new parent into the branch we process */
20978 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
20980 + if (d_really_is_negative(dentry)) {
20981 + au_set_h_dptr(dentry, btop, NULL);
20982 + au_set_dbtop(dentry, bcpup);
20983 + au_set_dbbot(dentry, bcpup);
20985 + AuDebugOn(add_entry
20986 + && !au_ftest_wrdir(args->flags, TMPFILE)
20987 + && !au_h_dptr(dentry, bcpup));
20995 +/* ---------------------------------------------------------------------- */
20997 +void au_pin_hdir_unlock(struct au_pin *p)
21000 + au_hn_inode_unlock(p->hdir);
21003 +int au_pin_hdir_lock(struct au_pin *p)
21011 + /* even if an error happens later, keep this lock */
21012 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
21015 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
21020 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
21021 + p->h_parent, p->br);
21027 +int au_pin_hdir_relock(struct au_pin *p)
21030 + struct inode *h_i;
21031 + struct dentry *h_d[] = {
21036 + err = au_pin_hdir_lock(p);
21037 + if (unlikely(err))
21040 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
21043 + if (d_is_positive(h_d[i])) {
21044 + h_i = d_inode(h_d[i]);
21045 + err = !h_i->i_nlink;
21053 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
21055 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
21058 +void au_pin_hdir_acquire_nest(struct au_pin *p)
21061 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
21062 + p->lsc_hi, 0, NULL, _RET_IP_);
21063 + au_pin_hdir_set_owner(p, current);
21067 +void au_pin_hdir_release(struct au_pin *p)
21070 + au_pin_hdir_set_owner(p, p->task);
21071 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
21075 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
21077 + if (pin && pin->parent)
21078 + return au_h_dptr(pin->parent, pin->bindex);
21082 +void au_unpin(struct au_pin *p)
21085 + au_pin_hdir_unlock(p);
21086 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
21087 + vfsub_mnt_drop_write(p->h_mnt);
21091 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21092 + di_read_unlock(p->parent, AuLock_IR);
21093 + iput(p->hdir->hi_inode);
21095 + p->parent = NULL;
21098 + /* do not clear p->task */
21101 +int au_do_pin(struct au_pin *p)
21104 + struct super_block *sb;
21105 + struct inode *h_dir;
21108 + sb = p->dentry->d_sb;
21109 + p->br = au_sbr(sb, p->bindex);
21110 + if (IS_ROOT(p->dentry)) {
21111 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21112 + p->h_mnt = au_br_mnt(p->br);
21113 + err = vfsub_mnt_want_write(p->h_mnt);
21114 + if (unlikely(err)) {
21115 + au_fclr_pin(p->flags, MNT_WRITE);
21122 + p->h_dentry = NULL;
21123 + if (p->bindex <= au_dbbot(p->dentry))
21124 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
21126 + p->parent = dget_parent(p->dentry);
21127 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21128 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
21131 + p->h_parent = au_h_dptr(p->parent, p->bindex);
21132 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
21134 + h_dir = p->hdir->hi_inode;
21138 + * if DI_LOCKED is not set, then p->parent may be different
21139 + * and h_parent can be NULL.
21141 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
21143 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21144 + di_read_unlock(p->parent, AuLock_IR);
21146 + p->parent = NULL;
21150 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
21151 + p->h_mnt = au_br_mnt(p->br);
21152 + err = vfsub_mnt_want_write(p->h_mnt);
21153 + if (unlikely(err)) {
21154 + au_fclr_pin(p->flags, MNT_WRITE);
21155 + if (!au_ftest_pin(p->flags, DI_LOCKED))
21156 + di_read_unlock(p->parent, AuLock_IR);
21158 + p->parent = NULL;
21164 + err = au_pin_hdir_lock(p);
21166 + goto out; /* success */
21171 + pr_err("err %d\n", err);
21172 + err = au_busy_or_stale();
21177 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
21178 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
21179 + unsigned int udba, unsigned char flags)
21181 + p->dentry = dentry;
21183 + p->lsc_di = lsc_di;
21184 + p->lsc_hi = lsc_hi;
21185 + p->flags = flags;
21186 + p->bindex = bindex;
21188 + p->parent = NULL;
21192 + p->h_dentry = NULL;
21193 + p->h_parent = NULL;
21195 + p->task = current;
21198 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
21199 + unsigned int udba, unsigned char flags)
21201 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
21203 + return au_do_pin(pin);
21206 +/* ---------------------------------------------------------------------- */
21209 + * ->setattr() and ->getattr() are called in various cases.
21210 + * chmod, stat: dentry is revalidated.
21211 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
21213 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
21215 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
21216 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
21219 + struct dentry *parent;
21222 + if (au_digen_test(dentry, sigen)) {
21223 + parent = dget_parent(dentry);
21224 + di_read_lock_parent(parent, AuLock_IR);
21225 + err = au_refresh_dentry(dentry, parent);
21226 + di_read_unlock(parent, AuLock_IR);
21234 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
21235 + struct au_icpup_args *a)
21239 + aufs_bindex_t btop, ibtop;
21240 + struct dentry *hi_wh, *parent;
21241 + struct inode *inode;
21242 + struct au_wr_dir_args wr_dir_args = {
21243 + .force_btgt = -1,
21247 + if (d_is_dir(dentry))
21248 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21249 + /* plink or hi_wh() case */
21250 + btop = au_dbtop(dentry);
21251 + inode = d_inode(dentry);
21252 + ibtop = au_ibtop(inode);
21253 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
21254 + wr_dir_args.force_btgt = ibtop;
21255 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21256 + if (unlikely(err < 0))
21260 + au_fset_icpup(a->flags, DID_CPUP);
21263 + a->pin_flags = AuPin_MNT_WRITE;
21265 + if (!IS_ROOT(dentry)) {
21266 + au_fset_pin(a->pin_flags, DI_LOCKED);
21267 + parent = dget_parent(dentry);
21268 + di_write_lock_parent(parent);
21271 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
21272 + if (unlikely(err))
21276 + a->h_path.dentry = au_h_dptr(dentry, btop);
21277 + a->h_inode = d_inode(a->h_path.dentry);
21278 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
21279 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
21280 + if (ia->ia_size < i_size_read(a->h_inode))
21281 + sz = ia->ia_size;
21282 + inode_unlock_shared(a->h_inode);
21286 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
21287 + hi_wh = au_hi_wh(inode, a->btgt);
21289 + struct au_cp_generic cpg = {
21290 + .dentry = dentry,
21296 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
21297 + if (unlikely(err))
21299 + hi_wh = au_hi_wh(inode, a->btgt);
21300 + /* todo: revalidate hi_wh? */
21305 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
21306 + di_downgrade_lock(parent, AuLock_IR);
21310 + if (!au_ftest_icpup(a->flags, DID_CPUP))
21311 + goto out; /* success */
21313 + if (!d_unhashed(dentry)) {
21314 + struct au_cp_generic cpg = {
21315 + .dentry = dentry,
21320 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21322 + err = au_sio_cpup_simple(&cpg);
21324 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21325 + } else if (!hi_wh)
21326 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
21328 + a->h_path.dentry = hi_wh; /* do not dget here */
21331 + a->h_inode = d_inode(a->h_path.dentry);
21333 + goto out; /* success */
21334 + au_unpin(&a->pin);
21337 + di_write_unlock(parent);
21342 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21346 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
21349 + struct inode *inode, *delegated;
21350 + struct super_block *sb;
21351 + struct file *file;
21352 + struct au_icpup_args *a;
21354 + inode = d_inode(dentry);
21355 + IMustLock(inode);
21357 + err = setattr_prepare(dentry, ia);
21358 + if (unlikely(err))
21362 + a = kzalloc(sizeof(*a), GFP_NOFS);
21363 + if (unlikely(!a))
21366 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
21367 + ia->ia_valid &= ~ATTR_MODE;
21370 + sb = dentry->d_sb;
21371 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21372 + if (unlikely(err))
21375 + if (ia->ia_valid & ATTR_FILE) {
21376 + /* currently ftruncate(2) only */
21377 + AuDebugOn(!d_is_reg(dentry));
21378 + file = ia->ia_file;
21379 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
21381 + if (unlikely(err))
21383 + ia->ia_file = au_hf_top(file);
21384 + a->udba = AuOpt_UDBA_NONE;
21386 + /* fchmod() doesn't pass ia_file */
21387 + a->udba = au_opt_udba(sb);
21388 + di_write_lock_child(dentry);
21389 + /* no d_unlinked(), to set UDBA_NONE for root */
21390 + if (d_unhashed(dentry))
21391 + a->udba = AuOpt_UDBA_NONE;
21392 + if (a->udba != AuOpt_UDBA_NONE) {
21393 + AuDebugOn(IS_ROOT(dentry));
21394 + err = au_reval_for_attr(dentry, au_sigen(sb));
21395 + if (unlikely(err))
21400 + err = au_pin_and_icpup(dentry, ia, a);
21401 + if (unlikely(err < 0))
21403 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
21404 + ia->ia_file = NULL;
21405 + ia->ia_valid &= ~ATTR_FILE;
21408 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
21409 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
21410 + == (ATTR_MODE | ATTR_CTIME)) {
21411 + err = security_path_chmod(&a->h_path, ia->ia_mode);
21412 + if (unlikely(err))
21414 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
21415 + && (ia->ia_valid & ATTR_CTIME)) {
21416 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
21417 + if (unlikely(err))
21421 + if (ia->ia_valid & ATTR_SIZE) {
21424 + if (ia->ia_size < i_size_read(inode))
21426 + truncate_setsize(inode, ia->ia_size);
21429 + if (ia->ia_valid & ATTR_FILE)
21431 + inode_unlock(a->h_inode);
21432 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
21433 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
21435 + delegated = NULL;
21437 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
21439 + err = break_deleg_wait(&delegated);
21447 + * regardless aufs 'acl' option setting.
21448 + * why don't all acl-aware fs call this func from their ->setattr()?
21450 + if (!err && (ia->ia_valid & ATTR_MODE))
21451 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
21453 + au_cpup_attr_changeable(inode);
21456 + inode_unlock(a->h_inode);
21457 + au_unpin(&a->pin);
21458 + if (unlikely(err))
21459 + au_update_dbtop(dentry);
21461 + di_write_unlock(dentry);
21463 + fi_write_unlock(file);
21464 + ia->ia_file = file;
21465 + ia->ia_valid |= ATTR_FILE;
21468 + si_read_unlock(sb);
21476 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
21477 +static int au_h_path_to_set_attr(struct dentry *dentry,
21478 + struct au_icpup_args *a, struct path *h_path)
21481 + struct super_block *sb;
21483 + sb = dentry->d_sb;
21484 + a->udba = au_opt_udba(sb);
21485 + /* no d_unlinked(), to set UDBA_NONE for root */
21486 + if (d_unhashed(dentry))
21487 + a->udba = AuOpt_UDBA_NONE;
21488 + if (a->udba != AuOpt_UDBA_NONE) {
21489 + AuDebugOn(IS_ROOT(dentry));
21490 + err = au_reval_for_attr(dentry, au_sigen(sb));
21491 + if (unlikely(err))
21494 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
21495 + if (unlikely(err < 0))
21498 + h_path->dentry = a->h_path.dentry;
21499 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
21505 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
21506 + struct au_sxattr *arg)
21509 + struct path h_path;
21510 + struct super_block *sb;
21511 + struct au_icpup_args *a;
21512 + struct inode *h_inode;
21514 + IMustLock(inode);
21517 + a = kzalloc(sizeof(*a), GFP_NOFS);
21518 + if (unlikely(!a))
21521 + sb = dentry->d_sb;
21522 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21523 + if (unlikely(err))
21526 + h_path.dentry = NULL; /* silence gcc */
21527 + di_write_lock_child(dentry);
21528 + err = au_h_path_to_set_attr(dentry, a, &h_path);
21529 + if (unlikely(err))
21532 + inode_unlock(a->h_inode);
21533 + switch (arg->type) {
21534 + case AU_XATTR_SET:
21535 + AuDebugOn(d_is_negative(h_path.dentry));
21536 + err = vfsub_setxattr(h_path.dentry,
21537 + arg->u.set.name, arg->u.set.value,
21538 + arg->u.set.size, arg->u.set.flags);
21541 + err = -EOPNOTSUPP;
21542 + h_inode = d_inode(h_path.dentry);
21543 + if (h_inode->i_op->set_acl)
21544 + /* this will call posix_acl_update_mode */
21545 + err = h_inode->i_op->set_acl(h_inode,
21546 + arg->u.acl_set.acl,
21547 + arg->u.acl_set.type);
21551 + au_cpup_attr_timesizes(inode);
21553 + au_unpin(&a->pin);
21554 + if (unlikely(err))
21555 + au_update_dbtop(dentry);
21558 + di_write_unlock(dentry);
21559 + si_read_unlock(sb);
21568 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
21569 + unsigned int nlink)
21573 + inode->i_mode = st->mode;
21574 + /* don't i_[ug]id_write() here */
21575 + inode->i_uid = st->uid;
21576 + inode->i_gid = st->gid;
21577 + inode->i_atime = st->atime;
21578 + inode->i_mtime = st->mtime;
21579 + inode->i_ctime = st->ctime;
21581 + au_cpup_attr_nlink(inode, /*force*/0);
21582 + if (S_ISDIR(inode->i_mode)) {
21583 + n = inode->i_nlink;
21586 + smp_mb(); /* for i_nlink */
21587 + /* 0 can happen */
21588 + set_nlink(inode, n);
21591 + spin_lock(&inode->i_lock);
21592 + inode->i_blocks = st->blocks;
21593 + i_size_write(inode, st->size);
21594 + spin_unlock(&inode->i_lock);
21598 + * common routine for aufs_getattr() and au_getxattr().
21599 + * returns zero or negative (an error).
21600 + * @dentry will be read-locked in success.
21602 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
21603 + struct path *h_path, int locked)
21606 + unsigned int mnt_flags, sigen;
21607 + unsigned char udba_none;
21608 + aufs_bindex_t bindex;
21609 + struct super_block *sb, *h_sb;
21611 + h_path->mnt = NULL;
21612 + h_path->dentry = NULL;
21615 + sb = dentry->d_sb;
21616 + mnt_flags = au_mntflags(sb);
21617 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
21619 + if (unlikely(locked))
21620 + goto body; /* skip locking dinfo */
21622 + /* support fstat(2) */
21623 + if (!d_unlinked(dentry) && !udba_none) {
21624 + sigen = au_sigen(sb);
21625 + err = au_digen_test(dentry, sigen);
21627 + di_read_lock_child(dentry, AuLock_IR);
21628 + err = au_dbrange_test(dentry);
21629 + if (unlikely(err)) {
21630 + di_read_unlock(dentry, AuLock_IR);
21634 + AuDebugOn(IS_ROOT(dentry));
21635 + di_write_lock_child(dentry);
21636 + err = au_dbrange_test(dentry);
21638 + err = au_reval_for_attr(dentry, sigen);
21640 + di_downgrade_lock(dentry, AuLock_IR);
21642 + di_write_unlock(dentry);
21647 + di_read_lock_child(dentry, AuLock_IR);
21651 + inode = d_inode(dentry);
21652 + if (unlikely(!inode))
21655 + bindex = au_ibtop(inode);
21656 + h_path->mnt = au_sbr_mnt(sb, bindex);
21657 + h_sb = h_path->mnt->mnt_sb;
21659 + && !au_test_fs_bad_iattr(h_sb)
21661 + goto out; /* success */
21663 + if (au_dbtop(dentry) == bindex)
21664 + h_path->dentry = au_h_dptr(dentry, bindex);
21665 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
21666 + h_path->dentry = au_plink_lkup(inode, bindex);
21667 + if (IS_ERR(h_path->dentry))
21668 + /* pretending success */
21669 + h_path->dentry = NULL;
21671 + dput(h_path->dentry);
21678 +static int aufs_getattr(const struct path *path, struct kstat *st,
21679 + u32 request, unsigned int query)
21682 + unsigned char positive;
21683 + struct path h_path;
21684 + struct dentry *dentry;
21685 + struct inode *inode;
21686 + struct super_block *sb;
21688 + dentry = path->dentry;
21689 + inode = d_inode(dentry);
21690 + sb = dentry->d_sb;
21691 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21692 + if (unlikely(err))
21694 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
21696 + if (unlikely(err))
21698 + if (unlikely(!h_path.dentry))
21699 + /* illegally overlapped or something */
21700 + goto out_fill; /* pretending success */
21702 + positive = d_is_positive(h_path.dentry);
21704 + /* no vfsub version */
21705 + err = vfs_getattr(&h_path, st, request, query);
21708 + au_refresh_iattr(inode, st,
21709 + d_inode(h_path.dentry)->i_nlink);
21710 + goto out_fill; /* success */
21716 + generic_fillattr(inode, st);
21718 + di_read_unlock(dentry, AuLock_IR);
21720 + si_read_unlock(sb);
21726 +/* ---------------------------------------------------------------------- */
21728 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
21729 + struct delayed_call *done)
21732 + struct dentry *h_dentry;
21733 + struct inode *h_inode;
21735 + aufs_bindex_t bindex;
21737 + ret = NULL; /* suppress a warning */
21742 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
21743 + if (unlikely(err))
21746 + err = au_d_hashed_positive(dentry);
21747 + if (unlikely(err))
21751 + inode = d_inode(dentry);
21752 + bindex = au_ibtop(inode);
21753 + h_inode = au_h_iptr(inode, bindex);
21754 + if (unlikely(!h_inode->i_op->get_link))
21759 + if (au_dbtop(dentry) <= bindex) {
21760 + h_dentry = au_h_dptr(dentry, bindex);
21765 + h_dentry = d_find_any_alias(h_inode);
21766 + if (IS_ERR(h_dentry)) {
21767 + err = PTR_ERR(h_dentry);
21771 + if (unlikely(!h_dentry))
21775 + AuDbg("%ps\n", h_inode->i_op->get_link);
21776 + AuDbgDentry(h_dentry);
21777 + ret = vfs_get_link(h_dentry, done);
21780 + err = PTR_ERR(ret);
21783 + aufs_read_unlock(dentry, AuLock_IR);
21785 + if (unlikely(err))
21786 + ret = ERR_PTR(err);
21787 + AuTraceErrPtr(ret);
21791 +/* ---------------------------------------------------------------------- */
21793 +static int au_is_special(struct inode *inode)
21795 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
21798 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
21802 + aufs_bindex_t bindex;
21803 + struct super_block *sb;
21804 + struct inode *h_inode;
21805 + struct vfsmount *h_mnt;
21807 + sb = inode->i_sb;
21808 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
21809 + "unexpected s_flags 0x%lx", sb->s_flags);
21811 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
21813 + si_read_lock(sb, AuLock_FLUSH);
21814 + ii_write_lock_child(inode);
21817 + bindex = au_ibtop(inode);
21818 + h_inode = au_h_iptr(inode, bindex);
21819 + if (!au_test_ro(sb, bindex, inode)) {
21820 + h_mnt = au_sbr_mnt(sb, bindex);
21821 + err = vfsub_mnt_want_write(h_mnt);
21823 + err = vfsub_update_time(h_inode, ts, flags);
21824 + vfsub_mnt_drop_write(h_mnt);
21826 + } else if (au_is_special(h_inode)) {
21828 + * Never copy-up here.
21829 + * These special files may already be opened and used for
21830 + * communicating. If we copied it up, then the communication
21831 + * would be corrupted.
21833 + AuWarn1("timestamps for i%lu are ignored "
21834 + "since it is on readonly branch (hi%lu).\n",
21835 + inode->i_ino, h_inode->i_ino);
21836 + } else if (flags & ~S_ATIME) {
21838 + AuIOErr1("unexpected flags 0x%x\n", flags);
21843 + au_cpup_attr_timesizes(inode);
21844 + ii_write_unlock(inode);
21845 + si_read_unlock(sb);
21848 + if (!err && (flags & S_VERSION))
21849 + inode_inc_iversion(inode);
21854 +/* ---------------------------------------------------------------------- */
21856 +/* no getattr version will be set by module.c:aufs_init() */
21857 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
21859 + [AuIop_SYMLINK] = {
21860 + .permission = aufs_permission,
21861 +#ifdef CONFIG_FS_POSIX_ACL
21862 + .get_acl = aufs_get_acl,
21863 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
21866 + .setattr = aufs_setattr,
21867 + .getattr = aufs_getattr,
21869 +#ifdef CONFIG_AUFS_XATTR
21870 + .listxattr = aufs_listxattr,
21873 + .get_link = aufs_get_link,
21875 + /* .update_time = aufs_update_time */
21878 + .create = aufs_create,
21879 + .lookup = aufs_lookup,
21880 + .link = aufs_link,
21881 + .unlink = aufs_unlink,
21882 + .symlink = aufs_symlink,
21883 + .mkdir = aufs_mkdir,
21884 + .rmdir = aufs_rmdir,
21885 + .mknod = aufs_mknod,
21886 + .rename = aufs_rename,
21888 + .permission = aufs_permission,
21889 +#ifdef CONFIG_FS_POSIX_ACL
21890 + .get_acl = aufs_get_acl,
21891 + .set_acl = aufs_set_acl,
21894 + .setattr = aufs_setattr,
21895 + .getattr = aufs_getattr,
21897 +#ifdef CONFIG_AUFS_XATTR
21898 + .listxattr = aufs_listxattr,
21901 + .update_time = aufs_update_time,
21902 + .atomic_open = aufs_atomic_open,
21903 + .tmpfile = aufs_tmpfile
21905 + [AuIop_OTHER] = {
21906 + .permission = aufs_permission,
21907 +#ifdef CONFIG_FS_POSIX_ACL
21908 + .get_acl = aufs_get_acl,
21909 + .set_acl = aufs_set_acl,
21912 + .setattr = aufs_setattr,
21913 + .getattr = aufs_getattr,
21915 +#ifdef CONFIG_AUFS_XATTR
21916 + .listxattr = aufs_listxattr,
21919 + .update_time = aufs_update_time
21922 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
21923 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
21924 +++ linux/fs/aufs/i_op_del.c 2021-12-03 15:38:59.936647310 +0100
21926 +// SPDX-License-Identifier: GPL-2.0
21928 + * Copyright (C) 2005-2021 Junjiro R. Okajima
21930 + * This program, aufs is free software; you can redistribute it and/or modify
21931 + * it under the terms of the GNU General Public License as published by
21932 + * the Free Software Foundation; either version 2 of the License, or
21933 + * (at your option) any later version.
21935 + * This program is distributed in the hope that it will be useful,
21936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21938 + * GNU General Public License for more details.
21940 + * You should have received a copy of the GNU General Public License
21941 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21945 + * inode operations (del entry)
21948 +#include <linux/iversion.h>
21952 + * decide if a new whiteout for @dentry is necessary or not.
21953 + * when it is necessary, prepare the parent dir for the upper branch whose
21954 + * branch index is @bcpup for creation. the actual creation of the whiteout will
21955 + * be done by caller.
21957 + * 0: wh is unnecessary
21958 + * plus: wh is necessary
21961 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
21963 + int need_wh, err;
21964 + aufs_bindex_t btop;
21965 + struct super_block *sb;
21967 + sb = dentry->d_sb;
21968 + btop = au_dbtop(dentry);
21969 + if (*bcpup < 0) {
21971 + if (au_test_ro(sb, btop, d_inode(dentry))) {
21972 + err = AuWbrCopyup(au_sbi(sb), dentry);
21974 + if (unlikely(err < 0))
21978 + AuDebugOn(btop < *bcpup
21979 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
21980 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
21982 + if (*bcpup != btop) {
21983 + err = au_cpup_dirs(dentry, *bcpup);
21984 + if (unlikely(err))
21988 + struct au_dinfo *dinfo, *tmp;
21990 + need_wh = -ENOMEM;
21991 + dinfo = au_di(dentry);
21992 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
21994 + au_di_cp(tmp, dinfo);
21995 + au_di_swap(tmp, dinfo);
21996 + /* returns the number of positive dentries */
21997 + need_wh = au_lkup_dentry(dentry, btop + 1,
21998 + /* AuLkup_IGNORE_PERM */ 0);
21999 + au_di_swap(tmp, dinfo);
22000 + au_rw_write_unlock(&tmp->di_rwsem);
22004 + AuDbg("need_wh %d\n", need_wh);
22012 + * simple tests for the del-entry operations.
22013 + * following the checks in vfs, plus the parent-child relationship.
22015 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
22016 + struct dentry *h_parent, int isdir)
22020 + struct dentry *h_dentry, *h_latest;
22021 + struct inode *h_inode;
22022 + struct path h_ppath;
22023 + struct super_block *sb;
22024 + struct au_branch *br;
22026 + h_dentry = au_h_dptr(dentry, bindex);
22027 + if (d_really_is_positive(dentry)) {
22029 + if (unlikely(d_is_negative(h_dentry)))
22031 + h_inode = d_inode(h_dentry);
22032 + if (unlikely(!h_inode->i_nlink))
22035 + h_mode = h_inode->i_mode;
22038 + if (unlikely(S_ISDIR(h_mode)))
22040 + } else if (unlikely(!S_ISDIR(h_mode))) {
22045 + /* rename(2) case */
22047 + if (unlikely(d_is_positive(h_dentry)))
22052 + /* expected parent dir is locked */
22053 + if (unlikely(h_parent != h_dentry->d_parent))
22058 + * rmdir a dir may break the consistency on some filesystem.
22059 + * let's try heavy test.
22062 + sb = dentry->d_sb;
22063 + br = au_sbr(sb, bindex);
22064 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
22065 + && au_test_h_perm(d_inode(h_parent),
22066 + MAY_EXEC | MAY_WRITE)))
22069 + h_ppath.dentry = h_parent;
22070 + h_ppath.mnt = au_br_mnt(br);
22071 + h_latest = au_sio_lkup_one(&dentry->d_name, &h_ppath);
22073 + if (IS_ERR(h_latest))
22075 + if (h_latest == h_dentry)
22084 + * decide the branch where we operate for @dentry. the branch index will be set
22085 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
22086 + * dir for reverting.
22087 + * when a new whiteout is necessary, create it.
22089 +static struct dentry*
22090 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
22091 + struct au_dtime *dt, struct au_pin *pin)
22093 + struct dentry *wh_dentry;
22094 + struct super_block *sb;
22095 + struct path h_path;
22096 + int err, need_wh;
22097 + unsigned int udba;
22098 + aufs_bindex_t bcpup;
22100 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
22101 + wh_dentry = ERR_PTR(need_wh);
22102 + if (unlikely(need_wh < 0))
22105 + sb = dentry->d_sb;
22106 + udba = au_opt_udba(sb);
22108 + err = au_pin(pin, dentry, bcpup, udba,
22109 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
22110 + wh_dentry = ERR_PTR(err);
22111 + if (unlikely(err))
22114 + h_path.dentry = au_pinned_h_parent(pin);
22115 + if (udba != AuOpt_UDBA_NONE
22116 + && au_dbtop(dentry) == bcpup) {
22117 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
22118 + wh_dentry = ERR_PTR(err);
22119 + if (unlikely(err))
22123 + h_path.mnt = au_sbr_mnt(sb, bcpup);
22124 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
22125 + wh_dentry = NULL;
22127 + goto out; /* success, no need to create whiteout */
22129 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
22130 + if (IS_ERR(wh_dentry))
22133 + /* returns with the parent is locked and wh_dentry is dget-ed */
22134 + goto out; /* success */
22139 + return wh_dentry;
22143 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
22144 + * in order to be revertible and save time for removing many child whiteouts
22146 + * returns 1 when there are too many child whiteout and caller should remove
22147 + * them asynchronously. returns 0 when the number of children is enough small to
22148 + * remove now or the branch fs is a remote fs.
22149 + * otherwise return an error.
22151 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
22152 + struct au_nhash *whlist, struct inode *dir)
22154 + int rmdir_later, err, dirwh;
22155 + struct dentry *h_dentry;
22156 + struct super_block *sb;
22157 + struct inode *inode;
22159 + sb = dentry->d_sb;
22160 + SiMustAnyLock(sb);
22161 + h_dentry = au_h_dptr(dentry, bindex);
22162 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
22163 + if (unlikely(err))
22166 + /* stop monitoring */
22167 + inode = d_inode(dentry);
22168 + au_hn_free(au_hi(inode, bindex));
22170 + if (!au_test_fs_remote(h_dentry->d_sb)) {
22171 + dirwh = au_sbi(sb)->si_dirwh;
22172 + rmdir_later = (dirwh <= 1);
22173 + if (!rmdir_later)
22174 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
22177 + return rmdir_later;
22180 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
22181 + if (unlikely(err)) {
22182 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
22183 + h_dentry, bindex, err);
22193 + * final procedure for deleting a entry.
22194 + * maintain dentry and iattr.
22196 +static void epilog(struct inode *dir, struct dentry *dentry,
22197 + aufs_bindex_t bindex)
22199 + struct inode *inode;
22201 + inode = d_inode(dentry);
22203 + inode->i_ctime = dir->i_ctime;
22205 + au_dir_ts(dir, bindex);
22206 + inode_inc_iversion(dir);
22210 + * when an error happened, remove the created whiteout and revert everything.
22212 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
22213 + aufs_bindex_t bwh, struct dentry *wh_dentry,
22214 + struct dentry *dentry, struct au_dtime *dt)
22217 + struct path h_path = {
22218 + .dentry = wh_dentry,
22219 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
22222 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
22224 + au_set_dbwh(dentry, bwh);
22225 + au_dtime_revert(dt);
22229 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
22233 +/* ---------------------------------------------------------------------- */
22235 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
22238 + aufs_bindex_t bwh, bindex, btop;
22239 + struct inode *inode, *h_dir, *delegated;
22240 + struct dentry *parent, *wh_dentry;
22241 + /* to reduce stack size */
22243 + struct au_dtime dt;
22244 + struct au_pin pin;
22245 + struct path h_path;
22251 + a = kmalloc(sizeof(*a), GFP_NOFS);
22252 + if (unlikely(!a))
22255 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
22256 + if (unlikely(err))
22258 + err = au_d_hashed_positive(dentry);
22259 + if (unlikely(err))
22261 + inode = d_inode(dentry);
22262 + IMustLock(inode);
22264 + if (unlikely(d_is_dir(dentry)))
22265 + goto out_unlock; /* possible? */
22267 + btop = au_dbtop(dentry);
22268 + bwh = au_dbwh(dentry);
22270 + parent = dentry->d_parent; /* dir inode is locked */
22271 + di_write_lock_parent(parent);
22272 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
22274 + err = PTR_ERR(wh_dentry);
22275 + if (IS_ERR(wh_dentry))
22278 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
22279 + a->h_path.dentry = au_h_dptr(dentry, btop);
22280 + dget(a->h_path.dentry);
22281 + if (bindex == btop) {
22282 + h_dir = au_pinned_h_dir(&a->pin);
22283 + delegated = NULL;
22284 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
22285 + if (unlikely(err == -EWOULDBLOCK)) {
22286 + pr_warn("cannot retry for NFSv4 delegation"
22287 + " for an internal unlink\n");
22291 + /* dir inode is locked */
22292 + h_dir = d_inode(wh_dentry->d_parent);
22293 + IMustLock(h_dir);
22298 + vfsub_drop_nlink(inode);
22299 + epilog(dir, dentry, bindex);
22301 + /* update target timestamps */
22302 + if (bindex == btop) {
22303 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
22305 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22307 + /* todo: this timestamp may be reverted later */
22308 + inode->i_ctime = h_dir->i_ctime;
22309 + goto out_unpin; /* success */
22316 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22323 + au_unpin(&a->pin);
22325 + dput(a->h_path.dentry);
22327 + di_write_unlock(parent);
22329 + aufs_read_unlock(dentry, AuLock_DW);
22336 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
22338 + int err, rmdir_later;
22339 + aufs_bindex_t bwh, bindex, btop;
22340 + struct inode *inode;
22341 + struct dentry *parent, *wh_dentry, *h_dentry;
22342 + struct au_whtmp_rmdir *args;
22343 + /* to reduce stack size */
22345 + struct au_dtime dt;
22346 + struct au_pin pin;
22352 + a = kmalloc(sizeof(*a), GFP_NOFS);
22353 + if (unlikely(!a))
22356 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22357 + if (unlikely(err))
22359 + err = au_alive_dir(dentry);
22360 + if (unlikely(err))
22362 + inode = d_inode(dentry);
22363 + IMustLock(inode);
22365 + if (unlikely(!d_is_dir(dentry)))
22366 + goto out_unlock; /* possible? */
22369 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
22370 + if (unlikely(!args))
22373 + parent = dentry->d_parent; /* dir inode is locked */
22374 + di_write_lock_parent(parent);
22375 + err = au_test_empty(dentry, &args->whlist);
22376 + if (unlikely(err))
22379 + btop = au_dbtop(dentry);
22380 + bwh = au_dbwh(dentry);
22382 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
22384 + err = PTR_ERR(wh_dentry);
22385 + if (IS_ERR(wh_dentry))
22388 + h_dentry = au_h_dptr(dentry, btop);
22391 + if (bindex == btop) {
22392 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
22394 + rmdir_later = err;
22398 + /* stop monitoring */
22399 + au_hn_free(au_hi(inode, btop));
22401 + /* dir inode is locked */
22402 + IMustLock(d_inode(wh_dentry->d_parent));
22407 + vfsub_dead_dir(inode);
22408 + au_set_dbdiropq(dentry, -1);
22409 + epilog(dir, dentry, bindex);
22411 + if (rmdir_later) {
22412 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
22416 + goto out_unpin; /* success */
22424 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
22431 + au_unpin(&a->pin);
22435 + di_write_unlock(parent);
22437 + au_whtmp_rmdir_free(args);
22439 + aufs_read_unlock(dentry, AuLock_DW);
22446 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
22447 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
22448 +++ linux/fs/aufs/i_op_ren.c 2021-12-03 15:38:59.936647310 +0100
22450 +// SPDX-License-Identifier: GPL-2.0
22452 + * Copyright (C) 2005-2021 Junjiro R. Okajima
22454 + * This program, aufs is free software; you can redistribute it and/or modify
22455 + * it under the terms of the GNU General Public License as published by
22456 + * the Free Software Foundation; either version 2 of the License, or
22457 + * (at your option) any later version.
22459 + * This program is distributed in the hope that it will be useful,
22460 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22461 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22462 + * GNU General Public License for more details.
22464 + * You should have received a copy of the GNU General Public License
22465 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22469 + * inode operation (rename entry)
22470 + * todo: this is crazy monster
22473 +#include <linux/iversion.h>
22476 +enum { AuSRC, AuDST, AuSrcDst };
22477 +enum { AuPARENT, AuCHILD, AuParentChild };
22479 +#define AuRen_ISDIR_SRC 1
22480 +#define AuRen_ISDIR_DST (1 << 1)
22481 +#define AuRen_ISSAMEDIR (1 << 2)
22482 +#define AuRen_WHSRC (1 << 3)
22483 +#define AuRen_WHDST (1 << 4)
22484 +#define AuRen_MNT_WRITE (1 << 5)
22485 +#define AuRen_DT_DSTDIR (1 << 6)
22486 +#define AuRen_DIROPQ_SRC (1 << 7)
22487 +#define AuRen_DIROPQ_DST (1 << 8)
22488 +#define AuRen_DIRREN (1 << 9)
22489 +#define AuRen_DROPPED_SRC (1 << 10)
22490 +#define AuRen_DROPPED_DST (1 << 11)
22491 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
22492 +#define au_fset_ren(flags, name) \
22493 + do { (flags) |= AuRen_##name; } while (0)
22494 +#define au_fclr_ren(flags, name) \
22495 + do { (flags) &= ~AuRen_##name; } while (0)
22497 +#ifndef CONFIG_AUFS_DIRREN
22498 +#undef AuRen_DIRREN
22499 +#define AuRen_DIRREN 0
22502 +struct au_ren_args {
22504 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
22506 + struct inode *dir, *inode;
22507 + struct au_hinode *hdir, *hinode;
22508 + struct au_dtime dt[AuParentChild];
22509 + aufs_bindex_t btop, bdiropq;
22512 +#define src_dentry sd[AuSRC].dentry
22513 +#define src_dir sd[AuSRC].dir
22514 +#define src_inode sd[AuSRC].inode
22515 +#define src_h_dentry sd[AuSRC].h_dentry
22516 +#define src_parent sd[AuSRC].parent
22517 +#define src_h_parent sd[AuSRC].h_parent
22518 +#define src_wh_dentry sd[AuSRC].wh_dentry
22519 +#define src_hdir sd[AuSRC].hdir
22520 +#define src_hinode sd[AuSRC].hinode
22521 +#define src_h_dir sd[AuSRC].hdir->hi_inode
22522 +#define src_dt sd[AuSRC].dt
22523 +#define src_btop sd[AuSRC].btop
22524 +#define src_bdiropq sd[AuSRC].bdiropq
22526 +#define dst_dentry sd[AuDST].dentry
22527 +#define dst_dir sd[AuDST].dir
22528 +#define dst_inode sd[AuDST].inode
22529 +#define dst_h_dentry sd[AuDST].h_dentry
22530 +#define dst_parent sd[AuDST].parent
22531 +#define dst_h_parent sd[AuDST].h_parent
22532 +#define dst_wh_dentry sd[AuDST].wh_dentry
22533 +#define dst_hdir sd[AuDST].hdir
22534 +#define dst_hinode sd[AuDST].hinode
22535 +#define dst_h_dir sd[AuDST].hdir->hi_inode
22536 +#define dst_dt sd[AuDST].dt
22537 +#define dst_btop sd[AuDST].btop
22538 +#define dst_bdiropq sd[AuDST].bdiropq
22540 + struct dentry *h_trap;
22541 + struct au_branch *br;
22542 + struct path h_path;
22543 + struct au_nhash whlist;
22544 + aufs_bindex_t btgt, src_bwh;
22547 + unsigned short auren_flags;
22548 + unsigned char flags; /* syscall parameter */
22549 + unsigned char exchange;
22552 + struct au_whtmp_rmdir *thargs;
22553 + struct dentry *h_dst;
22554 + struct au_hinode *h_root;
22557 +/* ---------------------------------------------------------------------- */
22560 + * functions for reverting.
22561 + * when an error happened in a single rename systemcall, we should revert
22562 + * everything as if nothing happened.
22563 + * we don't need to revert the copied-up/down the parent dir since they are
22567 +#define RevertFailure(fmt, ...) do { \
22568 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
22569 + ##__VA_ARGS__, err, rerr); \
22573 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
22576 + struct dentry *d;
22577 +#define src_or_dst(member) a->sd[idx].member
22579 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22580 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22581 + rerr = au_diropq_remove(d, a->btgt);
22582 + au_hn_inode_unlock(src_or_dst(hinode));
22583 + au_set_dbdiropq(d, src_or_dst(bdiropq));
22585 + RevertFailure("remove diropq %pd", d);
22587 +#undef src_or_dst_
22590 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
22592 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
22593 + au_ren_do_rev_diropq(err, a, AuSRC);
22594 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
22595 + au_ren_do_rev_diropq(err, a, AuDST);
22598 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
22601 + struct inode *delegated;
22602 + struct path h_ppath = {
22603 + .dentry = a->src_h_parent,
22604 + .mnt = a->h_path.mnt
22607 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
22608 + rerr = PTR_ERR(a->h_path.dentry);
22609 + if (IS_ERR(a->h_path.dentry)) {
22610 + RevertFailure("lkup one %pd", a->src_dentry);
22614 + delegated = NULL;
22615 + rerr = vfsub_rename(a->dst_h_dir,
22616 + au_h_dptr(a->src_dentry, a->btgt),
22617 + a->src_h_dir, &a->h_path, &delegated, a->flags);
22618 + if (unlikely(rerr == -EWOULDBLOCK)) {
22619 + pr_warn("cannot retry for NFSv4 delegation"
22620 + " for an internal rename\n");
22623 + d_drop(a->h_path.dentry);
22624 + dput(a->h_path.dentry);
22625 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
22627 + RevertFailure("rename %pd", a->src_dentry);
22630 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
22633 + struct inode *delegated;
22634 + struct path h_ppath = {
22635 + .dentry = a->dst_h_parent,
22636 + .mnt = a->h_path.mnt
22639 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
22640 + rerr = PTR_ERR(a->h_path.dentry);
22641 + if (IS_ERR(a->h_path.dentry)) {
22642 + RevertFailure("lkup one %pd", a->dst_dentry);
22645 + if (d_is_positive(a->h_path.dentry)) {
22646 + d_drop(a->h_path.dentry);
22647 + dput(a->h_path.dentry);
22651 + delegated = NULL;
22652 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
22653 + &delegated, a->flags);
22654 + if (unlikely(rerr == -EWOULDBLOCK)) {
22655 + pr_warn("cannot retry for NFSv4 delegation"
22656 + " for an internal rename\n");
22659 + d_drop(a->h_path.dentry);
22660 + dput(a->h_path.dentry);
22662 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
22664 + RevertFailure("rename %pd", a->h_dst);
22667 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
22671 + a->h_path.dentry = a->src_wh_dentry;
22672 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
22673 + au_set_dbwh(a->src_dentry, a->src_bwh);
22675 + RevertFailure("unlink %pd", a->src_wh_dentry);
22677 +#undef RevertFailure
22679 +/* ---------------------------------------------------------------------- */
22682 + * when we have to copyup the renaming entry, do it with the rename-target name
22683 + * in order to minimize the cost (the later actual rename is unnecessary).
22684 + * otherwise rename it on the target branch.
22686 +static int au_ren_or_cpup(struct au_ren_args *a)
22689 + struct dentry *d;
22690 + struct inode *delegated;
22692 + d = a->src_dentry;
22693 + if (au_dbtop(d) == a->btgt) {
22694 + a->h_path.dentry = a->dst_h_dentry;
22695 + AuDebugOn(au_dbtop(d) != a->btgt);
22696 + delegated = NULL;
22697 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
22698 + a->dst_h_dir, &a->h_path, &delegated,
22700 + if (unlikely(err == -EWOULDBLOCK)) {
22701 + pr_warn("cannot retry for NFSv4 delegation"
22702 + " for an internal rename\n");
22708 + if (!err && a->h_dst)
22709 + /* it will be set to dinfo later */
22715 +/* cf. aufs_rmdir() */
22716 +static int au_ren_del_whtmp(struct au_ren_args *a)
22719 + struct inode *dir;
22721 + dir = a->dst_dir;
22722 + SiMustAnyLock(dir->i_sb);
22723 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
22724 + au_sbi(dir->i_sb)->si_dirwh)
22725 + || au_test_fs_remote(a->h_dst->d_sb)) {
22726 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
22727 + if (unlikely(err))
22728 + pr_warn("failed removing whtmp dir %pd (%d), "
22729 + "ignored.\n", a->h_dst, err);
22731 + au_nhash_wh_free(&a->thargs->whlist);
22732 + a->thargs->whlist = a->whlist;
22733 + a->whlist.nh_num = 0;
22734 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
22736 + a->thargs = NULL;
22742 +/* make it 'opaque' dir. */
22743 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
22746 + struct dentry *d, *diropq;
22747 +#define src_or_dst(member) a->sd[idx].member
22750 + d = src_or_dst(dentry); /* {src,dst}_dentry */
22751 + src_or_dst(bdiropq) = au_dbdiropq(d);
22752 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
22753 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
22754 + diropq = au_diropq_create(d, a->btgt);
22755 + au_hn_inode_unlock(src_or_dst(hinode));
22756 + if (IS_ERR(diropq))
22757 + err = PTR_ERR(diropq);
22761 +#undef src_or_dst_
22765 +static int au_ren_diropq(struct au_ren_args *a)
22768 + unsigned char always;
22769 + struct dentry *d;
22772 + d = a->dst_dentry; /* already renamed on the branch */
22773 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
22774 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
22775 + && !au_ftest_ren(a->auren_flags, DIRREN)
22776 + && a->btgt != au_dbdiropq(a->src_dentry)
22777 + && (a->dst_wh_dentry
22778 + || a->btgt <= au_dbdiropq(d)
22779 + /* hide the lower to keep xino */
22780 + /* the lowers may not be a dir, but we hide them anyway */
22781 + || a->btgt < au_dbbot(d)
22784 + err = au_ren_do_diropq(a, AuSRC);
22785 + if (unlikely(err))
22787 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
22789 + if (!a->exchange)
22790 + goto out; /* success */
22792 + d = a->src_dentry; /* already renamed on the branch */
22793 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22794 + && a->btgt != au_dbdiropq(a->dst_dentry)
22795 + && (a->btgt < au_dbdiropq(d)
22796 + || a->btgt < au_dbbot(d)
22798 + AuDbgDentry(a->src_dentry);
22799 + AuDbgDentry(a->dst_dentry);
22800 + err = au_ren_do_diropq(a, AuDST);
22801 + if (unlikely(err))
22802 + goto out_rev_src;
22803 + au_fset_ren(a->auren_flags, DIROPQ_DST);
22805 + goto out; /* success */
22808 + AuDbg("err %d, reverting src\n", err);
22809 + au_ren_rev_diropq(err, a);
22814 +static int do_rename(struct au_ren_args *a)
22817 + struct dentry *d, *h_d;
22819 + if (!a->exchange) {
22820 + /* prepare workqueue args for asynchronous rmdir */
22821 + h_d = a->dst_h_dentry;
22822 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
22823 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
22824 + && d_is_positive(h_d)) {
22826 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
22828 + if (unlikely(!a->thargs))
22830 + a->h_dst = dget(h_d);
22833 + /* create whiteout for src_dentry */
22834 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
22835 + a->src_bwh = au_dbwh(a->src_dentry);
22836 + AuDebugOn(a->src_bwh >= 0);
22837 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
22838 + a->src_h_parent);
22839 + err = PTR_ERR(a->src_wh_dentry);
22840 + if (IS_ERR(a->src_wh_dentry))
22844 + /* lookup whiteout for dentry */
22845 + if (au_ftest_ren(a->auren_flags, WHDST)) {
22846 + h_d = au_wh_lkup(a->dst_h_parent,
22847 + &a->dst_dentry->d_name, a->br);
22848 + err = PTR_ERR(h_d);
22851 + if (d_is_negative(h_d))
22854 + a->dst_wh_dentry = h_d;
22857 + /* rename dentry to tmpwh */
22859 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
22860 + if (unlikely(err))
22863 + d = a->dst_dentry;
22864 + au_set_h_dptr(d, a->btgt, NULL);
22865 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
22866 + if (unlikely(err))
22868 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
22872 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
22873 +#if 0 /* debugging */
22874 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
22875 + && d_is_positive(a->dst_h_dentry)
22876 + && a->src_btop != a->btgt);
22879 + /* rename by vfs_rename or cpup */
22880 + err = au_ren_or_cpup(a);
22881 + if (unlikely(err))
22882 + /* leave the copied-up one */
22885 + /* make dir opaque */
22886 + err = au_ren_diropq(a);
22887 + if (unlikely(err))
22890 + /* update target timestamps */
22891 + if (a->exchange) {
22892 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
22893 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
22894 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22895 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22897 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
22898 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
22899 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
22900 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
22902 + if (!a->exchange) {
22903 + /* remove whiteout for dentry */
22904 + if (a->dst_wh_dentry) {
22905 + a->h_path.dentry = a->dst_wh_dentry;
22906 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
22908 + if (unlikely(err))
22912 + /* remove whtmp */
22914 + au_ren_del_whtmp(a); /* ignore this error */
22916 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
22919 + goto out_success;
22922 + au_ren_rev_diropq(err, a);
22924 + au_ren_rev_rename(err, a);
22928 + au_ren_rev_whtmp(err, a);
22930 + dput(a->dst_wh_dentry);
22931 + a->dst_wh_dentry = NULL;
22933 + if (a->src_wh_dentry)
22934 + au_ren_rev_whsrc(err, a);
22936 + dput(a->src_wh_dentry);
22937 + dput(a->dst_wh_dentry);
22941 + au_whtmp_rmdir_free(a->thargs);
22942 + a->thargs = NULL;
22948 +/* ---------------------------------------------------------------------- */
22951 + * test if @dentry dir can be rename destination or not.
22952 + * success means, it is a logically empty dir.
22954 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
22956 + return au_test_empty(dentry, whlist);
22960 + * test if @a->src_dentry dir can be rename source or not.
22961 + * if it can, return 0.
22963 + * - it is a logically empty dir.
22964 + * - or, it exists on writable branch and has no children including whiteouts
22965 + * on the lower branch unless DIRREN is on.
22967 +static int may_rename_srcdir(struct au_ren_args *a)
22970 + unsigned int rdhash;
22971 + aufs_bindex_t btop, btgt;
22972 + struct dentry *dentry;
22973 + struct super_block *sb;
22974 + struct au_sbinfo *sbinfo;
22976 + dentry = a->src_dentry;
22977 + sb = dentry->d_sb;
22978 + sbinfo = au_sbi(sb);
22979 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
22980 + au_fset_ren(a->auren_flags, DIRREN);
22983 + btop = au_dbtop(dentry);
22984 + if (btop != btgt) {
22985 + struct au_nhash whlist;
22987 + SiMustAnyLock(sb);
22988 + rdhash = sbinfo->si_rdhash;
22990 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
22992 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
22993 + if (unlikely(err))
22995 + err = au_test_empty(dentry, &whlist);
22996 + au_nhash_wh_free(&whlist);
23000 + if (btop == au_dbtaildir(dentry))
23001 + return 0; /* success */
23003 + err = au_test_empty_lower(dentry);
23006 + if (err == -ENOTEMPTY) {
23007 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23010 + AuWarn1("renaming dir who has child(ren) on multiple "
23011 + "branches, is not supported\n");
23018 +/* side effect: sets whlist and h_dentry */
23019 +static int au_ren_may_dir(struct au_ren_args *a)
23022 + unsigned int rdhash;
23023 + struct dentry *d;
23025 + d = a->dst_dentry;
23026 + SiMustAnyLock(d->d_sb);
23029 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
23030 + rdhash = au_sbi(d->d_sb)->si_rdhash;
23032 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
23033 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
23034 + if (unlikely(err))
23037 + if (!a->exchange) {
23038 + au_set_dbtop(d, a->dst_btop);
23039 + err = may_rename_dstdir(d, &a->whlist);
23040 + au_set_dbtop(d, a->btgt);
23042 + err = may_rename_srcdir(a);
23044 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
23045 + if (unlikely(err))
23048 + d = a->src_dentry;
23049 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
23050 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23051 + err = may_rename_srcdir(a);
23052 + if (unlikely(err)) {
23053 + au_nhash_wh_free(&a->whlist);
23054 + a->whlist.nh_num = 0;
23061 +/* ---------------------------------------------------------------------- */
23064 + * simple tests for rename.
23065 + * following the checks in vfs, plus the parent-child relationship.
23067 +static int au_may_ren(struct au_ren_args *a)
23070 + struct inode *h_inode;
23072 + if (a->src_btop == a->btgt) {
23073 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
23074 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
23075 + if (unlikely(err))
23078 + if (unlikely(a->src_h_dentry == a->h_trap))
23083 + if (a->dst_btop != a->btgt)
23086 + err = -ENOTEMPTY;
23087 + if (unlikely(a->dst_h_dentry == a->h_trap))
23091 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
23092 + if (d_really_is_negative(a->dst_dentry)) {
23093 + if (d_is_negative(a->dst_h_dentry))
23094 + err = au_may_add(a->dst_dentry, a->btgt,
23095 + a->dst_h_parent, isdir);
23097 + if (unlikely(d_is_negative(a->dst_h_dentry)))
23099 + h_inode = d_inode(a->dst_h_dentry);
23100 + if (h_inode->i_nlink)
23101 + err = au_may_del(a->dst_dentry, a->btgt,
23102 + a->dst_h_parent, isdir);
23106 + if (unlikely(err == -ENOENT || err == -EEXIST))
23112 +/* ---------------------------------------------------------------------- */
23117 + * - src_dir and dir by lock_rename()
23118 + * - inode if exists
23121 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
23123 + * + di_write_lock2_child()
23124 + * + di_write_lock_child()
23125 + * + ii_write_lock_child()
23126 + * + di_write_lock_child2()
23127 + * + ii_write_lock_child2()
23128 + * + src_parent and parent
23129 + * + di_write_lock_parent()
23130 + * + ii_write_lock_parent()
23131 + * + di_write_lock_parent2()
23132 + * + ii_write_lock_parent2()
23133 + * + lower src_dir and dir by vfsub_lock_rename()
23134 + * + verify the every relationships between child and parent. if any
23135 + * of them failed, unlock all and return -EBUSY.
23137 +static void au_ren_unlock(struct au_ren_args *a)
23139 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
23140 + a->dst_h_parent, a->dst_hdir);
23141 + if (au_ftest_ren(a->auren_flags, DIRREN)
23143 + au_hn_inode_unlock(a->h_root);
23144 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
23145 + vfsub_mnt_drop_write(au_br_mnt(a->br));
23148 +static int au_ren_lock(struct au_ren_args *a)
23151 + unsigned int udba;
23154 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
23155 + a->src_hdir = au_hi(a->src_dir, a->btgt);
23156 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
23157 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
23159 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
23160 + if (unlikely(err))
23162 + au_fset_ren(a->auren_flags, MNT_WRITE);
23163 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23164 + struct dentry *root;
23165 + struct inode *dir;
23168 + * sbinfo is already locked, so this ii_read_lock is
23169 + * unnecessary. but our debugging feature checks it.
23171 + root = a->src_inode->i_sb->s_root;
23172 + if (root != a->src_parent && root != a->dst_parent) {
23173 + dir = d_inode(root);
23174 + ii_read_lock_parent3(dir);
23175 + a->h_root = au_hi(dir, a->btgt);
23176 + ii_read_unlock(dir);
23177 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
23180 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
23181 + a->dst_h_parent, a->dst_hdir);
23182 + udba = au_opt_udba(a->src_dentry->d_sb);
23183 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
23184 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
23185 + err = au_busy_or_stale();
23186 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
23187 + err = au_h_verify(a->src_h_dentry, udba,
23188 + d_inode(a->src_h_parent), a->src_h_parent,
23190 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
23191 + err = au_h_verify(a->dst_h_dentry, udba,
23192 + d_inode(a->dst_h_parent), a->dst_h_parent,
23195 + goto out; /* success */
23197 + err = au_busy_or_stale();
23198 + au_ren_unlock(a);
23204 +/* ---------------------------------------------------------------------- */
23206 +static void au_ren_refresh_dir(struct au_ren_args *a)
23208 + struct inode *dir;
23210 + dir = a->dst_dir;
23211 + inode_inc_iversion(dir);
23212 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
23213 + /* is this updating defined in POSIX? */
23214 + au_cpup_attr_timesizes(a->src_inode);
23215 + au_cpup_attr_nlink(dir, /*force*/1);
23217 + au_dir_ts(dir, a->btgt);
23219 + if (a->exchange) {
23220 + dir = a->src_dir;
23221 + inode_inc_iversion(dir);
23222 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23223 + /* is this updating defined in POSIX? */
23224 + au_cpup_attr_timesizes(a->dst_inode);
23225 + au_cpup_attr_nlink(dir, /*force*/1);
23227 + au_dir_ts(dir, a->btgt);
23230 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23233 + dir = a->src_dir;
23234 + inode_inc_iversion(dir);
23235 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
23236 + au_cpup_attr_nlink(dir, /*force*/1);
23237 + au_dir_ts(dir, a->btgt);
23240 +static void au_ren_refresh(struct au_ren_args *a)
23242 + aufs_bindex_t bbot, bindex;
23243 + struct dentry *d, *h_d;
23244 + struct inode *i, *h_i;
23245 + struct super_block *sb;
23247 + d = a->dst_dentry;
23250 + /* already dget-ed by au_ren_or_cpup() */
23251 + au_set_h_dptr(d, a->btgt, a->h_dst);
23253 + i = a->dst_inode;
23255 + if (!a->exchange) {
23256 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
23257 + vfsub_drop_nlink(i);
23259 + vfsub_dead_dir(i);
23260 + au_cpup_attr_timesizes(i);
23262 + au_update_dbrange(d, /*do_put_zero*/1);
23264 + au_cpup_attr_nlink(i, /*force*/1);
23267 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
23268 + au_set_h_dptr(d, bindex, NULL);
23269 + bbot = au_dbbot(d);
23270 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
23271 + au_set_h_dptr(d, bindex, NULL);
23272 + au_update_dbrange(d, /*do_put_zero*/0);
23276 + || au_ftest_ren(a->auren_flags, DIRREN)) {
23277 + d_drop(a->src_dentry);
23278 + if (au_ftest_ren(a->auren_flags, DIRREN))
23279 + au_set_dbwh(a->src_dentry, -1);
23283 + d = a->src_dentry;
23284 + au_set_dbwh(d, -1);
23285 + bbot = au_dbbot(d);
23286 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23287 + h_d = au_h_dptr(d, bindex);
23289 + au_set_h_dptr(d, bindex, NULL);
23291 + au_set_dbbot(d, a->btgt);
23294 + i = a->src_inode;
23295 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
23296 + return; /* success */
23298 + bbot = au_ibbot(i);
23299 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
23300 + h_i = au_h_iptr(i, bindex);
23302 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
23303 + /* ignore this error */
23304 + au_set_h_iptr(i, bindex, NULL, 0);
23307 + au_set_ibbot(i, a->btgt);
23310 +/* ---------------------------------------------------------------------- */
23312 +/* mainly for link(2) and rename(2) */
23313 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
23315 + aufs_bindex_t bdiropq, bwh;
23316 + struct dentry *parent;
23317 + struct au_branch *br;
23319 + parent = dentry->d_parent;
23320 + IMustLock(d_inode(parent)); /* dir is locked */
23322 + bdiropq = au_dbdiropq(parent);
23323 + bwh = au_dbwh(dentry);
23324 + br = au_sbr(dentry->d_sb, btgt);
23325 + if (au_br_rdonly(br)
23326 + || (0 <= bdiropq && bdiropq < btgt)
23327 + || (0 <= bwh && bwh < btgt))
23330 + AuDbg("btgt %d\n", btgt);
23334 +/* sets src_btop, dst_btop and btgt */
23335 +static int au_ren_wbr(struct au_ren_args *a)
23338 + struct au_wr_dir_args wr_dir_args = {
23339 + /* .force_btgt = -1, */
23340 + .flags = AuWrDir_ADD_ENTRY
23343 + a->src_btop = au_dbtop(a->src_dentry);
23344 + a->dst_btop = au_dbtop(a->dst_dentry);
23345 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
23346 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
23347 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
23348 + wr_dir_args.force_btgt = a->src_btop;
23349 + if (a->dst_inode && a->dst_btop < a->src_btop)
23350 + wr_dir_args.force_btgt = a->dst_btop;
23351 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
23352 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
23355 + au_update_dbtop(a->dst_dentry);
23360 +static void au_ren_dt(struct au_ren_args *a)
23362 + a->h_path.dentry = a->src_h_parent;
23363 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
23364 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
23365 + a->h_path.dentry = a->dst_h_parent;
23366 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
23369 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
23370 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
23374 + a->h_path.dentry = a->src_h_dentry;
23375 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
23376 + if (d_is_positive(a->dst_h_dentry)) {
23377 + au_fset_ren(a->auren_flags, DT_DSTDIR);
23378 + a->h_path.dentry = a->dst_h_dentry;
23379 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
23383 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
23385 + struct dentry *h_d;
23386 + struct inode *h_inode;
23388 + au_dtime_revert(a->src_dt + AuPARENT);
23389 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
23390 + au_dtime_revert(a->dst_dt + AuPARENT);
23392 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
23393 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
23394 + h_inode = d_inode(h_d);
23395 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23396 + au_dtime_revert(a->src_dt + AuCHILD);
23397 + inode_unlock(h_inode);
23399 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
23400 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
23401 + h_inode = d_inode(h_d);
23402 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
23403 + au_dtime_revert(a->dst_dt + AuCHILD);
23404 + inode_unlock(h_inode);
23409 +/* ---------------------------------------------------------------------- */
23411 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
23412 + struct inode *_dst_dir, struct dentry *_dst_dentry,
23413 + unsigned int _flags)
23415 + int err, lock_flags;
23417 + /* reduce stack space */
23418 + struct au_ren_args *a;
23419 + struct au_pin pin;
23421 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
23422 + IMustLock(_src_dir);
23423 + IMustLock(_dst_dir);
23426 + if (unlikely(_flags & RENAME_WHITEOUT))
23430 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
23431 + a = kzalloc(sizeof(*a), GFP_NOFS);
23432 + if (unlikely(!a))
23435 + a->flags = _flags;
23436 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
23437 + && RENAME_EXCHANGE > U8_MAX);
23438 + a->exchange = _flags & RENAME_EXCHANGE;
23439 + a->src_dir = _src_dir;
23440 + a->src_dentry = _src_dentry;
23441 + a->src_inode = NULL;
23442 + if (d_really_is_positive(a->src_dentry))
23443 + a->src_inode = d_inode(a->src_dentry);
23444 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
23445 + a->dst_dir = _dst_dir;
23446 + a->dst_dentry = _dst_dentry;
23447 + a->dst_inode = NULL;
23448 + if (d_really_is_positive(a->dst_dentry))
23449 + a->dst_inode = d_inode(a->dst_dentry);
23450 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
23451 + if (a->dst_inode) {
23453 + * if EXCHANGE && src is non-dir && dst is dir,
23454 + * dst is not locked.
23456 + /* IMustLock(a->dst_inode); */
23457 + au_igrab(a->dst_inode);
23461 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
23462 + if (d_is_dir(a->src_dentry)) {
23463 + au_fset_ren(a->auren_flags, ISDIR_SRC);
23464 + if (unlikely(!a->exchange
23465 + && d_really_is_positive(a->dst_dentry)
23466 + && !d_is_dir(a->dst_dentry)))
23468 + lock_flags |= AuLock_DIRS;
23470 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
23471 + au_fset_ren(a->auren_flags, ISDIR_DST);
23472 + if (unlikely(!a->exchange
23473 + && d_really_is_positive(a->src_dentry)
23474 + && !d_is_dir(a->src_dentry)))
23476 + lock_flags |= AuLock_DIRS;
23478 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
23480 + if (unlikely(err))
23483 + err = au_d_hashed_positive(a->src_dentry);
23484 + if (unlikely(err))
23487 + if (a->dst_inode) {
23489 + * If it is a dir, VFS unhash it before this
23490 + * function. It means we cannot rely upon d_unhashed().
23492 + if (unlikely(!a->dst_inode->i_nlink))
23494 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
23495 + err = au_d_hashed_positive(a->dst_dentry);
23496 + if (unlikely(err && !a->exchange))
23498 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
23500 + } else if (unlikely(d_unhashed(a->dst_dentry)))
23504 + * is it possible?
23505 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
23506 + * there may exist a problem somewhere else.
23509 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
23512 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
23513 + di_write_lock_parent(a->dst_parent);
23515 + /* which branch we process */
23516 + err = au_ren_wbr(a);
23517 + if (unlikely(err < 0))
23519 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
23520 + a->h_path.mnt = au_br_mnt(a->br);
23522 + /* are they available to be renamed */
23523 + err = au_ren_may_dir(a);
23524 + if (unlikely(err))
23525 + goto out_children;
23527 + /* prepare the writable parent dir on the same branch */
23528 + if (a->dst_btop == a->btgt) {
23529 + au_fset_ren(a->auren_flags, WHDST);
23531 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
23532 + if (unlikely(err))
23533 + goto out_children;
23537 + if (!a->exchange) {
23538 + if (a->src_dir != a->dst_dir) {
23540 + * this temporary unlock is safe,
23541 + * because both dir->i_mutex are locked.
23543 + di_write_unlock(a->dst_parent);
23544 + di_write_lock_parent(a->src_parent);
23545 + err = au_wr_dir_need_wh(a->src_dentry,
23546 + au_ftest_ren(a->auren_flags,
23549 + di_write_unlock(a->src_parent);
23550 + di_write_lock2_parent(a->src_parent, a->dst_parent,
23552 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
23554 + err = au_wr_dir_need_wh(a->src_dentry,
23555 + au_ftest_ren(a->auren_flags,
23559 + if (unlikely(err < 0))
23560 + goto out_children;
23562 + au_fset_ren(a->auren_flags, WHSRC);
23565 + if (a->src_btop != a->btgt) {
23566 + err = au_pin(&pin, a->src_dentry, a->btgt,
23567 + au_opt_udba(a->src_dentry->d_sb),
23568 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23570 + struct au_cp_generic cpg = {
23571 + .dentry = a->src_dentry,
23573 + .bsrc = a->src_btop,
23576 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23578 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
23579 + err = au_sio_cpup_simple(&cpg);
23582 + if (unlikely(err))
23583 + goto out_children;
23584 + a->src_btop = a->btgt;
23585 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
23586 + if (!a->exchange)
23587 + au_fset_ren(a->auren_flags, WHSRC);
23591 + if (a->exchange && a->dst_inode
23592 + && a->dst_btop != a->btgt) {
23593 + err = au_pin(&pin, a->dst_dentry, a->btgt,
23594 + au_opt_udba(a->dst_dentry->d_sb),
23595 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23597 + struct au_cp_generic cpg = {
23598 + .dentry = a->dst_dentry,
23600 + .bsrc = a->dst_btop,
23603 + .flags = AuCpup_DTIME | AuCpup_HOPEN
23605 + err = au_sio_cpup_simple(&cpg);
23608 + if (unlikely(err))
23609 + goto out_children;
23610 + a->dst_btop = a->btgt;
23611 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
23614 + /* lock them all */
23615 + err = au_ren_lock(a);
23616 + if (unlikely(err))
23617 + /* leave the copied-up one */
23618 + goto out_children;
23620 + if (!a->exchange) {
23621 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
23622 + err = au_may_ren(a);
23623 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
23624 + err = -ENAMETOOLONG;
23625 + if (unlikely(err))
23629 + /* store timestamps to be revertible */
23632 + /* store dirren info */
23633 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
23634 + err = au_dr_rename(a->src_dentry, a->btgt,
23635 + &a->dst_dentry->d_name, &rev);
23637 + if (unlikely(err))
23642 + err = do_rename(a);
23643 + if (unlikely(err))
23646 + if (au_ftest_ren(a->auren_flags, DIRREN))
23647 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
23649 + /* update dir attributes */
23650 + au_ren_refresh_dir(a);
23652 + /* dput/iput all lower dentries */
23653 + au_ren_refresh(a);
23655 + goto out_hdir; /* success */
23658 + if (au_ftest_ren(a->auren_flags, DIRREN))
23659 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
23661 + au_ren_rev_dt(err, a);
23663 + au_ren_unlock(a);
23665 + au_nhash_wh_free(&a->whlist);
23666 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
23667 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
23668 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
23669 + au_set_dbtop(a->dst_dentry, a->dst_btop);
23673 + if (d_unhashed(a->src_dentry))
23674 + au_fset_ren(a->auren_flags, DROPPED_SRC);
23675 + if (d_unhashed(a->dst_dentry))
23676 + au_fset_ren(a->auren_flags, DROPPED_DST);
23677 + if (!a->exchange)
23678 + d_move(a->src_dentry, a->dst_dentry);
23680 + d_exchange(a->src_dentry, a->dst_dentry);
23681 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
23682 + d_drop(a->dst_dentry);
23684 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
23685 + d_drop(a->src_dentry);
23687 + au_update_dbtop(a->dst_dentry);
23688 + if (!a->dst_inode)
23689 + d_drop(a->dst_dentry);
23691 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
23692 + di_write_unlock(a->dst_parent);
23694 + di_write_unlock2(a->src_parent, a->dst_parent);
23696 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
23698 + iput(a->dst_inode);
23700 + au_whtmp_rmdir_free(a->thargs);
23706 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
23707 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
23708 +++ linux/fs/aufs/Kconfig 2021-12-03 15:38:59.929980643 +0100
23710 +# SPDX-License-Identifier: GPL-2.0
23712 + tristate "Aufs (Advanced multi layered unification filesystem) support"
23714 + Aufs is a stackable unification filesystem such as Unionfs,
23715 + which unifies several directories and provides a merged single
23717 + In the early days, aufs was entirely re-designed and
23718 + re-implemented Unionfs Version 1.x series. Introducing many
23719 + original ideas, approaches and improvements, it becomes totally
23720 + different from Unionfs while keeping the basic features.
23724 + prompt "Maximum number of branches"
23725 + default AUFS_BRANCH_MAX_127
23727 + Specifies the maximum number of branches (or member directories)
23728 + in a single aufs. The larger value consumes more system
23729 + resources and has a minor impact to performance.
23730 +config AUFS_BRANCH_MAX_127
23733 + Specifies the maximum number of branches (or member directories)
23734 + in a single aufs. The larger value consumes more system
23735 + resources and has a minor impact to performance.
23736 +config AUFS_BRANCH_MAX_511
23739 + Specifies the maximum number of branches (or member directories)
23740 + in a single aufs. The larger value consumes more system
23741 + resources and has a minor impact to performance.
23742 +config AUFS_BRANCH_MAX_1023
23745 + Specifies the maximum number of branches (or member directories)
23746 + in a single aufs. The larger value consumes more system
23747 + resources and has a minor impact to performance.
23748 +config AUFS_BRANCH_MAX_32767
23751 + Specifies the maximum number of branches (or member directories)
23752 + in a single aufs. The larger value consumes more system
23753 + resources and has a minor impact to performance.
23756 +config AUFS_SBILIST
23758 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
23761 + Automatic configuration for internal use.
23762 + When aufs supports Magic SysRq or /proc, enabled automatically.
23764 +config AUFS_HNOTIFY
23765 + bool "Detect direct branch access (bypassing aufs)"
23767 + If you want to modify files on branches directly, eg. bypassing aufs,
23768 + and want aufs to detect the changes of them fully, then enable this
23769 + option and use 'udba=notify' mount option.
23770 + Currently there is only one available configuration, "fsnotify".
23771 + It will have a negative impact to the performance.
23772 + See detail in aufs.5.
23775 + prompt "method" if AUFS_HNOTIFY
23776 + default AUFS_HFSNOTIFY
23777 +config AUFS_HFSNOTIFY
23782 +config AUFS_EXPORT
23783 + bool "NFS-exportable aufs"
23784 + depends on EXPORTFS
23786 + If you want to export your mounted aufs via NFS, then enable this
23787 + option. There are several requirements for this configuration.
23788 + See detail in aufs.5.
23790 +config AUFS_INO_T_64
23792 + depends on AUFS_EXPORT
23793 + depends on 64BIT && !(ALPHA || S390)
23796 + Automatic configuration for internal use.
23797 + /* typedef unsigned long/int __kernel_ino_t */
23798 + /* alpha and s390x are int */
23801 + bool "support for XATTR/EA (including Security Labels)"
23803 + If your branch fs supports XATTR/EA and you want to make them
23804 + available in aufs too, then enable this opsion and specify the
23805 + branch attributes for EA.
23806 + See detail in aufs.5.
23809 + bool "File-based Hierarchical Storage Management"
23811 + Hierarchical Storage Management (or HSM) is a well-known feature
23812 + in the storage world. Aufs provides this feature as file-based.
23813 + with multiple branches.
23814 + These multiple branches are prioritized, ie. the topmost one
23815 + should be the fastest drive and be used heavily.
23818 + bool "Readdir in userspace"
23820 + Aufs has two methods to provide a merged view for a directory,
23821 + by a user-space library and by kernel-space natively. The latter
23822 + is always enabled but sometimes large and slow.
23823 + If you enable this option, install the library in aufs2-util
23824 + package, and set some environment variables for your readdir(3),
23825 + then the work will be handled in user-space which generally
23826 + shows better performance in most cases.
23827 + See detail in aufs.5.
23829 +config AUFS_DIRREN
23830 + bool "Workaround for rename(2)-ing a directory"
23832 + By default, aufs returns EXDEV error in renameing a dir who has
23833 + his child on the lower branch, since it is a bad idea to issue
23834 + rename(2) internally for every lower branch. But user may not
23835 + accept this behaviour. So here is a workaround to allow such
23836 + rename(2) and store some extra infromation on the writable
23837 + branch. Obviously this costs high (and I don't like it).
23838 + To use this feature, you need to enable this configuration AND
23839 + to specify the mount option `dirren.'
23840 + See details in aufs.5 and the design documents.
23843 + bool "Show whiteouts"
23845 + If you want to make the whiteouts in aufs visible, then enable
23846 + this option and specify 'shwh' mount option. Although it may
23847 + sounds like philosophy or something, but in technically it
23848 + simply shows the name of whiteout with keeping its behaviour.
23850 +config AUFS_BR_RAMFS
23851 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
23853 + If you want to use ramfs as an aufs branch fs, then enable this
23854 + option. Generally tmpfs is recommended.
23855 + Aufs prohibited them to be a branch fs by default, because
23856 + initramfs becomes unusable after switch_root or something
23857 + generally. If you sets initramfs as an aufs branch and boot your
23858 + system by switch_root, you will meet a problem easily since the
23859 + files in initramfs may be inaccessible.
23860 + Unless you are going to use ramfs as an aufs branch fs without
23861 + switch_root or something, leave it N.
23863 +config AUFS_BR_FUSE
23864 + bool "Fuse fs as an aufs branch"
23865 + depends on FUSE_FS
23868 + If you want to use fuse-based userspace filesystem as an aufs
23869 + branch fs, then enable this option.
23870 + It implements the internal poll(2) operation which is
23871 + implemented by fuse only (curretnly).
23876 + Automatic configuration for internal use.
23878 +config AUFS_BR_HFSPLUS
23879 + bool "Hfsplus as an aufs branch"
23880 + depends on HFSPLUS_FS
23883 + If you want to use hfsplus fs as an aufs branch fs, then enable
23884 + this option. This option introduces a small overhead at
23885 + copying-up a file on hfsplus.
23887 +config AUFS_BDEV_LOOP
23889 + depends on BLK_DEV_LOOP
23892 + Automatic configuration for internal use.
23893 + Convert =[ym] into =y.
23896 + bool "Debug aufs"
23898 + Enable this to compile aufs internal debug code.
23899 + It will have a negative impact to the performance.
23901 +config AUFS_MAGIC_SYSRQ
23903 + depends on AUFS_DEBUG && MAGIC_SYSRQ
23906 + Automatic configuration for internal use.
23907 + When aufs supports Magic SysRq, enabled automatically.
23909 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
23910 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
23911 +++ linux/fs/aufs/lcnt.h 2021-12-03 15:38:59.936647310 +0100
23913 +/* SPDX-License-Identifier: GPL-2.0 */
23915 + * Copyright (C) 2018-2021 Junjiro R. Okajima
23917 + * This program, aufs is free software; you can redistribute it and/or modify
23918 + * it under the terms of the GNU General Public License as published by
23919 + * the Free Software Foundation; either version 2 of the License, or
23920 + * (at your option) any later version.
23922 + * This program is distributed in the hope that it will be useful,
23923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23925 + * GNU General Public License for more details.
23927 + * You should have received a copy of the GNU General Public License
23928 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23932 + * simple long counter wrapper
23935 +#ifndef __AUFS_LCNT_H__
23936 +#define __AUFS_LCNT_H__
23940 +#include "debug.h"
23942 +#define AuLCntATOMIC 1
23943 +#define AuLCntPCPUCNT 2
23945 + * why does percpu_refcount require extra synchronize_rcu()s in
23946 + * au_br_do_free()
23948 +#define AuLCntPCPUREF 3
23950 +/* #define AuLCntChosen AuLCntATOMIC */
23951 +#define AuLCntChosen AuLCntPCPUCNT
23952 +/* #define AuLCntChosen AuLCntPCPUREF */
23954 +#if AuLCntChosen == AuLCntATOMIC
23955 +#include <linux/atomic.h>
23957 +typedef atomic_long_t au_lcnt_t;
23959 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23961 + atomic_long_set(cnt, 0);
23965 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
23970 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
23971 + int do_sync __maybe_unused)
23976 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
23978 + atomic_long_inc(cnt);
23981 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
23983 + atomic_long_dec(cnt);
23986 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
23988 + return atomic_long_read(cnt);
23992 +#if AuLCntChosen == AuLCntPCPUCNT
23993 +#include <linux/percpu_counter.h>
23995 +typedef struct percpu_counter au_lcnt_t;
23997 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
23999 + return percpu_counter_init(cnt, 0, GFP_NOFS);
24002 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24007 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
24009 + percpu_counter_destroy(cnt);
24012 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24014 + percpu_counter_inc(cnt);
24017 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24019 + percpu_counter_dec(cnt);
24022 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
24026 + n = percpu_counter_sum(cnt);
24028 + if (LONG_MAX != LLONG_MAX
24030 + AuWarn1("%s\n", "wrap-around");
24036 +#if AuLCntChosen == AuLCntPCPUREF
24037 +#include <linux/percpu-refcount.h>
24039 +typedef struct percpu_ref au_lcnt_t;
24041 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
24044 + release = percpu_ref_exit;
24045 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
24048 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
24050 + synchronize_rcu();
24053 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
24055 + percpu_ref_kill(cnt);
24057 + au_lcnt_wait_for_fin(cnt);
24060 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
24062 + percpu_ref_get(cnt);
24065 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
24067 + percpu_ref_put(cnt);
24071 + * avoid calling this func as possible.
24073 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
24077 + percpu_ref_switch_to_atomic_sync(cnt);
24078 + l = atomic_long_read(&cnt->count);
24080 + percpu_ref_switch_to_percpu(cnt);
24082 + /* percpu_ref is initialized by 1 instead of 0 */
24087 +#ifdef CONFIG_AUFS_DEBUG
24088 +#define AuLCntZero(val) do { \
24091 + AuDbg("%s = %ld\n", #val, l); \
24094 +#define AuLCntZero(val) do {} while (0)
24097 +#endif /* __KERNEL__ */
24098 +#endif /* __AUFS_LCNT_H__ */
24099 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
24100 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
24101 +++ linux/fs/aufs/loop.c 2021-12-03 15:38:59.936647310 +0100
24103 +// SPDX-License-Identifier: GPL-2.0
24105 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24107 + * This program, aufs is free software; you can redistribute it and/or modify
24108 + * it under the terms of the GNU General Public License as published by
24109 + * the Free Software Foundation; either version 2 of the License, or
24110 + * (at your option) any later version.
24112 + * This program is distributed in the hope that it will be useful,
24113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24115 + * GNU General Public License for more details.
24117 + * You should have received a copy of the GNU General Public License
24118 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24122 + * support for loopback block device as a branch
24127 +/* added into drivers/block/loop.c */
24128 +static struct file *(*backing_file_func)(struct super_block *sb);
24131 + * test if two lower dentries have overlapping branches.
24133 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
24135 + struct super_block *h_sb;
24136 + struct file *backing_file;
24138 + if (unlikely(!backing_file_func)) {
24139 + /* don't load "loop" module here */
24140 + backing_file_func = symbol_get(loop_backing_file);
24141 + if (unlikely(!backing_file_func))
24142 + /* "loop" module is not loaded */
24146 + h_sb = h_adding->d_sb;
24147 + backing_file = backing_file_func(h_sb);
24148 + if (!backing_file)
24151 + h_adding = backing_file->f_path.dentry;
24153 + * h_adding can be local NFS.
24154 + * in this case aufs cannot detect the loop.
24156 + if (unlikely(h_adding->d_sb == sb))
24158 + return !!au_test_subdir(h_adding, sb->s_root);
24161 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
24162 +int au_test_loopback_kthread(void)
24165 + struct task_struct *tsk = current;
24166 + char c, comm[sizeof(tsk->comm)];
24169 + if (tsk->flags & PF_KTHREAD) {
24170 + get_task_comm(comm, tsk);
24172 + ret = ('0' <= c && c <= '9'
24173 + && !strncmp(comm, "loop", 4));
24179 +/* ---------------------------------------------------------------------- */
24181 +#define au_warn_loopback_step 16
24182 +static int au_warn_loopback_nelem = au_warn_loopback_step;
24183 +static unsigned long *au_warn_loopback_array;
24185 +void au_warn_loopback(struct super_block *h_sb)
24187 + int i, new_nelem;
24188 + unsigned long *a, magic;
24189 + static DEFINE_SPINLOCK(spin);
24191 + magic = h_sb->s_magic;
24192 + spin_lock(&spin);
24193 + a = au_warn_loopback_array;
24194 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
24195 + if (a[i] == magic) {
24196 + spin_unlock(&spin);
24200 + /* h_sb is new to us, print it */
24201 + if (i < au_warn_loopback_nelem) {
24206 + /* expand the array */
24207 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
24208 + a = au_kzrealloc(au_warn_loopback_array,
24209 + au_warn_loopback_nelem * sizeof(unsigned long),
24210 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
24211 + /*may_shrink*/0);
24213 + au_warn_loopback_nelem = new_nelem;
24214 + au_warn_loopback_array = a;
24219 + spin_unlock(&spin);
24220 + AuWarn1("realloc failed, ignored\n");
24224 + spin_unlock(&spin);
24225 + pr_warn("you may want to try another patch for loopback file "
24226 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
24229 +int au_loopback_init(void)
24232 + struct super_block *sb __maybe_unused;
24234 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
24237 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
24238 + sizeof(unsigned long), GFP_NOFS);
24239 + if (unlikely(!au_warn_loopback_array))
24245 +void au_loopback_fin(void)
24247 + if (backing_file_func)
24248 + symbol_put(loop_backing_file);
24249 + au_kfree_try_rcu(au_warn_loopback_array);
24251 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
24252 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
24253 +++ linux/fs/aufs/loop.h 2021-12-03 15:38:59.936647310 +0100
24255 +/* SPDX-License-Identifier: GPL-2.0 */
24257 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24259 + * This program, aufs is free software; you can redistribute it and/or modify
24260 + * it under the terms of the GNU General Public License as published by
24261 + * the Free Software Foundation; either version 2 of the License, or
24262 + * (at your option) any later version.
24264 + * This program is distributed in the hope that it will be useful,
24265 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24266 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24267 + * GNU General Public License for more details.
24269 + * You should have received a copy of the GNU General Public License
24270 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24274 + * support for loopback mount as a branch
24277 +#ifndef __AUFS_LOOP_H__
24278 +#define __AUFS_LOOP_H__
24283 +struct super_block;
24285 +#ifdef CONFIG_AUFS_BDEV_LOOP
24286 +/* drivers/block/loop.c */
24287 +struct file *loop_backing_file(struct super_block *sb);
24290 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
24291 +int au_test_loopback_kthread(void);
24292 +void au_warn_loopback(struct super_block *h_sb);
24294 +int au_loopback_init(void);
24295 +void au_loopback_fin(void);
24297 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
24299 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
24300 + struct dentry *h_adding)
24301 +AuStubInt0(au_test_loopback_kthread, void)
24302 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
24304 +AuStubInt0(au_loopback_init, void)
24305 +AuStubVoid(au_loopback_fin, void)
24306 +#endif /* BLK_DEV_LOOP */
24308 +#endif /* __KERNEL__ */
24309 +#endif /* __AUFS_LOOP_H__ */
24310 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
24311 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
24312 +++ linux/fs/aufs/magic.mk 2021-12-03 15:38:59.936647310 +0100
24314 +# SPDX-License-Identifier: GPL-2.0
24316 +# defined in ${srctree}/fs/fuse/inode.c
24318 +ifdef CONFIG_FUSE_FS
24319 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
24322 +# defined in ${srctree}/fs/xfs/xfs_sb.h
24324 +ifdef CONFIG_XFS_FS
24325 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
24328 +# defined in ${srctree}/fs/configfs/mount.c
24330 +ifdef CONFIG_CONFIGFS_FS
24331 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
24334 +# defined in ${srctree}/fs/ubifs/ubifs.h
24336 +ifdef CONFIG_UBIFS_FS
24337 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
24340 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
24342 +ifdef CONFIG_HFSPLUS_FS
24343 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
24345 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
24346 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
24347 +++ linux/fs/aufs/Makefile 2021-12-03 15:38:59.929980643 +0100
24349 +# SPDX-License-Identifier: GPL-2.0
24351 +include ${src}/magic.mk
24352 +ifeq (${CONFIG_AUFS_FS},m)
24353 +include ${src}/conf.mk
24355 +-include ${src}/priv_def.mk
24357 +# cf. include/linux/kernel.h
24359 +ccflags-y += -DDEBUG
24360 +# sparse requires the full pathname
24362 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
24364 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
24367 +obj-$(CONFIG_AUFS_FS) += aufs.o
24368 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
24369 + wkq.o vfsub.o dcsub.o \
24370 + cpup.o whout.o wbr_policy.o \
24371 + dinfo.o dentry.o \
24373 + finfo.o file.o f_op.o \
24375 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
24379 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
24380 +aufs-$(CONFIG_SYSFS) += sysfs.o
24381 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
24382 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
24383 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
24384 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
24385 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
24386 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
24387 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
24388 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
24389 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
24390 +aufs-$(CONFIG_AUFS_POLL) += poll.o
24391 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
24392 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
24393 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
24394 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
24395 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
24396 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
24397 +++ linux/fs/aufs/module.c 2021-12-03 15:38:59.936647310 +0100
24399 +// SPDX-License-Identifier: GPL-2.0
24401 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24403 + * This program, aufs is free software; you can redistribute it and/or modify
24404 + * it under the terms of the GNU General Public License as published by
24405 + * the Free Software Foundation; either version 2 of the License, or
24406 + * (at your option) any later version.
24408 + * This program is distributed in the hope that it will be useful,
24409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24411 + * GNU General Public License for more details.
24413 + * You should have received a copy of the GNU General Public License
24414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24418 + * module global variables and operations
24421 +#include <linux/module.h>
24422 +#include <linux/seq_file.h>
24425 +/* shrinkable realloc */
24426 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
24434 +#if 0 /* unused */
24441 + AuDebugOn(!new_sz);
24444 + diff = au_kmidx_sub(sz, new_sz);
24450 + /* expand or SLOB */
24451 + p = krealloc(p, new_sz, gfp);
24452 + else if (new_sz < sz && may_shrink) {
24456 + q = kmalloc(new_sz, gfp);
24459 + memcpy(q, p, new_sz);
24460 + au_kfree_try_rcu(p);
24471 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24474 + p = au_krealloc(p, new_sz, gfp, may_shrink);
24475 + if (p && new_sz > nused)
24476 + memset(p + nused, 0, new_sz - nused);
24480 +/* ---------------------------------------------------------------------- */
24484 +struct kmem_cache *au_cache[AuCache_Last];
24486 +static void au_cache_fin(void)
24491 + * Make sure all delayed rcu free inodes are flushed before we
24496 + /* excluding AuCache_HNOTIFY */
24497 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
24498 + for (i = 0; i < AuCache_HNOTIFY; i++) {
24499 + kmem_cache_destroy(au_cache[i]);
24500 + au_cache[i] = NULL;
24504 +static int __init au_cache_init(void)
24506 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
24507 + if (au_cache[AuCache_DINFO])
24508 + /* SLAB_DESTROY_BY_RCU */
24509 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
24510 + au_icntnr_init_once);
24511 + if (au_cache[AuCache_ICNTNR])
24512 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
24513 + au_fi_init_once);
24514 + if (au_cache[AuCache_FINFO])
24515 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
24516 + if (au_cache[AuCache_VDIR])
24517 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
24518 + if (au_cache[AuCache_DEHSTR])
24525 +/* ---------------------------------------------------------------------- */
24527 +int au_dir_roflags;
24529 +#ifdef CONFIG_AUFS_SBILIST
24531 + * iterate_supers_type() doesn't protect us from
24532 + * remounting (branch management)
24534 +struct hlist_bl_head au_sbilist;
24538 + * functions for module interface.
24540 +MODULE_LICENSE("GPL");
24541 +/* MODULE_LICENSE("GPL v2"); */
24542 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
24543 +MODULE_DESCRIPTION(AUFS_NAME
24544 + " -- Advanced multi layered unification filesystem");
24545 +MODULE_VERSION(AUFS_VERSION);
24546 +MODULE_ALIAS_FS(AUFS_NAME);
24548 +/* this module parameter has no meaning when SYSFS is disabled */
24549 +int sysaufs_brs = 1;
24550 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
24551 +module_param_named(brs, sysaufs_brs, int, 0444);
24553 +/* this module parameter has no meaning when USER_NS is disabled */
24555 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
24556 +module_param_named(allow_userns, au_userns, bool, 0444);
24558 +/* ---------------------------------------------------------------------- */
24560 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
24562 +int au_seq_path(struct seq_file *seq, struct path *path)
24566 + err = seq_path(seq, path, au_esc_chars);
24575 +/* ---------------------------------------------------------------------- */
24577 +static int __init aufs_init(void)
24582 + p = au_esc_chars;
24583 + for (i = 1; i <= ' '; i++)
24589 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
24591 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
24592 + for (i = 0; i < AuIop_Last; i++)
24593 + aufs_iop_nogetattr[i].getattr = NULL;
24595 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
24597 + au_sbilist_init();
24598 + sysaufs_brs_init();
24601 + err = sysaufs_init();
24602 + if (unlikely(err))
24604 + err = dbgaufs_init();
24605 + if (unlikely(err))
24606 + goto out_sysaufs;
24607 + err = au_procfs_init();
24608 + if (unlikely(err))
24609 + goto out_dbgaufs;
24610 + err = au_wkq_init();
24611 + if (unlikely(err))
24613 + err = au_loopback_init();
24614 + if (unlikely(err))
24616 + err = au_hnotify_init();
24617 + if (unlikely(err))
24618 + goto out_loopback;
24619 + err = au_sysrq_init();
24620 + if (unlikely(err))
24622 + err = au_cache_init();
24623 + if (unlikely(err))
24626 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
24627 + err = register_filesystem(&aufs_fs_type);
24628 + if (unlikely(err))
24631 + /* since we define pr_fmt, call printk directly */
24632 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
24633 + goto out; /* success */
24640 + au_hnotify_fin();
24642 + au_loopback_fin();
24656 +static void __exit aufs_exit(void)
24658 + unregister_filesystem(&aufs_fs_type);
24661 + au_hnotify_fin();
24662 + au_loopback_fin();
24670 +module_init(aufs_init);
24671 +module_exit(aufs_exit);
24672 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
24673 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
24674 +++ linux/fs/aufs/module.h 2021-12-03 15:38:59.936647310 +0100
24676 +/* SPDX-License-Identifier: GPL-2.0 */
24678 + * Copyright (C) 2005-2021 Junjiro R. Okajima
24680 + * This program, aufs is free software; you can redistribute it and/or modify
24681 + * it under the terms of the GNU General Public License as published by
24682 + * the Free Software Foundation; either version 2 of the License, or
24683 + * (at your option) any later version.
24685 + * This program is distributed in the hope that it will be useful,
24686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24688 + * GNU General Public License for more details.
24690 + * You should have received a copy of the GNU General Public License
24691 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24695 + * module initialization and module-global
24698 +#ifndef __AUFS_MODULE_H__
24699 +#define __AUFS_MODULE_H__
24703 +#include <linux/slab.h>
24704 +#include "debug.h"
24705 +#include "dentry.h"
24708 +#include "inode.h"
24713 +/* module parameters */
24714 +extern int sysaufs_brs;
24715 +extern bool au_userns;
24717 +/* ---------------------------------------------------------------------- */
24719 +extern int au_dir_roflags;
24721 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
24722 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
24726 + * Comparing the size of the object with sizeof(struct rcu_head)
24727 + * case 1: object is always larger
24728 + * --> au_kfree_rcu() or au_kfree_do_rcu()
24729 + * case 2: object is always smaller
24730 + * --> au_kfree_small()
24731 + * case 3: object can be any size
24732 + * --> au_kfree_try_rcu()
24735 +static inline void au_kfree_do_rcu(const void *p)
24738 + struct rcu_head rcu;
24739 + } *a = (void *)p;
24741 + kfree_rcu(a, rcu);
24744 +#define au_kfree_rcu(_p) do { \
24745 + typeof(_p) p = (_p); \
24746 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
24748 + au_kfree_do_rcu(p); \
24751 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
24752 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
24754 +static inline void au_kfree_try_rcu(const void *p)
24758 + if (au_kfree_sz_test(p))
24759 + au_kfree_do_rcu(p);
24764 +static inline void au_kfree_small(const void *p)
24768 + AuDebugOn(au_kfree_sz_test(p));
24772 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
24774 +#ifndef CONFIG_SLOB
24775 + return kmalloc_index(sz) - kmalloc_index(new_sz);
24777 + return -1; /* SLOB is untested */
24781 +int au_seq_path(struct seq_file *seq, struct path *path);
24783 +#ifdef CONFIG_PROC_FS
24785 +int __init au_procfs_init(void);
24786 +void au_procfs_fin(void);
24788 +AuStubInt0(au_procfs_init, void);
24789 +AuStubVoid(au_procfs_fin, void);
24792 +/* ---------------------------------------------------------------------- */
24801 + AuCache_HNOTIFY, /* must be last */
24805 +extern struct kmem_cache *au_cache[AuCache_Last];
24807 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
24808 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
24809 +#define AuCacheCtor(type, ctor) \
24810 + kmem_cache_create(#type, sizeof(struct type), \
24811 + __alignof__(struct type), AuCacheFlags, ctor)
24813 +#define AuCacheFuncs(name, index) \
24814 + static inline struct au_##name *au_cache_alloc_##name(void) \
24815 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \
24816 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
24817 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
24819 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
24820 + { void *p = rcu; \
24821 + p -= offsetof(struct au_##name, rcu); \
24822 + kmem_cache_free(au_cache[AuCache_##index], p); } \
24823 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
24824 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
24825 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
24827 + static inline void au_cache_free_##name(struct au_##name *p) \
24828 + { /* au_cache_free_##name##_norcu(p); */ \
24829 + au_cache_free_##name##_rcu(p); }
24831 +AuCacheFuncs(dinfo, DINFO);
24832 +AuCacheFuncs(icntnr, ICNTNR);
24833 +AuCacheFuncs(finfo, FINFO);
24834 +AuCacheFuncs(vdir, VDIR);
24835 +AuCacheFuncs(vdir_dehstr, DEHSTR);
24836 +#ifdef CONFIG_AUFS_HNOTIFY
24837 +AuCacheFuncs(hnotify, HNOTIFY);
24840 +#endif /* __KERNEL__ */
24841 +#endif /* __AUFS_MODULE_H__ */
24842 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
24843 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
24844 +++ linux/fs/aufs/mvdown.c 2021-12-03 15:38:59.939980643 +0100
24846 +// SPDX-License-Identifier: GPL-2.0
24848 + * Copyright (C) 2011-2021 Junjiro R. Okajima
24850 + * This program, aufs is free software; you can redistribute it and/or modify
24851 + * it under the terms of the GNU General Public License as published by
24852 + * the Free Software Foundation; either version 2 of the License, or
24853 + * (at your option) any later version.
24855 + * This program is distributed in the hope that it will be useful,
24856 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24857 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24858 + * GNU General Public License for more details.
24860 + * You should have received a copy of the GNU General Public License
24861 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24865 + * move-down, opposite of copy-up
24870 +struct au_mvd_args {
24872 + struct super_block *h_sb;
24873 + struct dentry *h_parent;
24874 + struct au_hinode *hdir;
24875 + struct inode *h_dir, *h_inode;
24876 + struct au_pin pin;
24877 + } info[AUFS_MVDOWN_NARRAY];
24879 + struct aufs_mvdown mvdown;
24880 + struct dentry *dentry, *parent;
24881 + struct inode *inode, *dir;
24882 + struct super_block *sb;
24883 + aufs_bindex_t bopq, bwh, bfound;
24884 + unsigned char rename_lock;
24887 +#define mvd_errno mvdown.au_errno
24888 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
24889 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
24890 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
24891 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
24893 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
24894 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
24895 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
24896 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
24897 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
24898 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
24900 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
24901 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
24902 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
24903 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
24904 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
24905 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
24907 +#define AU_MVD_PR(flag, ...) do { \
24909 + pr_err(__VA_ARGS__); \
24912 +static int find_lower_writable(struct au_mvd_args *a)
24914 + struct super_block *sb;
24915 + aufs_bindex_t bindex, bbot;
24916 + struct au_branch *br;
24919 + bindex = a->mvd_bsrc;
24920 + bbot = au_sbbot(sb);
24921 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
24922 + for (bindex++; bindex <= bbot; bindex++) {
24923 + br = au_sbr(sb, bindex);
24924 + if (au_br_fhsm(br->br_perm)
24925 + && !sb_rdonly(au_br_sb(br)))
24928 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
24929 + for (bindex++; bindex <= bbot; bindex++) {
24930 + br = au_sbr(sb, bindex);
24931 + if (!au_br_rdonly(br))
24935 + for (bindex++; bindex <= bbot; bindex++) {
24936 + br = au_sbr(sb, bindex);
24937 + if (!sb_rdonly(au_br_sb(br))) {
24938 + if (au_br_rdonly(br))
24940 + |= AUFS_MVDOWN_ROLOWER_R;
24948 +/* make the parent dir on bdst */
24949 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
24954 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
24955 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
24956 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
24957 + a->mvd_h_dst_parent = NULL;
24958 + if (au_dbbot(a->parent) >= a->mvd_bdst)
24959 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24960 + if (!a->mvd_h_dst_parent) {
24961 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
24962 + if (unlikely(err)) {
24963 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
24966 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
24974 +/* lock them all */
24975 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
24978 + struct dentry *h_trap;
24980 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
24981 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
24982 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
24983 + au_opt_udba(a->sb),
24984 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24986 + if (unlikely(err)) {
24987 + AU_MVD_PR(dmsg, "pin_dst failed\n");
24991 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
24992 + a->rename_lock = 0;
24993 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
24994 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
24995 + au_opt_udba(a->sb),
24996 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
24997 + err = au_do_pin(&a->mvd_pin_src);
24999 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25000 + if (unlikely(err)) {
25001 + AU_MVD_PR(dmsg, "pin_src failed\n");
25004 + goto out; /* success */
25007 + a->rename_lock = 1;
25008 + au_pin_hdir_unlock(&a->mvd_pin_dst);
25009 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
25010 + au_opt_udba(a->sb),
25011 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
25013 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
25014 + if (unlikely(err)) {
25015 + AU_MVD_PR(dmsg, "pin_src failed\n");
25016 + au_pin_hdir_lock(&a->mvd_pin_dst);
25019 + au_pin_hdir_unlock(&a->mvd_pin_src);
25020 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25021 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25023 + err = (h_trap != a->mvd_h_src_parent);
25025 + err = (h_trap != a->mvd_h_dst_parent);
25027 + BUG_ON(err); /* it should never happen */
25028 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
25031 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25032 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25033 + au_pin_hdir_lock(&a->mvd_pin_src);
25034 + au_unpin(&a->mvd_pin_src);
25035 + au_pin_hdir_lock(&a->mvd_pin_dst);
25038 + goto out; /* success */
25041 + au_unpin(&a->mvd_pin_dst);
25047 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
25049 + if (!a->rename_lock)
25050 + au_unpin(&a->mvd_pin_src);
25052 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
25053 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
25054 + au_pin_hdir_lock(&a->mvd_pin_src);
25055 + au_unpin(&a->mvd_pin_src);
25056 + au_pin_hdir_lock(&a->mvd_pin_dst);
25058 + au_unpin(&a->mvd_pin_dst);
25061 +/* copy-down the file */
25062 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
25065 + struct au_cp_generic cpg = {
25066 + .dentry = a->dentry,
25067 + .bdst = a->mvd_bdst,
25068 + .bsrc = a->mvd_bsrc,
25070 + .pin = &a->mvd_pin_dst,
25071 + .flags = AuCpup_DTIME | AuCpup_HOPEN
25074 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
25075 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25076 + au_fset_cpup(cpg.flags, OVERWRITE);
25077 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
25078 + au_fset_cpup(cpg.flags, RWDST);
25079 + err = au_sio_cpdown_simple(&cpg);
25080 + if (unlikely(err))
25081 + AU_MVD_PR(dmsg, "cpdown failed\n");
25088 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
25091 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
25094 + struct path h_path;
25095 + struct au_branch *br;
25096 + struct inode *delegated;
25098 + br = au_sbr(a->sb, a->mvd_bdst);
25099 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
25100 + err = PTR_ERR(h_path.dentry);
25101 + if (IS_ERR(h_path.dentry)) {
25102 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
25107 + if (d_is_positive(h_path.dentry)) {
25108 + h_path.mnt = au_br_mnt(br);
25109 + delegated = NULL;
25110 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
25111 + &delegated, /*force*/0);
25112 + if (unlikely(err == -EWOULDBLOCK)) {
25113 + pr_warn("cannot retry for NFSv4 delegation"
25114 + " for an internal unlink\n");
25117 + if (unlikely(err))
25118 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
25120 + dput(h_path.dentry);
25128 + * unlink the topmost h_dentry
25130 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
25133 + struct path h_path;
25134 + struct inode *delegated;
25136 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
25137 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
25138 + delegated = NULL;
25139 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
25140 + if (unlikely(err == -EWOULDBLOCK)) {
25141 + pr_warn("cannot retry for NFSv4 delegation"
25142 + " for an internal unlink\n");
25145 + if (unlikely(err))
25146 + AU_MVD_PR(dmsg, "unlink failed\n");
25152 +/* Since mvdown succeeded, we ignore an error of this function */
25153 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
25156 + struct au_branch *br;
25158 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
25159 + br = au_sbr(a->sb, a->mvd_bsrc);
25160 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
25162 + br = au_sbr(a->sb, a->mvd_bdst);
25163 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
25164 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
25167 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
25169 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
25173 + * copy-down the file and unlink the bsrc file.
25174 + * - unlink the bdst whout if exist
25175 + * - copy-down the file (with whtmp name and rename)
25176 + * - unlink the bsrc file
25178 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
25182 + err = au_do_mkdir(dmsg, a);
25184 + err = au_do_lock(dmsg, a);
25185 + if (unlikely(err))
25189 + * do not revert the activities we made on bdst since they should be
25190 + * harmless in aufs.
25193 + err = au_do_cpdown(dmsg, a);
25195 + err = au_do_unlink_wh(dmsg, a);
25196 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
25197 + err = au_do_unlink(dmsg, a);
25198 + if (unlikely(err))
25201 + AuDbg("%pd2, 0x%x, %d --> %d\n",
25202 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
25203 + if (find_lower_writable(a) < 0)
25204 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
25206 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
25207 + au_do_stfs(dmsg, a);
25209 + /* maintain internal array */
25210 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
25211 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
25212 + au_set_dbtop(a->dentry, a->mvd_bdst);
25213 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
25214 + au_set_ibtop(a->inode, a->mvd_bdst);
25216 + /* hide the lower */
25217 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
25218 + au_set_dbbot(a->dentry, a->mvd_bsrc);
25219 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
25220 + au_set_ibbot(a->inode, a->mvd_bsrc);
25222 + if (au_dbbot(a->dentry) < a->mvd_bdst)
25223 + au_set_dbbot(a->dentry, a->mvd_bdst);
25224 + if (au_ibbot(a->inode) < a->mvd_bdst)
25225 + au_set_ibbot(a->inode, a->mvd_bdst);
25228 + au_do_unlock(dmsg, a);
25234 +/* ---------------------------------------------------------------------- */
25236 +/* make sure the file is idle */
25237 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
25239 + int err, plinked;
25242 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
25243 + if (au_dbtop(a->dentry) == a->mvd_bsrc
25244 + && au_dcount(a->dentry) == 1
25245 + && atomic_read(&a->inode->i_count) == 1
25246 + /* && a->mvd_h_src_inode->i_nlink == 1 */
25247 + && (!plinked || !au_plink_test(a->inode))
25248 + && a->inode->i_nlink == 1)
25253 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
25254 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
25255 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
25256 + a->mvd_h_src_inode->i_nlink,
25257 + plinked, plinked ? au_plink_test(a->inode) : 0);
25264 +/* make sure the parent dir is fine */
25265 +static int au_mvd_args_parent(const unsigned char dmsg,
25266 + struct au_mvd_args *a)
25269 + aufs_bindex_t bindex;
25272 + if (unlikely(au_alive_dir(a->parent))) {
25274 + AU_MVD_PR(dmsg, "parent dir is dead\n");
25278 + a->bopq = au_dbdiropq(a->parent);
25279 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
25280 + AuDbg("b%d\n", bindex);
25281 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
25282 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
25284 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
25285 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
25286 + a->bopq, a->mvd_bdst);
25294 +static int au_mvd_args_intermediate(const unsigned char dmsg,
25295 + struct au_mvd_args *a)
25298 + struct au_dinfo *dinfo, *tmp;
25300 + /* lookup the next lower positive entry */
25302 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
25303 + if (unlikely(!tmp))
25308 + dinfo = au_di(a->dentry);
25309 + au_di_cp(tmp, dinfo);
25310 + au_di_swap(tmp, dinfo);
25312 + /* returns the number of positive dentries */
25313 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
25314 + /* AuLkup_IGNORE_PERM */ 0);
25316 + a->bwh = au_dbwh(a->dentry);
25317 + else if (err > 0)
25318 + a->bfound = au_dbtop(a->dentry);
25320 + au_di_swap(tmp, dinfo);
25321 + au_rw_write_unlock(&tmp->di_rwsem);
25323 + if (unlikely(err < 0))
25324 + AU_MVD_PR(dmsg, "failed look-up lower\n");
25327 + * here, we have these cases.
25329 + * no positive dentry under bsrc. there are more sub-cases.
25331 + * there no whiteout, we can safely move-down.
25334 + * bsrc < bwh && bwh < bdst
25335 + * there is a whiteout on RO branch. cannot proceed.
25337 + * there is a whiteout on the RW target branch. it should
25340 + * there is a whiteout somewhere unrelated branch.
25341 + * -1 < bfound && bfound <= bsrc
25344 + * found, but it is on RO branch between bsrc and bdst. cannot
25347 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
25350 + * found, after we create the file on bdst, it will be hidden.
25353 + AuDebugOn(a->bfound == -1
25355 + && a->bwh <= a->mvd_bsrc);
25356 + AuDebugOn(-1 < a->bfound
25357 + && a->bfound <= a->mvd_bsrc);
25360 + if (a->bfound == -1
25361 + && a->mvd_bsrc < a->bwh
25363 + && a->bwh < a->mvd_bdst) {
25364 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
25365 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
25366 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
25368 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
25369 + a->mvd_errno = EAU_MVDOWN_UPPER;
25370 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
25371 + a->mvd_bdst, a->bfound);
25375 + err = 0; /* success */
25382 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
25387 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
25388 + && a->bfound == a->mvd_bdst)
25394 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
25397 + struct au_branch *br;
25400 + if (unlikely(S_ISDIR(a->inode->i_mode)))
25404 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
25405 + a->mvd_bsrc = au_ibtop(a->inode);
25407 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
25408 + if (unlikely(a->mvd_bsrc < 0
25409 + || (a->mvd_bsrc < au_dbtop(a->dentry)
25410 + || au_dbbot(a->dentry) < a->mvd_bsrc
25411 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
25412 + || (a->mvd_bsrc < au_ibtop(a->inode)
25413 + || au_ibbot(a->inode) < a->mvd_bsrc
25414 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
25415 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
25416 + AU_MVD_PR(dmsg, "no upper\n");
25420 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
25421 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25422 + AU_MVD_PR(dmsg, "on the bottom\n");
25425 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
25426 + br = au_sbr(a->sb, a->mvd_bsrc);
25427 + err = au_br_rdonly(br);
25428 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
25429 + if (unlikely(err))
25431 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
25432 + || IS_APPEND(a->mvd_h_src_inode))) {
25434 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
25440 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
25441 + a->mvd_bdst = find_lower_writable(a);
25442 + if (unlikely(a->mvd_bdst < 0)) {
25443 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
25444 + AU_MVD_PR(dmsg, "no writable lower branch\n");
25448 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
25449 + if (unlikely(a->mvd_bdst < 0
25450 + || au_sbbot(a->sb) < a->mvd_bdst)) {
25451 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
25452 + AU_MVD_PR(dmsg, "no lower brid\n");
25457 + err = au_mvd_args_busy(dmsg, a);
25459 + err = au_mvd_args_parent(dmsg, a);
25461 + err = au_mvd_args_intermediate(dmsg, a);
25463 + err = au_mvd_args_exist(dmsg, a);
25465 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
25472 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
25475 + unsigned char dmsg;
25476 + struct au_mvd_args *args;
25477 + struct inode *inode;
25479 + inode = d_inode(dentry);
25481 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25485 + args = kmalloc(sizeof(*args), GFP_NOFS);
25486 + if (unlikely(!args))
25489 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
25491 + /* VERIFY_WRITE */
25492 + err = !access_ok(uarg, sizeof(*uarg));
25493 + if (unlikely(err)) {
25498 + AuDbg("flags 0x%x\n", args->mvdown.flags);
25499 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
25500 + args->mvdown.au_errno = 0;
25501 + args->dentry = dentry;
25502 + args->inode = inode;
25503 + args->sb = dentry->d_sb;
25506 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
25507 + args->parent = dget_parent(dentry);
25508 + args->dir = d_inode(args->parent);
25509 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
25510 + dput(args->parent);
25511 + if (unlikely(args->parent != dentry->d_parent)) {
25512 + AU_MVD_PR(dmsg, "parent dir is moved\n");
25516 + inode_lock_nested(inode, I_MUTEX_CHILD);
25517 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
25518 + if (unlikely(err))
25521 + di_write_lock_parent(args->parent);
25522 + err = au_mvd_args(dmsg, args);
25523 + if (unlikely(err))
25526 + err = au_do_mvdown(dmsg, args);
25527 + if (unlikely(err))
25530 + au_cpup_attr_timesizes(args->dir);
25531 + au_cpup_attr_timesizes(inode);
25532 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
25533 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
25534 + /* au_digen_dec(dentry); */
25537 + di_write_unlock(args->parent);
25538 + aufs_read_unlock(dentry, AuLock_DW);
25540 + inode_unlock(inode);
25542 + inode_unlock(args->dir);
25544 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
25547 + au_kfree_rcu(args);
25552 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
25553 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
25554 +++ linux/fs/aufs/opts.c 2021-12-03 15:38:59.939980643 +0100
25556 +// SPDX-License-Identifier: GPL-2.0
25558 + * Copyright (C) 2005-2021 Junjiro R. Okajima
25560 + * This program, aufs is free software; you can redistribute it and/or modify
25561 + * it under the terms of the GNU General Public License as published by
25562 + * the Free Software Foundation; either version 2 of the License, or
25563 + * (at your option) any later version.
25565 + * This program is distributed in the hope that it will be useful,
25566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25568 + * GNU General Public License for more details.
25570 + * You should have received a copy of the GNU General Public License
25571 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25575 + * mount options/flags
25578 +#include <linux/namei.h>
25579 +#include <linux/types.h> /* a distribution requires */
25580 +#include <linux/parser.h>
25583 +/* ---------------------------------------------------------------------- */
25587 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
25588 + Opt_idel, Opt_imod,
25589 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
25590 + Opt_rdblk_def, Opt_rdhash_def,
25591 + Opt_xino, Opt_noxino,
25592 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
25593 + Opt_trunc_xino_path, Opt_itrunc_xino,
25594 + Opt_trunc_xib, Opt_notrunc_xib,
25595 + Opt_shwh, Opt_noshwh,
25596 + Opt_plink, Opt_noplink, Opt_list_plink,
25598 + Opt_dio, Opt_nodio,
25599 + Opt_diropq_a, Opt_diropq_w,
25600 + Opt_warn_perm, Opt_nowarn_perm,
25601 + Opt_wbr_copyup, Opt_wbr_create,
25603 + Opt_verbose, Opt_noverbose,
25604 + Opt_sum, Opt_nosum, Opt_wsum,
25605 + Opt_dirperm1, Opt_nodirperm1,
25606 + Opt_dirren, Opt_nodirren,
25607 + Opt_acl, Opt_noacl,
25608 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
25611 +static match_table_t options = {
25612 + {Opt_br, "br=%s"},
25613 + {Opt_br, "br:%s"},
25615 + {Opt_add, "add=%d:%s"},
25616 + {Opt_add, "add:%d:%s"},
25617 + {Opt_add, "ins=%d:%s"},
25618 + {Opt_add, "ins:%d:%s"},
25619 + {Opt_append, "append=%s"},
25620 + {Opt_append, "append:%s"},
25621 + {Opt_prepend, "prepend=%s"},
25622 + {Opt_prepend, "prepend:%s"},
25624 + {Opt_del, "del=%s"},
25625 + {Opt_del, "del:%s"},
25626 + /* {Opt_idel, "idel:%d"}, */
25627 + {Opt_mod, "mod=%s"},
25628 + {Opt_mod, "mod:%s"},
25629 + /* {Opt_imod, "imod:%d:%s"}, */
25631 + {Opt_dirwh, "dirwh=%d"},
25633 + {Opt_xino, "xino=%s"},
25634 + {Opt_noxino, "noxino"},
25635 + {Opt_trunc_xino, "trunc_xino"},
25636 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
25637 + {Opt_notrunc_xino, "notrunc_xino"},
25638 + {Opt_trunc_xino_path, "trunc_xino=%s"},
25639 + {Opt_itrunc_xino, "itrunc_xino=%d"},
25640 + /* {Opt_zxino, "zxino=%s"}, */
25641 + {Opt_trunc_xib, "trunc_xib"},
25642 + {Opt_notrunc_xib, "notrunc_xib"},
25644 +#ifdef CONFIG_PROC_FS
25645 + {Opt_plink, "plink"},
25647 + {Opt_ignore_silent, "plink"},
25650 + {Opt_noplink, "noplink"},
25652 +#ifdef CONFIG_AUFS_DEBUG
25653 + {Opt_list_plink, "list_plink"},
25656 + {Opt_udba, "udba=%s"},
25658 + {Opt_dio, "dio"},
25659 + {Opt_nodio, "nodio"},
25661 +#ifdef CONFIG_AUFS_DIRREN
25662 + {Opt_dirren, "dirren"},
25663 + {Opt_nodirren, "nodirren"},
25665 + {Opt_ignore, "dirren"},
25666 + {Opt_ignore_silent, "nodirren"},
25669 +#ifdef CONFIG_AUFS_FHSM
25670 + {Opt_fhsm_sec, "fhsm_sec=%d"},
25672 + {Opt_ignore, "fhsm_sec=%d"},
25675 + {Opt_diropq_a, "diropq=always"},
25676 + {Opt_diropq_a, "diropq=a"},
25677 + {Opt_diropq_w, "diropq=whiteouted"},
25678 + {Opt_diropq_w, "diropq=w"},
25680 + {Opt_warn_perm, "warn_perm"},
25681 + {Opt_nowarn_perm, "nowarn_perm"},
25683 + /* keep them temporary */
25684 + {Opt_ignore_silent, "nodlgt"},
25685 + {Opt_ignore, "clean_plink"},
25687 +#ifdef CONFIG_AUFS_SHWH
25688 + {Opt_shwh, "shwh"},
25690 + {Opt_noshwh, "noshwh"},
25692 + {Opt_dirperm1, "dirperm1"},
25693 + {Opt_nodirperm1, "nodirperm1"},
25695 + {Opt_verbose, "verbose"},
25696 + {Opt_verbose, "v"},
25697 + {Opt_noverbose, "noverbose"},
25698 + {Opt_noverbose, "quiet"},
25699 + {Opt_noverbose, "q"},
25700 + {Opt_noverbose, "silent"},
25702 + {Opt_sum, "sum"},
25703 + {Opt_nosum, "nosum"},
25704 + {Opt_wsum, "wsum"},
25706 + {Opt_rdcache, "rdcache=%d"},
25707 + {Opt_rdblk, "rdblk=%d"},
25708 + {Opt_rdblk_def, "rdblk=def"},
25709 + {Opt_rdhash, "rdhash=%d"},
25710 + {Opt_rdhash_def, "rdhash=def"},
25712 + {Opt_wbr_create, "create=%s"},
25713 + {Opt_wbr_create, "create_policy=%s"},
25714 + {Opt_wbr_copyup, "cpup=%s"},
25715 + {Opt_wbr_copyup, "copyup=%s"},
25716 + {Opt_wbr_copyup, "copyup_policy=%s"},
25718 + /* generic VFS flag */
25719 +#ifdef CONFIG_FS_POSIX_ACL
25720 + {Opt_acl, "acl"},
25721 + {Opt_noacl, "noacl"},
25723 + {Opt_ignore, "acl"},
25724 + {Opt_ignore_silent, "noacl"},
25727 + /* internal use for the scripts */
25728 + {Opt_ignore_silent, "si=%s"},
25730 + {Opt_br, "dirs=%s"},
25731 + {Opt_ignore, "debug=%d"},
25732 + {Opt_ignore, "delete=whiteout"},
25733 + {Opt_ignore, "delete=all"},
25734 + {Opt_ignore, "imap=%s"},
25736 + /* temporary workaround, due to old mount(8)? */
25737 + {Opt_ignore_silent, "relatime"},
25742 +/* ---------------------------------------------------------------------- */
25744 +static const char *au_parser_pattern(int val, match_table_t tbl)
25746 + struct match_token *p;
25749 + while (p->pattern) {
25750 + if (p->token == val)
25751 + return p->pattern;
25758 +static const char *au_optstr(int *val, match_table_t tbl)
25760 + struct match_token *p;
25767 + while (p->pattern) {
25769 + && (v & p->token) == p->token) {
25770 + *val &= ~p->token;
25771 + return p->pattern;
25780 +/* ---------------------------------------------------------------------- */
25782 +static match_table_t brperm = {
25783 + {AuBrPerm_RO, AUFS_BRPERM_RO},
25784 + {AuBrPerm_RR, AUFS_BRPERM_RR},
25785 + {AuBrPerm_RW, AUFS_BRPERM_RW},
25789 +static match_table_t brattr = {
25791 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
25792 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
25793 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
25794 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
25795 +#ifdef CONFIG_AUFS_FHSM
25796 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
25798 +#ifdef CONFIG_AUFS_XATTR
25799 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
25800 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
25801 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
25802 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
25803 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
25804 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
25807 + /* ro/rr branch */
25808 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
25811 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
25812 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
25817 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
25824 + p = strchr(str, '+');
25827 + v = match_token(str, table, args);
25829 + if (v & AuBrAttr_CMOO_Mask)
25830 + attr &= ~AuBrAttr_CMOO_Mask;
25835 + pr_warn("ignored branch attribute %s\n", str);
25845 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
25853 + p = au_optstr(&perm, brattr);
25856 + memcpy(q, p, sz + 1);
25862 + p = au_optstr(&perm, brattr);
25866 + memcpy(q, p, sz + 1);
25872 + return q - str->a;
25875 +static int noinline_for_stack br_perm_val(char *perm)
25877 + int val, bad, sz;
25879 + substring_t args[MAX_OPT_ARGS];
25880 + au_br_perm_str_t attr;
25882 + p = strchr(perm, '+');
25885 + val = match_token(perm, brperm, args);
25889 + pr_warn("ignored branch permission %s\n", perm);
25890 + val = AuBrPerm_RO;
25896 + val |= br_attr_val(p + 1, brattr, args);
25899 + switch (val & AuBrPerm_Mask) {
25900 + case AuBrPerm_RO:
25901 + case AuBrPerm_RR:
25902 + bad = val & AuBrWAttr_Mask;
25903 + val &= ~AuBrWAttr_Mask;
25905 + case AuBrPerm_RW:
25906 + bad = val & AuBrRAttr_Mask;
25907 + val &= ~AuBrRAttr_Mask;
25912 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
25913 + * does not treat it as an error, just warning.
25914 + * this is a tiny guard for the user operation.
25916 + if (val & AuBrAttr_UNPIN) {
25917 + bad |= AuBrAttr_UNPIN;
25918 + val &= ~AuBrAttr_UNPIN;
25921 + if (unlikely(bad)) {
25922 + sz = au_do_optstr_br_attr(&attr, bad);
25924 + pr_warn("ignored branch attribute %s\n", attr.a);
25931 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
25933 + au_br_perm_str_t attr;
25939 + p = au_optstr(&perm, brperm);
25940 + AuDebugOn(!p || !*p);
25942 + memcpy(q, p, sz + 1);
25945 + sz = au_do_optstr_br_attr(&attr, perm);
25948 + memcpy(q, attr.a, sz + 1);
25951 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
25954 +/* ---------------------------------------------------------------------- */
25956 +static match_table_t udbalevel = {
25957 + {AuOpt_UDBA_REVAL, "reval"},
25958 + {AuOpt_UDBA_NONE, "none"},
25959 +#ifdef CONFIG_AUFS_HNOTIFY
25960 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
25961 +#ifdef CONFIG_AUFS_HFSNOTIFY
25962 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
25968 +static int noinline_for_stack udba_val(char *str)
25970 + substring_t args[MAX_OPT_ARGS];
25972 + return match_token(str, udbalevel, args);
25975 +const char *au_optstr_udba(int udba)
25977 + return au_parser_pattern(udba, udbalevel);
25980 +/* ---------------------------------------------------------------------- */
25982 +static match_table_t au_wbr_create_policy = {
25983 + {AuWbrCreate_TDP, "tdp"},
25984 + {AuWbrCreate_TDP, "top-down-parent"},
25985 + {AuWbrCreate_RR, "rr"},
25986 + {AuWbrCreate_RR, "round-robin"},
25987 + {AuWbrCreate_MFS, "mfs"},
25988 + {AuWbrCreate_MFS, "most-free-space"},
25989 + {AuWbrCreate_MFSV, "mfs:%d"},
25990 + {AuWbrCreate_MFSV, "most-free-space:%d"},
25992 + /* top-down regardless the parent, and then mfs */
25993 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
25994 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
25996 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
25997 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
25998 + {AuWbrCreate_PMFS, "pmfs"},
25999 + {AuWbrCreate_PMFSV, "pmfs:%d"},
26000 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
26001 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
26006 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
26007 + struct au_opt_wbr_create *create)
26010 + unsigned long long ull;
26013 + if (!match_u64(arg, &ull))
26014 + create->mfsrr_watermark = ull;
26016 + pr_err("bad integer in %s\n", str);
26023 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
26024 + struct au_opt_wbr_create *create)
26029 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
26030 + create->mfs_second = n;
26032 + pr_err("bad integer in %s\n", str);
26039 +static int noinline_for_stack
26040 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
26043 + substring_t args[MAX_OPT_ARGS];
26045 + err = match_token(str, au_wbr_create_policy, args);
26046 + create->wbr_create = err;
26048 + case AuWbrCreate_MFSRRV:
26049 + case AuWbrCreate_TDMFSV:
26050 + case AuWbrCreate_PMFSRRV:
26051 + e = au_wbr_mfs_wmark(&args[0], str, create);
26053 + e = au_wbr_mfs_sec(&args[1], str, create);
26057 + case AuWbrCreate_MFSRR:
26058 + case AuWbrCreate_TDMFS:
26059 + case AuWbrCreate_PMFSRR:
26060 + e = au_wbr_mfs_wmark(&args[0], str, create);
26061 + if (unlikely(e)) {
26066 + case AuWbrCreate_MFS:
26067 + case AuWbrCreate_PMFS:
26068 + create->mfs_second = AUFS_MFS_DEF_SEC;
26070 + case AuWbrCreate_MFSV:
26071 + case AuWbrCreate_PMFSV:
26072 + e = au_wbr_mfs_sec(&args[0], str, create);
26081 +const char *au_optstr_wbr_create(int wbr_create)
26083 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
26086 +static match_table_t au_wbr_copyup_policy = {
26087 + {AuWbrCopyup_TDP, "tdp"},
26088 + {AuWbrCopyup_TDP, "top-down-parent"},
26089 + {AuWbrCopyup_BUP, "bup"},
26090 + {AuWbrCopyup_BUP, "bottom-up-parent"},
26091 + {AuWbrCopyup_BU, "bu"},
26092 + {AuWbrCopyup_BU, "bottom-up"},
26096 +static int noinline_for_stack au_wbr_copyup_val(char *str)
26098 + substring_t args[MAX_OPT_ARGS];
26100 + return match_token(str, au_wbr_copyup_policy, args);
26103 +const char *au_optstr_wbr_copyup(int wbr_copyup)
26105 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
26108 +/* ---------------------------------------------------------------------- */
26110 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
26112 +static void dump_opts(struct au_opts *opts)
26114 +#ifdef CONFIG_AUFS_DEBUG
26115 + /* reduce stack space */
26117 + struct au_opt_add *add;
26118 + struct au_opt_del *del;
26119 + struct au_opt_mod *mod;
26120 + struct au_opt_xino *xino;
26121 + struct au_opt_xino_itrunc *xino_itrunc;
26122 + struct au_opt_wbr_create *create;
26124 + struct au_opt *opt;
26127 + while (opt->type != Opt_tail) {
26128 + switch (opt->type) {
26130 + u.add = &opt->add;
26131 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
26132 + u.add->bindex, u.add->pathname, u.add->perm,
26133 + u.add->path.dentry);
26137 + u.del = &opt->del;
26138 + AuDbg("del {%s, %p}\n",
26139 + u.del->pathname, u.del->h_path.dentry);
26143 + u.mod = &opt->mod;
26144 + AuDbg("mod {%s, 0x%x, %p}\n",
26145 + u.mod->path, u.mod->perm, u.mod->h_root);
26148 + u.add = &opt->add;
26149 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
26150 + u.add->bindex, u.add->pathname, u.add->perm,
26151 + u.add->path.dentry);
26153 + case Opt_prepend:
26154 + u.add = &opt->add;
26155 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
26156 + u.add->bindex, u.add->pathname, u.add->perm,
26157 + u.add->path.dentry);
26160 + AuDbg("dirwh %d\n", opt->dirwh);
26162 + case Opt_rdcache:
26163 + AuDbg("rdcache %d\n", opt->rdcache);
26166 + AuDbg("rdblk %u\n", opt->rdblk);
26168 + case Opt_rdblk_def:
26169 + AuDbg("rdblk_def\n");
26172 + AuDbg("rdhash %u\n", opt->rdhash);
26174 + case Opt_rdhash_def:
26175 + AuDbg("rdhash_def\n");
26178 + u.xino = &opt->xino;
26179 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
26181 + case Opt_trunc_xino:
26182 + AuLabel(trunc_xino);
26184 + case Opt_notrunc_xino:
26185 + AuLabel(notrunc_xino);
26187 + case Opt_trunc_xino_path:
26188 + case Opt_itrunc_xino:
26189 + u.xino_itrunc = &opt->xino_itrunc;
26190 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
26195 + case Opt_trunc_xib:
26196 + AuLabel(trunc_xib);
26198 + case Opt_notrunc_xib:
26199 + AuLabel(notrunc_xib);
26207 + case Opt_dirperm1:
26208 + AuLabel(dirperm1);
26210 + case Opt_nodirperm1:
26211 + AuLabel(nodirperm1);
26216 + case Opt_noplink:
26217 + AuLabel(noplink);
26219 + case Opt_list_plink:
26220 + AuLabel(list_plink);
26223 + AuDbg("udba %d, %s\n",
26224 + opt->udba, au_optstr_udba(opt->udba));
26232 + case Opt_diropq_a:
26233 + AuLabel(diropq_a);
26235 + case Opt_diropq_w:
26236 + AuLabel(diropq_w);
26238 + case Opt_warn_perm:
26239 + AuLabel(warn_perm);
26241 + case Opt_nowarn_perm:
26242 + AuLabel(nowarn_perm);
26244 + case Opt_verbose:
26245 + AuLabel(verbose);
26247 + case Opt_noverbose:
26248 + AuLabel(noverbose);
26259 + case Opt_wbr_create:
26260 + u.create = &opt->wbr_create;
26261 + AuDbg("create %d, %s\n", u.create->wbr_create,
26262 + au_optstr_wbr_create(u.create->wbr_create));
26263 + switch (u.create->wbr_create) {
26264 + case AuWbrCreate_MFSV:
26265 + case AuWbrCreate_PMFSV:
26266 + AuDbg("%d sec\n", u.create->mfs_second);
26268 + case AuWbrCreate_MFSRR:
26269 + case AuWbrCreate_TDMFS:
26270 + AuDbg("%llu watermark\n",
26271 + u.create->mfsrr_watermark);
26273 + case AuWbrCreate_MFSRRV:
26274 + case AuWbrCreate_TDMFSV:
26275 + case AuWbrCreate_PMFSRRV:
26276 + AuDbg("%llu watermark, %d sec\n",
26277 + u.create->mfsrr_watermark,
26278 + u.create->mfs_second);
26282 + case Opt_wbr_copyup:
26283 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
26284 + au_optstr_wbr_copyup(opt->wbr_copyup));
26286 + case Opt_fhsm_sec:
26287 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
26292 + case Opt_nodirren:
26293 + AuLabel(nodirren);
26309 +void au_opts_free(struct au_opts *opts)
26311 + struct au_opt *opt;
26314 + while (opt->type != Opt_tail) {
26315 + switch (opt->type) {
26318 + case Opt_prepend:
26319 + path_put(&opt->add.path);
26323 + path_put(&opt->del.h_path);
26327 + dput(opt->mod.h_root);
26330 + fput(opt->xino.file);
26337 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
26338 + aufs_bindex_t bindex)
26341 + struct au_opt_add *add = &opt->add;
26344 + add->bindex = bindex;
26345 + add->perm = AuBrPerm_RO;
26346 + add->pathname = opt_str;
26347 + p = strchr(opt_str, '=');
26351 + add->perm = br_perm_val(p);
26354 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
26357 + add->perm = AuBrPerm_RO;
26358 + if (au_test_fs_rr(add->path.dentry->d_sb))
26359 + add->perm = AuBrPerm_RR;
26360 + else if (!bindex && !(sb_flags & SB_RDONLY))
26361 + add->perm = AuBrPerm_RW;
26363 + opt->type = Opt_add;
26366 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
26373 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
26377 + del->pathname = args[0].from;
26378 + AuDbg("del path %s\n", del->pathname);
26380 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
26381 + if (unlikely(err))
26382 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
26387 +#if 0 /* reserved for future use */
26388 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
26389 + struct au_opt_del *del, substring_t args[])
26392 + struct dentry *root;
26395 + root = sb->s_root;
26396 + aufs_read_lock(root, AuLock_FLUSH);
26397 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26398 + pr_err("out of bounds, %d\n", bindex);
26403 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
26404 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
26407 + aufs_read_unlock(root, !AuLock_IR);
26412 +static int noinline_for_stack
26413 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
26416 + struct path path;
26420 + mod->path = args[0].from;
26421 + p = strchr(mod->path, '=');
26422 + if (unlikely(!p)) {
26423 + pr_err("no permission %s\n", args[0].from);
26428 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
26429 + if (unlikely(err)) {
26430 + pr_err("lookup failed %s (%d)\n", mod->path, err);
26434 + mod->perm = br_perm_val(p);
26435 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
26436 + mod->h_root = dget(path.dentry);
26443 +#if 0 /* reserved for future use */
26444 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
26445 + struct au_opt_mod *mod, substring_t args[])
26448 + struct dentry *root;
26451 + root = sb->s_root;
26452 + aufs_read_lock(root, AuLock_FLUSH);
26453 + if (bindex < 0 || au_sbbot(sb) < bindex) {
26454 + pr_err("out of bounds, %d\n", bindex);
26459 + mod->perm = br_perm_val(args[1].from);
26460 + AuDbg("mod path %s, perm 0x%x, %s\n",
26461 + mod->path, mod->perm, args[1].from);
26462 + mod->h_root = dget(au_h_dptr(root, bindex));
26465 + aufs_read_unlock(root, !AuLock_IR);
26470 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
26471 + substring_t args[])
26474 + struct file *file;
26476 + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0);
26477 + err = PTR_ERR(file);
26478 + if (IS_ERR(file))
26482 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
26484 + pr_err("%s must be outside\n", args[0].from);
26489 + xino->file = file;
26490 + xino->path = args[0].from;
26496 +static int noinline_for_stack
26497 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
26498 + struct au_opt_xino_itrunc *xino_itrunc,
26499 + substring_t args[])
26502 + aufs_bindex_t bbot, bindex;
26503 + struct path path;
26504 + struct dentry *root;
26506 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
26507 + if (unlikely(err)) {
26508 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
26512 + xino_itrunc->bindex = -1;
26513 + root = sb->s_root;
26514 + aufs_read_lock(root, AuLock_FLUSH);
26515 + bbot = au_sbbot(sb);
26516 + for (bindex = 0; bindex <= bbot; bindex++) {
26517 + if (au_h_dptr(root, bindex) == path.dentry) {
26518 + xino_itrunc->bindex = bindex;
26522 + aufs_read_unlock(root, !AuLock_IR);
26525 + if (unlikely(xino_itrunc->bindex < 0)) {
26526 + pr_err("no such branch %s\n", args[0].from);
26534 +/* called without aufs lock */
26535 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
26537 + int err, n, token;
26538 + aufs_bindex_t bindex;
26539 + unsigned char skipped;
26540 + struct dentry *root;
26541 + struct au_opt *opt, *opt_tail;
26543 + /* reduce the stack space */
26545 + struct au_opt_xino_itrunc *xino_itrunc;
26546 + struct au_opt_wbr_create *create;
26549 + substring_t args[MAX_OPT_ARGS];
26553 + a = kmalloc(sizeof(*a), GFP_NOFS);
26554 + if (unlikely(!a))
26557 + root = sb->s_root;
26561 + opt_tail = opt + opts->max_opt - 1;
26562 + opt->type = Opt_tail;
26563 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
26566 + token = match_token(opt_str, options, a->args);
26570 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
26572 + err = opt_add(opt, opt_str, opts->sb_flags,
26574 + if (unlikely(!err && ++opt > opt_tail)) {
26578 + opt->type = Opt_tail;
26583 + if (unlikely(match_int(&a->args[0], &n))) {
26584 + pr_err("bad integer in %s\n", opt_str);
26588 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
26591 + opt->type = token;
26594 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26595 + /*dummy bindex*/1);
26597 + opt->type = token;
26599 + case Opt_prepend:
26600 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
26603 + opt->type = token;
26606 + err = au_opts_parse_del(&opt->del, a->args);
26608 + opt->type = token;
26610 +#if 0 /* reserved for future use */
26612 + del->pathname = "(indexed)";
26613 + if (unlikely(match_int(&args[0], &n))) {
26614 + pr_err("bad integer in %s\n", opt_str);
26617 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
26619 + opt->type = token;
26623 + err = au_opts_parse_mod(&opt->mod, a->args);
26625 + opt->type = token;
26627 +#ifdef IMOD /* reserved for future use */
26629 + u.mod->path = "(indexed)";
26630 + if (unlikely(match_int(&a->args[0], &n))) {
26631 + pr_err("bad integer in %s\n", opt_str);
26634 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
26636 + opt->type = token;
26640 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
26642 + opt->type = token;
26645 + case Opt_trunc_xino_path:
26646 + err = au_opts_parse_xino_itrunc_path
26647 + (sb, &opt->xino_itrunc, a->args);
26649 + opt->type = token;
26652 + case Opt_itrunc_xino:
26653 + u.xino_itrunc = &opt->xino_itrunc;
26654 + if (unlikely(match_int(&a->args[0], &n))) {
26655 + pr_err("bad integer in %s\n", opt_str);
26658 + u.xino_itrunc->bindex = n;
26659 + aufs_read_lock(root, AuLock_FLUSH);
26660 + if (n < 0 || au_sbbot(sb) < n) {
26661 + pr_err("out of bounds, %d\n", n);
26662 + aufs_read_unlock(root, !AuLock_IR);
26665 + aufs_read_unlock(root, !AuLock_IR);
26667 + opt->type = token;
26671 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
26674 + opt->type = token;
26677 + case Opt_rdcache:
26678 + if (unlikely(match_int(&a->args[0], &n))) {
26679 + pr_err("bad integer in %s\n", opt_str);
26682 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
26683 + pr_err("rdcache must be smaller than %d\n",
26684 + AUFS_RDCACHE_MAX);
26687 + opt->rdcache = n;
26689 + opt->type = token;
26692 + if (unlikely(match_int(&a->args[0], &n)
26694 + || n > KMALLOC_MAX_SIZE)) {
26695 + pr_err("bad integer in %s\n", opt_str);
26698 + if (unlikely(n && n < NAME_MAX)) {
26699 + pr_err("rdblk must be larger than %d\n",
26705 + opt->type = token;
26708 + if (unlikely(match_int(&a->args[0], &n)
26710 + || n * sizeof(struct hlist_head)
26711 + > KMALLOC_MAX_SIZE)) {
26712 + pr_err("bad integer in %s\n", opt_str);
26717 + opt->type = token;
26720 + case Opt_trunc_xino:
26721 + case Opt_notrunc_xino:
26723 + case Opt_trunc_xib:
26724 + case Opt_notrunc_xib:
26727 + case Opt_dirperm1:
26728 + case Opt_nodirperm1:
26730 + case Opt_noplink:
26731 + case Opt_list_plink:
26734 + case Opt_diropq_a:
26735 + case Opt_diropq_w:
26736 + case Opt_warn_perm:
26737 + case Opt_nowarn_perm:
26738 + case Opt_verbose:
26739 + case Opt_noverbose:
26743 + case Opt_rdblk_def:
26744 + case Opt_rdhash_def:
26746 + case Opt_nodirren:
26750 + opt->type = token;
26754 + opt->udba = udba_val(a->args[0].from);
26755 + if (opt->udba >= 0) {
26757 + opt->type = token;
26759 + pr_err("wrong value, %s\n", opt_str);
26762 + case Opt_wbr_create:
26763 + u.create = &opt->wbr_create;
26764 + u.create->wbr_create
26765 + = au_wbr_create_val(a->args[0].from, u.create);
26766 + if (u.create->wbr_create >= 0) {
26768 + opt->type = token;
26770 + pr_err("wrong value, %s\n", opt_str);
26772 + case Opt_wbr_copyup:
26773 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
26774 + if (opt->wbr_copyup >= 0) {
26776 + opt->type = token;
26778 + pr_err("wrong value, %s\n", opt_str);
26781 + case Opt_fhsm_sec:
26782 + if (unlikely(match_int(&a->args[0], &n)
26784 + pr_err("bad integer in %s\n", opt_str);
26787 + if (sysaufs_brs) {
26788 + opt->fhsm_second = n;
26789 + opt->type = token;
26791 + pr_warn("ignored %s\n", opt_str);
26796 + pr_warn("ignored %s\n", opt_str);
26798 + case Opt_ignore_silent:
26803 + pr_err("unknown option %s\n", opt_str);
26807 + if (!err && !skipped) {
26808 + if (unlikely(++opt > opt_tail)) {
26811 + opt->type = Opt_tail;
26814 + opt->type = Opt_tail;
26820 + if (unlikely(err))
26821 + au_opts_free(opts);
26827 +static int au_opt_wbr_create(struct super_block *sb,
26828 + struct au_opt_wbr_create *create)
26831 + struct au_sbinfo *sbinfo;
26833 + SiMustWriteLock(sb);
26835 + err = 1; /* handled */
26836 + sbinfo = au_sbi(sb);
26837 + if (sbinfo->si_wbr_create_ops->fin) {
26838 + err = sbinfo->si_wbr_create_ops->fin(sb);
26843 + sbinfo->si_wbr_create = create->wbr_create;
26844 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
26845 + switch (create->wbr_create) {
26846 + case AuWbrCreate_MFSRRV:
26847 + case AuWbrCreate_MFSRR:
26848 + case AuWbrCreate_TDMFS:
26849 + case AuWbrCreate_TDMFSV:
26850 + case AuWbrCreate_PMFSRR:
26851 + case AuWbrCreate_PMFSRRV:
26852 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
26854 + case AuWbrCreate_MFS:
26855 + case AuWbrCreate_MFSV:
26856 + case AuWbrCreate_PMFS:
26857 + case AuWbrCreate_PMFSV:
26858 + sbinfo->si_wbr_mfs.mfs_expire
26859 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
26863 + if (sbinfo->si_wbr_create_ops->init)
26864 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
26871 + * plus: processed without an error
26872 + * zero: unprocessed
26874 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
26875 + struct au_opts *opts)
26878 + struct au_sbinfo *sbinfo;
26880 + SiMustWriteLock(sb);
26882 + err = 1; /* handled */
26883 + sbinfo = au_sbi(sb);
26884 + switch (opt->type) {
26886 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
26887 + sbinfo->si_mntflags |= opt->udba;
26888 + opts->given_udba |= opt->udba;
26892 + au_opt_set(sbinfo->si_mntflags, PLINK);
26894 + case Opt_noplink:
26895 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26896 + au_plink_put(sb, /*verbose*/1);
26897 + au_opt_clr(sbinfo->si_mntflags, PLINK);
26899 + case Opt_list_plink:
26900 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26901 + au_plink_list(sb);
26905 + au_opt_set(sbinfo->si_mntflags, DIO);
26906 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26909 + au_opt_clr(sbinfo->si_mntflags, DIO);
26910 + au_fset_opts(opts->flags, REFRESH_DYAOP);
26913 + case Opt_fhsm_sec:
26914 + au_fhsm_set(sbinfo, opt->fhsm_second);
26917 + case Opt_diropq_a:
26918 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26920 + case Opt_diropq_w:
26921 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
26924 + case Opt_warn_perm:
26925 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
26927 + case Opt_nowarn_perm:
26928 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
26931 + case Opt_verbose:
26932 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
26934 + case Opt_noverbose:
26935 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
26939 + au_opt_set(sbinfo->si_mntflags, SUM);
26942 + au_opt_clr(sbinfo->si_mntflags, SUM);
26943 + au_opt_set(sbinfo->si_mntflags, SUM_W);
26946 + au_opt_clr(sbinfo->si_mntflags, SUM);
26947 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
26950 + case Opt_wbr_create:
26951 + err = au_opt_wbr_create(sb, &opt->wbr_create);
26953 + case Opt_wbr_copyup:
26954 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
26955 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
26959 + sbinfo->si_dirwh = opt->dirwh;
26962 + case Opt_rdcache:
26963 + sbinfo->si_rdcache
26964 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
26967 + sbinfo->si_rdblk = opt->rdblk;
26969 + case Opt_rdblk_def:
26970 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26973 + sbinfo->si_rdhash = opt->rdhash;
26975 + case Opt_rdhash_def:
26976 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26980 + au_opt_set(sbinfo->si_mntflags, SHWH);
26983 + au_opt_clr(sbinfo->si_mntflags, SHWH);
26986 + case Opt_dirperm1:
26987 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
26989 + case Opt_nodirperm1:
26990 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
26993 + case Opt_trunc_xino:
26994 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
26996 + case Opt_notrunc_xino:
26997 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27000 + case Opt_trunc_xino_path:
27001 + case Opt_itrunc_xino:
27002 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27008 + case Opt_trunc_xib:
27009 + au_fset_opts(opts->flags, TRUNC_XIB);
27011 + case Opt_notrunc_xib:
27012 + au_fclr_opts(opts->flags, TRUNC_XIB);
27017 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27018 + err = au_dr_opt_set(sb);
27023 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27025 + case Opt_nodirren:
27027 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27028 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27034 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27038 + sb->s_flags |= SB_POSIXACL;
27041 + sb->s_flags &= ~SB_POSIXACL;
27053 + * returns tri-state.
27054 + * plus: processed without an error
27055 + * zero: unprocessed
27058 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27059 + struct au_opts *opts)
27061 + int err, do_refresh;
27064 + switch (opt->type) {
27066 + opt->add.bindex = au_sbbot(sb) + 1;
27067 + if (opt->add.bindex < 0)
27068 + opt->add.bindex = 0;
27070 + /* Always goto add, not fallthrough */
27071 + case Opt_prepend:
27072 + opt->add.bindex = 0;
27074 + add: /* indented label */
27076 + err = au_br_add(sb, &opt->add,
27077 + au_ftest_opts(opts->flags, REMOUNT));
27080 + au_fset_opts(opts->flags, REFRESH);
27086 + err = au_br_del(sb, &opt->del,
27087 + au_ftest_opts(opts->flags, REMOUNT));
27090 + au_fset_opts(opts->flags, TRUNC_XIB);
27091 + au_fset_opts(opts->flags, REFRESH);
27097 + err = au_br_mod(sb, &opt->mod,
27098 + au_ftest_opts(opts->flags, REMOUNT),
27103 + au_fset_opts(opts->flags, REFRESH);
27110 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27111 + struct au_opt_xino **opt_xino,
27112 + struct au_opts *opts)
27117 + switch (opt->type) {
27119 + err = au_xino_set(sb, &opt->xino,
27120 + !!au_ftest_opts(opts->flags, REMOUNT));
27121 + if (unlikely(err))
27124 + *opt_xino = &opt->xino;
27129 + *opt_xino = (void *)-1;
27136 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27137 + unsigned int pending)
27140 + aufs_bindex_t bindex, bbot;
27141 + unsigned char do_plink, skip, do_free, can_no_dreval;
27142 + struct au_branch *br;
27143 + struct au_wbr *wbr;
27144 + struct dentry *root, *dentry;
27145 + struct inode *dir, *h_dir;
27146 + struct au_sbinfo *sbinfo;
27147 + struct au_hinode *hdir;
27149 + SiMustAnyLock(sb);
27151 + sbinfo = au_sbi(sb);
27152 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27154 + if (!(sb_flags & SB_RDONLY)) {
27155 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27156 + pr_warn("first branch should be rw\n");
27157 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27158 + pr_warn_once("shwh should be used with ro\n");
27161 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27162 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27163 + pr_warn_once("udba=*notify requires xino\n");
27165 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27166 + pr_warn_once("dirperm1 breaks the protection"
27167 + " by the permission bits on the lower branch\n");
27171 + root = sb->s_root;
27172 + dir = d_inode(root);
27173 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27174 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27176 + bbot = au_sbbot(sb);
27177 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27179 + h_dir = au_h_iptr(dir, bindex);
27180 + br = au_sbr(sb, bindex);
27182 + if ((br->br_perm & AuBrAttr_ICEX)
27183 + && !h_dir->i_op->listxattr)
27184 + br->br_perm &= ~AuBrAttr_ICEX;
27185 +#if 0 /* untested */
27186 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27187 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27188 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27192 + wbr = br->br_wbr;
27194 + wbr_wh_read_lock(wbr);
27196 + if (!au_br_writable(br->br_perm)) {
27199 + || (!wbr->wbr_whbase
27200 + && !wbr->wbr_plink
27201 + && !wbr->wbr_orph));
27202 + } else if (!au_br_wh_linkable(br->br_perm)) {
27203 + /* skip = (!br->br_whbase && !br->br_orph); */
27204 + skip = (!wbr || !wbr->wbr_whbase);
27205 + if (skip && wbr) {
27207 + skip = !!wbr->wbr_plink;
27209 + skip = !wbr->wbr_plink;
27212 + /* skip = (br->br_whbase && br->br_ohph); */
27213 + skip = (wbr && wbr->wbr_whbase);
27216 + skip = !!wbr->wbr_plink;
27218 + skip = !wbr->wbr_plink;
27222 + wbr_wh_read_unlock(wbr);
27224 + if (can_no_dreval) {
27225 + dentry = br->br_path.dentry;
27226 + spin_lock(&dentry->d_lock);
27227 + if (dentry->d_flags &
27228 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27229 + can_no_dreval = 0;
27230 + spin_unlock(&dentry->d_lock);
27233 + if (au_br_fhsm(br->br_perm)) {
27235 + AuDebugOn(!br->br_fhsm);
27241 + hdir = au_hi(dir, bindex);
27242 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27244 + wbr_wh_write_lock(wbr);
27245 + err = au_wh_init(br, sb);
27247 + wbr_wh_write_unlock(wbr);
27248 + au_hn_inode_unlock(hdir);
27250 + if (!err && do_free) {
27251 + au_kfree_rcu(wbr);
27252 + br->br_wbr = NULL;
27256 + if (can_no_dreval)
27257 + au_fset_si(sbinfo, NO_DREVAL);
27259 + au_fclr_si(sbinfo, NO_DREVAL);
27262 + au_fset_si(sbinfo, FHSM);
27263 + for (bindex = bbot; bindex >= 0; bindex--) {
27264 + br = au_sbr(sb, bindex);
27265 + if (au_br_fhsm(br->br_perm)) {
27266 + au_fhsm_set_bottom(sb, bindex);
27271 + au_fclr_si(sbinfo, FHSM);
27272 + au_fhsm_set_bottom(sb, -1);
27278 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27281 + unsigned int tmp;
27282 + aufs_bindex_t bindex, bbot;
27283 + struct au_opt *opt;
27284 + struct au_opt_xino *opt_xino, xino;
27285 + struct au_sbinfo *sbinfo;
27286 + struct au_branch *br;
27287 + struct inode *dir;
27289 + SiMustWriteLock(sb);
27294 + while (err >= 0 && opt->type != Opt_tail)
27295 + err = au_opt_simple(sb, opt++, opts);
27298 + else if (unlikely(err < 0))
27301 + /* disable xino and udba temporary */
27302 + sbinfo = au_sbi(sb);
27303 + tmp = sbinfo->si_mntflags;
27304 + au_opt_clr(sbinfo->si_mntflags, XINO);
27305 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27308 + while (err >= 0 && opt->type != Opt_tail)
27309 + err = au_opt_br(sb, opt++, opts);
27312 + else if (unlikely(err < 0))
27315 + bbot = au_sbbot(sb);
27316 + if (unlikely(bbot < 0)) {
27318 + pr_err("no branches\n");
27322 + if (au_opt_test(tmp, XINO))
27323 + au_opt_set(sbinfo->si_mntflags, XINO);
27325 + while (!err && opt->type != Opt_tail)
27326 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27327 + if (unlikely(err))
27330 + err = au_opts_verify(sb, sb->s_flags, tmp);
27331 + if (unlikely(err))
27334 + /* restore xino */
27335 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27336 + xino.file = au_xino_def(sb);
27337 + err = PTR_ERR(xino.file);
27338 + if (IS_ERR(xino.file))
27341 + err = au_xino_set(sb, &xino, /*remount*/0);
27343 + if (unlikely(err))
27347 + /* restore udba */
27348 + tmp &= AuOptMask_UDBA;
27349 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27350 + sbinfo->si_mntflags |= tmp;
27351 + bbot = au_sbbot(sb);
27352 + for (bindex = 0; bindex <= bbot; bindex++) {
27353 + br = au_sbr(sb, bindex);
27354 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27355 + if (unlikely(err))
27356 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27358 + /* go on even if err */
27360 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27361 + dir = d_inode(sb->s_root);
27362 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27369 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27372 + unsigned char no_dreval;
27373 + struct inode *dir;
27374 + struct au_opt_xino *opt_xino;
27375 + struct au_opt *opt;
27376 + struct au_sbinfo *sbinfo;
27378 + SiMustWriteLock(sb);
27380 + err = au_dr_opt_flush(sb);
27381 + if (unlikely(err))
27383 + au_fset_opts(opts->flags, DR_FLUSHED);
27385 + dir = d_inode(sb->s_root);
27386 + sbinfo = au_sbi(sb);
27389 + while (err >= 0 && opt->type != Opt_tail) {
27390 + err = au_opt_simple(sb, opt, opts);
27392 + err = au_opt_br(sb, opt, opts);
27394 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27400 + /* go on even err */
27402 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27403 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27404 + if (unlikely(rerr && !err))
27407 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27408 + au_fset_opts(opts->flags, REFRESH_IDOP);
27410 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27411 + rerr = au_xib_trunc(sb);
27412 + if (unlikely(rerr && !err))
27416 + /* will be handled by the caller */
27417 + if (!au_ftest_opts(opts->flags, REFRESH)
27418 + && (opts->given_udba
27419 + || au_opt_test(sbinfo->si_mntflags, XINO)
27420 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27422 + au_fset_opts(opts->flags, REFRESH);
27424 + AuDbg("status 0x%x\n", opts->flags);
27430 +/* ---------------------------------------------------------------------- */
27432 +unsigned int au_opt_udba(struct super_block *sb)
27434 + return au_mntflags(sb) & AuOptMask_UDBA;
27436 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27437 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27438 +++ linux/fs/aufs/opts.h 2021-12-03 15:38:59.939980643 +0100
27440 +/* SPDX-License-Identifier: GPL-2.0 */
27442 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27444 + * This program, aufs is free software; you can redistribute it and/or modify
27445 + * it under the terms of the GNU General Public License as published by
27446 + * the Free Software Foundation; either version 2 of the License, or
27447 + * (at your option) any later version.
27449 + * This program is distributed in the hope that it will be useful,
27450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27452 + * GNU General Public License for more details.
27454 + * You should have received a copy of the GNU General Public License
27455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27459 + * mount options/flags
27462 +#ifndef __AUFS_OPTS_H__
27463 +#define __AUFS_OPTS_H__
27467 +#include <linux/path.h>
27471 +/* ---------------------------------------------------------------------- */
27474 +#define AuOpt_XINO 1 /* external inode number bitmap
27475 + and translation table */
27476 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27477 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27478 +#define AuOpt_UDBA_REVAL (1 << 3)
27479 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27480 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27481 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27482 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27484 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27485 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27486 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27487 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27488 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27489 +#define AuOpt_DIO (1 << 14) /* direct io */
27490 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27492 +#ifndef CONFIG_AUFS_HNOTIFY
27493 +#undef AuOpt_UDBA_HNOTIFY
27494 +#define AuOpt_UDBA_HNOTIFY 0
27496 +#ifndef CONFIG_AUFS_DIRREN
27497 +#undef AuOpt_DIRREN
27498 +#define AuOpt_DIRREN 0
27500 +#ifndef CONFIG_AUFS_SHWH
27502 +#define AuOpt_SHWH 0
27505 +#define AuOpt_Def (AuOpt_XINO \
27506 + | AuOpt_UDBA_REVAL \
27508 + /* | AuOpt_DIRPERM1 */ \
27509 + | AuOpt_WARN_PERM)
27510 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
27511 + | AuOpt_UDBA_REVAL \
27512 + | AuOpt_UDBA_HNOTIFY)
27514 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
27515 +#define au_opt_set(flags, name) do { \
27516 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
27517 + ((flags) |= AuOpt_##name); \
27519 +#define au_opt_set_udba(flags, name) do { \
27520 + (flags) &= ~AuOptMask_UDBA; \
27521 + ((flags) |= AuOpt_##name); \
27523 +#define au_opt_clr(flags, name) do { \
27524 + ((flags) &= ~AuOpt_##name); \
27527 +static inline unsigned int au_opts_plink(unsigned int mntflags)
27529 +#ifdef CONFIG_PROC_FS
27532 + return mntflags & ~AuOpt_PLINK;
27536 +/* ---------------------------------------------------------------------- */
27538 +/* policies to select one among multiple writable branches */
27540 + AuWbrCreate_TDP, /* top down parent */
27541 + AuWbrCreate_RR, /* round robin */
27542 + AuWbrCreate_MFS, /* most free space */
27543 + AuWbrCreate_MFSV, /* mfs with seconds */
27544 + AuWbrCreate_MFSRR, /* mfs then rr */
27545 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
27546 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
27547 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
27548 + AuWbrCreate_PMFS, /* parent and mfs */
27549 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
27550 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
27551 + AuWbrCreate_PMFSRRV, /* plus seconds */
27553 + AuWbrCreate_Def = AuWbrCreate_TDP
27557 + AuWbrCopyup_TDP, /* top down parent */
27558 + AuWbrCopyup_BUP, /* bottom up parent */
27559 + AuWbrCopyup_BU, /* bottom up */
27561 + AuWbrCopyup_Def = AuWbrCopyup_TDP
27564 +/* ---------------------------------------------------------------------- */
27566 +struct au_opt_add {
27567 + aufs_bindex_t bindex;
27570 + struct path path;
27573 +struct au_opt_del {
27575 + struct path h_path;
27578 +struct au_opt_mod {
27581 + struct dentry *h_root;
27584 +struct au_opt_xino {
27586 + struct file *file;
27589 +struct au_opt_xino_itrunc {
27590 + aufs_bindex_t bindex;
27593 +struct au_opt_wbr_create {
27596 + unsigned long long mfsrr_watermark;
27602 + struct au_opt_xino xino;
27603 + struct au_opt_xino_itrunc xino_itrunc;
27604 + struct au_opt_add add;
27605 + struct au_opt_del del;
27606 + struct au_opt_mod mod;
27609 + unsigned int rdblk;
27610 + unsigned int rdhash;
27612 + struct au_opt_wbr_create wbr_create;
27614 + unsigned int fhsm_second;
27619 +#define AuOpts_REMOUNT 1
27620 +#define AuOpts_REFRESH (1 << 1)
27621 +#define AuOpts_TRUNC_XIB (1 << 2)
27622 +#define AuOpts_REFRESH_DYAOP (1 << 3)
27623 +#define AuOpts_REFRESH_IDOP (1 << 4)
27624 +#define AuOpts_DR_FLUSHED (1 << 5)
27625 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
27626 +#define au_fset_opts(flags, name) \
27627 + do { (flags) |= AuOpts_##name; } while (0)
27628 +#define au_fclr_opts(flags, name) \
27629 + do { (flags) &= ~AuOpts_##name; } while (0)
27631 +#ifndef CONFIG_AUFS_DIRREN
27632 +#undef AuOpts_DR_FLUSHED
27633 +#define AuOpts_DR_FLUSHED 0
27637 + struct au_opt *opt;
27640 + unsigned int given_udba;
27641 + unsigned int flags;
27642 + unsigned long sb_flags;
27645 +/* ---------------------------------------------------------------------- */
27648 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
27649 +const char *au_optstr_udba(int udba);
27650 +const char *au_optstr_wbr_copyup(int wbr_copyup);
27651 +const char *au_optstr_wbr_create(int wbr_create);
27653 +void au_opts_free(struct au_opts *opts);
27654 +struct super_block;
27655 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
27656 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27657 + unsigned int pending);
27658 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
27659 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
27661 +unsigned int au_opt_udba(struct super_block *sb);
27663 +#endif /* __KERNEL__ */
27664 +#endif /* __AUFS_OPTS_H__ */
27665 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
27666 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
27667 +++ linux/fs/aufs/plink.c 2021-12-03 15:38:59.939980643 +0100
27669 +// SPDX-License-Identifier: GPL-2.0
27671 + * Copyright (C) 2005-2021 Junjiro R. Okajima
27673 + * This program, aufs is free software; you can redistribute it and/or modify
27674 + * it under the terms of the GNU General Public License as published by
27675 + * the Free Software Foundation; either version 2 of the License, or
27676 + * (at your option) any later version.
27678 + * This program is distributed in the hope that it will be useful,
27679 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27680 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27681 + * GNU General Public License for more details.
27683 + * You should have received a copy of the GNU General Public License
27684 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27694 + * the pseudo-link maintenance mode.
27695 + * during a user process maintains the pseudo-links,
27696 + * prohibit adding a new plink and branch manipulation.
27700 + * For entry functions which will handle plink, and i_mutex is already held
27702 + * They cannot wait and should return an error at once.
27703 + * Callers has to check the error.
27705 + * For entry functions which will handle plink, but i_mutex is not held
27707 + * They can wait the plink maintenance mode to finish.
27709 + * They behave like F_SETLK and F_SETLKW.
27710 + * If the caller never handle plink, then both flags are unnecessary.
27713 +int au_plink_maint(struct super_block *sb, int flags)
27717 + struct task_struct *parent, *prev;
27718 + struct au_sbinfo *sbi;
27720 + SiMustAnyLock(sb);
27723 + if (!au_opt_test(au_mntflags(sb), PLINK))
27726 + sbi = au_sbi(sb);
27727 + pid = sbi->si_plink_maint_pid;
27728 + if (!pid || pid == current->pid)
27731 + /* todo: it highly depends upon /sbin/mount.aufs */
27733 + parent = current;
27737 + parent = rcu_dereference(parent->real_parent);
27738 + if (parent == prev)
27740 + ppid = task_pid_vnr(parent);
27741 + if (pid == ppid) {
27742 + rcu_read_unlock();
27747 + rcu_read_unlock();
27749 + if (au_ftest_lock(flags, NOPLMW)) {
27750 + /* if there is no i_mutex lock in VFS, we don't need to wait */
27751 + /* AuDebugOn(!lockdep_depth(current)); */
27752 + while (sbi->si_plink_maint_pid) {
27753 + si_read_unlock(sb);
27754 + /* gave up wake_up_bit() */
27755 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
27757 + if (au_ftest_lock(flags, FLUSH))
27758 + au_nwt_flush(&sbi->si_nowait);
27759 + si_noflush_read_lock(sb);
27761 + } else if (au_ftest_lock(flags, NOPLM)) {
27762 + AuDbg("ppid %d, pid %d\n", ppid, pid);
27770 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
27772 + spin_lock(&sbinfo->si_plink_maint_lock);
27773 + sbinfo->si_plink_maint_pid = 0;
27774 + spin_unlock(&sbinfo->si_plink_maint_lock);
27775 + wake_up_all(&sbinfo->si_plink_wq);
27778 +int au_plink_maint_enter(struct super_block *sb)
27781 + struct au_sbinfo *sbinfo;
27784 + sbinfo = au_sbi(sb);
27785 + /* make sure i am the only one in this fs */
27786 + si_write_lock(sb, AuLock_FLUSH);
27787 + if (au_opt_test(au_mntflags(sb), PLINK)) {
27788 + spin_lock(&sbinfo->si_plink_maint_lock);
27789 + if (!sbinfo->si_plink_maint_pid)
27790 + sbinfo->si_plink_maint_pid = current->pid;
27793 + spin_unlock(&sbinfo->si_plink_maint_lock);
27795 + si_write_unlock(sb);
27800 +/* ---------------------------------------------------------------------- */
27802 +#ifdef CONFIG_AUFS_DEBUG
27803 +void au_plink_list(struct super_block *sb)
27806 + struct au_sbinfo *sbinfo;
27807 + struct hlist_bl_head *hbl;
27808 + struct hlist_bl_node *pos;
27809 + struct au_icntnr *icntnr;
27811 + SiMustAnyLock(sb);
27813 + sbinfo = au_sbi(sb);
27814 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
27815 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
27817 + for (i = 0; i < AuPlink_NHASH; i++) {
27818 + hbl = sbinfo->si_plink + i;
27819 + hlist_bl_lock(hbl);
27820 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27821 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
27822 + hlist_bl_unlock(hbl);
27827 +/* is the inode pseudo-linked? */
27828 +int au_plink_test(struct inode *inode)
27831 + struct au_sbinfo *sbinfo;
27832 + struct hlist_bl_head *hbl;
27833 + struct hlist_bl_node *pos;
27834 + struct au_icntnr *icntnr;
27836 + sbinfo = au_sbi(inode->i_sb);
27837 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27838 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
27839 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27842 + i = au_plink_hash(inode->i_ino);
27843 + hbl = sbinfo->si_plink + i;
27844 + hlist_bl_lock(hbl);
27845 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
27846 + if (&icntnr->vfs_inode == inode) {
27850 + hlist_bl_unlock(hbl);
27854 +/* ---------------------------------------------------------------------- */
27857 + * generate a name for plink.
27858 + * the file will be stored under AUFS_WH_PLINKDIR.
27860 +/* 20 is max digits length of ulong 64 */
27861 +#define PLINK_NAME_LEN ((20 + 1) * 2)
27863 +static int plink_name(char *name, int len, struct inode *inode,
27864 + aufs_bindex_t bindex)
27867 + struct inode *h_inode;
27869 + h_inode = au_h_iptr(inode, bindex);
27870 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
27874 +struct au_do_plink_lkup_args {
27875 + struct dentry **errp;
27876 + struct qstr *tgtname;
27877 + struct path *h_ppath;
27880 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
27881 + struct path *h_ppath)
27883 + struct dentry *h_dentry;
27884 + struct inode *h_inode;
27886 + h_inode = d_inode(h_ppath->dentry);
27887 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
27888 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
27889 + inode_unlock_shared(h_inode);
27894 +static void au_call_do_plink_lkup(void *args)
27896 + struct au_do_plink_lkup_args *a = args;
27897 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
27900 +/* lookup the plink-ed @inode under the branch at @bindex */
27901 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
27903 + struct dentry *h_dentry;
27904 + struct au_branch *br;
27905 + struct path h_ppath;
27907 + char a[PLINK_NAME_LEN];
27908 + struct qstr tgtname = QSTR_INIT(a, 0);
27910 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
27912 + br = au_sbr(inode->i_sb, bindex);
27913 + h_ppath.dentry = br->br_wbr->wbr_plink;
27914 + h_ppath.mnt = au_br_mnt(br);
27915 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
27917 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
27918 + struct au_do_plink_lkup_args args = {
27919 + .errp = &h_dentry,
27920 + .tgtname = &tgtname,
27921 + .h_ppath = &h_ppath
27924 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
27925 + if (unlikely(wkq_err))
27926 + h_dentry = ERR_PTR(wkq_err);
27928 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
27933 +/* create a pseudo-link */
27934 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
27935 + struct dentry *h_dentry)
27938 + struct path h_path;
27939 + struct inode *h_dir, *delegated;
27941 + h_dir = d_inode(h_ppath->dentry);
27942 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
27943 + h_path.mnt = h_ppath->mnt;
27945 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
27946 + err = PTR_ERR(h_path.dentry);
27947 + if (IS_ERR(h_path.dentry))
27951 + /* wh.plink dir is not monitored */
27952 + /* todo: is it really safe? */
27953 + if (d_is_positive(h_path.dentry)
27954 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
27955 + delegated = NULL;
27956 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
27957 + if (unlikely(err == -EWOULDBLOCK)) {
27958 + pr_warn("cannot retry for NFSv4 delegation"
27959 + " for an internal unlink\n");
27962 + dput(h_path.dentry);
27963 + h_path.dentry = NULL;
27967 + if (!err && d_is_negative(h_path.dentry)) {
27968 + delegated = NULL;
27969 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
27970 + if (unlikely(err == -EWOULDBLOCK)) {
27971 + pr_warn("cannot retry for NFSv4 delegation"
27972 + " for an internal link\n");
27976 + dput(h_path.dentry);
27979 + inode_unlock(h_dir);
27983 +struct do_whplink_args {
27985 + struct qstr *tgt;
27986 + struct path *h_ppath;
27987 + struct dentry *h_dentry;
27990 +static void call_do_whplink(void *args)
27992 + struct do_whplink_args *a = args;
27993 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
27996 +static int whplink(struct dentry *h_dentry, struct inode *inode,
27997 + aufs_bindex_t bindex)
27999 + int err, wkq_err;
28000 + struct au_branch *br;
28001 + struct au_wbr *wbr;
28002 + struct path h_ppath;
28003 + char a[PLINK_NAME_LEN];
28004 + struct qstr tgtname = QSTR_INIT(a, 0);
28006 + br = au_sbr(inode->i_sb, bindex);
28007 + wbr = br->br_wbr;
28008 + h_ppath.dentry = wbr->wbr_plink;
28009 + h_ppath.mnt = au_br_mnt(br);
28010 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28012 + /* always superio. */
28013 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28014 + struct do_whplink_args args = {
28017 + .h_ppath = &h_ppath,
28018 + .h_dentry = h_dentry
28020 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28021 + if (unlikely(wkq_err))
28024 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28030 + * create a new pseudo-link for @h_dentry on @bindex.
28031 + * the linked inode is held in aufs @inode.
28033 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28034 + struct dentry *h_dentry)
28036 + struct super_block *sb;
28037 + struct au_sbinfo *sbinfo;
28038 + struct hlist_bl_head *hbl;
28039 + struct hlist_bl_node *pos;
28040 + struct au_icntnr *icntnr;
28041 + int found, err, cnt, i;
28043 + sb = inode->i_sb;
28044 + sbinfo = au_sbi(sb);
28045 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28046 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28048 + found = au_plink_test(inode);
28052 + i = au_plink_hash(inode->i_ino);
28053 + hbl = sbinfo->si_plink + i;
28056 + hlist_bl_lock(hbl);
28057 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28058 + if (&icntnr->vfs_inode == inode) {
28064 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28065 + hlist_bl_add_head(&icntnr->plink, hbl);
28067 + hlist_bl_unlock(hbl);
28069 + cnt = au_hbl_count(hbl);
28070 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28071 + if (cnt > AUFS_PLINK_WARN)
28072 + AuWarn1(msg ", %d\n", cnt);
28074 + err = whplink(h_dentry, inode, bindex);
28075 + if (unlikely(err)) {
28076 + pr_warn("err %d, damaged pseudo link.\n", err);
28077 + au_hbl_del(&icntnr->plink, hbl);
28078 + iput(&icntnr->vfs_inode);
28081 + iput(&icntnr->vfs_inode);
28084 +/* free all plinks */
28085 +void au_plink_put(struct super_block *sb, int verbose)
28088 + struct au_sbinfo *sbinfo;
28089 + struct hlist_bl_head *hbl;
28090 + struct hlist_bl_node *pos, *tmp;
28091 + struct au_icntnr *icntnr;
28093 + SiMustWriteLock(sb);
28095 + sbinfo = au_sbi(sb);
28096 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28097 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28099 + /* no spin_lock since sbinfo is write-locked */
28101 + for (i = 0; i < AuPlink_NHASH; i++) {
28102 + hbl = sbinfo->si_plink + i;
28103 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28104 + pr_warn("pseudo-link is not flushed");
28107 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28108 + iput(&icntnr->vfs_inode);
28109 + INIT_HLIST_BL_HEAD(hbl);
28113 +void au_plink_clean(struct super_block *sb, int verbose)
28115 + struct dentry *root;
28117 + root = sb->s_root;
28118 + aufs_write_lock(root);
28119 + if (au_opt_test(au_mntflags(sb), PLINK))
28120 + au_plink_put(sb, verbose);
28121 + aufs_write_unlock(root);
28124 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28127 + aufs_bindex_t btop, bbot, bindex;
28130 + btop = au_ibtop(inode);
28131 + bbot = au_ibbot(inode);
28133 + for (bindex = btop; bindex <= bbot; bindex++) {
28134 + if (!au_h_iptr(inode, bindex)
28135 + || au_ii_br_id(inode, bindex) != br_id)
28137 + au_set_h_iptr(inode, bindex, NULL, 0);
28142 + for (bindex = btop; bindex <= bbot; bindex++)
28143 + if (au_h_iptr(inode, bindex)) {
28153 +/* free the plinks on a branch specified by @br_id */
28154 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28156 + struct au_sbinfo *sbinfo;
28157 + struct hlist_bl_head *hbl;
28158 + struct hlist_bl_node *pos, *tmp;
28159 + struct au_icntnr *icntnr;
28160 + struct inode *inode;
28163 + SiMustWriteLock(sb);
28165 + sbinfo = au_sbi(sb);
28166 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28167 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28169 + /* no bit_lock since sbinfo is write-locked */
28170 + for (i = 0; i < AuPlink_NHASH; i++) {
28171 + hbl = sbinfo->si_plink + i;
28172 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28173 + inode = au_igrab(&icntnr->vfs_inode);
28174 + ii_write_lock_child(inode);
28175 + do_put = au_plink_do_half_refresh(inode, br_id);
28177 + hlist_bl_del(&icntnr->plink);
28180 + ii_write_unlock(inode);
28185 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28186 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28187 +++ linux/fs/aufs/poll.c 2021-12-03 15:38:59.939980643 +0100
28189 +// SPDX-License-Identifier: GPL-2.0
28191 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28193 + * This program, aufs is free software; you can redistribute it and/or modify
28194 + * it under the terms of the GNU General Public License as published by
28195 + * the Free Software Foundation; either version 2 of the License, or
28196 + * (at your option) any later version.
28198 + * This program is distributed in the hope that it will be useful,
28199 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28200 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28201 + * GNU General Public License for more details.
28203 + * You should have received a copy of the GNU General Public License
28204 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28209 + * There is only one filesystem which implements ->poll operation, currently.
28214 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28217 + struct file *h_file;
28218 + struct super_block *sb;
28220 + /* We should pretend an error happened. */
28221 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28222 + sb = file->f_path.dentry->d_sb;
28223 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28225 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28226 + if (IS_ERR(h_file)) {
28227 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28231 + mask = vfs_poll(h_file, pt);
28232 + fput(h_file); /* instead of au_read_post() */
28235 + si_read_unlock(sb);
28236 + if (mask & EPOLLERR)
28237 + AuDbg("mask 0x%x\n", mask);
28240 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28241 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28242 +++ linux/fs/aufs/posix_acl.c 2021-12-03 15:38:59.939980643 +0100
28244 +// SPDX-License-Identifier: GPL-2.0
28246 + * Copyright (C) 2014-2021 Junjiro R. Okajima
28248 + * This program, aufs is free software; you can redistribute it and/or modify
28249 + * it under the terms of the GNU General Public License as published by
28250 + * the Free Software Foundation; either version 2 of the License, or
28251 + * (at your option) any later version.
28253 + * This program is distributed in the hope that it will be useful,
28254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28256 + * GNU General Public License for more details.
28258 + * You should have received a copy of the GNU General Public License
28259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28263 + * posix acl operations
28266 +#include <linux/fs.h>
28269 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
28271 + struct posix_acl *acl;
28273 + aufs_bindex_t bindex;
28274 + struct inode *h_inode;
28275 + struct super_block *sb;
28278 + sb = inode->i_sb;
28279 + si_read_lock(sb, AuLock_FLUSH);
28280 + ii_read_lock_child(inode);
28281 + if (!(sb->s_flags & SB_POSIXACL))
28284 + bindex = au_ibtop(inode);
28285 + h_inode = au_h_iptr(inode, bindex);
28286 + if (unlikely(!h_inode
28287 + || ((h_inode->i_mode & S_IFMT)
28288 + != (inode->i_mode & S_IFMT)))) {
28289 + err = au_busy_or_stale();
28290 + acl = ERR_PTR(err);
28294 + /* always topmost only */
28295 + acl = get_acl(h_inode, type);
28297 + forget_cached_acl(inode, type);
28299 + set_cached_acl(inode, type, acl);
28302 + ii_read_unlock(inode);
28303 + si_read_unlock(sb);
28305 + AuTraceErrPtr(acl);
28309 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
28313 + struct dentry *dentry;
28314 + struct au_sxattr arg = {
28315 + .type = AU_ACL_SET,
28322 + IMustLock(inode);
28324 + if (inode->i_ino == AUFS_ROOT_INO)
28325 + dentry = dget(inode->i_sb->s_root);
28327 + dentry = d_find_alias(inode);
28329 + dentry = d_find_any_alias(inode);
28331 + pr_warn("cannot handle this inode, "
28332 + "please report to aufs-users ML\n");
28338 + ssz = au_sxattr(dentry, inode, &arg);
28339 + /* forget even it if succeeds since the branch might set differently */
28340 + forget_cached_acl(inode, type);
28349 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28350 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28351 +++ linux/fs/aufs/procfs.c 2021-12-03 15:38:59.939980643 +0100
28353 +// SPDX-License-Identifier: GPL-2.0
28355 + * Copyright (C) 2010-2021 Junjiro R. Okajima
28357 + * This program, aufs is free software; you can redistribute it and/or modify
28358 + * it under the terms of the GNU General Public License as published by
28359 + * the Free Software Foundation; either version 2 of the License, or
28360 + * (at your option) any later version.
28362 + * This program is distributed in the hope that it will be useful,
28363 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28364 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28365 + * GNU General Public License for more details.
28367 + * You should have received a copy of the GNU General Public License
28368 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28372 + * procfs interfaces
28375 +#include <linux/proc_fs.h>
28378 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28380 + struct au_sbinfo *sbinfo;
28382 + sbinfo = file->private_data;
28384 + au_plink_maint_leave(sbinfo);
28385 + kobject_put(&sbinfo->si_kobj);
28391 +static void au_procfs_plm_write_clean(struct file *file)
28393 + struct au_sbinfo *sbinfo;
28395 + sbinfo = file->private_data;
28397 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28400 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28403 + struct super_block *sb;
28404 + struct au_sbinfo *sbinfo;
28405 + struct hlist_bl_node *pos;
28408 + if (unlikely(file->private_data))
28412 + /* don't use au_sbilist_lock() here */
28413 + hlist_bl_lock(&au_sbilist);
28414 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28415 + if (id == sysaufs_si_id(sbinfo)) {
28416 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28417 + sb = sbinfo->si_sb;
28420 + hlist_bl_unlock(&au_sbilist);
28423 + if (unlikely(!sb))
28426 + err = au_plink_maint_enter(sb);
28428 + /* keep kobject_get() */
28429 + file->private_data = sbinfo;
28431 + kobject_put(&sbinfo->si_kobj);
28437 + * Accept a valid "si=xxxx" only.
28438 + * Once it is accepted successfully, accept "clean" too.
28440 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28441 + size_t count, loff_t *ppos)
28444 + unsigned long id;
28445 + /* last newline is allowed */
28446 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28449 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28453 + if (unlikely(count > sizeof(buf)))
28456 + err = copy_from_user(buf, ubuf, count);
28457 + if (unlikely(err)) {
28464 + if (!strcmp("clean", buf)) {
28465 + au_procfs_plm_write_clean(file);
28466 + goto out_success;
28467 + } else if (unlikely(strncmp("si=", buf, 3)))
28470 + err = kstrtoul(buf + 3, 16, &id);
28471 + if (unlikely(err))
28474 + err = au_procfs_plm_write_si(file, id);
28475 + if (unlikely(err))
28479 + err = count; /* success */
28484 +static const struct proc_ops au_procfs_plm_op = {
28485 + .proc_write = au_procfs_plm_write,
28486 + .proc_release = au_procfs_plm_release
28489 +/* ---------------------------------------------------------------------- */
28491 +static struct proc_dir_entry *au_procfs_dir;
28493 +void au_procfs_fin(void)
28495 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
28496 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28499 +int __init au_procfs_init(void)
28502 + struct proc_dir_entry *entry;
28505 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
28506 + if (unlikely(!au_procfs_dir))
28509 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
28510 + au_procfs_dir, &au_procfs_plm_op);
28511 + if (unlikely(!entry))
28515 + goto out; /* success */
28519 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
28523 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
28524 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
28525 +++ linux/fs/aufs/rdu.c 2021-12-03 15:38:59.939980643 +0100
28527 +// SPDX-License-Identifier: GPL-2.0
28529 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28531 + * This program, aufs is free software; you can redistribute it and/or modify
28532 + * it under the terms of the GNU General Public License as published by
28533 + * the Free Software Foundation; either version 2 of the License, or
28534 + * (at your option) any later version.
28536 + * This program is distributed in the hope that it will be useful,
28537 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28538 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28539 + * GNU General Public License for more details.
28541 + * You should have received a copy of the GNU General Public License
28542 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28546 + * readdir in userspace.
28549 +#include <linux/compat.h>
28550 +#include <linux/fs_stack.h>
28551 +#include <linux/security.h>
28554 +/* bits for struct aufs_rdu.flags */
28555 +#define AuRdu_CALLED 1
28556 +#define AuRdu_CONT (1 << 1)
28557 +#define AuRdu_FULL (1 << 2)
28558 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
28559 +#define au_fset_rdu(flags, name) \
28560 + do { (flags) |= AuRdu_##name; } while (0)
28561 +#define au_fclr_rdu(flags, name) \
28562 + do { (flags) &= ~AuRdu_##name; } while (0)
28564 +struct au_rdu_arg {
28565 + struct dir_context ctx;
28566 + struct aufs_rdu *rdu;
28567 + union au_rdu_ent_ul ent;
28568 + unsigned long end;
28570 + struct super_block *sb;
28574 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
28575 + loff_t offset, u64 h_ino, unsigned int d_type)
28578 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
28579 + struct aufs_rdu *rdu = arg->rdu;
28580 + struct au_rdu_ent ent;
28584 + au_fset_rdu(rdu->cookie.flags, CALLED);
28585 + len = au_rdu_len(nlen);
28586 + if (arg->ent.ul + len < arg->end) {
28588 + ent.bindex = rdu->cookie.bindex;
28589 + ent.type = d_type;
28591 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28592 + ent.type = DT_UNKNOWN;
28594 + /* unnecessary to support mmap_sem since this is a dir */
28596 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
28598 + if (copy_to_user(arg->ent.e->name, name, nlen))
28600 + /* the terminating NULL */
28601 + if (__put_user(0, arg->ent.e->name + nlen))
28604 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
28605 + arg->ent.ul += len;
28609 + au_fset_rdu(rdu->cookie.flags, FULL);
28611 + rdu->tail = arg->ent;
28615 + /* AuTraceErr(err); */
28619 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
28623 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
28625 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
28626 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
28628 + if (unlikely(offset != cookie->h_pos))
28634 + au_fclr_rdu(cookie->flags, CALLED);
28636 + err = vfsub_iterate_dir(h_file, &arg->ctx);
28640 + && au_ftest_rdu(cookie->flags, CALLED)
28641 + && !au_ftest_rdu(cookie->flags, FULL));
28642 + cookie->h_pos = h_file->f_pos;
28649 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
28652 + aufs_bindex_t bbot;
28653 + struct au_rdu_arg arg = {
28655 + .actor = au_rdu_fill
28658 + struct dentry *dentry;
28659 + struct inode *inode;
28660 + struct file *h_file;
28661 + struct au_rdu_cookie *cookie = &rdu->cookie;
28663 + /* VERIFY_WRITE */
28664 + err = !access_ok(rdu->ent.e, rdu->sz);
28665 + if (unlikely(err)) {
28671 + rdu->tail = rdu->ent;
28674 + arg.ent = rdu->ent;
28675 + arg.end = arg.ent.ul;
28676 + arg.end += rdu->sz;
28679 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
28682 + err = security_file_permission(file, MAY_READ);
28684 + if (unlikely(err))
28687 + dentry = file->f_path.dentry;
28688 + inode = d_inode(dentry);
28689 + inode_lock_shared(inode);
28691 + arg.sb = inode->i_sb;
28692 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
28693 + if (unlikely(err))
28695 + err = au_alive_dir(dentry);
28696 + if (unlikely(err))
28698 + /* todo: reval? */
28699 + fi_read_lock(file);
28702 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
28703 + && cookie->generation != au_figen(file)))
28708 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
28710 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
28712 + bbot = au_fbtop(file);
28713 + if (cookie->bindex < bbot)
28714 + cookie->bindex = bbot;
28715 + bbot = au_fbbot_dir(file);
28716 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
28717 + for (; !err && cookie->bindex <= bbot;
28718 + cookie->bindex++, cookie->h_pos = 0) {
28719 + h_file = au_hf_dir(file, cookie->bindex);
28723 + au_fclr_rdu(cookie->flags, FULL);
28724 + err = au_rdu_do(h_file, &arg);
28726 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
28729 + AuDbg("rent %llu\n", rdu->rent);
28731 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
28732 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
28733 + au_fset_rdu(cookie->flags, CONT);
28734 + cookie->generation = au_figen(file);
28737 + ii_read_lock_child(inode);
28738 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
28739 + ii_read_unlock(inode);
28742 + fi_read_unlock(file);
28744 + si_read_unlock(arg.sb);
28746 + inode_unlock_shared(inode);
28752 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
28756 + unsigned long long nent;
28757 + union au_rdu_ent_ul *u;
28758 + struct au_rdu_ent ent;
28759 + struct super_block *sb;
28762 + nent = rdu->nent;
28764 + sb = file->f_path.dentry->d_sb;
28765 + si_read_lock(sb, AuLock_FLUSH);
28766 + while (nent-- > 0) {
28767 + /* unnecessary to support mmap_sem since this is a dir */
28768 + err = copy_from_user(&ent, u->e, sizeof(ent));
28770 + /* VERIFY_WRITE */
28771 + err = !access_ok(&u->e->ino, sizeof(ino));
28772 + if (unlikely(err)) {
28778 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
28780 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
28782 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
28784 + if (unlikely(err)) {
28789 + err = __put_user(ino, &u->e->ino);
28790 + if (unlikely(err)) {
28795 + u->ul += au_rdu_len(ent.nlen);
28797 + si_read_unlock(sb);
28802 +/* ---------------------------------------------------------------------- */
28804 +static int au_rdu_verify(struct aufs_rdu *rdu)
28806 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
28807 + "%llu, b%d, 0x%x, g%u}\n",
28808 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
28810 + rdu->rent, rdu->shwh, rdu->full,
28811 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
28812 + rdu->cookie.generation);
28814 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
28818 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
28822 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28825 + struct aufs_rdu rdu;
28826 + void __user *p = (void __user *)arg;
28828 + err = copy_from_user(&rdu, p, sizeof(rdu));
28829 + if (unlikely(err)) {
28834 + err = au_rdu_verify(&rdu);
28835 + if (unlikely(err))
28839 + case AUFS_CTL_RDU:
28840 + err = au_rdu(file, &rdu);
28841 + if (unlikely(err))
28844 + e = copy_to_user(p, &rdu, sizeof(rdu));
28845 + if (unlikely(e)) {
28850 + case AUFS_CTL_RDU_INO:
28851 + err = au_rdu_ino(file, &rdu);
28855 + /* err = -ENOTTY; */
28864 +#ifdef CONFIG_COMPAT
28865 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
28868 + struct aufs_rdu rdu;
28869 + void __user *p = compat_ptr(arg);
28871 + /* todo: get_user()? */
28872 + err = copy_from_user(&rdu, p, sizeof(rdu));
28873 + if (unlikely(err)) {
28878 + rdu.ent.e = compat_ptr(rdu.ent.ul);
28879 + err = au_rdu_verify(&rdu);
28880 + if (unlikely(err))
28884 + case AUFS_CTL_RDU:
28885 + err = au_rdu(file, &rdu);
28886 + if (unlikely(err))
28889 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
28890 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
28891 + e = copy_to_user(p, &rdu, sizeof(rdu));
28892 + if (unlikely(e)) {
28897 + case AUFS_CTL_RDU_INO:
28898 + err = au_rdu_ino(file, &rdu);
28902 + /* err = -ENOTTY; */
28911 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
28912 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
28913 +++ linux/fs/aufs/rwsem.h 2021-12-03 15:38:59.939980643 +0100
28915 +/* SPDX-License-Identifier: GPL-2.0 */
28917 + * Copyright (C) 2005-2021 Junjiro R. Okajima
28919 + * This program, aufs is free software; you can redistribute it and/or modify
28920 + * it under the terms of the GNU General Public License as published by
28921 + * the Free Software Foundation; either version 2 of the License, or
28922 + * (at your option) any later version.
28924 + * This program is distributed in the hope that it will be useful,
28925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28927 + * GNU General Public License for more details.
28929 + * You should have received a copy of the GNU General Public License
28930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28934 + * simple read-write semaphore wrappers
28937 +#ifndef __AUFS_RWSEM_H__
28938 +#define __AUFS_RWSEM_H__
28942 +#include "debug.h"
28944 +/* in the future, the name 'au_rwsem' will be totally gone */
28945 +#define au_rwsem rw_semaphore
28947 +/* to debug easier, do not make them inlined functions */
28948 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
28949 +/* rwsem_is_locked() is unusable */
28950 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28951 + && !lockdep_recursing(current) \
28953 + && !lockdep_is_held_type(rw, 1))
28954 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28955 + && !lockdep_recursing(current) \
28957 + && !lockdep_is_held_type(rw, 0))
28958 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28959 + && !lockdep_recursing(current) \
28961 + && !lockdep_is_held(rw))
28962 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
28963 + && !lockdep_recursing(current) \
28965 + && lockdep_is_held(rw))
28967 +#define au_rw_init(rw) init_rwsem(rw)
28969 +#define au_rw_init_wlock(rw) do { \
28970 + au_rw_init(rw); \
28971 + down_write(rw); \
28974 +#define au_rw_init_wlock_nested(rw, lsc) do { \
28975 + au_rw_init(rw); \
28976 + down_write_nested(rw, lsc); \
28979 +#define au_rw_read_lock(rw) down_read(rw)
28980 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
28981 +#define au_rw_read_unlock(rw) up_read(rw)
28982 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
28983 +#define au_rw_write_lock(rw) down_write(rw)
28984 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
28985 +#define au_rw_write_unlock(rw) up_write(rw)
28986 +/* why is not _nested version defined? */
28987 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
28988 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
28990 +#endif /* __KERNEL__ */
28991 +#endif /* __AUFS_RWSEM_H__ */
28992 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
28993 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
28994 +++ linux/fs/aufs/sbinfo.c 2021-12-03 15:38:59.939980643 +0100
28996 +// SPDX-License-Identifier: GPL-2.0
28998 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29000 + * This program, aufs is free software; you can redistribute it and/or modify
29001 + * it under the terms of the GNU General Public License as published by
29002 + * the Free Software Foundation; either version 2 of the License, or
29003 + * (at your option) any later version.
29005 + * This program is distributed in the hope that it will be useful,
29006 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29007 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29008 + * GNU General Public License for more details.
29010 + * You should have received a copy of the GNU General Public License
29011 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29015 + * superblock private data
29018 +#include <linux/iversion.h>
29022 + * they are necessary regardless sysfs is disabled.
29024 +void au_si_free(struct kobject *kobj)
29027 + struct au_sbinfo *sbinfo;
29028 + char *locked __maybe_unused; /* debug only */
29030 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29031 + for (i = 0; i < AuPlink_NHASH; i++)
29032 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29033 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29035 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29036 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29037 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29038 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29040 + dbgaufs_si_fin(sbinfo);
29041 + au_rw_write_lock(&sbinfo->si_rwsem);
29042 + au_br_free(sbinfo);
29043 + au_rw_write_unlock(&sbinfo->si_rwsem);
29045 + au_kfree_try_rcu(sbinfo->si_branch);
29046 + mutex_destroy(&sbinfo->si_xib_mtx);
29047 + AuRwDestroy(&sbinfo->si_rwsem);
29049 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29050 + /* si_nfiles is waited too */
29051 + au_kfree_rcu(sbinfo);
29054 +int au_si_alloc(struct super_block *sb)
29057 + struct au_sbinfo *sbinfo;
29060 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29061 + if (unlikely(!sbinfo))
29064 + /* will be reallocated separately */
29065 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29066 + if (unlikely(!sbinfo->si_branch))
29069 + err = sysaufs_si_init(sbinfo);
29071 + dbgaufs_si_null(sbinfo);
29072 + err = dbgaufs_si_init(sbinfo);
29073 + if (unlikely(err))
29074 + kobject_put(&sbinfo->si_kobj);
29076 + if (unlikely(err))
29079 + au_nwt_init(&sbinfo->si_nowait);
29080 + au_rw_init_wlock(&sbinfo->si_rwsem);
29082 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29083 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29085 + sbinfo->si_bbot = -1;
29086 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29088 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29089 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29090 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29091 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29093 + au_fhsm_init(sbinfo);
29095 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29097 + sbinfo->si_xino_jiffy = jiffies;
29098 + sbinfo->si_xino_expire
29099 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29100 + mutex_init(&sbinfo->si_xib_mtx);
29101 + /* leave si_xib_last_pindex and si_xib_next_bit */
29103 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29105 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29106 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29107 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29108 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29110 + for (i = 0; i < AuPlink_NHASH; i++)
29111 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29112 + init_waitqueue_head(&sbinfo->si_plink_wq);
29113 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29115 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29117 + /* with getattr by default */
29118 + sbinfo->si_iop_array = aufs_iop;
29120 + /* leave other members for sysaufs and si_mnt. */
29121 + sbinfo->si_sb = sb;
29122 + sb->s_fs_info = sbinfo;
29124 + return 0; /* success */
29127 + au_kfree_try_rcu(sbinfo->si_branch);
29129 + au_kfree_rcu(sbinfo);
29134 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29137 + struct au_branch **brp;
29139 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29142 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29143 + if (unlikely(!sz))
29144 + sz = sizeof(*brp);
29145 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29148 + sbinfo->si_branch = brp;
29155 +/* ---------------------------------------------------------------------- */
29157 +unsigned int au_sigen_inc(struct super_block *sb)
29159 + unsigned int gen;
29160 + struct inode *inode;
29162 + SiMustWriteLock(sb);
29164 + gen = ++au_sbi(sb)->si_generation;
29165 + au_update_digen(sb->s_root);
29166 + inode = d_inode(sb->s_root);
29167 + au_update_iigen(inode, /*half*/0);
29168 + inode_inc_iversion(inode);
29172 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29174 + aufs_bindex_t br_id;
29176 + struct au_sbinfo *sbinfo;
29178 + SiMustWriteLock(sb);
29180 + sbinfo = au_sbi(sb);
29181 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29182 + br_id = ++sbinfo->si_last_br_id;
29183 + AuDebugOn(br_id < 0);
29184 + if (br_id && au_br_index(sb, br_id) < 0)
29191 +/* ---------------------------------------------------------------------- */
29193 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29194 +int si_read_lock(struct super_block *sb, int flags)
29199 + if (au_ftest_lock(flags, FLUSH))
29200 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29202 + si_noflush_read_lock(sb);
29203 + err = au_plink_maint(sb, flags);
29204 + if (unlikely(err))
29205 + si_read_unlock(sb);
29210 +int si_write_lock(struct super_block *sb, int flags)
29214 + if (au_ftest_lock(flags, FLUSH))
29215 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29217 + si_noflush_write_lock(sb);
29218 + err = au_plink_maint(sb, flags);
29219 + if (unlikely(err))
29220 + si_write_unlock(sb);
29225 +/* dentry and super_block lock. call at entry point */
29226 +int aufs_read_lock(struct dentry *dentry, int flags)
29229 + struct super_block *sb;
29231 + sb = dentry->d_sb;
29232 + err = si_read_lock(sb, flags);
29233 + if (unlikely(err))
29236 + if (au_ftest_lock(flags, DW))
29237 + di_write_lock_child(dentry);
29239 + di_read_lock_child(dentry, flags);
29241 + if (au_ftest_lock(flags, GEN)) {
29242 + err = au_digen_test(dentry, au_sigen(sb));
29243 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29244 + AuDebugOn(!err && au_dbrange_test(dentry));
29246 + err = au_dbrange_test(dentry);
29247 + if (unlikely(err))
29248 + aufs_read_unlock(dentry, flags);
29255 +void aufs_read_unlock(struct dentry *dentry, int flags)
29257 + if (au_ftest_lock(flags, DW))
29258 + di_write_unlock(dentry);
29260 + di_read_unlock(dentry, flags);
29261 + si_read_unlock(dentry->d_sb);
29264 +void aufs_write_lock(struct dentry *dentry)
29266 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29267 + di_write_lock_child(dentry);
29270 +void aufs_write_unlock(struct dentry *dentry)
29272 + di_write_unlock(dentry);
29273 + si_write_unlock(dentry->d_sb);
29276 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29279 + unsigned int sigen;
29280 + struct super_block *sb;
29283 + err = si_read_lock(sb, flags);
29284 + if (unlikely(err))
29287 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29289 + if (au_ftest_lock(flags, GEN)) {
29290 + sigen = au_sigen(sb);
29291 + err = au_digen_test(d1, sigen);
29292 + AuDebugOn(!err && au_dbrange_test(d1));
29294 + err = au_digen_test(d2, sigen);
29295 + AuDebugOn(!err && au_dbrange_test(d2));
29297 + if (unlikely(err))
29298 + aufs_read_and_write_unlock2(d1, d2);
29305 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29307 + di_write_unlock2(d1, d2);
29308 + si_read_unlock(d1->d_sb);
29310 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29311 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29312 +++ linux/fs/aufs/super.c 2021-12-03 15:38:59.939980643 +0100
29314 +// SPDX-License-Identifier: GPL-2.0
29316 + * Copyright (C) 2005-2021 Junjiro R. Okajima
29318 + * This program, aufs is free software; you can redistribute it and/or modify
29319 + * it under the terms of the GNU General Public License as published by
29320 + * the Free Software Foundation; either version 2 of the License, or
29321 + * (at your option) any later version.
29323 + * This program is distributed in the hope that it will be useful,
29324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29326 + * GNU General Public License for more details.
29328 + * You should have received a copy of the GNU General Public License
29329 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29333 + * mount and super_block operations
29336 +#include <linux/iversion.h>
29337 +#include <linux/mm.h>
29338 +#include <linux/seq_file.h>
29339 +#include <linux/statfs.h>
29340 +#include <linux/vmalloc.h>
29344 + * super_operations
29346 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29348 + struct au_icntnr *c;
29350 + c = au_cache_alloc_icntnr();
29352 + au_icntnr_init(c);
29353 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29354 + c->iinfo.ii_hinode = NULL;
29355 + return &c->vfs_inode;
29360 +static void aufs_destroy_inode(struct inode *inode)
29362 + if (!au_is_bad_inode(inode))
29363 + au_iinfo_fin(inode);
29366 +static void aufs_free_inode(struct inode *inode)
29368 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29371 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29373 + struct inode *inode;
29376 + inode = iget_locked(sb, ino);
29377 + if (unlikely(!inode)) {
29378 + inode = ERR_PTR(-ENOMEM);
29381 + if (!(inode->i_state & I_NEW))
29384 + err = au_xigen_new(inode);
29386 + err = au_iinfo_init(inode);
29388 + inode_inc_iversion(inode);
29390 + iget_failed(inode);
29391 + inode = ERR_PTR(err);
29395 + /* never return NULL */
29396 + AuDebugOn(!inode);
29397 + AuTraceErrPtr(inode);
29401 +/* lock free root dinfo */
29402 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29405 + aufs_bindex_t bindex, bbot;
29406 + struct path path;
29407 + struct au_hdentry *hdp;
29408 + struct au_branch *br;
29409 + au_br_perm_str_t perm;
29412 + bbot = au_sbbot(sb);
29414 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29415 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29416 + br = au_sbr(sb, bindex);
29417 + path.mnt = au_br_mnt(br);
29418 + path.dentry = hdp->hd_dentry;
29419 + err = au_seq_path(seq, &path);
29421 + au_optstr_br_perm(&perm, br->br_perm);
29422 + seq_printf(seq, "=%s", perm.a);
29423 + if (bindex != bbot)
29424 + seq_putc(seq, ':');
29427 + if (unlikely(err || seq_has_overflowed(seq)))
29433 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29434 + const char *append)
29439 + while (*pat != ':')
29442 + strcpy(p, append);
29443 + AuDebugOn(strlen(fmt) >= len);
29446 +static void au_show_wbr_create(struct seq_file *m, int v,
29447 + struct au_sbinfo *sbinfo)
29451 + struct au_wbr_mfs *mfs;
29453 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29455 + seq_puts(m, ",create=");
29456 + pat = au_optstr_wbr_create(v);
29457 + mfs = &sbinfo->si_wbr_mfs;
29459 + case AuWbrCreate_TDP:
29460 + case AuWbrCreate_RR:
29461 + case AuWbrCreate_MFS:
29462 + case AuWbrCreate_PMFS:
29463 + seq_puts(m, pat);
29465 + case AuWbrCreate_MFSRR:
29466 + case AuWbrCreate_TDMFS:
29467 + case AuWbrCreate_PMFSRR:
29468 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
29469 + seq_printf(m, fmt, mfs->mfsrr_watermark);
29471 + case AuWbrCreate_MFSV:
29472 + case AuWbrCreate_PMFSV:
29473 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
29474 + seq_printf(m, fmt,
29475 + jiffies_to_msecs(mfs->mfs_expire)
29478 + case AuWbrCreate_MFSRRV:
29479 + case AuWbrCreate_TDMFSV:
29480 + case AuWbrCreate_PMFSRRV:
29481 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
29482 + seq_printf(m, fmt, mfs->mfsrr_watermark,
29483 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
29490 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
29492 +#ifdef CONFIG_SYSFS
29496 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
29497 + aufs_bindex_t bindex, brid;
29498 + struct qstr *name;
29500 + struct dentry *d, *h_root;
29501 + struct au_branch *br;
29503 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29506 + f = au_sbi(sb)->si_xib;
29510 + /* stop printing the default xino path on the first writable branch */
29512 + bindex = au_xi_root(sb, f->f_path.dentry);
29513 + if (bindex >= 0) {
29514 + br = au_sbr_sb(sb, bindex);
29515 + h_root = au_br_dentry(br);
29518 + d = f->f_path.dentry;
29519 + name = &d->d_name;
29520 + /* safe ->d_parent because the file is unlinked */
29521 + if (d->d_parent == h_root
29522 + && name->len == len
29523 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
29526 + seq_puts(seq, ",xino=");
29527 + err = au_xino_path(seq, f);
29534 +/* seq_file will re-call me in case of too long string */
29535 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
29538 + unsigned int mnt_flags, v;
29539 + struct super_block *sb;
29540 + struct au_sbinfo *sbinfo;
29542 +#define AuBool(name, str) do { \
29543 + v = au_opt_test(mnt_flags, name); \
29544 + if (v != au_opt_test(AuOpt_Def, name)) \
29545 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
29548 +#define AuStr(name, str) do { \
29549 + v = mnt_flags & AuOptMask_##name; \
29550 + if (v != (AuOpt_Def & AuOptMask_##name)) \
29551 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
29554 +#define AuUInt(name, str, val) do { \
29555 + if (val != AUFS_##name##_DEF) \
29556 + seq_printf(m, "," #str "=%u", val); \
29559 + sb = dentry->d_sb;
29560 + if (sb->s_flags & SB_POSIXACL)
29561 + seq_puts(m, ",acl");
29562 +#if 0 /* reserved for future use */
29563 + if (sb->s_flags & SB_I_VERSION)
29564 + seq_puts(m, ",i_version");
29567 + /* lock free root dinfo */
29568 + si_noflush_read_lock(sb);
29569 + sbinfo = au_sbi(sb);
29570 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
29572 + mnt_flags = au_mntflags(sb);
29573 + if (au_opt_test(mnt_flags, XINO)) {
29574 + err = au_show_xino(m, sb);
29575 + if (unlikely(err))
29578 + seq_puts(m, ",noxino");
29580 + AuBool(TRUNC_XINO, trunc_xino);
29581 + AuStr(UDBA, udba);
29582 + AuBool(SHWH, shwh);
29583 + AuBool(PLINK, plink);
29584 + AuBool(DIO, dio);
29585 + AuBool(DIRPERM1, dirperm1);
29587 + v = sbinfo->si_wbr_create;
29588 + if (v != AuWbrCreate_Def)
29589 + au_show_wbr_create(m, v, sbinfo);
29591 + v = sbinfo->si_wbr_copyup;
29592 + if (v != AuWbrCopyup_Def)
29593 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
29595 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
29596 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
29597 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
29599 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
29601 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
29602 + AuUInt(RDCACHE, rdcache, v);
29604 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
29605 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
29607 + au_fhsm_show(m, sbinfo);
29609 + AuBool(DIRREN, dirren);
29610 + AuBool(SUM, sum);
29611 + /* AuBool(SUM_W, wsum); */
29612 + AuBool(WARN_PERM, warn_perm);
29613 + AuBool(VERBOSE, verbose);
29616 + /* be sure to print "br:" last */
29617 + if (!sysaufs_brs) {
29618 + seq_puts(m, ",br:");
29619 + au_show_brs(m, sb);
29621 + si_read_unlock(sb);
29629 +/* ---------------------------------------------------------------------- */
29631 +/* sum mode which returns the summation for statfs(2) */
29633 +static u64 au_add_till_max(u64 a, u64 b)
29641 + return ULLONG_MAX;
29644 +static u64 au_mul_till_max(u64 a, long mul)
29652 + return ULLONG_MAX;
29655 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
29658 + long bsize, factor;
29659 + u64 blocks, bfree, bavail, files, ffree;
29660 + aufs_bindex_t bbot, bindex, i;
29661 + unsigned char shared;
29662 + struct path h_path;
29663 + struct super_block *h_sb;
29666 + bsize = LONG_MAX;
29672 + bbot = au_sbbot(sb);
29673 + for (bindex = 0; bindex <= bbot; bindex++) {
29674 + h_path.mnt = au_sbr_mnt(sb, bindex);
29675 + h_sb = h_path.mnt->mnt_sb;
29677 + for (i = 0; !shared && i < bindex; i++)
29678 + shared = (au_sbr_sb(sb, i) == h_sb);
29682 + /* sb->s_root for NFS is unreliable */
29683 + h_path.dentry = h_path.mnt->mnt_root;
29684 + err = vfs_statfs(&h_path, buf);
29685 + if (unlikely(err))
29688 + if (bsize > buf->f_bsize) {
29690 + * we will reduce bsize, so we have to expand blocks
29691 + * etc. to match them again
29693 + factor = (bsize / buf->f_bsize);
29694 + blocks = au_mul_till_max(blocks, factor);
29695 + bfree = au_mul_till_max(bfree, factor);
29696 + bavail = au_mul_till_max(bavail, factor);
29697 + bsize = buf->f_bsize;
29700 + factor = (buf->f_bsize / bsize);
29701 + blocks = au_add_till_max(blocks,
29702 + au_mul_till_max(buf->f_blocks, factor));
29703 + bfree = au_add_till_max(bfree,
29704 + au_mul_till_max(buf->f_bfree, factor));
29705 + bavail = au_add_till_max(bavail,
29706 + au_mul_till_max(buf->f_bavail, factor));
29707 + files = au_add_till_max(files, buf->f_files);
29708 + ffree = au_add_till_max(ffree, buf->f_ffree);
29711 + buf->f_bsize = bsize;
29712 + buf->f_blocks = blocks;
29713 + buf->f_bfree = bfree;
29714 + buf->f_bavail = bavail;
29715 + buf->f_files = files;
29716 + buf->f_ffree = ffree;
29717 + buf->f_frsize = 0;
29723 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
29726 + struct path h_path;
29727 + struct super_block *sb;
29729 + /* lock free root dinfo */
29730 + sb = dentry->d_sb;
29731 + si_noflush_read_lock(sb);
29732 + if (!au_opt_test(au_mntflags(sb), SUM)) {
29733 + /* sb->s_root for NFS is unreliable */
29734 + h_path.mnt = au_sbr_mnt(sb, 0);
29735 + h_path.dentry = h_path.mnt->mnt_root;
29736 + err = vfs_statfs(&h_path, buf);
29738 + err = au_statfs_sum(sb, buf);
29739 + si_read_unlock(sb);
29742 + buf->f_type = AUFS_SUPER_MAGIC;
29743 + buf->f_namelen = AUFS_MAX_NAMELEN;
29744 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
29746 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
29751 +/* ---------------------------------------------------------------------- */
29753 +static int aufs_sync_fs(struct super_block *sb, int wait)
29756 + aufs_bindex_t bbot, bindex;
29757 + struct au_branch *br;
29758 + struct super_block *h_sb;
29761 + si_noflush_read_lock(sb);
29762 + bbot = au_sbbot(sb);
29763 + for (bindex = 0; bindex <= bbot; bindex++) {
29764 + br = au_sbr(sb, bindex);
29765 + if (!au_br_writable(br->br_perm))
29768 + h_sb = au_sbr_sb(sb, bindex);
29769 + e = vfsub_sync_filesystem(h_sb, wait);
29770 + if (unlikely(e && !err))
29772 + /* go on even if an error happens */
29774 + si_read_unlock(sb);
29779 +/* ---------------------------------------------------------------------- */
29781 +/* final actions when unmounting a file system */
29782 +static void aufs_put_super(struct super_block *sb)
29784 + struct au_sbinfo *sbinfo;
29786 + sbinfo = au_sbi(sb);
29788 + kobject_put(&sbinfo->si_kobj);
29791 +/* ---------------------------------------------------------------------- */
29793 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
29794 + struct super_block *sb, void *arg)
29797 + unsigned long long n, sz;
29804 + if (*hint > ULLONG_MAX / sizeof(array)) {
29805 + array = ERR_PTR(-EMFILE);
29806 + pr_err("hint %llu\n", *hint);
29810 + sz = sizeof(array) * *hint;
29811 + array = kzalloc(sz, GFP_NOFS);
29812 + if (unlikely(!array))
29813 + array = vzalloc(sz);
29814 + if (unlikely(!array)) {
29815 + array = ERR_PTR(-ENOMEM);
29819 + n = cb(sb, array, *hint, arg);
29820 + AuDebugOn(n > *hint);
29827 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
29828 + unsigned long long max __maybe_unused,
29831 + unsigned long long n;
29832 + struct inode **p, *inode;
29833 + struct list_head *head;
29838 + spin_lock(&sb->s_inode_list_lock);
29839 + list_for_each_entry(inode, head, i_sb_list) {
29840 + if (!au_is_bad_inode(inode)
29841 + && au_ii(inode)->ii_btop >= 0) {
29842 + spin_lock(&inode->i_lock);
29843 + if (atomic_read(&inode->i_count)) {
29847 + AuDebugOn(n > max);
29849 + spin_unlock(&inode->i_lock);
29852 + spin_unlock(&sb->s_inode_list_lock);
29857 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
29859 + struct au_sbinfo *sbi;
29861 + sbi = au_sbi(sb);
29862 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
29863 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
29866 +void au_iarray_free(struct inode **a, unsigned long long max)
29868 + unsigned long long ull;
29870 + for (ull = 0; ull < max; ull++)
29875 +/* ---------------------------------------------------------------------- */
29878 + * refresh dentry and inode at remount time.
29880 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
29881 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
29882 + struct dentry *parent)
29886 + di_write_lock_child(dentry);
29887 + di_read_lock_parent(parent, AuLock_IR);
29888 + err = au_refresh_dentry(dentry, parent);
29889 + if (!err && dir_flags)
29890 + au_hn_reset(d_inode(dentry), dir_flags);
29891 + di_read_unlock(parent, AuLock_IR);
29892 + di_write_unlock(dentry);
29897 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
29898 + struct au_sbinfo *sbinfo,
29899 + const unsigned int dir_flags, unsigned int do_idop)
29902 + struct dentry *parent;
29905 + parent = dget_parent(dentry);
29906 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
29907 + if (d_really_is_positive(dentry)) {
29908 + if (!d_is_dir(dentry))
29909 + err = au_do_refresh(dentry, /*dir_flags*/0,
29912 + err = au_do_refresh(dentry, dir_flags, parent);
29913 + if (unlikely(err))
29914 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
29917 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
29918 + AuDbgDentry(dentry);
29924 + au_refresh_dop(dentry, /*force_reval*/0);
29926 + au_refresh_dop(dentry, /*force_reval*/1);
29932 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
29934 + int err, i, j, ndentry, e;
29935 + unsigned int sigen;
29936 + struct au_dcsub_pages dpages;
29937 + struct au_dpage *dpage;
29938 + struct dentry **dentries, *d;
29939 + struct au_sbinfo *sbinfo;
29940 + struct dentry *root = sb->s_root;
29941 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
29944 + au_refresh_dop(root, /*force_reval*/0);
29946 + err = au_dpages_init(&dpages, GFP_NOFS);
29947 + if (unlikely(err))
29949 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
29950 + if (unlikely(err))
29953 + sigen = au_sigen(sb);
29954 + sbinfo = au_sbi(sb);
29955 + for (i = 0; i < dpages.ndpage; i++) {
29956 + dpage = dpages.dpages + i;
29957 + dentries = dpage->dentries;
29958 + ndentry = dpage->ndentry;
29959 + for (j = 0; j < ndentry; j++) {
29961 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
29963 + if (unlikely(e && !err))
29965 + /* go on even err */
29970 + au_dpages_free(&dpages);
29975 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
29978 + unsigned int sigen;
29979 + unsigned long long max, ull;
29980 + struct inode *inode, **array;
29982 + array = au_iarray_alloc(sb, &max);
29983 + err = PTR_ERR(array);
29984 + if (IS_ERR(array))
29988 + sigen = au_sigen(sb);
29989 + for (ull = 0; ull < max; ull++) {
29990 + inode = array[ull];
29991 + if (unlikely(!inode))
29995 + ii_write_lock_child(inode);
29996 + if (au_iigen(inode, NULL) != sigen) {
29997 + e = au_refresh_hinode_self(inode);
29998 + if (unlikely(e)) {
29999 + au_refresh_iop(inode, /*force_getattr*/1);
30000 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30003 + /* go on even if err */
30006 + if (!e && do_idop)
30007 + au_refresh_iop(inode, /*force_getattr*/0);
30008 + ii_write_unlock(inode);
30011 + au_iarray_free(array, max);
30017 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30020 + unsigned int udba;
30021 + aufs_bindex_t bindex, bbot;
30022 + struct dentry *root;
30023 + struct inode *inode;
30024 + struct au_branch *br;
30025 + struct au_sbinfo *sbi;
30027 + au_sigen_inc(sb);
30028 + sbi = au_sbi(sb);
30029 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30031 + root = sb->s_root;
30032 + DiMustNoWaiters(root);
30033 + inode = d_inode(root);
30034 + IiMustNoWaiters(inode);
30036 + udba = au_opt_udba(sb);
30037 + bbot = au_sbbot(sb);
30038 + for (bindex = 0; bindex <= bbot; bindex++) {
30039 + br = au_sbr(sb, bindex);
30040 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30041 + if (unlikely(err))
30042 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30044 + /* go on even if err */
30046 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30049 + if (au_ftest_si(sbi, NO_DREVAL)) {
30050 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30051 + sb->s_d_op = &aufs_dop_noreval;
30052 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30053 + sbi->si_iop_array = aufs_iop_nogetattr;
30055 + AuDebugOn(sb->s_d_op == &aufs_dop);
30056 + sb->s_d_op = &aufs_dop;
30057 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30058 + sbi->si_iop_array = aufs_iop;
30060 + pr_info("reset to %ps and %ps\n",
30061 + sb->s_d_op, sbi->si_iop_array);
30064 + di_write_unlock(root);
30065 + err = au_refresh_d(sb, do_idop);
30066 + e = au_refresh_i(sb, do_idop);
30067 + if (unlikely(e && !err))
30069 + /* aufs_write_lock() calls ..._child() */
30070 + di_write_lock_child(root);
30072 + au_cpup_attr_all(inode, /*force*/1);
30074 + if (unlikely(err))
30075 + AuIOErr("refresh failed, ignored, %d\n", err);
30078 +/* stop extra interpretation of errno in mount(8), and strange error messages */
30079 +static int cvt_err(int err)
30093 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
30096 + unsigned int mntflags;
30097 + struct au_opts opts = {
30100 + struct dentry *root;
30101 + struct inode *inode;
30102 + struct au_sbinfo *sbinfo;
30105 + root = sb->s_root;
30106 + if (!data || !*data) {
30107 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30109 + di_write_lock_child(root);
30110 + err = au_opts_verify(sb, *flags, /*pending*/0);
30111 + aufs_write_unlock(root);
30117 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30118 + if (unlikely(!opts.opt))
30120 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30121 + opts.flags = AuOpts_REMOUNT;
30122 + opts.sb_flags = *flags;
30124 + /* parse it before aufs lock */
30125 + err = au_opts_parse(sb, data, &opts);
30126 + if (unlikely(err))
30129 + sbinfo = au_sbi(sb);
30130 + inode = d_inode(root);
30131 + inode_lock(inode);
30132 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
30133 + if (unlikely(err))
30135 + di_write_lock_child(root);
30137 + /* au_opts_remount() may return an error */
30138 + err = au_opts_remount(sb, &opts);
30139 + au_opts_free(&opts);
30141 + if (au_ftest_opts(opts.flags, REFRESH))
30142 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
30144 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
30145 + mntflags = au_mntflags(sb);
30146 + do_dx = !!au_opt_test(mntflags, DIO);
30147 + au_dy_arefresh(do_dx);
30150 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
30151 + aufs_write_unlock(root);
30154 + inode_unlock(inode);
30156 + free_page((unsigned long)opts.opt);
30158 + err = cvt_err(err);
30163 +static const struct super_operations aufs_sop = {
30164 + .alloc_inode = aufs_alloc_inode,
30165 + .destroy_inode = aufs_destroy_inode,
30166 + .free_inode = aufs_free_inode,
30167 + /* always deleting, no clearing */
30168 + .drop_inode = generic_delete_inode,
30169 + .show_options = aufs_show_options,
30170 + .statfs = aufs_statfs,
30171 + .put_super = aufs_put_super,
30172 + .sync_fs = aufs_sync_fs,
30173 + .remount_fs = aufs_remount_fs
30176 +/* ---------------------------------------------------------------------- */
30178 +static int alloc_root(struct super_block *sb)
30181 + struct inode *inode;
30182 + struct dentry *root;
30185 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30186 + err = PTR_ERR(inode);
30187 + if (IS_ERR(inode))
30190 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30191 + inode->i_fop = &aufs_dir_fop;
30192 + inode->i_mode = S_IFDIR;
30193 + set_nlink(inode, 2);
30194 + unlock_new_inode(inode);
30196 + root = d_make_root(inode);
30197 + if (unlikely(!root))
30199 + err = PTR_ERR(root);
30200 + if (IS_ERR(root))
30203 + err = au_di_init(root);
30205 + sb->s_root = root;
30206 + return 0; /* success */
30214 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
30215 + int silent __maybe_unused)
30218 + struct au_opts opts = {
30221 + struct au_sbinfo *sbinfo;
30222 + struct dentry *root;
30223 + struct inode *inode;
30224 + char *arg = raw_data;
30226 + if (unlikely(!arg || !*arg)) {
30228 + pr_err("no arg\n");
30233 + opts.opt = (void *)__get_free_page(GFP_NOFS);
30234 + if (unlikely(!opts.opt))
30236 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
30237 + opts.sb_flags = sb->s_flags;
30239 + err = au_si_alloc(sb);
30240 + if (unlikely(err))
30242 + sbinfo = au_sbi(sb);
30244 + /* all timestamps always follow the ones on the branch */
30245 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
30246 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
30247 + sb->s_op = &aufs_sop;
30248 + sb->s_d_op = &aufs_dop;
30249 + sb->s_magic = AUFS_SUPER_MAGIC;
30250 + sb->s_maxbytes = 0;
30251 + sb->s_stack_depth = 1;
30252 + au_export_init(sb);
30253 + au_xattr_init(sb);
30255 + err = alloc_root(sb);
30256 + if (unlikely(err)) {
30257 + si_write_unlock(sb);
30260 + root = sb->s_root;
30261 + inode = d_inode(root);
30264 + * actually we can parse options regardless aufs lock here.
30265 + * but at remount time, parsing must be done before aufs lock.
30266 + * so we follow the same rule.
30268 + ii_write_lock_parent(inode);
30269 + aufs_write_unlock(root);
30270 + err = au_opts_parse(sb, arg, &opts);
30271 + if (unlikely(err))
30274 + /* lock vfs_inode first, then aufs. */
30275 + inode_lock(inode);
30276 + aufs_write_lock(root);
30277 + err = au_opts_mount(sb, &opts);
30278 + au_opts_free(&opts);
30279 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
30280 + sb->s_d_op = &aufs_dop_noreval;
30281 + pr_info("%ps\n", sb->s_d_op);
30282 + au_refresh_dop(root, /*force_reval*/0);
30283 + sbinfo->si_iop_array = aufs_iop_nogetattr;
30284 + au_refresh_iop(inode, /*force_getattr*/0);
30286 + aufs_write_unlock(root);
30287 + inode_unlock(inode);
30289 + goto out_opts; /* success */
30293 + sb->s_root = NULL;
30295 + kobject_put(&sbinfo->si_kobj);
30296 + sb->s_fs_info = NULL;
30298 + free_page((unsigned long)opts.opt);
30301 + err = cvt_err(err);
30306 +/* ---------------------------------------------------------------------- */
30308 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
30309 + const char *dev_name __maybe_unused,
30312 + struct dentry *root;
30314 + /* all timestamps always follow the ones on the branch */
30315 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
30316 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
30317 + if (IS_ERR(root))
30320 + au_sbilist_add(root->d_sb);
30326 +static void aufs_kill_sb(struct super_block *sb)
30328 + struct au_sbinfo *sbinfo;
30330 + sbinfo = au_sbi(sb);
30332 + au_sbilist_del(sb);
30333 + aufs_write_lock(sb->s_root);
30335 + if (sbinfo->si_wbr_create_ops->fin)
30336 + sbinfo->si_wbr_create_ops->fin(sb);
30337 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30338 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30339 + au_remount_refresh(sb, /*do_idop*/0);
30341 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30342 + au_plink_put(sb, /*verbose*/1);
30344 + au_dr_opt_flush(sb);
30345 + sbinfo->si_sb = NULL;
30346 + aufs_write_unlock(sb->s_root);
30347 + au_nwt_flush(&sbinfo->si_nowait);
30349 + kill_anon_super(sb);
30352 +struct file_system_type aufs_fs_type = {
30353 + .name = AUFS_FSTYPE,
30354 + /* a race between rename and others */
30355 + .fs_flags = FS_RENAME_DOES_D_MOVE,
30356 + .mount = aufs_mount,
30357 + .kill_sb = aufs_kill_sb,
30358 + /* no need to __module_get() and module_put(). */
30359 + .owner = THIS_MODULE,
30361 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30362 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30363 +++ linux/fs/aufs/super.h 2021-12-03 15:38:59.939980643 +0100
30365 +/* SPDX-License-Identifier: GPL-2.0 */
30367 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30369 + * This program, aufs is free software; you can redistribute it and/or modify
30370 + * it under the terms of the GNU General Public License as published by
30371 + * the Free Software Foundation; either version 2 of the License, or
30372 + * (at your option) any later version.
30374 + * This program is distributed in the hope that it will be useful,
30375 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30376 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30377 + * GNU General Public License for more details.
30379 + * You should have received a copy of the GNU General Public License
30380 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30384 + * super_block operations
30387 +#ifndef __AUFS_SUPER_H__
30388 +#define __AUFS_SUPER_H__
30392 +#include <linux/fs.h>
30393 +#include <linux/kobject.h>
30396 +#include "rwsem.h"
30399 +/* policies to select one among multiple writable branches */
30400 +struct au_wbr_copyup_operations {
30401 + int (*copyup)(struct dentry *dentry);
30404 +#define AuWbr_DIR 1 /* target is a dir */
30405 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30407 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30408 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30409 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30411 +struct au_wbr_create_operations {
30412 + int (*create)(struct dentry *dentry, unsigned int flags);
30413 + int (*init)(struct super_block *sb);
30414 + int (*fin)(struct super_block *sb);
30417 +struct au_wbr_mfs {
30418 + struct mutex mfs_lock; /* protect this structure */
30419 + unsigned long mfs_jiffy;
30420 + unsigned long mfs_expire;
30421 + aufs_bindex_t mfs_bindex;
30423 + unsigned long long mfsrr_bytes;
30424 + unsigned long long mfsrr_watermark;
30427 +#define AuPlink_NHASH 100
30428 +static inline int au_plink_hash(ino_t ino)
30430 + return ino % AuPlink_NHASH;
30433 +/* File-based Hierarchical Storage Management */
30435 +#ifdef CONFIG_AUFS_FHSM
30436 + /* allow only one process who can receive the notification */
30437 + spinlock_t fhsm_spin;
30439 + wait_queue_head_t fhsm_wqh;
30440 + atomic_t fhsm_readable;
30442 + /* these are protected by si_rwsem */
30443 + unsigned long fhsm_expire;
30444 + aufs_bindex_t fhsm_bottom;
30449 +struct au_sbinfo {
30450 + /* nowait tasks in the system-wide workqueue */
30451 + struct au_nowait_tasks si_nowait;
30454 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30455 + * rwsem for au_sbinfo is necessary.
30457 + struct au_rwsem si_rwsem;
30460 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30463 + au_lcnt_t si_ninodes, si_nfiles;
30465 + /* branch management */
30466 + unsigned int si_generation;
30468 + /* see AuSi_ flags */
30469 + unsigned char au_si_status;
30471 + aufs_bindex_t si_bbot;
30473 + /* dirty trick to keep br_id plus */
30474 + unsigned int si_last_br_id :
30475 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30476 + struct au_branch **si_branch;
30478 + /* policy to select a writable branch */
30479 + unsigned char si_wbr_copyup;
30480 + unsigned char si_wbr_create;
30481 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30482 + struct au_wbr_create_operations *si_wbr_create_ops;
30484 + /* round robin */
30485 + atomic_t si_wbr_rr_next;
30487 + /* most free space */
30488 + struct au_wbr_mfs si_wbr_mfs;
30490 + /* File-based Hierarchical Storage Management */
30491 + struct au_fhsm si_fhsm;
30493 + /* mount flags */
30494 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30495 + unsigned int si_mntflags;
30497 + /* external inode number (bitmap and translation table) */
30498 + loff_t si_ximaxent; /* max entries in a xino */
30500 + struct file *si_xib;
30501 + struct mutex si_xib_mtx; /* protect xib members */
30502 + unsigned long *si_xib_buf;
30503 + unsigned long si_xib_last_pindex;
30504 + int si_xib_next_bit;
30506 + unsigned long si_xino_jiffy;
30507 + unsigned long si_xino_expire;
30508 + /* reserved for future use */
30509 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30511 +#ifdef CONFIG_AUFS_EXPORT
30512 + /* i_generation */
30513 + /* todo: make xigen file an array to support many inode numbers */
30514 + struct file *si_xigen;
30515 + atomic_t si_xigen_next;
30518 + /* dirty trick to support atomic_open */
30519 + struct hlist_bl_head si_aopen;
30521 + /* vdir parameters */
30522 + unsigned long si_rdcache; /* max cache time in jiffies */
30523 + unsigned int si_rdblk; /* deblk size */
30524 + unsigned int si_rdhash; /* hash size */
30527 + * If the number of whiteouts are larger than si_dirwh, leave all of
30528 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30529 + * future fsck.aufs or kernel thread will remove them later.
30530 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30532 + unsigned int si_dirwh;
30534 + /* pseudo_link list */
30535 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30536 + wait_queue_head_t si_plink_wq;
30537 + spinlock_t si_plink_maint_lock;
30538 + pid_t si_plink_maint_pid;
30541 + struct hlist_bl_head si_files;
30543 + /* with/without getattr, brother of sb->s_d_op */
30544 + const struct inode_operations *si_iop_array;
30547 + * sysfs and lifetime management.
30548 + * this is not a small structure and it may be a waste of memory in case
30549 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30550 + * but using sysfs is majority.
30552 + struct kobject si_kobj;
30553 +#ifdef CONFIG_DEBUG_FS
30554 + struct dentry *si_dbgaufs;
30555 + struct dentry *si_dbgaufs_plink;
30556 + struct dentry *si_dbgaufs_xib;
30557 +#ifdef CONFIG_AUFS_EXPORT
30558 + struct dentry *si_dbgaufs_xigen;
30562 +#ifdef CONFIG_AUFS_SBILIST
30563 + struct hlist_bl_node si_list;
30566 + /* dirty, necessary for unmounting, sysfs and sysrq */
30567 + struct super_block *si_sb;
30570 +/* sbinfo status flags */
30572 + * set true when refresh_dirs() failed at remount time.
30573 + * then try refreshing dirs at access time again.
30574 + * if it is false, refreshing dirs at access time is unnecessary
30576 +#define AuSi_FAILED_REFRESH_DIR 1
30577 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30578 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30580 +#ifndef CONFIG_AUFS_FHSM
30582 +#define AuSi_FHSM 0
30585 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30586 + unsigned int flag)
30588 + AuRwMustAnyLock(&sbi->si_rwsem);
30589 + return sbi->au_si_status & flag;
30591 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30592 +#define au_fset_si(sbinfo, name) do { \
30593 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30594 + (sbinfo)->au_si_status |= AuSi_##name; \
30596 +#define au_fclr_si(sbinfo, name) do { \
30597 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30598 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30601 +/* ---------------------------------------------------------------------- */
30603 +/* policy to select one among writable branches */
30604 +#define AuWbrCopyup(sbinfo, ...) \
30605 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30606 +#define AuWbrCreate(sbinfo, ...) \
30607 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30609 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30610 +#define AuLock_DW 1 /* write-lock dentry */
30611 +#define AuLock_IR (1 << 1) /* read-lock inode */
30612 +#define AuLock_IW (1 << 2) /* write-lock inode */
30613 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30614 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30615 + /* except RENAME_EXCHANGE */
30616 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30617 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30618 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30619 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30620 +#define au_fset_lock(flags, name) \
30621 + do { (flags) |= AuLock_##name; } while (0)
30622 +#define au_fclr_lock(flags, name) \
30623 + do { (flags) &= ~AuLock_##name; } while (0)
30625 +/* ---------------------------------------------------------------------- */
30628 +extern struct file_system_type aufs_fs_type;
30629 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30630 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30631 + unsigned long long max, void *arg);
30632 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30633 + struct super_block *sb, void *arg);
30634 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30635 +void au_iarray_free(struct inode **a, unsigned long long max);
30638 +void au_si_free(struct kobject *kobj);
30639 +int au_si_alloc(struct super_block *sb);
30640 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
30642 +unsigned int au_sigen_inc(struct super_block *sb);
30643 +aufs_bindex_t au_new_br_id(struct super_block *sb);
30645 +int si_read_lock(struct super_block *sb, int flags);
30646 +int si_write_lock(struct super_block *sb, int flags);
30647 +int aufs_read_lock(struct dentry *dentry, int flags);
30648 +void aufs_read_unlock(struct dentry *dentry, int flags);
30649 +void aufs_write_lock(struct dentry *dentry);
30650 +void aufs_write_unlock(struct dentry *dentry);
30651 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
30652 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
30654 +/* wbr_policy.c */
30655 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
30656 +extern struct au_wbr_create_operations au_wbr_create_ops[];
30657 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
30658 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
30659 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
30662 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
30664 +#ifdef CONFIG_AUFS_FHSM
30667 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
30671 + spin_lock(&fhsm->fhsm_spin);
30672 + pid = fhsm->fhsm_pid;
30673 + spin_unlock(&fhsm->fhsm_spin);
30678 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
30679 +void au_fhsm_wrote_all(struct super_block *sb, int force);
30680 +int au_fhsm_fd(struct super_block *sb, int oflags);
30681 +int au_fhsm_br_alloc(struct au_branch *br);
30682 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
30683 +void au_fhsm_fin(struct super_block *sb);
30684 +void au_fhsm_init(struct au_sbinfo *sbinfo);
30685 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
30686 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
30688 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
30690 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
30691 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
30692 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
30693 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
30694 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
30695 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
30696 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
30697 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
30698 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
30701 +/* ---------------------------------------------------------------------- */
30703 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
30705 + return sb->s_fs_info;
30708 +/* ---------------------------------------------------------------------- */
30710 +#ifdef CONFIG_AUFS_EXPORT
30711 +int au_test_nfsd(void);
30712 +void au_export_init(struct super_block *sb);
30713 +void au_xigen_inc(struct inode *inode);
30714 +int au_xigen_new(struct inode *inode);
30715 +int au_xigen_set(struct super_block *sb, struct path *path);
30716 +void au_xigen_clr(struct super_block *sb);
30718 +static inline int au_busy_or_stale(void)
30720 + if (!au_test_nfsd())
30725 +AuStubInt0(au_test_nfsd, void)
30726 +AuStubVoid(au_export_init, struct super_block *sb)
30727 +AuStubVoid(au_xigen_inc, struct inode *inode)
30728 +AuStubInt0(au_xigen_new, struct inode *inode)
30729 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
30730 +AuStubVoid(au_xigen_clr, struct super_block *sb)
30731 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
30732 +#endif /* CONFIG_AUFS_EXPORT */
30734 +/* ---------------------------------------------------------------------- */
30736 +#ifdef CONFIG_AUFS_SBILIST
30738 +extern struct hlist_bl_head au_sbilist;
30740 +static inline void au_sbilist_init(void)
30742 + INIT_HLIST_BL_HEAD(&au_sbilist);
30745 +static inline void au_sbilist_add(struct super_block *sb)
30747 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
30750 +static inline void au_sbilist_del(struct super_block *sb)
30752 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
30755 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
30756 +static inline void au_sbilist_lock(void)
30758 + hlist_bl_lock(&au_sbilist);
30761 +static inline void au_sbilist_unlock(void)
30763 + hlist_bl_unlock(&au_sbilist);
30765 +#define AuGFP_SBILIST GFP_ATOMIC
30767 +AuStubVoid(au_sbilist_lock, void)
30768 +AuStubVoid(au_sbilist_unlock, void)
30769 +#define AuGFP_SBILIST GFP_NOFS
30770 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
30772 +AuStubVoid(au_sbilist_init, void)
30773 +AuStubVoid(au_sbilist_add, struct super_block *sb)
30774 +AuStubVoid(au_sbilist_del, struct super_block *sb)
30775 +AuStubVoid(au_sbilist_lock, void)
30776 +AuStubVoid(au_sbilist_unlock, void)
30777 +#define AuGFP_SBILIST GFP_NOFS
30780 +/* ---------------------------------------------------------------------- */
30782 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
30785 + * This function is a dynamic '__init' function actually,
30786 + * so the tiny check for si_rwsem is unnecessary.
30788 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
30789 +#ifdef CONFIG_DEBUG_FS
30790 + sbinfo->si_dbgaufs = NULL;
30791 + sbinfo->si_dbgaufs_plink = NULL;
30792 + sbinfo->si_dbgaufs_xib = NULL;
30793 +#ifdef CONFIG_AUFS_EXPORT
30794 + sbinfo->si_dbgaufs_xigen = NULL;
30799 +/* ---------------------------------------------------------------------- */
30801 +/* current->atomic_flags */
30802 +/* this value should never corrupt the ones defined in linux/sched.h */
30803 +#define PFA_AUFS 0x10
30805 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
30806 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
30807 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
30809 +static inline int si_pid_test(struct super_block *sb)
30811 + return !!task_test_aufs(current);
30814 +static inline void si_pid_clr(struct super_block *sb)
30816 + AuDebugOn(!task_test_aufs(current));
30817 + task_clear_aufs(current);
30820 +static inline void si_pid_set(struct super_block *sb)
30822 + AuDebugOn(task_test_aufs(current));
30823 + task_set_aufs(current);
30826 +/* ---------------------------------------------------------------------- */
30828 +/* lock superblock. mainly for entry point functions */
30829 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
30830 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
30831 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
30832 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
30834 +#define __si_read_trylock_nested(sb) \
30835 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
30836 +#define __si_write_trylock_nested(sb) \
30837 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
30840 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
30841 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
30842 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
30844 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
30845 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
30846 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
30848 +static inline void si_noflush_read_lock(struct super_block *sb)
30850 + __si_read_lock(sb);
30854 +static inline int si_noflush_read_trylock(struct super_block *sb)
30858 + locked = __si_read_trylock(sb);
30864 +static inline void si_noflush_write_lock(struct super_block *sb)
30866 + __si_write_lock(sb);
30870 +static inline int si_noflush_write_trylock(struct super_block *sb)
30874 + locked = __si_write_trylock(sb);
30880 +#if 0 /* reserved */
30881 +static inline int si_read_trylock(struct super_block *sb, int flags)
30883 + if (au_ftest_lock(flags, FLUSH))
30884 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30885 + return si_noflush_read_trylock(sb);
30889 +static inline void si_read_unlock(struct super_block *sb)
30892 + __si_read_unlock(sb);
30895 +#if 0 /* reserved */
30896 +static inline int si_write_trylock(struct super_block *sb, int flags)
30898 + if (au_ftest_lock(flags, FLUSH))
30899 + au_nwt_flush(&au_sbi(sb)->si_nowait);
30900 + return si_noflush_write_trylock(sb);
30904 +static inline void si_write_unlock(struct super_block *sb)
30907 + __si_write_unlock(sb);
30910 +#if 0 /* reserved */
30911 +static inline void si_downgrade_lock(struct super_block *sb)
30913 + __si_downgrade_lock(sb);
30917 +/* ---------------------------------------------------------------------- */
30919 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
30921 + SiMustAnyLock(sb);
30922 + return au_sbi(sb)->si_bbot;
30925 +static inline unsigned int au_mntflags(struct super_block *sb)
30927 + SiMustAnyLock(sb);
30928 + return au_sbi(sb)->si_mntflags;
30931 +static inline unsigned int au_sigen(struct super_block *sb)
30933 + SiMustAnyLock(sb);
30934 + return au_sbi(sb)->si_generation;
30937 +static inline struct au_branch *au_sbr(struct super_block *sb,
30938 + aufs_bindex_t bindex)
30940 + SiMustAnyLock(sb);
30941 + return au_sbi(sb)->si_branch[0 + bindex];
30944 +static inline loff_t au_xi_maxent(struct super_block *sb)
30946 + SiMustAnyLock(sb);
30947 + return au_sbi(sb)->si_ximaxent;
30950 +#endif /* __KERNEL__ */
30951 +#endif /* __AUFS_SUPER_H__ */
30952 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
30953 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
30954 +++ linux/fs/aufs/sysaufs.c 2021-12-03 15:38:59.939980643 +0100
30956 +// SPDX-License-Identifier: GPL-2.0
30958 + * Copyright (C) 2005-2021 Junjiro R. Okajima
30960 + * This program, aufs is free software; you can redistribute it and/or modify
30961 + * it under the terms of the GNU General Public License as published by
30962 + * the Free Software Foundation; either version 2 of the License, or
30963 + * (at your option) any later version.
30965 + * This program is distributed in the hope that it will be useful,
30966 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30967 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30968 + * GNU General Public License for more details.
30970 + * You should have received a copy of the GNU General Public License
30971 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30975 + * sysfs interface and lifetime management
30976 + * they are necessary regardless sysfs is disabled.
30979 +#include <linux/random.h>
30982 +unsigned long sysaufs_si_mask;
30983 +struct kset *sysaufs_kset;
30985 +#define AuSiAttr(_name) { \
30986 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
30987 + .show = sysaufs_si_##_name, \
30990 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
30991 +struct attribute *sysaufs_si_attrs[] = {
30992 + &sysaufs_si_attr_xi_path.attr,
30996 +static const struct sysfs_ops au_sbi_ops = {
30997 + .show = sysaufs_si_show
31000 +static struct kobj_type au_sbi_ktype = {
31001 + .release = au_si_free,
31002 + .sysfs_ops = &au_sbi_ops,
31003 + .default_attrs = sysaufs_si_attrs
31006 +/* ---------------------------------------------------------------------- */
31008 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31012 + sbinfo->si_kobj.kset = sysaufs_kset;
31013 + /* cf. sysaufs_name() */
31014 + err = kobject_init_and_add
31015 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31016 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31021 +void sysaufs_fin(void)
31023 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31024 + kset_unregister(sysaufs_kset);
31027 +int __init sysaufs_init(void)
31032 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31033 + } while (!sysaufs_si_mask);
31036 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31037 + if (unlikely(!sysaufs_kset))
31039 + err = PTR_ERR(sysaufs_kset);
31040 + if (IS_ERR(sysaufs_kset))
31042 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31043 + if (unlikely(err))
31044 + kset_unregister(sysaufs_kset);
31049 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31050 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31051 +++ linux/fs/aufs/sysaufs.h 2021-12-03 15:38:59.939980643 +0100
31053 +/* SPDX-License-Identifier: GPL-2.0 */
31055 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31057 + * This program, aufs is free software; you can redistribute it and/or modify
31058 + * it under the terms of the GNU General Public License as published by
31059 + * the Free Software Foundation; either version 2 of the License, or
31060 + * (at your option) any later version.
31062 + * This program is distributed in the hope that it will be useful,
31063 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31064 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31065 + * GNU General Public License for more details.
31067 + * You should have received a copy of the GNU General Public License
31068 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31072 + * sysfs interface and mount lifetime management
31075 +#ifndef __SYSAUFS_H__
31076 +#define __SYSAUFS_H__
31080 +#include <linux/sysfs.h>
31081 +#include "module.h"
31083 +struct super_block;
31086 +struct sysaufs_si_attr {
31087 + struct attribute attr;
31088 + int (*show)(struct seq_file *seq, struct super_block *sb);
31091 +/* ---------------------------------------------------------------------- */
31094 +extern unsigned long sysaufs_si_mask;
31095 +extern struct kset *sysaufs_kset;
31096 +extern struct attribute *sysaufs_si_attrs[];
31097 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31098 +int __init sysaufs_init(void);
31099 +void sysaufs_fin(void);
31101 +/* ---------------------------------------------------------------------- */
31103 +/* some people doesn't like to show a pointer in kernel */
31104 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31106 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31109 +#define SysaufsSiNamePrefix "si_"
31110 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31111 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31113 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31114 + sysaufs_si_id(sbinfo));
31118 +#ifdef CONFIG_SYSFS
31120 +extern struct attribute_group *sysaufs_attr_group;
31122 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31123 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31125 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31126 +#ifdef CONFIG_COMPAT
31127 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31130 +void sysaufs_br_init(struct au_branch *br);
31131 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31132 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31134 +#define sysaufs_brs_init() do {} while (0)
31137 +#define sysaufs_attr_group NULL
31139 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31140 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31141 + struct attribute *attr, char *buf)
31142 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31143 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31144 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31146 +static inline void sysaufs_brs_init(void)
31151 +#endif /* CONFIG_SYSFS */
31153 +#endif /* __KERNEL__ */
31154 +#endif /* __SYSAUFS_H__ */
31155 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31156 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31157 +++ linux/fs/aufs/sysfs.c 2021-12-03 15:38:59.939980643 +0100
31159 +// SPDX-License-Identifier: GPL-2.0
31161 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31163 + * This program, aufs is free software; you can redistribute it and/or modify
31164 + * it under the terms of the GNU General Public License as published by
31165 + * the Free Software Foundation; either version 2 of the License, or
31166 + * (at your option) any later version.
31168 + * This program is distributed in the hope that it will be useful,
31169 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31170 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31171 + * GNU General Public License for more details.
31173 + * You should have received a copy of the GNU General Public License
31174 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31178 + * sysfs interface
31181 +#include <linux/compat.h>
31182 +#include <linux/seq_file.h>
31185 +#ifdef CONFIG_AUFS_FS_MODULE
31186 +/* this entry violates the "one line per file" policy of sysfs */
31187 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31191 + static char *conf =
31192 +/* this file is generated at compiling */
31193 +#include "conf.str"
31196 + err = snprintf(buf, PAGE_SIZE, conf);
31197 + if (unlikely(err >= PAGE_SIZE))
31202 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31205 +static struct attribute *au_attr[] = {
31206 +#ifdef CONFIG_AUFS_FS_MODULE
31207 + &au_config_attr.attr,
31209 + NULL, /* need to NULL terminate the list of attributes */
31212 +static struct attribute_group sysaufs_attr_group_body = {
31216 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31218 +/* ---------------------------------------------------------------------- */
31220 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31224 + SiMustAnyLock(sb);
31227 + if (au_opt_test(au_mntflags(sb), XINO)) {
31228 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31229 + seq_putc(seq, '\n');
31235 + * the lifetime of branch is independent from the entry under sysfs.
31236 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31239 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31240 + aufs_bindex_t bindex, int idx)
31243 + struct path path;
31244 + struct dentry *root;
31245 + struct au_branch *br;
31246 + au_br_perm_str_t perm;
31248 + AuDbg("b%d\n", bindex);
31251 + root = sb->s_root;
31252 + di_read_lock_parent(root, !AuLock_IR);
31253 + br = au_sbr(sb, bindex);
31256 + case AuBrSysfs_BR:
31257 + path.mnt = au_br_mnt(br);
31258 + path.dentry = au_h_dptr(root, bindex);
31259 + err = au_seq_path(seq, &path);
31261 + au_optstr_br_perm(&perm, br->br_perm);
31262 + seq_printf(seq, "=%s\n", perm.a);
31265 + case AuBrSysfs_BRID:
31266 + seq_printf(seq, "%d\n", br->br_id);
31269 + di_read_unlock(root, !AuLock_IR);
31270 + if (unlikely(err || seq_has_overflowed(seq)))
31276 +/* ---------------------------------------------------------------------- */
31278 +static struct seq_file *au_seq(char *p, ssize_t len)
31280 + struct seq_file *seq;
31282 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31284 + /* mutex_init(&seq.lock); */
31287 + return seq; /* success */
31290 + seq = ERR_PTR(-ENOMEM);
31294 +#define SysaufsBr_PREFIX "br"
31295 +#define SysaufsBrid_PREFIX "brid"
31297 +/* todo: file size may exceed PAGE_SIZE */
31298 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31304 + aufs_bindex_t bbot;
31305 + struct au_sbinfo *sbinfo;
31306 + struct super_block *sb;
31307 + struct seq_file *seq;
31309 + struct attribute **cattr;
31311 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31312 + sb = sbinfo->si_sb;
31315 + * prevent a race condition between sysfs and aufs.
31316 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31317 + * prohibits maintaining the sysfs entries.
31318 + * hew we acquire read lock after sysfs_get_active_two().
31319 + * on the other hand, the remount process may maintain the sysfs/aufs
31320 + * entries after acquiring write lock.
31321 + * it can cause a deadlock.
31322 + * simply we gave up processing read here.
31325 + if (unlikely(!si_noflush_read_trylock(sb)))
31328 + seq = au_seq(buf, PAGE_SIZE);
31329 + err = PTR_ERR(seq);
31333 + name = (void *)attr->name;
31334 + cattr = sysaufs_si_attrs;
31336 + if (!strcmp(name, (*cattr)->name)) {
31337 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31344 + if (!strncmp(name, SysaufsBrid_PREFIX,
31345 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31346 + idx = AuBrSysfs_BRID;
31347 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31348 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31349 + sizeof(SysaufsBr_PREFIX) - 1)) {
31350 + idx = AuBrSysfs_BR;
31351 + name += sizeof(SysaufsBr_PREFIX) - 1;
31355 + err = kstrtol(name, 10, &l);
31357 + bbot = au_sbbot(sb);
31359 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31366 + err = seq->count;
31367 + /* sysfs limit */
31368 + if (unlikely(err == PAGE_SIZE))
31371 + au_kfree_rcu(seq);
31373 + si_read_unlock(sb);
31378 +/* ---------------------------------------------------------------------- */
31380 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31384 + aufs_bindex_t bindex, bbot;
31387 + struct seq_file *seq;
31388 + struct au_branch *br;
31390 + si_read_lock(sb, AuLock_FLUSH);
31391 + bbot = au_sbbot(sb);
31397 + buf = (void *)__get_free_page(GFP_NOFS);
31398 + if (unlikely(!buf))
31401 + seq = au_seq(buf, PAGE_SIZE);
31402 + err = PTR_ERR(seq);
31406 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31407 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31408 + /* VERIFY_WRITE */
31409 + err = !access_ok(arg, sizeof(*arg));
31410 + if (unlikely(err))
31413 + br = au_sbr(sb, bindex);
31414 + brid = br->br_id;
31415 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31416 + err = __put_user(brid, &arg->id);
31417 + if (unlikely(err))
31420 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31421 + err = __put_user(br->br_perm, &arg->perm);
31422 + if (unlikely(err))
31425 + err = au_seq_path(seq, &br->br_path);
31426 + if (unlikely(err))
31428 + seq_putc(seq, '\0');
31429 + if (!seq_has_overflowed(seq)) {
31430 + err = copy_to_user(arg->path, seq->buf, seq->count);
31432 + if (unlikely(err))
31439 + if (unlikely(err))
31443 + au_kfree_rcu(seq);
31445 + free_page((unsigned long)buf);
31447 + si_read_unlock(sb);
31451 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31453 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31456 +#ifdef CONFIG_COMPAT
31457 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31459 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31463 +/* ---------------------------------------------------------------------- */
31465 +void sysaufs_br_init(struct au_branch *br)
31468 + struct au_brsysfs *br_sysfs;
31469 + struct attribute *attr;
31471 + br_sysfs = br->br_sysfs;
31472 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31473 + attr = &br_sysfs->attr;
31474 + sysfs_attr_init(attr);
31475 + attr->name = br_sysfs->name;
31476 + attr->mode = 0444;
31481 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31483 + struct au_branch *br;
31484 + struct kobject *kobj;
31485 + struct au_brsysfs *br_sysfs;
31487 + aufs_bindex_t bbot;
31489 + if (!sysaufs_brs)
31492 + kobj = &au_sbi(sb)->si_kobj;
31493 + bbot = au_sbbot(sb);
31494 + for (; bindex <= bbot; bindex++) {
31495 + br = au_sbr(sb, bindex);
31496 + br_sysfs = br->br_sysfs;
31497 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31498 + sysfs_remove_file(kobj, &br_sysfs->attr);
31504 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31507 + aufs_bindex_t bbot;
31508 + struct kobject *kobj;
31509 + struct au_branch *br;
31510 + struct au_brsysfs *br_sysfs;
31512 + if (!sysaufs_brs)
31515 + kobj = &au_sbi(sb)->si_kobj;
31516 + bbot = au_sbbot(sb);
31517 + for (; bindex <= bbot; bindex++) {
31518 + br = au_sbr(sb, bindex);
31519 + br_sysfs = br->br_sysfs;
31520 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31521 + SysaufsBr_PREFIX "%d", bindex);
31522 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31523 + SysaufsBrid_PREFIX "%d", bindex);
31524 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31525 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31526 + if (unlikely(err))
31527 + pr_warn("failed %s under sysfs(%d)\n",
31528 + br_sysfs->name, err);
31533 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31534 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31535 +++ linux/fs/aufs/sysrq.c 2021-12-03 15:38:59.939980643 +0100
31537 +// SPDX-License-Identifier: GPL-2.0
31539 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31541 + * This program, aufs is free software; you can redistribute it and/or modify
31542 + * it under the terms of the GNU General Public License as published by
31543 + * the Free Software Foundation; either version 2 of the License, or
31544 + * (at your option) any later version.
31546 + * This program is distributed in the hope that it will be useful,
31547 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31548 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31549 + * GNU General Public License for more details.
31551 + * You should have received a copy of the GNU General Public License
31552 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31556 + * magic sysrq handler
31559 +/* #include <linux/sysrq.h> */
31560 +#include <linux/writeback.h>
31563 +/* ---------------------------------------------------------------------- */
31565 +static void sysrq_sb(struct super_block *sb)
31568 + struct au_sbinfo *sbinfo;
31569 + struct file *file;
31570 + struct hlist_bl_head *files;
31571 + struct hlist_bl_node *pos;
31572 + struct au_finfo *finfo;
31575 + plevel = au_plevel;
31576 + au_plevel = KERN_WARNING;
31578 + /* since we define pr_fmt, call printk directly */
31579 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31581 + sbinfo = au_sbi(sb);
31582 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31583 + pr("superblock\n");
31586 +#if 0 /* reserved */
31588 + int err, i, j, ndentry;
31589 + struct au_dcsub_pages dpages;
31590 + struct au_dpage *dpage;
31592 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31593 + if (unlikely(err))
31595 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31597 + for (i = 0; i < dpages.ndpage; i++) {
31598 + dpage = dpages.dpages + i;
31599 + ndentry = dpage->ndentry;
31600 + for (j = 0; j < ndentry; j++)
31601 + au_dpri_dentry(dpage->dentries[j]);
31603 + au_dpages_free(&dpages);
31607 + pr("isolated inode\n");
31608 + spin_lock(&sb->s_inode_list_lock);
31609 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31610 + spin_lock(&i->i_lock);
31611 + if (hlist_empty(&i->i_dentry))
31612 + au_dpri_inode(i);
31613 + spin_unlock(&i->i_lock);
31615 + spin_unlock(&sb->s_inode_list_lock);
31618 + files = &au_sbi(sb)->si_files;
31619 + hlist_bl_lock(files);
31620 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31623 + file = finfo->fi_file;
31624 + mode = file_inode(file)->i_mode;
31625 + if (!special_file(mode))
31626 + au_dpri_file(file);
31628 + hlist_bl_unlock(files);
31632 + au_plevel = plevel;
31635 +/* ---------------------------------------------------------------------- */
31637 +/* module parameter */
31638 +static char *aufs_sysrq_key = "a";
31639 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
31640 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
31642 +static void au_sysrq(int key __maybe_unused)
31644 + struct au_sbinfo *sbinfo;
31645 + struct hlist_bl_node *pos;
31648 + au_sbilist_lock();
31649 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
31650 + sysrq_sb(sbinfo->si_sb);
31651 + au_sbilist_unlock();
31655 +static struct sysrq_key_op au_sysrq_op = {
31656 + .handler = au_sysrq,
31657 + .help_msg = "Aufs",
31658 + .action_msg = "Aufs",
31659 + .enable_mask = SYSRQ_ENABLE_DUMP
31662 +/* ---------------------------------------------------------------------- */
31664 +int __init au_sysrq_init(void)
31670 + key = *aufs_sysrq_key;
31671 + if ('a' <= key && key <= 'z')
31672 + err = register_sysrq_key(key, &au_sysrq_op);
31673 + if (unlikely(err))
31674 + pr_err("err %d, sysrq=%c\n", err, key);
31678 +void au_sysrq_fin(void)
31682 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
31683 + if (unlikely(err))
31684 + pr_err("err %d (ignored)\n", err);
31686 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
31687 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
31688 +++ linux/fs/aufs/vdir.c 2021-12-03 15:38:59.939980643 +0100
31690 +// SPDX-License-Identifier: GPL-2.0
31692 + * Copyright (C) 2005-2021 Junjiro R. Okajima
31694 + * This program, aufs is free software; you can redistribute it and/or modify
31695 + * it under the terms of the GNU General Public License as published by
31696 + * the Free Software Foundation; either version 2 of the License, or
31697 + * (at your option) any later version.
31699 + * This program is distributed in the hope that it will be useful,
31700 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31701 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31702 + * GNU General Public License for more details.
31704 + * You should have received a copy of the GNU General Public License
31705 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31709 + * virtual or vertical directory
31712 +#include <linux/iversion.h>
31715 +static unsigned int calc_size(int nlen)
31717 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
31720 +static int set_deblk_end(union au_vdir_deblk_p *p,
31721 + union au_vdir_deblk_p *deblk_end)
31723 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
31724 + p->de->de_str.len = 0;
31728 + return -1; /* error */
31731 +/* returns true or false */
31732 +static int is_deblk_end(union au_vdir_deblk_p *p,
31733 + union au_vdir_deblk_p *deblk_end)
31735 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
31736 + return !p->de->de_str.len;
31740 +static unsigned char *last_deblk(struct au_vdir *vdir)
31742 + return vdir->vd_deblk[vdir->vd_nblk - 1];
31745 +/* ---------------------------------------------------------------------- */
31747 +/* estimate the appropriate size for name hash table */
31748 +unsigned int au_rdhash_est(loff_t sz)
31756 + if (sz < AUFS_RDHASH_DEF)
31757 + n = AUFS_RDHASH_DEF;
31758 + /* pr_info("n %u\n", n); */
31763 + * the allocated memory has to be freed by
31764 + * au_nhash_wh_free() or au_nhash_de_free().
31766 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
31768 + struct hlist_head *head;
31772 + sz = sizeof(*nhash->nh_head) * num_hash;
31773 + head = kmalloc(sz, gfp);
31775 + nhash->nh_num = num_hash;
31776 + nhash->nh_head = head;
31777 + for (u = 0; u < num_hash; u++)
31778 + INIT_HLIST_HEAD(head++);
31779 + return 0; /* success */
31785 +static void nhash_count(struct hlist_head *head)
31787 +#if 0 /* debugging */
31789 + struct hlist_node *pos;
31792 + hlist_for_each(pos, head)
31794 + pr_info("%lu\n", n);
31798 +static void au_nhash_wh_do_free(struct hlist_head *head)
31800 + struct au_vdir_wh *pos;
31801 + struct hlist_node *node;
31803 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
31804 + au_kfree_rcu(pos);
31807 +static void au_nhash_de_do_free(struct hlist_head *head)
31809 + struct au_vdir_dehstr *pos;
31810 + struct hlist_node *node;
31812 + hlist_for_each_entry_safe(pos, node, head, hash)
31813 + au_cache_free_vdir_dehstr(pos);
31816 +static void au_nhash_do_free(struct au_nhash *nhash,
31817 + void (*free)(struct hlist_head *head))
31820 + struct hlist_head *head;
31822 + n = nhash->nh_num;
31826 + head = nhash->nh_head;
31827 + while (n-- > 0) {
31828 + nhash_count(head);
31831 + au_kfree_try_rcu(nhash->nh_head);
31834 +void au_nhash_wh_free(struct au_nhash *whlist)
31836 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
31839 +static void au_nhash_de_free(struct au_nhash *delist)
31841 + au_nhash_do_free(delist, au_nhash_de_do_free);
31844 +/* ---------------------------------------------------------------------- */
31846 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
31850 + unsigned int u, n;
31851 + struct hlist_head *head;
31852 + struct au_vdir_wh *pos;
31855 + n = whlist->nh_num;
31856 + head = whlist->nh_head;
31857 + for (u = 0; u < n; u++, head++)
31858 + hlist_for_each_entry(pos, head, wh_hash)
31859 + if (pos->wh_bindex == btgt && ++num > limit)
31864 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
31865 + unsigned char *name,
31866 + unsigned int len)
31869 + /* const unsigned int magic_bit = 12; */
31871 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
31878 + /* v = hash_long(v, magic_bit); */
31879 + v %= nhash->nh_num;
31880 + return nhash->nh_head + v;
31883 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
31886 + return str->len == nlen && !memcmp(str->name, name, nlen);
31889 +/* returns found or not */
31890 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
31892 + struct hlist_head *head;
31893 + struct au_vdir_wh *pos;
31894 + struct au_vdir_destr *str;
31896 + head = au_name_hash(whlist, name, nlen);
31897 + hlist_for_each_entry(pos, head, wh_hash) {
31898 + str = &pos->wh_str;
31899 + AuDbg("%.*s\n", str->len, str->name);
31900 + if (au_nhash_test_name(str, name, nlen))
31906 +/* returns found(true) or not */
31907 +static int test_known(struct au_nhash *delist, char *name, int nlen)
31909 + struct hlist_head *head;
31910 + struct au_vdir_dehstr *pos;
31911 + struct au_vdir_destr *str;
31913 + head = au_name_hash(delist, name, nlen);
31914 + hlist_for_each_entry(pos, head, hash) {
31916 + AuDbg("%.*s\n", str->len, str->name);
31917 + if (au_nhash_test_name(str, name, nlen))
31923 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
31924 + unsigned char d_type)
31926 +#ifdef CONFIG_AUFS_SHWH
31927 + wh->wh_ino = ino;
31928 + wh->wh_type = d_type;
31932 +/* ---------------------------------------------------------------------- */
31934 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
31935 + unsigned int d_type, aufs_bindex_t bindex,
31936 + unsigned char shwh)
31939 + struct au_vdir_destr *str;
31940 + struct au_vdir_wh *wh;
31942 + AuDbg("%.*s\n", nlen, name);
31943 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
31946 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
31947 + if (unlikely(!wh))
31951 + wh->wh_bindex = bindex;
31953 + au_shwh_init_wh(wh, ino, d_type);
31954 + str = &wh->wh_str;
31956 + memcpy(str->name, name, nlen);
31957 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
31964 +static int append_deblk(struct au_vdir *vdir)
31967 + unsigned long ul;
31968 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31969 + union au_vdir_deblk_p p, deblk_end;
31970 + unsigned char **o;
31973 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
31974 + GFP_NOFS, /*may_shrink*/0);
31975 + if (unlikely(!o))
31978 + vdir->vd_deblk = o;
31979 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
31981 + ul = vdir->vd_nblk++;
31982 + vdir->vd_deblk[ul] = p.deblk;
31983 + vdir->vd_last.ul = ul;
31984 + vdir->vd_last.p.deblk = p.deblk;
31985 + deblk_end.deblk = p.deblk + deblk_sz;
31986 + err = set_deblk_end(&p, &deblk_end);
31993 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
31994 + unsigned int d_type, struct au_nhash *delist)
31998 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
31999 + union au_vdir_deblk_p p, *room, deblk_end;
32000 + struct au_vdir_dehstr *dehstr;
32002 + p.deblk = last_deblk(vdir);
32003 + deblk_end.deblk = p.deblk + deblk_sz;
32004 + room = &vdir->vd_last.p;
32005 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32006 + || !is_deblk_end(room, &deblk_end));
32008 + sz = calc_size(nlen);
32009 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32010 + err = append_deblk(vdir);
32011 + if (unlikely(err))
32014 + p.deblk = last_deblk(vdir);
32015 + deblk_end.deblk = p.deblk + deblk_sz;
32017 + AuDebugOn(room->deblk != p.deblk);
32021 + dehstr = au_cache_alloc_vdir_dehstr();
32022 + if (unlikely(!dehstr))
32025 + dehstr->str = &room->de->de_str;
32026 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32027 + room->de->de_ino = ino;
32028 + room->de->de_type = d_type;
32029 + room->de->de_str.len = nlen;
32030 + memcpy(room->de->de_str.name, name, nlen);
32033 + room->deblk += sz;
32034 + if (unlikely(set_deblk_end(room, &deblk_end)))
32035 + err = append_deblk(vdir);
32042 +/* ---------------------------------------------------------------------- */
32044 +void au_vdir_free(struct au_vdir *vdir)
32046 + unsigned char **deblk;
32048 + deblk = vdir->vd_deblk;
32049 + while (vdir->vd_nblk--)
32050 + au_kfree_try_rcu(*deblk++);
32051 + au_kfree_try_rcu(vdir->vd_deblk);
32052 + au_cache_free_vdir(vdir);
32055 +static struct au_vdir *alloc_vdir(struct file *file)
32057 + struct au_vdir *vdir;
32058 + struct super_block *sb;
32061 + sb = file->f_path.dentry->d_sb;
32062 + SiMustAnyLock(sb);
32065 + vdir = au_cache_alloc_vdir();
32066 + if (unlikely(!vdir))
32069 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32070 + if (unlikely(!vdir->vd_deblk))
32073 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32074 + if (!vdir->vd_deblk_sz) {
32075 + /* estimate the appropriate size for deblk */
32076 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32077 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32079 + vdir->vd_nblk = 0;
32080 + vdir->vd_version = 0;
32081 + vdir->vd_jiffy = 0;
32082 + err = append_deblk(vdir);
32084 + return vdir; /* success */
32086 + au_kfree_try_rcu(vdir->vd_deblk);
32089 + au_cache_free_vdir(vdir);
32091 + vdir = ERR_PTR(err);
32095 +static int reinit_vdir(struct au_vdir *vdir)
32098 + union au_vdir_deblk_p p, deblk_end;
32100 + while (vdir->vd_nblk > 1) {
32101 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32102 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32105 + p.deblk = vdir->vd_deblk[0];
32106 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32107 + err = set_deblk_end(&p, &deblk_end);
32108 + /* keep vd_dblk_sz */
32109 + vdir->vd_last.ul = 0;
32110 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32111 + vdir->vd_version = 0;
32112 + vdir->vd_jiffy = 0;
32117 +/* ---------------------------------------------------------------------- */
32119 +#define AuFillVdir_CALLED 1
32120 +#define AuFillVdir_WHABLE (1 << 1)
32121 +#define AuFillVdir_SHWH (1 << 2)
32122 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32123 +#define au_fset_fillvdir(flags, name) \
32124 + do { (flags) |= AuFillVdir_##name; } while (0)
32125 +#define au_fclr_fillvdir(flags, name) \
32126 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32128 +#ifndef CONFIG_AUFS_SHWH
32129 +#undef AuFillVdir_SHWH
32130 +#define AuFillVdir_SHWH 0
32133 +struct fillvdir_arg {
32134 + struct dir_context ctx;
32135 + struct file *file;
32136 + struct au_vdir *vdir;
32137 + struct au_nhash delist;
32138 + struct au_nhash whlist;
32139 + aufs_bindex_t bindex;
32140 + unsigned int flags;
32144 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32145 + loff_t offset __maybe_unused, u64 h_ino,
32146 + unsigned int d_type)
32148 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32149 + char *name = (void *)__name;
32150 + struct super_block *sb;
32152 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32155 + sb = arg->file->f_path.dentry->d_sb;
32156 + au_fset_fillvdir(arg->flags, CALLED);
32158 + if (nlen <= AUFS_WH_PFX_LEN
32159 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32160 + if (test_known(&arg->delist, name, nlen)
32161 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32162 + goto out; /* already exists or whiteouted */
32164 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32166 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32167 + d_type = DT_UNKNOWN;
32168 + arg->err = append_de(arg->vdir, name, nlen, ino,
32169 + d_type, &arg->delist);
32171 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32172 + name += AUFS_WH_PFX_LEN;
32173 + nlen -= AUFS_WH_PFX_LEN;
32174 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32175 + goto out; /* already whiteouted */
32177 + ino = 0; /* just to suppress a warning */
32179 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32182 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32183 + d_type = DT_UNKNOWN;
32184 + arg->err = au_nhash_append_wh
32185 + (&arg->whlist, name, nlen, ino, d_type,
32186 + arg->bindex, shwh);
32192 + arg->vdir->vd_jiffy = jiffies;
32194 + AuTraceErr(arg->err);
32198 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32199 + struct au_nhash *whlist, struct au_nhash *delist)
32201 +#ifdef CONFIG_AUFS_SHWH
32203 + unsigned int nh, u;
32204 + struct hlist_head *head;
32205 + struct au_vdir_wh *pos;
32206 + struct hlist_node *n;
32208 + struct au_vdir_destr *destr;
32210 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32213 + o = p = (void *)__get_free_page(GFP_NOFS);
32214 + if (unlikely(!p))
32218 + nh = whlist->nh_num;
32219 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32220 + p += AUFS_WH_PFX_LEN;
32221 + for (u = 0; u < nh; u++) {
32222 + head = whlist->nh_head + u;
32223 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32224 + destr = &pos->wh_str;
32225 + memcpy(p, destr->name, destr->len);
32226 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32227 + pos->wh_ino, pos->wh_type, delist);
32228 + if (unlikely(err))
32233 + free_page((unsigned long)o);
32243 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32246 + unsigned int rdhash;
32248 + aufs_bindex_t bbot, bindex, btop;
32249 + unsigned char shwh;
32250 + struct file *hf, *file;
32251 + struct super_block *sb;
32253 + file = arg->file;
32254 + sb = file->f_path.dentry->d_sb;
32255 + SiMustAnyLock(sb);
32257 + rdhash = au_sbi(sb)->si_rdhash;
32259 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32260 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32261 + if (unlikely(err))
32263 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32264 + if (unlikely(err))
32270 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32272 + au_fset_fillvdir(arg->flags, SHWH);
32274 + btop = au_fbtop(file);
32275 + bbot = au_fbbot_dir(file);
32276 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32277 + hf = au_hf_dir(file, bindex);
32281 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32283 + if (unlikely(offset))
32286 + arg->bindex = bindex;
32287 + au_fclr_fillvdir(arg->flags, WHABLE);
32289 + || (bindex != bbot
32290 + && au_br_whable(au_sbr_perm(sb, bindex))))
32291 + au_fset_fillvdir(arg->flags, WHABLE);
32294 + au_fclr_fillvdir(arg->flags, CALLED);
32296 + err = vfsub_iterate_dir(hf, &arg->ctx);
32299 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32302 + * dir_relax() may be good for concurrency, but aufs should not
32303 + * use it since it will cause a lockdep problem.
32307 + if (!err && shwh)
32308 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32310 + au_nhash_wh_free(&arg->whlist);
32313 + au_nhash_de_free(&arg->delist);
32318 +static int read_vdir(struct file *file, int may_read)
32321 + unsigned long expire;
32322 + unsigned char do_read;
32323 + struct fillvdir_arg arg = {
32325 + .actor = fillvdir
32328 + struct inode *inode;
32329 + struct au_vdir *vdir, *allocated;
32332 + inode = file_inode(file);
32333 + IMustLock(inode);
32334 + IiMustWriteLock(inode);
32335 + SiMustAnyLock(inode->i_sb);
32337 + allocated = NULL;
32339 + expire = au_sbi(inode->i_sb)->si_rdcache;
32340 + vdir = au_ivdir(inode);
32343 + vdir = alloc_vdir(file);
32344 + err = PTR_ERR(vdir);
32345 + if (IS_ERR(vdir))
32348 + allocated = vdir;
32349 + } else if (may_read
32350 + && (!inode_eq_iversion(inode, vdir->vd_version)
32351 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32353 + err = reinit_vdir(vdir);
32354 + if (unlikely(err))
32359 + return 0; /* success */
32363 + err = au_do_read_vdir(&arg);
32365 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32366 + vdir->vd_version = inode_query_iversion(inode);
32367 + vdir->vd_last.ul = 0;
32368 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32370 + au_set_ivdir(inode, allocated);
32371 + } else if (allocated)
32372 + au_vdir_free(allocated);
32378 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32381 + unsigned long ul, n;
32382 + const unsigned int deblk_sz = src->vd_deblk_sz;
32384 + AuDebugOn(tgt->vd_nblk != 1);
32387 + if (tgt->vd_nblk < src->vd_nblk) {
32388 + unsigned char **p;
32390 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32391 + GFP_NOFS, /*may_shrink*/0);
32392 + if (unlikely(!p))
32394 + tgt->vd_deblk = p;
32397 + if (tgt->vd_deblk_sz != deblk_sz) {
32398 + unsigned char *p;
32400 + tgt->vd_deblk_sz = deblk_sz;
32401 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32402 + /*may_shrink*/1);
32403 + if (unlikely(!p))
32405 + tgt->vd_deblk[0] = p;
32407 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32408 + tgt->vd_version = src->vd_version;
32409 + tgt->vd_jiffy = src->vd_jiffy;
32411 + n = src->vd_nblk;
32412 + for (ul = 1; ul < n; ul++) {
32413 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32415 + if (unlikely(!tgt->vd_deblk[ul]))
32419 + tgt->vd_nblk = n;
32420 + tgt->vd_last.ul = tgt->vd_last.ul;
32421 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32422 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32423 + - src->vd_deblk[src->vd_last.ul];
32425 + return 0; /* success */
32428 + rerr = reinit_vdir(tgt);
32433 +int au_vdir_init(struct file *file)
32436 + struct inode *inode;
32437 + struct au_vdir *vdir_cache, *allocated;
32439 + /* test file->f_pos here instead of ctx->pos */
32440 + err = read_vdir(file, !file->f_pos);
32441 + if (unlikely(err))
32444 + allocated = NULL;
32445 + vdir_cache = au_fvdir_cache(file);
32446 + if (!vdir_cache) {
32447 + vdir_cache = alloc_vdir(file);
32448 + err = PTR_ERR(vdir_cache);
32449 + if (IS_ERR(vdir_cache))
32451 + allocated = vdir_cache;
32452 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32453 + /* test file->f_pos here instead of ctx->pos */
32454 + err = reinit_vdir(vdir_cache);
32455 + if (unlikely(err))
32458 + return 0; /* success */
32460 + inode = file_inode(file);
32461 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32463 + file->f_version = inode_query_iversion(inode);
32465 + au_set_fvdir_cache(file, allocated);
32466 + } else if (allocated)
32467 + au_vdir_free(allocated);
32473 +static loff_t calc_offset(struct au_vdir *vdir)
32476 + union au_vdir_deblk_p p;
32478 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32479 + offset = vdir->vd_last.p.deblk - p.deblk;
32480 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32484 +/* returns true or false */
32485 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32488 + unsigned int deblk_sz;
32489 + unsigned long ul, n;
32491 + union au_vdir_deblk_p p, deblk_end;
32492 + struct au_vdir *vdir_cache;
32495 + vdir_cache = au_fvdir_cache(file);
32496 + offset = calc_offset(vdir_cache);
32497 + AuDbg("offset %lld\n", offset);
32498 + if (ctx->pos == offset)
32501 + vdir_cache->vd_last.ul = 0;
32502 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32507 + deblk_sz = vdir_cache->vd_deblk_sz;
32508 + ul = div64_u64(ctx->pos, deblk_sz);
32509 + AuDbg("ul %lu\n", ul);
32510 + if (ul >= vdir_cache->vd_nblk)
32513 + n = vdir_cache->vd_nblk;
32514 + for (; ul < n; ul++) {
32515 + p.deblk = vdir_cache->vd_deblk[ul];
32516 + deblk_end.deblk = p.deblk + deblk_sz;
32518 + offset *= deblk_sz;
32519 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32522 + l = calc_size(p.de->de_str.len);
32526 + if (!is_deblk_end(&p, &deblk_end)) {
32528 + vdir_cache->vd_last.ul = ul;
32529 + vdir_cache->vd_last.p = p;
32537 + AuDbg("valid %d\n", !valid);
32541 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32543 + unsigned int l, deblk_sz;
32544 + union au_vdir_deblk_p deblk_end;
32545 + struct au_vdir *vdir_cache;
32546 + struct au_vdir_de *de;
32548 + if (!seek_vdir(file, ctx))
32551 + vdir_cache = au_fvdir_cache(file);
32552 + deblk_sz = vdir_cache->vd_deblk_sz;
32554 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32555 + deblk_end.deblk += deblk_sz;
32556 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32557 + de = vdir_cache->vd_last.p.de;
32558 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32559 + de->de_str.len, de->de_str.name, ctx->pos,
32560 + (unsigned long)de->de_ino, de->de_type);
32561 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32562 + de->de_str.len, de->de_ino,
32564 + /* todo: ignore the error caused by udba? */
32565 + /* return err; */
32569 + l = calc_size(de->de_str.len);
32570 + vdir_cache->vd_last.p.deblk += l;
32573 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32574 + vdir_cache->vd_last.ul++;
32575 + vdir_cache->vd_last.p.deblk
32576 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32577 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32586 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32587 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32588 +++ linux/fs/aufs/vfsub.c 2021-12-03 15:38:59.939980643 +0100
32590 +// SPDX-License-Identifier: GPL-2.0
32592 + * Copyright (C) 2005-2021 Junjiro R. Okajima
32594 + * This program, aufs is free software; you can redistribute it and/or modify
32595 + * it under the terms of the GNU General Public License as published by
32596 + * the Free Software Foundation; either version 2 of the License, or
32597 + * (at your option) any later version.
32599 + * This program is distributed in the hope that it will be useful,
32600 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32601 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32602 + * GNU General Public License for more details.
32604 + * You should have received a copy of the GNU General Public License
32605 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32609 + * sub-routines for VFS
32612 +#include <linux/mnt_namespace.h>
32613 +#include <linux/namei.h>
32614 +#include <linux/nsproxy.h>
32615 +#include <linux/security.h>
32616 +#include <linux/splice.h>
32619 +#ifdef CONFIG_AUFS_BR_FUSE
32620 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32622 + if (!au_test_fuse(h_sb) || !au_userns)
32625 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32629 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
32634 + down_read(&h_sb->s_umount);
32635 + err = __sync_filesystem(h_sb, wait);
32636 + up_read(&h_sb->s_umount);
32642 +/* ---------------------------------------------------------------------- */
32644 +int vfsub_update_h_iattr(struct path *h_path, int *did)
32648 + struct super_block *h_sb;
32651 + * Always needs h_path->mnt for LSM or FUSE branch.
32653 + AuDebugOn(!h_path->mnt);
32655 + /* for remote fs, leave work for its getattr or d_revalidate */
32656 + /* for bad i_attr fs, handle them in aufs_getattr() */
32657 + /* still some fs may acquire i_mutex. we need to skip them */
32661 + h_sb = h_path->dentry->d_sb;
32662 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
32664 + err = vfsub_getattr(h_path, &st);
32669 +/* ---------------------------------------------------------------------- */
32671 +struct file *vfsub_dentry_open(struct path *path, int flags)
32673 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
32677 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
32679 + struct file *file;
32682 + file = filp_open(path,
32683 + oflags /* | __FMODE_NONOTIFY */,
32686 + if (IS_ERR(file))
32688 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
32695 + * Ideally this function should call VFS:do_last() in order to keep all its
32696 + * checkings. But it is very hard for aufs to regenerate several VFS internal
32697 + * structure such as nameidata. This is a second (or third) best approach.
32698 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
32700 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
32701 + struct vfsub_aopen_args *args)
32704 + struct au_branch *br = args->br;
32705 + struct file *file = args->file;
32706 + /* copied from linux/fs/namei.c:atomic_open() */
32707 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
32710 + AuDebugOn(!dir->i_op->atomic_open);
32712 + err = au_br_test_oflag(args->open_flag, br);
32713 + if (unlikely(err))
32716 + au_lcnt_inc(&br->br_nfiles);
32717 + file->f_path.dentry = DENTRY_NOT_SET;
32718 + file->f_path.mnt = au_br_mnt(br);
32719 + AuDbg("%ps\n", dir->i_op->atomic_open);
32720 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
32721 + args->create_mode);
32722 + if (unlikely(err < 0)) {
32723 + au_lcnt_dec(&br->br_nfiles);
32727 + /* temporary workaround for nfsv4 branch */
32728 + if (au_test_nfs(dir->i_sb))
32729 + nfs_mark_for_revalidate(dir);
32731 + if (file->f_mode & FMODE_CREATED)
32732 + fsnotify_create(dir, dentry);
32733 + if (!(file->f_mode & FMODE_OPENED)) {
32734 + au_lcnt_dec(&br->br_nfiles);
32738 + /* todo: call VFS:may_open() here */
32739 + /* todo: ima_file_check() too? */
32740 + if (!err && (args->open_flag & __FMODE_EXEC))
32741 + err = deny_write_access(file);
32743 + fsnotify_open(file);
32745 + au_lcnt_dec(&br->br_nfiles);
32746 + /* note that the file is created and still opened */
32752 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
32756 + err = kern_path(name, flags, path);
32757 + if (!err && d_is_positive(path->dentry))
32758 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
32762 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
32763 + struct path *ppath, int len)
32765 + struct path path;
32767 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
32768 + if (IS_ERR(path.dentry))
32770 + if (d_is_positive(path.dentry)) {
32771 + path.mnt = ppath->mnt;
32772 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32776 + AuTraceErrPtr(path.dentry);
32777 + return path.dentry;
32780 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
32783 + struct path path;
32785 + /* VFS checks it too, but by WARN_ON_ONCE() */
32786 + IMustLock(d_inode(ppath->dentry));
32788 + path.dentry = lookup_one_len(name, ppath->dentry, len);
32789 + if (IS_ERR(path.dentry))
32791 + if (d_is_positive(path.dentry)) {
32792 + path.mnt = ppath->mnt;
32793 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
32797 + AuTraceErrPtr(path.dentry);
32798 + return path.dentry;
32801 +void vfsub_call_lkup_one(void *args)
32803 + struct vfsub_lkup_one_args *a = args;
32804 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
32807 +/* ---------------------------------------------------------------------- */
32809 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
32810 + struct dentry *d2, struct au_hinode *hdir2)
32812 + struct dentry *d;
32815 + d = lock_rename(d1, d2);
32817 + au_hn_suspend(hdir1);
32818 + if (hdir1 != hdir2)
32819 + au_hn_suspend(hdir2);
32824 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
32825 + struct dentry *d2, struct au_hinode *hdir2)
32827 + au_hn_resume(hdir1);
32828 + if (hdir1 != hdir2)
32829 + au_hn_resume(hdir2);
32831 + unlock_rename(d1, d2);
32835 +/* ---------------------------------------------------------------------- */
32837 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
32840 + struct dentry *d;
32844 + d = path->dentry;
32845 + path->dentry = d->d_parent;
32846 + err = security_path_mknod(path, d, mode, 0);
32847 + path->dentry = d;
32848 + if (unlikely(err))
32852 + err = vfs_create(dir, path->dentry, mode, want_excl);
32855 + struct path tmp = *path;
32858 + vfsub_update_h_iattr(&tmp, &did);
32860 + tmp.dentry = path->dentry->d_parent;
32861 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32870 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
32873 + struct dentry *d;
32877 + d = path->dentry;
32878 + path->dentry = d->d_parent;
32879 + err = security_path_symlink(path, d, symname);
32880 + path->dentry = d;
32881 + if (unlikely(err))
32885 + err = vfs_symlink(dir, path->dentry, symname);
32888 + struct path tmp = *path;
32891 + vfsub_update_h_iattr(&tmp, &did);
32893 + tmp.dentry = path->dentry->d_parent;
32894 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32903 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
32906 + struct dentry *d;
32910 + d = path->dentry;
32911 + path->dentry = d->d_parent;
32912 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
32913 + path->dentry = d;
32914 + if (unlikely(err))
32918 + err = vfs_mknod(dir, path->dentry, mode, dev);
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 +static int au_test_nlink(struct inode *inode)
32938 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
32940 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
32941 + || inode->i_nlink < link_max)
32946 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
32947 + struct inode **delegated_inode)
32950 + struct dentry *d;
32954 + err = au_test_nlink(d_inode(src_dentry));
32955 + if (unlikely(err))
32958 + /* we don't call may_linkat() */
32959 + d = path->dentry;
32960 + path->dentry = d->d_parent;
32961 + err = security_path_link(src_dentry, path, d);
32962 + path->dentry = d;
32963 + if (unlikely(err))
32967 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
32970 + struct path tmp = *path;
32973 + /* fuse has different memory inode for the same inumber */
32974 + vfsub_update_h_iattr(&tmp, &did);
32976 + tmp.dentry = path->dentry->d_parent;
32977 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32978 + tmp.dentry = src_dentry;
32979 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
32988 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
32989 + struct inode *dir, struct path *path,
32990 + struct inode **delegated_inode, unsigned int flags)
32993 + struct path tmp = {
32996 + struct dentry *d;
32999 + IMustLock(src_dir);
33001 + d = path->dentry;
33002 + path->dentry = d->d_parent;
33003 + tmp.dentry = src_dentry->d_parent;
33004 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33005 + path->dentry = d;
33006 + if (unlikely(err))
33010 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
33011 + delegated_inode, flags);
33016 + tmp.dentry = d->d_parent;
33017 + vfsub_update_h_iattr(&tmp, &did);
33019 + tmp.dentry = src_dentry;
33020 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33021 + tmp.dentry = src_dentry->d_parent;
33022 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33031 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33034 + struct dentry *d;
33038 + d = path->dentry;
33039 + path->dentry = d->d_parent;
33040 + err = security_path_mkdir(path, d, mode);
33041 + path->dentry = d;
33042 + if (unlikely(err))
33046 + err = vfs_mkdir(dir, path->dentry, mode);
33049 + struct path tmp = *path;
33052 + vfsub_update_h_iattr(&tmp, &did);
33054 + tmp.dentry = path->dentry->d_parent;
33055 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33064 +int vfsub_rmdir(struct inode *dir, struct path *path)
33067 + struct dentry *d;
33071 + d = path->dentry;
33072 + path->dentry = d->d_parent;
33073 + err = security_path_rmdir(path, d);
33074 + path->dentry = d;
33075 + if (unlikely(err))
33079 + err = vfs_rmdir(dir, path->dentry);
33082 + struct path tmp = {
33083 + .dentry = path->dentry->d_parent,
33087 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33094 +/* ---------------------------------------------------------------------- */
33096 +/* todo: support mmap_sem? */
33097 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33103 + err = vfs_read(file, ubuf, count, ppos);
33106 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33110 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33116 + err = kernel_read(file, kbuf, count, ppos);
33120 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33124 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33130 + err = vfs_write(file, ubuf, count, ppos);
33133 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33137 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33142 + err = kernel_write(file, kbuf, count, ppos);
33145 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33149 +int vfsub_flush(struct file *file, fl_owner_t id)
33154 + if (file->f_op->flush) {
33155 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33156 + err = file->f_op->flush(file, id);
33159 + err = file->f_op->flush(file, id);
33163 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33169 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33173 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33176 + err = iterate_dir(file, ctx);
33179 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33184 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33185 + struct pipe_inode_info *pipe, size_t len,
33186 + unsigned int flags)
33191 + err = do_splice_to(in, ppos, pipe, len, flags);
33193 + file_accessed(in);
33195 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33199 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33200 + loff_t *ppos, size_t len, unsigned int flags)
33205 + err = do_splice_from(pipe, out, ppos, len, flags);
33208 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33212 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33216 + /* file can be NULL */
33218 + err = vfs_fsync(file, datasync);
33222 + AuDebugOn(!file);
33223 + path = &file->f_path;
33225 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33230 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33231 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33232 + struct file *h_file)
33235 + struct inode *h_inode;
33236 + struct super_block *h_sb;
33239 + err = vfsub_truncate(h_path, length);
33243 + h_inode = d_inode(h_path->dentry);
33244 + h_sb = h_inode->i_sb;
33246 + sb_start_write(h_sb);
33248 + err = locks_verify_truncate(h_inode, h_file, length);
33250 + err = security_path_truncate(h_path);
33253 + err = do_truncate(h_path->dentry, length, attr, h_file);
33257 + sb_end_write(h_sb);
33264 +/* ---------------------------------------------------------------------- */
33266 +struct au_vfsub_mkdir_args {
33268 + struct inode *dir;
33269 + struct path *path;
33273 +static void au_call_vfsub_mkdir(void *args)
33275 + struct au_vfsub_mkdir_args *a = args;
33276 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33279 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33281 + int err, do_sio, wkq_err;
33283 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33286 + err = vfsub_mkdir(dir, path, mode);
33289 + struct au_vfsub_mkdir_args args = {
33295 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33296 + if (unlikely(wkq_err))
33303 +struct au_vfsub_rmdir_args {
33305 + struct inode *dir;
33306 + struct path *path;
33309 +static void au_call_vfsub_rmdir(void *args)
33311 + struct au_vfsub_rmdir_args *a = args;
33312 + *a->errp = vfsub_rmdir(a->dir, a->path);
33315 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33317 + int err, do_sio, wkq_err;
33319 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
33322 + err = vfsub_rmdir(dir, path);
33325 + struct au_vfsub_rmdir_args args = {
33330 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33331 + if (unlikely(wkq_err))
33338 +/* ---------------------------------------------------------------------- */
33340 +struct notify_change_args {
33342 + struct path *path;
33343 + struct iattr *ia;
33344 + struct inode **delegated_inode;
33347 +static void call_notify_change(void *args)
33349 + struct notify_change_args *a = args;
33350 + struct inode *h_inode;
33352 + h_inode = d_inode(a->path->dentry);
33353 + IMustLock(h_inode);
33355 + *a->errp = -EPERM;
33356 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33358 + *a->errp = notify_change(a->path->dentry, a->ia,
33359 + a->delegated_inode);
33362 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33364 + AuTraceErr(*a->errp);
33367 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33368 + struct inode **delegated_inode)
33371 + struct notify_change_args args = {
33375 + .delegated_inode = delegated_inode
33378 + call_notify_change(&args);
33383 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33384 + struct inode **delegated_inode)
33386 + int err, wkq_err;
33387 + struct notify_change_args args = {
33391 + .delegated_inode = delegated_inode
33394 + wkq_err = au_wkq_wait(call_notify_change, &args);
33395 + if (unlikely(wkq_err))
33401 +/* ---------------------------------------------------------------------- */
33403 +struct unlink_args {
33405 + struct inode *dir;
33406 + struct path *path;
33407 + struct inode **delegated_inode;
33410 +static void call_unlink(void *args)
33412 + struct unlink_args *a = args;
33413 + struct dentry *d = a->path->dentry;
33414 + struct inode *h_inode;
33415 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33416 + && au_dcount(d) == 1);
33418 + IMustLock(a->dir);
33420 + a->path->dentry = d->d_parent;
33421 + *a->errp = security_path_unlink(a->path, d);
33422 + a->path->dentry = d;
33423 + if (unlikely(*a->errp))
33426 + if (!stop_sillyrename)
33429 + if (d_is_positive(d)) {
33430 + h_inode = d_inode(d);
33435 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
33438 + struct path tmp = {
33439 + .dentry = d->d_parent,
33440 + .mnt = a->path->mnt
33442 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33445 + if (!stop_sillyrename)
33450 + AuTraceErr(*a->errp);
33454 + * @dir: must be locked.
33455 + * @dentry: target dentry.
33457 +int vfsub_unlink(struct inode *dir, struct path *path,
33458 + struct inode **delegated_inode, int force)
33461 + struct unlink_args args = {
33465 + .delegated_inode = delegated_inode
33469 + call_unlink(&args);
33473 + wkq_err = au_wkq_wait(call_unlink, &args);
33474 + if (unlikely(wkq_err))
33480 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33481 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33482 +++ linux/fs/aufs/vfsub.h 2021-12-03 15:38:59.939980643 +0100
33484 +/* SPDX-License-Identifier: GPL-2.0 */
33486 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33488 + * This program, aufs is free software; you can redistribute it and/or modify
33489 + * it under the terms of the GNU General Public License as published by
33490 + * the Free Software Foundation; either version 2 of the License, or
33491 + * (at your option) any later version.
33493 + * This program is distributed in the hope that it will be useful,
33494 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33495 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33496 + * GNU General Public License for more details.
33498 + * You should have received a copy of the GNU General Public License
33499 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33503 + * sub-routines for VFS
33506 +#ifndef __AUFS_VFSUB_H__
33507 +#define __AUFS_VFSUB_H__
33511 +#include <linux/fs.h>
33512 +#include <linux/mount.h>
33513 +#include <linux/posix_acl.h>
33514 +#include <linux/xattr.h>
33515 +#include "debug.h"
33517 +/* copied from linux/fs/internal.h */
33518 +/* todo: BAD approach!! */
33519 +extern void __mnt_drop_write(struct vfsmount *);
33520 +extern struct file *alloc_empty_file(int, const struct cred *);
33522 +/* ---------------------------------------------------------------------- */
33524 +/* lock subclass for lower inode */
33525 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33526 +/* reduce? gave up. */
33528 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33529 + AuLsc_I_PARENT, /* lower inode, parent first */
33530 + AuLsc_I_PARENT2, /* copyup dirs */
33531 + AuLsc_I_PARENT3, /* copyup wh */
33537 +/* to debug easier, do not make them inlined functions */
33538 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33539 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33541 +/* ---------------------------------------------------------------------- */
33543 +static inline void vfsub_drop_nlink(struct inode *inode)
33545 + AuDebugOn(!inode->i_nlink);
33546 + drop_nlink(inode);
33549 +static inline void vfsub_dead_dir(struct inode *inode)
33551 + AuDebugOn(!S_ISDIR(inode->i_mode));
33552 + inode->i_flags |= S_DEAD;
33553 + clear_nlink(inode);
33556 +static inline int vfsub_native_ro(struct inode *inode)
33558 + return sb_rdonly(inode->i_sb)
33559 + || IS_RDONLY(inode)
33560 + /* || IS_APPEND(inode) */
33561 + || IS_IMMUTABLE(inode);
33564 +#ifdef CONFIG_AUFS_BR_FUSE
33565 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33567 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33570 +int vfsub_sync_filesystem(struct super_block *h_sb, int wait);
33572 +/* ---------------------------------------------------------------------- */
33574 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33575 +struct file *vfsub_dentry_open(struct path *path, int flags);
33576 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33578 +struct vfsub_aopen_args {
33579 + struct file *file;
33580 + unsigned int open_flag;
33581 + umode_t create_mode;
33582 + struct au_branch *br;
33584 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33585 + struct vfsub_aopen_args *args);
33586 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33588 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33589 + struct path *ppath, int len);
33590 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33593 +struct vfsub_lkup_one_args {
33594 + struct dentry **errp;
33595 + struct qstr *name;
33596 + struct path *ppath;
33599 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33600 + struct path *ppath)
33602 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33605 +void vfsub_call_lkup_one(void *args);
33607 +/* ---------------------------------------------------------------------- */
33609 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
33614 + err = mnt_want_write(mnt);
33619 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
33622 + mnt_drop_write(mnt);
33626 +#if 0 /* reserved */
33627 +static inline void vfsub_mnt_drop_write_file(struct file *file)
33630 + mnt_drop_write_file(file);
33635 +/* ---------------------------------------------------------------------- */
33638 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33639 + struct dentry *d2, struct au_hinode *hdir2);
33640 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33641 + struct dentry *d2, struct au_hinode *hdir2);
33643 +int vfsub_create(struct inode *dir, struct path *path, int mode,
33645 +int vfsub_symlink(struct inode *dir, struct path *path,
33646 + const char *symname);
33647 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
33648 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
33649 + struct path *path, struct inode **delegated_inode);
33650 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
33651 + struct inode *hdir, struct path *path,
33652 + struct inode **delegated_inode, unsigned int flags);
33653 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
33654 +int vfsub_rmdir(struct inode *dir, struct path *path);
33656 +/* ---------------------------------------------------------------------- */
33658 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33660 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33662 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33664 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
33666 +int vfsub_flush(struct file *file, fl_owner_t id);
33667 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
33669 +static inline loff_t vfsub_f_size_read(struct file *file)
33671 + return i_size_read(file_inode(file));
33674 +static inline unsigned int vfsub_file_flags(struct file *file)
33676 + unsigned int flags;
33678 + spin_lock(&file->f_lock);
33679 + flags = file->f_flags;
33680 + spin_unlock(&file->f_lock);
33685 +static inline int vfsub_file_execed(struct file *file)
33687 + /* todo: direct access f_flags */
33688 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
33691 +#if 0 /* reserved */
33692 +static inline void vfsub_file_accessed(struct file *h_file)
33694 + file_accessed(h_file);
33695 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
33699 +#if 0 /* reserved */
33700 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
33701 + struct dentry *h_dentry)
33703 + struct path h_path = {
33704 + .dentry = h_dentry,
33707 + touch_atime(&h_path);
33708 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
33712 +static inline int vfsub_update_time(struct inode *h_inode,
33713 + struct timespec64 *ts, int flags)
33715 + return inode_update_time(h_inode, ts, flags);
33716 + /* no vfsub_update_h_iattr() since we don't have struct path */
33719 +#ifdef CONFIG_FS_POSIX_ACL
33720 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
33724 + err = posix_acl_chmod(h_inode, h_mode);
33725 + if (err == -EOPNOTSUPP)
33730 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
33733 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33734 + struct pipe_inode_info *pipe, size_t len,
33735 + unsigned int flags);
33736 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33737 + loff_t *ppos, size_t len, unsigned int flags);
33739 +static inline long vfsub_truncate(struct path *path, loff_t length)
33744 + err = vfs_truncate(path, length);
33749 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33750 + struct file *h_file);
33751 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
33754 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
33757 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
33763 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
33769 +/* copy_file_range(2) is a systemcall */
33770 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
33771 + struct file *dst, loff_t dst_pos,
33772 + size_t len, unsigned int flags)
33777 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
33783 +/* ---------------------------------------------------------------------- */
33785 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
33790 + err = vfs_llseek(file, offset, origin);
33795 +/* ---------------------------------------------------------------------- */
33797 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
33798 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
33799 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33800 + struct inode **delegated_inode);
33801 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33802 + struct inode **delegated_inode);
33803 +int vfsub_unlink(struct inode *dir, struct path *path,
33804 + struct inode **delegated_inode, int force);
33806 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
33808 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
33811 +/* ---------------------------------------------------------------------- */
33813 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
33814 + const void *value, size_t size, int flags)
33819 + err = vfs_setxattr(dentry, name, value, size, flags);
33825 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
33830 + err = vfs_removexattr(dentry, name);
33836 +#endif /* __KERNEL__ */
33837 +#endif /* __AUFS_VFSUB_H__ */
33838 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
33839 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
33840 +++ linux/fs/aufs/wbr_policy.c 2021-12-03 15:38:59.939980643 +0100
33842 +// SPDX-License-Identifier: GPL-2.0
33844 + * Copyright (C) 2005-2021 Junjiro R. Okajima
33846 + * This program, aufs is free software; you can redistribute it and/or modify
33847 + * it under the terms of the GNU General Public License as published by
33848 + * the Free Software Foundation; either version 2 of the License, or
33849 + * (at your option) any later version.
33851 + * This program is distributed in the hope that it will be useful,
33852 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33853 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33854 + * GNU General Public License for more details.
33856 + * You should have received a copy of the GNU General Public License
33857 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33861 + * policies for selecting one among multiple writable branches
33864 +#include <linux/statfs.h>
33867 +/* subset of cpup_attr() */
33868 +static noinline_for_stack
33869 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
33873 + struct inode *h_isrc;
33875 + h_isrc = d_inode(h_src);
33876 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
33877 + ia.ia_mode = h_isrc->i_mode;
33878 + ia.ia_uid = h_isrc->i_uid;
33879 + ia.ia_gid = h_isrc->i_gid;
33880 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
33881 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
33882 + /* no delegation since it is just created */
33883 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33885 + /* is this nfs only? */
33886 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
33887 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
33888 + ia.ia_mode = h_isrc->i_mode;
33889 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
33895 +#define AuCpdown_PARENT_OPQ 1
33896 +#define AuCpdown_WHED (1 << 1)
33897 +#define AuCpdown_MADE_DIR (1 << 2)
33898 +#define AuCpdown_DIROPQ (1 << 3)
33899 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
33900 +#define au_fset_cpdown(flags, name) \
33901 + do { (flags) |= AuCpdown_##name; } while (0)
33902 +#define au_fclr_cpdown(flags, name) \
33903 + do { (flags) &= ~AuCpdown_##name; } while (0)
33905 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
33906 + unsigned int *flags)
33909 + struct dentry *opq_dentry;
33911 + opq_dentry = au_diropq_create(dentry, bdst);
33912 + err = PTR_ERR(opq_dentry);
33913 + if (IS_ERR(opq_dentry))
33915 + dput(opq_dentry);
33916 + au_fset_cpdown(*flags, DIROPQ);
33922 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
33923 + struct inode *dir, aufs_bindex_t bdst)
33926 + struct path h_path;
33927 + struct au_branch *br;
33929 + br = au_sbr(dentry->d_sb, bdst);
33930 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
33931 + err = PTR_ERR(h_path.dentry);
33932 + if (IS_ERR(h_path.dentry))
33936 + if (d_is_positive(h_path.dentry)) {
33937 + h_path.mnt = au_br_mnt(br);
33938 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
33941 + dput(h_path.dentry);
33947 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
33948 + struct au_pin *pin,
33949 + struct dentry *h_parent, void *arg)
33952 + aufs_bindex_t bopq, btop;
33953 + struct path h_path;
33954 + struct dentry *parent;
33955 + struct inode *h_dir, *h_inode, *inode, *dir;
33956 + unsigned int *flags = arg;
33958 + btop = au_dbtop(dentry);
33959 + /* dentry is di-locked */
33960 + parent = dget_parent(dentry);
33961 + dir = d_inode(parent);
33962 + h_dir = d_inode(h_parent);
33963 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
33964 + IMustLock(h_dir);
33966 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
33967 + if (unlikely(err < 0))
33969 + h_path.dentry = au_h_dptr(dentry, bdst);
33970 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
33971 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
33972 + if (unlikely(err))
33974 + au_fset_cpdown(*flags, MADE_DIR);
33976 + bopq = au_dbdiropq(dentry);
33977 + au_fclr_cpdown(*flags, WHED);
33978 + au_fclr_cpdown(*flags, DIROPQ);
33979 + if (au_dbwh(dentry) == bdst)
33980 + au_fset_cpdown(*flags, WHED);
33981 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
33982 + au_fset_cpdown(*flags, PARENT_OPQ);
33983 + h_inode = d_inode(h_path.dentry);
33984 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
33985 + if (au_ftest_cpdown(*flags, WHED)) {
33986 + err = au_cpdown_dir_opq(dentry, bdst, flags);
33987 + if (unlikely(err)) {
33988 + inode_unlock(h_inode);
33993 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
33994 + inode_unlock(h_inode);
33995 + if (unlikely(err))
33998 + if (au_ftest_cpdown(*flags, WHED)) {
33999 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34000 + if (unlikely(err))
34004 + inode = d_inode(dentry);
34005 + if (au_ibbot(inode) < bdst)
34006 + au_set_ibbot(inode, bdst);
34007 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34008 + au_hi_flags(inode, /*isdir*/1));
34009 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34010 + goto out; /* success */
34014 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34015 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34016 + rerr = au_diropq_remove(dentry, bdst);
34017 + inode_unlock(h_inode);
34018 + if (unlikely(rerr)) {
34019 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34020 + dentry, bdst, rerr);
34026 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34027 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34028 + if (unlikely(rerr)) {
34029 + AuIOErr("failed removing %pd b%d (%d)\n",
34030 + dentry, bdst, rerr);
34035 + au_set_h_dptr(dentry, bdst, NULL);
34036 + if (au_dbbot(dentry) == bdst)
34037 + au_update_dbbot(dentry);
34043 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34046 + unsigned int flags;
34049 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34054 +/* ---------------------------------------------------------------------- */
34056 +/* policies for create */
34058 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34060 + int err, i, j, ndentry;
34061 + aufs_bindex_t bopq;
34062 + struct au_dcsub_pages dpages;
34063 + struct au_dpage *dpage;
34064 + struct dentry **dentries, *parent, *d;
34066 + err = au_dpages_init(&dpages, GFP_NOFS);
34067 + if (unlikely(err))
34069 + parent = dget_parent(dentry);
34070 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34071 + if (unlikely(err))
34075 + for (i = 0; i < dpages.ndpage; i++) {
34076 + dpage = dpages.dpages + i;
34077 + dentries = dpage->dentries;
34078 + ndentry = dpage->ndentry;
34079 + for (j = 0; j < ndentry; j++) {
34081 + di_read_lock_parent2(d, !AuLock_IR);
34082 + bopq = au_dbdiropq(d);
34083 + di_read_unlock(d, !AuLock_IR);
34084 + if (bopq >= 0 && bopq < err)
34091 + au_dpages_free(&dpages);
34096 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34098 + for (; bindex >= 0; bindex--)
34099 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34104 +/* top down parent */
34105 +static int au_wbr_create_tdp(struct dentry *dentry,
34106 + unsigned int flags __maybe_unused)
34109 + aufs_bindex_t btop, bindex;
34110 + struct super_block *sb;
34111 + struct dentry *parent, *h_parent;
34113 + sb = dentry->d_sb;
34114 + btop = au_dbtop(dentry);
34116 + if (!au_br_rdonly(au_sbr(sb, btop)))
34120 + parent = dget_parent(dentry);
34121 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34122 + h_parent = au_h_dptr(parent, bindex);
34123 + if (!h_parent || d_is_negative(h_parent))
34126 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34133 + /* bottom up here */
34134 + if (unlikely(err < 0)) {
34135 + err = au_wbr_bu(sb, btop - 1);
34137 + err = au_wbr_nonopq(dentry, err);
34141 + AuDbg("b%d\n", err);
34145 +/* ---------------------------------------------------------------------- */
34147 +/* an exception for the policy other than tdp */
34148 +static int au_wbr_create_exp(struct dentry *dentry)
34151 + aufs_bindex_t bwh, bdiropq;
34152 + struct dentry *parent;
34155 + bwh = au_dbwh(dentry);
34156 + parent = dget_parent(dentry);
34157 + bdiropq = au_dbdiropq(parent);
34159 + if (bdiropq >= 0)
34160 + err = min(bdiropq, bwh);
34163 + AuDbg("%d\n", err);
34164 + } else if (bdiropq >= 0) {
34166 + AuDbg("%d\n", err);
34171 + err = au_wbr_nonopq(dentry, err);
34173 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34176 + AuDbg("%d\n", err);
34180 +/* ---------------------------------------------------------------------- */
34183 +static int au_wbr_create_init_rr(struct super_block *sb)
34187 + err = au_wbr_bu(sb, au_sbbot(sb));
34188 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34191 + AuDbg("b%d\n", err);
34195 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34199 + aufs_bindex_t bindex, bbot;
34200 + struct super_block *sb;
34203 + err = au_wbr_create_exp(dentry);
34207 + sb = dentry->d_sb;
34208 + next = &au_sbi(sb)->si_wbr_rr_next;
34209 + bbot = au_sbbot(sb);
34211 + for (bindex = 0; bindex <= bbot; bindex++) {
34212 + if (!au_ftest_wbr(flags, DIR)) {
34213 + err = atomic_dec_return(next) + 1;
34214 + /* modulo for 0 is meaningless */
34215 + if (unlikely(!err))
34216 + err = atomic_dec_return(next) + 1;
34218 + err = atomic_read(next);
34219 + AuDbg("%d\n", err);
34222 + AuDbg("%d\n", err);
34223 + if (!au_br_rdonly(au_sbr(sb, err)))
34229 + err = au_wbr_nonopq(dentry, err);
34232 + AuDbg("%d\n", err);
34236 +/* ---------------------------------------------------------------------- */
34238 +/* most free space */
34239 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34241 + struct super_block *sb;
34242 + struct au_branch *br;
34243 + struct au_wbr_mfs *mfs;
34244 + struct dentry *h_parent;
34245 + aufs_bindex_t bindex, bbot;
34247 + unsigned long long b, bavail;
34248 + struct path h_path;
34249 + /* reduce the stack usage */
34250 + struct kstatfs *st;
34252 + st = kmalloc(sizeof(*st), GFP_NOFS);
34253 + if (unlikely(!st)) {
34254 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34259 + sb = dentry->d_sb;
34260 + mfs = &au_sbi(sb)->si_wbr_mfs;
34261 + MtxMustLock(&mfs->mfs_lock);
34262 + mfs->mfs_bindex = -EROFS;
34263 + mfs->mfsrr_bytes = 0;
34266 + bbot = au_sbbot(sb);
34268 + bindex = au_dbtop(parent);
34269 + bbot = au_dbtaildir(parent);
34272 + for (; bindex <= bbot; bindex++) {
34274 + h_parent = au_h_dptr(parent, bindex);
34275 + if (!h_parent || d_is_negative(h_parent))
34278 + br = au_sbr(sb, bindex);
34279 + if (au_br_rdonly(br))
34282 + /* sb->s_root for NFS is unreliable */
34283 + h_path.mnt = au_br_mnt(br);
34284 + h_path.dentry = h_path.mnt->mnt_root;
34285 + err = vfs_statfs(&h_path, st);
34286 + if (unlikely(err)) {
34287 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34291 + /* when the available size is equal, select the lower one */
34292 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34293 + || sizeof(b) < sizeof(st->f_bsize));
34294 + b = st->f_bavail * st->f_bsize;
34295 + br->br_wbr->wbr_bytes = b;
34296 + if (b >= bavail) {
34298 + mfs->mfs_bindex = bindex;
34299 + mfs->mfs_jiffy = jiffies;
34303 + mfs->mfsrr_bytes = bavail;
34304 + AuDbg("b%d\n", mfs->mfs_bindex);
34305 + au_kfree_rcu(st);
34308 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34311 + struct dentry *parent;
34312 + struct super_block *sb;
34313 + struct au_wbr_mfs *mfs;
34315 + err = au_wbr_create_exp(dentry);
34319 + sb = dentry->d_sb;
34321 + if (au_ftest_wbr(flags, PARENT))
34322 + parent = dget_parent(dentry);
34323 + mfs = &au_sbi(sb)->si_wbr_mfs;
34324 + mutex_lock(&mfs->mfs_lock);
34325 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34326 + || mfs->mfs_bindex < 0
34327 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34328 + au_mfs(dentry, parent);
34329 + mutex_unlock(&mfs->mfs_lock);
34330 + err = mfs->mfs_bindex;
34334 + err = au_wbr_nonopq(dentry, err);
34337 + AuDbg("b%d\n", err);
34341 +static int au_wbr_create_init_mfs(struct super_block *sb)
34343 + struct au_wbr_mfs *mfs;
34345 + mfs = &au_sbi(sb)->si_wbr_mfs;
34346 + mutex_init(&mfs->mfs_lock);
34347 + mfs->mfs_jiffy = 0;
34348 + mfs->mfs_bindex = -EROFS;
34353 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34355 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34359 +/* ---------------------------------------------------------------------- */
34361 +/* top down regardless parent, and then mfs */
34362 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34363 + unsigned int flags __maybe_unused)
34366 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34367 + unsigned long long watermark;
34368 + struct super_block *sb;
34369 + struct au_wbr_mfs *mfs;
34370 + struct au_branch *br;
34371 + struct dentry *parent;
34373 + sb = dentry->d_sb;
34374 + mfs = &au_sbi(sb)->si_wbr_mfs;
34375 + mutex_lock(&mfs->mfs_lock);
34376 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34377 + || mfs->mfs_bindex < 0)
34378 + au_mfs(dentry, /*parent*/NULL);
34379 + watermark = mfs->mfsrr_watermark;
34380 + bmfs = mfs->mfs_bindex;
34381 + mutex_unlock(&mfs->mfs_lock);
34383 + /* another style of au_wbr_create_exp() */
34384 + bwh = au_dbwh(dentry);
34385 + parent = dget_parent(dentry);
34386 + btail = au_dbtaildir(parent);
34387 + if (bwh >= 0 && bwh < btail)
34390 + err = au_wbr_nonopq(dentry, btail);
34391 + if (unlikely(err < 0))
34395 + for (bindex = 0; bindex <= btail; bindex++) {
34396 + br = au_sbr(sb, bindex);
34397 + if (au_br_rdonly(br))
34399 + if (br->br_wbr->wbr_bytes > watermark) {
34410 + AuDbg("b%d\n", err);
34414 +/* ---------------------------------------------------------------------- */
34416 +/* most free space and then round robin */
34417 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34420 + struct au_wbr_mfs *mfs;
34422 + err = au_wbr_create_mfs(dentry, flags);
34424 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34425 + mutex_lock(&mfs->mfs_lock);
34426 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34427 + err = au_wbr_create_rr(dentry, flags);
34428 + mutex_unlock(&mfs->mfs_lock);
34431 + AuDbg("b%d\n", err);
34435 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34439 + au_wbr_create_init_mfs(sb); /* ignore */
34440 + err = au_wbr_create_init_rr(sb);
34445 +/* ---------------------------------------------------------------------- */
34447 +/* top down parent and most free space */
34448 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34451 + unsigned long long b;
34452 + aufs_bindex_t bindex, btop, bbot;
34453 + struct super_block *sb;
34454 + struct dentry *parent, *h_parent;
34455 + struct au_branch *br;
34457 + err = au_wbr_create_tdp(dentry, flags);
34458 + if (unlikely(err < 0))
34460 + parent = dget_parent(dentry);
34461 + btop = au_dbtop(parent);
34462 + bbot = au_dbtaildir(parent);
34463 + if (btop == bbot)
34464 + goto out_parent; /* success */
34466 + e2 = au_wbr_create_mfs(dentry, flags);
34468 + goto out_parent; /* success */
34470 + /* when the available size is equal, select upper one */
34471 + sb = dentry->d_sb;
34472 + br = au_sbr(sb, err);
34473 + b = br->br_wbr->wbr_bytes;
34474 + AuDbg("b%d, %llu\n", err, b);
34476 + for (bindex = btop; bindex <= bbot; bindex++) {
34477 + h_parent = au_h_dptr(parent, bindex);
34478 + if (!h_parent || d_is_negative(h_parent))
34481 + br = au_sbr(sb, bindex);
34482 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34483 + b = br->br_wbr->wbr_bytes;
34485 + AuDbg("b%d, %llu\n", err, b);
34490 + err = au_wbr_nonopq(dentry, err);
34495 + AuDbg("b%d\n", err);
34499 +/* ---------------------------------------------------------------------- */
34502 + * - top down parent
34503 + * - most free space with parent
34504 + * - most free space round-robin regardless parent
34506 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34509 + unsigned long long watermark;
34510 + struct super_block *sb;
34511 + struct au_branch *br;
34512 + struct au_wbr_mfs *mfs;
34514 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34515 + if (unlikely(err < 0))
34518 + sb = dentry->d_sb;
34519 + br = au_sbr(sb, err);
34520 + mfs = &au_sbi(sb)->si_wbr_mfs;
34521 + mutex_lock(&mfs->mfs_lock);
34522 + watermark = mfs->mfsrr_watermark;
34523 + mutex_unlock(&mfs->mfs_lock);
34524 + if (br->br_wbr->wbr_bytes < watermark)
34525 + /* regardless the parent dir */
34526 + err = au_wbr_create_mfsrr(dentry, flags);
34529 + AuDbg("b%d\n", err);
34533 +/* ---------------------------------------------------------------------- */
34535 +/* policies for copyup */
34537 +/* top down parent */
34538 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34540 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34543 +/* bottom up parent */
34544 +static int au_wbr_copyup_bup(struct dentry *dentry)
34547 + aufs_bindex_t bindex, btop;
34548 + struct dentry *parent, *h_parent;
34549 + struct super_block *sb;
34552 + sb = dentry->d_sb;
34553 + parent = dget_parent(dentry);
34554 + btop = au_dbtop(parent);
34555 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34556 + h_parent = au_h_dptr(parent, bindex);
34557 + if (!h_parent || d_is_negative(h_parent))
34560 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34567 + /* bottom up here */
34568 + if (unlikely(err < 0))
34569 + err = au_wbr_bu(sb, btop - 1);
34571 + AuDbg("b%d\n", err);
34576 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
34580 + err = au_wbr_bu(dentry->d_sb, btop);
34581 + AuDbg("b%d\n", err);
34583 + err = au_wbr_nonopq(dentry, err);
34585 + AuDbg("b%d\n", err);
34589 +static int au_wbr_copyup_bu(struct dentry *dentry)
34592 + aufs_bindex_t btop;
34594 + btop = au_dbtop(dentry);
34595 + err = au_wbr_do_copyup_bu(dentry, btop);
34599 +/* ---------------------------------------------------------------------- */
34601 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
34602 + [AuWbrCopyup_TDP] = {
34603 + .copyup = au_wbr_copyup_tdp
34605 + [AuWbrCopyup_BUP] = {
34606 + .copyup = au_wbr_copyup_bup
34608 + [AuWbrCopyup_BU] = {
34609 + .copyup = au_wbr_copyup_bu
34613 +struct au_wbr_create_operations au_wbr_create_ops[] = {
34614 + [AuWbrCreate_TDP] = {
34615 + .create = au_wbr_create_tdp
34617 + [AuWbrCreate_RR] = {
34618 + .create = au_wbr_create_rr,
34619 + .init = au_wbr_create_init_rr
34621 + [AuWbrCreate_MFS] = {
34622 + .create = au_wbr_create_mfs,
34623 + .init = au_wbr_create_init_mfs,
34624 + .fin = au_wbr_create_fin_mfs
34626 + [AuWbrCreate_MFSV] = {
34627 + .create = au_wbr_create_mfs,
34628 + .init = au_wbr_create_init_mfs,
34629 + .fin = au_wbr_create_fin_mfs
34631 + [AuWbrCreate_MFSRR] = {
34632 + .create = au_wbr_create_mfsrr,
34633 + .init = au_wbr_create_init_mfsrr,
34634 + .fin = au_wbr_create_fin_mfs
34636 + [AuWbrCreate_MFSRRV] = {
34637 + .create = au_wbr_create_mfsrr,
34638 + .init = au_wbr_create_init_mfsrr,
34639 + .fin = au_wbr_create_fin_mfs
34641 + [AuWbrCreate_TDMFS] = {
34642 + .create = au_wbr_create_tdmfs,
34643 + .init = au_wbr_create_init_mfs,
34644 + .fin = au_wbr_create_fin_mfs
34646 + [AuWbrCreate_TDMFSV] = {
34647 + .create = au_wbr_create_tdmfs,
34648 + .init = au_wbr_create_init_mfs,
34649 + .fin = au_wbr_create_fin_mfs
34651 + [AuWbrCreate_PMFS] = {
34652 + .create = au_wbr_create_pmfs,
34653 + .init = au_wbr_create_init_mfs,
34654 + .fin = au_wbr_create_fin_mfs
34656 + [AuWbrCreate_PMFSV] = {
34657 + .create = au_wbr_create_pmfs,
34658 + .init = au_wbr_create_init_mfs,
34659 + .fin = au_wbr_create_fin_mfs
34661 + [AuWbrCreate_PMFSRR] = {
34662 + .create = au_wbr_create_pmfsrr,
34663 + .init = au_wbr_create_init_mfsrr,
34664 + .fin = au_wbr_create_fin_mfs
34666 + [AuWbrCreate_PMFSRRV] = {
34667 + .create = au_wbr_create_pmfsrr,
34668 + .init = au_wbr_create_init_mfsrr,
34669 + .fin = au_wbr_create_fin_mfs
34672 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
34673 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
34674 +++ linux/fs/aufs/whout.c 2021-12-03 15:38:59.939980643 +0100
34676 +// SPDX-License-Identifier: GPL-2.0
34678 + * Copyright (C) 2005-2021 Junjiro R. Okajima
34680 + * This program, aufs is free software; you can redistribute it and/or modify
34681 + * it under the terms of the GNU General Public License as published by
34682 + * the Free Software Foundation; either version 2 of the License, or
34683 + * (at your option) any later version.
34685 + * This program is distributed in the hope that it will be useful,
34686 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34687 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34688 + * GNU General Public License for more details.
34690 + * You should have received a copy of the GNU General Public License
34691 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34695 + * whiteout for logical deletion and opaque directory
34700 +#define WH_MASK 0444
34703 + * If a directory contains this file, then it is opaque. We start with the
34704 + * .wh. flag so that it is blocked by lookup.
34706 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
34707 + sizeof(AUFS_WH_DIROPQ) - 1);
34710 + * generate whiteout name, which is NOT terminated by NULL.
34711 + * @name: original d_name.name
34712 + * @len: original d_name.len
34713 + * @wh: whiteout qstr
34714 + * returns zero when succeeds, otherwise error.
34715 + * succeeded value as wh->name should be freed by kfree().
34717 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
34721 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
34722 + return -ENAMETOOLONG;
34724 + wh->len = name->len + AUFS_WH_PFX_LEN;
34725 + p = kmalloc(wh->len, GFP_NOFS);
34728 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
34729 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
34736 +/* ---------------------------------------------------------------------- */
34739 + * test if the @wh_name exists under @h_ppath.
34740 + * @try_sio specifies the necessary of super-io.
34742 +int au_wh_test(struct path *h_ppath, struct qstr *wh_name, int try_sio)
34745 + struct dentry *wh_dentry;
34748 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
34750 + wh_dentry = au_sio_lkup_one(wh_name, h_ppath);
34751 + err = PTR_ERR(wh_dentry);
34752 + if (IS_ERR(wh_dentry)) {
34753 + if (err == -ENAMETOOLONG)
34759 + if (d_is_negative(wh_dentry))
34760 + goto out_wh; /* success */
34763 + if (d_is_reg(wh_dentry))
34764 + goto out_wh; /* success */
34767 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
34768 + wh_dentry, d_inode(wh_dentry)->i_mode);
34777 + * test if the @h_path->dentry sets opaque or not.
34779 +int au_diropq_test(struct path *h_path)
34782 + struct inode *h_dir;
34784 + h_dir = d_inode(h_path->dentry);
34785 + err = au_wh_test(h_path, &diropq_name,
34786 + au_test_h_perm_sio(h_dir, MAY_EXEC));
34791 + * returns a negative dentry whose name is unique and temporary.
34793 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
34794 + struct qstr *prefix)
34796 + struct dentry *dentry;
34798 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
34800 + /* strict atomic_t is unnecessary here */
34801 + static unsigned short cnt;
34803 + struct path h_ppath;
34805 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
34808 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
34809 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
34810 + dentry = ERR_PTR(-ENAMETOOLONG);
34811 + if (unlikely(qs.len > NAME_MAX))
34813 + dentry = ERR_PTR(-ENOMEM);
34814 + name = kmalloc(qs.len + 1, GFP_NOFS);
34815 + if (unlikely(!name))
34819 + /* doubly whiteout-ed */
34820 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
34821 + p = name + AUFS_WH_PFX_LEN * 2;
34822 + memcpy(p, prefix->name, prefix->len);
34823 + p += prefix->len;
34825 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
34827 + h_ppath.dentry = h_parent;
34828 + h_ppath.mnt = au_br_mnt(br);
34830 + for (i = 0; i < 3; i++) {
34831 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
34832 + dentry = au_sio_lkup_one(&qs, &h_ppath);
34833 + if (IS_ERR(dentry) || d_is_negative(dentry))
34837 + /* pr_warn("could not get random name\n"); */
34838 + dentry = ERR_PTR(-EEXIST);
34839 + AuDbg("%.*s\n", AuLNPair(&qs));
34843 + if (name != defname)
34844 + au_kfree_try_rcu(name);
34846 + AuTraceErrPtr(dentry);
34851 + * rename the @h_dentry on @br to the whiteouted temporary name.
34853 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
34856 + struct path h_path = {
34857 + .mnt = au_br_mnt(br)
34859 + struct inode *h_dir, *delegated;
34860 + struct dentry *h_parent;
34862 + h_parent = h_dentry->d_parent; /* dir inode is locked */
34863 + h_dir = d_inode(h_parent);
34864 + IMustLock(h_dir);
34866 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
34867 + err = PTR_ERR(h_path.dentry);
34868 + if (IS_ERR(h_path.dentry))
34871 + /* under the same dir, no need to lock_rename() */
34872 + delegated = NULL;
34873 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
34876 + if (unlikely(err == -EWOULDBLOCK)) {
34877 + pr_warn("cannot retry for NFSv4 delegation"
34878 + " for an internal rename\n");
34881 + dput(h_path.dentry);
34888 +/* ---------------------------------------------------------------------- */
34890 + * functions for removing a whiteout
34893 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
34896 + struct inode *delegated;
34899 + * forces superio when the dir has a sticky bit.
34900 + * this may be a violation of unix fs semantics.
34902 + force = (h_dir->i_mode & S_ISVTX)
34903 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
34904 + delegated = NULL;
34905 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
34906 + if (unlikely(err == -EWOULDBLOCK)) {
34907 + pr_warn("cannot retry for NFSv4 delegation"
34908 + " for an internal unlink\n");
34914 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
34915 + struct dentry *dentry)
34919 + err = do_unlink_wh(h_dir, h_path);
34920 + if (!err && dentry)
34921 + au_set_dbwh(dentry, -1);
34926 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
34929 + struct path h_path;
34932 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
34933 + if (IS_ERR(h_path.dentry))
34934 + err = PTR_ERR(h_path.dentry);
34936 + if (d_is_reg(h_path.dentry)) {
34937 + h_path.mnt = h_ppath->mnt;
34938 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
34940 + dput(h_path.dentry);
34946 +/* ---------------------------------------------------------------------- */
34948 + * initialize/clean whiteout for a branch
34951 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
34955 + struct inode *delegated;
34957 + if (d_is_negative(whpath->dentry))
34961 + err = vfsub_rmdir(h_dir, whpath);
34963 + delegated = NULL;
34964 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
34965 + if (unlikely(err == -EWOULDBLOCK)) {
34966 + pr_warn("cannot retry for NFSv4 delegation"
34967 + " for an internal unlink\n");
34971 + if (unlikely(err))
34972 + pr_warn("failed removing %pd (%d), ignored.\n",
34973 + whpath->dentry, err);
34976 +static int test_linkable(struct dentry *h_root)
34978 + struct inode *h_dir = d_inode(h_root);
34980 + if (h_dir->i_op->link)
34983 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
34984 + h_root, au_sbtype(h_root->d_sb));
34985 + return -ENOSYS; /* the branch doesn't have its ->link() */
34988 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
34989 +static int au_whdir(struct inode *h_dir, struct path *path)
34994 + if (d_is_negative(path->dentry)) {
34997 + if (au_test_nfs(path->dentry->d_sb))
34999 + err = vfsub_mkdir(h_dir, path, mode);
35000 + } else if (d_is_dir(path->dentry))
35003 + pr_err("unknown %pd exists\n", path->dentry);
35008 +struct au_wh_base {
35009 + const struct qstr *name;
35010 + struct dentry *dentry;
35013 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35014 + struct path *h_path)
35016 + h_path->dentry = base[AuBrWh_BASE].dentry;
35017 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35018 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35019 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35020 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35021 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35025 + * returns tri-state,
35026 + * minus: error, caller should print the message
35028 + * plus: error, caller should NOT print the message
35030 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35031 + int do_plink, struct au_wh_base base[],
35032 + struct path *h_path)
35035 + struct inode *h_dir;
35037 + h_dir = d_inode(h_root);
35038 + h_path->dentry = base[AuBrWh_BASE].dentry;
35039 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35040 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35042 + err = test_linkable(h_root);
35043 + if (unlikely(err)) {
35048 + err = au_whdir(h_dir, h_path);
35049 + if (unlikely(err))
35051 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35053 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35054 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35055 + err = au_whdir(h_dir, h_path);
35056 + if (unlikely(err))
35058 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35065 + * for the moment, aufs supports the branch filesystem which does not support
35066 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35067 + * copyup failed. finally, such filesystem will not be used as the writable
35070 + * returns tri-state, see above.
35072 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35073 + int do_plink, struct au_wh_base base[],
35074 + struct path *h_path)
35077 + struct inode *h_dir;
35079 + WbrWhMustWriteLock(wbr);
35081 + err = test_linkable(h_root);
35082 + if (unlikely(err)) {
35088 + * todo: should this create be done in /sbin/mount.aufs helper?
35091 + h_dir = d_inode(h_root);
35092 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35093 + h_path->dentry = base[AuBrWh_BASE].dentry;
35094 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35095 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35098 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35099 + if (unlikely(err))
35102 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35104 + err = au_whdir(h_dir, h_path);
35105 + if (unlikely(err))
35107 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35109 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35110 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35112 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35113 + err = au_whdir(h_dir, h_path);
35114 + if (unlikely(err))
35116 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35123 + * initialize the whiteout base file/dir for @br.
35125 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35128 + const unsigned char do_plink
35129 + = !!au_opt_test(au_mntflags(sb), PLINK);
35130 + struct inode *h_dir;
35131 + struct path path = br->br_path;
35132 + struct dentry *h_root = path.dentry;
35133 + struct au_wbr *wbr = br->br_wbr;
35134 + static const struct qstr base_name[] = {
35135 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35136 + sizeof(AUFS_BASE_NAME) - 1),
35137 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35138 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35139 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35140 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35142 + struct au_wh_base base[] = {
35143 + [AuBrWh_BASE] = {
35144 + .name = base_name + AuBrWh_BASE,
35147 + [AuBrWh_PLINK] = {
35148 + .name = base_name + AuBrWh_PLINK,
35151 + [AuBrWh_ORPH] = {
35152 + .name = base_name + AuBrWh_ORPH,
35158 + WbrWhMustWriteLock(wbr);
35160 + for (i = 0; i < AuBrWh_Last; i++) {
35161 + /* doubly whiteouted */
35162 + struct dentry *d;
35164 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35165 + err = PTR_ERR(d);
35169 + base[i].dentry = d;
35171 + && wbr->wbr_wh[i]
35172 + && wbr->wbr_wh[i] != base[i].dentry);
35176 + for (i = 0; i < AuBrWh_Last; i++) {
35177 + dput(wbr->wbr_wh[i]);
35178 + wbr->wbr_wh[i] = NULL;
35182 + if (!au_br_writable(br->br_perm)) {
35183 + h_dir = d_inode(h_root);
35184 + au_wh_init_ro(h_dir, base, &path);
35185 + } else if (!au_br_wh_linkable(br->br_perm)) {
35186 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35192 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35198 + goto out; /* success */
35201 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35202 + err, h_root, au_sbtype(h_root->d_sb));
35204 + for (i = 0; i < AuBrWh_Last; i++)
35205 + dput(base[i].dentry);
35209 +/* ---------------------------------------------------------------------- */
35211 + * whiteouts are all hard-linked usually.
35212 + * when its link count reaches a ceiling, we create a new whiteout base
35213 + * asynchronously.
35216 +struct reinit_br_wh {
35217 + struct super_block *sb;
35218 + struct au_branch *br;
35221 +static void reinit_br_wh(void *arg)
35224 + aufs_bindex_t bindex;
35225 + struct path h_path;
35226 + struct reinit_br_wh *a = arg;
35227 + struct au_wbr *wbr;
35228 + struct inode *dir, *delegated;
35229 + struct dentry *h_root;
35230 + struct au_hinode *hdir;
35233 + wbr = a->br->br_wbr;
35234 + /* big aufs lock */
35235 + si_noflush_write_lock(a->sb);
35236 + if (!au_br_writable(a->br->br_perm))
35238 + bindex = au_br_index(a->sb, a->br->br_id);
35239 + if (unlikely(bindex < 0))
35242 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35243 + dir = d_inode(a->sb->s_root);
35244 + hdir = au_hi(dir, bindex);
35245 + h_root = au_h_dptr(a->sb->s_root, bindex);
35246 + AuDebugOn(h_root != au_br_dentry(a->br));
35248 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35249 + wbr_wh_write_lock(wbr);
35250 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35253 + h_path.dentry = wbr->wbr_whbase;
35254 + h_path.mnt = au_br_mnt(a->br);
35255 + delegated = NULL;
35256 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35258 + if (unlikely(err == -EWOULDBLOCK)) {
35259 + pr_warn("cannot retry for NFSv4 delegation"
35260 + " for an internal unlink\n");
35264 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35267 + dput(wbr->wbr_whbase);
35268 + wbr->wbr_whbase = NULL;
35270 + err = au_wh_init(a->br, a->sb);
35271 + wbr_wh_write_unlock(wbr);
35272 + au_hn_inode_unlock(hdir);
35273 + di_read_unlock(a->sb->s_root, AuLock_IR);
35275 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35279 + atomic_dec(&wbr->wbr_wh_running);
35280 + au_lcnt_dec(&a->br->br_count);
35281 + si_write_unlock(a->sb);
35282 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35284 + if (unlikely(err))
35285 + AuIOErr("err %d\n", err);
35288 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35290 + int do_dec, wkq_err;
35291 + struct reinit_br_wh *arg;
35294 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35297 + /* ignore ENOMEM */
35298 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35301 + * dec(wh_running), kfree(arg) and dec(br_count)
35302 + * in reinit function
35306 + au_lcnt_inc(&br->br_count);
35307 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35308 + if (unlikely(wkq_err)) {
35309 + atomic_dec(&br->br_wbr->wbr_wh_running);
35310 + au_lcnt_dec(&br->br_count);
35311 + au_kfree_rcu(arg);
35318 + atomic_dec(&br->br_wbr->wbr_wh_running);
35321 +/* ---------------------------------------------------------------------- */
35324 + * create the whiteout @wh.
35326 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35327 + struct dentry *wh)
35330 + struct path h_path = {
35333 + struct au_branch *br;
35334 + struct au_wbr *wbr;
35335 + struct dentry *h_parent;
35336 + struct inode *h_dir, *delegated;
35338 + h_parent = wh->d_parent; /* dir inode is locked */
35339 + h_dir = d_inode(h_parent);
35340 + IMustLock(h_dir);
35342 + br = au_sbr(sb, bindex);
35343 + h_path.mnt = au_br_mnt(br);
35344 + wbr = br->br_wbr;
35345 + wbr_wh_read_lock(wbr);
35346 + if (wbr->wbr_whbase) {
35347 + delegated = NULL;
35348 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35349 + if (unlikely(err == -EWOULDBLOCK)) {
35350 + pr_warn("cannot retry for NFSv4 delegation"
35351 + " for an internal link\n");
35354 + if (!err || err != -EMLINK)
35357 + /* link count full. re-initialize br_whbase. */
35358 + kick_reinit_br_wh(sb, br);
35361 + /* return this error in this context */
35362 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35364 + au_fhsm_wrote(sb, bindex, /*force*/0);
35367 + wbr_wh_read_unlock(wbr);
35371 +/* ---------------------------------------------------------------------- */
35374 + * create or remove the diropq.
35376 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35377 + unsigned int flags)
35379 + struct dentry *opq_dentry;
35380 + struct super_block *sb;
35381 + struct au_branch *br;
35382 + struct path h_path;
35385 + sb = dentry->d_sb;
35386 + br = au_sbr(sb, bindex);
35387 + h_path.dentry = au_h_dptr(dentry, bindex);
35388 + h_path.mnt = au_br_mnt(br);
35389 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35390 + if (IS_ERR(opq_dentry))
35393 + if (au_ftest_diropq(flags, CREATE)) {
35394 + err = link_or_create_wh(sb, bindex, opq_dentry);
35396 + au_set_dbdiropq(dentry, bindex);
35397 + goto out; /* success */
35400 + h_path.dentry = opq_dentry;
35401 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35403 + au_set_dbdiropq(dentry, -1);
35405 + dput(opq_dentry);
35406 + opq_dentry = ERR_PTR(err);
35409 + return opq_dentry;
35412 +struct do_diropq_args {
35413 + struct dentry **errp;
35414 + struct dentry *dentry;
35415 + aufs_bindex_t bindex;
35416 + unsigned int flags;
35419 +static void call_do_diropq(void *args)
35421 + struct do_diropq_args *a = args;
35422 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35425 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35426 + unsigned int flags)
35428 + struct dentry *diropq, *h_dentry;
35430 + h_dentry = au_h_dptr(dentry, bindex);
35431 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
35432 + diropq = do_diropq(dentry, bindex, flags);
35435 + struct do_diropq_args args = {
35437 + .dentry = dentry,
35438 + .bindex = bindex,
35442 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35443 + if (unlikely(wkq_err))
35444 + diropq = ERR_PTR(wkq_err);
35450 +/* ---------------------------------------------------------------------- */
35453 + * lookup whiteout dentry.
35454 + * @h_parent: lower parent dentry which must exist and be locked
35455 + * @base_name: name of dentry which will be whiteouted
35456 + * returns dentry for whiteout.
35458 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35459 + struct au_branch *br)
35462 + struct qstr wh_name;
35463 + struct dentry *wh_dentry;
35464 + struct path h_path;
35466 + err = au_wh_name_alloc(&wh_name, base_name);
35467 + wh_dentry = ERR_PTR(err);
35469 + h_path.dentry = h_parent;
35470 + h_path.mnt = au_br_mnt(br);
35471 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35472 + au_kfree_try_rcu(wh_name.name);
35474 + return wh_dentry;
35478 + * link/create a whiteout for @dentry on @bindex.
35480 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35481 + struct dentry *h_parent)
35483 + struct dentry *wh_dentry;
35484 + struct super_block *sb;
35487 + sb = dentry->d_sb;
35488 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35489 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35490 + err = link_or_create_wh(sb, bindex, wh_dentry);
35492 + au_set_dbwh(dentry, bindex);
35493 + au_fhsm_wrote(sb, bindex, /*force*/0);
35496 + wh_dentry = ERR_PTR(err);
35500 + return wh_dentry;
35503 +/* ---------------------------------------------------------------------- */
35505 +/* Delete all whiteouts in this directory on branch bindex. */
35506 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35507 + aufs_bindex_t bindex)
35510 + unsigned long ul, n;
35511 + struct qstr wh_name;
35513 + struct hlist_head *head;
35514 + struct au_vdir_wh *pos;
35515 + struct au_vdir_destr *str;
35518 + p = (void *)__get_free_page(GFP_NOFS);
35519 + wh_name.name = p;
35520 + if (unlikely(!wh_name.name))
35524 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35525 + p += AUFS_WH_PFX_LEN;
35526 + n = whlist->nh_num;
35527 + head = whlist->nh_head;
35528 + for (ul = 0; !err && ul < n; ul++, head++) {
35529 + hlist_for_each_entry(pos, head, wh_hash) {
35530 + if (pos->wh_bindex != bindex)
35533 + str = &pos->wh_str;
35534 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35535 + memcpy(p, str->name, str->len);
35536 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35537 + err = unlink_wh_name(h_path, &wh_name);
35542 + AuIOErr("whiteout name too long %.*s\n",
35543 + str->len, str->name);
35548 + free_page((unsigned long)wh_name.name);
35554 +struct del_wh_children_args {
35556 + struct path *h_path;
35557 + struct au_nhash *whlist;
35558 + aufs_bindex_t bindex;
35561 +static void call_del_wh_children(void *args)
35563 + struct del_wh_children_args *a = args;
35564 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35567 +/* ---------------------------------------------------------------------- */
35569 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
35571 + struct au_whtmp_rmdir *whtmp;
35573 + unsigned int rdhash;
35575 + SiMustAnyLock(sb);
35577 + whtmp = kzalloc(sizeof(*whtmp), gfp);
35578 + if (unlikely(!whtmp)) {
35579 + whtmp = ERR_PTR(-ENOMEM);
35583 + /* no estimation for dir size */
35584 + rdhash = au_sbi(sb)->si_rdhash;
35586 + rdhash = AUFS_RDHASH_DEF;
35587 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
35588 + if (unlikely(err)) {
35589 + au_kfree_rcu(whtmp);
35590 + whtmp = ERR_PTR(err);
35597 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
35600 + au_lcnt_dec(&whtmp->br->br_count);
35601 + dput(whtmp->wh_dentry);
35602 + iput(whtmp->dir);
35603 + au_nhash_wh_free(&whtmp->whlist);
35604 + au_kfree_rcu(whtmp);
35608 + * rmdir the whiteouted temporary named dir @h_dentry.
35609 + * @whlist: whiteouted children.
35611 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35612 + struct dentry *wh_dentry, struct au_nhash *whlist)
35615 + unsigned int h_nlink;
35616 + struct path wh_path;
35617 + struct inode *wh_inode, *h_dir;
35618 + struct au_branch *br;
35620 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
35621 + IMustLock(h_dir);
35623 + br = au_sbr(dir->i_sb, bindex);
35624 + wh_path.dentry = wh_dentry;
35625 + wh_path.mnt = au_br_mnt(br);
35626 + wh_inode = d_inode(wh_dentry);
35627 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
35630 + * someone else might change some whiteouts while we were sleeping.
35631 + * it means this whlist may have an obsoleted entry.
35633 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
35634 + err = del_wh_children(&wh_path, whlist, bindex);
35637 + struct del_wh_children_args args = {
35639 + .h_path = &wh_path,
35640 + .whlist = whlist,
35644 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
35645 + if (unlikely(wkq_err))
35648 + inode_unlock(wh_inode);
35651 + h_nlink = h_dir->i_nlink;
35652 + err = vfsub_rmdir(h_dir, &wh_path);
35653 + /* some fs doesn't change the parent nlink in some cases */
35654 + h_nlink -= h_dir->i_nlink;
35658 + if (au_ibtop(dir) == bindex) {
35659 + /* todo: dir->i_mutex is necessary */
35660 + au_cpup_attr_timesizes(dir);
35662 + vfsub_drop_nlink(dir);
35664 + return 0; /* success */
35667 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
35671 +static void call_rmdir_whtmp(void *args)
35674 + aufs_bindex_t bindex;
35675 + struct au_whtmp_rmdir *a = args;
35676 + struct super_block *sb;
35677 + struct dentry *h_parent;
35678 + struct inode *h_dir;
35679 + struct au_hinode *hdir;
35681 + /* rmdir by nfsd may cause deadlock with this i_mutex */
35682 + /* inode_lock(a->dir); */
35684 + sb = a->dir->i_sb;
35685 + si_read_lock(sb, !AuLock_FLUSH);
35686 + if (!au_br_writable(a->br->br_perm))
35688 + bindex = au_br_index(sb, a->br->br_id);
35689 + if (unlikely(bindex < 0))
35693 + ii_write_lock_parent(a->dir);
35694 + h_parent = dget_parent(a->wh_dentry);
35695 + h_dir = d_inode(h_parent);
35696 + hdir = au_hi(a->dir, bindex);
35697 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
35698 + if (unlikely(err))
35700 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35701 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
35704 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
35705 + au_hn_inode_unlock(hdir);
35706 + vfsub_mnt_drop_write(au_br_mnt(a->br));
35710 + ii_write_unlock(a->dir);
35712 + /* inode_unlock(a->dir); */
35713 + au_whtmp_rmdir_free(a);
35714 + si_read_unlock(sb);
35715 + au_nwt_done(&au_sbi(sb)->si_nowait);
35716 + if (unlikely(err))
35717 + AuIOErr("err %d\n", err);
35720 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35721 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
35724 + struct super_block *sb;
35728 + /* all post-process will be done in do_rmdir_whtmp(). */
35730 + args->dir = au_igrab(dir);
35731 + args->br = au_sbr(sb, bindex);
35732 + au_lcnt_inc(&args->br->br_count);
35733 + args->wh_dentry = dget(wh_dentry);
35734 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
35735 + if (unlikely(wkq_err)) {
35736 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
35737 + au_whtmp_rmdir_free(args);
35740 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
35741 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
35742 +++ linux/fs/aufs/whout.h 2021-12-03 15:38:59.943313977 +0100
35744 +/* SPDX-License-Identifier: GPL-2.0 */
35746 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35748 + * This program, aufs is free software; you can redistribute it and/or modify
35749 + * it under the terms of the GNU General Public License as published by
35750 + * the Free Software Foundation; either version 2 of the License, or
35751 + * (at your option) any later version.
35753 + * This program is distributed in the hope that it will be useful,
35754 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35755 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35756 + * GNU General Public License for more details.
35758 + * You should have received a copy of the GNU General Public License
35759 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35763 + * whiteout for logical deletion and opaque directory
35766 +#ifndef __AUFS_WHOUT_H__
35767 +#define __AUFS_WHOUT_H__
35774 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
35775 +int au_wh_test(struct path *h_ppath, struct qstr *wh_name, int try_sio);
35776 +int au_diropq_test(struct path *h_path);
35778 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35779 + struct qstr *prefix);
35780 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
35781 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35782 + struct dentry *dentry);
35783 +int au_wh_init(struct au_branch *br, struct super_block *sb);
35785 +/* diropq flags */
35786 +#define AuDiropq_CREATE 1
35787 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
35788 +#define au_fset_diropq(flags, name) \
35789 + do { (flags) |= AuDiropq_##name; } while (0)
35790 +#define au_fclr_diropq(flags, name) \
35791 + do { (flags) &= ~AuDiropq_##name; } while (0)
35793 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35794 + unsigned int flags);
35795 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35796 + struct au_branch *br);
35797 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35798 + struct dentry *h_parent);
35800 +/* real rmdir for the whiteout-ed dir */
35801 +struct au_whtmp_rmdir {
35802 + struct inode *dir;
35803 + struct au_branch *br;
35804 + struct dentry *wh_dentry;
35805 + struct au_nhash whlist;
35808 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
35809 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
35810 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
35811 + struct dentry *wh_dentry, struct au_nhash *whlist);
35812 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
35813 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
35815 +/* ---------------------------------------------------------------------- */
35817 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
35818 + aufs_bindex_t bindex)
35820 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
35823 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
35825 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
35828 +#endif /* __KERNEL__ */
35829 +#endif /* __AUFS_WHOUT_H__ */
35830 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
35831 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
35832 +++ linux/fs/aufs/wkq.c 2021-12-03 15:38:59.943313977 +0100
35834 +// SPDX-License-Identifier: GPL-2.0
35836 + * Copyright (C) 2005-2021 Junjiro R. Okajima
35838 + * This program, aufs is free software; you can redistribute it and/or modify
35839 + * it under the terms of the GNU General Public License as published by
35840 + * the Free Software Foundation; either version 2 of the License, or
35841 + * (at your option) any later version.
35843 + * This program is distributed in the hope that it will be useful,
35844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35846 + * GNU General Public License for more details.
35848 + * You should have received a copy of the GNU General Public License
35849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35853 + * workqueue for asynchronous/super-io operations
35854 + * todo: try new credential scheme
35857 +#include <linux/module.h>
35860 +/* internal workqueue named AUFS_WKQ_NAME */
35862 +static struct workqueue_struct *au_wkq;
35864 +struct au_wkinfo {
35865 + struct work_struct wk;
35866 + struct kobject *kobj;
35868 + unsigned int flags; /* see wkq.h */
35870 + au_wkq_func_t func;
35873 +#ifdef CONFIG_LOCKDEP
35875 + struct held_lock **hlock;
35878 + struct completion *comp;
35881 +/* ---------------------------------------------------------------------- */
35883 + * Aufs passes some operations to the workqueue such as the internal copyup.
35884 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
35885 + * job run by workqueue depends upon the locks acquired in the other task.
35886 + * Delegating a small operation to the workqueue, aufs passes its lockdep
35887 + * information too. And the job in the workqueue restores the info in order to
35888 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
35889 + * correctly and expectedly.
35892 +#ifndef CONFIG_LOCKDEP
35893 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
35894 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
35895 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
35896 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
35897 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
35899 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
35901 + wkinfo->hlock = NULL;
35902 + wkinfo->dont_check = 0;
35909 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
35911 + static DEFINE_SPINLOCK(spin);
35914 + struct lock_class_key *key;
35916 + { .name = "&sbinfo->si_rwsem" },
35917 + { .name = "&finfo->fi_rwsem" },
35918 + { .name = "&dinfo->di_rwsem" },
35919 + { .name = "&iinfo->ii_rwsem" }
35924 + /* lockless read from 'set.' see below */
35925 + if (set == ARRAY_SIZE(a)) {
35926 + for (i = 0; i < ARRAY_SIZE(a); i++)
35927 + if (a[i].key == key)
35932 + spin_lock(&spin);
35934 + for (i = 0; i < ARRAY_SIZE(a); i++)
35935 + if (a[i].key == key) {
35936 + spin_unlock(&spin);
35939 + for (i = 0; i < ARRAY_SIZE(a); i++) {
35941 + if (unlikely(a[i].key == key)) { /* rare but possible */
35942 + spin_unlock(&spin);
35947 + if (strstr(a[i].name, name)) {
35949 + * the order of these three lines is important for the
35950 + * lockless read above.
35953 + spin_unlock(&spin);
35955 + /* AuDbg("%d, %s\n", set, name); */
35959 + spin_unlock(&spin);
35968 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
35971 + struct task_struct *curr;
35972 + struct held_lock **hl, *held_locks, *p;
35976 + wkinfo->dont_check = lockdep_recursing(curr);
35977 + if (wkinfo->dont_check)
35979 + n = curr->lockdep_depth;
35984 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
35985 + if (unlikely(!wkinfo->hlock))
35989 +#if 0 /* left for debugging */
35990 + if (0 && au_debug_test())
35991 + lockdep_print_held_locks(curr);
35993 + held_locks = curr->held_locks;
35994 + hl = wkinfo->hlock;
35996 + p = held_locks++;
35997 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36006 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36008 + au_kfree_try_rcu(wkinfo->hlock);
36011 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36013 + struct held_lock *p, **hl = wkinfo->hlock;
36016 + if (wkinfo->dont_check)
36020 + while ((p = *hl++)) { /* assignment */
36021 + subclass = lockdep_hlock_class(p)->subclass;
36022 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36024 + rwsem_acquire_read(p->instance, subclass, 0,
36025 + /*p->acquire_ip*/_RET_IP_);
36027 + rwsem_acquire(p->instance, subclass, 0,
36028 + /*p->acquire_ip*/_RET_IP_);
36032 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36034 + struct held_lock *p, **hl = wkinfo->hlock;
36036 + if (wkinfo->dont_check)
36040 + while ((p = *hl++)) /* assignment */
36041 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36045 +static void wkq_func(struct work_struct *wk)
36047 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36049 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36050 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36052 + au_wkq_lockdep_pre(wkinfo);
36053 + wkinfo->func(wkinfo->args);
36054 + au_wkq_lockdep_post(wkinfo);
36055 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36056 + complete(wkinfo->comp);
36058 + kobject_put(wkinfo->kobj);
36059 + module_put(THIS_MODULE); /* todo: ?? */
36060 + au_kfree_rcu(wkinfo);
36065 + * Since struct completion is large, try allocating it dynamically.
36067 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36069 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36071 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36073 + init_completion(*comp);
36074 + wkinfo->comp = *comp;
36080 +static void au_wkq_comp_free(struct completion *comp)
36082 + au_kfree_rcu(comp);
36085 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36087 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36088 + if (au_wkq_test()) {
36089 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36090 + " due to a dead dir by UDBA,"
36091 + " or async xino write?\n");
36092 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36095 + au_dbg_verify_kthread();
36097 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36098 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36099 + queue_work(au_wkq, &wkinfo->wk);
36101 + INIT_WORK(&wkinfo->wk, wkq_func);
36102 + schedule_work(&wkinfo->wk);
36107 + * Be careful. It is easy to make deadlock happen.
36108 + * processA: lock, wkq and wait
36109 + * processB: wkq and wait, lock in wkq
36112 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36115 + AuWkqCompDeclare(comp);
36116 + struct au_wkinfo wkinfo = {
36122 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36123 + if (unlikely(err))
36125 + err = au_wkq_lockdep_alloc(&wkinfo);
36126 + if (unlikely(err))
36129 + au_wkq_run(&wkinfo);
36130 + /* no timeout, no interrupt */
36131 + wait_for_completion(wkinfo.comp);
36133 + au_wkq_lockdep_free(&wkinfo);
36136 + au_wkq_comp_free(comp);
36138 + destroy_work_on_stack(&wkinfo.wk);
36143 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36144 + * problem in a concurrent umounting.
36146 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36147 + unsigned int flags)
36150 + struct au_wkinfo *wkinfo;
36152 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36155 + * wkq_func() must free this wkinfo.
36156 + * it highly depends upon the implementation of workqueue.
36159 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36161 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36162 + wkinfo->flags = flags & ~AuWkq_WAIT;
36163 + wkinfo->func = func;
36164 + wkinfo->args = args;
36165 + wkinfo->comp = NULL;
36166 + au_wkq_lockdep_init(wkinfo);
36167 + kobject_get(wkinfo->kobj);
36168 + __module_get(THIS_MODULE); /* todo: ?? */
36170 + au_wkq_run(wkinfo);
36173 + au_nwt_done(&au_sbi(sb)->si_nowait);
36179 +/* ---------------------------------------------------------------------- */
36181 +void au_nwt_init(struct au_nowait_tasks *nwt)
36183 + atomic_set(&nwt->nw_len, 0);
36184 + /* smp_mb(); */ /* atomic_set */
36185 + init_waitqueue_head(&nwt->nw_wq);
36188 +void au_wkq_fin(void)
36190 + destroy_workqueue(au_wkq);
36193 +int __init au_wkq_init(void)
36198 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36199 + if (IS_ERR(au_wkq))
36200 + err = PTR_ERR(au_wkq);
36201 + else if (!au_wkq)
36206 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36207 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36208 +++ linux/fs/aufs/wkq.h 2021-12-03 15:38:59.943313977 +0100
36210 +/* SPDX-License-Identifier: GPL-2.0 */
36212 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36214 + * This program, aufs is free software; you can redistribute it and/or modify
36215 + * it under the terms of the GNU General Public License as published by
36216 + * the Free Software Foundation; either version 2 of the License, or
36217 + * (at your option) any later version.
36219 + * This program is distributed in the hope that it will be useful,
36220 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36221 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36222 + * GNU General Public License for more details.
36224 + * You should have received a copy of the GNU General Public License
36225 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36229 + * workqueue for asynchronous/super-io operations
36230 + * todo: try new credentials management scheme
36233 +#ifndef __AUFS_WKQ_H__
36234 +#define __AUFS_WKQ_H__
36238 +#include <linux/wait.h>
36240 +struct super_block;
36242 +/* ---------------------------------------------------------------------- */
36245 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36247 +struct au_nowait_tasks {
36249 + wait_queue_head_t nw_wq;
36252 +/* ---------------------------------------------------------------------- */
36254 +typedef void (*au_wkq_func_t)(void *args);
36257 +#define AuWkq_WAIT 1
36258 +#define AuWkq_NEST (1 << 1)
36259 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36260 +#define au_fset_wkq(flags, name) \
36261 + do { (flags) |= AuWkq_##name; } while (0)
36262 +#define au_fclr_wkq(flags, name) \
36263 + do { (flags) &= ~AuWkq_##name; } while (0)
36266 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36267 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36268 + unsigned int flags);
36269 +void au_nwt_init(struct au_nowait_tasks *nwt);
36270 +int __init au_wkq_init(void);
36271 +void au_wkq_fin(void);
36273 +/* ---------------------------------------------------------------------- */
36275 +static inline int au_wkq_test(void)
36277 + return current->flags & PF_WQ_WORKER;
36280 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36282 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36285 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36287 + if (atomic_dec_and_test(&nwt->nw_len))
36288 + wake_up_all(&nwt->nw_wq);
36291 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36293 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36297 +#endif /* __KERNEL__ */
36298 +#endif /* __AUFS_WKQ_H__ */
36299 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36300 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36301 +++ linux/fs/aufs/xattr.c 2021-12-03 15:38:59.943313977 +0100
36303 +// SPDX-License-Identifier: GPL-2.0
36305 + * Copyright (C) 2014-2021 Junjiro R. Okajima
36307 + * This program, aufs is free software; you can redistribute it and/or modify
36308 + * it under the terms of the GNU General Public License as published by
36309 + * the Free Software Foundation; either version 2 of the License, or
36310 + * (at your option) any later version.
36312 + * This program is distributed in the hope that it will be useful,
36313 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36314 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36315 + * GNU General Public License for more details.
36317 + * You should have received a copy of the GNU General Public License
36318 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36322 + * handling xattr functions
36325 +#include <linux/fs.h>
36326 +#include <linux/posix_acl_xattr.h>
36327 +#include <linux/xattr.h>
36330 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36332 + if (!ignore_flags)
36340 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36345 +#define cmp(brattr, prefix) do { \
36346 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36347 + XATTR_##prefix##_PREFIX_LEN)) { \
36348 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36354 + cmp(SEC, SECURITY);
36355 + cmp(SYS, SYSTEM);
36356 + cmp(TR, TRUSTED);
36360 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36367 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36369 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
36370 + char *name, char **buf, unsigned int ignore_flags,
36371 + unsigned int verbose)
36375 + struct inode *h_idst;
36377 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
36379 + if (unlikely(err <= 0)) {
36380 + if (err == -ENODATA
36381 + || (err == -EOPNOTSUPP
36382 + && ((ignore_flags & au_xattr_out_of_list)
36383 + || (au_test_nfs_noacl(d_inode(h_src))
36384 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
36386 + XATTR_NAME_POSIX_ACL_DEFAULT))))
36389 + if (err && (verbose || au_debug_test()))
36390 + pr_err("%s, err %d\n", name, err);
36394 + /* unlock it temporary */
36395 + h_idst = d_inode(h_dst);
36396 + inode_unlock(h_idst);
36397 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
36398 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36399 + if (unlikely(err)) {
36400 + if (verbose || au_debug_test())
36401 + pr_err("%s, err %d\n", name, err);
36402 + err = au_xattr_ignore(err, name, ignore_flags);
36409 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
36410 + unsigned int verbose)
36412 + int err, unlocked, acl_access, acl_default;
36414 + struct inode *h_isrc, *h_idst;
36415 + char *value, *p, *o, *e;
36417 + /* try stopping to update the source inode while we are referencing */
36418 + /* there should not be the parent-child relationship between them */
36419 + h_isrc = d_inode(h_src);
36420 + h_idst = d_inode(h_dst);
36421 + inode_unlock(h_idst);
36422 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36423 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36426 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36427 + ssz = vfs_listxattr(h_src, NULL, 0);
36429 + if (unlikely(err < 0)) {
36431 + if (err == -ENODATA
36432 + || err == -EOPNOTSUPP)
36433 + err = 0; /* ignore */
36442 + p = kmalloc(ssz, GFP_NOFS);
36444 + if (unlikely(!p))
36446 + err = vfs_listxattr(h_src, p, ssz);
36448 + inode_unlock_shared(h_isrc);
36450 + AuDbg("err %d, ssz %zd\n", err, ssz);
36451 + if (unlikely(err < 0))
36459 + while (!err && p < e) {
36460 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
36461 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
36462 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
36463 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
36465 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36467 + p += strlen(p) + 1;
36470 + ignore_flags |= au_xattr_out_of_list;
36471 + if (!err && !acl_access) {
36472 + err = au_do_cpup_xattr(h_dst, h_src,
36473 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
36474 + ignore_flags, verbose);
36477 + if (!err && !acl_default) {
36478 + err = au_do_cpup_xattr(h_dst, h_src,
36479 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
36480 + ignore_flags, verbose);
36484 + au_kfree_try_rcu(value);
36487 + au_kfree_try_rcu(o);
36490 + inode_unlock_shared(h_isrc);
36495 +/* ---------------------------------------------------------------------- */
36497 +static int au_smack_reentering(struct super_block *sb)
36499 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36501 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36502 + * i_op->getxattr(). ouch.
36504 + return si_pid_test(sb);
36515 +struct au_lgxattr {
36523 + const char *name;
36530 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36531 + struct au_lgxattr *arg)
36535 + struct path h_path;
36536 + struct super_block *sb;
36538 + sb = dentry->d_sb;
36539 + reenter = au_smack_reentering(sb);
36541 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36542 + if (unlikely(err))
36545 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36546 + if (unlikely(err))
36548 + if (unlikely(!h_path.dentry))
36549 + /* illegally overlapped or something */
36550 + goto out_di; /* pretending success */
36552 + /* always topmost entry only */
36553 + switch (arg->type) {
36554 + case AU_XATTR_LIST:
36555 + err = vfs_listxattr(h_path.dentry,
36556 + arg->u.list.list, arg->u.list.size);
36558 + case AU_XATTR_GET:
36559 + AuDebugOn(d_is_negative(h_path.dentry));
36560 + err = vfs_getxattr(h_path.dentry,
36561 + arg->u.get.name, arg->u.get.value,
36562 + arg->u.get.size);
36568 + di_read_unlock(dentry, AuLock_IR);
36571 + si_read_unlock(sb);
36577 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
36579 + struct au_lgxattr arg = {
36580 + .type = AU_XATTR_LIST,
36587 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
36590 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
36591 + const char *name, void *value, size_t size)
36593 + struct au_lgxattr arg = {
36594 + .type = AU_XATTR_GET,
36602 + return au_lgxattr(dentry, inode, &arg);
36605 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
36606 + const char *name, const void *value, size_t size,
36609 + struct au_sxattr arg = {
36610 + .type = AU_XATTR_SET,
36619 + return au_sxattr(dentry, inode, &arg);
36622 +/* ---------------------------------------------------------------------- */
36624 +static int au_xattr_get(const struct xattr_handler *handler,
36625 + struct dentry *dentry, struct inode *inode,
36626 + const char *name, void *buffer, size_t size)
36628 + return au_getxattr(dentry, inode, name, buffer, size);
36631 +static int au_xattr_set(const struct xattr_handler *handler,
36632 + struct dentry *dentry, struct inode *inode,
36633 + const char *name, const void *value, size_t size,
36636 + return au_setxattr(dentry, inode, name, value, size, flags);
36639 +static const struct xattr_handler au_xattr_handler = {
36642 + .get = au_xattr_get,
36643 + .set = au_xattr_set
36646 +static const struct xattr_handler *au_xattr_handlers[] = {
36647 +#ifdef CONFIG_FS_POSIX_ACL
36648 + &posix_acl_access_xattr_handler,
36649 + &posix_acl_default_xattr_handler,
36651 + &au_xattr_handler, /* must be last */
36655 +void au_xattr_init(struct super_block *sb)
36657 + sb->s_xattr = au_xattr_handlers;
36659 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
36660 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
36661 +++ linux/fs/aufs/xino.c 2021-12-03 15:38:59.943313977 +0100
36663 +// SPDX-License-Identifier: GPL-2.0
36665 + * Copyright (C) 2005-2021 Junjiro R. Okajima
36667 + * This program, aufs is free software; you can redistribute it and/or modify
36668 + * it under the terms of the GNU General Public License as published by
36669 + * the Free Software Foundation; either version 2 of the License, or
36670 + * (at your option) any later version.
36672 + * This program is distributed in the hope that it will be useful,
36673 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36674 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36675 + * GNU General Public License for more details.
36677 + * You should have received a copy of the GNU General Public License
36678 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36682 + * external inode number translation table and bitmap
36684 + * things to consider
36686 + * + au_xino object
36687 + * + XINO files (xino, xib, xigen)
36688 + * + dynamic debugfs entries (xiN)
36689 + * + static debugfs entries (xib, xigen)
36690 + * + static sysfs entry (xi_path)
36691 + * - several entry points to handle them.
36692 + * + mount(2) without xino option (default)
36693 + * + mount(2) with xino option
36694 + * + mount(2) with noxino option
36696 + * + remount with add/del branches
36697 + * + remount with xino/noxino options
36700 +#include <linux/seq_file.h>
36701 +#include <linux/statfs.h>
36704 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
36705 + aufs_bindex_t bbot,
36706 + struct super_block *h_sb)
36708 + /* todo: try binary-search if the branches are many */
36709 + for (; btop <= bbot; btop++)
36710 + if (h_sb == au_sbr_sb(sb, btop))
36716 + * find another branch who is on the same filesystem of the specified
36717 + * branch{@btgt}. search until @bbot.
36719 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
36720 + aufs_bindex_t bbot)
36722 + aufs_bindex_t bindex;
36723 + struct super_block *tgt_sb;
36725 + tgt_sb = au_sbr_sb(sb, btgt);
36726 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
36728 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
36733 +/* ---------------------------------------------------------------------- */
36736 + * stop unnecessary notify events at creating xino files
36739 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
36741 + aufs_bindex_t bfound, bindex, bbot;
36742 + struct dentry *parent;
36743 + struct au_branch *br;
36746 + parent = dentry->d_parent; /* safe d_parent access */
36747 + bbot = au_sbbot(sb);
36748 + for (bindex = 0; bindex <= bbot; bindex++) {
36749 + br = au_sbr(sb, bindex);
36750 + if (au_br_dentry(br) == parent) {
36756 + AuDbg("bfound b%d\n", bfound);
36760 +struct au_xino_lock_dir {
36761 + struct au_hinode *hdir;
36762 + struct dentry *parent;
36763 + struct inode *dir;
36766 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
36767 + unsigned int lsc)
36769 + struct dentry *parent;
36770 + struct inode *dir;
36772 + parent = dget_parent(dentry);
36773 + dir = d_inode(parent);
36774 + inode_lock_nested(dir, lsc);
36775 +#if 0 /* it should not happen */
36776 + spin_lock(&dentry->d_lock);
36777 + if (unlikely(dentry->d_parent != parent)) {
36778 + spin_unlock(&dentry->d_lock);
36779 + inode_unlock(dir);
36784 + spin_unlock(&dentry->d_lock);
36791 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
36792 + struct au_xino_lock_dir *ldir)
36794 + aufs_bindex_t bindex;
36796 + ldir->hdir = NULL;
36797 + bindex = au_xi_root(sb, xipath->dentry);
36798 + if (bindex >= 0) {
36799 + /* rw branch root */
36800 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
36801 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
36804 + ldir->parent = au_dget_parent_lock(xipath->dentry,
36806 + ldir->dir = d_inode(ldir->parent);
36810 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
36813 + au_hn_inode_unlock(ldir->hdir);
36815 + inode_unlock(ldir->dir);
36816 + dput(ldir->parent);
36820 +/* ---------------------------------------------------------------------- */
36823 + * create and set a new xino file
36825 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
36828 + struct file *file;
36829 + struct dentry *h_parent, *d;
36830 + struct inode *h_dir, *inode;
36832 + static DEFINE_MUTEX(mtx);
36835 + * at mount-time, and the xino file is the default path,
36836 + * hnotify is disabled so we have no notify events to ignore.
36837 + * when a user specified the xino, we cannot get au_hdir to be ignored.
36840 + mutex_lock(&mtx);
36841 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36842 + /* | __FMODE_NONOTIFY */,
36844 + if (IS_ERR(file)) {
36846 + mutex_unlock(&mtx);
36848 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
36852 + /* keep file count */
36854 + d = file->f_path.dentry;
36855 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
36857 + mutex_unlock(&mtx);
36858 + /* mnt_want_write() is unnecessary here */
36859 + h_dir = d_inode(h_parent);
36860 + inode = file_inode(file);
36861 + /* no delegation since it is just created */
36862 + if (inode->i_nlink)
36863 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
36865 + inode_unlock(h_dir);
36867 + if (unlikely(err)) {
36869 + pr_err("unlink %s(%d)\n", fpath, err);
36874 + if (unlikely(sb == d->d_sb)) {
36876 + pr_err("%s must be outside\n", fpath);
36879 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
36881 + pr_err("xino doesn't support %s(%s)\n",
36882 + fpath, au_sbtype(d->d_sb));
36885 + return file; /* success */
36889 + file = ERR_PTR(err);
36894 + * create a new xinofile at the same place/path as @base.
36896 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
36897 + struct file *copy_src)
36899 + struct file *file;
36900 + struct dentry *dentry;
36901 + struct inode *dir, *delegated;
36902 + struct qstr *name;
36903 + struct path ppath, path;
36904 + int err, do_unlock;
36905 + struct au_xino_lock_dir ldir;
36908 + au_xino_lock_dir(sb, base, &ldir);
36909 + dentry = base->dentry;
36910 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
36911 + ppath.mnt = base->mnt;
36912 + dir = d_inode(ppath.dentry);
36915 + name = &dentry->d_name;
36916 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
36917 + if (IS_ERR(path.dentry)) {
36918 + file = (void *)path.dentry;
36919 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
36923 + /* no need to mnt_want_write() since we call dentry_open() later */
36924 + err = vfs_create(dir, path.dentry, 0666, NULL);
36925 + if (unlikely(err)) {
36926 + file = ERR_PTR(err);
36927 + pr_err("%pd create err %d\n", dentry, err);
36931 + path.mnt = base->mnt;
36932 + file = vfsub_dentry_open(&path,
36933 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
36934 + /* | __FMODE_NONOTIFY */);
36935 + if (IS_ERR(file)) {
36936 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
36940 + delegated = NULL;
36941 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
36942 + au_xino_unlock_dir(&ldir);
36944 + if (unlikely(err == -EWOULDBLOCK)) {
36945 + pr_warn("cannot retry for NFSv4 delegation"
36946 + " for an internal unlink\n");
36949 + if (unlikely(err)) {
36950 + pr_err("%pd unlink err %d\n", dentry, err);
36955 + /* no one can touch copy_src xino */
36956 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
36957 + if (unlikely(err)) {
36958 + pr_err("%pd copy err %d\n", dentry, err);
36962 + goto out_dput; /* success */
36966 + file = ERR_PTR(err);
36968 + dput(path.dentry);
36971 + au_xino_unlock_dir(&ldir);
36975 +struct file *au_xino_file1(struct au_xino *xi)
36977 + struct file *file;
36978 + unsigned int u, nfile;
36981 + nfile = xi->xi_nfile;
36982 + for (u = 0; u < nfile; u++) {
36983 + file = xi->xi_file[u];
36991 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37002 + if (idx < xi->xi_nfile) {
37003 + f = xi->xi_file[idx];
37007 + p = au_kzrealloc(xi->xi_file,
37008 + sizeof(*xi->xi_file) * xi->xi_nfile,
37009 + sizeof(*xi->xi_file) * (idx + 1),
37010 + GFP_NOFS, /*may_shrink*/0);
37012 + MtxMustLock(&xi->xi_mtx);
37014 + xi->xi_nfile = idx + 1;
37022 + xi->xi_file[idx] = file;
37029 + * if @xinew->xi is not set, then create new xigen file.
37031 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37033 + struct file *file;
37036 + SiMustAnyLock(sb);
37038 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37039 + if (IS_ERR(file)) {
37040 + err = PTR_ERR(file);
37041 + pr_err("%s[%d], err %d\n",
37042 + xinew->xi ? "xino" : "xigen",
37043 + xinew->idx, err);
37048 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37051 + /* todo: make xigen file an array */
37052 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37055 + if (unlikely(err))
37056 + file = ERR_PTR(err);
37062 +/* ---------------------------------------------------------------------- */
37065 + * truncate xino files
37067 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37068 + int idx, struct kstatfs *st)
37072 + struct file *file, *new_xino;
37073 + struct au_xi_new xinew = {
37078 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37079 + file = au_xino_file(xinew.xi, idx);
37083 + xinew.base = &file->f_path;
37084 + err = vfs_statfs(xinew.base, st);
37085 + if (unlikely(err)) {
37086 + AuErr1("statfs err %d, ignored\n", err);
37091 + blocks = file_inode(file)->i_blocks;
37092 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37093 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37095 + xinew.copy_src = file;
37096 + new_xino = au_xi_new(sb, &xinew);
37097 + if (IS_ERR(new_xino)) {
37098 + err = PTR_ERR(new_xino);
37099 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37103 + err = vfs_statfs(&new_xino->f_path, st);
37105 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37106 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37107 + st->f_bfree, st->f_blocks);
37109 + AuErr1("statfs err %d, ignored\n", err);
37117 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37120 + unsigned long jiffy;
37121 + aufs_bindex_t bbot;
37122 + struct kstatfs *st;
37123 + struct au_branch *br;
37124 + struct au_xino *xi;
37127 + st = kmalloc(sizeof(*st), GFP_NOFS);
37128 + if (unlikely(!st))
37132 + bbot = au_sbbot(sb);
37133 + if (unlikely(bindex < 0 || bbot < bindex))
37138 + br = au_sbr(sb, bindex);
37139 + xi = br->br_xino;
37140 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37141 + err = au_xino_do_trunc(sb, bindex, i, st);
37143 + au_sbi(sb)->si_xino_jiffy = jiffy;
37146 + au_kfree_rcu(st);
37151 +struct xino_do_trunc_args {
37152 + struct super_block *sb;
37153 + struct au_branch *br;
37157 +static void xino_do_trunc(void *_args)
37159 + struct xino_do_trunc_args *args = _args;
37160 + struct super_block *sb;
37161 + struct au_branch *br;
37162 + struct inode *dir;
37164 + aufs_bindex_t bindex;
37168 + dir = d_inode(sb->s_root);
37172 + si_noflush_write_lock(sb);
37173 + ii_read_lock_parent(dir);
37174 + bindex = au_br_index(sb, br->br_id);
37175 + err = au_xino_trunc(sb, bindex, idx);
37176 + ii_read_unlock(dir);
37177 + if (unlikely(err))
37178 + pr_warn("err b%d, (%d)\n", bindex, err);
37179 + atomic_dec(&br->br_xino->xi_truncating);
37180 + au_lcnt_dec(&br->br_count);
37181 + si_write_unlock(sb);
37182 + au_nwt_done(&au_sbi(sb)->si_nowait);
37183 + au_kfree_rcu(args);
37187 + * returns the index in the xi_file array whose corresponding file is necessary
37188 + * to truncate, or -1 which means no need to truncate.
37190 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37194 + struct kstatfs st;
37195 + struct au_sbinfo *sbinfo;
37196 + struct au_xino *xi;
37197 + struct file *file;
37199 + /* todo: si_xino_expire and the ratio should be customizable */
37200 + sbinfo = au_sbi(sb);
37201 + if (time_before(jiffies,
37202 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37205 + /* truncation border */
37206 + xi = br->br_xino;
37207 + for (u = 0; u < xi->xi_nfile; u++) {
37208 + file = au_xino_file(xi, u);
37212 + err = vfs_statfs(&file->f_path, &st);
37213 + if (unlikely(err)) {
37214 + AuErr1("statfs err %d, ignored\n", err);
37217 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37218 + >= AUFS_XINO_DEF_TRUNC)
37225 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37228 + struct xino_do_trunc_args *args;
37231 + idx = xino_trunc_test(sb, br);
37235 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37238 + /* lock and kfree() will be called in trunc_xino() */
37239 + args = kmalloc(sizeof(*args), GFP_NOFS);
37240 + if (unlikely(!args)) {
37241 + AuErr1("no memory\n");
37245 + au_lcnt_inc(&br->br_count);
37249 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37251 + return; /* success */
37253 + pr_err("wkq %d\n", wkq_err);
37254 + au_lcnt_dec(&br->br_count);
37255 + au_kfree_rcu(args);
37258 + atomic_dec(&br->br_xino->xi_truncating);
37261 +/* ---------------------------------------------------------------------- */
37263 +struct au_xi_calc {
37268 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37269 + struct au_xi_calc *calc)
37273 + maxent = au_xi_maxent(sb);
37274 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37275 + calc->pos *= sizeof(ino_t);
37278 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37279 + struct au_xi_calc *calc)
37282 + struct file *file;
37283 + struct au_xino *xi = br->br_xino;
37284 + struct au_xi_new xinew = {
37288 + SiMustAnyLock(sb);
37294 + mutex_lock(&xi->xi_mtx);
37295 + file = au_xino_file(xi, calc->idx);
37299 + file = au_xino_file(xi, /*idx*/-1);
37300 + AuDebugOn(!file);
37301 + xinew.idx = calc->idx;
37302 + xinew.base = &file->f_path;
37303 + /* xinew.copy_src = NULL; */
37304 + file = au_xi_new(sb, &xinew);
37305 + if (IS_ERR(file))
37306 + err = PTR_ERR(file);
37309 + mutex_unlock(&xi->xi_mtx);
37314 +struct au_xino_do_new_async_args {
37315 + struct super_block *sb;
37316 + struct au_branch *br;
37317 + struct au_xi_calc calc;
37321 +struct au_xi_writing {
37322 + struct hlist_bl_node node;
37323 + ino_t h_ino, ino;
37326 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37329 +static void au_xino_call_do_new_async(void *args)
37331 + struct au_xino_do_new_async_args *a = args;
37332 + struct au_branch *br;
37333 + struct super_block *sb;
37334 + struct au_sbinfo *sbi;
37335 + struct inode *root;
37336 + struct file *file;
37337 + struct au_xi_writing *del, *p;
37338 + struct hlist_bl_head *hbl;
37339 + struct hlist_bl_node *pos;
37344 + sbi = au_sbi(sb);
37345 + si_noflush_read_lock(sb);
37346 + root = d_inode(sb->s_root);
37347 + ii_read_lock_child(root);
37348 + err = au_xino_do_new_async(sb, br, &a->calc);
37349 + if (unlikely(err)) {
37350 + AuIOErr("err %d\n", err);
37354 + file = au_xino_file(br->br_xino, a->calc.idx);
37355 + AuDebugOn(!file);
37356 + err = au_xino_do_write(file, &a->calc, a->ino);
37357 + if (unlikely(err)) {
37358 + AuIOErr("err %d\n", err);
37363 + hbl = &br->br_xino->xi_writing;
37364 + hlist_bl_lock(hbl);
37365 + au_hbl_for_each(pos, hbl) {
37366 + p = container_of(pos, struct au_xi_writing, node);
37367 + if (p->ino == a->ino) {
37369 + hlist_bl_del(&p->node);
37373 + hlist_bl_unlock(hbl);
37374 + au_kfree_rcu(del);
37377 + au_lcnt_dec(&br->br_count);
37378 + ii_read_unlock(root);
37379 + si_read_unlock(sb);
37380 + au_nwt_done(&sbi->si_nowait);
37385 + * create a new xino file asynchronously
37387 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37388 + struct au_xi_calc *calc, ino_t ino)
37391 + struct au_xino_do_new_async_args *arg;
37394 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37395 + if (unlikely(!arg))
37400 + arg->calc = *calc;
37402 + au_lcnt_inc(&br->br_count);
37403 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37404 + if (unlikely(err)) {
37405 + pr_err("wkq %d\n", err);
37406 + au_lcnt_dec(&br->br_count);
37407 + au_kfree_rcu(arg);
37415 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37416 + * at the position of @h_ino.
37418 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37423 + struct au_xi_calc calc;
37424 + struct au_sbinfo *sbinfo;
37425 + struct file *file;
37426 + struct au_xino *xi;
37427 + struct hlist_bl_head *hbl;
37428 + struct hlist_bl_node *pos;
37429 + struct au_xi_writing *p;
37432 + if (!au_opt_test(au_mntflags(sb), XINO))
37433 + return 0; /* no xino */
37436 + au_xi_calc(sb, h_ino, &calc);
37437 + xi = au_sbr(sb, bindex)->br_xino;
37438 + file = au_xino_file(xi, calc.idx);
37440 + hbl = &xi->xi_writing;
37441 + hlist_bl_lock(hbl);
37442 + au_hbl_for_each(pos, hbl) {
37443 + p = container_of(pos, struct au_xi_writing, node);
37444 + if (p->h_ino == h_ino) {
37445 + AuDbg("hi%llu, i%llu, found\n",
37446 + (u64)p->h_ino, (u64)p->ino);
37451 + hlist_bl_unlock(hbl);
37453 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37454 + return 0; /* no xino */
37456 + sbinfo = au_sbi(sb);
37457 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37458 + if (sz == sizeof(*ino))
37459 + return 0; /* success */
37462 + if (unlikely(sz >= 0)) {
37464 + AuIOErr("xino read error (%zd)\n", sz);
37469 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37474 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37475 + if (sz == sizeof(ino))
37476 + return 0; /* success */
37478 + AuIOErr("write failed (%zd)\n", sz);
37483 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37484 + * at the position of @h_ino.
37485 + * even if @ino is zero, it is written to the xinofile and means no entry.
37486 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37487 + * try truncating it.
37489 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37493 + unsigned int mnt_flags;
37494 + struct au_xi_calc calc;
37495 + struct file *file;
37496 + struct au_branch *br;
37497 + struct au_xino *xi;
37498 + struct au_xi_writing *p;
37500 + SiMustAnyLock(sb);
37502 + mnt_flags = au_mntflags(sb);
37503 + if (!au_opt_test(mnt_flags, XINO))
37506 + au_xi_calc(sb, h_ino, &calc);
37507 + br = au_sbr(sb, bindex);
37508 + xi = br->br_xino;
37509 + file = au_xino_file(xi, calc.idx);
37511 + /* store the inum pair into the list */
37512 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37513 + p->h_ino = h_ino;
37515 + au_hbl_add(&p->node, &xi->xi_writing);
37517 + /* create and write a new xino file asynchronously */
37518 + err = au_xino_new_async(sb, br, &calc, ino);
37520 + return 0; /* success */
37524 + err = au_xino_do_write(file, &calc, ino);
37526 + br = au_sbr(sb, bindex);
37527 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37528 + && au_test_fs_trunc_xino(au_br_sb(br)))
37529 + xino_try_trunc(sb, br);
37530 + return 0; /* success */
37534 + AuIOErr("write failed (%d)\n", err);
37538 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37541 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37542 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37546 + const int prevent_endless = 10;
37550 + err = vfsub_read_k(file, kbuf, size, pos);
37551 + if (err == -EINTR
37552 + && !au_wkq_test()
37553 + && fatal_signal_pending(current)) {
37554 + err = xino_fread_wkq(file, kbuf, size, pos);
37555 + BUG_ON(err == -EINTR);
37557 + } while (i++ < prevent_endless
37558 + && (err == -EAGAIN || err == -EINTR));
37560 +#if 0 /* reserved for future use */
37562 + fsnotify_access(file->f_path.dentry);
37568 +struct xino_fread_args {
37570 + struct file *file;
37576 +static void call_xino_fread(void *args)
37578 + struct xino_fread_args *a = args;
37579 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
37582 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37587 + struct xino_fread_args args = {
37595 + wkq_err = au_wkq_wait(call_xino_fread, &args);
37596 + if (unlikely(wkq_err))
37602 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37605 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
37610 + const int prevent_endless = 10;
37614 + err = vfsub_write_k(file, kbuf, size, pos);
37615 + if (err == -EINTR
37616 + && !au_wkq_test()
37617 + && fatal_signal_pending(current)) {
37618 + err = xino_fwrite_wkq(file, kbuf, size, pos);
37619 + BUG_ON(err == -EINTR);
37621 + } while (i++ < prevent_endless
37622 + && (err == -EAGAIN || err == -EINTR));
37624 +#if 0 /* reserved for future use */
37626 + fsnotify_modify(file->f_path.dentry);
37632 +struct do_xino_fwrite_args {
37634 + struct file *file;
37640 +static void call_do_xino_fwrite(void *args)
37642 + struct do_xino_fwrite_args *a = args;
37643 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
37646 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
37651 + struct do_xino_fwrite_args args = {
37660 + * it breaks RLIMIT_FSIZE and normal user's limit,
37661 + * users should care about quota and real 'filesystem full.'
37663 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
37664 + if (unlikely(wkq_err))
37670 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
37674 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
37676 + err = do_xino_fwrite(file, buf, size, pos);
37680 + err = xino_fwrite_wkq(file, buf, size, pos);
37687 +/* ---------------------------------------------------------------------- */
37690 + * inode number bitmap
37692 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
37693 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
37697 + AuDebugOn(bit < 0 || page_bits <= bit);
37698 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
37702 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
37704 + AuDebugOn(ino < AUFS_FIRST_INO);
37705 + ino -= AUFS_FIRST_INO;
37706 + *pindex = ino / page_bits;
37707 + *bit = ino % page_bits;
37710 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
37715 + struct au_sbinfo *sbinfo;
37716 + struct file *xib;
37717 + unsigned long *p;
37719 + sbinfo = au_sbi(sb);
37720 + MtxMustLock(&sbinfo->si_xib_mtx);
37721 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
37722 + || !au_opt_test(sbinfo->si_mntflags, XINO));
37724 + if (pindex == sbinfo->si_xib_last_pindex)
37727 + xib = sbinfo->si_xib;
37728 + p = sbinfo->si_xib_buf;
37729 + pos = sbinfo->si_xib_last_pindex;
37730 + pos *= PAGE_SIZE;
37731 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37732 + if (unlikely(sz != PAGE_SIZE))
37736 + pos *= PAGE_SIZE;
37737 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
37738 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
37740 + memset(p, 0, PAGE_SIZE);
37741 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
37743 + if (sz == PAGE_SIZE) {
37744 + sbinfo->si_xib_last_pindex = pindex;
37745 + return 0; /* success */
37749 + AuIOErr1("write failed (%zd)\n", sz);
37756 +static void au_xib_clear_bit(struct inode *inode)
37759 + unsigned long pindex;
37760 + struct super_block *sb;
37761 + struct au_sbinfo *sbinfo;
37763 + AuDebugOn(inode->i_nlink);
37765 + sb = inode->i_sb;
37766 + xib_calc_bit(inode->i_ino, &pindex, &bit);
37767 + AuDebugOn(page_bits <= bit);
37768 + sbinfo = au_sbi(sb);
37769 + mutex_lock(&sbinfo->si_xib_mtx);
37770 + err = xib_pindex(sb, pindex);
37772 + clear_bit(bit, sbinfo->si_xib_buf);
37773 + sbinfo->si_xib_next_bit = bit;
37775 + mutex_unlock(&sbinfo->si_xib_mtx);
37778 +/* ---------------------------------------------------------------------- */
37781 + * truncate a xino bitmap file
37785 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
37789 + unsigned long pindex;
37790 + loff_t pos, pend;
37791 + struct au_sbinfo *sbinfo;
37793 + unsigned long *p;
37796 + sbinfo = au_sbi(sb);
37797 + MtxMustLock(&sbinfo->si_xib_mtx);
37798 + p = sbinfo->si_xib_buf;
37799 + pend = vfsub_f_size_read(file);
37801 + while (pos < pend) {
37802 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
37804 + if (unlikely(sz <= 0))
37808 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
37809 + if (unlikely(*ino < AUFS_FIRST_INO))
37812 + xib_calc_bit(*ino, &pindex, &bit);
37813 + AuDebugOn(page_bits <= bit);
37814 + err = xib_pindex(sb, pindex);
37826 +static int xib_restore(struct super_block *sb)
37829 + unsigned int nfile;
37830 + aufs_bindex_t bindex, bbot;
37832 + struct au_branch *br;
37833 + struct au_xino *xi;
37834 + struct file *file;
37837 + page = (void *)__get_free_page(GFP_NOFS);
37838 + if (unlikely(!page))
37842 + bbot = au_sbbot(sb);
37843 + for (bindex = 0; !err && bindex <= bbot; bindex++)
37844 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
37845 + br = au_sbr(sb, bindex);
37846 + xi = br->br_xino;
37847 + nfile = xi->xi_nfile;
37848 + for (i = 0; i < nfile; i++) {
37849 + file = au_xino_file(xi, i);
37851 + err = do_xib_restore(sb, file, page);
37854 + AuDbg("skip shared b%d\n", bindex);
37855 + free_page((unsigned long)page);
37861 +int au_xib_trunc(struct super_block *sb)
37866 + struct au_sbinfo *sbinfo;
37867 + unsigned long *p;
37868 + struct file *file;
37870 + SiMustWriteLock(sb);
37873 + sbinfo = au_sbi(sb);
37874 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
37877 + file = sbinfo->si_xib;
37878 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
37881 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
37882 + err = PTR_ERR(file);
37883 + if (IS_ERR(file))
37885 + fput(sbinfo->si_xib);
37886 + sbinfo->si_xib = file;
37888 + p = sbinfo->si_xib_buf;
37889 + memset(p, 0, PAGE_SIZE);
37891 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
37892 + if (unlikely(sz != PAGE_SIZE)) {
37894 + AuIOErr("err %d\n", err);
37900 + mutex_lock(&sbinfo->si_xib_mtx);
37901 + /* mnt_want_write() is unnecessary here */
37902 + err = xib_restore(sb);
37903 + mutex_unlock(&sbinfo->si_xib_mtx);
37909 +/* ---------------------------------------------------------------------- */
37911 +struct au_xino *au_xino_alloc(unsigned int nfile)
37913 + struct au_xino *xi;
37915 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
37916 + if (unlikely(!xi))
37918 + xi->xi_nfile = nfile;
37919 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
37920 + if (unlikely(!xi->xi_file))
37923 + xi->xi_nondir.total = 8; /* initial size */
37924 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
37926 + if (unlikely(!xi->xi_nondir.array))
37929 + spin_lock_init(&xi->xi_nondir.spin);
37930 + init_waitqueue_head(&xi->xi_nondir.wqh);
37931 + mutex_init(&xi->xi_mtx);
37932 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
37933 + atomic_set(&xi->xi_truncating, 0);
37934 + kref_init(&xi->xi_kref);
37935 + goto out; /* success */
37938 + au_kfree_try_rcu(xi->xi_file);
37940 + au_kfree_rcu(xi);
37946 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
37949 + struct au_xino *xi;
37952 + xi = au_xino_alloc(idx + 1);
37953 + if (unlikely(!xi)) {
37960 + xi->xi_file[idx] = file;
37961 + AuDebugOn(br->br_xino);
37962 + br->br_xino = xi;
37968 +static void au_xino_release(struct kref *kref)
37970 + struct au_xino *xi;
37972 + unsigned long ul;
37973 + struct hlist_bl_head *hbl;
37974 + struct hlist_bl_node *pos, *n;
37975 + struct au_xi_writing *p;
37977 + xi = container_of(kref, struct au_xino, xi_kref);
37978 + for (i = 0; i < xi->xi_nfile; i++)
37979 + if (xi->xi_file[i])
37980 + fput(xi->xi_file[i]);
37981 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
37982 + AuDebugOn(xi->xi_nondir.array[i]);
37983 + mutex_destroy(&xi->xi_mtx);
37984 + hbl = &xi->xi_writing;
37985 + ul = au_hbl_count(hbl);
37986 + if (unlikely(ul)) {
37987 + pr_warn("xi_writing %lu\n", ul);
37988 + hlist_bl_lock(hbl);
37989 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
37990 + hlist_bl_del(&p->node);
37991 + /* kmemleak reported au_kfree_rcu() doesn't free it */
37994 + hlist_bl_unlock(hbl);
37996 + au_kfree_try_rcu(xi->xi_file);
37997 + au_kfree_try_rcu(xi->xi_nondir.array);
37998 + au_kfree_rcu(xi);
38001 +int au_xino_put(struct au_branch *br)
38004 + struct au_xino *xi;
38007 + xi = br->br_xino;
38009 + br->br_xino = NULL;
38010 + ret = kref_put(&xi->xi_kref, au_xino_release);
38016 +/* ---------------------------------------------------------------------- */
38019 + * xino mount option handlers
38023 +static void xino_clear_xib(struct super_block *sb)
38025 + struct au_sbinfo *sbinfo;
38027 + SiMustWriteLock(sb);
38029 + sbinfo = au_sbi(sb);
38030 + if (sbinfo->si_xib)
38031 + fput(sbinfo->si_xib);
38032 + sbinfo->si_xib = NULL;
38033 + if (sbinfo->si_xib_buf)
38034 + free_page((unsigned long)sbinfo->si_xib_buf);
38035 + sbinfo->si_xib_buf = NULL;
38038 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38042 + struct au_sbinfo *sbinfo;
38043 + struct file *file;
38044 + struct super_block *xi_sb;
38046 + SiMustWriteLock(sb);
38048 + sbinfo = au_sbi(sb);
38049 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38050 + err = PTR_ERR(file);
38051 + if (IS_ERR(file))
38053 + if (sbinfo->si_xib)
38054 + fput(sbinfo->si_xib);
38055 + sbinfo->si_xib = file;
38056 + xi_sb = file_inode(file)->i_sb;
38057 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38058 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38060 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38061 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38064 + sbinfo->si_ximaxent /= sizeof(ino_t);
38067 + if (!sbinfo->si_xib_buf)
38068 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38069 + if (unlikely(!sbinfo->si_xib_buf))
38072 + sbinfo->si_xib_last_pindex = 0;
38073 + sbinfo->si_xib_next_bit = 0;
38074 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38076 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38077 + if (unlikely(err != PAGE_SIZE))
38081 + goto out; /* success */
38084 + if (sbinfo->si_xib_buf)
38085 + free_page((unsigned long)sbinfo->si_xib_buf);
38086 + sbinfo->si_xib_buf = NULL;
38090 + fput(sbinfo->si_xib);
38091 + sbinfo->si_xib = NULL;
38097 +/* xino for each branch */
38098 +static void xino_clear_br(struct super_block *sb)
38100 + aufs_bindex_t bindex, bbot;
38101 + struct au_branch *br;
38103 + bbot = au_sbbot(sb);
38104 + for (bindex = 0; bindex <= bbot; bindex++) {
38105 + br = au_sbr(sb, bindex);
38111 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38112 + aufs_bindex_t bshared)
38114 + struct au_branch *brshared;
38116 + brshared = au_sbr(sb, bshared);
38117 + AuDebugOn(!brshared->br_xino);
38118 + AuDebugOn(!brshared->br_xino->xi_file);
38119 + if (br->br_xino != brshared->br_xino) {
38120 + au_xino_get(brshared);
38122 + br->br_xino = brshared->br_xino;
38126 +struct au_xino_do_set_br {
38127 + struct au_branch *br;
38129 + aufs_bindex_t bshared;
38132 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38133 + struct au_xino_do_set_br *args)
38136 + struct au_xi_calc calc;
38137 + struct file *file;
38138 + struct au_branch *br;
38139 + struct au_xi_new xinew = {
38144 + xinew.xi = br->br_xino;
38145 + au_xi_calc(sb, args->h_ino, &calc);
38146 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38147 + if (args->bshared >= 0)
38148 + /* shared xino */
38149 + au_xino_set_br_shared(sb, br, args->bshared);
38150 + else if (!xinew.xi) {
38152 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38153 + if (unlikely(err))
38157 + /* force re-creating */
38158 + xinew.xi = br->br_xino;
38159 + xinew.idx = calc.idx;
38160 + mutex_lock(&xinew.xi->xi_mtx);
38161 + file = au_xi_new(sb, &xinew);
38162 + mutex_unlock(&xinew.xi->xi_mtx);
38163 + err = PTR_ERR(file);
38164 + if (IS_ERR(file))
38166 + AuDebugOn(!file);
38168 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38169 + if (unlikely(err))
38177 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38180 + aufs_bindex_t bindex, bbot;
38181 + struct au_xino_do_set_br args;
38182 + struct inode *inode;
38184 + SiMustWriteLock(sb);
38186 + bbot = au_sbbot(sb);
38187 + inode = d_inode(sb->s_root);
38188 + for (bindex = 0; bindex <= bbot; bindex++) {
38189 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38190 + args.br = au_sbr(sb, bindex);
38191 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38192 + err = au_xino_do_set_br(sb, path, &args);
38193 + if (unlikely(err))
38201 +void au_xino_clr(struct super_block *sb)
38203 + struct au_sbinfo *sbinfo;
38205 + au_xigen_clr(sb);
38206 + xino_clear_xib(sb);
38207 + xino_clear_br(sb);
38208 + dbgaufs_brs_del(sb, 0);
38209 + sbinfo = au_sbi(sb);
38210 + /* lvalue, do not call au_mntflags() */
38211 + au_opt_clr(sbinfo->si_mntflags, XINO);
38214 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38217 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38218 + struct qstr *dname, *cur_name;
38219 + struct file *cur_xino;
38220 + struct au_sbinfo *sbinfo;
38221 + struct path *path, *cur_path;
38223 + SiMustWriteLock(sb);
38226 + sbinfo = au_sbi(sb);
38227 + path = &xiopt->file->f_path;
38228 + dentry = path->dentry;
38229 + parent = dget_parent(dentry);
38232 + cur_xino = sbinfo->si_xib;
38234 + cur_path = &cur_xino->f_path;
38235 + cur_dentry = cur_path->dentry;
38236 + cur_parent = dget_parent(cur_dentry);
38237 + cur_name = &cur_dentry->d_name;
38238 + dname = &dentry->d_name;
38239 + skip = (cur_parent == parent
38240 + && au_qstreq(dname, cur_name));
38241 + dput(cur_parent);
38247 + au_opt_set(sbinfo->si_mntflags, XINO);
38248 + err = au_xino_set_xib(sb, path);
38249 + /* si_x{read,write} are set */
38251 + err = au_xigen_set(sb, path);
38253 + err = au_xino_set_br(sb, path);
38255 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38256 + goto out; /* success */
38260 + AuIOErr("failed setting xino(%d).\n", err);
38269 + * create a xinofile at the default place/path.
38271 +struct file *au_xino_def(struct super_block *sb)
38273 + struct file *file;
38275 + struct au_branch *br;
38276 + struct super_block *h_sb;
38277 + struct path path;
38278 + aufs_bindex_t bbot, bindex, bwr;
38281 + bbot = au_sbbot(sb);
38283 + for (bindex = 0; bindex <= bbot; bindex++) {
38284 + br = au_sbr(sb, bindex);
38285 + if (au_br_writable(br->br_perm)
38286 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38293 + file = ERR_PTR(-ENOMEM);
38294 + page = (void *)__get_free_page(GFP_NOFS);
38295 + if (unlikely(!page))
38297 + path.mnt = au_br_mnt(br);
38298 + path.dentry = au_h_dptr(sb->s_root, bwr);
38299 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38300 + file = (void *)p;
38301 + if (!IS_ERR(p)) {
38302 + strcat(p, "/" AUFS_XINO_FNAME);
38303 + AuDbg("%s\n", p);
38304 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38306 + free_page((unsigned long)page);
38308 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38310 + if (IS_ERR(file))
38312 + h_sb = file->f_path.dentry->d_sb;
38313 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38314 + pr_err("xino doesn't support %s(%s)\n",
38315 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38317 + file = ERR_PTR(-EINVAL);
38325 +/* ---------------------------------------------------------------------- */
38328 + * initialize the xinofile for the specified branch @br
38329 + * at the place/path where @base_file indicates.
38330 + * test whether another branch is on the same filesystem or not,
38331 + * if found then share the xinofile with another branch.
38333 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38334 + struct path *base)
38337 + struct au_xino_do_set_br args = {
38342 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38344 + err = au_xino_do_set_br(sb, base, &args);
38345 + if (unlikely(err))
38351 +/* ---------------------------------------------------------------------- */
38354 + * get an unused inode number from bitmap
38356 +ino_t au_xino_new_ino(struct super_block *sb)
38359 + unsigned long *p, pindex, ul, pend;
38360 + struct au_sbinfo *sbinfo;
38361 + struct file *file;
38362 + int free_bit, err;
38364 + if (!au_opt_test(au_mntflags(sb), XINO))
38365 + return iunique(sb, AUFS_FIRST_INO);
38367 + sbinfo = au_sbi(sb);
38368 + mutex_lock(&sbinfo->si_xib_mtx);
38369 + p = sbinfo->si_xib_buf;
38370 + free_bit = sbinfo->si_xib_next_bit;
38371 + if (free_bit < page_bits && !test_bit(free_bit, p))
38372 + goto out; /* success */
38373 + free_bit = find_first_zero_bit(p, page_bits);
38374 + if (free_bit < page_bits)
38375 + goto out; /* success */
38377 + pindex = sbinfo->si_xib_last_pindex;
38378 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38379 + err = xib_pindex(sb, ul);
38380 + if (unlikely(err))
38382 + free_bit = find_first_zero_bit(p, page_bits);
38383 + if (free_bit < page_bits)
38384 + goto out; /* success */
38387 + file = sbinfo->si_xib;
38388 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38389 + for (ul = pindex + 1; ul <= pend; ul++) {
38390 + err = xib_pindex(sb, ul);
38391 + if (unlikely(err))
38393 + free_bit = find_first_zero_bit(p, page_bits);
38394 + if (free_bit < page_bits)
38395 + goto out; /* success */
38400 + set_bit(free_bit, p);
38401 + sbinfo->si_xib_next_bit = free_bit + 1;
38402 + pindex = sbinfo->si_xib_last_pindex;
38403 + mutex_unlock(&sbinfo->si_xib_mtx);
38404 + ino = xib_calc_ino(pindex, free_bit);
38405 + AuDbg("i%lu\n", (unsigned long)ino);
38408 + mutex_unlock(&sbinfo->si_xib_mtx);
38413 +/* for s_op->delete_inode() */
38414 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38417 + unsigned int mnt_flags;
38418 + aufs_bindex_t bindex, bbot, bi;
38419 + unsigned char try_trunc;
38420 + struct au_iinfo *iinfo;
38421 + struct super_block *sb;
38422 + struct au_hinode *hi;
38423 + struct inode *h_inode;
38424 + struct au_branch *br;
38425 + struct au_xi_calc calc;
38426 + struct file *file;
38428 + AuDebugOn(au_is_bad_inode(inode));
38430 + sb = inode->i_sb;
38431 + mnt_flags = au_mntflags(sb);
38432 + if (!au_opt_test(mnt_flags, XINO)
38433 + || inode->i_ino == AUFS_ROOT_INO)
38437 + au_xigen_inc(inode);
38438 + au_xib_clear_bit(inode);
38441 + iinfo = au_ii(inode);
38442 + bindex = iinfo->ii_btop;
38446 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38447 + hi = au_hinode(iinfo, bindex);
38448 + bbot = iinfo->ii_bbot;
38449 + for (; bindex <= bbot; bindex++, hi++) {
38450 + h_inode = hi->hi_inode;
38452 + || (!unlinked && h_inode->i_nlink))
38455 + /* inode may not be revalidated */
38456 + bi = au_br_index(sb, hi->hi_id);
38460 + br = au_sbr(sb, bi);
38461 + au_xi_calc(sb, h_inode->i_ino, &calc);
38462 + file = au_xino_file(br->br_xino, calc.idx);
38463 + if (IS_ERR_OR_NULL(file))
38466 + err = au_xino_do_write(file, &calc, /*ino*/0);
38467 + if (!err && try_trunc
38468 + && au_test_fs_trunc_xino(au_br_sb(br)))
38469 + xino_try_trunc(sb, br);
38473 +/* ---------------------------------------------------------------------- */
38475 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38477 + int found, total, i;
38480 + total = xi->xi_nondir.total;
38481 + for (i = 0; i < total; i++) {
38482 + if (xi->xi_nondir.array[i] != h_ino)
38491 +static int au_xinondir_expand(struct au_xino *xi)
38496 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38499 + sz = xi->xi_nondir.total * sizeof(ino_t);
38500 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38502 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38503 + /*may_shrink*/0);
38505 + xi->xi_nondir.array = p;
38506 + xi->xi_nondir.total <<= 1;
38507 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38515 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38516 + ino_t h_ino, int idx)
38518 + struct au_xino *xi;
38520 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38521 + xi = au_sbr(sb, bindex)->br_xino;
38522 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38524 + spin_lock(&xi->xi_nondir.spin);
38525 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38526 + xi->xi_nondir.array[idx] = 0;
38527 + spin_unlock(&xi->xi_nondir.spin);
38528 + wake_up_all(&xi->xi_nondir.wqh);
38531 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38534 + int err, found, empty;
38535 + struct au_xino *xi;
38539 + if (!au_opt_test(au_mntflags(sb), XINO))
38540 + goto out; /* no xino */
38542 + xi = au_sbr(sb, bindex)->br_xino;
38545 + spin_lock(&xi->xi_nondir.spin);
38546 + found = au_xinondir_find(xi, h_ino);
38547 + if (found == -1) {
38548 + empty = au_xinondir_find(xi, /*h_ino*/0);
38549 + if (empty == -1) {
38550 + empty = xi->xi_nondir.total;
38551 + err = au_xinondir_expand(xi);
38552 + if (unlikely(err))
38555 + xi->xi_nondir.array[empty] = h_ino;
38558 + spin_unlock(&xi->xi_nondir.spin);
38559 + wait_event(xi->xi_nondir.wqh,
38560 + xi->xi_nondir.array[found] != h_ino);
38565 + spin_unlock(&xi->xi_nondir.spin);
38570 +/* ---------------------------------------------------------------------- */
38572 +int au_xino_path(struct seq_file *seq, struct file *file)
38576 + err = au_seq_path(seq, &file->f_path);
38577 + if (unlikely(err))
38580 +#define Deleted "\\040(deleted)"
38581 + seq->count -= sizeof(Deleted) - 1;
38582 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
38583 + sizeof(Deleted) - 1));
38589 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
38590 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
38591 +++ linux/include/uapi/linux/aufs_type.h 2021-12-03 15:38:59.943313977 +0100
38593 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
38595 + * Copyright (C) 2005-2021 Junjiro R. Okajima
38597 + * This program, aufs is free software; you can redistribute it and/or modify
38598 + * it under the terms of the GNU General Public License as published by
38599 + * the Free Software Foundation; either version 2 of the License, or
38600 + * (at your option) any later version.
38602 + * This program is distributed in the hope that it will be useful,
38603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38605 + * GNU General Public License for more details.
38607 + * You should have received a copy of the GNU General Public License
38608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
38611 +#ifndef __AUFS_TYPE_H__
38612 +#define __AUFS_TYPE_H__
38614 +#define AUFS_NAME "aufs"
38618 + * define it before including all other headers.
38619 + * sched.h may use pr_* macros before defining "current", so define the
38620 + * no-current version first, and re-define later.
38622 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
38623 +#include <linux/sched.h>
38625 +#define pr_fmt(fmt) \
38626 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
38627 + (int)sizeof(current->comm), current->comm, current->pid
38628 +#include <linux/limits.h>
38630 +#include <stdint.h>
38631 +#include <sys/types.h>
38632 +#include <limits.h>
38633 +#endif /* __KERNEL__ */
38635 +#define AUFS_VERSION "5.10.82-20211129"
38637 +/* todo? move this to linux-2.6.19/include/magic.h */
38638 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
38640 +/* ---------------------------------------------------------------------- */
38643 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
38644 +typedef int8_t aufs_bindex_t;
38645 +#define AUFS_BRANCH_MAX 127
38647 +typedef int16_t aufs_bindex_t;
38648 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
38649 +#define AUFS_BRANCH_MAX 511
38650 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
38651 +#define AUFS_BRANCH_MAX 1023
38652 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
38653 +#define AUFS_BRANCH_MAX 32767
38657 +#ifndef AUFS_BRANCH_MAX
38658 +#error unknown CONFIG_AUFS_BRANCH_MAX value
38660 +#endif /* __KERNEL__ */
38662 +/* ---------------------------------------------------------------------- */
38664 +#define AUFS_FSTYPE AUFS_NAME
38666 +#define AUFS_ROOT_INO 2
38667 +#define AUFS_FIRST_INO 11
38669 +#define AUFS_WH_PFX ".wh."
38670 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
38671 +#define AUFS_WH_TMP_LEN 4
38672 +/* a limit for rmdir/rename a dir and copyup */
38673 +#define AUFS_MAX_NAMELEN (NAME_MAX \
38674 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
38676 + - AUFS_WH_TMP_LEN) /* hex */
38677 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
38678 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
38679 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
38680 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
38681 +#define AUFS_DIRWH_DEF 3
38682 +#define AUFS_RDCACHE_DEF 10 /* seconds */
38683 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
38684 +#define AUFS_RDBLK_DEF 512 /* bytes */
38685 +#define AUFS_RDHASH_DEF 32
38686 +#define AUFS_WKQ_NAME AUFS_NAME "d"
38687 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
38688 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
38689 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
38690 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
38692 +/* pseudo-link maintenace under /proc */
38693 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
38694 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
38695 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
38697 +/* dirren, renamed dir */
38698 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
38699 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
38700 +/* whiteouted doubly */
38701 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
38702 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
38704 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
38705 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
38707 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
38708 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
38709 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
38711 +/* doubly whiteouted */
38712 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
38713 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
38714 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
38716 +/* branch permissions and attributes */
38717 +#define AUFS_BRPERM_RW "rw"
38718 +#define AUFS_BRPERM_RO "ro"
38719 +#define AUFS_BRPERM_RR "rr"
38720 +#define AUFS_BRATTR_COO_REG "coo_reg"
38721 +#define AUFS_BRATTR_COO_ALL "coo_all"
38722 +#define AUFS_BRATTR_FHSM "fhsm"
38723 +#define AUFS_BRATTR_UNPIN "unpin"
38724 +#define AUFS_BRATTR_ICEX "icex"
38725 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
38726 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
38727 +#define AUFS_BRATTR_ICEX_TR "icextr"
38728 +#define AUFS_BRATTR_ICEX_USR "icexusr"
38729 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
38730 +#define AUFS_BRRATTR_WH "wh"
38731 +#define AUFS_BRWATTR_NLWH "nolwh"
38732 +#define AUFS_BRWATTR_MOO "moo"
38734 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
38735 +#define AuBrPerm_RO (1 << 1) /* readonly */
38736 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
38737 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
38739 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
38740 +#define AuBrAttr_COO_ALL (1 << 4)
38741 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
38743 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
38744 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
38745 + branch. meaningless since
38746 + linux-3.18-rc1 */
38748 +/* ignore error in copying XATTR */
38749 +#define AuBrAttr_ICEX_SEC (1 << 7)
38750 +#define AuBrAttr_ICEX_SYS (1 << 8)
38751 +#define AuBrAttr_ICEX_TR (1 << 9)
38752 +#define AuBrAttr_ICEX_USR (1 << 10)
38753 +#define AuBrAttr_ICEX_OTH (1 << 11)
38754 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
38755 + | AuBrAttr_ICEX_SYS \
38756 + | AuBrAttr_ICEX_TR \
38757 + | AuBrAttr_ICEX_USR \
38758 + | AuBrAttr_ICEX_OTH)
38760 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
38761 +#define AuBrRAttr_Mask AuBrRAttr_WH
38763 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
38764 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
38765 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
38767 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
38769 +/* #warning test userspace */
38771 +#ifndef CONFIG_AUFS_FHSM
38772 +#undef AuBrAttr_FHSM
38773 +#define AuBrAttr_FHSM 0
38775 +#ifndef CONFIG_AUFS_XATTR
38776 +#undef AuBrAttr_ICEX
38777 +#define AuBrAttr_ICEX 0
38778 +#undef AuBrAttr_ICEX_SEC
38779 +#define AuBrAttr_ICEX_SEC 0
38780 +#undef AuBrAttr_ICEX_SYS
38781 +#define AuBrAttr_ICEX_SYS 0
38782 +#undef AuBrAttr_ICEX_TR
38783 +#define AuBrAttr_ICEX_TR 0
38784 +#undef AuBrAttr_ICEX_USR
38785 +#define AuBrAttr_ICEX_USR 0
38786 +#undef AuBrAttr_ICEX_OTH
38787 +#define AuBrAttr_ICEX_OTH 0
38791 +/* the longest combination */
38792 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
38793 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
38794 + "+" AUFS_BRATTR_COO_REG \
38795 + "+" AUFS_BRATTR_FHSM \
38796 + "+" AUFS_BRATTR_UNPIN \
38797 + "+" AUFS_BRATTR_ICEX_SEC \
38798 + "+" AUFS_BRATTR_ICEX_SYS \
38799 + "+" AUFS_BRATTR_ICEX_USR \
38800 + "+" AUFS_BRATTR_ICEX_OTH \
38801 + "+" AUFS_BRWATTR_NLWH)
38804 + char a[AuBrPermStrSz];
38805 +} au_br_perm_str_t;
38807 +static inline int au_br_writable(int brperm)
38809 + return brperm & AuBrPerm_RW;
38812 +static inline int au_br_whable(int brperm)
38814 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
38817 +static inline int au_br_wh_linkable(int brperm)
38819 + return !(brperm & AuBrWAttr_NoLinkWH);
38822 +static inline int au_br_cmoo(int brperm)
38824 + return brperm & AuBrAttr_CMOO_Mask;
38827 +static inline int au_br_fhsm(int brperm)
38829 + return brperm & AuBrAttr_FHSM;
38832 +/* ---------------------------------------------------------------------- */
38836 + /* readdir in userspace */
38840 + AuCtl_WBR_FD, /* pathconf wrapper */
38841 + AuCtl_IBUSY, /* busy inode */
38842 + AuCtl_MVDOWN, /* move-down */
38843 + AuCtl_BR, /* info about branches */
38844 + AuCtl_FHSM_FD /* connection for fhsm */
38847 +/* borrowed from linux/include/linux/kernel.h */
38849 +#ifdef _GNU_SOURCE
38850 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
38852 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
38854 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
38857 +/* borrowed from linux/include/linux/compiler-gcc3.h */
38859 +#define __aligned(x) __attribute__((aligned(x)))
38864 +#define __packed __attribute__((packed))
38868 +struct au_rdu_cookie {
38873 + uint32_t generation;
38876 +struct au_rdu_ent {
38885 +static inline int au_rdu_len(int nlen)
38887 + /* include the terminating NULL */
38888 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
38889 + sizeof(uint64_t));
38892 +union au_rdu_ent_ul {
38893 + struct au_rdu_ent __user *e;
38905 + uint64_t sz; /* AuCtl_RDU */
38906 + uint64_t nent; /* AuCtl_RDU_INO */
38908 + union au_rdu_ent_ul ent;
38909 + uint16_t verify[AufsCtlRduV_End];
38911 + /* input/output */
38915 + union au_rdu_ent_ul tail;
38916 + /* number of entries which were added in a single call */
38921 + struct au_rdu_cookie cookie;
38924 +/* ---------------------------------------------------------------------- */
38926 +/* dirren. the branch is identified by the filename who contains this */
38927 +struct au_drinfo {
38930 + uint8_t oldnamelen;
38931 + uint64_t _padding;
38933 + uint8_t oldname[];
38936 +struct au_drinfo_fdata {
38938 + struct au_drinfo drinfo;
38941 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
38943 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
38945 +/* ---------------------------------------------------------------------- */
38947 +struct aufs_wbr_fd {
38952 +/* ---------------------------------------------------------------------- */
38954 +struct aufs_ibusy {
38955 + uint64_t ino, h_ino;
38959 +/* ---------------------------------------------------------------------- */
38961 +/* error code for move-down */
38962 +/* the actual message strings are implemented in aufs-util.git */
38964 + EAU_MVDOWN_OPAQUE = 1,
38965 + EAU_MVDOWN_WHITEOUT,
38966 + EAU_MVDOWN_UPPER,
38967 + EAU_MVDOWN_BOTTOM,
38968 + EAU_MVDOWN_NOUPPER,
38969 + EAU_MVDOWN_NOLOWERBR,
38973 +/* flags for move-down */
38974 +#define AUFS_MVDOWN_DMSG 1
38975 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
38976 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
38977 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
38978 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
38979 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
38980 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
38981 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
38982 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
38983 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
38984 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
38985 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
38986 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
38988 +/* index for move-down */
38990 + AUFS_MVDOWN_UPPER,
38991 + AUFS_MVDOWN_LOWER,
38992 + AUFS_MVDOWN_NARRAY
38996 + * additional info of move-down
38997 + * number of free blocks and inodes.
38998 + * subset of struct kstatfs, but smaller and always 64bit.
39000 +struct aufs_stfs {
39001 + uint64_t f_blocks;
39002 + uint64_t f_bavail;
39003 + uint64_t f_files;
39004 + uint64_t f_ffree;
39007 +struct aufs_stbr {
39008 + int16_t brid; /* optional input */
39009 + int16_t bindex; /* output */
39010 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39013 +struct aufs_mvdown {
39014 + uint32_t flags; /* input/output */
39015 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39016 + int8_t au_errno; /* output */
39019 +/* ---------------------------------------------------------------------- */
39021 +union aufs_brinfo {
39022 + /* PATH_MAX may differ between kernel-space and user-space */
39023 + char _spacer[4096];
39031 +/* ---------------------------------------------------------------------- */
39033 +#define AuCtlType 'A'
39034 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39035 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39036 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39037 + struct aufs_wbr_fd)
39038 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39039 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39040 + struct aufs_mvdown)
39041 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39042 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39044 +#endif /* __AUFS_TYPE_H__ */
39045 SPDX-License-Identifier: GPL-2.0
39046 aufs5.10.82 loopback patch
39048 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39049 index d09b1ef4a2b56..ee27ab8e34898 100644
39050 --- a/drivers/block/loop.c
39051 +++ b/drivers/block/loop.c
39052 @@ -637,6 +637,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39056 +static struct file *loop_real_file(struct file *file)
39058 + struct file *f = NULL;
39060 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39061 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39065 static void loop_reread_partitions(struct loop_device *lo,
39066 struct block_device *bdev)
39068 @@ -692,6 +701,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39071 struct file *file = NULL, *old_file;
39072 + struct file *f, *virt_file = NULL, *old_virt_file;
39076 @@ -711,12 +721,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39080 + f = loop_real_file(file);
39082 + virt_file = file;
39087 error = loop_validate_file(file, bdev);
39091 old_file = lo->lo_backing_file;
39092 + old_virt_file = lo->lo_backing_virt_file;
39096 @@ -728,6 +745,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39097 blk_mq_freeze_queue(lo->lo_queue);
39098 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39099 lo->lo_backing_file = file;
39100 + lo->lo_backing_virt_file = virt_file;
39101 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39102 mapping_set_gfp_mask(file->f_mapping,
39103 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39104 @@ -741,6 +759,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39108 + if (old_virt_file)
39109 + fput(old_virt_file);
39111 loop_reread_partitions(lo, bdev);
39113 @@ -749,6 +769,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39114 mutex_unlock(&loop_ctl_mutex);
39122 @@ -1077,7 +1099,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39123 struct block_device *bdev,
39124 const struct loop_config *config)
39126 - struct file *file;
39127 + struct file *file, *f, *virt_file = NULL;
39128 struct inode *inode;
39129 struct address_space *mapping;
39130 struct block_device *claimed_bdev = NULL;
39131 @@ -1093,6 +1115,12 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39132 file = fget(config->fd);
39135 + f = loop_real_file(file);
39137 + virt_file = file;
39143 * If we don't hold exclusive handle for the device, upgrade to it
39144 @@ -1148,6 +1176,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39145 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39146 lo->lo_device = bdev;
39147 lo->lo_backing_file = file;
39148 + lo->lo_backing_virt_file = virt_file;
39149 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39150 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39152 @@ -1202,6 +1231,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39153 bd_abort_claiming(bdev, claimed_bdev, loop_configure);
39159 /* This is safe: open() is still holding a reference. */
39160 module_put(THIS_MODULE);
39161 @@ -1211,6 +1242,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39162 static int __loop_clr_fd(struct loop_device *lo, bool release)
39164 struct file *filp = NULL;
39165 + struct file *virt_filp = lo->lo_backing_virt_file;
39166 gfp_t gfp = lo->old_gfp_mask;
39167 struct block_device *bdev = lo->lo_device;
39169 @@ -1237,6 +1269,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39171 spin_lock_irq(&lo->lo_lock);
39172 lo->lo_backing_file = NULL;
39173 + lo->lo_backing_virt_file = NULL;
39174 spin_unlock_irq(&lo->lo_lock);
39176 loop_release_xfer(lo);
39177 @@ -1320,6 +1353,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
39186 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
39187 index af75a5ee40944..1d847cb194ff6 100644
39188 --- a/drivers/block/loop.h
39189 +++ b/drivers/block/loop.h
39190 @@ -46,7 +46,7 @@ struct loop_device {
39191 int (*ioctl)(struct loop_device *, int cmd,
39192 unsigned long arg);
39194 - struct file * lo_backing_file;
39195 + struct file *lo_backing_file, *lo_backing_virt_file;
39196 struct block_device *lo_device;
39199 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39200 index 99ceca1440449..e49dfe8550329 100644
39201 --- a/fs/aufs/f_op.c
39202 +++ b/fs/aufs/f_op.c
39203 @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39204 if (IS_ERR(h_file))
39207 - if (au_test_loopback_kthread()) {
39208 + if (0 && au_test_loopback_kthread()) {
39209 au_warn_loopback(h_file->f_path.dentry->d_sb);
39210 if (file->f_mapping != h_file->f_mapping) {
39211 file->f_mapping = h_file->f_mapping;
39212 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39213 index 74347bd75b380..5ef888a1d53f4 100644
39214 --- a/fs/aufs/loop.c
39215 +++ b/fs/aufs/loop.c
39216 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39217 symbol_put(loop_backing_file);
39218 au_kfree_try_rcu(au_warn_loopback_array);
39221 +/* ---------------------------------------------------------------------- */
39223 +/* support the loopback block device insude aufs */
39225 +struct file *aufs_real_loop(struct file *file)
39229 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39230 + fi_read_lock(file);
39231 + f = au_hf_top(file);
39232 + fi_read_unlock(file);
39236 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39237 index 7293bee427f96..3345c098d0d47 100644
39238 --- a/fs/aufs/loop.h
39239 +++ b/fs/aufs/loop.h
39240 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39242 int au_loopback_init(void);
39243 void au_loopback_fin(void);
39245 +struct file *aufs_real_loop(struct file *file);
39247 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39249 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39251 AuStubInt0(au_loopback_init, void)
39252 AuStubVoid(au_loopback_fin, void)
39254 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39255 #endif /* BLK_DEV_LOOP */
39257 #endif /* __KERNEL__ */
39258 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39259 index 8e2d8464dac0e..ab6e940aac7ab 100644
39260 --- a/fs/aufs/super.c
39261 +++ b/fs/aufs/super.c
39262 @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
39263 .statfs = aufs_statfs,
39264 .put_super = aufs_put_super,
39265 .sync_fs = aufs_sync_fs,
39266 - .remount_fs = aufs_remount_fs
39267 + .remount_fs = aufs_remount_fs,
39268 +#ifdef CONFIG_AUFS_BDEV_LOOP
39269 + .real_loop = aufs_real_loop
39273 /* ---------------------------------------------------------------------- */
39274 diff --git a/include/linux/fs.h b/include/linux/fs.h
39275 index 2cc1a02e444c4..e53241a43d244 100644
39276 --- a/include/linux/fs.h
39277 +++ b/include/linux/fs.h
39278 @@ -1967,6 +1967,10 @@ struct super_operations {
39279 struct shrink_control *);
39280 long (*free_cached_objects)(struct super_block *,
39281 struct shrink_control *);
39282 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39284 + struct file *(*real_loop)(struct file *);