1 SPDX-License-Identifier: GPL-2.0
2 aufs6.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index a46b0cbc4d8f..d90a3b0dbc53 100644
8 @@ -337,6 +337,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 6ecc9b0a53f2..255420c2676e 100644
20 @@ -129,3 +129,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 aufs6.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index aa3b947fb080..fb7020b24f7c 100644
32 @@ -3396,6 +3396,19 @@ F: kernel/audit*
34 K: \baudit_[a-z_0-9]\+\b
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
50 M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
51 R: Dave Ertman <david.m.ertman@intel.com>
52 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
53 index 28a95fd366fe..6bd18fb1e53a 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -641,6 +641,26 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +/* Just to make the compiler silence, declare it */
65 +struct file *loop_backing_file(struct super_block *sb);
66 +struct file *loop_backing_file(struct super_block *sb)
69 + struct loop_device *l;
72 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
73 + l = sb->s_bdev->bd_disk->private_data;
74 + ret = l->lo_backing_file;
78 +EXPORT_SYMBOL_GPL(loop_backing_file);
80 /* loop sysfs attributes */
82 static ssize_t loop_attr_show(struct device *dev, char *page,
83 diff --git a/fs/dcache.c b/fs/dcache.c
84 index 71a8e943a0fa..13afe5474f86 100644
87 @@ -1211,6 +1211,9 @@ enum d_walk_ret {
91 +/* AUFS calls d_walk(). Just to make the compiler silence, declare it */
92 +void d_walk(struct dentry *parent, void *data,
93 + enum d_walk_ret (*enter)(void *, struct dentry *));
95 * d_walk - walk the dentry tree
96 * @parent: start of walk
97 @@ -1219,7 +1222,7 @@ enum d_walk_ret {
99 * The @enter() callbacks are called with d_lock held.
101 -static void d_walk(struct dentry *parent, void *data,
102 +void d_walk(struct dentry *parent, void *data,
103 enum d_walk_ret (*enter)(void *, struct dentry *))
105 struct dentry *this_parent, *dentry;
106 diff --git a/fs/fcntl.c b/fs/fcntl.c
107 index 54cc85d3338e..5dcfe97a5ba5 100644
112 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
114 -static int setfl(int fd, struct file * filp, unsigned int arg)
115 +int setfl(int fd, struct file * filp, unsigned int arg)
117 struct inode * inode = file_inode(filp);
119 @@ -65,6 +65,8 @@ static int setfl(int fd, struct file * filp, unsigned int arg)
121 if (filp->f_op->check_flags)
122 error = filp->f_op->check_flags(arg);
123 + if (!error && filp->f_op->setfl)
124 + error = filp->f_op->setfl(filp, arg);
128 diff --git a/fs/namespace.c b/fs/namespace.c
129 index 5a51315c6678..a4b6ce51848e 100644
132 @@ -860,6 +860,12 @@ static inline int check_mnt(struct mount *mnt)
133 return mnt->mnt_ns == current->nsproxy->mnt_ns;
136 +/* for aufs, CONFIG_AUFS_BR_FUSE */
137 +int is_current_mnt_ns(struct vfsmount *mnt)
139 + return check_mnt(real_mount(mnt));
143 * vfsmount lock must be held for write
145 diff --git a/fs/splice.c b/fs/splice.c
146 index 218e24b1ac40..7210ddc5aa81 100644
149 @@ -933,7 +933,7 @@ static int warn_unsupported(struct file *file, const char *op)
151 * Attempt to initiate a splice from pipe to file.
153 -static ssize_t do_splice_from(struct pipe_inode_info *pipe, struct file *out,
154 +ssize_t do_splice_from(struct pipe_inode_info *pipe, struct file *out,
155 loff_t *ppos, size_t len, unsigned int flags)
157 if (unlikely(!out->f_op->splice_write))
158 diff --git a/include/linux/fs.h b/include/linux/fs.h
159 index 00fc429b0af0..b3a73aed62b8 100644
160 --- a/include/linux/fs.h
161 +++ b/include/linux/fs.h
162 @@ -1113,6 +1113,7 @@ extern void fasync_free(struct fasync_struct *);
163 /* can be called from interrupts */
164 extern void kill_fasync(struct fasync_struct **, int, int);
166 +extern int setfl(int fd, struct file *filp, unsigned int arg);
167 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
168 extern int f_setown(struct file *filp, int who, int force);
169 extern void f_delown(struct file *filp);
170 @@ -2024,6 +2025,7 @@ struct file_operations {
171 int (*lock) (struct file *, int, struct file_lock *);
172 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
173 int (*check_flags)(int);
174 + int (*setfl)(struct file *, unsigned long);
175 int (*flock) (struct file *, int, struct file_lock *);
176 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
177 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
178 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
179 index 08b0d1d9d78b..009f69c4e09d 100644
180 --- a/include/linux/lockdep.h
181 +++ b/include/linux/lockdep.h
182 @@ -192,6 +192,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
183 return lock->key == key;
186 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
191 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
192 index 8f882f5881e8..6b9808f09843 100644
193 --- a/include/linux/mnt_namespace.h
194 +++ b/include/linux/mnt_namespace.h
195 @@ -7,12 +7,15 @@ struct mnt_namespace;
197 struct user_namespace;
201 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
202 struct user_namespace *, struct fs_struct *);
203 extern void put_mnt_ns(struct mnt_namespace *ns);
204 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
206 +extern int is_current_mnt_ns(struct vfsmount *mnt);
208 extern const struct file_operations proc_mounts_operations;
209 extern const struct file_operations proc_mountinfo_operations;
210 extern const struct file_operations proc_mountstats_operations;
211 diff --git a/include/linux/splice.h b/include/linux/splice.h
212 index 9dec4861d09f..14583d846864 100644
213 --- a/include/linux/splice.h
214 +++ b/include/linux/splice.h
215 @@ -108,4 +108,7 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
217 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
218 extern const struct pipe_buf_operations default_pipe_buf_ops;
220 +extern ssize_t do_splice_from(struct pipe_inode_info *pipe, struct file *out,
221 + loff_t *ppos, size_t len, unsigned int flags);
223 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
224 index 151bd3de5936..2223ee909c10 100644
225 --- a/kernel/locking/lockdep.c
226 +++ b/kernel/locking/lockdep.c
227 @@ -218,7 +218,7 @@ unsigned long max_lock_class_idx;
228 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
229 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
231 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
232 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
234 unsigned int class_idx = hlock->class_idx;
236 @@ -239,6 +239,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
238 return lock_classes + class_idx;
240 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
242 #ifdef CONFIG_LOCK_STAT
243 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
244 SPDX-License-Identifier: GPL-2.0
245 aufs6.x-rcN mmap patch
247 diff --git a/fs/proc/base.c b/fs/proc/base.c
248 index 18550c071d71..560be8fb4fca 100644
251 @@ -2213,7 +2213,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
253 vma = find_exact_vma(mm, vm_start, vm_end);
254 if (vma && vma->vm_file) {
255 - *path = *file_user_path(vma->vm_file);
256 + *path = vma_pr_or_file(vma)->f_path;
260 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
261 index c6e7ebc63756..d7ccfd909764 100644
262 --- a/fs/proc/nommu.c
263 +++ b/fs/proc/nommu.c
264 @@ -39,7 +39,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
265 file = region->vm_file;
268 - struct inode *inode = file_inode(region->vm_file);
269 + struct inode *inode;
271 + file = vmr_pr_or_file(region);
272 + inode = file_inode(file);
273 dev = inode->i_sb->s_dev;
276 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
277 index 23fbab954c20..6faced8ef8fe 100644
278 --- a/fs/proc/task_mmu.c
279 +++ b/fs/proc/task_mmu.c
280 @@ -273,7 +273,8 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
281 const char *name = NULL;
284 - const struct inode *inode = file_user_inode(vma->vm_file);
285 + const struct inode *inode
286 + = file_inode(file = vma_pr_or_file(vma));
288 dev = inode->i_sb->s_dev;
290 @@ -2700,7 +2701,7 @@ static int show_numa_map(struct seq_file *m, void *v)
291 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
292 struct vm_area_struct *vma = v;
293 struct numa_maps *md = &numa_priv->md;
294 - struct file *file = vma->vm_file;
295 + struct file *file = vma_pr_or_file(vma);
296 struct mm_struct *mm = vma->vm_mm;
298 struct mempolicy *pol;
299 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
300 index bce674533000..b12b5a75c799 100644
301 --- a/fs/proc/task_nommu.c
302 +++ b/fs/proc/task_nommu.c
303 @@ -137,7 +137,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
307 - struct inode *inode = file_inode(vma->vm_file);
308 + struct inode *inode;
310 + file = vma_pr_or_file(vma);
311 + inode = file_inode(file);
312 dev = inode->i_sb->s_dev;
314 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
315 diff --git a/include/linux/mm.h b/include/linux/mm.h
316 index 0436b919f1c7..a04c7dde4bc2 100644
317 --- a/include/linux/mm.h
318 +++ b/include/linux/mm.h
319 @@ -2452,6 +2452,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
320 static inline struct vm_area_struct *vma_lookup(struct mm_struct *mm,
323 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
324 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
325 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
327 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
328 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
330 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
332 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
334 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
335 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
338 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
339 +extern void vmr_do_fput(struct vm_region *, const char[], int);
341 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
343 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
344 +#endif /* !CONFIG_MMU */
348 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
349 +#define vma_pr_or_file(vma) (vma)->vm_file
350 +#define vma_get_file(vma) get_file((vma)->vm_file)
351 +#define vma_fput(vma) fput((vma)->vm_file)
354 +#define vmr_pr_or_file(region) (region)->vm_file
355 +#define vmr_fput(region) fput((region)->vm_file)
356 +#endif /* !CONFIG_MMU */
358 +#endif /* CONFIG_AUFS_FS */
360 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
361 void *buf, int len, unsigned int gup_flags);
362 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
363 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
364 index 5240bd7bca33..f91323e92ef9 100644
365 --- a/include/linux/mm_types.h
366 +++ b/include/linux/mm_types.h
367 @@ -555,6 +555,9 @@ struct vm_region {
368 unsigned long vm_top; /* region allocated to here */
369 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
370 struct file *vm_file; /* the backing file or NULL */
371 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
372 + struct file *vm_prfile; /* the virtual backing file or NULL */
375 int vm_usage; /* region usage count (access under nommu_region_sem) */
376 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
377 @@ -719,6 +722,9 @@ struct vm_area_struct {
378 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
380 struct file * vm_file; /* File we map to (can be NULL). */
381 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
382 + struct file *vm_prfile; /* shadow of vm_file */
384 void * vm_private_data; /* was vm_pte (shared mem) */
386 #ifdef CONFIG_ANON_VMA_NAME
387 diff --git a/kernel/fork.c b/kernel/fork.c
388 index 39a5046c2f0b..478a22f5f367 100644
391 @@ -718,7 +718,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
393 struct address_space *mapping = file->f_mapping;
397 i_mmap_lock_write(mapping);
398 if (vma_is_shared_maywrite(tmp))
399 mapping_allow_writable(mapping);
400 diff --git a/mm/Makefile b/mm/Makefile
401 index e4b5b75aaec9..2ec2544009fb 100644
404 @@ -134,3 +134,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
405 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
406 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
407 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
409 diff --git a/mm/filemap.c b/mm/filemap.c
410 index 7437b2bd75c1..cecf1956f7a9 100644
413 @@ -3631,7 +3631,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
414 vm_fault_t ret = VM_FAULT_LOCKED;
416 sb_start_pagefault(mapping->host->i_sb);
417 - file_update_time(vmf->vma->vm_file);
418 + vma_file_update_time(vmf->vma);
420 if (folio->mapping != mapping) {
422 diff --git a/mm/mmap.c b/mm/mmap.c
423 index 6dbda99a47da..8610432aa357 100644
426 @@ -140,7 +140,7 @@ static void remove_vma(struct vm_area_struct *vma, bool unreachable)
427 if (vma->vm_ops && vma->vm_ops->close)
428 vma->vm_ops->close(vma);
430 - fput(vma->vm_file);
432 mpol_put(vma_policy(vma));
435 @@ -557,7 +557,7 @@ static inline void vma_complete(struct vma_prepare *vp,
437 uprobe_munmap(vp->remove, vp->remove->vm_start,
442 if (vp->remove->anon_vma)
443 anon_vma_merge(vp->vma, vp->remove);
444 @@ -2361,7 +2361,7 @@ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
448 - get_file(new->vm_file);
451 if (new->vm_ops && new->vm_ops->open)
452 new->vm_ops->open(new);
453 @@ -2854,7 +2854,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
454 * and cause general protection fault
457 - fput(vma->vm_file);
461 /* Update vm_flags to pick up the change. */
462 @@ -2940,7 +2940,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
464 if (file || vma->vm_file) {
466 - fput(vma->vm_file);
470 vma_iter_set(&vmi, vma->vm_end);
471 @@ -3002,6 +3002,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
472 unsigned long populate = 0;
473 unsigned long ret = -EINVAL;
475 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
476 + struct file *prfile;
479 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
480 current->comm, current->pid);
481 @@ -3060,10 +3063,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
482 if (vma->vm_flags & VM_LOCKED)
485 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
487 + file = vma->vm_file;
488 + prfile = vma->vm_prfile;
489 + ret = do_mmap(vma->vm_file, start, size,
490 + prot, flags, /*vm_flags*/0, pgoff, &populate, NULL);
491 + if (!IS_ERR_VALUE(ret) && file && prfile) {
492 + struct vm_area_struct *new_vma;
494 + new_vma = find_vma(mm, ret);
495 + if (!new_vma->vm_prfile)
496 + new_vma->vm_prfile = prfile;
501 + * two fput()s instead of vma_fput(vma),
502 + * coz vma may not be available anymore.
508 file = get_file(vma->vm_file);
509 ret = do_mmap(vma->vm_file, start, size,
510 prot, flags, 0, pgoff, &populate, NULL);
512 +#endif /* CONFIG_AUFS_FS */
514 mmap_write_unlock(mm);
516 @@ -3406,7 +3433,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
517 if (anon_vma_clone(new_vma, vma))
518 goto out_free_mempol;
519 if (new_vma->vm_file)
520 - get_file(new_vma->vm_file);
521 + vma_get_file(new_vma);
522 if (new_vma->vm_ops && new_vma->vm_ops->open)
523 new_vma->vm_ops->open(new_vma);
524 if (vma_link(mm, new_vma))
525 @@ -3420,7 +3447,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
526 new_vma->vm_ops->close(new_vma);
528 if (new_vma->vm_file)
529 - fput(new_vma->vm_file);
532 unlink_anon_vmas(new_vma);
534 diff --git a/mm/nommu.c b/mm/nommu.c
535 index 5ec8f44e7ce9..efda87a7f99a 100644
538 @@ -521,7 +521,7 @@ static void __put_nommu_region(struct vm_region *region)
539 up_write(&nommu_region_sem);
542 - fput(region->vm_file);
545 /* IO memory and memory shared directly out of the pagecache
546 * from ramfs/tmpfs mustn't be released here */
547 @@ -601,7 +601,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
548 if (vma->vm_ops && vma->vm_ops->close)
549 vma->vm_ops->close(vma);
551 - fput(vma->vm_file);
553 put_nommu_region(vma->vm_region);
556 @@ -1133,7 +1133,7 @@ unsigned long do_mmap(struct file *file,
557 goto error_just_free;
560 - fput(region->vm_file);
562 kmem_cache_free(vm_region_jar, region);
565 @@ -1219,10 +1219,10 @@ unsigned long do_mmap(struct file *file,
569 - fput(region->vm_file);
571 kmem_cache_free(vm_region_jar, region);
573 - fput(vma->vm_file);
578 diff --git a/mm/prfile.c b/mm/prfile.c
580 index 000000000000..8f820a235364
584 +// SPDX-License-Identifier: GPL-2.0
586 + * Mainly for aufs which mmap(2) different file and wants to print different
587 + * path in /proc/PID/maps.
588 + * Call these functions via macros defined in linux/mm.h.
590 + * See Documentation/filesystems/aufs/design/06mmap.txt
592 + * Copyright (c) 2014-2022 Junjro R. Okajima
593 + * Copyright (c) 2014 Ian Campbell
596 +#include <linux/mm.h>
597 +#include <linux/file.h>
598 +#include <linux/fs.h>
600 +/* #define PRFILE_TRACE */
601 +static inline void prfile_trace(struct file *f, struct file *pr,
602 + const char func[], int line, const char func2[])
606 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
610 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
613 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
615 + prfile_trace(f, pr, func, line, __func__);
616 + file_update_time(f);
618 + file_update_time(pr);
621 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
624 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
626 + prfile_trace(f, pr, func, line, __func__);
627 + return (f && pr) ? pr : f;
630 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
640 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
642 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
644 + prfile_trace(f, pr, func, line, __func__);
651 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
654 + struct file *f = region->vm_file, *pr = region->vm_prfile;
656 + prfile_trace(f, pr, func, line, __func__);
657 + return (f && pr) ? pr : f;
660 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
662 + struct file *f = region->vm_file, *pr = region->vm_prfile;
664 + prfile_trace(f, pr, func, line, __func__);
669 +#endif /* !CONFIG_MMU */
670 SPDX-License-Identifier: GPL-2.0
671 aufs6.x-rcN standalone patch
673 diff --git a/fs/dcache.c b/fs/dcache.c
674 index 13afe5474f86..05d9dab666bb 100644
677 @@ -1321,6 +1321,7 @@ void d_walk(struct dentry *parent, void *data,
681 +EXPORT_SYMBOL_GPL(d_walk);
684 struct vfsmount *mnt;
685 @@ -2883,6 +2884,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
687 write_sequnlock(&rename_lock);
689 +EXPORT_SYMBOL_GPL(d_exchange);
692 * d_ancestor - search for an ancestor
693 diff --git a/fs/exec.c b/fs/exec.c
694 index ff6f26671cfc..ea7aa14a730e 100644
697 @@ -113,6 +113,7 @@ bool path_noexec(const struct path *path)
698 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
699 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
701 +EXPORT_SYMBOL_GPL(path_noexec);
705 diff --git a/fs/fcntl.c b/fs/fcntl.c
706 index 5dcfe97a5ba5..48adde670824 100644
709 @@ -88,6 +88,7 @@ int setfl(int fd, struct file * filp, unsigned int arg)
713 +EXPORT_SYMBOL_GPL(setfl);
715 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
717 diff --git a/fs/file_table.c b/fs/file_table.c
718 index 4f03beed4737..1f0527dad5e1 100644
719 --- a/fs/file_table.c
720 +++ b/fs/file_table.c
721 @@ -221,6 +221,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
723 return ERR_PTR(-ENFILE);
725 +EXPORT_SYMBOL_GPL(alloc_empty_file);
728 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
729 diff --git a/fs/namespace.c b/fs/namespace.c
730 index a4b6ce51848e..c7415f75ab4c 100644
733 @@ -865,6 +865,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
735 return check_mnt(real_mount(mnt));
737 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
740 * vfsmount lock must be held for write
741 @@ -2053,6 +2054,7 @@ struct vfsmount *collect_mounts(const struct path *path)
742 return ERR_CAST(tree);
745 +EXPORT_SYMBOL_GPL(collect_mounts);
747 static void free_mnt_ns(struct mnt_namespace *);
748 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *, bool);
749 @@ -2083,6 +2085,7 @@ void drop_collected_mounts(struct vfsmount *mnt)
753 +EXPORT_SYMBOL_GPL(drop_collected_mounts);
755 static bool has_locked_children(struct mount *mnt, struct dentry *dentry)
757 @@ -2154,6 +2157,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
761 +EXPORT_SYMBOL_GPL(iterate_mounts);
763 static void lock_mnt_tree(struct mount *mnt)
765 diff --git a/fs/notify/group.c b/fs/notify/group.c
766 index 1de6631a3925..3008eb37a18d 100644
767 --- a/fs/notify/group.c
768 +++ b/fs/notify/group.c
769 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
771 refcount_inc(&group->refcnt);
773 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
776 * Drop a reference to a group. Free it if it's through.
777 diff --git a/fs/open.c b/fs/open.c
778 index ee8460c83c77..cb296bf7770f 100644
781 @@ -66,6 +66,7 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
782 inode_unlock(dentry->d_inode);
785 +EXPORT_SYMBOL_GPL(do_truncate);
787 long vfs_truncate(const struct path *path, loff_t length)
789 diff --git a/fs/read_write.c b/fs/read_write.c
790 index d4c036e82b6c..c61361ff5e67 100644
791 --- a/fs/read_write.c
792 +++ b/fs/read_write.c
793 @@ -483,6 +483,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
797 +EXPORT_SYMBOL_GPL(vfs_read);
799 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
801 @@ -598,6 +599,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
802 file_end_write(file);
805 +EXPORT_SYMBOL_GPL(vfs_write);
807 /* file_ppos returns &file->f_pos or NULL if file is stream */
808 static inline loff_t *file_ppos(struct file *file)
809 diff --git a/fs/splice.c b/fs/splice.c
810 index 7210ddc5aa81..9e83f46eacc8 100644
813 @@ -940,6 +940,7 @@ ssize_t do_splice_from(struct pipe_inode_info *pipe, struct file *out,
814 return warn_unsupported(out, "write");
815 return out->f_op->splice_write(pipe, out, ppos, len, flags);
817 +EXPORT_SYMBOL_GPL(do_splice_from);
820 * Indicate to the caller that there was a premature EOF when reading from the
821 diff --git a/fs/xattr.c b/fs/xattr.c
822 index f8b643f91a98..9a2d9b3aaf0a 100644
825 @@ -405,6 +405,7 @@ vfs_getxattr_alloc(struct mnt_idmap *idmap, struct dentry *dentry,
826 *xattr_value = value;
829 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
832 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
833 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
834 index 2223ee909c10..d0ac4fc69a31 100644
835 --- a/kernel/locking/lockdep.c
836 +++ b/kernel/locking/lockdep.c
837 @@ -239,6 +239,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
839 return lock_classes + class_idx;
841 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
842 #define hlock_class(hlock) lockdep_hlock_class(hlock)
844 #ifdef CONFIG_LOCK_STAT
845 diff --git a/kernel/task_work.c b/kernel/task_work.c
846 index 95a7e1b7f1da..5053670775d3 100644
847 --- a/kernel/task_work.c
848 +++ b/kernel/task_work.c
849 @@ -183,3 +183,4 @@ void task_work_run(void)
853 +EXPORT_SYMBOL_GPL(task_work_run);
854 diff --git a/security/security.c b/security/security.c
855 index 7e118858b545..4b5bbe8c6889 100644
856 --- a/security/security.c
857 +++ b/security/security.c
858 @@ -1840,6 +1840,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
860 return call_int_hook(path_rmdir, dir, dentry);
862 +EXPORT_SYMBOL_GPL(security_path_rmdir);
865 * security_path_unlink() - Check if removing a hard link is allowed
866 @@ -1875,6 +1876,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
868 return call_int_hook(path_symlink, dir, dentry, old_name);
870 +EXPORT_SYMBOL_GPL(security_path_symlink);
873 * security_path_link - Check if creating a hard link is allowed
874 @@ -1893,6 +1895,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
876 return call_int_hook(path_link, old_dentry, new_dir, new_dentry);
878 +EXPORT_SYMBOL_GPL(security_path_link);
881 * security_path_rename() - Check if renaming a file is allowed
882 @@ -1954,6 +1957,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
884 return call_int_hook(path_chmod, path, mode);
886 +EXPORT_SYMBOL_GPL(security_path_chmod);
889 * security_path_chown() - Check if changing the file's owner/group is allowed
890 @@ -1971,6 +1975,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
892 return call_int_hook(path_chown, path, uid, gid);
894 +EXPORT_SYMBOL_GPL(security_path_chown);
897 * security_path_chroot() - Check if changing the root directory is allowed
898 @@ -2215,6 +2220,7 @@ int security_inode_permission(struct inode *inode, int mask)
900 return call_int_hook(inode_permission, inode, mask);
902 +EXPORT_SYMBOL_GPL(security_inode_permission);
905 * security_inode_setattr() - Check if setting file attributes is allowed
906 @@ -2694,6 +2700,7 @@ int security_file_permission(struct file *file, int mask)
908 return call_int_hook(file_permission, file, mask);
910 +EXPORT_SYMBOL_GPL(security_file_permission);
913 * security_file_alloc() - Allocate and init a file's LSM blob
914 @@ -2996,6 +3003,7 @@ int security_file_truncate(struct file *file)
916 return call_int_hook(file_truncate, file);
918 +EXPORT_SYMBOL_GPL(security_file_truncate);
921 * security_task_alloc() - Allocate a task's LSM blob
922 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
923 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
924 +++ linux/Documentation/ABI/testing/debugfs-aufs 2024-05-13 17:13:00.614737564 +0200
926 +What: /debug/aufs/si_<id>/
928 +Contact: J. R. Okajima <hooanon05g@gmail.com>
930 + Under /debug/aufs, a directory named si_<id> is created
931 + per aufs mount, where <id> is a unique id generated
934 +What: /debug/aufs/si_<id>/plink
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + It has three lines and shows the information about the
939 + pseudo-link. The first line is a single number
940 + representing a number of buckets. The second line is a
941 + number of pseudo-links per buckets (separated by a
942 + blank). The last line is a single number representing a
943 + total number of psedo-links.
944 + When the aufs mount option 'noplink' is specified, it
945 + will show "1\n0\n0\n".
947 +What: /debug/aufs/si_<id>/xib
949 +Contact: J. R. Okajima <hooanon05g@gmail.com>
951 + It shows the consumed blocks by xib (External Inode Number
952 + Bitmap), its block size and file size.
953 + When the aufs mount option 'noxino' is specified, it
954 + will be empty. About XINO files, see the aufs manual.
956 +What: /debug/aufs/si_<id>/xi<branch-index>
958 +Contact: J. R. Okajima <hooanon05g@gmail.com>
960 + It shows the consumed blocks by xino (External Inode Number
961 + Translation Table), its link count, block size and file
963 + Due to the file size limit, there may exist multiple
964 + xino files per branch. In this case, "-N" is added to
965 + the filename and it corresponds to the index of the
966 + internal xino array. "-0" is omitted.
967 + When the aufs mount option 'noxino' is specified, Those
968 + entries won't exist. About XINO files, see the aufs
971 +What: /debug/aufs/si_<id>/xigen
973 +Contact: J. R. Okajima <hooanon05g@gmail.com>
975 + It shows the consumed blocks by xigen (External Inode
976 + Generation Table), its block size and file size.
977 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
979 + When the aufs mount option 'noxino' is specified, it
980 + will be empty. About XINO files, see the aufs manual.
981 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
982 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
983 +++ linux/Documentation/ABI/testing/sysfs-aufs 2024-05-13 17:13:00.614737564 +0200
985 +What: /sys/fs/aufs/si_<id>/
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + Under /sys/fs/aufs, a directory named si_<id> is created
990 + per aufs mount, where <id> is a unique id generated
993 +What: /sys/fs/aufs/si_<id>/br<idx>
995 +Contact: J. R. Okajima <hooanon05g@gmail.com>
997 + It shows the abolute path of a member directory (which
998 + is called branch) in aufs, and its permission.
1000 +What: /sys/fs/aufs/si_<id>/brid<idx>
1002 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1004 + It shows the id of a member directory (which is called
1007 +What: /sys/fs/aufs/si_<id>/xi_path
1009 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1011 + It shows the abolute path of XINO (External Inode Number
1012 + Bitmap, Translation Table and Generation Table) file
1013 + even if it is the default path.
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/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1017 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1018 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2024-05-13 17:13:00.614737564 +0200
1021 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1023 +# This program is free software; you can redistribute it and/or modify
1024 +# it under the terms of the GNU General Public License as published by
1025 +# the Free Software Foundation; either version 2 of the License, or
1026 +# (at your option) any later version.
1028 +# This program is distributed in the hope that it will be useful,
1029 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1030 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1031 +# GNU General Public License for more details.
1033 +# You should have received a copy of the GNU General Public License
1034 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1037 +----------------------------------------
1039 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1040 +1. abbrev. for "advanced multi-layered unification filesystem".
1041 +2. abbrev. for "another unionfs".
1042 +3. abbrev. for "auf das" in German which means "on the" in English.
1043 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1044 + But "Filesystem aufs Filesystem" is hard to understand.
1045 +4. abbrev. for "African Urban Fashion Show".
1047 +AUFS is a filesystem with features:
1048 +- multi layered stackable unification filesystem, the member directory
1049 + is called as a branch.
1050 +- branch permission and attribute, 'readonly', 'real-readonly',
1051 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1053 +- internal "file copy-on-write".
1054 +- logical deletion, whiteout.
1055 +- dynamic branch manipulation, adding, deleting and changing permission.
1056 +- allow bypassing aufs, user's direct branch access.
1057 +- external inode number translation table and bitmap which maintains the
1058 + persistent aufs inode number.
1059 +- seekable directory, including NFS readdir.
1060 +- file mapping, mmap and sharing pages.
1061 +- pseudo-link, hardlink over branches.
1062 +- loopback mounted filesystem as a branch.
1063 +- several policies to select one among multiple writable branches.
1064 +- revert a single systemcall when an error occurs in aufs.
1068 +Multi Layered Stackable Unification Filesystem
1069 +----------------------------------------------------------------------
1070 +Most people already knows what it is.
1071 +It is a filesystem which unifies several directories and provides a
1072 +merged single directory. When users access a file, the access will be
1073 +passed/re-directed/converted (sorry, I am not sure which English word is
1074 +correct) to the real file on the member filesystem. The member
1075 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1076 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1077 +readonly branch is handled by creating 'whiteout' on the upper writable
1080 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1081 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1082 +different approaches to implement the merged-view.
1083 +The former tries putting it into VFS, and the latter implements as a
1084 +separate filesystem.
1085 +(If I misunderstand about these implementations, please let me know and
1086 +I shall correct it. Because it is a long time ago when I read their
1087 +source files last time).
1089 +UnionMount's approach will be able to small, but may be hard to share
1090 +branches between several UnionMount since the whiteout in it is
1091 +implemented in the inode on branch filesystem and always
1092 +shared. According to Bharata's post, readdir does not seems to be
1094 +There are several missing features known in this implementations such as
1095 +- for users, the inode number may change silently. eg. copy-up.
1096 +- link(2) may break by copy-up.
1097 +- read(2) may get an obsoleted filedata (fstat(2) too).
1098 +- fcntl(F_SETLK) may be broken by copy-up.
1099 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1102 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1103 +merged into mainline. This is another implementation of UnionMount as a
1104 +separated filesystem. All the limitations and known problems which
1105 +UnionMount are equally inherited to "overlay" filesystem.
1107 +Unionfs has a longer history. When I started implementing a stackable
1108 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1109 +inode, dentry and file objects and they have an array pointing lower
1110 +same kind objects. After contributing many patches for Unionfs, I
1111 +re-started my project AUFS (Jun 2006).
1113 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1114 +implemented my own ideas, approaches and enhancements and it became
1115 +totally different one.
1117 +Comparing DM snapshot and fs based implementation
1118 +- the number of bytes to be copied between devices is much smaller.
1119 +- the type of filesystem must be one and only.
1120 +- the fs must be writable, no readonly fs, even for the lower original
1121 + device. so the compression fs will not be usable. but if we use
1122 + loopback mount, we may address this issue.
1124 + mount /cdrom/squashfs.img /sq
1125 + losetup /sq/ext2.img
1126 + losetup /somewhere/cow
1127 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1128 +- it will be difficult (or needs more operations) to extract the
1129 + difference between the original device and COW.
1130 +- DM snapshot-merge may help a lot when users try merging. in the
1131 + fs-layer union, users will use rsync(1).
1133 +You may want to read my old paper "Filesystems in LiveCD"
1134 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1137 +Several characters/aspects/persona of aufs
1138 +----------------------------------------------------------------------
1140 +Aufs has several characters, aspects or persona.
1141 +1. a filesystem, callee of VFS helper
1142 +2. sub-VFS, caller of VFS helper for branches
1143 +3. a virtual filesystem which maintains persistent inode number
1144 +4. reader/writer of files on branches such like an application
1146 +1. Callee of VFS Helper
1147 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1148 +unlink(2) from an application reaches sys_unlink() kernel function and
1149 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1150 +calls filesystem specific unlink operation. Actually aufs implements the
1151 +unlink operation but it behaves like a redirector.
1153 +2. Caller of VFS Helper for Branches
1154 +aufs_unlink() passes the unlink request to the branch filesystem as if
1155 +it were called from VFS. So the called unlink operation of the branch
1156 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1157 +every necessary pre/post operation for the branch filesystem.
1158 +- acquire the lock for the parent dir on a branch
1159 +- lookup in a branch
1160 +- revalidate dentry on a branch
1161 +- mnt_want_write() for a branch
1162 +- vfs_unlink() for a branch
1163 +- mnt_drop_write() for a branch
1164 +- release the lock on a branch
1166 +3. Persistent Inode Number
1167 +One of the most important issue for a filesystem is to maintain inode
1168 +numbers. This is particularly important to support exporting a
1169 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1170 +backend block device for its own. But some storage is necessary to
1171 +keep and maintain the inode numbers. It may be a large space and may not
1172 +suit to keep in memory. Aufs rents some space from its first writable
1173 +branch filesystem (by default) and creates file(s) on it. These files
1174 +are created by aufs internally and removed soon (currently) keeping
1176 +Note: Because these files are removed, they are totally gone after
1177 + unmounting aufs. It means the inode numbers are not persistent
1178 + across unmount or reboot. I have a plan to make them really
1179 + persistent which will be important for aufs on NFS server.
1181 +4. Read/Write Files Internally (copy-on-write)
1182 +Because a branch can be readonly, when you write a file on it, aufs will
1183 +"copy-up" it to the upper writable branch internally. And then write the
1184 +originally requested thing to the file. Generally kernel doesn't
1185 +open/read/write file actively. In aufs, even a single write may cause a
1186 +internal "file copy". This behaviour is very similar to cp(1) command.
1188 +Some people may think it is better to pass such work to user space
1189 +helper, instead of doing in kernel space. Actually I am still thinking
1190 +about it. But currently I have implemented it in kernel space.
1191 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1192 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1193 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2024-05-13 17:13:00.614737564 +0200
1196 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1198 +# This program is free software; you can redistribute it and/or modify
1199 +# it under the terms of the GNU General Public License as published by
1200 +# the Free Software Foundation; either version 2 of the License, or
1201 +# (at your option) any later version.
1203 +# This program is distributed in the hope that it will be useful,
1204 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1205 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1206 +# GNU General Public License for more details.
1208 +# You should have received a copy of the GNU General Public License
1209 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1211 +Basic Aufs Internal Structure
1213 +Superblock/Inode/Dentry/File Objects
1214 +----------------------------------------------------------------------
1215 +As like an ordinary filesystem, aufs has its own
1216 +superblock/inode/dentry/file objects. All these objects have a
1217 +dynamically allocated array and store the same kind of pointers to the
1218 +lower filesystem, branch.
1219 +For example, when you build a union with one readwrite branch and one
1220 +readonly, mounted /au, /rw and /ro respectively.
1222 +- /ro/fileA exists but /rw/fileA
1224 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1225 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1226 +- [0] = NULL (because /rw/fileA doesn't exist)
1229 +This style of an array is essentially same to the aufs
1230 +superblock/inode/dentry/file objects.
1232 +Because aufs supports manipulating branches, ie. add/delete/change
1233 +branches dynamically, these objects has its own generation. When
1234 +branches are changed, the generation in aufs superblock is
1235 +incremented. And a generation in other object are compared when it is
1236 +accessed. When a generation in other objects are obsoleted, aufs
1237 +refreshes the internal array.
1241 +----------------------------------------------------------------------
1242 +Additionally aufs superblock has some data for policies to select one
1243 +among multiple writable branches, XIB files, pseudo-links and kobject.
1244 +See below in detail.
1245 +About the policies which supports copy-down a directory, see
1246 +wbr_policy.txt too.
1249 +Branch and XINO(External Inode Number Translation Table)
1250 +----------------------------------------------------------------------
1251 +Every branch has its own xino (external inode number translation table)
1252 +file. The xino file is created and unlinked by aufs internally. When two
1253 +members of a union exist on the same filesystem, they share the single
1255 +The struct of a xino file is simple, just a sequence of aufs inode
1256 +numbers which is indexed by the lower inode number.
1257 +In the above sample, assume the inode number of /ro/fileA is i111 and
1258 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1259 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1261 +When the inode numbers are not contiguous, the xino file will be sparse
1262 +which has a hole in it and doesn't consume as much disk space as it
1263 +might appear. If your branch filesystem consumes disk space for such
1264 +holes, then you should specify 'xino=' option at mounting aufs.
1266 +Aufs has a mount option to free the disk blocks for such holes in XINO
1267 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1268 +meet a problem of disk shortage due to XINO files, then you should try
1269 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1270 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1271 +the holes in XINO files.
1273 +Also a writable branch has three kinds of "whiteout bases". All these
1274 +are existed when the branch is joined to aufs, and their names are
1275 +whiteout-ed doubly, so that users will never see their names in aufs
1277 +1. a regular file which will be hardlinked to all whiteouts.
1278 +2. a directory to store a pseudo-link.
1279 +3. a directory to store an "orphan"-ed file temporary.
1282 + When you remove a file on a readonly branch, aufs handles it as a
1283 + logical deletion and creates a whiteout on the upper writable branch
1284 + as a hardlink of this file in order not to consume inode on the
1287 + See below, Pseudo-link.
1289 + When "fileC" exists on the lower readonly branch only and it is
1290 + opened and removed with its parent dir, and then user writes
1291 + something into it, then aufs copies-up fileC to this
1292 + directory. Because there is no other dir to store fileC. After
1293 + creating a file under this dir, the file is unlinked.
1295 +Because aufs supports manipulating branches, ie. add/delete/change
1296 +dynamically, a branch has its own id. When the branch order changes,
1297 +aufs finds the new index by searching the branch id.
1301 +----------------------------------------------------------------------
1302 +Assume "fileA" exists on the lower readonly branch only and it is
1303 +hardlinked to "fileB" on the branch. When you write something to fileA,
1304 +aufs copies-up it to the upper writable branch. Additionally aufs
1305 +creates a hardlink under the Pseudo-link Directory of the writable
1306 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1307 +simple list. If fileB is read after unlinking fileA, aufs returns
1308 +filedata from the pseudo-link instead of the lower readonly
1309 +branch. Because the pseudo-link is based upon the inode, to keep the
1310 +inode number by xino (see above) is essentially necessary.
1312 +All the hardlinks under the Pseudo-link Directory of the writable branch
1313 +should be restored in a proper location later. Aufs provides a utility
1314 +to do this. The userspace helpers executed at remounting and unmounting
1316 +During this utility is running, it puts aufs into the pseudo-link
1317 +maintenance mode. In this mode, only the process which began the
1318 +maintenance mode (and its child processes) is allowed to operate in
1319 +aufs. Some other processes which are not related to the pseudo-link will
1320 +be allowed to run too, but the rest have to return an error or wait
1321 +until the maintenance mode ends. If a process already acquires an inode
1322 +mutex (in VFS), it has to return an error.
1325 +XIB(external inode number bitmap)
1326 +----------------------------------------------------------------------
1327 +Addition to the xino file per a branch, aufs has an external inode number
1328 +bitmap in a superblock object. It is also an internal file such like a
1330 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1332 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1334 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1335 +reduce the number of consumed disk blocks for these files.
1338 +Virtual or Vertical Dir, and Readdir in Userspace
1339 +----------------------------------------------------------------------
1340 +In order to support multiple layers (branches), aufs readdir operation
1341 +constructs a virtual dir block on memory. For readdir, aufs calls
1342 +vfs_readdir() internally for each dir on branches, merges their entries
1343 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1344 +object. So the file object has its entry list until it is closed. The
1345 +entry list will be updated when the file position is zero and becomes
1346 +obsoleted. This decision is made in aufs automatically.
1348 +The dynamically allocated memory block for the name of entries has a
1349 +unit of 512 bytes (by default) and stores the names contiguously (no
1350 +padding). Another block for each entry is handled by kmem_cache too.
1351 +During building dir blocks, aufs creates hash list and judging whether
1352 +the entry is whiteouted by its upper branch or already listed.
1353 +The merged result is cached in the corresponding inode object and
1354 +maintained by a customizable life-time option.
1356 +Some people may call it can be a security hole or invite DoS attack
1357 +since the opened and once readdir-ed dir (file object) holds its entry
1358 +list and becomes a pressure for system memory. But I'd say it is similar
1359 +to files under /proc or /sys. The virtual files in them also holds a
1360 +memory page (generally) while they are opened. When an idea to reduce
1361 +memory for them is introduced, it will be applied to aufs too.
1362 +For those who really hate this situation, I've developed readdir(3)
1363 +library which operates this merging in userspace. You just need to set
1364 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1365 +kernel space for readdir(3).
1369 +----------------------------------------------------------------------
1370 +Aufs sometimes requires privilege access to a branch. For instance,
1371 +in copy-up/down operation. When a user process is going to make changes
1372 +to a file which exists in the lower readonly branch only, and the mode
1373 +of one of ancestor directories may not be writable by a user
1374 +process. Here aufs copy-up the file with its ancestors and they may
1375 +require privilege to set its owner/group/mode/etc.
1376 +This is a typical case of a application character of aufs (see
1379 +Aufs uses workqueue synchronously for this case. It creates its own
1380 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1381 +passes the request to call mkdir or write (for example), and wait for
1382 +its completion. This approach solves a problem of a signal handler
1384 +If aufs didn't adopt the workqueue and changed the privilege of the
1385 +process, then the process may receive the unexpected SIGXFSZ or other
1388 +Also aufs uses the system global workqueue ("events" kernel thread) too
1389 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1390 +whiteout base and etc. This is unrelated to a privilege.
1391 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1392 +superblock at the beginning, at the same time waits for the completion
1393 +of all queued asynchronous tasks.
1397 +----------------------------------------------------------------------
1398 +The whiteout in aufs is very similar to Unionfs's. That is represented
1399 +by its filename. UnionMount takes an approach of a file mode, but I am
1400 +afraid several utilities (find(1) or something) will have to support it.
1402 +Basically the whiteout represents "logical deletion" which stops aufs to
1403 +lookup further, but also it represents "dir is opaque" which also stop
1406 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1407 +In order to make several functions in a single systemcall to be
1408 +revertible, aufs adopts an approach to rename a directory to a temporary
1409 +unique whiteouted name.
1410 +For example, in rename(2) dir where the target dir already existed, aufs
1411 +renames the target dir to a temporary unique whiteouted name before the
1412 +actual rename on a branch, and then handles other actions (make it opaque,
1413 +update the attributes, etc). If an error happens in these actions, aufs
1414 +simply renames the whiteouted name back and returns an error. If all are
1415 +succeeded, aufs registers a function to remove the whiteouted unique
1416 +temporary name completely and asynchronously to the system global
1421 +----------------------------------------------------------------------
1422 +It is a well-known feature or concept.
1423 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1424 +internally and makes change to the new file on the upper writable branch.
1425 +When the trigger systemcall does not update the timestamps of the parent
1426 +dir, aufs reverts it after copy-up.
1429 +Move-down (aufs3.9 and later)
1430 +----------------------------------------------------------------------
1431 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1432 +the lower readonly branch to the upper writable branch when a user
1433 +changes something about the file.
1434 +"Move-down" is an opposite action of copy-up. Basically this action is
1435 +ran manually instead of automatically and internally.
1436 +For desgin and implementation, aufs has to consider these issues.
1437 +- whiteout for the file may exist on the lower branch.
1438 +- ancestor directories may not exist on the lower branch.
1439 +- diropq for the ancestor directories may exist on the upper branch.
1440 +- free space on the lower branch will reduce.
1441 +- another access to the file may happen during moving-down, including
1442 + UDBA (see "Revalidate Dentry and UDBA").
1443 +- the file should not be hard-linked nor pseudo-linked. they should be
1444 + handled by auplink utility later.
1446 +Sometimes users want to move-down a file from the upper writable branch
1447 +to the lower readonly or writable branch. For instance,
1448 +- the free space of the upper writable branch is going to run out.
1449 +- create a new intermediate branch between the upper and lower branch.
1452 +For this purpose, use "aumvdown" command in aufs-util.git.
1453 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1454 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1455 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2024-05-13 17:13:00.614737564 +0200
1458 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1460 +# This program is free software; you can redistribute it and/or modify
1461 +# it under the terms of the GNU General Public License as published by
1462 +# the Free Software Foundation; either version 2 of the License, or
1463 +# (at your option) any later version.
1465 +# This program is distributed in the hope that it will be useful,
1466 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1467 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1468 +# GNU General Public License for more details.
1470 +# You should have received a copy of the GNU General Public License
1471 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1473 +Support for a branch who has its ->atomic_open()
1474 +----------------------------------------------------------------------
1475 +The filesystems who implement its ->atomic_open() are not majority. For
1476 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1477 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1478 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1479 +sure whether all filesystems who have ->atomic_open() behave like this,
1480 +but NFSv4 surely returns the error.
1482 +In order to support ->atomic_open() for aufs, there are a few
1485 +A. Introduce aufs_atomic_open()
1486 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1488 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1489 + an aufs user Pip Cet's approach
1490 + - calls aufs_create(), VFS finish_open() and notify_change().
1491 + - pass fake-mode to finish_open(), and then correct the mode by
1493 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1494 + - no aufs_atomic_open().
1495 + - aufs_lookup() registers the TID to an aufs internal object.
1496 + - aufs_create() does nothing when the matching TID is registered, but
1497 + registers the mode.
1498 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1499 + TID is registered.
1500 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1502 + - no aufs_atomic_open().
1503 + - aufs_create() registers the TID to an internal object. this info
1504 + represents "this process created this file just now."
1505 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1506 + registered TID and re-try open() with superuser's credential.
1508 +Pros and cons for each approach.
1511 + - straightforward but highly depends upon VFS internal.
1512 + - the atomic behavaiour is kept.
1513 + - some of parameters such as nameidata are hard to reproduce for
1517 + - easy to implement.
1518 + - the atomic behavaiour is lost.
1520 + - the atomic behavaiour is kept.
1521 + - dirty and tricky.
1522 + - VFS checks whether the file is created correctly after calling
1523 + ->create(), which means this approach doesn't work.
1525 + - easy to implement.
1526 + - the atomic behavaiour is lost.
1527 + - to open a file with superuser's credential and give it to a user
1528 + process is a bad idea, since the file object keeps the credential
1529 + in it. It may affect LSM or something. This approach doesn't work
1532 +The approach A is ideal, but it hard to implement. So here is a
1533 +variation of A, which is to be implemented.
1535 +A-1. Introduce aufs_atomic_open()
1536 + - calls branch fs ->atomic_open() if exists. otherwise calls
1537 + vfs_create() and finish_open().
1538 + - the demerit is that the several checks after branch fs
1539 + ->atomic_open() are lost. in the ordinary case, the checks are
1540 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1541 + be implemented in aufs, but not all I am afraid.
1542 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1543 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1544 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2024-05-13 17:13:00.614737564 +0200
1547 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1549 +# This program is free software; you can redistribute it and/or modify
1550 +# it under the terms of the GNU General Public License as published by
1551 +# the Free Software Foundation; either version 2 of the License, or
1552 +# (at your option) any later version.
1554 +# This program is distributed in the hope that it will be useful,
1555 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1556 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1557 +# GNU General Public License for more details.
1559 +# You should have received a copy of the GNU General Public License
1560 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1563 +----------------------------------------------------------------------
1564 +Since aufs has a character of sub-VFS (see Introduction), it operates
1565 +lookup for branches as VFS does. It may be a heavy work. But almost all
1566 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1567 +directly connected to its parent. Digging down the directory hierarchy
1568 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1571 +When a branch is a remote filesystem, aufs basically relies upon its
1572 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1574 +For d_revalidate, aufs implements three levels of revalidate tests. See
1575 +"Revalidate Dentry and UDBA" in detail.
1578 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1579 +----------------------------------------------------------------------
1580 +Let's try case study.
1581 +- aufs has two branches, upper readwrite and lower readonly.
1583 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1584 +- user invoked "chmod a+rx /au/dirA"
1585 +- the internal copy-up is activated and "/rw/dirA" is created and its
1586 + permission bits are set to world readable.
1587 +- then "/au/dirA" becomes world readable?
1589 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1590 +or it may be a natively readonly filesystem. If aufs respects the lower
1591 +branch, it should not respond readdir request from other users. But user
1592 +allowed it by chmod. Should really aufs rejects showing the entries
1595 +To be honest, I don't have a good solution for this case. So aufs
1596 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1598 +When dirperm1 is specified, aufs checks only the highest one for the
1599 +directory permission, and shows the entries. Otherwise, as usual, checks
1600 +every dir existing on all branches and rejects the request.
1602 +As a side effect, dirperm1 option improves the performance of aufs
1603 +because the number of permission check is reduced when the number of
1607 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1608 +----------------------------------------------------------------------
1609 +Generally VFS helpers re-validate a dentry as a part of lookup.
1610 +0. digging down the directory hierarchy.
1611 +1. lock the parent dir by its i_mutex.
1612 +2. lookup the final (child) entry.
1614 +4. call the actual operation (create, unlink, etc.)
1615 +5. unlock the parent dir
1617 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1618 +called. Actually aufs implements it and checks the dentry on a branch is
1620 +But it is not enough. Because aufs has to release the lock for the
1621 +parent dir on a branch at the end of ->lookup() (step 2) and
1622 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1624 +If the file on a branch is changed directly, eg. bypassing aufs, after
1625 +aufs released the lock, then the subsequent operation may cause
1626 +something unpleasant result.
1628 +This situation is a result of VFS architecture, ->lookup() and
1629 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1630 +design from VFS's point of view. It is just not suitable for sub-VFS
1633 +Aufs supports such case by three level of revalidation which is
1634 +selectable by user.
1635 +1. Simple Revalidate
1636 + Addition to the native flow in VFS's, confirm the child-parent
1637 + relationship on the branch just after locking the parent dir on the
1638 + branch in the "actual operation" (step 4). When this validation
1639 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1640 + checks the validation of the dentry on branches.
1641 +2. Monitor Changes Internally by Inotify/Fsnotify
1642 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1643 + the dentry on the branch, and returns EBUSY if it finds different
1645 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1646 + during it is in cache. When the event is notified, aufs registers a
1647 + function to kernel 'events' thread by schedule_work(). And the
1648 + function sets some special status to the cached aufs dentry and inode
1649 + private data. If they are not cached, then aufs has nothing to
1650 + do. When the same file is accessed through aufs (step 0-3) later,
1651 + aufs will detect the status and refresh all necessary data.
1652 + In this mode, aufs has to ignore the event which is fired by aufs
1654 +3. No Extra Validation
1655 + This is the simplest test and doesn't add any additional revalidation
1656 + test, and skip the revalidation in step 4. It is useful and improves
1657 + aufs performance when system surely hide the aufs branches from user,
1658 + by over-mounting something (or another method).
1659 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1660 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1661 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2024-05-13 17:13:00.614737564 +0200
1664 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1666 +# This program is free software; you can redistribute it and/or modify
1667 +# it under the terms of the GNU General Public License as published by
1668 +# the Free Software Foundation; either version 2 of the License, or
1669 +# (at your option) any later version.
1671 +# This program is distributed in the hope that it will be useful,
1672 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1673 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1674 +# GNU General Public License for more details.
1676 +# You should have received a copy of the GNU General Public License
1677 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1679 +Branch Manipulation
1681 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1682 +and changing its permission/attribute, there are a lot of works to do.
1686 +----------------------------------------------------------------------
1687 +o Confirm the adding dir exists outside of aufs, including loopback
1688 + mount, and its various attributes.
1689 +o Initialize the xino file and whiteout bases if necessary.
1692 +o Check the owner/group/mode of the directory
1693 + When the owner/group/mode of the adding directory differs from the
1694 + existing branch, aufs issues a warning because it may impose a
1696 + For example, when a upper writable branch has a world writable empty
1697 + top directory, a malicious user can create any files on the writable
1698 + branch directly, like copy-up and modify manually. If something like
1699 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1700 + writable branch, and the writable branch is world-writable, then a
1701 + malicious guy may create /etc/passwd on the writable branch directly
1702 + and the infected file will be valid in aufs.
1703 + I am afraid it can be a security issue, but aufs can do nothing except
1704 + producing a warning.
1708 +----------------------------------------------------------------------
1709 +o Confirm the deleting branch is not busy
1710 + To be general, there is one merit to adopt "remount" interface to
1711 + manipulate branches. It is to discard caches. At deleting a branch,
1712 + aufs checks the still cached (and connected) dentries and inodes. If
1713 + there are any, then they are all in-use. An inode without its
1714 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1716 + For the cached one, aufs checks whether the same named entry exists on
1718 + If the cached one is a directory, because aufs provides a merged view
1719 + to users, as long as one dir is left on any branch aufs can show the
1720 + dir to users. In this case, the branch can be removed from aufs.
1721 + Otherwise aufs rejects deleting the branch.
1723 + If any file on the deleting branch is opened by aufs, then aufs
1727 +Modify the Permission of a Branch
1728 +----------------------------------------------------------------------
1729 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1732 +o rw --> ro: Confirm the modifying branch is not busy
1733 + Aufs rejects the request if any of these conditions are true.
1734 + - a file on the branch is mmap-ed.
1735 + - a regular file on the branch is opened for write and there is no
1736 + same named entry on the upper branch.
1737 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1738 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1739 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2024-05-13 17:13:00.614737564 +0200
1742 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1744 +# This program is free software; you can redistribute it and/or modify
1745 +# it under the terms of the GNU General Public License as published by
1746 +# the Free Software Foundation; either version 2 of the License, or
1747 +# (at your option) any later version.
1749 +# This program is distributed in the hope that it will be useful,
1750 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1751 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1752 +# GNU General Public License for more details.
1754 +# You should have received a copy of the GNU General Public License
1755 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1757 +Policies to Select One among Multiple Writable Branches
1758 +----------------------------------------------------------------------
1759 +When the number of writable branch is more than one, aufs has to decide
1760 +the target branch for file creation or copy-up. By default, the highest
1761 +writable branch which has the parent (or ancestor) dir of the target
1762 +file is chosen (top-down-parent policy).
1763 +By user's request, aufs implements some other policies to select the
1764 +writable branch, for file creation several policies, round-robin,
1765 +most-free-space, and other policies. For copy-up, top-down-parent,
1766 +bottom-up-parent, bottom-up and others.
1768 +As expected, the round-robin policy selects the branch in circular. When
1769 +you have two writable branches and creates 10 new files, 5 files will be
1770 +created for each branch. mkdir(2) systemcall is an exception. When you
1771 +create 10 new directories, all will be created on the same branch.
1772 +And the most-free-space policy selects the one which has most free
1773 +space among the writable branches. The amount of free space will be
1774 +checked by aufs internally, and users can specify its time interval.
1776 +The policies for copy-up is more simple,
1777 +top-down-parent is equivalent to the same named on in create policy,
1778 +bottom-up-parent selects the writable branch where the parent dir
1779 +exists and the nearest upper one from the copyup-source,
1780 +bottom-up selects the nearest upper writable branch from the
1781 +copyup-source, regardless the existence of the parent dir.
1783 +There are some rules or exceptions to apply these policies.
1784 +- If there is a readonly branch above the policy-selected branch and
1785 + the parent dir is marked as opaque (a variation of whiteout), or the
1786 + target (creating) file is whiteout-ed on the upper readonly branch,
1787 + then the result of the policy is ignored and the target file will be
1788 + created on the nearest upper writable branch than the readonly branch.
1789 +- If there is a writable branch above the policy-selected branch and
1790 + the parent dir is marked as opaque or the target file is whiteouted
1791 + on the branch, then the result of the policy is ignored and the target
1792 + file will be created on the highest one among the upper writable
1793 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1795 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1796 + They try selecting the branch where the source exists as possible
1797 + since copyup a large file will take long time. If it can't be,
1798 + ie. the branch where the source exists is readonly, then they will
1799 + follow the copyup policy.
1800 +- There is an exception for rename(2) when the target exists.
1801 + If the rename target exists, aufs compares the index of the branches
1802 + where the source and the target exists and selects the higher
1803 + one. If the selected branch is readonly, then aufs follows the
1805 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1806 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1807 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2024-05-13 17:13:00.614737564 +0200
1810 +// to view this graph, run dot(1) command in GRAPHVIZ.
1812 +// This program is free software; you can redistribute it and/or modify
1813 +// it under the terms of the GNU General Public License as published by
1814 +// the Free Software Foundation; either version 2 of the License, or
1815 +// (at your option) any later version.
1817 +// This program is distributed in the hope that it will be useful,
1818 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1819 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1820 +// GNU General Public License for more details.
1822 +// You should have received a copy of the GNU General Public License
1823 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1827 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1831 +aufs_rename -> whinfo [label="store/remove"];
1834 +inode_list [label="h_inum list in branch\ncache"];
1837 +whinode [label="h_inum list file"];
1840 +brmgmt [label="br_add/del/mod/umount"];
1842 +brmgmt -> inode_list [label="create/remove"];
1843 +brmgmt -> whinode [label="load/store"];
1845 +inode_list -> whinode [style=dashed,dir=both];
1847 +aufs_rename -> inode_list [label="add/del"];
1849 +aufs_lookup -> inode_list [label="search"];
1851 +aufs_lookup -> whinfo [label="load/remove"];
1853 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1854 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1855 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2024-05-13 17:13:00.614737564 +0200
1858 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1860 +# This program is free software; you can redistribute it and/or modify
1861 +# it under the terms of the GNU General Public License as published by
1862 +# the Free Software Foundation; either version 2 of the License, or
1863 +# (at your option) any later version.
1865 +# This program is distributed in the hope that it will be useful,
1866 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1867 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1868 +# GNU General Public License for more details.
1870 +# You should have received a copy of the GNU General Public License
1871 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1873 +Special handling for renaming a directory (DIRREN)
1874 +----------------------------------------------------------------------
1875 +First, let's assume we have a simple usecase.
1879 +- /ro/dirA and /ro/dirA/file exist too
1880 +- there is no dirB on both branches
1881 +- a user issues rename("dirA", "dirB")
1883 +Now, what should aufs behave against this rename(2)?
1884 +There are a few possible cases.
1887 + since dirA exists on a readonly branch which cannot be renamed.
1889 + it is possible to copy-up dirA (only the dir itself), but the child
1890 + entries ("file" in this case) should not be. it must be a bad
1891 + approach to copy-up recursively.
1892 +C. returns a success.
1893 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1894 + is a violation of aufs' policy.
1895 +D. construct an extra information which indicates that /ro/dirA should
1896 + be handled as the name of dirB.
1897 + overlayfs has a similar feature called REDIRECT.
1899 +Until now, aufs implements the case B only which returns EXDEV, and
1900 +expects the userspace application behaves like mv(1) which tries
1901 +issueing rename(2) recursively.
1903 +A new aufs feature called DIRREN is introduced which implements the case
1904 +D. There are several "extra information" added.
1906 +1. detailed info per renamed directory
1907 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1908 +2. the inode-number list of directories on a branch
1909 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1911 +The filename of "detailed info per directory" represents the lower
1912 +branch, and its format is
1913 +- a type of the branch id
1915 + + uuid (not implemented yet)
1918 +- the inode-number of the branch root dir
1920 +And it contains these info in a single regular file.
1922 +- branch's inode-number of the logically renamed dir
1923 +- the name of the before-renamed dir
1925 +The "detailed info per directory" file is created in aufs rename(2), and
1926 +loaded in any lookup.
1927 +The info is considered in lookup for the matching case only. Here
1928 +"matching" means that the root of branch (in the info filename) is same
1929 +to the current looking-up branch. After looking-up the before-renamed
1930 +name, the inode-number is compared. And the matched dentry is used.
1932 +The "inode-number list of directories" is a regular file which contains
1933 +simply the inode-numbers on the branch. The file is created or updated
1934 +in removing the branch, and loaded in adding the branch. Its lifetime is
1935 +equal to the branch.
1936 +The list is referred in lookup, and when the current target inode is
1937 +found in the list, the aufs tries loading the "detailed info per
1938 +directory" and get the changed and valid name of the dir.
1940 +Theoretically these "extra informaiton" may be able to be put into XATTR
1941 +in the dir inode. But aufs doesn't choose this way because
1942 +1. XATTR may not be supported by the branch (or its configuration)
1943 +2. XATTR may have its size limit.
1944 +3. XATTR may be less easy to convert than a regular file, when the
1945 + format of the info is changed in the future.
1946 +At the same time, I agree that the regular file approach is much slower
1947 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1950 +This DIRREN feature is enabled by aufs configuration, and is activated
1951 +by a new mount option.
1953 +For the more complicated case, there is a work with UDBA option, which
1954 +is to dected the direct access to the branches (by-passing aufs) and to
1955 +maintain the cashes in aufs. Since a single cached aufs dentry may
1956 +contains two names, before- and after-rename, the name comparision in
1957 +UDBA handler may not work correctly. In this case, the behaviour will be
1958 +equivalen to udba=reval case.
1959 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1960 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1961 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2024-05-13 17:13:00.614737564 +0200
1964 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1966 +# This program is free software; you can redistribute it and/or modify
1967 +# it under the terms of the GNU General Public License as published by
1968 +# the Free Software Foundation; either version 2 of the License, or
1969 +# (at your option) any later version.
1971 +# This program is distributed in the hope that it will be useful,
1972 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1973 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1974 +# GNU General Public License for more details.
1976 +# You should have received a copy of the GNU General Public License
1977 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1979 +File-based Hierarchical Storage Management (FHSM)
1980 +----------------------------------------------------------------------
1981 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1982 +storage world. Aufs provides this feature as file-based with multiple
1983 +writable branches, based upon the principle of "Colder, the Lower".
1984 +Here the word "colder" means that the less used files, and "lower" means
1985 +that the position in the order of the stacked branches vertically.
1986 +These multiple writable branches are prioritized, ie. the topmost one
1987 +should be the fastest drive and be used heavily.
1989 +o Characters in aufs FHSM story
1990 +- aufs itself and a new branch attribute.
1991 +- a new ioctl interface to move-down and to establish a connection with
1992 + the daemon ("move-down" is a converse of "copy-up").
1993 +- userspace tool and daemon.
1995 +The userspace daemon establishes a connection with aufs and waits for
1996 +the notification. The notified information is very similar to struct
1997 +statfs containing the number of consumed blocks and inodes.
1998 +When the consumed blocks/inodes of a branch exceeds the user-specified
1999 +upper watermark, the daemon activates its move-down process until the
2000 +consumed blocks/inodes reaches the user-specified lower watermark.
2002 +The actual move-down is done by aufs based upon the request from
2003 +user-space since we need to maintain the inode number and the internal
2004 +pointer arrays in aufs.
2006 +Currently aufs FHSM handles the regular files only. Additionally they
2007 +must not be hard-linked nor pseudo-linked.
2010 +o Cowork of aufs and the user-space daemon
2011 + During the userspace daemon established the connection, aufs sends a
2012 + small notification to it whenever aufs writes something into the
2013 + writable branch. But it may cost high since aufs issues statfs(2)
2014 + internally. So user can specify a new option to cache the
2015 + info. Actually the notification is controlled by these factors.
2016 + + the specified cache time.
2017 + + classified as "force" by aufs internally.
2018 + Until the specified time expires, aufs doesn't send the info
2019 + except the forced cases. When aufs decide forcing, the info is always
2020 + notified to userspace.
2021 + For example, the number of free inodes is generally large enough and
2022 + the shortage of it happens rarely. So aufs doesn't force the
2023 + notification when creating a new file, directory and others. This is
2024 + the typical case which aufs doesn't force.
2025 + When aufs writes the actual filedata and the files consumes any of new
2026 + blocks, the aufs forces notifying.
2029 +o Interfaces in aufs
2030 +- New branch attribute.
2032 + Specifies that the branch is managed by FHSM feature. In other word,
2033 + participant in the FHSM.
2034 + When nofhsm is set to the branch, it will not be the source/target
2035 + branch of the move-down operation. This attribute is set
2036 + independently from coo and moo attributes, and if you want full
2037 + FHSM, you should specify them as well.
2038 +- New mount option.
2040 + Specifies a second to suppress many less important info to be
2043 + + AUFS_CTL_FHSM_FD
2044 + create a new file descriptor which userspace can read the notification
2045 + (a subset of struct statfs) from aufs.
2046 +- Module parameter 'brs'
2047 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2049 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2050 + When there are two or more branches with fhsm attributes,
2051 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2052 + terminates it. As a result of remounting and branch-manipulation, the
2053 + number of branches with fhsm attribute can be one. In this case,
2054 + /sbin/mount.aufs will terminate the user-space daemon.
2057 +Finally the operation is done as these steps in kernel-space.
2059 + + no one else is using the file.
2060 + + the file is not hard-linked.
2061 + + the file is not pseudo-linked.
2062 + + the file is a regular file.
2063 + + the parent dir is not opaqued.
2064 +- find the target writable branch.
2065 +- make sure the file is not whiteout-ed by the upper (than the target)
2067 +- make the parent dir on the target branch.
2068 +- mutex lock the inode on the branch.
2069 +- unlink the whiteout on the target branch (if exists).
2070 +- lookup and create the whiteout-ed temporary name on the target branch.
2071 +- copy the file as the whiteout-ed temporary name on the target branch.
2072 +- rename the whiteout-ed temporary name to the original name.
2073 +- unlink the file on the source branch.
2074 +- maintain the internal pointer array and the external inode number
2076 +- maintain the timestamps and other attributes of the parent dir and the
2079 +And of course, in every step, an error may happen. So the operation
2080 +should restore the original file state after an error happens.
2081 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2082 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2083 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2024-05-13 17:13:00.614737564 +0200
2086 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2088 +# This program is free software; you can redistribute it and/or modify
2089 +# it under the terms of the GNU General Public License as published by
2090 +# the Free Software Foundation; either version 2 of the License, or
2091 +# (at your option) any later version.
2093 +# This program is distributed in the hope that it will be useful,
2094 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2095 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2096 +# GNU General Public License for more details.
2098 +# You should have received a copy of the GNU General Public License
2099 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2101 +mmap(2) -- File Memory Mapping
2102 +----------------------------------------------------------------------
2103 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2104 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2106 +This approach is simple and good, but there is one problem.
2107 +Under /proc, several entries show the mmapped files by its path (with
2108 +device and inode number), and the printed path will be the path on the
2109 +branch fs's instead of virtual aufs's.
2110 +This is not a problem in most cases, but some utilities lsof(1) (and its
2111 +user) may expect the path on aufs.
2113 +To address this issue, aufs adds a new member called vm_prfile in struct
2114 +vm_area_struct (and struct vm_region). The original vm_file points to
2115 +the file on the branch fs in order to handle everything correctly as
2116 +usual. The new vm_prfile points to a virtual file in aufs, and the
2117 +show-functions in procfs refers to vm_prfile if it is set.
2118 +Also we need to maintain several other places where touching vm_file
2120 +- fork()/clone() copies vma and the reference count of vm_file is
2122 +- merging vma maintains the ref count too.
2124 +This is not a good approach. It just fakes the printed path. But it
2125 +leaves all behaviour around f_mapping unchanged. This is surely an
2127 +Actually aufs had adopted another complicated approach which calls
2128 +generic_file_mmap() and handles struct vm_operations_struct. In this
2129 +approach, aufs met a hard problem and I could not solve it without
2130 +switching the approach.
2132 +There may be one more another approach which is
2133 +- bind-mount the branch-root onto the aufs-root internally
2134 +- grab the new vfsmount (ie. struct mount)
2135 +- lazy-umount the branch-root internally
2136 +- in open(2) the aufs-file, open the branch-file with the hidden
2137 + vfsmount (instead of the original branch's vfsmount)
2138 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2139 + but it may be possible from userspace by the mount helper.
2141 +Adding the internal hidden vfsmount and using it in opening a file, the
2142 +file path under /proc will be printed correctly. This approach looks
2143 +smarter, but is not possible I am afraid.
2144 +- aufs-root may be bind-mount later. when it happens, another hidden
2145 + vfsmount will be required.
2146 +- it is hard to get the chance to bind-mount and lazy-umount
2147 + + in kernel-space, FS can have vfsmount in open(2) via
2148 + file->f_path, and aufs can know its vfsmount. But several locks are
2149 + already acquired, and if aufs tries to bind-mount and lazy-umount
2150 + here, then it may cause a deadlock.
2151 + + in user-space, bind-mount doesn't invoke the mount helper.
2152 +- since /proc shows dev and ino, aufs has to give vma these info. it
2153 + means a new member vm_prinode will be necessary. this is essentially
2154 + equivalent to vm_prfile described above.
2156 +I have to give up this "looks-smater" approach.
2157 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2158 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2159 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2024-05-13 17:13:00.614737564 +0200
2162 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2164 +# This program is free software; you can redistribute it and/or modify
2165 +# it under the terms of the GNU General Public License as published by
2166 +# the Free Software Foundation; either version 2 of the License, or
2167 +# (at your option) any later version.
2169 +# This program is distributed in the hope that it will be useful,
2170 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2171 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2172 +# GNU General Public License for more details.
2174 +# You should have received a copy of the GNU General Public License
2175 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2177 +Listing XATTR/EA and getting the value
2178 +----------------------------------------------------------------------
2179 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2180 +shows the values from the topmost existing file. This behaviour is good
2181 +for the non-dir entries since the bahaviour exactly matches the shown
2182 +information. But for the directories, aufs considers all the same named
2183 +entries on the lower branches. Which means, if one of the lower entry
2184 +rejects readdir call, then aufs returns an error even if the topmost
2185 +entry allows it. This behaviour is necessary to respect the branch fs's
2186 +security, but can make users confused since the user-visible standard
2187 +attributes don't match the behaviour.
2188 +To address this issue, aufs has a mount option called dirperm1 which
2189 +checks the permission for the topmost entry only, and ignores the lower
2190 +entry's permission.
2192 +A similar issue can happen around XATTR.
2193 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2194 +always set. Otherwise these very unpleasant situation would happen.
2195 +- listxattr(2) may return the duplicated entries.
2196 +- users may not be able to remove or reset the XATTR forever,
2199 +XATTR/EA support in the internal (copy,move)-(up,down)
2200 +----------------------------------------------------------------------
2201 +Generally the extended attributes of inode are categorized as these.
2202 +- "security" for LSM and capability.
2203 +- "system" for posix ACL, 'acl' mount option is required for the branch
2205 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2206 +- "user" for userspace, 'user_xattr' mount option is required for the
2207 + branch fs generally.
2209 +Moreover there are some other categories. Aufs handles these rather
2210 +unpopular categories as the ordinary ones, ie. there is no special
2211 +condition nor exception.
2213 +In copy-up, the support for XATTR on the dst branch may differ from the
2214 +src branch. In this case, the copy-up operation will get an error and
2215 +the original user operation which triggered the copy-up will fail. It
2216 +can happen that even all copy-up will fail.
2217 +When both of src and dst branches support XATTR and if an error occurs
2218 +during copying XATTR, then the copy-up should fail obviously. That is a
2219 +good reason and aufs should return an error to userspace. But when only
2220 +the src branch support that XATTR, aufs should not return an error.
2221 +For example, the src branch supports ACL but the dst branch doesn't
2222 +because the dst branch may natively un-support it or temporary
2223 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2224 +may NOT return an error even if the XATTR is not supported. It is
2225 +totally up to the branch fs.
2227 +Anyway when the aufs internal copy-up gets an error from the dst branch
2228 +fs, then aufs tries removing the just copied entry and returns the error
2229 +to the userspace. The worst case of this situation will be all copy-up
2232 +For the copy-up operation, there two basic approaches.
2233 +- copy the specified XATTR only (by category above), and return the
2234 + error unconditionally if it happens.
2235 +- copy all XATTR, and ignore the error on the specified category only.
2237 +In order to support XATTR and to implement the correct behaviour, aufs
2238 +chooses the latter approach and introduces some new branch attributes,
2239 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2240 +They correspond to the XATTR namespaces (see above). Additionally, to be
2241 +convenient, "icex" is also provided which means all "icex*" attributes
2242 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2244 +The meaning of these attributes is to ignore the error from setting
2245 +XATTR on that branch.
2246 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2247 +error from the dst branch according to the specified attributes.
2249 +Some XATTR may have its default value. The default value may come from
2250 +the parent dir or the environment. If the default value is set at the
2251 +file creating-time, it will be overwritten by copy-up.
2252 +Some contradiction may happen I am afraid.
2253 +Do we need another attribute to stop copying XATTR? I am unsure. For
2254 +now, aufs implements the branch attributes to ignore the error.
2255 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2256 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2257 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2024-05-13 17:13:00.614737564 +0200
2260 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2262 +# This program is free software; you can redistribute it and/or modify
2263 +# it under the terms of the GNU General Public License as published by
2264 +# the Free Software Foundation; either version 2 of the License, or
2265 +# (at your option) any later version.
2267 +# This program is distributed in the hope that it will be useful,
2268 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2269 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2270 +# GNU General Public License for more details.
2272 +# You should have received a copy of the GNU General Public License
2273 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2275 +Export Aufs via NFS
2276 +----------------------------------------------------------------------
2277 +Here is an approach.
2278 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2280 +- iget_locked(): initialize aufs inode generation for a new inode, and
2281 + store it in xigen file.
2282 +- destroy_inode(): increment aufs inode generation and store it in xigen
2283 + file. it is necessary even if it is not unlinked, because any data of
2284 + inode may be changed by UDBA.
2285 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2286 + build file handle by
2287 + + branch id (4 bytes)
2288 + + superblock generation (4 bytes)
2289 + + inode number (4 or 8 bytes)
2290 + + parent dir inode number (4 or 8 bytes)
2291 + + inode generation (4 bytes))
2292 + + return value of exportfs_encode_fh() for the parent on a branch (4
2294 + + file handle for a branch (by exportfs_encode_fh())
2296 + + find the index of a branch from its id in handle, and check it is
2297 + still exist in aufs.
2298 + + 1st level: get the inode number from handle and search it in cache.
2299 + + 2nd level: if not found in cache, get the parent inode number from
2300 + the handle and search it in cache. and then open the found parent
2301 + dir, find the matching inode number by vfs_readdir() and get its
2302 + name, and call lookup_one_len() for the target dentry.
2303 + + 3rd level: if the parent dir is not cached, call
2304 + exportfs_decode_fh() for a branch and get the parent on a branch,
2305 + build a pathname of it, convert it a pathname in aufs, call
2306 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2308 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2309 + for every branch, but not itself. to get this, (currently) aufs
2310 + searches in current->nsproxy->mnt_ns list. it may not be a good
2311 + idea, but I didn't get other approach.
2312 + + test the generation of the gotten inode.
2313 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2314 + convert it into ESTALE for NFSD.
2315 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2316 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2317 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2318 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2319 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2024-05-13 17:13:00.614737564 +0200
2322 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2324 +# This program is free software; you can redistribute it and/or modify
2325 +# it under the terms of the GNU General Public License as published by
2326 +# the Free Software Foundation; either version 2 of the License, or
2327 +# (at your option) any later version.
2329 +# This program is distributed in the hope that it will be useful,
2330 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2331 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2332 +# GNU General Public License for more details.
2334 +# You should have received a copy of the GNU General Public License
2335 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2337 +Show Whiteout Mode (shwh)
2338 +----------------------------------------------------------------------
2339 +Generally aufs hides the name of whiteouts. But in some cases, to show
2340 +them is very useful for users. For instance, creating a new middle layer
2341 +(branch) by merging existing layers.
2343 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2344 +When you have three branches,
2345 +- Bottom: 'system', squashfs (underlying base system), read-only
2346 +- Middle: 'mods', squashfs, read-only
2347 +- Top: 'overlay', ram (tmpfs), read-write
2349 +The top layer is loaded at boot time and saved at shutdown, to preserve
2350 +the changes made to the system during the session.
2351 +When larger changes have been made, or smaller changes have accumulated,
2352 +the size of the saved top layer data grows. At this point, it would be
2353 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2354 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2355 +restoring save and load speed.
2357 +This merging is simplified by the use of another aufs mount, of just the
2358 +two overlay branches using the 'shwh' option.
2359 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2360 + aufs /livesys/merge_union
2362 +A merged view of these two branches is then available at
2363 +/livesys/merge_union, and the new feature is that the whiteouts are
2365 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2366 +writing to all branches. Also the default mode for all branches is 'ro'.
2367 +It is now possible to save the combined contents of the two overlay
2368 +branches to a new squashfs, e.g.:
2369 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2371 +This new squashfs archive can be stored on the boot device and the
2372 +initramfs will use it to replace the old one at the next boot.
2373 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2374 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2375 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2024-05-13 17:13:00.614737564 +0200
2378 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2380 +# This program is free software; you can redistribute it and/or modify
2381 +# it under the terms of the GNU General Public License as published by
2382 +# the Free Software Foundation; either version 2 of the License, or
2383 +# (at your option) any later version.
2385 +# This program is distributed in the hope that it will be useful,
2386 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2387 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2388 +# GNU General Public License for more details.
2390 +# You should have received a copy of the GNU General Public License
2391 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2393 +Dynamically customizable FS operations
2394 +----------------------------------------------------------------------
2395 +Generally FS operations (struct inode_operations, struct
2396 +address_space_operations, struct file_operations, etc.) are defined as
2397 +"static const", but it never means that FS have only one set of
2398 +operation. Some FS have multiple sets of them. For instance, ext2 has
2399 +three sets, one for XIP, for NOBH, and for normal.
2400 +Since aufs overrides and redirects these operations, sometimes aufs has
2401 +to change its behaviour according to the branch FS type. More importantly
2402 +VFS acts differently if a function (member in the struct) is set or
2403 +not. It means aufs should have several sets of operations and select one
2404 +among them according to the branch FS definition.
2406 +In order to solve this problem and not to affect the behaviour of VFS,
2407 +aufs defines these operations dynamically. For instance, aufs defines
2408 +dummy direct_IO function for struct address_space_operations, but it may
2409 +not be set to the address_space_operations actually. When the branch FS
2410 +doesn't have it, aufs doesn't set it to its address_space_operations
2411 +while the function definition itself is still alive. So the behaviour
2412 +itself will not change, and it will return an error when direct_IO is
2415 +The lifetime of these dynamically generated operation object is
2416 +maintained by aufs branch object. When the branch is removed from aufs,
2417 +the reference counter of the object is decremented. When it reaches
2418 +zero, the dynamically generated operation object will be freed.
2420 +This approach is designed to support AIO (io_submit), Direct I/O and
2422 +Currently this approach is applied to address_space_operations for
2423 +regular files only.
2424 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2425 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2426 +++ linux/Documentation/filesystems/aufs/README 2024-05-13 17:13:00.614737564 +0200
2429 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2435 +----------------------------------------
2436 +In the early days, aufs was entirely re-designed and re-implemented
2437 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2438 +improvements and implementations, it became totally different from
2439 +Unionfs while keeping the basic features.
2440 +Later, Unionfs Version 2.x series began taking some of the same
2441 +approaches to aufs1's.
2442 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2443 +University and his team.
2445 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2446 +aufs-linux.git or aufs-standalone.git.
2447 +If you want older kernel version support,
2448 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2449 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2450 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2451 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2452 + or aufs1 from CVS on SourceForge.
2454 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2455 + were changed. Now they are aufs-linux.git and
2456 + aufs-standalone.git and they contain aufs5 and later branches.
2458 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2459 + According to Christoph Hellwig, linux rejects all union-type
2460 + filesystems but UnionMount.
2461 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2463 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2464 + UnionMount, and he pointed out an issue around a directory mutex
2465 + lock and aufs addressed it. But it is still unsure whether aufs will
2466 + be merged (or any other union solution).
2467 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2471 +----------------------------------------
2472 +- unite several directories into a single virtual filesystem. The member
2473 + directory is called as a branch.
2474 +- you can specify the permission flags to the branch, which are 'readonly',
2475 + 'readwrite' and 'whiteout-able.'
2476 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2477 + readonly branch are modifiable logically.
2478 +- dynamic branch manipulation, add, del.
2481 +Also there are many enhancements in aufs, such as:
2482 +- test only the highest one for the directory permission (dirperm1)
2483 +- copyup on open (coo=)
2484 +- 'move' policy for copy-up between two writable branches, after
2485 + checking free space.
2487 +- readdir(3) in userspace.
2488 +- keep inode number by external inode number table
2489 +- keep the timestamps of file/dir in internal copyup operation
2490 +- seekable directory, supporting NFS readdir.
2491 +- whiteout is hardlinked in order to reduce the consumption of inodes
2493 +- do not copyup, nor create a whiteout when it is unnecessary
2494 +- revert a single systemcall when an error occurs in aufs
2495 +- remount interface instead of ioctl
2496 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2497 +- loopback mounted filesystem as a branch
2498 +- kernel thread for removing the dir who has a plenty of whiteouts
2499 +- support copyup sparse file (a file which has a 'hole' in it)
2500 +- default permission flags for branches
2501 +- selectable permission flags for ro branch, whether whiteout can
2504 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2505 +- support multiple writable branches, some policies to select one
2506 + among multiple writable branches.
2507 +- a new semantics for link(2) and rename(2) to support multiple
2508 + writable branches.
2509 +- no glibc changes are required.
2510 +- pseudo hardlink (hardlink over branches)
2511 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2512 + including NFS or remote filesystem branch.
2513 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2516 +Currently these features are dropped temporary from aufs6.
2517 +See design/08plan.txt in detail.
2518 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2520 +- statistics of aufs thread (/sys/fs/aufs/stat)
2522 +Features or just an idea in the future (see also design/*.txt),
2523 +- reorder the branch index without del/re-add.
2524 +- permanent xino files for NFSD
2525 +- an option for refreshing the opened files after add/del branches
2526 +- light version, without branch manipulation. (unnecessary?)
2527 +- copyup in userspace
2528 +- inotify in userspace
2533 +----------------------------------------
2534 +There are three GIT trees for aufs6, aufs-linux.git,
2535 +aufs-standalone.git, and aufs-util.git.
2536 +While the aufs-util is always necessary, you need either of aufs-linux
2537 +or aufs-standalone.
2539 +The aufs-linux tree includes the whole linux mainline GIT tree,
2540 +git://git.kernel.org/.../torvalds/linux.git.
2541 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2542 +build aufs6 as an external kernel module.
2543 +Several extra patches are not included in this tree. Only
2544 +aufs-standalone tree contains them. They are described in the later
2545 +section "Configuration and Compilation."
2547 +On the other hand, the aufs-standalone tree has only aufs source files
2548 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2549 +But you need to apply all aufs patches manually.
2551 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2552 +represents the linux kernel version, "linux-6.x". For instance,
2553 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2554 +"aufs6.x-rcN" branch.
2557 +$ git clone --reference /your/linux/git/tree \
2558 + git://github.com/sfjro/aufs-linux.git aufs-linux.git
2559 +- if you don't have linux GIT tree, then remove "--reference ..."
2560 +$ cd aufs-linux.git
2561 +$ git checkout origin/aufs6.0
2563 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2564 +leave the patch-work to GIT.
2565 +$ cd /your/linux/git/tree
2566 +$ git remote add aufs git://github.com/sfjro/aufs-linux.git
2568 +$ git checkout -b my6.0 v6.0
2569 +$ (add your local change...)
2570 +$ git pull aufs aufs6.0
2571 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2572 +- you may need to solve some conflicts between your_changes and
2573 + aufs6.0. in this case, git-rerere is recommended so that you can
2574 + solve the similar conflicts automatically when you upgrade to 6.1 or
2575 + later in the future.
2577 +o aufs-standalone tree
2578 +$ git clone git://github.com/sfjro/aufs-standalone.git aufs-standalone.git
2579 +$ cd aufs-standalone.git
2580 +$ git checkout origin/aufs6.0
2583 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2584 +- note that the public aufs-util.git is on SourceForge instead of
2587 +$ git checkout origin/aufs6.0
2589 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2590 +The minor version number, 'x' in '6.x', of aufs may not always
2591 +follow the minor version number of the kernel.
2592 +Because changes in the kernel that cause the use of a new
2593 +minor version number do not always require changes to aufs-util.
2595 +Since aufs-util has its own minor version number, you may not be
2596 +able to find a GIT branch in aufs-util for your kernel's
2597 +exact minor version number.
2598 +In this case, you should git-checkout the branch for the
2599 +nearest lower number.
2601 +For (an unreleased) example:
2602 +If you are using "linux-6.10" and the "aufs6.10" branch
2603 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2604 +or something numerically smaller is the branch for your kernel.
2606 +Also you can view all branches by
2610 +3. Configuration and Compilation
2611 +----------------------------------------
2612 +Make sure you have git-checkout'ed the correct branch.
2614 +For aufs-linux tree,
2615 +- enable CONFIG_AUFS_FS.
2616 +- set other aufs configurations if necessary.
2617 +- for aufs5.13 and later
2618 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2619 + also a caller of VFS functions for branch filesystems, subclassing of
2620 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2621 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2622 + need to customize some LOCKDEP numbers. Here are what I use on my
2624 + CONFIG_LOCKDEP_BITS=21
2625 + CONFIG_LOCKDEP_CHAINS_BITS=21
2626 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2627 + Also you will need to expand some constant values in LOCKDEP. Refer
2628 + to lockdep-debug.patch in aufs-standalone.git.
2630 +For aufs-standalone tree,
2631 +There are several ways to build.
2634 +- apply ./aufs6-kbuild.patch to your kernel source files.
2635 +- apply ./aufs6-base.patch too.
2636 +- apply ./aufs6-mmap.patch too.
2637 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2638 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs-standalone.patch.
2639 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2640 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2641 +- enable CONFIG_AUFS_FS, you can select either
2643 +- and build your kernel as usual.
2644 +- install the built kernel.
2645 +- install the header files too by "make headers_install" to the
2646 + directory where you specify. By default, it is $PWD/usr.
2647 + "make help" shows a brief note for headers_install.
2648 +- and reboot your system.
2651 +- module only (CONFIG_AUFS_FS=m).
2652 +- apply ./aufs6-base.patch to your kernel source files.
2653 +- apply ./aufs6-mmap.patch too.
2654 +- apply ./aufs6-standalone.patch too.
2655 +- build your kernel, don't forget "make headers_install", and reboot.
2656 +- edit ./config.mk and set other aufs configurations if necessary.
2657 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2658 + every aufs configurations.
2659 +- build the module by simple "make".
2660 +- you can specify ${KDIR} make variable which points to your kernel
2662 +- install the files
2663 + + run "make install" to install the aufs module, or copy the built
2664 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2665 + + run "make install_headers" (instead of headers_install) to install
2666 + the modified aufs header file (you can specify DESTDIR which is
2667 + available in aufs standalone version's Makefile only), or copy
2668 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2669 + you like manually. By default, the target directory is $PWD/usr.
2670 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2671 + kernel source tree.
2673 +Note: The header file aufs_type.h is necessary to build aufs-util
2674 + as well as "make headers_install" in the kernel source tree.
2675 + headers_install is subject to be forgotten, but it is essentially
2676 + necessary, not only for building aufs-util.
2677 + You may not meet problems without headers_install in some older
2681 +- read README in aufs-util, build and install it
2682 +- note that your distribution may contain an obsoleted version of
2683 + aufs_type.h in /usr/include/linux or something. When you build aufs
2684 + utilities, make sure that your compiler refers the correct aufs header
2685 + file which is built by "make headers_install."
2686 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2687 + then run "make install_ulib" too. And refer to the aufs manual in
2690 +There several other patches in aufs-standalone.git. They are all
2691 +optional. When you meet some problems, they will help you.
2692 +- aufs6-loopback.patch
2693 + Supports a nested loopback mount in a branch-fs. This patch is
2694 + unnecessary until aufs produces a message like "you may want to try
2695 + another patch for loopback file".
2697 + Modifies a system global kernel internal function get_next_ino() in
2698 + order to stop assigning 0 for an inode-number. Not directly related to
2699 + aufs, but recommended generally.
2701 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2702 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2703 + duplication of inode number, which is important for backup tools and
2704 + other utilities. When you find aufs XINO files for tmpfs branch
2705 + growing too much, try this patch.
2706 +- lockdep-debug.patch
2707 + Similar to some kernel configurations for LOCKDEP (see the top of
2708 + this section), you will need expand some constants in LOCKDEP for
2709 + aufs if you enable CONFIG_LOCKDEP.
2713 +----------------------------------------
2714 +At first, make sure aufs-util are installed, and please read the aufs
2715 +manual, aufs.5 in aufs-util.git tree.
2719 +$ mkdir /tmp/rw /tmp/aufs
2720 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2722 +Here is another example. The result is equivalent.
2723 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2725 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2726 +# mount -o remount,append:${HOME} /tmp/aufs
2728 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2729 +you modify a file under /tmp/aufs, the one on your home directory is
2730 +not affected, instead the same named file will be newly created under
2731 +/tmp/rw. And all of your modification to a file will be applied to
2732 +the one under /tmp/rw. This is called the file based Copy on Write
2734 +Aufs mount options are described in aufs.5.
2735 +If you run chroot or something and make your aufs as a root directory,
2736 +then you need to customize the shutdown script. See the aufs manual in
2739 +Additionally, there are some sample usages of aufs which are a
2740 +diskless system with network booting, and LiveCD over NFS.
2741 +See sample dir in CVS tree on SourceForge.
2745 +----------------------------------------
2746 +When you have any problems or strange behaviour in aufs, please let me
2748 +- /proc/mounts (instead of the output of mount(8))
2749 +- /sys/module/aufs/*
2750 +- /sys/fs/aufs/* (if you have them)
2751 +- /debug/aufs/* (if you have them)
2752 +- linux kernel version
2753 + if your kernel is not plain, for example modified by distributor,
2754 + the url where i can download its source is necessary too.
2755 +- aufs version which was printed at loading the module or booting the
2756 + system, instead of the date you downloaded.
2757 +- configuration (define/undefine CONFIG_AUFS_xxx)
2758 +- kernel configuration or /proc/config.gz (if you have it)
2759 +- LSM (linux security module, if you are using)
2760 +- behaviour which you think to be incorrect
2761 +- actual operation, reproducible one is better
2762 +- mailto: aufs-users at lists.sourceforge.net
2764 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2765 +and Feature Requests) on SourceForge. Please join and write to
2769 +6. Acknowledgements
2770 +----------------------------------------
2771 +Thanks to everyone who have tried and are using aufs, whoever
2772 +have reported a bug or any feedback.
2774 +Especially donators:
2775 +Tomas Matejicek(slax.org) made a donation (much more than once).
2776 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2777 + scripts) is making "doubling" donations.
2778 + Unfortunately I cannot list all of the donators, but I really
2780 + It ends Aug 2010, but the ordinary donation URL is still available.
2781 + <http://sourceforge.net/donate/index.php?group_id=167503>
2782 +Dai Itasaka made a donation (2007/8).
2783 +Chuck Smith made a donation (2008/4, 10 and 12).
2784 +Henk Schoneveld made a donation (2008/9).
2785 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2786 +Francois Dupoux made a donation (2008/11).
2787 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2788 + aufs2 GIT tree (2009/2).
2789 +William Grant made a donation (2009/3).
2790 +Patrick Lane made a donation (2009/4).
2791 +The Mail Archive (mail-archive.com) made donations (2009/5).
2792 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2793 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2794 +Pavel Pronskiy made a donation (2011/2).
2795 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2796 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2797 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2799 +Sam Liddicott made a donation (2011/9).
2800 +Era Scarecrow made a donation (2013/4).
2801 +Bor Ratajc made a donation (2013/4).
2802 +Alessandro Gorreta made a donation (2013/4).
2803 +POIRETTE Marc made a donation (2013/4).
2804 +Alessandro Gorreta made a donation (2013/4).
2805 +lauri kasvandik made a donation (2013/5).
2806 +"pemasu from Finland" made a donation (2013/7).
2807 +The Parted Magic Project made a donation (2013/9 and 11).
2808 +Pavel Barta made a donation (2013/10).
2809 +Nikolay Pertsev made a donation (2014/5).
2810 +James B made a donation (2014/7, 2015/7, and 2021/12).
2811 +Stefano Di Biase made a donation (2014/8).
2812 +Daniel Epellei made a donation (2015/1).
2813 +OmegaPhil made a donation (2016/1, 2018/4).
2814 +Tomasz Szewczyk made a donation (2016/4).
2815 +James Burry made a donation (2016/12).
2816 +Carsten Rose made a donation (2018/9).
2817 +Porteus Kiosk made a donation (2018/10).
2818 +huronOS team: Enya Quetzalli made donations (2022/5, 2023/5 and 8).
2819 +Vasily Mikhaylichenko made a donation (2023/5).
2821 +Thank you very much.
2822 +Donations are always, including future donations, very important and
2823 +helpful for me to keep on developing aufs.
2827 +----------------------------------------
2828 +If you are an experienced user, no explanation is needed. Aufs is
2829 +just a linux filesystem.
2834 +# Local variables: ;
2837 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2838 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2839 +++ linux/fs/aufs/aufs.h 2024-05-13 17:13:00.618070924 +0200
2841 +/* SPDX-License-Identifier: GPL-2.0 */
2843 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2845 + * This program is free software; you can redistribute it and/or modify
2846 + * it under the terms of the GNU General Public License as published by
2847 + * the Free Software Foundation; either version 2 of the License, or
2848 + * (at your option) any later version.
2850 + * This program is distributed in the hope that it will be useful,
2851 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2852 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2853 + * GNU General Public License for more details.
2855 + * You should have received a copy of the GNU General Public License
2856 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2860 + * all header files
2868 +#define AuStub(type, name, body, ...) \
2869 + static inline type name(__VA_ARGS__) { body; }
2871 +#define AuStubVoid(name, ...) \
2872 + AuStub(void, name, , __VA_ARGS__)
2873 +#define AuStubInt0(name, ...) \
2874 + AuStub(int, name, return 0, __VA_ARGS__)
2878 +#include "branch.h"
2881 +#include "dbgaufs.h"
2882 +#include "dentry.h"
2884 +#include "dirren.h"
2887 +#include "fstype.h"
2892 +#include "module.h"
2896 +#include "sysaufs.h"
2901 +#endif /* __KERNEL__ */
2902 +#endif /* __AUFS_H__ */
2903 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2904 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2905 +++ linux/fs/aufs/branch.c 2024-05-13 17:13:00.618070924 +0200
2907 +// SPDX-License-Identifier: GPL-2.0
2909 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2911 + * This program is free software; you can redistribute it and/or modify
2912 + * it under the terms of the GNU General Public License as published by
2913 + * the Free Software Foundation; either version 2 of the License, or
2914 + * (at your option) any later version.
2916 + * This program is distributed in the hope that it will be useful,
2917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2919 + * GNU General Public License for more details.
2921 + * You should have received a copy of the GNU General Public License
2922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2926 + * branch management
2929 +#include <linux/compat.h>
2930 +#include <linux/statfs.h>
2934 + * free a single branch
2936 +static void au_br_do_free(struct au_branch *br)
2939 + struct au_wbr *wbr;
2940 + struct au_dykey **key;
2942 + au_hnotify_fin_br(br);
2943 + /* always, regardless the mount option */
2944 + au_dr_hino_free(&br->br_dirren);
2947 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2948 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2949 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2950 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2954 + for (i = 0; i < AuBrWh_Last; i++)
2955 + dput(wbr->wbr_wh[i]);
2956 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2957 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2960 + if (br->br_fhsm) {
2961 + au_br_fhsm_fin(br->br_fhsm);
2962 + au_kfree_try_rcu(br->br_fhsm);
2965 + key = br->br_dykey;
2966 + for (i = 0; i < AuBrDynOp; i++, key++)
2972 + /* recursive lock, s_umount of branch's */
2973 + /* synchronize_rcu(); */ /* why? */
2975 + path_put(&br->br_path);
2977 + au_kfree_rcu(wbr);
2978 + au_lcnt_wait_for_fin(&br->br_nfiles);
2979 + au_lcnt_wait_for_fin(&br->br_count);
2980 + /* I don't know why, but percpu_refcount requires this */
2981 + /* synchronize_rcu(); */
2986 + * frees all branches
2988 +void au_br_free(struct au_sbinfo *sbinfo)
2990 + aufs_bindex_t bmax;
2991 + struct au_branch **br;
2993 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2995 + bmax = sbinfo->si_bbot + 1;
2996 + br = sbinfo->si_branch;
2998 + au_br_do_free(*br++);
3002 + * find the index of a branch which is specified by @br_id.
3004 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3006 + aufs_bindex_t bindex, bbot;
3008 + bbot = au_sbbot(sb);
3009 + for (bindex = 0; bindex <= bbot; bindex++)
3010 + if (au_sbr_id(sb, bindex) == br_id)
3015 +/* ---------------------------------------------------------------------- */
3021 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3022 + struct dentry *h_root)
3024 + if (unlikely(h_adding == h_root
3025 + || au_test_loopback_overlap(sb, h_adding)))
3027 + if (h_adding->d_sb != h_root->d_sb)
3029 + return au_test_subdir(h_adding, h_root)
3030 + || au_test_subdir(h_root, h_adding);
3034 + * returns a newly allocated branch. @new_nbranch is a number of branches
3035 + * after adding a branch.
3037 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3040 + struct au_branch *add_branch;
3041 + struct dentry *root;
3042 + struct inode *inode;
3046 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3047 + if (unlikely(!add_branch))
3049 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3050 + if (unlikely(!add_branch->br_xino))
3052 + err = au_hnotify_init_br(add_branch, perm);
3053 + if (unlikely(err))
3056 + if (au_br_writable(perm)) {
3057 + /* may be freed separately at changing the branch permission */
3058 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3060 + if (unlikely(!add_branch->br_wbr))
3064 + if (au_br_fhsm(perm)) {
3065 + err = au_fhsm_br_alloc(add_branch);
3066 + if (unlikely(err))
3070 + root = sb->s_root;
3071 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3073 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3075 + inode = d_inode(root);
3076 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3080 + return add_branch; /* success */
3083 + au_kfree_rcu(add_branch->br_wbr);
3085 + au_hnotify_fin_br(add_branch);
3087 + au_xino_put(add_branch);
3089 + au_kfree_rcu(add_branch);
3091 + return ERR_PTR(err);
3095 + * test if the branch permission is legal or not.
3097 +static int test_br(struct inode *inode, int brperm, char *path)
3101 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3106 + pr_err("write permission for readonly mount or inode, %s\n", path);
3114 + * 0: success, the caller will add it
3115 + * plus: success, it is already unified, the caller should ignore it
3118 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3121 + aufs_bindex_t bbot, bindex;
3122 + struct dentry *root, *h_dentry;
3123 + struct inode *inode, *h_inode;
3125 + root = sb->s_root;
3126 + bbot = au_sbbot(sb);
3127 + if (unlikely(bbot >= 0
3128 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3132 + pr_err("%s duplicated\n", add->pathname);
3137 + err = -ENOSPC; /* -E2BIG; */
3138 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3139 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3140 + pr_err("number of branches exceeded %s\n", add->pathname);
3145 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3146 + pr_err("bad index %d\n", add->bindex);
3150 + inode = d_inode(add->path.dentry);
3152 + if (unlikely(!inode->i_nlink)) {
3153 + pr_err("no existence %s\n", add->pathname);
3158 + if (unlikely(inode->i_sb == sb)) {
3159 + pr_err("%s must be outside\n", add->pathname);
3163 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3164 + pr_err("unsupported filesystem, %s (%s)\n",
3165 + add->pathname, au_sbtype(inode->i_sb));
3169 + if (unlikely(inode->i_sb->s_stack_depth)) {
3170 + pr_err("already stacked, %s (%s)\n",
3171 + add->pathname, au_sbtype(inode->i_sb));
3175 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3176 + if (unlikely(err))
3180 + return 0; /* success */
3183 + for (bindex = 0; bindex <= bbot; bindex++)
3184 + if (unlikely(test_overlap(sb, add->path.dentry,
3185 + au_h_dptr(root, bindex)))) {
3186 + pr_err("%s is overlapped\n", add->pathname);
3191 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3192 + h_dentry = au_h_dptr(root, 0);
3193 + h_inode = d_inode(h_dentry);
3194 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3195 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3196 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3197 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3199 + i_uid_read(inode), i_gid_read(inode),
3200 + (inode->i_mode & S_IALLUGO),
3201 + i_uid_read(h_inode), i_gid_read(h_inode),
3202 + (h_inode->i_mode & S_IALLUGO));
3210 + * initialize or clean the whiteouts for an adding branch
3212 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3215 + int err, old_perm;
3216 + aufs_bindex_t bindex;
3217 + struct inode *h_inode;
3218 + struct au_wbr *wbr;
3219 + struct au_hinode *hdir;
3220 + struct dentry *h_dentry;
3222 + err = vfsub_mnt_want_write(au_br_mnt(br));
3223 + if (unlikely(err))
3227 + old_perm = br->br_perm;
3228 + br->br_perm = new_perm;
3231 + bindex = au_br_index(sb, br->br_id);
3232 + if (0 <= bindex) {
3233 + hdir = au_hi(d_inode(sb->s_root), bindex);
3234 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3236 + h_dentry = au_br_dentry(br);
3237 + h_inode = d_inode(h_dentry);
3238 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3241 + err = au_wh_init(br, sb);
3243 + wbr_wh_write_lock(wbr);
3244 + err = au_wh_init(br, sb);
3245 + wbr_wh_write_unlock(wbr);
3248 + au_hn_inode_unlock(hdir);
3250 + inode_unlock(h_inode);
3251 + vfsub_mnt_drop_write(au_br_mnt(br));
3252 + br->br_perm = old_perm;
3254 + if (!err && wbr && !au_br_writable(new_perm)) {
3255 + au_kfree_rcu(wbr);
3256 + br->br_wbr = NULL;
3263 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3267 + struct kstatfs kst;
3268 + struct au_wbr *wbr;
3271 + au_rw_init(&wbr->wbr_wh_rwsem);
3272 + atomic_set(&wbr->wbr_wh_running, 0);
3275 + * a limit for rmdir/rename a dir
3276 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3278 + err = vfs_statfs(&br->br_path, &kst);
3279 + if (unlikely(err))
3282 + if (kst.f_namelen >= NAME_MAX)
3283 + err = au_br_init_wh(sb, br, perm);
3285 + pr_err("%pd(%s), unsupported namelen %ld\n",
3287 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3293 +/* initialize a new branch */
3294 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3295 + struct au_opt_add *add)
3298 + struct au_branch *brbase;
3300 + struct inode *h_inode;
3303 + br->br_perm = add->perm;
3304 + br->br_path = add->path; /* set first, path_get() later */
3305 + spin_lock_init(&br->br_dykey_lock);
3306 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3307 + au_lcnt_init(&br->br_count, /*release*/NULL);
3308 + br->br_id = au_new_br_id(sb);
3309 + AuDebugOn(br->br_id < 0);
3311 + /* always, regardless the given option */
3312 + err = au_dr_br_init(sb, br, &add->path);
3313 + if (unlikely(err))
3316 + if (au_br_writable(add->perm)) {
3317 + err = au_wbr_init(br, sb, add->perm);
3318 + if (unlikely(err))
3322 + if (au_opt_test(au_mntflags(sb), XINO)) {
3323 + brbase = au_sbr(sb, 0);
3324 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3326 + h_inode = d_inode(add->path.dentry);
3327 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3328 + if (unlikely(err)) {
3329 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3334 + sysaufs_br_init(br);
3335 + path_get(&br->br_path);
3336 + goto out; /* success */
3339 + memset(&br->br_path, 0, sizeof(br->br_path));
3344 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3345 + struct au_branch *br, aufs_bindex_t bbot,
3346 + aufs_bindex_t amount)
3348 + struct au_branch **brp;
3350 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3352 + brp = sbinfo->si_branch + bindex;
3353 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3355 + sbinfo->si_bbot++;
3356 + if (unlikely(bbot < 0))
3357 + sbinfo->si_bbot = 0;
3360 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3361 + aufs_bindex_t bbot, aufs_bindex_t amount)
3363 + struct au_hdentry *hdp;
3365 + AuRwMustWriteLock(&dinfo->di_rwsem);
3367 + hdp = au_hdentry(dinfo, bindex);
3368 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3369 + au_h_dentry_init(hdp);
3371 + if (unlikely(bbot < 0))
3372 + dinfo->di_btop = 0;
3375 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3376 + aufs_bindex_t bbot, aufs_bindex_t amount)
3378 + struct au_hinode *hip;
3380 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3382 + hip = au_hinode(iinfo, bindex);
3383 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3384 + au_hinode_init(hip);
3386 + if (unlikely(bbot < 0))
3387 + iinfo->ii_btop = 0;
3390 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3391 + aufs_bindex_t bindex)
3393 + struct dentry *root, *h_dentry;
3394 + struct inode *root_inode, *h_inode;
3395 + aufs_bindex_t bbot, amount;
3397 + root = sb->s_root;
3398 + root_inode = d_inode(root);
3399 + bbot = au_sbbot(sb);
3400 + amount = bbot + 1 - bindex;
3401 + h_dentry = au_br_dentry(br);
3402 + au_sbilist_lock();
3403 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3404 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3405 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3406 + au_set_h_dptr(root, bindex, dget(h_dentry));
3407 + h_inode = d_inode(h_dentry);
3408 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3409 + au_sbilist_unlock();
3412 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3415 + aufs_bindex_t bbot, add_bindex;
3416 + struct dentry *root, *h_dentry;
3417 + struct inode *root_inode;
3418 + struct au_branch *add_branch;
3420 + root = sb->s_root;
3421 + root_inode = d_inode(root);
3422 + IMustLock(root_inode);
3423 + IiMustWriteLock(root_inode);
3424 + err = test_add(sb, add, remount);
3425 + if (unlikely(err < 0))
3429 + goto out; /* success */
3432 + bbot = au_sbbot(sb);
3433 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3434 + err = PTR_ERR(add_branch);
3435 + if (IS_ERR(add_branch))
3438 + err = au_br_init(add_branch, sb, add);
3439 + if (unlikely(err)) {
3440 + au_br_do_free(add_branch);
3444 + add_bindex = add->bindex;
3445 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3446 + au_br_do_add(sb, add_branch, add_bindex);
3447 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3448 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3450 + h_dentry = add->path.dentry;
3451 + if (!add_bindex) {
3452 + au_cpup_attr_all(root_inode, /*force*/1);
3453 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3455 + au_add_nlink(root_inode, d_inode(h_dentry));
3461 +/* ---------------------------------------------------------------------- */
3463 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3464 + unsigned long long max __maybe_unused,
3467 + unsigned long long n;
3468 + struct file **p, *f;
3469 + struct hlist_bl_head *files;
3470 + struct hlist_bl_node *pos;
3471 + struct au_finfo *finfo;
3475 + files = &au_sbi(sb)->si_files;
3476 + hlist_bl_lock(files);
3477 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3478 + f = finfo->fi_file;
3480 + && !special_file(file_inode(f)->i_mode)) {
3484 + AuDebugOn(n > max);
3487 + hlist_bl_unlock(files);
3492 +static struct file **au_farray_alloc(struct super_block *sb,
3493 + unsigned long long *max)
3495 + struct au_sbinfo *sbi;
3498 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3499 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3502 +static void au_farray_free(struct file **a, unsigned long long max)
3504 + unsigned long long ull;
3506 + for (ull = 0; ull < max; ull++)
3512 +/* ---------------------------------------------------------------------- */
3518 +/* to show the line number, do not make it inlined function */
3519 +#define AuVerbose(do_info, fmt, ...) do { \
3521 + pr_info(fmt, ##__VA_ARGS__); \
3524 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3525 + aufs_bindex_t bbot)
3527 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3530 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3531 + aufs_bindex_t bbot)
3533 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3537 + * test if the branch is deletable or not.
3539 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3540 + unsigned int sigen, const unsigned int verbose)
3542 + int err, i, j, ndentry;
3543 + aufs_bindex_t btop, bbot;
3544 + struct au_dcsub_pages dpages;
3545 + struct au_dpage *dpage;
3548 + err = au_dpages_init(&dpages, GFP_NOFS);
3549 + if (unlikely(err))
3551 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3552 + if (unlikely(err))
3555 + for (i = 0; !err && i < dpages.ndpage; i++) {
3556 + dpage = dpages.dpages + i;
3557 + ndentry = dpage->ndentry;
3558 + for (j = 0; !err && j < ndentry; j++) {
3559 + d = dpage->dentries[j];
3560 + AuDebugOn(au_dcount(d) <= 0);
3561 + if (!au_digen_test(d, sigen)) {
3562 + di_read_lock_child(d, AuLock_IR);
3563 + if (unlikely(au_dbrange_test(d))) {
3564 + di_read_unlock(d, AuLock_IR);
3568 + di_write_lock_child(d);
3569 + if (unlikely(au_dbrange_test(d))) {
3570 + di_write_unlock(d);
3573 + err = au_reval_dpath(d, sigen);
3575 + di_downgrade_lock(d, AuLock_IR);
3577 + di_write_unlock(d);
3582 + /* AuDbgDentry(d); */
3583 + btop = au_dbtop(d);
3584 + bbot = au_dbbot(d);
3585 + if (btop <= bindex
3587 + && au_h_dptr(d, bindex)
3588 + && au_test_dbusy(d, btop, bbot)) {
3590 + AuVerbose(verbose, "busy %pd\n", d);
3593 + di_read_unlock(d, AuLock_IR);
3598 + au_dpages_free(&dpages);
3603 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3604 + unsigned int sigen, const unsigned int verbose)
3607 + unsigned long long max, ull;
3608 + struct inode *i, **array;
3609 + aufs_bindex_t btop, bbot;
3611 + array = au_iarray_alloc(sb, &max);
3612 + err = PTR_ERR(array);
3613 + if (IS_ERR(array))
3617 + AuDbg("b%d\n", bindex);
3618 + for (ull = 0; !err && ull < max; ull++) {
3622 + if (i->i_ino == AUFS_ROOT_INO)
3625 + /* AuDbgInode(i); */
3626 + if (au_iigen(i, NULL) == sigen)
3627 + ii_read_lock_child(i);
3629 + ii_write_lock_child(i);
3630 + err = au_refresh_hinode_self(i);
3633 + ii_downgrade_lock(i);
3635 + ii_write_unlock(i);
3640 + btop = au_ibtop(i);
3641 + bbot = au_ibbot(i);
3642 + if (btop <= bindex
3644 + && au_h_iptr(i, bindex)
3645 + && au_test_ibusy(i, btop, bbot)) {
3647 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3650 + ii_read_unlock(i);
3652 + au_iarray_free(array, max);
3658 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3659 + const unsigned int verbose)
3662 + unsigned int sigen;
3664 + sigen = au_sigen(root->d_sb);
3665 + DiMustNoWaiters(root);
3666 + IiMustNoWaiters(d_inode(root));
3667 + di_write_unlock(root);
3668 + err = test_dentry_busy(root, bindex, sigen, verbose);
3670 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3671 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3676 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3677 + struct file **to_free, int *idx)
3680 + unsigned char matched, root;
3681 + aufs_bindex_t bindex, bbot;
3682 + struct au_fidir *fidir;
3683 + struct au_hfile *hfile;
3686 + root = IS_ROOT(file->f_path.dentry);
3689 + to_free[*idx] = file;
3695 + fidir = au_fi(file)->fi_hdir;
3696 + AuDebugOn(!fidir);
3697 + bbot = au_fbbot_dir(file);
3698 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3699 + hfile = fidir->fd_hfile + bindex;
3700 + if (!hfile->hf_file)
3703 + if (hfile->hf_br->br_id == br_id) {
3715 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3716 + struct file **to_free, int opened)
3719 + unsigned long long ull, max;
3720 + aufs_bindex_t btop;
3721 + struct file *file, **array;
3722 + struct dentry *root;
3723 + struct au_hfile *hfile;
3725 + array = au_farray_alloc(sb, &max);
3726 + err = PTR_ERR(array);
3727 + if (IS_ERR(array))
3732 + root = sb->s_root;
3733 + di_write_unlock(root);
3734 + for (ull = 0; ull < max; ull++) {
3735 + file = array[ull];
3736 + if (unlikely(!file))
3739 + /* AuDbg("%pD\n", file); */
3740 + fi_read_lock(file);
3741 + btop = au_fbtop(file);
3742 + if (!d_is_dir(file->f_path.dentry)) {
3743 + hfile = &au_fi(file)->fi_htop;
3744 + if (hfile->hf_br->br_id == br_id)
3747 + err = test_dir_busy(file, br_id, to_free, &idx);
3748 + fi_read_unlock(file);
3749 + if (unlikely(err))
3752 + di_write_lock_child(root);
3753 + au_farray_free(array, max);
3754 + AuDebugOn(idx > opened);
3760 +static void br_del_file(struct file **to_free, unsigned long long opened,
3761 + aufs_bindex_t br_id)
3763 + unsigned long long ull;
3764 + aufs_bindex_t bindex, btop, bbot, bfound;
3765 + struct file *file;
3766 + struct au_fidir *fidir;
3767 + struct au_hfile *hfile;
3769 + for (ull = 0; ull < opened; ull++) {
3770 + file = to_free[ull];
3771 + if (unlikely(!file))
3774 + /* AuDbg("%pD\n", file); */
3775 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3777 + fidir = au_fi(file)->fi_hdir;
3778 + AuDebugOn(!fidir);
3779 + fi_write_lock(file);
3780 + btop = au_fbtop(file);
3781 + bbot = au_fbbot_dir(file);
3782 + for (bindex = btop; bindex <= bbot; bindex++) {
3783 + hfile = fidir->fd_hfile + bindex;
3784 + if (!hfile->hf_file)
3787 + if (hfile->hf_br->br_id == br_id) {
3792 + AuDebugOn(bfound < 0);
3793 + au_set_h_fptr(file, bfound, NULL);
3794 + if (bfound == btop) {
3795 + for (btop++; btop <= bbot; btop++)
3796 + if (au_hf_dir(file, btop)) {
3797 + au_set_fbtop(file, btop);
3801 + fi_write_unlock(file);
3805 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3806 + const aufs_bindex_t bindex,
3807 + const aufs_bindex_t bbot)
3809 + struct au_branch **brp, **p;
3811 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3813 + brp = sbinfo->si_branch + bindex;
3814 + if (bindex < bbot)
3815 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3816 + sbinfo->si_branch[0 + bbot] = NULL;
3817 + sbinfo->si_bbot--;
3819 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3822 + sbinfo->si_branch = p;
3823 + /* harmless error */
3826 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3827 + const aufs_bindex_t bbot)
3829 + struct au_hdentry *hdp, *p;
3831 + AuRwMustWriteLock(&dinfo->di_rwsem);
3833 + hdp = au_hdentry(dinfo, bindex);
3834 + if (bindex < bbot)
3835 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3836 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3839 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3842 + dinfo->di_hdentry = p;
3843 + /* harmless error */
3846 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3847 + const aufs_bindex_t bbot)
3849 + struct au_hinode *hip, *p;
3851 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3853 + hip = au_hinode(iinfo, bindex);
3854 + if (bindex < bbot)
3855 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3856 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3859 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3862 + iinfo->ii_hinode = p;
3863 + /* harmless error */
3866 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3867 + struct au_branch *br)
3869 + aufs_bindex_t bbot;
3870 + struct au_sbinfo *sbinfo;
3871 + struct dentry *root, *h_root;
3872 + struct inode *inode, *h_inode;
3873 + struct au_hinode *hinode;
3875 + SiMustWriteLock(sb);
3877 + root = sb->s_root;
3878 + inode = d_inode(root);
3879 + sbinfo = au_sbi(sb);
3880 + bbot = sbinfo->si_bbot;
3882 + h_root = au_h_dptr(root, bindex);
3883 + hinode = au_hi(inode, bindex);
3884 + h_inode = au_igrab(hinode->hi_inode);
3887 + au_sbilist_lock();
3888 + au_br_do_del_brp(sbinfo, bindex, bbot);
3889 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3890 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3891 + au_sbilist_unlock();
3893 + /* ignore an error */
3894 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3898 + au_br_do_free(br);
3901 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3902 + unsigned long long max, void *arg)
3907 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3910 + unsigned long long opened;
3911 + unsigned int mnt_flags;
3912 + aufs_bindex_t bindex, bbot, br_id;
3913 + unsigned char do_wh, verbose;
3914 + struct au_branch *br;
3915 + struct au_wbr *wbr;
3916 + struct dentry *root;
3917 + struct file **to_free;
3922 + root = sb->s_root;
3923 + bindex = au_find_dbindex(root, del->h_path.dentry);
3926 + goto out; /* success */
3928 + pr_err("%s no such branch\n", del->pathname);
3931 + AuDbg("bindex b%d\n", bindex);
3934 + mnt_flags = au_mntflags(sb);
3935 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3936 + bbot = au_sbbot(sb);
3937 + if (unlikely(!bbot)) {
3938 + AuVerbose(verbose, "no more branches left\n");
3942 + br = au_sbr(sb, bindex);
3943 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3944 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3945 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3949 + br_id = br->br_id;
3950 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3951 + if (unlikely(opened)) {
3952 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3953 + err = PTR_ERR(to_free);
3954 + if (IS_ERR(to_free))
3957 + err = test_file_busy(sb, br_id, to_free, opened);
3958 + if (unlikely(err)) {
3959 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3965 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3967 + /* instead of WbrWhMustWriteLock(wbr) */
3968 + SiMustWriteLock(sb);
3969 + for (i = 0; i < AuBrWh_Last; i++) {
3970 + dput(wbr->wbr_wh[i]);
3971 + wbr->wbr_wh[i] = NULL;
3975 + err = test_children_busy(root, bindex, verbose);
3976 + if (unlikely(err)) {
3985 + * now we confirmed the branch is deletable.
3986 + * let's free the remaining opened dirs on the branch.
3988 + di_write_unlock(root);
3989 + br_del_file(to_free, opened, br_id);
3990 + di_write_lock_child(root);
3993 + sysaufs_brs_del(sb, bindex); /* remove successors */
3994 + dbgaufs_xino_del(br); /* remove one */
3995 + au_br_do_del(sb, bindex, br);
3996 + sysaufs_brs_add(sb, bindex); /* append successors */
3997 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4000 + au_cpup_attr_all(d_inode(root), /*force*/1);
4001 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4003 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4004 + if (au_opt_test(mnt_flags, PLINK))
4005 + au_plink_half_refresh(sb, br_id);
4007 + goto out; /* success */
4011 + rerr = au_br_init_wh(sb, br, br->br_perm);
4013 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4014 + del->pathname, rerr);
4017 + au_farray_free(to_free, opened);
4021 +/* ---------------------------------------------------------------------- */
4023 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4026 + aufs_bindex_t btop, bbot;
4027 + struct aufs_ibusy ibusy;
4028 + struct inode *inode, *h_inode;
4031 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4034 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4036 + /* VERIFY_WRITE */
4037 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4038 + if (unlikely(err)) {
4045 + si_read_lock(sb, AuLock_FLUSH);
4046 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4050 + ibusy.h_ino = 0; /* invalid */
4051 + inode = ilookup(sb, ibusy.ino);
4053 + || inode->i_ino == AUFS_ROOT_INO
4054 + || au_is_bad_inode(inode))
4057 + ii_read_lock_child(inode);
4058 + btop = au_ibtop(inode);
4059 + bbot = au_ibbot(inode);
4060 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4061 + h_inode = au_h_iptr(inode, ibusy.bindex);
4062 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4063 + ibusy.h_ino = h_inode->i_ino;
4065 + ii_read_unlock(inode);
4069 + si_read_unlock(sb);
4071 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4072 + if (unlikely(err)) {
4081 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4083 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4086 +#ifdef CONFIG_COMPAT
4087 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4089 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4093 +/* ---------------------------------------------------------------------- */
4096 + * change a branch permission
4099 +static void au_warn_ima(void)
4102 + /* since it doesn't support mark_files_ro() */
4103 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4107 +static int do_need_sigen_inc(int a, int b)
4109 + return au_br_whable(a) && !au_br_whable(b);
4112 +static int need_sigen_inc(int old, int new)
4114 + return do_need_sigen_inc(old, new)
4115 + || do_need_sigen_inc(new, old);
4118 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4121 + unsigned int mnt_flags;
4122 + unsigned long long ull, max;
4123 + aufs_bindex_t br_id;
4124 + unsigned char verbose, writer;
4125 + struct file *file, *hf, **array;
4126 + struct au_hfile *hfile;
4127 + struct inode *h_inode;
4129 + mnt_flags = au_mntflags(sb);
4130 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4132 + array = au_farray_alloc(sb, &max);
4133 + err = PTR_ERR(array);
4134 + if (IS_ERR(array))
4138 + br_id = au_sbr_id(sb, bindex);
4139 + for (ull = 0; ull < max; ull++) {
4140 + file = array[ull];
4141 + if (unlikely(!file))
4144 + /* AuDbg("%pD\n", file); */
4145 + fi_read_lock(file);
4146 + if (unlikely(au_test_mmapped(file))) {
4148 + AuVerbose(verbose, "mmapped %pD\n", file);
4150 + FiMustNoWaiters(file);
4151 + fi_read_unlock(file);
4155 + hfile = &au_fi(file)->fi_htop;
4156 + hf = hfile->hf_file;
4157 + if (!d_is_reg(file->f_path.dentry)
4158 + || !(file->f_mode & FMODE_WRITE)
4159 + || hfile->hf_br->br_id != br_id
4160 + || !(hf->f_mode & FMODE_WRITE))
4161 + array[ull] = NULL;
4167 + FiMustNoWaiters(file);
4168 + fi_read_unlock(file);
4176 + for (ull = 0; ull < max; ull++) {
4177 + file = array[ull];
4181 + /* todo: already flushed? */
4183 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4184 + * approach which resets f_mode and calls mnt_drop_write() and
4185 + * file_release_write() for each file, because the branch
4186 + * attribute in aufs world is totally different from the native
4189 + /* fi_read_lock(file); */
4190 + hfile = &au_fi(file)->fi_htop;
4191 + hf = hfile->hf_file;
4192 + /* fi_read_unlock(file); */
4193 + spin_lock(&hf->f_lock);
4194 + writer = !!(hf->f_mode & FMODE_WRITER);
4195 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4196 + spin_unlock(&hf->f_lock);
4198 + h_inode = file_inode(hf);
4199 + if (hf->f_mode & FMODE_READ)
4200 + i_readcount_inc(h_inode);
4201 + put_write_access(h_inode);
4202 + mnt_put_write_access(hf->f_path.mnt);
4207 + au_farray_free(array, max);
4213 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4217 + aufs_bindex_t bindex;
4218 + struct dentry *root;
4219 + struct au_branch *br;
4220 + struct au_br_fhsm *bf;
4222 + root = sb->s_root;
4223 + bindex = au_find_dbindex(root, mod->h_root);
4226 + return 0; /* success */
4228 + pr_err("%s no such branch\n", mod->path);
4231 + AuDbg("bindex b%d\n", bindex);
4233 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4234 + if (unlikely(err))
4237 + br = au_sbr(sb, bindex);
4238 + AuDebugOn(mod->h_root != au_br_dentry(br));
4239 + if (br->br_perm == mod->perm)
4240 + return 0; /* success */
4242 + /* pre-allocate for non-fhsm --> fhsm */
4244 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4245 + err = au_fhsm_br_alloc(br);
4246 + if (unlikely(err))
4249 + br->br_fhsm = NULL;
4252 + if (au_br_writable(br->br_perm)) {
4253 + /* remove whiteout base */
4254 + err = au_br_init_wh(sb, br, mod->perm);
4255 + if (unlikely(err))
4258 + if (!au_br_writable(mod->perm)) {
4259 + /* rw --> ro, file might be mmapped */
4260 + DiMustNoWaiters(root);
4261 + IiMustNoWaiters(d_inode(root));
4262 + di_write_unlock(root);
4263 + err = au_br_mod_files_ro(sb, bindex);
4264 + /* aufs_write_lock() calls ..._child() */
4265 + di_write_lock_child(root);
4267 + if (unlikely(err)) {
4269 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4272 + rerr = au_wbr_init(br, sb, br->br_perm);
4273 + if (unlikely(rerr)) {
4274 + AuIOErr("nested error %d (%d)\n",
4276 + br->br_perm = mod->perm;
4280 + } else if (au_br_writable(mod->perm)) {
4283 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4285 + err = au_wbr_init(br, sb, mod->perm);
4286 + if (unlikely(err)) {
4287 + au_kfree_rcu(br->br_wbr);
4288 + br->br_wbr = NULL;
4292 + if (unlikely(err))
4295 + if (au_br_fhsm(br->br_perm)) {
4296 + if (!au_br_fhsm(mod->perm)) {
4297 + /* fhsm --> non-fhsm */
4298 + au_br_fhsm_fin(br->br_fhsm);
4299 + au_kfree_rcu(br->br_fhsm);
4300 + br->br_fhsm = NULL;
4302 + } else if (au_br_fhsm(mod->perm))
4303 + /* non-fhsm --> fhsm */
4306 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4307 + br->br_perm = mod->perm;
4308 + goto out; /* success */
4311 + au_kfree_try_rcu(bf);
4317 +/* ---------------------------------------------------------------------- */
4319 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4322 + struct kstatfs kstfs;
4324 + err = vfs_statfs(&br->br_path, &kstfs);
4326 + stfs->f_blocks = kstfs.f_blocks;
4327 + stfs->f_bavail = kstfs.f_bavail;
4328 + stfs->f_files = kstfs.f_files;
4329 + stfs->f_ffree = kstfs.f_ffree;
4334 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4335 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4336 +++ linux/fs/aufs/branch.h 2024-05-13 17:13:00.618070924 +0200
4338 +/* SPDX-License-Identifier: GPL-2.0 */
4340 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4342 + * This program is free software; you can redistribute it and/or modify
4343 + * it under the terms of the GNU General Public License as published by
4344 + * the Free Software Foundation; either version 2 of the License, or
4345 + * (at your option) any later version.
4347 + * This program is distributed in the hope that it will be useful,
4348 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4349 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4350 + * GNU General Public License for more details.
4352 + * You should have received a copy of the GNU General Public License
4353 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4357 + * branch filesystems and xino for them
4360 +#ifndef __AUFS_BRANCH_H__
4361 +#define __AUFS_BRANCH_H__
4365 +#include <linux/mount.h>
4366 +#include "dirren.h"
4372 +/* ---------------------------------------------------------------------- */
4376 + struct file **xi_file;
4377 + unsigned int xi_nfile;
4383 + /* reserved for future use */
4384 + /* unsigned long *bitmap; */
4385 + wait_queue_head_t wqh;
4388 + struct mutex xi_mtx; /* protects xi_file array */
4389 + struct hlist_bl_head xi_writing;
4391 + atomic_t xi_truncating;
4393 + struct kref xi_kref;
4396 +/* File-based Hierarchical Storage Management */
4397 +struct au_br_fhsm {
4398 +#ifdef CONFIG_AUFS_FHSM
4399 + struct mutex bf_lock;
4400 + unsigned long bf_jiffy;
4401 + struct aufs_stfs bf_stfs;
4406 +/* members for writable branch only */
4407 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4409 + struct au_rwsem wbr_wh_rwsem;
4410 + struct dentry *wbr_wh[AuBrWh_Last];
4411 + atomic_t wbr_wh_running;
4412 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4413 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4414 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4417 + unsigned long long wbr_bytes;
4420 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4421 +#define AuBrDynOp (AuDyLast * 4)
4423 +#ifdef CONFIG_AUFS_HFSNOTIFY
4424 +/* support for asynchronous destruction */
4425 +struct au_br_hfsnotify {
4426 + struct fsnotify_group *hfsn_group;
4430 +/* sysfs entries */
4431 +struct au_brsysfs {
4433 + struct attribute attr;
4442 +/* protected by superblock rwsem */
4444 + struct au_xino *br_xino;
4446 + aufs_bindex_t br_id;
4449 + struct path br_path;
4450 + spinlock_t br_dykey_lock;
4451 + struct au_dykey *br_dykey[AuBrDynOp];
4452 + au_lcnt_t br_nfiles; /* opened files */
4453 + au_lcnt_t br_count; /* in-use for other */
4455 + struct au_wbr *br_wbr;
4456 + struct au_br_fhsm *br_fhsm;
4458 +#ifdef CONFIG_AUFS_HFSNOTIFY
4459 + struct au_br_hfsnotify *br_hfsn;
4462 +#ifdef CONFIG_SYSFS
4463 + /* entries under sysfs per mount-point */
4464 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4467 +#ifdef CONFIG_DEBUG_FS
4468 + struct dentry *br_dbgaufs; /* xino */
4471 + struct au_dr_br br_dirren;
4474 +/* ---------------------------------------------------------------------- */
4476 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4478 + return br->br_path.mnt;
4481 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4483 + return br->br_path.dentry;
4486 +static inline struct mnt_idmap *au_br_idmap(struct au_branch *br)
4488 + return mnt_idmap(br->br_path.mnt);
4491 +static inline struct super_block *au_br_sb(struct au_branch *br)
4493 + return au_br_mnt(br)->mnt_sb;
4496 +static inline int au_br_rdonly(struct au_branch *br)
4498 + return (sb_rdonly(au_br_sb(br))
4499 + || !au_br_writable(br->br_perm))
4503 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4505 +#ifdef CONFIG_AUFS_HNOTIFY
4506 + return !(brperm & AuBrPerm_RR);
4512 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4514 + int err, exec_flag;
4517 + exec_flag = oflag & __FMODE_EXEC;
4518 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4524 +static inline void au_xino_get(struct au_branch *br)
4526 + struct au_xino *xi;
4530 + kref_get(&xi->xi_kref);
4533 +static inline int au_xino_count(struct au_branch *br)
4536 + struct au_xino *xi;
4541 + v = kref_read(&xi->xi_kref);
4546 +/* ---------------------------------------------------------------------- */
4550 +void au_br_free(struct au_sbinfo *sinfo);
4551 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4553 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4555 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4556 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4557 +#ifdef CONFIG_COMPAT
4558 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4561 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4564 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4567 +static const loff_t au_loff_max = LLONG_MAX;
4569 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4570 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4572 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4573 + struct file *copy_src);
4575 + struct au_xino *xi; /* switch between xino and xigen */
4577 + struct path *base;
4578 + struct file *copy_src;
4580 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4582 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4584 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4586 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4587 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4589 +int au_xib_trunc(struct super_block *sb);
4590 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4592 +struct au_xino *au_xino_alloc(unsigned int nfile);
4593 +int au_xino_put(struct au_branch *br);
4594 +struct file *au_xino_file1(struct au_xino *xi);
4596 +struct au_opt_xino;
4597 +void au_xino_clr(struct super_block *sb);
4598 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4599 +struct file *au_xino_def(struct super_block *sb);
4600 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4601 + struct path *base);
4603 +ino_t au_xino_new_ino(struct super_block *sb);
4604 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4606 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4607 + ino_t h_ino, int idx);
4608 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4611 +int au_xino_path(struct seq_file *seq, struct file *file);
4613 +/* ---------------------------------------------------------------------- */
4615 +/* @idx is signed to accept -1 meaning the first file */
4616 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4618 + struct file *file;
4625 + if (idx < xi->xi_nfile)
4626 + file = xi->xi_file[idx];
4628 + file = au_xino_file1(xi);
4634 +/* ---------------------------------------------------------------------- */
4636 +/* Superblock to branch */
4638 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4640 + return au_sbr(sb, bindex)->br_id;
4644 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4646 + return au_br_mnt(au_sbr(sb, bindex));
4650 +struct mnt_idmap *au_sbr_idmap(struct super_block *sb, aufs_bindex_t bindex)
4652 + return au_br_idmap(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 2024-05-13 17:13:00.618070924 +0200
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 2024-05-13 17:13:00.618070924 +0200
4761 +// SPDX-License-Identifier: GPL-2.0
4763 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4765 + * This program 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 = inode_get_atime(h_inode);
4897 + dt->dt_mtime = inode_get_mtime(h_inode);
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 path *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 + br = au_sbr(dst->d_sb, bindex);
4940 + h_path.mnt = au_br_mnt(br);
4941 + h_path.dentry = au_h_dptr(dst, bindex);
4942 + h_idst = d_inode(h_path.dentry);
4943 + h_isrc = d_inode(h_src->dentry);
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 = inode_get_atime(h_isrc);
4964 + ia.ia_mtime = inode_get_mtime(h_isrc);
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, 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 path *h_path, umode_t mode)
5355 + struct dentry *h_dentry;
5356 + /* struct inode *h_inode; */
5357 + struct mnt_idmap *h_idmap;
5359 + h_idmap = mnt_idmap(h_path->mnt);
5360 + h_dentry = h_path->dentry;
5361 + /* h_inode = d_inode(h_dentry); */
5362 + /* forget_all_cached_acls(h_inode)); */
5363 + err = vfsub_remove_acl(h_idmap, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5365 + if (err == -EOPNOTSUPP)
5368 + err = vfsub_acl_chmod(h_idmap, h_dentry, mode);
5374 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5375 + struct inode *h_dir, struct path *h_path)
5378 + struct inode *dir, *inode;
5379 + struct mnt_idmap *h_idmap;
5381 + h_idmap = mnt_idmap(h_path->mnt);
5382 + err = vfsub_remove_acl(h_idmap, h_path->dentry,
5383 + XATTR_NAME_POSIX_ACL_DEFAULT);
5385 + if (err == -EOPNOTSUPP)
5387 + if (unlikely(err))
5391 + * strange behaviour from the users view,
5392 + * particularly setattr case
5394 + dir = d_inode(dst_parent);
5395 + if (au_ibtop(dir) == cpg->bdst)
5396 + au_cpup_attr_nlink(dir, /*force*/1);
5397 + inode = d_inode(cpg->dentry);
5398 + au_cpup_attr_nlink(inode, /*force*/1);
5404 +static noinline_for_stack
5405 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5406 + struct au_cpup_reg_attr *h_src_attr)
5410 + unsigned int mnt_flags;
5411 + unsigned char isdir, isreg, force;
5412 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5413 + struct au_dtime dt;
5414 + struct path h_path;
5415 + struct dentry *h_src, *h_dst, *h_parent;
5416 + struct inode *h_inode, *h_dir;
5417 + struct super_block *sb;
5419 + /* bsrc branch can be ro/rw. */
5420 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5421 + h_inode = d_inode(h_src);
5422 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5424 + /* try stopping to be referenced while we are creating */
5425 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5426 + if (au_ftest_cpup(cpg->flags, RENAME))
5427 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5428 + AUFS_WH_PFX_LEN));
5429 + h_parent = h_dst->d_parent; /* dir inode is locked */
5430 + h_dir = d_inode(h_parent);
5432 + AuDebugOn(h_parent != h_dst->d_parent);
5434 + sb = cpg->dentry->d_sb;
5435 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5437 + h_path.dentry = h_parent;
5438 + au_dtime_store(&dt, dst_parent, &h_path);
5440 + h_path.dentry = h_dst;
5444 + mode = h_inode->i_mode;
5445 + switch (mode & S_IFMT) {
5448 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5450 + err = au_do_cpup_regular(cpg, h_src_attr);
5454 + err = vfsub_mkdir(h_dir, &h_path, mode);
5456 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5459 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5463 + AuDebugOn(!capable(CAP_MKNOD));
5467 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5470 + AuIOErr("Unknown inode type 0%o\n", mode);
5474 + err = au_reset_acl(&h_path, mode);
5476 + mnt_flags = au_mntflags(sb);
5477 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5479 + && au_opt_test(mnt_flags, XINO)
5480 + && (h_inode->i_nlink == 1
5481 + || (h_inode->i_state & I_LINKABLE))
5482 + /* todo: unnecessary? */
5483 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5484 + && cpg->bdst < cpg->bsrc
5485 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5486 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5487 + /* ignore this error */
5492 + force = !!cpg->len;
5493 + if (cpg->len == -1)
5494 + force = !!i_size_read(h_inode);
5496 + au_fhsm_wrote(sb, cpg->bdst, force);
5500 + au_dtime_revert(&dt);
5504 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5507 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5508 + struct path h_ppath;
5509 + struct inode *h_dir;
5510 + aufs_bindex_t bdst;
5512 + dentry = cpg->dentry;
5514 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5515 + h_dentry = au_h_dptr(dentry, bdst);
5516 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5518 + au_set_h_dptr(dentry, bdst, NULL);
5519 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5521 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5522 + au_set_h_dptr(dentry, bdst, h_dentry);
5525 + parent = dget_parent(dentry);
5526 + h_ppath.dentry = au_h_dptr(parent, bdst);
5528 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5529 + if (IS_ERR(h_path->dentry))
5530 + err = PTR_ERR(h_path->dentry);
5532 + if (unlikely(err))
5535 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5536 + h_dir = d_inode(h_parent);
5538 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5539 + /* no delegation since it is just created */
5540 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5542 + dput(h_path->dentry);
5549 + * copyup the @dentry from @bsrc to @bdst.
5550 + * the caller must set the both of lower dentries.
5551 + * @len is for truncating when it is -1 copyup the entire file.
5552 + * in link/rename cases, @dst_parent may be different from the real one.
5553 + * basic->bsrc can be larger than basic->bdst.
5554 + * aufs doesn't touch the credential so
5555 + * security_inode_copy_up{,_xattr}() are unnecessary.
5557 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5560 + aufs_bindex_t old_ibtop;
5561 + unsigned char isdir, plink;
5562 + struct dentry *h_src, *h_dst, *h_parent;
5563 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5564 + struct super_block *sb;
5565 + struct au_branch *br;
5566 + struct path h_src_path;
5567 + /* to reduce stack size */
5569 + struct au_dtime dt;
5570 + struct path h_path;
5571 + struct au_cpup_reg_attr h_src_attr;
5575 + a = kmalloc(sizeof(*a), GFP_NOFS);
5578 + a->h_src_attr.valid = 0;
5580 + sb = cpg->dentry->d_sb;
5581 + br = au_sbr(sb, cpg->bdst);
5582 + a->h_path.mnt = au_br_mnt(br);
5583 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5584 + h_parent = h_dst->d_parent; /* dir inode is locked */
5585 + h_dir = d_inode(h_parent);
5588 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5589 + inode = d_inode(cpg->dentry);
5592 + dst_parent = dget_parent(cpg->dentry);
5596 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5597 + dst_inode = au_h_iptr(inode, cpg->bdst);
5599 + if (unlikely(!plink)) {
5601 + AuIOErr("hi%lu(i%lu) exists on b%d "
5602 + "but plink is disabled\n",
5603 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5607 + if (dst_inode->i_nlink) {
5608 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5610 + h_src = au_plink_lkup(inode, cpg->bdst);
5611 + err = PTR_ERR(h_src);
5612 + if (IS_ERR(h_src))
5614 + if (unlikely(d_is_negative(h_src))) {
5616 + AuIOErr("i%lu exists on b%d "
5617 + "but not pseudo-linked\n",
5618 + inode->i_ino, cpg->bdst);
5624 + a->h_path.dentry = h_parent;
5625 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5628 + a->h_path.dentry = h_dst;
5630 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5631 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5632 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5634 + au_dtime_revert(&a->dt);
5635 + if (unlikely(err == -EWOULDBLOCK)) {
5636 + pr_warn("cannot retry for NFSv4 delegation"
5637 + " for an internal link\n");
5643 + /* todo: cpup_wh_file? */
5645 + au_update_ibrange(inode, /*do_put_zero*/1);
5648 + isdir = S_ISDIR(inode->i_mode);
5649 + old_ibtop = au_ibtop(inode);
5650 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5651 + if (unlikely(err))
5653 + dst_inode = d_inode(h_dst);
5654 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5655 + /* todo: necessary? */
5656 + /* au_pin_hdir_unlock(cpg->pin); */
5658 + h_src_path.dentry = h_src;
5659 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5660 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5661 + if (unlikely(err)) {
5662 + /* todo: necessary? */
5663 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5664 + inode_unlock(dst_inode);
5668 + if (cpg->bdst < old_ibtop) {
5669 + if (S_ISREG(inode->i_mode)) {
5670 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5671 + if (unlikely(err)) {
5672 + /* ignore an error */
5673 + /* au_pin_hdir_relock(cpg->pin); */
5674 + inode_unlock(dst_inode);
5678 + au_set_ibtop(inode, cpg->bdst);
5680 + au_set_ibbot(inode, cpg->bdst);
5681 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5682 + au_hi_flags(inode, isdir));
5684 + /* todo: necessary? */
5685 + /* err = au_pin_hdir_relock(cpg->pin); */
5686 + inode_unlock(dst_inode);
5687 + if (unlikely(err))
5690 + src_inode = d_inode(h_src);
5692 + && (src_inode->i_nlink > 1
5693 + || src_inode->i_state & I_LINKABLE)
5695 + au_plink_append(inode, cpg->bdst, h_dst);
5697 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5698 + a->h_path.dentry = h_dst;
5699 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5702 + goto out_parent; /* success */
5706 + a->h_path.dentry = h_parent;
5707 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5708 + a->h_path.dentry = h_dst;
5710 + if (d_is_positive(h_dst)) {
5712 + /* no delegation since it is just created */
5713 + rerr = vfsub_unlink(h_dir, &a->h_path,
5714 + /*delegated*/NULL, /*force*/0);
5716 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5718 + au_dtime_revert(&a->dt);
5720 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5730 +#if 0 /* reserved */
5731 +struct au_cpup_single_args {
5733 + struct au_cp_generic *cpg;
5734 + struct dentry *dst_parent;
5737 +static void au_call_cpup_single(void *args)
5739 + struct au_cpup_single_args *a = args;
5741 + au_pin_hdir_acquire_nest(a->cpg->pin);
5742 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5743 + au_pin_hdir_release(a->cpg->pin);
5748 + * prevent SIGXFSZ in copy-up.
5749 + * testing CAP_MKNOD is for generic fs,
5750 + * but CAP_FSETID is for xfs only, currently.
5752 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5755 + struct super_block *sb;
5756 + struct inode *h_dir;
5759 + sb = au_pinned_parent(pin)->d_sb;
5760 + if (!au_wkq_test()
5761 + && (!au_sbi(sb)->si_plink_maint_pid
5762 + || au_plink_maint(sb, AuLock_NOPLM))) {
5763 + switch (mode & S_IFMT) {
5765 + /* no condition about RLIMIT_FSIZE and the file size */
5770 + do_sio = !capable(CAP_MKNOD);
5774 + do_sio = ((mode & (S_ISUID | S_ISGID))
5775 + && !capable(CAP_FSETID));
5776 + /* this workaround may be removed in the future */
5778 + h_dir = au_pinned_h_dir(pin);
5779 + do_sio = h_dir->i_mode & S_ISVTX;
5786 +#if 0 /* reserved */
5787 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5790 + struct dentry *h_dentry;
5792 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5793 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5794 + err = au_cpup_single(cpg, dst_parent);
5796 + struct au_cpup_single_args args = {
5799 + .dst_parent = dst_parent
5801 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5802 + if (unlikely(wkq_err))
5811 + * copyup the @dentry from the first active lower branch to @bdst,
5812 + * using au_cpup_single().
5814 +static int au_cpup_simple(struct au_cp_generic *cpg)
5817 + unsigned int flags_orig;
5818 + struct dentry *dentry;
5820 + AuDebugOn(cpg->bsrc < 0);
5822 + dentry = cpg->dentry;
5823 + DiMustWriteLock(dentry);
5825 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5827 + flags_orig = cpg->flags;
5828 + au_fset_cpup(cpg->flags, RENAME);
5829 + err = au_cpup_single(cpg, NULL);
5830 + cpg->flags = flags_orig;
5832 + return 0; /* success */
5835 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5836 + au_set_dbtop(dentry, cpg->bsrc);
5842 +struct au_cpup_simple_args {
5844 + struct au_cp_generic *cpg;
5847 +static void au_call_cpup_simple(void *args)
5849 + struct au_cpup_simple_args *a = args;
5851 + au_pin_hdir_acquire_nest(a->cpg->pin);
5852 + *a->errp = au_cpup_simple(a->cpg);
5853 + au_pin_hdir_release(a->cpg->pin);
5856 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5859 + struct dentry *dentry, *parent;
5860 + struct file *h_file;
5861 + struct inode *h_dir;
5862 + struct mnt_idmap *h_idmap;
5864 + dentry = cpg->dentry;
5866 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5867 + AuDebugOn(cpg->bsrc < 0);
5868 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5869 + err = PTR_ERR(h_file);
5870 + if (IS_ERR(h_file))
5874 + parent = dget_parent(dentry);
5875 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5876 + h_idmap = au_sbr_idmap(dentry->d_sb, cpg->bdst);
5877 + if (!au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC | MAY_WRITE)
5878 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5879 + err = au_cpup_simple(cpg);
5881 + struct au_cpup_simple_args args = {
5885 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5886 + if (unlikely(wkq_err))
5892 + au_h_open_post(dentry, cpg->bsrc, h_file);
5898 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5900 + aufs_bindex_t bsrc, bbot;
5901 + struct dentry *dentry, *h_dentry;
5903 + if (cpg->bsrc < 0) {
5904 + dentry = cpg->dentry;
5905 + bbot = au_dbbot(dentry);
5906 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5907 + h_dentry = au_h_dptr(dentry, bsrc);
5909 + AuDebugOn(d_is_negative(h_dentry));
5913 + AuDebugOn(bsrc > bbot);
5916 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5917 + return au_do_sio_cpup_simple(cpg);
5920 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5922 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5923 + return au_do_sio_cpup_simple(cpg);
5926 +/* ---------------------------------------------------------------------- */
5929 + * copyup the deleted file for writing.
5931 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5932 + struct file *file)
5935 + unsigned int flags_orig;
5936 + aufs_bindex_t bsrc_orig;
5937 + struct au_dinfo *dinfo;
5939 + struct au_hdentry *hd;
5940 + struct dentry *h_dentry;
5943 + dinfo = au_di(cpg->dentry);
5944 + AuRwMustWriteLock(&dinfo->di_rwsem);
5946 + bsrc_orig = cpg->bsrc;
5947 + cpg->bsrc = dinfo->di_btop;
5948 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5949 + hdst.h_dentry = hdst.hd->hd_dentry;
5950 + hdst.hd->hd_dentry = wh_dentry;
5951 + dinfo->di_btop = cpg->bdst;
5953 + hsrc.h_dentry = NULL;
5955 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5956 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5957 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5959 + flags_orig = cpg->flags;
5960 + cpg->flags = !AuCpup_DTIME;
5961 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5962 + cpg->flags = flags_orig;
5965 + err = au_reopen_nondir(file);
5966 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5968 + hdst.hd->hd_dentry = hdst.h_dentry;
5969 + dinfo->di_btop = cpg->bsrc;
5970 + cpg->bsrc = bsrc_orig;
5975 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5978 + aufs_bindex_t bdst;
5979 + struct au_dtime dt;
5980 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5981 + struct au_branch *br;
5982 + struct path h_path;
5984 + dentry = cpg->dentry;
5986 + br = au_sbr(dentry->d_sb, bdst);
5987 + parent = dget_parent(dentry);
5988 + h_parent = au_h_dptr(parent, bdst);
5989 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5990 + err = PTR_ERR(wh_dentry);
5991 + if (IS_ERR(wh_dentry))
5994 + h_path.dentry = h_parent;
5995 + h_path.mnt = au_br_mnt(br);
5996 + au_dtime_store(&dt, parent, &h_path);
5997 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5998 + if (unlikely(err))
6002 + h_path.dentry = wh_dentry;
6003 + if (!d_is_dir(wh_dentry)) {
6004 + /* no delegation since it is just created */
6005 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6006 + /*delegated*/NULL, /*force*/0);
6008 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6009 + if (unlikely(err)) {
6010 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6014 + au_dtime_revert(&dt);
6015 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6024 +struct au_cpup_wh_args {
6026 + struct au_cp_generic *cpg;
6027 + struct file *file;
6030 +static void au_call_cpup_wh(void *args)
6032 + struct au_cpup_wh_args *a = args;
6034 + au_pin_hdir_acquire_nest(a->cpg->pin);
6035 + *a->errp = au_cpup_wh(a->cpg, a->file);
6036 + au_pin_hdir_release(a->cpg->pin);
6039 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6042 + aufs_bindex_t bdst;
6043 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6044 + struct inode *dir, *h_dir, *h_tmpdir;
6045 + struct au_wbr *wbr;
6046 + struct au_pin wh_pin, *pin_orig;
6047 + struct mnt_idmap *h_idmap;
6049 + dentry = cpg->dentry;
6051 + parent = dget_parent(dentry);
6052 + dir = d_inode(parent);
6055 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6058 + if (!h_dir->i_nlink) {
6059 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6060 + h_orph = wbr->wbr_orph;
6062 + h_parent = dget(au_h_dptr(parent, bdst));
6063 + au_set_h_dptr(parent, bdst, dget(h_orph));
6064 + h_tmpdir = d_inode(h_orph);
6065 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6067 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6068 + /* todo: au_h_open_pre()? */
6070 + pin_orig = cpg->pin;
6071 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6072 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6073 + cpg->pin = &wh_pin;
6076 + h_idmap = au_sbr_idmap(dentry->d_sb, bdst);
6077 + if (!au_test_h_perm_sio(h_idmap, h_tmpdir, MAY_EXEC | MAY_WRITE)
6078 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6079 + err = au_cpup_wh(cpg, file);
6081 + struct au_cpup_wh_args args = {
6086 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6087 + if (unlikely(wkq_err))
6092 + inode_unlock(h_tmpdir);
6093 + /* todo: au_h_open_post()? */
6094 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6095 + au_set_h_dptr(parent, bdst, h_parent);
6096 + AuDebugOn(!pin_orig);
6097 + cpg->pin = pin_orig;
6105 +/* ---------------------------------------------------------------------- */
6108 + * generic routine for both of copy-up and copy-down.
6110 +/* cf. revalidate function in file.c */
6111 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6112 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6113 + struct au_pin *pin,
6114 + struct dentry *h_parent, void *arg),
6118 + struct au_pin pin;
6119 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6122 + parent = dget_parent(dentry);
6123 + if (IS_ROOT(parent))
6126 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6127 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6129 + /* do not use au_dpage */
6130 + real_parent = parent;
6133 + parent = dget_parent(dentry);
6134 + h_parent = au_h_dptr(parent, bdst);
6136 + goto out; /* success */
6138 + /* find top dir which is necessary to cpup */
6142 + parent = dget_parent(d);
6143 + di_read_lock_parent3(parent, !AuLock_IR);
6144 + h_parent = au_h_dptr(parent, bdst);
6145 + di_read_unlock(parent, !AuLock_IR);
6146 + } while (!h_parent);
6148 + if (d != real_parent)
6149 + di_write_lock_child3(d);
6151 + /* somebody else might create while we were sleeping */
6152 + h_dentry = au_h_dptr(d, bdst);
6153 + if (!h_dentry || d_is_negative(h_dentry)) {
6155 + au_update_dbtop(d);
6157 + au_pin_set_dentry(&pin, d);
6158 + err = au_do_pin(&pin);
6160 + err = cp(d, bdst, &pin, h_parent, arg);
6165 + if (d != real_parent)
6166 + di_write_unlock(d);
6167 + if (unlikely(err))
6176 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6177 + struct au_pin *pin,
6178 + struct dentry *h_parent __maybe_unused,
6179 + void *arg __maybe_unused)
6181 + struct au_cp_generic cpg = {
6187 + .flags = AuCpup_DTIME
6189 + return au_sio_cpup_simple(&cpg);
6192 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6194 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6197 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6200 + struct dentry *parent;
6201 + struct inode *dir;
6203 + parent = dget_parent(dentry);
6204 + dir = d_inode(parent);
6206 + if (au_h_iptr(dir, bdst))
6209 + di_read_unlock(parent, AuLock_IR);
6210 + di_write_lock_parent(parent);
6211 + /* someone else might change our inode while we were sleeping */
6212 + if (!au_h_iptr(dir, bdst))
6213 + err = au_cpup_dirs(dentry, bdst);
6214 + di_downgrade_lock(parent, AuLock_IR);
6220 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6221 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6222 +++ linux/fs/aufs/cpup.h 2024-05-13 17:13:00.618070924 +0200
6224 +/* SPDX-License-Identifier: GPL-2.0 */
6226 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6228 + * This program is free software; you can redistribute it and/or modify
6229 + * it under the terms of the GNU General Public License as published by
6230 + * the Free Software Foundation; either version 2 of the License, or
6231 + * (at your option) any later version.
6233 + * This program is distributed in the hope that it will be useful,
6234 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6235 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6236 + * GNU General Public License for more details.
6238 + * You should have received a copy of the GNU General Public License
6239 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6243 + * copy-up/down functions
6246 +#ifndef __AUFS_CPUP_H__
6247 +#define __AUFS_CPUP_H__
6251 +#include <linux/path.h>
6257 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6258 +void au_cpup_attr_timesizes(struct inode *inode);
6259 +void au_cpup_attr_nlink(struct inode *inode, int force);
6260 +void au_cpup_attr_changeable(struct inode *inode);
6261 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6262 +void au_cpup_attr_all(struct inode *inode, int force);
6264 +/* ---------------------------------------------------------------------- */
6266 +struct au_cp_generic {
6267 + struct dentry *dentry;
6268 + aufs_bindex_t bdst, bsrc;
6270 + struct au_pin *pin;
6271 + unsigned int flags;
6275 +#define AuCpup_DTIME BIT(0) /* do dtime_store/revert */
6276 +#define AuCpup_KEEPLINO BIT(1) /* do not clear the lower xino,
6278 +#define AuCpup_RENAME BIT(2) /* rename after cpup */
6279 +#define AuCpup_HOPEN BIT(3) /* call h_open_pre/post() in
6281 +#define AuCpup_OVERWRITE BIT(4) /* allow overwriting the
6283 +#define AuCpup_RWDST BIT(5) /* force write target even if
6284 + the branch is marked as RO */
6286 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6287 +#undef AuCpup_HOPEN
6288 +#define AuCpup_HOPEN 0
6291 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6292 +#define au_fset_cpup(flags, name) \
6293 + do { (flags) |= AuCpup_##name; } while (0)
6294 +#define au_fclr_cpup(flags, name) \
6295 + do { (flags) &= ~AuCpup_##name; } while (0)
6297 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6298 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6299 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6300 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6302 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6303 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6304 + struct au_pin *pin,
6305 + struct dentry *h_parent, void *arg),
6307 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6308 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6310 +/* ---------------------------------------------------------------------- */
6312 +/* keep timestamps when copyup */
6314 + struct dentry *dt_dentry;
6315 + struct path dt_h_path;
6316 + struct timespec64 dt_atime, dt_mtime;
6318 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6319 + struct path *h_path);
6320 +void au_dtime_revert(struct au_dtime *dt);
6322 +#endif /* __KERNEL__ */
6323 +#endif /* __AUFS_CPUP_H__ */
6324 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6325 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6326 +++ linux/fs/aufs/dbgaufs.c 2024-05-13 17:13:00.618070924 +0200
6328 +// SPDX-License-Identifier: GPL-2.0
6330 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6332 + * This program is free software; you can redistribute it and/or modify
6333 + * it under the terms of the GNU General Public License as published by
6334 + * the Free Software Foundation; either version 2 of the License, or
6335 + * (at your option) any later version.
6337 + * This program is distributed in the hope that it will be useful,
6338 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6339 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6340 + * GNU General Public License for more details.
6342 + * You should have received a copy of the GNU General Public License
6343 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6347 + * debugfs interface
6350 +#include <linux/debugfs.h>
6353 +#ifndef CONFIG_SYSFS
6354 +#error DEBUG_FS depends upon SYSFS
6357 +static struct dentry *dbgaufs;
6358 +static const mode_t dbgaufs_mode = 0444;
6360 +/* 20 is max digits length of ulong 64 */
6361 +struct dbgaufs_arg {
6367 + * common function for all XINO files
6369 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6370 + struct file *file)
6374 + p = file->private_data;
6376 + /* this is struct dbgaufs_arg */
6377 + AuDebugOn(!au_kfree_sz_test(p));
6378 + au_kfree_do_rcu(p);
6383 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6388 + struct dbgaufs_arg *p;
6391 + p = kmalloc(sizeof(*p), GFP_NOFS);
6397 + file->private_data = p;
6401 + err = vfsub_getattr(&xf->f_path, &st);
6405 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6406 + cnt, st.blocks, st.blksize,
6407 + (long long)st.size);
6409 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6410 + st.blocks, st.blksize,
6411 + (long long)st.size);
6412 + AuDebugOn(p->n >= sizeof(p->a));
6414 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6422 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6423 + size_t count, loff_t *ppos)
6425 + struct dbgaufs_arg *p;
6427 + p = file->private_data;
6428 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6431 +/* ---------------------------------------------------------------------- */
6433 +struct dbgaufs_plink_arg {
6438 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6439 + struct file *file)
6441 + free_page((unsigned long)file->private_data);
6445 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6447 + int err, i, limit;
6448 + unsigned long n, sum;
6449 + struct dbgaufs_plink_arg *p;
6450 + struct au_sbinfo *sbinfo;
6451 + struct super_block *sb;
6452 + struct hlist_bl_head *hbl;
6455 + p = (void *)get_zeroed_page(GFP_NOFS);
6460 + sbinfo = inode->i_private;
6461 + sb = sbinfo->si_sb;
6462 + si_noflush_read_lock(sb);
6463 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6464 + limit = PAGE_SIZE - sizeof(p->n);
6466 + /* the number of buckets */
6467 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6472 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6474 + n = au_hbl_count(hbl);
6477 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6480 + if (unlikely(limit <= 0))
6483 + p->a[p->n - 1] = '\n';
6485 + /* the sum of plinks */
6486 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6489 + if (unlikely(limit <= 0))
6492 +#define str "1\n0\n0\n"
6493 + p->n = sizeof(str) - 1;
6494 + strscpy(p->a, str, sizeof(str));
6497 + si_read_unlock(sb);
6500 + file->private_data = p;
6501 + goto out; /* success */
6504 + free_page((unsigned long)p);
6509 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6510 + size_t count, loff_t *ppos)
6512 + struct dbgaufs_plink_arg *p;
6514 + p = file->private_data;
6515 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6518 +static const struct file_operations dbgaufs_plink_fop = {
6519 + .owner = THIS_MODULE,
6520 + .open = dbgaufs_plink_open,
6521 + .release = dbgaufs_plink_release,
6522 + .read = dbgaufs_plink_read
6525 +/* ---------------------------------------------------------------------- */
6527 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6530 + struct au_sbinfo *sbinfo;
6531 + struct super_block *sb;
6533 + sbinfo = inode->i_private;
6534 + sb = sbinfo->si_sb;
6535 + si_noflush_read_lock(sb);
6536 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6537 + si_read_unlock(sb);
6541 +static const struct file_operations dbgaufs_xib_fop = {
6542 + .owner = THIS_MODULE,
6543 + .open = dbgaufs_xib_open,
6544 + .release = dbgaufs_xi_release,
6545 + .read = dbgaufs_xi_read
6548 +/* ---------------------------------------------------------------------- */
6550 +#define DbgaufsXi_PREFIX "xi"
6552 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6556 + aufs_bindex_t bindex;
6557 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6558 + struct au_sbinfo *sbinfo;
6559 + struct super_block *sb;
6560 + struct au_xino *xi;
6562 + struct qstr *name;
6563 + struct au_branch *br;
6566 + name = &file->f_path.dentry->d_name;
6567 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6568 + || memcmp(name->name, DbgaufsXi_PREFIX,
6569 + sizeof(DbgaufsXi_PREFIX) - 1)))
6572 + AuDebugOn(name->len >= sizeof(a));
6573 + memcpy(a, name->name, name->len);
6574 + a[name->len] = '\0';
6575 + p = strchr(a, '-');
6578 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6579 + if (unlikely(err))
6584 + err = kstrtol(p + 1, 10, &l);
6585 + if (unlikely(err))
6591 + sbinfo = inode->i_private;
6592 + sb = sbinfo->si_sb;
6593 + si_noflush_read_lock(sb);
6594 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6596 + br = au_sbr(sb, bindex);
6598 + if (unlikely(idx >= xi->xi_nfile))
6600 + xf = au_xino_file(xi, idx);
6602 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6603 + au_xino_count(br));
6606 + si_read_unlock(sb);
6612 +static const struct file_operations dbgaufs_xino_fop = {
6613 + .owner = THIS_MODULE,
6614 + .open = dbgaufs_xino_open,
6615 + .release = dbgaufs_xi_release,
6616 + .read = dbgaufs_xi_read
6619 +void dbgaufs_xino_del(struct au_branch *br)
6621 + struct dentry *dbgaufs;
6623 + dbgaufs = br->br_dbgaufs;
6627 + br->br_dbgaufs = NULL;
6628 + /* debugfs acquires the parent i_mutex */
6630 + debugfs_remove(dbgaufs);
6634 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6636 + aufs_bindex_t bbot;
6637 + struct au_branch *br;
6639 + if (!au_sbi(sb)->si_dbgaufs)
6642 + bbot = au_sbbot(sb);
6643 + for (; bindex <= bbot; bindex++) {
6644 + br = au_sbr(sb, bindex);
6645 + dbgaufs_xino_del(br);
6649 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6650 + unsigned int idx, struct dentry *parent,
6651 + struct au_sbinfo *sbinfo)
6653 + struct au_branch *br;
6655 + /* "xi" bindex(5) "-" idx(2) NULL */
6656 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6659 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6661 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6663 + br = au_sbr(sb, bindex);
6664 + if (br->br_dbgaufs) {
6665 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6667 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6668 + /* debugfs acquires the parent i_mutex */
6670 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6674 + pr_warn("failed renaming %pd/%s, ignored.\n",
6679 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6680 + sbinfo, &dbgaufs_xino_fop);
6682 + if (unlikely(!br->br_dbgaufs))
6683 + pr_warn("failed creating %pd/%s, ignored.\n",
6688 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6689 + struct dentry *parent, struct au_sbinfo *sbinfo)
6691 + struct au_branch *br;
6692 + struct au_xino *xi;
6695 + br = au_sbr(sb, bindex);
6697 + for (u = 0; u < xi->xi_nfile; u++)
6698 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6701 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6703 + struct au_sbinfo *sbinfo;
6704 + struct dentry *parent;
6705 + aufs_bindex_t bbot;
6707 + if (!au_opt_test(au_mntflags(sb), XINO))
6710 + sbinfo = au_sbi(sb);
6711 + parent = sbinfo->si_dbgaufs;
6715 + bbot = au_sbbot(sb);
6717 + for (; bindex <= bbot; bindex++)
6718 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6720 + for (; bbot >= bindex; bbot--)
6721 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6724 +/* ---------------------------------------------------------------------- */
6726 +#ifdef CONFIG_AUFS_EXPORT
6727 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6730 + struct au_sbinfo *sbinfo;
6731 + struct super_block *sb;
6733 + sbinfo = inode->i_private;
6734 + sb = sbinfo->si_sb;
6735 + si_noflush_read_lock(sb);
6736 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6737 + si_read_unlock(sb);
6741 +static const struct file_operations dbgaufs_xigen_fop = {
6742 + .owner = THIS_MODULE,
6743 + .open = dbgaufs_xigen_open,
6744 + .release = dbgaufs_xi_release,
6745 + .read = dbgaufs_xi_read
6748 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6753 + * This function is a dynamic '__init' function actually,
6754 + * so the tiny check for si_rwsem is unnecessary.
6756 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6759 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6760 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6761 + &dbgaufs_xigen_fop);
6762 + if (sbinfo->si_dbgaufs_xigen)
6768 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6772 +#endif /* CONFIG_AUFS_EXPORT */
6774 +/* ---------------------------------------------------------------------- */
6776 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6779 + * This function is a dynamic '__fin' function actually,
6780 + * so the tiny check for si_rwsem is unnecessary.
6782 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6784 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6785 + sbinfo->si_dbgaufs = NULL;
6788 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6791 + char name[SysaufsSiNameLen];
6794 + * This function is a dynamic '__init' function actually,
6795 + * so the tiny check for si_rwsem is unnecessary.
6797 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6801 + AuErr1("/debug/aufs is uninitialized\n");
6806 + sysaufs_name(sbinfo, name);
6807 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6808 + if (unlikely(!sbinfo->si_dbgaufs))
6811 + /* regardless plink/noplink option */
6812 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6813 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6814 + &dbgaufs_plink_fop);
6815 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6818 + /* regardless xino/noxino option */
6819 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6820 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6821 + &dbgaufs_xib_fop);
6822 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6825 + err = dbgaufs_xigen_init(sbinfo);
6827 + goto out; /* success */
6830 + dbgaufs_si_fin(sbinfo);
6832 + if (unlikely(err))
6833 + pr_err("debugfs/aufs failed\n");
6837 +/* ---------------------------------------------------------------------- */
6839 +void dbgaufs_fin(void)
6841 + debugfs_remove(dbgaufs);
6844 +int __init dbgaufs_init(void)
6849 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6854 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6855 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6856 +++ linux/fs/aufs/dbgaufs.h 2024-05-13 17:13:00.618070924 +0200
6858 +/* SPDX-License-Identifier: GPL-2.0 */
6860 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6862 + * This program is free software; you can redistribute it and/or modify
6863 + * it under the terms of the GNU General Public License as published by
6864 + * the Free Software Foundation; either version 2 of the License, or
6865 + * (at your option) any later version.
6867 + * This program is distributed in the hope that it will be useful,
6868 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6869 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6870 + * GNU General Public License for more details.
6872 + * You should have received a copy of the GNU General Public License
6873 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6877 + * debugfs interface
6880 +#ifndef __DBGAUFS_H__
6881 +#define __DBGAUFS_H__
6885 +struct super_block;
6889 +#ifdef CONFIG_DEBUG_FS
6891 +void dbgaufs_xino_del(struct au_branch *br);
6892 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6893 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6894 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6895 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6896 +void dbgaufs_fin(void);
6897 +int __init dbgaufs_init(void);
6899 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6900 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6901 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6903 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6904 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6905 +AuStubVoid(dbgaufs_fin, void)
6906 +AuStubInt0(__init dbgaufs_init, void)
6907 +#endif /* CONFIG_DEBUG_FS */
6909 +#endif /* __KERNEL__ */
6910 +#endif /* __DBGAUFS_H__ */
6911 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6912 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6913 +++ linux/fs/aufs/dcsub.c 2024-05-13 17:13:00.618070924 +0200
6915 +// SPDX-License-Identifier: GPL-2.0
6917 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6919 + * This program is free software; you can redistribute it and/or modify
6920 + * it under the terms of the GNU General Public License as published by
6921 + * the Free Software Foundation; either version 2 of the License, or
6922 + * (at your option) any later version.
6924 + * This program is distributed in the hope that it will be useful,
6925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6927 + * GNU General Public License for more details.
6929 + * You should have received a copy of the GNU General Public License
6930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6934 + * sub-routines for dentry cache
6939 +static void au_dpage_free(struct au_dpage *dpage)
6942 + struct dentry **p;
6944 + p = dpage->dentries;
6945 + for (i = 0; i < dpage->ndentry; i++)
6947 + free_page((unsigned long)dpage->dentries);
6950 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6956 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6957 + if (unlikely(!dpages->dpages))
6960 + p = (void *)__get_free_page(gfp);
6964 + dpages->dpages[0].ndentry = 0;
6965 + dpages->dpages[0].dentries = p;
6966 + dpages->ndpage = 1;
6967 + return 0; /* success */
6970 + au_kfree_try_rcu(dpages->dpages);
6975 +void au_dpages_free(struct au_dcsub_pages *dpages)
6978 + struct au_dpage *p;
6980 + p = dpages->dpages;
6981 + for (i = 0; i < dpages->ndpage; i++)
6982 + au_dpage_free(p++);
6983 + au_kfree_try_rcu(dpages->dpages);
6986 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6987 + struct dentry *dentry, gfp_t gfp)
6990 + struct au_dpage *dpage;
6993 + dpage = dpages->dpages + dpages->ndpage - 1;
6994 + sz = PAGE_SIZE / sizeof(dentry);
6995 + if (unlikely(dpage->ndentry >= sz)) {
6996 + AuLabel(new dpage);
6998 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6999 + p = au_kzrealloc(dpages->dpages, sz,
7000 + sz + sizeof(*dpages->dpages), gfp,
7005 + dpages->dpages = p;
7006 + dpage = dpages->dpages + dpages->ndpage;
7007 + p = (void *)__get_free_page(gfp);
7011 + dpage->ndentry = 0;
7012 + dpage->dentries = p;
7016 + AuDebugOn(au_dcount(dentry) <= 0);
7017 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7018 + return 0; /* success */
7024 +/* todo: BAD approach */
7025 +/* copied from linux/fs/dcache.c */
7033 +extern void d_walk(struct dentry *parent, void *data,
7034 + enum d_walk_ret (*enter)(void *, struct dentry *));
7036 +struct ac_dpages_arg {
7038 + struct au_dcsub_pages *dpages;
7039 + struct super_block *sb;
7040 + au_dpages_test test;
7044 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7046 + enum d_walk_ret ret;
7047 + struct ac_dpages_arg *arg = _arg;
7049 + ret = D_WALK_CONTINUE;
7050 + if (dentry->d_sb == arg->sb
7051 + && !IS_ROOT(dentry)
7052 + && au_dcount(dentry) > 0
7054 + && (!arg->test || arg->test(dentry, arg->arg))) {
7055 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7056 + if (unlikely(arg->err))
7057 + ret = D_WALK_QUIT;
7063 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7064 + au_dpages_test test, void *arg)
7066 + struct ac_dpages_arg args = {
7074 + d_walk(root, &args, au_call_dpages_append);
7079 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7080 + int do_include, au_dpages_test test, void *arg)
7085 + write_seqlock(&rename_lock);
7086 + spin_lock(&dentry->d_lock);
7088 + && au_dcount(dentry) > 0
7089 + && (!test || test(dentry, arg)))
7090 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7091 + spin_unlock(&dentry->d_lock);
7092 + if (unlikely(err))
7096 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7099 + while (!IS_ROOT(dentry)) {
7100 + dentry = dentry->d_parent; /* rename_lock is locked */
7101 + spin_lock(&dentry->d_lock);
7102 + if (au_dcount(dentry) > 0
7103 + && (!test || test(dentry, arg)))
7104 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7105 + spin_unlock(&dentry->d_lock);
7106 + if (unlikely(err))
7111 + write_sequnlock(&rename_lock);
7115 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7117 + return au_di(dentry) && dentry->d_sb == arg;
7120 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7121 + struct dentry *dentry, int do_include)
7123 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7124 + au_dcsub_dpages_aufs, dentry->d_sb);
7127 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7129 + struct path path[2] = {
7138 + return path_is_under(path + 0, path + 1);
7140 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7141 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7142 +++ linux/fs/aufs/dcsub.h 2024-05-13 17:13:00.618070924 +0200
7144 +/* SPDX-License-Identifier: GPL-2.0 */
7146 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7148 + * This program is free software; you can redistribute it and/or modify
7149 + * it under the terms of the GNU General Public License as published by
7150 + * the Free Software Foundation; either version 2 of the License, or
7151 + * (at your option) any later version.
7153 + * This program is distributed in the hope that it will be useful,
7154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7156 + * GNU General Public License for more details.
7158 + * You should have received a copy of the GNU General Public License
7159 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7163 + * sub-routines for dentry cache
7166 +#ifndef __AUFS_DCSUB_H__
7167 +#define __AUFS_DCSUB_H__
7171 +#include <linux/dcache.h>
7172 +#include <linux/fs.h>
7176 + struct dentry **dentries;
7179 +struct au_dcsub_pages {
7181 + struct au_dpage *dpages;
7184 +/* ---------------------------------------------------------------------- */
7187 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7188 +void au_dpages_free(struct au_dcsub_pages *dpages);
7189 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7190 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7191 + au_dpages_test test, void *arg);
7192 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7193 + int do_include, au_dpages_test test, void *arg);
7194 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7195 + struct dentry *dentry, int do_include);
7196 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7198 +/* ---------------------------------------------------------------------- */
7201 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7202 + * include/linux/dcache.h. Try them (in the future).
7205 +static inline int au_d_hashed_positive(struct dentry *d)
7208 + struct inode *inode = d_inode(d);
7211 + if (unlikely(d_unhashed(d)
7212 + || d_is_negative(d)
7213 + || !inode->i_nlink))
7218 +static inline int au_d_linkable(struct dentry *d)
7221 + struct inode *inode = d_inode(d);
7223 + err = au_d_hashed_positive(d);
7225 + && d_is_positive(d)
7226 + && (inode->i_state & I_LINKABLE))
7231 +static inline int au_d_alive(struct dentry *d)
7234 + struct inode *inode;
7238 + err = au_d_hashed_positive(d);
7240 + inode = d_inode(d);
7241 + if (unlikely(d_unlinked(d)
7242 + || d_is_negative(d)
7243 + || !inode->i_nlink))
7249 +static inline int au_alive_dir(struct dentry *d)
7253 + err = au_d_alive(d);
7254 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7259 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7261 + return a->len == b->len
7262 + && !memcmp(a->name, b->name, a->len);
7267 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7269 + * the type of d_lockref.count became int, but the inlined function d_count()
7270 + * still returns unsigned int.
7271 + * I don't know why. Maybe it is for every d_count() users?
7272 + * Anyway au_dcount() lives on.
7274 +static inline int au_dcount(struct dentry *d)
7276 + return (int)d_count(d);
7279 +#endif /* __KERNEL__ */
7280 +#endif /* __AUFS_DCSUB_H__ */
7281 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7282 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7283 +++ linux/fs/aufs/debug.c 2024-05-13 17:13:00.618070924 +0200
7285 +// SPDX-License-Identifier: GPL-2.0
7287 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7289 + * This program is free software; you can redistribute it and/or modify
7290 + * it under the terms of the GNU General Public License as published by
7291 + * the Free Software Foundation; either version 2 of the License, or
7292 + * (at your option) any later version.
7294 + * This program is distributed in the hope that it will be useful,
7295 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7296 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7297 + * GNU General Public License for more details.
7299 + * You should have received a copy of the GNU General Public License
7300 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7304 + * debug print functions
7307 +#include <linux/iversion.h>
7310 +/* Returns 0, or -errno. arg is in kp->arg. */
7311 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7315 + err = kstrtoint(val, 0, &n);
7325 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7326 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7331 + return sprintf(buffer, "%d", atomic_read(a));
7334 +static const struct kernel_param_ops param_ops_atomic_t = {
7335 + .set = param_atomic_t_set,
7336 + .get = param_atomic_t_get
7337 + /* void (*free)(void *arg) */
7340 +atomic_t aufs_debug = ATOMIC_INIT(0);
7341 +MODULE_PARM_DESC(debug, "debug print");
7342 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7344 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7345 +char *au_plevel = KERN_DEBUG;
7346 +#define dpri(fmt, ...) do { \
7348 + && strcmp(au_plevel, KERN_DEBUG)) \
7349 + || au_debug_test()) \
7350 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7353 +/* ---------------------------------------------------------------------- */
7355 +void au_dpri_whlist(struct au_nhash *whlist)
7357 + unsigned long ul, n;
7358 + struct hlist_head *head;
7359 + struct au_vdir_wh *pos;
7361 + n = whlist->nh_num;
7362 + head = whlist->nh_head;
7363 + for (ul = 0; ul < n; ul++) {
7364 + hlist_for_each_entry(pos, head, wh_hash)
7365 + dpri("b%d, %.*s, %d\n",
7367 + pos->wh_str.len, pos->wh_str.name,
7373 +void au_dpri_vdir(struct au_vdir *vdir)
7376 + union au_vdir_deblk_p p;
7379 + if (!vdir || IS_ERR(vdir)) {
7380 + dpri("err %ld\n", PTR_ERR(vdir));
7384 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7385 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7386 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7387 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7388 + p.deblk = vdir->vd_deblk[ul];
7390 + dpri("[%lu]: %p\n", ul, o);
7394 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7395 + struct dentry *wh)
7399 + struct timespec64 ctime;
7401 + if (!inode || IS_ERR(inode)) {
7402 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7406 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7407 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7408 + && sizeof(inode->i_blocks) != sizeof(u64));
7410 + n = (void *)wh->d_name.name;
7411 + l = wh->d_name.len;
7414 + ctime = inode_get_ctime(inode);
7415 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7416 + " acl %p, def_acl %p,"
7417 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7419 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7420 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7421 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7422 + inode->i_acl, inode->i_default_acl,
7423 + hn, (long long)timespec64_to_ns(&ctime) & 0x0ffff,
7424 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7425 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7426 + inode->i_generation,
7427 + l ? ", wh " : "", l, n);
7431 +void au_dpri_inode(struct inode *inode)
7433 + struct au_iinfo *iinfo;
7434 + struct au_hinode *hi;
7435 + aufs_bindex_t bindex;
7438 + err = do_pri_inode(-1, inode, -1, NULL);
7439 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7442 + iinfo = au_ii(inode);
7443 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7444 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7445 + if (iinfo->ii_btop < 0)
7448 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7449 + hi = au_hinode(iinfo, bindex);
7451 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7455 +void au_dpri_dalias(struct inode *inode)
7459 + spin_lock(&inode->i_lock);
7460 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7461 + au_dpri_dentry(d);
7462 + spin_unlock(&inode->i_lock);
7465 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7467 + struct dentry *wh = NULL;
7469 + struct inode *inode;
7470 + struct au_iinfo *iinfo;
7471 + struct au_hinode *hi;
7473 + if (!dentry || IS_ERR(dentry)) {
7474 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7477 + /* do not call dget_parent() here */
7478 + /* note: access d_xxx without d_lock */
7479 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7480 + bindex, dentry, dentry,
7481 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7482 + au_dcount(dentry), dentry->d_flags,
7483 + d_unhashed(dentry) ? "un" : "");
7486 + if (d_is_positive(dentry))
7487 + inode = d_inode(dentry);
7489 + && au_test_aufs(dentry->d_sb)
7491 + && !au_is_bad_inode(inode)) {
7492 + iinfo = au_ii(inode);
7493 + hi = au_hinode(iinfo, bindex);
7495 + wh = hi->hi_whdentry;
7497 + do_pri_inode(bindex, inode, hn, wh);
7501 +void au_dpri_dentry(struct dentry *dentry)
7503 + struct au_dinfo *dinfo;
7504 + aufs_bindex_t bindex;
7507 + err = do_pri_dentry(-1, dentry);
7508 + if (err || !au_test_aufs(dentry->d_sb))
7511 + dinfo = au_di(dentry);
7514 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7515 + dinfo->di_btop, dinfo->di_bbot,
7516 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7517 + dinfo->di_tmpfile);
7518 + if (dinfo->di_btop < 0)
7520 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7521 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7524 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7528 + if (!file || IS_ERR(file)) {
7529 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7534 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7535 + && au_test_aufs(file->f_path.dentry->d_sb)
7537 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7538 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7539 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7540 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7541 + file->f_version, file->f_pos, a);
7542 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7543 + do_pri_dentry(bindex, file->f_path.dentry);
7547 +void au_dpri_file(struct file *file)
7549 + struct au_finfo *finfo;
7550 + struct au_fidir *fidir;
7551 + struct au_hfile *hfile;
7552 + aufs_bindex_t bindex;
7555 + err = do_pri_file(-1, file);
7557 + || IS_ERR_OR_NULL(file->f_path.dentry)
7558 + || !au_test_aufs(file->f_path.dentry->d_sb))
7561 + finfo = au_fi(file);
7564 + if (finfo->fi_btop < 0)
7566 + fidir = finfo->fi_hdir;
7568 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7570 + for (bindex = finfo->fi_btop;
7571 + bindex >= 0 && bindex <= fidir->fd_bbot;
7573 + hfile = fidir->fd_hfile + bindex;
7574 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7578 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7580 + struct vfsmount *mnt;
7581 + struct super_block *sb;
7583 + if (!br || IS_ERR(br))
7585 + mnt = au_br_mnt(br);
7586 + if (!mnt || IS_ERR(mnt))
7589 + if (!sb || IS_ERR(sb))
7592 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7593 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7595 + bindex, br->br_perm, br->br_id, br->br_wbr,
7596 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7597 + sb->s_flags, sb->s_count,
7598 + atomic_read(&sb->s_active),
7599 + !!au_xino_file(br->br_xino, /*idx*/-1));
7603 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7607 +void au_dpri_sb(struct super_block *sb)
7609 + struct au_sbinfo *sbinfo;
7610 + aufs_bindex_t bindex;
7612 + /* to reduce stack size */
7614 + struct vfsmount mnt;
7615 + struct au_branch fake;
7618 + /* this function can be called from magic sysrq */
7619 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7620 + if (unlikely(!a)) {
7621 + dpri("no memory\n");
7625 + a->mnt.mnt_sb = sb;
7626 + a->fake.br_path.mnt = &a->mnt;
7627 + err = do_pri_br(-1, &a->fake);
7629 + dpri("dev 0x%x\n", sb->s_dev);
7630 + if (err || !au_test_aufs(sb))
7633 + sbinfo = au_sbi(sb);
7636 + dpri("nw %d, gen %u, kobj %d\n",
7637 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7638 + kref_read(&sbinfo->si_kobj.kref));
7639 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7640 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7643 +/* ---------------------------------------------------------------------- */
7645 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7647 + struct inode *h_inode, *inode = d_inode(dentry);
7648 + struct dentry *h_dentry;
7649 + aufs_bindex_t bindex, bbot, bi;
7651 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7654 + bbot = au_dbbot(dentry);
7655 + bi = au_ibbot(inode);
7658 + bindex = au_dbtop(dentry);
7659 + bi = au_ibtop(inode);
7663 + for (; bindex <= bbot; bindex++) {
7664 + h_dentry = au_h_dptr(dentry, bindex);
7667 + h_inode = au_h_iptr(inode, bindex);
7668 + if (unlikely(h_inode != d_inode(h_dentry))) {
7670 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7671 + AuDbgDentry(dentry);
7672 + AuDbgInode(inode);
7674 + if (au_test_fuse(h_inode->i_sb))
7682 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7685 + struct au_dcsub_pages dpages;
7686 + struct au_dpage *dpage;
7687 + struct dentry **dentries;
7689 + err = au_dpages_init(&dpages, GFP_NOFS);
7691 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7693 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7694 + dpage = dpages.dpages + i;
7695 + dentries = dpage->dentries;
7696 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7697 + AuDebugOn(au_digen_test(dentries[j], sigen));
7699 + au_dpages_free(&dpages);
7702 +void au_dbg_verify_kthread(void)
7704 + if (au_wkq_test()) {
7707 + * It may be recursive, but udba=notify between two aufs mounts,
7708 + * where a single ro branch is shared, is not a problem.
7714 +/* ---------------------------------------------------------------------- */
7716 +int __init au_debug_init(void)
7718 + aufs_bindex_t bindex;
7719 + struct au_vdir_destr destr;
7722 + AuDebugOn(bindex >= 0);
7725 + AuDebugOn(destr.len < NAME_MAX);
7727 +#ifdef CONFIG_4KSTACKS
7728 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7733 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7734 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7735 +++ linux/fs/aufs/debug.h 2024-05-13 17:13:00.618070924 +0200
7737 +/* SPDX-License-Identifier: GPL-2.0 */
7739 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7741 + * This program is free software; you can redistribute it and/or modify
7742 + * it under the terms of the GNU General Public License as published by
7743 + * the Free Software Foundation; either version 2 of the License, or
7744 + * (at your option) any later version.
7746 + * This program is distributed in the hope that it will be useful,
7747 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7748 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7749 + * GNU General Public License for more details.
7751 + * You should have received a copy of the GNU General Public License
7752 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7756 + * debug print functions
7759 +#ifndef __AUFS_DEBUG_H__
7760 +#define __AUFS_DEBUG_H__
7764 +#include <linux/atomic.h>
7765 +#include <linux/module.h>
7766 +#include <linux/kallsyms.h>
7767 +#include <linux/sysrq.h>
7769 +#ifdef CONFIG_AUFS_DEBUG
7770 +#define AuDebugOn(a) BUG_ON(a)
7772 +/* module parameter */
7773 +extern atomic_t aufs_debug;
7774 +static inline void au_debug_on(void)
7776 + atomic_inc(&aufs_debug);
7778 +static inline void au_debug_off(void)
7780 + atomic_dec_if_positive(&aufs_debug);
7783 +static inline int au_debug_test(void)
7785 + return atomic_read(&aufs_debug) > 0;
7788 +#define AuDebugOn(a) do {} while (0)
7789 +AuStubVoid(au_debug_on, void)
7790 +AuStubVoid(au_debug_off, void)
7791 +AuStubInt0(au_debug_test, void)
7792 +#endif /* CONFIG_AUFS_DEBUG */
7794 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7796 +/* ---------------------------------------------------------------------- */
7800 +#define AuDbg(fmt, ...) do { \
7801 + if (au_debug_test()) \
7802 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7804 +#define AuLabel(l) AuDbg(#l "\n")
7805 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7806 +#define AuWarn1(fmt, ...) do { \
7807 + static unsigned char _c; \
7809 + pr_warn(fmt, ##__VA_ARGS__); \
7812 +#define AuErr1(fmt, ...) do { \
7813 + static unsigned char _c; \
7815 + pr_err(fmt, ##__VA_ARGS__); \
7818 +#define AuIOErr1(fmt, ...) do { \
7819 + static unsigned char _c; \
7821 + AuIOErr(fmt, ##__VA_ARGS__); \
7824 +#define AuUnsupportMsg "This operation is not supported." \
7825 + " Please report this application to aufs-users ML."
7826 +#define AuUnsupport(fmt, ...) do { \
7827 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7831 +#define AuTraceErr(e) do { \
7832 + if (unlikely((e) < 0)) \
7833 + AuDbg("err %d\n", (int)(e)); \
7836 +#define AuTraceErrPtr(p) do { \
7838 + AuDbg("err %ld\n", PTR_ERR(p)); \
7841 +/* dirty macros for debug print, use with "%.*s" and caution */
7842 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7844 +/* ---------------------------------------------------------------------- */
7847 +#ifdef CONFIG_AUFS_DEBUG
7848 +extern struct mutex au_dbg_mtx;
7849 +extern char *au_plevel;
7851 +void au_dpri_whlist(struct au_nhash *whlist);
7853 +void au_dpri_vdir(struct au_vdir *vdir);
7855 +void au_dpri_inode(struct inode *inode);
7856 +void au_dpri_dalias(struct inode *inode);
7857 +void au_dpri_dentry(struct dentry *dentry);
7859 +void au_dpri_file(struct file *filp);
7860 +struct super_block;
7861 +void au_dpri_sb(struct super_block *sb);
7863 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7864 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7865 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7866 +void au_dbg_verify_kthread(void);
7868 +int __init au_debug_init(void);
7870 +#define AuDbgWhlist(w) do { \
7871 + mutex_lock(&au_dbg_mtx); \
7873 + au_dpri_whlist(w); \
7874 + mutex_unlock(&au_dbg_mtx); \
7877 +#define AuDbgVdir(v) do { \
7878 + mutex_lock(&au_dbg_mtx); \
7880 + au_dpri_vdir(v); \
7881 + mutex_unlock(&au_dbg_mtx); \
7884 +#define AuDbgInode(i) do { \
7885 + mutex_lock(&au_dbg_mtx); \
7887 + au_dpri_inode(i); \
7888 + mutex_unlock(&au_dbg_mtx); \
7891 +#define AuDbgDAlias(i) do { \
7892 + mutex_lock(&au_dbg_mtx); \
7894 + au_dpri_dalias(i); \
7895 + mutex_unlock(&au_dbg_mtx); \
7898 +#define AuDbgDentry(d) do { \
7899 + mutex_lock(&au_dbg_mtx); \
7901 + au_dpri_dentry(d); \
7902 + mutex_unlock(&au_dbg_mtx); \
7905 +#define AuDbgFile(f) do { \
7906 + mutex_lock(&au_dbg_mtx); \
7908 + au_dpri_file(f); \
7909 + mutex_unlock(&au_dbg_mtx); \
7912 +#define AuDbgSb(sb) do { \
7913 + mutex_lock(&au_dbg_mtx); \
7914 + AuDbg(#sb "\n"); \
7916 + mutex_unlock(&au_dbg_mtx); \
7919 +#define AuDbgSym(addr) do { \
7920 + char sym[KSYM_SYMBOL_LEN]; \
7921 + sprint_symbol(sym, (unsigned long)addr); \
7922 + AuDbg("%s\n", sym); \
7925 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7926 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7927 +AuStubVoid(au_dbg_verify_kthread, void)
7928 +AuStubInt0(__init au_debug_init, void)
7930 +#define AuDbgWhlist(w) do {} while (0)
7931 +#define AuDbgVdir(v) do {} while (0)
7932 +#define AuDbgInode(i) do {} while (0)
7933 +#define AuDbgDAlias(i) do {} while (0)
7934 +#define AuDbgDentry(d) do {} while (0)
7935 +#define AuDbgFile(f) do {} while (0)
7936 +#define AuDbgSb(sb) do {} while (0)
7937 +#define AuDbgSym(addr) do {} while (0)
7938 +#endif /* CONFIG_AUFS_DEBUG */
7940 +/* ---------------------------------------------------------------------- */
7942 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7943 +int __init au_sysrq_init(void);
7944 +void au_sysrq_fin(void);
7946 +#ifdef CONFIG_HW_CONSOLE
7947 +#define au_dbg_blocked() do { \
7949 + handle_sysrq('w'); \
7952 +AuStubVoid(au_dbg_blocked, void)
7956 +AuStubInt0(__init au_sysrq_init, void)
7957 +AuStubVoid(au_sysrq_fin, void)
7958 +AuStubVoid(au_dbg_blocked, void)
7959 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7961 +#endif /* __KERNEL__ */
7962 +#endif /* __AUFS_DEBUG_H__ */
7963 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7964 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7965 +++ linux/fs/aufs/dentry.c 2024-05-13 17:13:00.618070924 +0200
7967 +// SPDX-License-Identifier: GPL-2.0
7969 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7971 + * This program is free software; you can redistribute it and/or modify
7972 + * it under the terms of the GNU General Public License as published by
7973 + * the Free Software Foundation; either version 2 of the License, or
7974 + * (at your option) any later version.
7976 + * This program is distributed in the hope that it will be useful,
7977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7979 + * GNU General Public License for more details.
7981 + * You should have received a copy of the GNU General Public License
7982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7986 + * lookup and dentry operations
7989 +#include <linux/iversion.h>
7993 + * returns positive/negative dentry, NULL or an error.
7994 + * NULL means whiteout-ed or not-found.
7996 +static struct dentry*
7997 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7998 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8000 + struct dentry *h_dentry;
8001 + struct inode *h_inode;
8002 + struct au_branch *br;
8003 + struct mnt_idmap *h_idmap;
8004 + struct path h_path;
8005 + int wh_found, opq;
8006 + unsigned char wh_able;
8007 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8008 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8012 + br = au_sbr(dentry->d_sb, bindex);
8013 + h_path.dentry = h_parent;
8014 + h_path.mnt = au_br_mnt(br);
8015 + h_idmap = au_br_idmap(br);
8016 + wh_able = !!au_br_whable(br->br_perm);
8018 + wh_found = au_wh_test(h_idmap, &h_path, &args->whname,
8020 + h_dentry = ERR_PTR(wh_found);
8023 + if (unlikely(wh_found < 0))
8026 + /* We found a whiteout */
8027 + /* au_set_dbbot(dentry, bindex); */
8028 + au_set_dbwh(dentry, bindex);
8030 + return NULL; /* success */
8034 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8036 + h_dentry = au_sio_lkup_one(h_idmap, args->name, &h_path);
8037 + if (IS_ERR(h_dentry)) {
8038 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8044 + h_inode = d_inode(h_dentry);
8045 + if (d_is_negative(h_dentry)) {
8048 + } else if (wh_found
8049 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8051 + else if (au_ftest_lkup(args->flags, DIRREN)
8053 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8054 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8055 + (unsigned long long)h_inode->i_ino);
8059 + if (au_dbbot(dentry) <= bindex)
8060 + au_set_dbbot(dentry, bindex);
8061 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8062 + au_set_dbtop(dentry, bindex);
8063 + au_set_h_dptr(dentry, bindex, h_dentry);
8065 + if (!d_is_dir(h_dentry)
8067 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8068 + goto out; /* success */
8070 + h_path.dentry = h_dentry;
8071 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8072 + opq = au_diropq_test(h_idmap, &h_path);
8073 + inode_unlock_shared(h_inode);
8075 + au_set_dbdiropq(dentry, bindex);
8076 + else if (unlikely(opq < 0)) {
8077 + au_set_h_dptr(dentry, bindex, NULL);
8078 + h_dentry = ERR_PTR(opq);
8089 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8091 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8092 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8098 + * returns the number of lower positive dentries,
8099 + * otherwise an error.
8100 + * can be called at unlinking with @type is zero.
8102 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8103 + unsigned int flags)
8105 + int npositive, err;
8106 + aufs_bindex_t bindex, btail, bdiropq;
8107 + unsigned char isdir, dirperm1, dirren;
8108 + struct au_do_lookup_args args = {
8110 + .name = &dentry->d_name
8112 + struct dentry *parent;
8113 + struct super_block *sb;
8115 + sb = dentry->d_sb;
8116 + err = au_test_shwh(sb, args.name);
8117 + if (unlikely(err))
8120 + err = au_wh_name_alloc(&args.whname, args.name);
8121 + if (unlikely(err))
8124 + isdir = !!d_is_dir(dentry);
8125 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8126 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8128 + au_fset_lkup(args.flags, DIRREN);
8131 + parent = dget_parent(dentry);
8132 + btail = au_dbtaildir(parent);
8133 + for (bindex = btop; bindex <= btail; bindex++) {
8134 + struct dentry *h_parent, *h_dentry;
8135 + struct inode *h_inode, *h_dir;
8136 + struct au_branch *br;
8138 + h_dentry = au_h_dptr(dentry, bindex);
8140 + if (d_is_positive(h_dentry))
8144 + h_parent = au_h_dptr(parent, bindex);
8145 + if (!h_parent || !d_is_dir(h_parent))
8149 + /* if the inum matches, then use the prepared name */
8150 + err = au_dr_lkup_name(&args, bindex);
8151 + if (unlikely(err))
8155 + h_dir = d_inode(h_parent);
8156 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8157 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8158 + inode_unlock_shared(h_dir);
8159 + err = PTR_ERR(h_dentry);
8160 + if (IS_ERR(h_dentry))
8163 + au_fclr_lkup(args.flags, ALLOW_NEG);
8165 + au_fset_lkup(args.flags, IGNORE_PERM);
8167 + if (au_dbwh(dentry) == bindex)
8171 + if (d_is_negative(h_dentry))
8173 + h_inode = d_inode(h_dentry);
8176 + args.type = h_inode->i_mode & S_IFMT;
8177 + if (args.type != S_IFDIR)
8180 + /* the type of lower may be different */
8181 + bdiropq = au_dbdiropq(dentry);
8182 + if (bdiropq >= 0 && bdiropq <= bindex)
8185 + br = au_sbr(sb, bindex);
8187 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8188 + /*add_ent*/NULL)) {
8189 + /* prepare next name to lookup */
8190 + err = au_dr_lkup(&args, dentry, bindex);
8191 + if (unlikely(err))
8197 + AuLabel(positive);
8198 + au_update_dbtop(dentry);
8201 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8202 + && au_dbtop(dentry) < 0)) {
8204 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8210 + au_kfree_try_rcu(args.whname.name);
8212 + au_dr_lkup_fin(&args);
8217 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
8218 + struct path *ppath)
8220 + struct dentry *dentry;
8223 + if (!au_test_h_perm_sio(idmap, d_inode(ppath->dentry), MAY_EXEC))
8224 + dentry = vfsub_lkup_one(name, ppath);
8226 + struct vfsub_lkup_one_args args = {
8232 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8233 + if (unlikely(wkq_err))
8234 + dentry = ERR_PTR(wkq_err);
8241 + * lookup @dentry on @bindex which should be negative.
8243 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8246 + struct dentry *parent, *h_dentry;
8247 + struct au_branch *br;
8248 + struct mnt_idmap *h_idmap;
8249 + struct path h_ppath;
8251 + parent = dget_parent(dentry);
8252 + br = au_sbr(dentry->d_sb, bindex);
8253 + h_ppath.dentry = au_h_dptr(parent, bindex);
8254 + h_ppath.mnt = au_br_mnt(br);
8255 + h_idmap = au_br_idmap(br);
8257 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8259 + h_dentry = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
8260 + err = PTR_ERR(h_dentry);
8261 + if (IS_ERR(h_dentry))
8263 + if (unlikely(d_is_positive(h_dentry))) {
8265 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8271 + if (bindex < au_dbtop(dentry))
8272 + au_set_dbtop(dentry, bindex);
8273 + if (au_dbbot(dentry) < bindex)
8274 + au_set_dbbot(dentry, bindex);
8275 + au_set_h_dptr(dentry, bindex, h_dentry);
8282 +/* ---------------------------------------------------------------------- */
8284 +/* subset of struct inode */
8286 + unsigned long i_ino;
8287 + /* unsigned int i_nlink; */
8293 + blkcnt_t i_blocks;
8298 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8300 + ia->i_ino = h_inode->i_ino;
8301 + /* ia->i_nlink = h_inode->i_nlink; */
8302 + ia->i_uid = h_inode->i_uid;
8303 + ia->i_gid = h_inode->i_gid;
8304 + ia->i_version = inode_query_iversion(h_inode);
8306 + ia->i_size = h_inode->i_size;
8307 + ia->i_blocks = h_inode->i_blocks;
8309 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8312 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8314 + return ia->i_ino != h_inode->i_ino
8315 + /* || ia->i_nlink != h_inode->i_nlink */
8316 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8317 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8318 + || !inode_eq_iversion(h_inode, ia->i_version)
8320 + || ia->i_size != h_inode->i_size
8321 + || ia->i_blocks != h_inode->i_blocks
8323 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8326 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8327 + struct au_branch *br)
8330 + struct au_iattr ia;
8331 + struct inode *h_inode;
8332 + struct dentry *h_d;
8333 + struct super_block *h_sb;
8334 + struct path h_ppath;
8337 + memset(&ia, -1, sizeof(ia));
8338 + h_sb = h_dentry->d_sb;
8340 + if (d_is_positive(h_dentry)) {
8341 + h_inode = d_inode(h_dentry);
8342 + au_iattr_save(&ia, h_inode);
8343 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8344 + /* nfs d_revalidate may return 0 for negative dentry */
8345 + /* fuse d_revalidate always return 0 for negative dentry */
8348 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8349 + h_ppath.dentry = h_parent;
8350 + h_ppath.mnt = au_br_mnt(br);
8351 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8352 + err = PTR_ERR(h_d);
8357 + if (unlikely(h_d != h_dentry
8358 + || d_inode(h_d) != h_inode
8359 + || (h_inode && au_iattr_test(&ia, h_inode))))
8360 + err = au_busy_or_stale();
8368 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8369 + struct dentry *h_parent, struct au_branch *br)
8374 + if (udba == AuOpt_UDBA_REVAL
8375 + && !au_test_fs_remote(h_dentry->d_sb)) {
8377 + err = (d_inode(h_dentry->d_parent) != h_dir);
8378 + } else if (udba != AuOpt_UDBA_NONE)
8379 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8384 +/* ---------------------------------------------------------------------- */
8386 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8389 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8390 + struct au_hdentry tmp, *p, *q;
8391 + struct au_dinfo *dinfo;
8392 + struct super_block *sb;
8394 + DiMustWriteLock(dentry);
8396 + sb = dentry->d_sb;
8397 + dinfo = au_di(dentry);
8398 + bbot = dinfo->di_bbot;
8399 + bwh = dinfo->di_bwh;
8400 + bdiropq = dinfo->di_bdiropq;
8401 + bindex = dinfo->di_btop;
8402 + p = au_hdentry(dinfo, bindex);
8403 + for (; bindex <= bbot; bindex++, p++) {
8404 + if (!p->hd_dentry)
8407 + new_bindex = au_br_index(sb, p->hd_id);
8408 + if (new_bindex == bindex)
8411 + if (dinfo->di_bwh == bindex)
8413 + if (dinfo->di_bdiropq == bindex)
8414 + bdiropq = new_bindex;
8415 + if (new_bindex < 0) {
8417 + p->hd_dentry = NULL;
8421 + /* swap two lower dentries, and loop again */
8422 + q = au_hdentry(dinfo, new_bindex);
8426 + if (tmp.hd_dentry) {
8432 + dinfo->di_bwh = -1;
8433 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8434 + dinfo->di_bwh = bwh;
8436 + dinfo->di_bdiropq = -1;
8438 + && bdiropq <= au_sbbot(sb)
8439 + && au_sbr_whable(sb, bdiropq))
8440 + dinfo->di_bdiropq = bdiropq;
8443 + dinfo->di_btop = -1;
8444 + dinfo->di_bbot = -1;
8445 + bbot = au_dbbot(parent);
8447 + p = au_hdentry(dinfo, bindex);
8448 + for (; bindex <= bbot; bindex++, p++)
8449 + if (p->hd_dentry) {
8450 + dinfo->di_btop = bindex;
8454 + if (dinfo->di_btop >= 0) {
8456 + p = au_hdentry(dinfo, bindex);
8457 + for (; bindex >= 0; bindex--, p--)
8458 + if (p->hd_dentry) {
8459 + dinfo->di_bbot = bindex;
8468 +static void au_do_hide(struct dentry *dentry)
8470 + struct inode *inode;
8472 + if (d_really_is_positive(dentry)) {
8473 + inode = d_inode(dentry);
8474 + if (!d_is_dir(dentry)) {
8475 + if (inode->i_nlink && !d_unhashed(dentry))
8476 + drop_nlink(inode);
8478 + clear_nlink(inode);
8479 + /* stop next lookup */
8480 + inode->i_flags |= S_DEAD;
8482 + smp_mb(); /* necessary? */
8487 +static int au_hide_children(struct dentry *parent)
8489 + int err, i, j, ndentry;
8490 + struct au_dcsub_pages dpages;
8491 + struct au_dpage *dpage;
8492 + struct dentry *dentry;
8494 + err = au_dpages_init(&dpages, GFP_NOFS);
8495 + if (unlikely(err))
8497 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8498 + if (unlikely(err))
8501 + /* in reverse order */
8502 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8503 + dpage = dpages.dpages + i;
8504 + ndentry = dpage->ndentry;
8505 + for (j = ndentry - 1; j >= 0; j--) {
8506 + dentry = dpage->dentries[j];
8507 + if (dentry != parent)
8508 + au_do_hide(dentry);
8513 + au_dpages_free(&dpages);
8518 +static void au_hide(struct dentry *dentry)
8522 + AuDbgDentry(dentry);
8523 + if (d_is_dir(dentry)) {
8524 + /* shrink_dcache_parent(dentry); */
8525 + err = au_hide_children(dentry);
8526 + if (unlikely(err))
8527 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8530 + au_do_hide(dentry);
8534 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8536 + * a dirty branch is added
8537 + * - on the top of layers
8538 + * - in the middle of layers
8539 + * - to the bottom of layers
8541 + * on the added branch there exists
8544 + * - a same named entry
8546 + * * negative --> positive
8547 + * * positive --> positive
8548 + * - type is unchanged
8549 + * - type is changed
8551 + * * negative --> negative
8552 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8555 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8556 + struct au_dinfo *tmp)
8559 + aufs_bindex_t bindex, bbot;
8561 + struct dentry *dentry;
8562 + struct inode *inode;
8564 + } orig_h, tmp_h = {
8567 + struct au_hdentry *hd;
8568 + struct inode *inode, *h_inode;
8569 + struct dentry *h_dentry;
8572 + AuDebugOn(dinfo->di_btop < 0);
8574 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8575 + orig_h.inode = NULL;
8576 + if (d_is_positive(orig_h.dentry)) {
8577 + orig_h.inode = d_inode(orig_h.dentry);
8578 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8580 + if (tmp->di_btop >= 0) {
8581 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8582 + if (d_is_positive(tmp_h.dentry)) {
8583 + tmp_h.inode = d_inode(tmp_h.dentry);
8584 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8589 + if (d_really_is_positive(dentry))
8590 + inode = d_inode(dentry);
8591 + if (!orig_h.inode) {
8592 + AuDbg("negative originally\n");
8598 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8599 + AuDebugOn(dinfo->di_bdiropq != -1);
8601 + if (!tmp_h.inode) {
8602 + AuDbg("negative --> negative\n");
8603 + /* should have only one negative lower */
8604 + if (tmp->di_btop >= 0
8605 + && tmp->di_btop < dinfo->di_btop) {
8606 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8607 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8608 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8609 + au_di_cp(dinfo, tmp);
8610 + hd = au_hdentry(tmp, tmp->di_btop);
8611 + au_set_h_dptr(dentry, tmp->di_btop,
8612 + dget(hd->hd_dentry));
8614 + au_dbg_verify_dinode(dentry);
8616 + AuDbg("negative --> positive\n");
8618 + * similar to the behaviour of creating with bypassing
8620 + * unhash it in order to force an error in the
8621 + * succeeding create operation.
8622 + * we should not set S_DEAD here.
8625 + /* au_di_swap(tmp, dinfo); */
8626 + au_dbg_verify_dinode(dentry);
8629 + AuDbg("positive originally\n");
8630 + /* inode may be NULL */
8631 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8632 + if (!tmp_h.inode) {
8633 + AuDbg("positive --> negative\n");
8634 + /* or bypassing aufs */
8636 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8637 + dinfo->di_bwh = tmp->di_bwh;
8639 + err = au_refresh_hinode_self(inode);
8640 + au_dbg_verify_dinode(dentry);
8641 + } else if (orig_h.mode == tmp_h.mode) {
8642 + AuDbg("positive --> positive, same type\n");
8643 + if (!S_ISDIR(orig_h.mode)
8644 + && dinfo->di_btop > tmp->di_btop) {
8646 + * similar to the behaviour of removing and
8651 + err = au_refresh_hinode_self(inode);
8652 + au_dbg_verify_dinode(dentry);
8654 + /* fill empty slots */
8655 + if (dinfo->di_btop > tmp->di_btop)
8656 + dinfo->di_btop = tmp->di_btop;
8657 + if (dinfo->di_bbot < tmp->di_bbot)
8658 + dinfo->di_bbot = tmp->di_bbot;
8659 + dinfo->di_bwh = tmp->di_bwh;
8660 + dinfo->di_bdiropq = tmp->di_bdiropq;
8661 + bbot = dinfo->di_bbot;
8662 + bindex = tmp->di_btop;
8663 + hd = au_hdentry(tmp, bindex);
8664 + for (; bindex <= bbot; bindex++, hd++) {
8665 + if (au_h_dptr(dentry, bindex))
8667 + h_dentry = hd->hd_dentry;
8670 + AuDebugOn(d_is_negative(h_dentry));
8671 + h_inode = d_inode(h_dentry);
8672 + AuDebugOn(orig_h.mode
8673 + != (h_inode->i_mode
8675 + au_set_h_dptr(dentry, bindex,
8679 + err = au_refresh_hinode(inode, dentry);
8680 + au_dbg_verify_dinode(dentry);
8683 + AuDbg("positive --> positive, different type\n");
8684 + /* similar to the behaviour of removing and creating */
8687 + err = au_refresh_hinode_self(inode);
8688 + au_dbg_verify_dinode(dentry);
8696 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8698 + const struct dentry_operations *dop
8699 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8700 + static const unsigned int mask
8701 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8703 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8705 + if (dentry->d_op == dop)
8708 + AuDbg("%pd\n", dentry);
8709 + spin_lock(&dentry->d_lock);
8710 + if (dop == &aufs_dop)
8711 + dentry->d_flags |= mask;
8713 + dentry->d_flags &= ~mask;
8714 + dentry->d_op = dop;
8715 + spin_unlock(&dentry->d_lock);
8718 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8720 + int err, ebrange, nbr;
8721 + unsigned int sigen;
8722 + struct au_dinfo *dinfo, *tmp;
8723 + struct super_block *sb;
8724 + struct inode *inode;
8726 + DiMustWriteLock(dentry);
8727 + AuDebugOn(IS_ROOT(dentry));
8728 + AuDebugOn(d_really_is_negative(parent));
8730 + sb = dentry->d_sb;
8731 + sigen = au_sigen(sb);
8732 + err = au_digen_test(parent, sigen);
8733 + if (unlikely(err))
8736 + nbr = au_sbbot(sb) + 1;
8737 + dinfo = au_di(dentry);
8738 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8739 + if (unlikely(err))
8741 + ebrange = au_dbrange_test(dentry);
8743 + ebrange = au_do_refresh_hdentry(dentry, parent);
8745 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8746 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8747 + if (d_really_is_positive(dentry)) {
8748 + inode = d_inode(dentry);
8749 + err = au_refresh_hinode_self(inode);
8751 + au_dbg_verify_dinode(dentry);
8753 + goto out_dgen; /* success */
8757 + /* temporary dinfo */
8758 + AuDbgDentry(dentry);
8760 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8761 + if (unlikely(!tmp))
8763 + au_di_swap(tmp, dinfo);
8764 + /* returns the number of positive dentries */
8766 + * if current working dir is removed, it returns an error.
8767 + * but the dentry is legal.
8769 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8770 + AuDbgDentry(dentry);
8771 + au_di_swap(tmp, dinfo);
8772 + if (err == -ENOENT)
8775 + /* compare/refresh by dinfo */
8776 + AuDbgDentry(dentry);
8777 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8778 + au_dbg_verify_dinode(dentry);
8781 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8782 + au_rw_write_unlock(&tmp->di_rwsem);
8784 + if (unlikely(err))
8788 + au_update_digen(dentry);
8790 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8791 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8792 + AuDbgDentry(dentry);
8798 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8799 + struct dentry *dentry, aufs_bindex_t bindex)
8804 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8807 + AuDbg("b%d\n", bindex);
8809 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8810 + * due to whiteout and branch permission.
8812 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8813 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8814 + /* it may return tri-state */
8815 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8817 + if (unlikely(valid < 0))
8827 +/* todo: remove this */
8828 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8829 + unsigned int flags, int do_udba, int dirren)
8832 + umode_t mode, h_mode;
8833 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8834 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8835 + struct inode *h_inode, *h_cached_inode;
8836 + struct dentry *h_dentry;
8837 + struct qstr *name, *h_name;
8844 + unhashed = !!d_unhashed(dentry);
8845 + is_root = !!IS_ROOT(dentry);
8846 + name = &dentry->d_name;
8847 + tmpfile = au_di(dentry)->di_tmpfile;
8850 + * Theoretically, REVAL test should be unnecessary in case of
8852 + * But {fs,i}notify doesn't fire some necessary events,
8853 + * IN_ATTRIB for atime/nlink/pageio
8854 + * Let's do REVAL test too.
8856 + if (do_udba && inode) {
8857 + mode = (inode->i_mode & S_IFMT);
8858 + plus = (inode->i_nlink > 0);
8859 + ibs = au_ibtop(inode);
8860 + ibe = au_ibbot(inode);
8863 + btop = au_dbtop(dentry);
8865 + if (inode && S_ISDIR(inode->i_mode))
8866 + btail = au_dbtaildir(dentry);
8867 + for (bindex = btop; bindex <= btail; bindex++) {
8868 + h_dentry = au_h_dptr(dentry, bindex);
8872 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8873 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8874 + spin_lock(&h_dentry->d_lock);
8875 + h_name = &h_dentry->d_name;
8876 + if (unlikely(do_udba
8879 + && (unhashed != !!d_unhashed(h_dentry)
8880 + || (!tmpfile && !dirren
8881 + && !au_qstreq(name, h_name))
8884 + && !(flags & LOOKUP_OPEN)
8885 + && (h_dentry->d_flags
8886 + & DCACHE_NFSFS_RENAMED)))
8890 + h_unhashed = d_unhashed(h_dentry);
8891 + spin_unlock(&h_dentry->d_lock);
8892 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8893 + unhashed, h_unhashed, dentry, h_dentry);
8896 + spin_unlock(&h_dentry->d_lock);
8898 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8899 + if (unlikely(err))
8900 + /* do not goto err, to keep the errno */
8903 + /* todo: plink too? */
8908 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8912 + if (d_is_positive(h_dentry))
8913 + h_inode = d_inode(h_dentry);
8916 + h_cached_inode = h_inode;
8918 + h_mode = (h_inode->i_mode & S_IFMT);
8919 + h_plus = (h_inode->i_nlink > 0);
8921 + if (inode && ibs <= bindex && bindex <= ibe)
8922 + h_cached_inode = au_h_iptr(inode, bindex);
8925 + if (unlikely(plus != h_plus && !tmpfile))
8928 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8930 + && !IS_ROOT(h_dentry)
8931 + && unhashed != d_unhashed(h_dentry)))
8934 + if (unlikely(mode != h_mode
8935 + || h_cached_inode != h_inode))
8948 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8949 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8952 + struct dentry *parent;
8954 + if (!au_digen_test(dentry, sigen))
8957 + parent = dget_parent(dentry);
8958 + di_read_lock_parent(parent, AuLock_IR);
8959 + AuDebugOn(au_digen_test(parent, sigen));
8960 + au_dbg_verify_gen(parent, sigen);
8961 + err = au_refresh_dentry(dentry, parent);
8962 + di_read_unlock(parent, AuLock_IR);
8968 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8971 + struct dentry *d, *parent;
8973 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8974 + return simple_reval_dpath(dentry, sigen);
8976 + /* slow loop, keep it simple and stupid */
8977 + /* cf: au_cpup_dirs() */
8980 + while (au_digen_test(dentry, sigen)) {
8984 + parent = dget_parent(d);
8985 + if (!au_digen_test(parent, sigen))
8991 + di_write_lock_child2(d);
8993 + /* someone might update our dentry while we were sleeping */
8994 + if (au_digen_test(d, sigen)) {
8996 + * todo: consolidate with simple_reval_dpath(),
8997 + * do_refresh() and au_reval_for_attr().
8999 + di_read_lock_parent(parent, AuLock_IR);
9000 + err = au_refresh_dentry(d, parent);
9001 + di_read_unlock(parent, AuLock_IR);
9005 + di_write_unlock(d);
9007 + if (unlikely(err))
9015 + * if valid returns 1, otherwise 0.
9017 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9020 + unsigned int sigen;
9021 + unsigned char do_udba, dirren;
9022 + struct super_block *sb;
9023 + struct inode *inode;
9025 + /* todo: support rcu-walk? */
9026 + if (flags & LOOKUP_RCU)
9030 + if (unlikely(!au_di(dentry)))
9034 + sb = dentry->d_sb;
9037 + * i_mutex of parent dir may be held,
9038 + * but we should not return 'invalid' due to busy.
9040 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9041 + if (unlikely(err)) {
9047 + if (d_really_is_positive(dentry))
9048 + inode = d_inode(dentry);
9049 + if (unlikely(inode && au_is_bad_inode(inode))) {
9054 + if (unlikely(au_dbrange_test(dentry))) {
9060 + sigen = au_sigen(sb);
9061 + if (au_digen_test(dentry, sigen)) {
9062 + AuDebugOn(IS_ROOT(dentry));
9063 + err = au_reval_dpath(dentry, sigen);
9064 + if (unlikely(err)) {
9069 + di_downgrade_lock(dentry, AuLock_IR);
9072 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9074 + && !(inode->i_state && I_LINKABLE)
9075 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9080 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9081 + if (do_udba && inode) {
9082 + aufs_bindex_t btop = au_ibtop(inode);
9083 + struct inode *h_inode;
9086 + h_inode = au_h_iptr(inode, btop);
9087 + if (h_inode && au_test_higen(inode, h_inode)) {
9094 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9095 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9096 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9098 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9104 + di_downgrade_lock(dentry, AuLock_IR);
9106 + aufs_read_unlock(dentry, AuLock_IR);
9111 + AuDbg("%pd invalid, %d\n", dentry, valid);
9117 +static void aufs_d_release(struct dentry *dentry)
9119 + if (au_di(dentry)) {
9120 + au_di_fin(dentry);
9121 + au_hn_di_reinit(dentry);
9125 +const struct dentry_operations aufs_dop = {
9126 + .d_revalidate = aufs_d_revalidate,
9127 + .d_weak_revalidate = aufs_d_revalidate,
9128 + .d_release = aufs_d_release
9131 +/* aufs_dop without d_revalidate */
9132 +const struct dentry_operations aufs_dop_noreval = {
9133 + .d_release = aufs_d_release
9135 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9136 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9137 +++ linux/fs/aufs/dentry.h 2024-05-13 17:13:00.618070924 +0200
9139 +/* SPDX-License-Identifier: GPL-2.0 */
9141 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9143 + * This program is free software; you can redistribute it and/or modify
9144 + * it under the terms of the GNU General Public License as published by
9145 + * the Free Software Foundation; either version 2 of the License, or
9146 + * (at your option) any later version.
9148 + * This program is distributed in the hope that it will be useful,
9149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9151 + * GNU General Public License for more details.
9153 + * You should have received a copy of the GNU General Public License
9154 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9158 + * lookup and dentry operations
9161 +#ifndef __AUFS_DENTRY_H__
9162 +#define __AUFS_DENTRY_H__
9166 +#include <linux/dcache.h>
9167 +#include "dirren.h"
9170 +struct au_hdentry {
9171 + struct dentry *hd_dentry;
9172 + aufs_bindex_t hd_id;
9176 + atomic_t di_generation;
9178 + struct au_rwsem di_rwsem;
9179 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9180 + unsigned char di_tmpfile; /* to allow the different name */
9181 + struct au_hdentry *di_hdentry;
9182 + struct file *di_htmpfile;
9183 + struct rcu_head rcu;
9184 +} ____cacheline_aligned_in_smp;
9186 +/* ---------------------------------------------------------------------- */
9188 +/* flags for au_lkup_dentry() */
9189 +#define AuLkup_ALLOW_NEG BIT(0)
9190 +#define AuLkup_IGNORE_PERM BIT(1)
9191 +#define AuLkup_DIRREN BIT(2)
9192 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9193 +#define au_fset_lkup(flags, name) \
9194 + do { (flags) |= AuLkup_##name; } while (0)
9195 +#define au_fclr_lkup(flags, name) \
9196 + do { (flags) &= ~AuLkup_##name; } while (0)
9198 +#ifndef CONFIG_AUFS_DIRREN
9199 +#undef AuLkup_DIRREN
9200 +#define AuLkup_DIRREN 0
9203 +struct au_do_lookup_args {
9204 + unsigned int flags;
9206 + struct qstr whname, *name;
9207 + struct au_dr_lookup dirren;
9210 +/* ---------------------------------------------------------------------- */
9213 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9215 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
9216 + struct path *ppath);
9217 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9218 + struct dentry *h_parent, struct au_branch *br);
9220 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9221 + unsigned int flags);
9222 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9223 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9224 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9225 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9228 +void au_di_init_once(void *_di);
9229 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9230 +void au_di_free(struct au_dinfo *dinfo);
9231 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9232 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9233 +int au_di_init(struct dentry *dentry);
9234 +void au_di_fin(struct dentry *dentry);
9235 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9237 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9238 +void di_read_unlock(struct dentry *d, int flags);
9239 +void di_downgrade_lock(struct dentry *d, int flags);
9240 +void di_write_lock(struct dentry *d, unsigned int lsc);
9241 +void di_write_unlock(struct dentry *d);
9242 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9243 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9244 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9246 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9247 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9248 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9249 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9251 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9252 + struct dentry *h_dentry);
9253 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9254 +int au_dbrange_test(struct dentry *dentry);
9255 +void au_update_digen(struct dentry *dentry);
9256 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9257 +void au_update_dbtop(struct dentry *dentry);
9258 +void au_update_dbbot(struct dentry *dentry);
9259 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9261 +/* ---------------------------------------------------------------------- */
9263 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9265 + return dentry->d_fsdata;
9268 +/* ---------------------------------------------------------------------- */
9270 +/* lock subclass for dinfo */
9272 + AuLsc_DI_CHILD, /* child first */
9273 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9274 + AuLsc_DI_CHILD3, /* copyup dirs */
9278 + AuLsc_DI_TMP /* temp for replacing dinfo */
9282 + * di_read_lock_child, di_write_lock_child,
9283 + * di_read_lock_child2, di_write_lock_child2,
9284 + * di_read_lock_child3, di_write_lock_child3,
9285 + * di_read_lock_parent, di_write_lock_parent,
9286 + * di_read_lock_parent2, di_write_lock_parent2,
9287 + * di_read_lock_parent3, di_write_lock_parent3,
9289 +#define AuReadLockFunc(name, lsc) \
9290 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9291 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9293 +#define AuWriteLockFunc(name, lsc) \
9294 +static inline void di_write_lock_##name(struct dentry *d) \
9295 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9297 +#define AuRWLockFuncs(name, lsc) \
9298 + AuReadLockFunc(name, lsc) \
9299 + AuWriteLockFunc(name, lsc)
9301 +AuRWLockFuncs(child, CHILD);
9302 +AuRWLockFuncs(child2, CHILD2);
9303 +AuRWLockFuncs(child3, CHILD3);
9304 +AuRWLockFuncs(parent, PARENT);
9305 +AuRWLockFuncs(parent2, PARENT2);
9306 +AuRWLockFuncs(parent3, PARENT3);
9308 +#undef AuReadLockFunc
9309 +#undef AuWriteLockFunc
9310 +#undef AuRWLockFuncs
9312 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9313 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9314 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9316 +/* ---------------------------------------------------------------------- */
9318 +/* todo: memory barrier? */
9319 +static inline unsigned int au_digen(struct dentry *d)
9321 + return atomic_read(&au_di(d)->di_generation);
9324 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9326 + hdentry->hd_dentry = NULL;
9329 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9330 + aufs_bindex_t bindex)
9332 + return di->di_hdentry + bindex;
9335 +static inline void au_hdput(struct au_hdentry *hd)
9338 + dput(hd->hd_dentry);
9341 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9343 + DiMustAnyLock(dentry);
9344 + return au_di(dentry)->di_btop;
9347 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9349 + DiMustAnyLock(dentry);
9350 + return au_di(dentry)->di_bbot;
9353 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9355 + DiMustAnyLock(dentry);
9356 + return au_di(dentry)->di_bwh;
9359 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9361 + DiMustAnyLock(dentry);
9362 + return au_di(dentry)->di_bdiropq;
9365 +/* todo: hard/soft set? */
9366 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9368 + DiMustWriteLock(dentry);
9369 + au_di(dentry)->di_btop = bindex;
9372 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9374 + DiMustWriteLock(dentry);
9375 + au_di(dentry)->di_bbot = bindex;
9378 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9380 + DiMustWriteLock(dentry);
9381 + /* dbwh can be outside of btop - bbot range */
9382 + au_di(dentry)->di_bwh = bindex;
9385 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9387 + DiMustWriteLock(dentry);
9388 + au_di(dentry)->di_bdiropq = bindex;
9391 +/* ---------------------------------------------------------------------- */
9393 +#ifdef CONFIG_AUFS_HNOTIFY
9394 +static inline void au_digen_dec(struct dentry *d)
9396 + atomic_dec(&au_di(d)->di_generation);
9399 +static inline void au_hn_di_reinit(struct dentry *dentry)
9401 + dentry->d_fsdata = NULL;
9404 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9405 +#endif /* CONFIG_AUFS_HNOTIFY */
9407 +#endif /* __KERNEL__ */
9408 +#endif /* __AUFS_DENTRY_H__ */
9409 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9410 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9411 +++ linux/fs/aufs/dinfo.c 2024-05-13 17:13:00.618070924 +0200
9413 +// SPDX-License-Identifier: GPL-2.0
9415 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9417 + * This program is free software; you can redistribute it and/or modify
9418 + * it under the terms of the GNU General Public License as published by
9419 + * the Free Software Foundation; either version 2 of the License, or
9420 + * (at your option) any later version.
9422 + * This program is distributed in the hope that it will be useful,
9423 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9424 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9425 + * GNU General Public License for more details.
9427 + * You should have received a copy of the GNU General Public License
9428 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9432 + * dentry private data
9437 +void au_di_init_once(void *_dinfo)
9439 + struct au_dinfo *dinfo = _dinfo;
9441 + au_rw_init(&dinfo->di_rwsem);
9444 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9446 + struct au_dinfo *dinfo;
9449 + dinfo = au_cache_alloc_dinfo();
9450 + if (unlikely(!dinfo))
9453 + nbr = au_sbbot(sb) + 1;
9456 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9457 + if (dinfo->di_hdentry) {
9458 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9459 + dinfo->di_btop = -1;
9460 + dinfo->di_bbot = -1;
9461 + dinfo->di_bwh = -1;
9462 + dinfo->di_bdiropq = -1;
9463 + dinfo->di_tmpfile = 0;
9464 + for (i = 0; i < nbr; i++)
9465 + dinfo->di_hdentry[i].hd_id = -1;
9466 + dinfo->di_htmpfile = NULL;
9470 + au_cache_free_dinfo(dinfo);
9477 +void au_di_free(struct au_dinfo *dinfo)
9479 + struct au_hdentry *p;
9480 + aufs_bindex_t bbot, bindex;
9482 + /* dentry may not be revalidated */
9483 + bindex = dinfo->di_btop;
9484 + if (bindex >= 0) {
9485 + bbot = dinfo->di_bbot;
9486 + p = au_hdentry(dinfo, bindex);
9487 + while (bindex++ <= bbot)
9490 + au_kfree_try_rcu(dinfo->di_hdentry);
9491 + au_cache_free_dinfo(dinfo);
9494 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9496 + struct au_hdentry *p;
9499 + AuRwMustWriteLock(&a->di_rwsem);
9500 + AuRwMustWriteLock(&b->di_rwsem);
9502 +#define DiSwap(v, name) \
9504 + v = a->di_##name; \
9505 + a->di_##name = b->di_##name; \
9506 + b->di_##name = v; \
9509 + DiSwap(p, hdentry);
9513 + DiSwap(bi, bdiropq);
9519 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9521 + AuRwMustWriteLock(&dst->di_rwsem);
9522 + AuRwMustWriteLock(&src->di_rwsem);
9524 + dst->di_btop = src->di_btop;
9525 + dst->di_bbot = src->di_bbot;
9526 + dst->di_bwh = src->di_bwh;
9527 + dst->di_bdiropq = src->di_bdiropq;
9531 +int au_di_init(struct dentry *dentry)
9534 + struct super_block *sb;
9535 + struct au_dinfo *dinfo;
9538 + sb = dentry->d_sb;
9539 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9541 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9542 + /* smp_mb(); */ /* atomic_set */
9543 + dentry->d_fsdata = dinfo;
9550 +void au_di_fin(struct dentry *dentry)
9552 + struct au_dinfo *dinfo;
9554 + dinfo = au_di(dentry);
9555 + AuRwDestroy(&dinfo->di_rwsem);
9556 + au_di_free(dinfo);
9559 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9562 + struct au_hdentry *hdp;
9564 + AuRwMustWriteLock(&dinfo->di_rwsem);
9567 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9569 + sz = sizeof(*hdp);
9570 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9573 + dinfo->di_hdentry = hdp;
9580 +/* ---------------------------------------------------------------------- */
9582 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9585 + case AuLsc_DI_CHILD:
9586 + ii_write_lock_child(inode);
9588 + case AuLsc_DI_CHILD2:
9589 + ii_write_lock_child2(inode);
9591 + case AuLsc_DI_CHILD3:
9592 + ii_write_lock_child3(inode);
9594 + case AuLsc_DI_PARENT:
9595 + ii_write_lock_parent(inode);
9597 + case AuLsc_DI_PARENT2:
9598 + ii_write_lock_parent2(inode);
9600 + case AuLsc_DI_PARENT3:
9601 + ii_write_lock_parent3(inode);
9608 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9611 + case AuLsc_DI_CHILD:
9612 + ii_read_lock_child(inode);
9614 + case AuLsc_DI_CHILD2:
9615 + ii_read_lock_child2(inode);
9617 + case AuLsc_DI_CHILD3:
9618 + ii_read_lock_child3(inode);
9620 + case AuLsc_DI_PARENT:
9621 + ii_read_lock_parent(inode);
9623 + case AuLsc_DI_PARENT2:
9624 + ii_read_lock_parent2(inode);
9626 + case AuLsc_DI_PARENT3:
9627 + ii_read_lock_parent3(inode);
9634 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9636 + struct inode *inode;
9638 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9639 + if (d_really_is_positive(d)) {
9640 + inode = d_inode(d);
9641 + if (au_ftest_lock(flags, IW))
9642 + do_ii_write_lock(inode, lsc);
9643 + else if (au_ftest_lock(flags, IR))
9644 + do_ii_read_lock(inode, lsc);
9648 +void di_read_unlock(struct dentry *d, int flags)
9650 + struct inode *inode;
9652 + if (d_really_is_positive(d)) {
9653 + inode = d_inode(d);
9654 + if (au_ftest_lock(flags, IW)) {
9655 + au_dbg_verify_dinode(d);
9656 + ii_write_unlock(inode);
9657 + } else if (au_ftest_lock(flags, IR)) {
9658 + au_dbg_verify_dinode(d);
9659 + ii_read_unlock(inode);
9662 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9665 +void di_downgrade_lock(struct dentry *d, int flags)
9667 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9668 + ii_downgrade_lock(d_inode(d));
9669 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9672 +void di_write_lock(struct dentry *d, unsigned int lsc)
9674 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9675 + if (d_really_is_positive(d))
9676 + do_ii_write_lock(d_inode(d), lsc);
9679 +void di_write_unlock(struct dentry *d)
9681 + au_dbg_verify_dinode(d);
9682 + if (d_really_is_positive(d))
9683 + ii_write_unlock(d_inode(d));
9684 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9687 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9689 + AuDebugOn(d1 == d2
9690 + || d_inode(d1) == d_inode(d2)
9691 + || d1->d_sb != d2->d_sb);
9693 + if ((isdir && au_test_subdir(d1, d2))
9695 + di_write_lock_child(d1);
9696 + di_write_lock_child2(d2);
9698 + di_write_lock_child(d2);
9699 + di_write_lock_child2(d1);
9703 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9705 + AuDebugOn(d1 == d2
9706 + || d_inode(d1) == d_inode(d2)
9707 + || d1->d_sb != d2->d_sb);
9709 + if ((isdir && au_test_subdir(d1, d2))
9711 + di_write_lock_parent(d1);
9712 + di_write_lock_parent2(d2);
9714 + di_write_lock_parent(d2);
9715 + di_write_lock_parent2(d1);
9719 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9721 + di_write_unlock(d1);
9722 + if (d_inode(d1) == d_inode(d2))
9723 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9725 + di_write_unlock(d2);
9728 +/* ---------------------------------------------------------------------- */
9730 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9734 + DiMustAnyLock(dentry);
9736 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9738 + AuDebugOn(bindex < 0);
9739 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9740 + AuDebugOn(d && au_dcount(d) <= 0);
9745 + * extended version of au_h_dptr().
9746 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9749 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9751 + struct dentry *h_dentry;
9752 + struct inode *inode, *h_inode;
9754 + AuDebugOn(d_really_is_negative(dentry));
9757 + if (au_dbtop(dentry) <= bindex
9758 + && bindex <= au_dbbot(dentry))
9759 + h_dentry = au_h_dptr(dentry, bindex);
9760 + if (h_dentry && !au_d_linkable(h_dentry)) {
9762 + goto out; /* success */
9765 + inode = d_inode(dentry);
9766 + AuDebugOn(bindex < au_ibtop(inode));
9767 + AuDebugOn(au_ibbot(inode) < bindex);
9768 + h_inode = au_h_iptr(inode, bindex);
9769 + h_dentry = d_find_alias(h_inode);
9771 + if (!IS_ERR(h_dentry)) {
9772 + if (!au_d_linkable(h_dentry))
9773 + goto out; /* success */
9779 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9780 + h_dentry = au_plink_lkup(inode, bindex);
9781 + AuDebugOn(!h_dentry);
9782 + if (!IS_ERR(h_dentry)) {
9783 + if (!au_d_hashed_positive(h_dentry))
9784 + goto out; /* success */
9791 + AuDbgDentry(h_dentry);
9795 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9797 + aufs_bindex_t bbot, bwh;
9799 + bbot = au_dbbot(dentry);
9801 + bwh = au_dbwh(dentry);
9804 + if (0 < bwh && bwh < bbot)
9810 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9812 + aufs_bindex_t bbot, bopq;
9814 + bbot = au_dbtail(dentry);
9816 + bopq = au_dbdiropq(dentry);
9817 + if (0 <= bopq && bopq < bbot)
9823 +/* ---------------------------------------------------------------------- */
9825 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9826 + struct dentry *h_dentry)
9828 + struct au_dinfo *dinfo;
9829 + struct au_hdentry *hd;
9830 + struct au_branch *br;
9832 + DiMustWriteLock(dentry);
9834 + dinfo = au_di(dentry);
9835 + hd = au_hdentry(dinfo, bindex);
9837 + hd->hd_dentry = h_dentry;
9839 + br = au_sbr(dentry->d_sb, bindex);
9840 + hd->hd_id = br->br_id;
9844 +int au_dbrange_test(struct dentry *dentry)
9847 + aufs_bindex_t btop, bbot;
9850 + btop = au_dbtop(dentry);
9851 + bbot = au_dbbot(dentry);
9853 + AuDebugOn(bbot < 0 && btop > bbot);
9856 + AuDebugOn(bbot >= 0);
9862 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9867 + if (unlikely(au_digen(dentry) != sigen
9868 + || au_iigen_test(d_inode(dentry), sigen)))
9874 +void au_update_digen(struct dentry *dentry)
9876 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9877 + /* smp_mb(); */ /* atomic_set */
9880 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9882 + struct au_dinfo *dinfo;
9883 + struct dentry *h_d;
9884 + struct au_hdentry *hdp;
9885 + aufs_bindex_t bindex, bbot;
9887 + DiMustWriteLock(dentry);
9889 + dinfo = au_di(dentry);
9890 + if (!dinfo || dinfo->di_btop < 0)
9893 + if (do_put_zero) {
9894 + bbot = dinfo->di_bbot;
9895 + bindex = dinfo->di_btop;
9896 + hdp = au_hdentry(dinfo, bindex);
9897 + for (; bindex <= bbot; bindex++, hdp++) {
9898 + h_d = hdp->hd_dentry;
9899 + if (h_d && d_is_negative(h_d))
9900 + au_set_h_dptr(dentry, bindex, NULL);
9904 + dinfo->di_btop = 0;
9905 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9906 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9907 + if (hdp->hd_dentry)
9909 + if (dinfo->di_btop > dinfo->di_bbot) {
9910 + dinfo->di_btop = -1;
9911 + dinfo->di_bbot = -1;
9915 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9916 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9917 + if (hdp->hd_dentry)
9919 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9922 +void au_update_dbtop(struct dentry *dentry)
9924 + aufs_bindex_t bindex, bbot;
9925 + struct dentry *h_dentry;
9927 + bbot = au_dbbot(dentry);
9928 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9929 + h_dentry = au_h_dptr(dentry, bindex);
9932 + if (d_is_positive(h_dentry)) {
9933 + au_set_dbtop(dentry, bindex);
9936 + au_set_h_dptr(dentry, bindex, NULL);
9940 +void au_update_dbbot(struct dentry *dentry)
9942 + aufs_bindex_t bindex, btop;
9943 + struct dentry *h_dentry;
9945 + btop = au_dbtop(dentry);
9946 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9947 + h_dentry = au_h_dptr(dentry, bindex);
9950 + if (d_is_positive(h_dentry)) {
9951 + au_set_dbbot(dentry, bindex);
9954 + au_set_h_dptr(dentry, bindex, NULL);
9958 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9960 + aufs_bindex_t bindex, bbot;
9962 + bbot = au_dbbot(dentry);
9963 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9964 + if (au_h_dptr(dentry, bindex) == h_dentry)
9968 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9969 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9970 +++ linux/fs/aufs/dir.c 2024-05-13 17:13:00.618070924 +0200
9972 +// SPDX-License-Identifier: GPL-2.0
9974 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9976 + * This program is free software; you can redistribute it and/or modify
9977 + * it under the terms of the GNU General Public License as published by
9978 + * the Free Software Foundation; either version 2 of the License, or
9979 + * (at your option) any later version.
9981 + * This program is distributed in the hope that it will be useful,
9982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9984 + * GNU General Public License for more details.
9986 + * You should have received a copy of the GNU General Public License
9987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9991 + * directory operations
9994 +#include <linux/fs_stack.h>
9995 +#include <linux/iversion.h>
9998 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10000 + unsigned int nlink;
10002 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10004 + nlink = dir->i_nlink;
10005 + nlink += h_dir->i_nlink - 2;
10006 + if (h_dir->i_nlink < 2)
10008 + smp_mb(); /* for i_nlink */
10009 + /* 0 can happen in revaliding */
10010 + set_nlink(dir, nlink);
10013 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10015 + unsigned int nlink;
10017 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10019 + nlink = dir->i_nlink;
10020 + nlink -= h_dir->i_nlink - 2;
10021 + if (h_dir->i_nlink < 2)
10023 + smp_mb(); /* for i_nlink */
10024 + /* nlink == 0 means the branch-fs is broken */
10025 + set_nlink(dir, nlink);
10028 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10031 + aufs_bindex_t bindex, bbot;
10032 + struct file *h_file;
10033 + struct dentry *h_dentry;
10037 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10039 + bbot = au_fbbot_dir(file);
10040 + for (bindex = au_fbtop(file);
10041 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10043 + h_file = au_hf_dir(file, bindex);
10044 + if (h_file && file_inode(h_file))
10045 + sz += vfsub_f_size_read(h_file);
10048 + AuDebugOn(!dentry);
10049 + AuDebugOn(!d_is_dir(dentry));
10051 + bbot = au_dbtaildir(dentry);
10052 + for (bindex = au_dbtop(dentry);
10053 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10055 + h_dentry = au_h_dptr(dentry, bindex);
10056 + if (h_dentry && d_is_positive(h_dentry))
10057 + sz += i_size_read(d_inode(h_dentry));
10060 + if (sz < KMALLOC_MAX_SIZE)
10061 + sz = roundup_pow_of_two(sz);
10062 + if (sz > KMALLOC_MAX_SIZE)
10063 + sz = KMALLOC_MAX_SIZE;
10064 + else if (sz < NAME_MAX) {
10065 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10066 + sz = AUFS_RDBLK_DEF;
10071 +struct au_dir_ts_arg {
10072 + struct dentry *dentry;
10073 + aufs_bindex_t brid;
10076 +static void au_do_dir_ts(void *arg)
10078 + struct au_dir_ts_arg *a = arg;
10079 + struct au_dtime dt;
10080 + struct path h_path;
10081 + struct timespec64 ts;
10082 + struct inode *dir, *h_dir;
10083 + struct super_block *sb;
10084 + struct au_branch *br;
10085 + struct au_hinode *hdir;
10087 + aufs_bindex_t btop, bindex;
10089 + sb = a->dentry->d_sb;
10090 + if (d_really_is_negative(a->dentry))
10092 + /* no dir->i_mutex lock */
10093 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10095 + dir = d_inode(a->dentry);
10096 + btop = au_ibtop(dir);
10097 + bindex = au_br_index(sb, a->brid);
10098 + if (bindex < btop)
10101 + br = au_sbr(sb, bindex);
10102 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10103 + if (!h_path.dentry)
10105 + h_path.mnt = au_br_mnt(br);
10106 + au_dtime_store(&dt, a->dentry, &h_path);
10108 + br = au_sbr(sb, btop);
10109 + if (!au_br_writable(br->br_perm))
10111 + h_path.dentry = au_h_dptr(a->dentry, btop);
10112 + h_path.mnt = au_br_mnt(br);
10113 + err = vfsub_mnt_want_write(h_path.mnt);
10116 + hdir = au_hi(dir, btop);
10117 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10118 + h_dir = au_h_iptr(dir, btop);
10119 + ts = inode_get_mtime(h_dir);
10120 + if (h_dir->i_nlink
10121 + && timespec64_compare(&ts, &dt.dt_mtime) < 0) {
10122 + dt.dt_h_path = h_path;
10123 + au_dtime_revert(&dt);
10125 + au_hn_inode_unlock(hdir);
10126 + vfsub_mnt_drop_write(h_path.mnt);
10127 + au_cpup_attr_timesizes(dir);
10130 + aufs_read_unlock(a->dentry, AuLock_DW);
10133 + au_nwt_done(&au_sbi(sb)->si_nowait);
10134 + au_kfree_try_rcu(arg);
10137 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10139 + int perm, wkq_err;
10140 + aufs_bindex_t btop;
10141 + struct au_dir_ts_arg *arg;
10142 + struct dentry *dentry;
10143 + struct super_block *sb;
10147 + dentry = d_find_any_alias(dir);
10148 + AuDebugOn(!dentry);
10149 + sb = dentry->d_sb;
10150 + btop = au_ibtop(dir);
10151 + if (btop == bindex) {
10152 + au_cpup_attr_timesizes(dir);
10156 + perm = au_sbr_perm(sb, btop);
10157 + if (!au_br_writable(perm))
10160 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10164 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10165 + arg->brid = au_sbr_id(sb, bindex);
10166 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10167 + if (unlikely(wkq_err)) {
10168 + pr_err("wkq %d\n", wkq_err);
10170 + au_kfree_try_rcu(arg);
10177 +/* ---------------------------------------------------------------------- */
10179 +static int reopen_dir(struct file *file)
10182 + unsigned int flags;
10183 + aufs_bindex_t bindex, btail, btop;
10184 + struct dentry *dentry, *h_dentry;
10185 + struct file *h_file;
10187 + /* open all lower dirs */
10188 + dentry = file->f_path.dentry;
10189 + btop = au_dbtop(dentry);
10190 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10191 + au_set_h_fptr(file, bindex, NULL);
10192 + au_set_fbtop(file, btop);
10194 + btail = au_dbtaildir(dentry);
10195 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10196 + au_set_h_fptr(file, bindex, NULL);
10197 + au_set_fbbot_dir(file, btail);
10199 + flags = vfsub_file_flags(file);
10200 + for (bindex = btop; bindex <= btail; bindex++) {
10201 + h_dentry = au_h_dptr(dentry, bindex);
10204 + h_file = au_hf_dir(file, bindex);
10208 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10209 + err = PTR_ERR(h_file);
10210 + if (IS_ERR(h_file))
10211 + goto out; /* close all? */
10212 + au_set_h_fptr(file, bindex, h_file);
10214 + au_update_figen(file);
10215 + /* todo: necessary? */
10216 + /* file->f_ra = h_file->f_ra; */
10223 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10226 + aufs_bindex_t bindex, btail;
10227 + struct dentry *dentry, *h_dentry;
10228 + struct vfsmount *mnt;
10230 + FiMustWriteLock(file);
10231 + AuDebugOn(h_file);
10234 + mnt = file->f_path.mnt;
10235 + dentry = file->f_path.dentry;
10236 + file->f_version = inode_query_iversion(d_inode(dentry));
10237 + bindex = au_dbtop(dentry);
10238 + au_set_fbtop(file, bindex);
10239 + btail = au_dbtaildir(dentry);
10240 + au_set_fbbot_dir(file, btail);
10241 + for (; !err && bindex <= btail; bindex++) {
10242 + h_dentry = au_h_dptr(dentry, bindex);
10246 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10247 + if (unlikely(err))
10249 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10250 + if (IS_ERR(h_file)) {
10251 + err = PTR_ERR(h_file);
10254 + au_set_h_fptr(file, bindex, h_file);
10256 + au_update_figen(file);
10257 + /* todo: necessary? */
10258 + /* file->f_ra = h_file->f_ra; */
10260 + return 0; /* success */
10263 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10264 + au_set_h_fptr(file, bindex, NULL);
10265 + au_set_fbtop(file, -1);
10266 + au_set_fbbot_dir(file, -1);
10271 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10272 + struct file *file)
10275 + struct super_block *sb;
10276 + struct au_fidir *fidir;
10279 + sb = file->f_path.dentry->d_sb;
10280 + si_read_lock(sb, AuLock_FLUSH);
10281 + fidir = au_fidir_alloc(sb);
10283 + struct au_do_open_args args = {
10284 + .open = do_open_dir,
10287 + err = au_do_open(file, &args);
10288 + if (unlikely(err))
10289 + au_kfree_rcu(fidir);
10291 + si_read_unlock(sb);
10295 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10296 + struct file *file)
10298 + struct au_vdir *vdir_cache;
10299 + struct au_finfo *finfo;
10300 + struct au_fidir *fidir;
10301 + struct au_hfile *hf;
10302 + aufs_bindex_t bindex, bbot;
10304 + finfo = au_fi(file);
10305 + fidir = finfo->fi_hdir;
10307 + au_hbl_del(&finfo->fi_hlist,
10308 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10309 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10311 + au_vdir_free(vdir_cache);
10313 + bindex = finfo->fi_btop;
10314 + if (bindex >= 0) {
10315 + hf = fidir->fd_hfile + bindex;
10317 + * calls fput() instead of filp_close(),
10318 + * since no dnotify or lock for the lower file.
10320 + bbot = fidir->fd_bbot;
10321 + for (; bindex <= bbot; bindex++, hf++)
10323 + au_hfput(hf, /*execed*/0);
10325 + au_kfree_rcu(fidir);
10326 + finfo->fi_hdir = NULL;
10328 + au_finfo_fin(file);
10332 +/* ---------------------------------------------------------------------- */
10334 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10337 + aufs_bindex_t bindex, bbot;
10338 + struct file *h_file;
10341 + bbot = au_fbbot_dir(file);
10342 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10343 + h_file = au_hf_dir(file, bindex);
10345 + err = vfsub_flush(h_file, id);
10350 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10352 + return au_do_flush(file, id, au_do_flush_dir);
10355 +/* ---------------------------------------------------------------------- */
10357 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10360 + aufs_bindex_t bbot, bindex;
10361 + struct inode *inode;
10362 + struct super_block *sb;
10365 + sb = dentry->d_sb;
10366 + inode = d_inode(dentry);
10367 + IMustLock(inode);
10368 + bbot = au_dbbot(dentry);
10369 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10370 + struct path h_path;
10372 + if (au_test_ro(sb, bindex, inode))
10374 + h_path.dentry = au_h_dptr(dentry, bindex);
10375 + if (!h_path.dentry)
10378 + h_path.mnt = au_sbr_mnt(sb, bindex);
10379 + err = vfsub_fsync(NULL, &h_path, datasync);
10385 +static int au_do_fsync_dir(struct file *file, int datasync)
10388 + aufs_bindex_t bbot, bindex;
10389 + struct file *h_file;
10390 + struct super_block *sb;
10391 + struct inode *inode;
10393 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10394 + if (unlikely(err))
10397 + inode = file_inode(file);
10398 + sb = inode->i_sb;
10399 + bbot = au_fbbot_dir(file);
10400 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10401 + h_file = au_hf_dir(file, bindex);
10402 + if (!h_file || au_test_ro(sb, bindex, inode))
10405 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10413 + * @file may be NULL
10415 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10419 + struct dentry *dentry;
10420 + struct inode *inode;
10421 + struct super_block *sb;
10424 + dentry = file->f_path.dentry;
10425 + inode = d_inode(dentry);
10426 + inode_lock(inode);
10427 + sb = dentry->d_sb;
10428 + si_noflush_read_lock(sb);
10430 + err = au_do_fsync_dir(file, datasync);
10432 + di_write_lock_child(dentry);
10433 + err = au_do_fsync_dir_no_file(dentry, datasync);
10435 + au_cpup_attr_timesizes(inode);
10436 + di_write_unlock(dentry);
10438 + fi_write_unlock(file);
10440 + si_read_unlock(sb);
10441 + inode_unlock(inode);
10445 +/* ---------------------------------------------------------------------- */
10447 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10450 + struct dentry *dentry;
10451 + struct inode *inode, *h_inode;
10452 + struct super_block *sb;
10454 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10456 + dentry = file->f_path.dentry;
10457 + inode = d_inode(dentry);
10458 + IMustLock(inode);
10460 + sb = dentry->d_sb;
10461 + si_read_lock(sb, AuLock_FLUSH);
10462 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10463 + if (unlikely(err))
10465 + err = au_alive_dir(dentry);
10467 + err = au_vdir_init(file);
10468 + di_downgrade_lock(dentry, AuLock_IR);
10469 + if (unlikely(err))
10472 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10473 + if (!au_test_nfsd()) {
10474 + err = au_vdir_fill_de(file, ctx);
10475 + fsstack_copy_attr_atime(inode, h_inode);
10478 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10479 + * encode_fh() and others.
10481 + atomic_inc(&h_inode->i_count);
10482 + di_read_unlock(dentry, AuLock_IR);
10483 + si_read_unlock(sb);
10484 + err = au_vdir_fill_de(file, ctx);
10485 + fsstack_copy_attr_atime(inode, h_inode);
10486 + fi_write_unlock(file);
10494 + di_read_unlock(dentry, AuLock_IR);
10495 + fi_write_unlock(file);
10497 + si_read_unlock(sb);
10501 +/* ---------------------------------------------------------------------- */
10503 +#define AuTestEmpty_WHONLY BIT(0)
10504 +#define AuTestEmpty_CALLED BIT(1)
10505 +#define AuTestEmpty_SHWH BIT(2)
10506 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10507 +#define au_fset_testempty(flags, name) \
10508 + do { (flags) |= AuTestEmpty_##name; } while (0)
10509 +#define au_fclr_testempty(flags, name) \
10510 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10512 +#ifndef CONFIG_AUFS_SHWH
10513 +#undef AuTestEmpty_SHWH
10514 +#define AuTestEmpty_SHWH 0
10517 +struct test_empty_arg {
10518 + struct dir_context ctx;
10519 + struct au_nhash *whlist;
10520 + unsigned int flags;
10522 + aufs_bindex_t bindex;
10525 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10526 + int namelen, loff_t offset __maybe_unused, u64 ino,
10527 + unsigned int d_type)
10529 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10531 + char *name = (void *)__name;
10534 + au_fset_testempty(arg->flags, CALLED);
10536 + if (is_dot_dotdot(name, namelen))
10537 + goto out; /* success */
10539 + if (namelen <= AUFS_WH_PFX_LEN
10540 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10541 + if (au_ftest_testempty(arg->flags, WHONLY)
10542 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10543 + arg->err = -ENOTEMPTY;
10547 + name += AUFS_WH_PFX_LEN;
10548 + namelen -= AUFS_WH_PFX_LEN;
10549 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10550 + arg->err = au_nhash_append_wh
10551 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10552 + au_ftest_testempty(arg->flags, SHWH));
10556 + AuTraceErr(arg->err);
10557 + return !arg->err;
10560 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10563 + struct file *h_file;
10564 + struct au_branch *br;
10566 + h_file = au_h_open(dentry, arg->bindex,
10567 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10568 + /*file*/NULL, /*force_wr*/0);
10569 + err = PTR_ERR(h_file);
10570 + if (IS_ERR(h_file))
10574 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10575 + && !file_inode(h_file)->i_nlink)
10580 + au_fclr_testempty(arg->flags, CALLED);
10582 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10585 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10589 + br = au_sbr(dentry->d_sb, arg->bindex);
10590 + au_lcnt_dec(&br->br_nfiles);
10595 +struct do_test_empty_args {
10597 + struct dentry *dentry;
10598 + struct test_empty_arg *arg;
10601 +static void call_do_test_empty(void *args)
10603 + struct do_test_empty_args *a = args;
10604 + *a->errp = do_test_empty(a->dentry, a->arg);
10607 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10609 + int err, wkq_err;
10610 + struct dentry *h_dentry;
10611 + struct inode *h_inode;
10612 + struct mnt_idmap *h_idmap;
10614 + h_idmap = au_sbr_idmap(dentry->d_sb, arg->bindex);
10615 + h_dentry = au_h_dptr(dentry, arg->bindex);
10616 + h_inode = d_inode(h_dentry);
10617 + /* todo: i_mode changes anytime? */
10618 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10619 + err = au_test_h_perm_sio(h_idmap, h_inode, MAY_EXEC | MAY_READ);
10620 + inode_unlock_shared(h_inode);
10622 + err = do_test_empty(dentry, arg);
10624 + struct do_test_empty_args args = {
10626 + .dentry = dentry,
10629 + unsigned int flags = arg->flags;
10631 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10632 + if (unlikely(wkq_err))
10634 + arg->flags = flags;
10640 +int au_test_empty_lower(struct dentry *dentry)
10643 + unsigned int rdhash;
10644 + aufs_bindex_t bindex, btop, btail;
10645 + struct au_nhash whlist;
10646 + struct test_empty_arg arg = {
10648 + .actor = test_empty_cb
10651 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10653 + SiMustAnyLock(dentry->d_sb);
10655 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10657 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10658 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10659 + if (unlikely(err))
10663 + arg.whlist = &whlist;
10664 + btop = au_dbtop(dentry);
10665 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10666 + au_fset_testempty(arg.flags, SHWH);
10667 + test_empty = do_test_empty;
10668 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10669 + test_empty = sio_test_empty;
10670 + arg.bindex = btop;
10671 + err = test_empty(dentry, &arg);
10672 + if (unlikely(err))
10675 + au_fset_testempty(arg.flags, WHONLY);
10676 + btail = au_dbtaildir(dentry);
10677 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10678 + struct dentry *h_dentry;
10680 + h_dentry = au_h_dptr(dentry, bindex);
10681 + if (h_dentry && d_is_positive(h_dentry)) {
10682 + arg.bindex = bindex;
10683 + err = test_empty(dentry, &arg);
10688 + au_nhash_wh_free(&whlist);
10693 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10696 + struct test_empty_arg arg = {
10698 + .actor = test_empty_cb
10701 + aufs_bindex_t bindex, btail;
10704 + arg.whlist = whlist;
10705 + arg.flags = AuTestEmpty_WHONLY;
10706 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10707 + au_fset_testempty(arg.flags, SHWH);
10708 + btail = au_dbtaildir(dentry);
10709 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10710 + struct dentry *h_dentry;
10712 + h_dentry = au_h_dptr(dentry, bindex);
10713 + if (h_dentry && d_is_positive(h_dentry)) {
10714 + arg.bindex = bindex;
10715 + err = sio_test_empty(dentry, &arg);
10722 +/* ---------------------------------------------------------------------- */
10724 +const struct file_operations aufs_dir_fop = {
10725 + .owner = THIS_MODULE,
10726 + .llseek = default_llseek,
10727 + .read = generic_read_dir,
10728 + .iterate_shared = aufs_iterate_shared,
10729 + .unlocked_ioctl = aufs_ioctl_dir,
10730 +#ifdef CONFIG_COMPAT
10731 + .compat_ioctl = aufs_compat_ioctl_dir,
10733 + .open = aufs_open_dir,
10734 + .release = aufs_release_dir,
10735 + .flush = aufs_flush_dir,
10736 + .fsync = aufs_fsync_dir
10738 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10739 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10740 +++ linux/fs/aufs/dir.h 2024-05-13 17:13:00.618070924 +0200
10742 +/* SPDX-License-Identifier: GPL-2.0 */
10744 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10746 + * This program is free software; you can redistribute it and/or modify
10747 + * it under the terms of the GNU General Public License as published by
10748 + * the Free Software Foundation; either version 2 of the License, or
10749 + * (at your option) any later version.
10751 + * This program is distributed in the hope that it will be useful,
10752 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10753 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10754 + * GNU General Public License for more details.
10756 + * You should have received a copy of the GNU General Public License
10757 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10761 + * directory operations
10764 +#ifndef __AUFS_DIR_H__
10765 +#define __AUFS_DIR_H__
10769 +#include <linux/fs.h>
10771 +/* ---------------------------------------------------------------------- */
10773 +/* need to be faster and smaller */
10776 + unsigned int nh_num;
10777 + struct hlist_head *nh_head;
10780 +struct au_vdir_destr {
10781 + unsigned char len;
10782 + unsigned char name[];
10785 +struct au_vdir_dehstr {
10786 + struct hlist_node hash;
10787 + struct au_vdir_destr *str;
10788 + struct rcu_head rcu;
10789 +} ____cacheline_aligned_in_smp;
10791 +struct au_vdir_de {
10793 + unsigned char de_type;
10794 + /* caution: packed */
10795 + struct au_vdir_destr de_str;
10798 +struct au_vdir_wh {
10799 + struct hlist_node wh_hash;
10800 +#ifdef CONFIG_AUFS_SHWH
10802 + aufs_bindex_t wh_bindex;
10803 + unsigned char wh_type;
10805 + aufs_bindex_t wh_bindex;
10807 + /* caution: packed */
10808 + struct au_vdir_destr wh_str;
10811 +union au_vdir_deblk_p {
10812 + unsigned char *deblk;
10813 + struct au_vdir_de *de;
10817 + unsigned char **vd_deblk;
10818 + unsigned long vd_nblk;
10820 + unsigned long ul;
10821 + union au_vdir_deblk_p p;
10825 + unsigned int vd_deblk_sz;
10826 + unsigned long vd_jiffy;
10827 + struct rcu_head rcu;
10828 +} ____cacheline_aligned_in_smp;
10830 +/* ---------------------------------------------------------------------- */
10833 +extern const struct file_operations aufs_dir_fop;
10834 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10835 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10836 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10837 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10838 +int au_test_empty_lower(struct dentry *dentry);
10839 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10842 +unsigned int au_rdhash_est(loff_t sz);
10843 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10844 +void au_nhash_wh_free(struct au_nhash *whlist);
10845 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10847 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10848 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10849 + unsigned int d_type, aufs_bindex_t bindex,
10850 + unsigned char shwh);
10851 +void au_vdir_free(struct au_vdir *vdir);
10852 +int au_vdir_init(struct file *file);
10853 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10856 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10858 +#ifdef CONFIG_AUFS_RDU
10860 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10861 +#ifdef CONFIG_COMPAT
10862 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10863 + unsigned long arg);
10866 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10867 + unsigned int cmd, unsigned long arg)
10868 +#ifdef CONFIG_COMPAT
10869 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10870 + unsigned int cmd, unsigned long arg)
10874 +#endif /* __KERNEL__ */
10875 +#endif /* __AUFS_DIR_H__ */
10876 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10877 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10878 +++ linux/fs/aufs/dirren.c 2024-05-13 17:13:00.618070924 +0200
10880 +// SPDX-License-Identifier: GPL-2.0
10882 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10884 + * This program is free software; you can redistribute it and/or modify
10885 + * it under the terms of the GNU General Public License as published by
10886 + * the Free Software Foundation; either version 2 of the License, or
10887 + * (at your option) any later version.
10889 + * This program is distributed in the hope that it will be useful,
10890 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10891 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10892 + * GNU General Public License for more details.
10894 + * You should have received a copy of the GNU General Public License
10895 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10899 + * special handling in renaming a directory
10900 + * in order to support looking-up the before-renamed name on the lower readonly
10904 +#include <linux/byteorder/generic.h>
10907 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10911 + idx = au_dr_ihash(ent->dr_h_ino);
10912 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10915 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10918 + struct hlist_bl_head *hbl;
10921 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10922 + hbl = dr->dr_h_ino + i;
10923 + hlist_bl_lock(hbl);
10924 + ret &= hlist_bl_empty(hbl);
10925 + hlist_bl_unlock(hbl);
10931 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10933 + struct au_dr_hino *found, *ent;
10934 + struct hlist_bl_head *hbl;
10935 + struct hlist_bl_node *pos;
10939 + idx = au_dr_ihash(ino);
10940 + hbl = dr->dr_h_ino + idx;
10941 + hlist_bl_lock(hbl);
10942 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10943 + if (ent->dr_h_ino == ino) {
10947 + hlist_bl_unlock(hbl);
10952 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10953 + struct au_dr_hino *add_ent)
10956 + struct hlist_bl_head *hbl;
10957 + struct hlist_bl_node *pos;
10958 + struct au_dr_hino *ent;
10961 + idx = au_dr_ihash(ino);
10962 + hbl = dr->dr_h_ino + idx;
10963 +#if 0 /* debug print */
10965 + struct hlist_bl_node *tmp;
10967 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10968 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10971 + hlist_bl_lock(hbl);
10972 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10973 + if (ent->dr_h_ino == ino) {
10977 + if (!found && add_ent)
10978 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10979 + hlist_bl_unlock(hbl);
10981 + if (!found && add_ent)
10982 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10987 +void au_dr_hino_free(struct au_dr_br *dr)
10990 + struct hlist_bl_head *hbl;
10991 + struct hlist_bl_node *pos, *tmp;
10992 + struct au_dr_hino *ent;
10994 + /* SiMustWriteLock(sb); */
10996 + for (i = 0; i < AuDirren_NHASH; i++) {
10997 + hbl = dr->dr_h_ino + i;
10998 + /* no spinlock since sbinfo must be write-locked */
10999 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11000 + au_kfree_rcu(ent);
11001 + INIT_HLIST_BL_HEAD(hbl);
11005 +/* returns the number of inodes or an error */
11006 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11007 + struct file *hinofile)
11011 + loff_t pos, oldsize;
11013 + struct inode *hinoinode;
11014 + struct hlist_bl_head *hbl;
11015 + struct hlist_bl_node *n1, *n2;
11016 + struct au_dr_hino *ent;
11018 + SiMustWriteLock(sb);
11019 + AuDebugOn(!au_br_writable(br->br_perm));
11021 + hinoinode = file_inode(hinofile);
11022 + oldsize = i_size_read(hinoinode);
11026 + hbl = br->br_dirren.dr_h_ino;
11027 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11028 + /* no bit-lock since sbinfo must be write-locked */
11029 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11030 + AuDbg("hi%llu, %pD2\n",
11031 + (unsigned long long)ent->dr_h_ino, hinofile);
11032 + u64 = cpu_to_be64(ent->dr_h_ino);
11033 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11034 + if (ssz == sizeof(u64))
11037 + /* write error */
11038 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11045 + /* regardless the error */
11046 + if (pos < oldsize) {
11047 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11055 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11062 + struct au_dr_hino *ent;
11063 + struct inode *hinoinode;
11064 + struct hlist_bl_head *hbl;
11068 + hbl = dr->dr_h_ino;
11069 + hinoinode = file_inode(hinofile);
11070 + sz = i_size_read(hinoinode);
11071 + AuDebugOn(sz % sizeof(u64));
11072 + n = sz / sizeof(u64);
11074 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11075 + if (unlikely(ssz != sizeof(u64))) {
11076 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11083 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11089 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11090 + AuDbg("hi%llu, %pD2\n",
11091 + (unsigned long long)ent->dr_h_ino, hinofile);
11092 + hidx = au_dr_ihash(ent->dr_h_ino);
11093 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11095 + goto out; /* success */
11098 + au_dr_hino_free(dr);
11105 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11106 + * @path is a switch to distinguish load and store.
11108 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11109 + struct au_branch *br, const struct path *path)
11112 + unsigned char load, suspend;
11113 + struct file *hinofile;
11114 + struct au_hinode *hdir;
11115 + struct inode *dir, *delegated;
11116 + struct path hinopath;
11117 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11118 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11120 + AuDebugOn(bindex < 0 && !br);
11121 + AuDebugOn(bindex >= 0 && br);
11126 + br = au_sbr(sb, bindex);
11129 + path = &br->br_path;
11130 + AuDebugOn(!au_br_writable(br->br_perm));
11131 + if (unlikely(!au_br_writable(br->br_perm)))
11137 + dir = d_inode(sb->s_root);
11138 + hdir = au_hinode(au_ii(dir), bindex);
11139 + dir = hdir->hi_inode;
11140 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11142 + dir = d_inode(path->dentry);
11143 + inode_lock_nested(dir, AuLsc_I_CHILD);
11145 + hinopath.mnt = path->mnt;
11146 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11147 + err = PTR_ERR(hinopath.dentry);
11148 + if (IS_ERR(hinopath.dentry))
11152 + flags = O_RDONLY;
11154 + if (d_is_negative(hinopath.dentry))
11155 + goto out_dput; /* success */
11157 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11158 + if (d_is_positive(hinopath.dentry)) {
11159 + delegated = NULL;
11160 + err = vfsub_unlink(dir, &hinopath, &delegated,
11163 + if (unlikely(err))
11164 + pr_err("ignored err %d, %pd2\n",
11165 + err, hinopath.dentry);
11166 + if (unlikely(err == -EWOULDBLOCK))
11171 + } else if (!d_is_positive(hinopath.dentry)) {
11172 + err = vfsub_create(dir, &hinopath, 0600,
11173 + /*want_excl*/false);
11175 + if (unlikely(err))
11178 + flags = O_WRONLY;
11180 + hinofile = vfsub_dentry_open(&hinopath, flags);
11182 + au_hn_inode_unlock(hdir);
11184 + inode_unlock(dir);
11185 + dput(hinopath.dentry);
11186 + AuTraceErrPtr(hinofile);
11187 + if (IS_ERR(hinofile)) {
11188 + err = PTR_ERR(hinofile);
11193 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11195 + err = au_dr_hino_store(sb, br, hinofile);
11200 + dput(hinopath.dentry);
11203 + au_hn_inode_unlock(hdir);
11205 + inode_unlock(dir);
11211 +/* ---------------------------------------------------------------------- */
11213 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11216 + struct kstatfs kstfs;
11218 + struct dentry *dentry;
11219 + struct super_block *sb;
11221 + err = vfs_statfs((void *)path, &kstfs);
11223 + if (unlikely(err))
11226 + /* todo: support for UUID */
11228 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11229 + brid->type = AuBrid_FSID;
11230 + brid->fsid = kstfs.f_fsid;
11232 + dentry = path->dentry;
11233 + sb = dentry->d_sb;
11236 + brid->type = AuBrid_DEV;
11245 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11246 + const struct path *path)
11249 + struct au_dr_br *dr;
11250 + struct hlist_bl_head *hbl;
11252 + dr = &br->br_dirren;
11253 + hbl = dr->dr_h_ino;
11254 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11255 + INIT_HLIST_BL_HEAD(hbl);
11257 + err = au_dr_brid_init(&dr->dr_brid, path);
11258 + if (unlikely(err))
11261 + if (au_opt_test(au_mntflags(sb), DIRREN))
11262 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11269 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11274 + if (au_br_writable(br->br_perm))
11275 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11277 + au_dr_hino_free(&br->br_dirren);
11282 +/* ---------------------------------------------------------------------- */
11284 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11285 + char *buf, size_t sz)
11288 + unsigned int major, minor;
11292 + err = snprintf(p, sz, "%d_", brid->type);
11293 + AuDebugOn(err > sz);
11296 + switch (brid->type) {
11297 + case AuBrid_Unset:
11299 + case AuBrid_UUID:
11300 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11302 + case AuBrid_FSID:
11303 + err = snprintf(p, sz, "%08x-%08x",
11304 + brid->fsid.val[0], brid->fsid.val[1]);
11307 + major = MAJOR(brid->dev);
11308 + minor = MINOR(brid->dev);
11309 + if (major <= 0xff && minor <= 0xff)
11310 + err = snprintf(p, sz, "%02x%02x", major, minor);
11312 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11315 + AuDebugOn(err > sz);
11318 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11319 + AuDebugOn(err > sz);
11326 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11329 + struct dentry *br_dentry;
11330 + struct inode *br_inode;
11332 + br_dentry = au_br_dentry(br);
11333 + br_inode = d_inode(br_dentry);
11334 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11335 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11336 + AuDebugOn(rlen > len);
11341 +/* ---------------------------------------------------------------------- */
11344 + * from the given @h_dentry, construct drinfo at @*fdata.
11345 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11348 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11349 + struct dentry *h_dentry,
11350 + unsigned char *allocated)
11353 + struct au_drinfo_fdata *f, *p;
11354 + struct au_drinfo *drinfo;
11355 + struct inode *h_inode;
11356 + struct qstr *qname;
11360 + h_inode = d_inode(h_dentry);
11361 + qname = &h_dentry->d_name;
11362 + drinfo = &f->drinfo;
11363 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11364 + drinfo->oldnamelen = qname->len;
11365 + if (*allocated < sizeof(*f) + qname->len) {
11366 + v = roundup_pow_of_two(*allocated + qname->len);
11367 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11368 + if (unlikely(!p)) {
11376 + drinfo = &f->drinfo;
11378 + memcpy(drinfo->oldname, qname->name, qname->len);
11379 + AuDbg("i%llu, %.*s\n",
11380 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11381 + drinfo->oldname);
11388 +/* callers have to free the return value */
11389 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11391 + struct au_drinfo *ret, *drinfo;
11392 + struct au_drinfo_fdata fdata;
11397 + ret = ERR_PTR(-EIO);
11399 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11400 + if (unlikely(ssz != sizeof(fdata))) {
11401 + AuIOErr("ssz %zd, %u, %pD2\n",
11402 + ssz, (unsigned int)sizeof(fdata), file);
11406 + fdata.magic = ntohl((__force __be32)fdata.magic);
11407 + switch (fdata.magic) {
11408 + case AUFS_DRINFO_MAGIC_V1:
11411 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11412 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11416 + drinfo = &fdata.drinfo;
11417 + len = drinfo->oldnamelen;
11419 + AuIOErr("broken drinfo %pD2\n", file);
11424 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11425 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11426 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11427 + (unsigned long long)drinfo->ino,
11428 + (unsigned long long)h_ino, file);
11429 + goto out; /* success */
11432 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11433 + if (unlikely(!ret)) {
11434 + ret = ERR_PTR(-ENOMEM);
11435 + AuTraceErrPtr(ret);
11440 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11441 + if (unlikely(ssz != len)) {
11442 + au_kfree_rcu(ret);
11443 + ret = ERR_PTR(-EIO);
11444 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11448 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11454 +/* ---------------------------------------------------------------------- */
11456 +/* in order to be revertible */
11457 +struct au_drinfo_rev_elm {
11459 + struct dentry *info_dentry;
11460 + struct au_drinfo *info_last;
11463 +struct au_drinfo_rev {
11464 + unsigned char already;
11465 + aufs_bindex_t nelm;
11466 + struct au_drinfo_rev_elm elm[];
11469 +/* todo: isn't it too large? */
11470 +struct au_drinfo_store {
11471 + struct path h_ppath;
11472 + struct dentry *h_dentry;
11473 + struct au_drinfo_fdata *fdata;
11474 + char *infoname; /* inside of whname, just after PFX */
11475 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11476 + aufs_bindex_t btgt, btail;
11477 + unsigned char no_sio,
11478 + allocated, /* current size of *fdata */
11479 + infonamelen, /* room size for p */
11480 + whnamelen, /* length of the generated name */
11481 + renameback; /* renamed back */
11484 +/* on rename(2) error, the caller should revert it using @elm */
11485 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11486 + struct au_drinfo_rev_elm *elm)
11491 + struct path infopath = {
11492 + .mnt = w->h_ppath.mnt
11494 + struct inode *h_dir, *h_inode, *delegated;
11495 + struct file *infofile;
11496 + struct qstr *qname;
11499 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11501 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11503 + AuTraceErrPtr(infopath.dentry);
11504 + if (IS_ERR(infopath.dentry)) {
11505 + err = PTR_ERR(infopath.dentry);
11510 + h_dir = d_inode(w->h_ppath.dentry);
11511 + if (elm && d_is_negative(infopath.dentry)) {
11512 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11514 + if (unlikely(err))
11516 + elm->created = 1;
11517 + elm->info_dentry = dget(infopath.dentry);
11520 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11521 + AuTraceErrPtr(infofile);
11522 + if (IS_ERR(infofile)) {
11523 + err = PTR_ERR(infofile);
11527 + h_inode = d_inode(infopath.dentry);
11528 + if (elm && i_size_read(h_inode)) {
11529 + h_inode = d_inode(w->h_dentry);
11530 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11531 + AuTraceErrPtr(elm->info_last);
11532 + if (IS_ERR(elm->info_last)) {
11533 + err = PTR_ERR(elm->info_last);
11534 + elm->info_last = NULL;
11535 + AuDebugOn(elm->info_dentry);
11540 + if (elm && w->renameback) {
11541 + delegated = NULL;
11542 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11544 + if (unlikely(err == -EWOULDBLOCK))
11550 + qname = &w->h_dentry->d_name;
11551 + len = sizeof(*w->fdata) + qname->len;
11553 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11554 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11555 + if (ssz == len) {
11556 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11557 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11558 + goto out_fput; /* success */
11563 + /* the caller should revert it using @elm */
11569 + dput(infopath.dentry);
11575 +struct au_call_drinfo_do_store_args {
11577 + struct au_drinfo_store *w;
11578 + struct au_drinfo_rev_elm *elm;
11581 +static void au_call_drinfo_do_store(void *args)
11583 + struct au_call_drinfo_do_store_args *a = args;
11585 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11588 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11589 + struct au_drinfo_rev_elm *elm)
11591 + int err, wkq_err;
11594 + err = au_drinfo_do_store(w, elm);
11596 + struct au_call_drinfo_do_store_args a = {
11601 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11602 + if (unlikely(wkq_err))
11610 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11611 + aufs_bindex_t btgt)
11615 + memset(w, 0, sizeof(*w));
11616 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11617 + strscpy(w->whname, AUFS_WH_DR_INFO_PFX, sizeof(AUFS_WH_DR_INFO_PFX));
11618 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11619 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11621 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11624 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11625 + if (unlikely(!w->fdata)) {
11629 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11636 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11638 + au_kfree_rcu(w->fdata);
11641 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11642 + struct au_drinfo_store *w)
11644 + struct au_drinfo_rev_elm *elm;
11645 + struct inode *h_dir, *delegated;
11647 + struct path infopath = {
11648 + .mnt = w->h_ppath.mnt
11651 + h_dir = d_inode(w->h_ppath.dentry);
11652 + IMustLock(h_dir);
11656 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11657 + AuDebugOn(elm->created && elm->info_last);
11658 + if (elm->created) {
11660 + delegated = NULL;
11661 + infopath.dentry = elm->info_dentry;
11662 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11665 + if (unlikely(err == -EWOULDBLOCK))
11667 + dput(elm->info_dentry);
11668 + } else if (elm->info_last) {
11670 + w->fdata->drinfo = *elm->info_last;
11671 + memcpy(w->fdata->drinfo.oldname,
11672 + elm->info_last->oldname,
11673 + elm->info_last->oldnamelen);
11674 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11675 + au_kfree_rcu(elm->info_last);
11677 + if (unlikely(err))
11678 + AuIOErr("%d, %s\n", err, w->whname);
11679 + /* go on even if err */
11683 +/* caller has to call au_dr_rename_fin() later */
11684 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11685 + struct qstr *dst_name, void *_rev)
11687 + int err, sz, nelm;
11688 + aufs_bindex_t bindex, btail;
11689 + struct au_drinfo_store work;
11690 + struct au_drinfo_rev *rev, **p;
11691 + struct au_drinfo_rev_elm *elm;
11692 + struct super_block *sb;
11693 + struct au_branch *br;
11694 + struct au_hinode *hdir;
11696 + err = au_drinfo_store_work_init(&work, btgt);
11698 + if (unlikely(err))
11702 + btail = au_dbtaildir(dentry);
11703 + nelm = btail - btgt;
11704 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11705 + rev = kcalloc(1, sz, GFP_NOFS);
11706 + if (unlikely(!rev)) {
11710 + rev->nelm = nelm;
11716 + sb = dentry->d_sb;
11717 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11718 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11719 + hdir = au_hi(d_inode(dentry), btgt);
11720 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11721 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11722 + work.h_dentry = au_h_dptr(dentry, bindex);
11723 + if (!work.h_dentry)
11726 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11727 + &work.allocated);
11729 + if (unlikely(err))
11732 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11733 + br = au_sbr(sb, bindex);
11734 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11735 + work.whnamelen += au_drinfo_name(br, work.infoname,
11736 + work.infonamelen);
11737 + AuDbg("whname %.*s, i%llu, %.*s\n",
11738 + work.whnamelen, work.whname,
11739 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11740 + work.fdata->drinfo.oldnamelen,
11741 + work.fdata->drinfo.oldname);
11743 + err = au_drinfo_store_sio(&work, elm);
11745 + if (unlikely(err))
11748 + if (unlikely(err)) {
11749 + /* revert all drinfo */
11750 + au_drinfo_store_rev(rev, &work);
11751 + au_kfree_try_rcu(rev);
11754 + au_hn_inode_unlock(hdir);
11757 + au_drinfo_store_work_fin(&work);
11762 +/* ---------------------------------------------------------------------- */
11764 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11765 + struct qstr *dst_name, void *_rev)
11767 + int err, already;
11769 + struct super_block *sb;
11770 + struct au_branch *br;
11771 + struct au_dr_br *dr;
11772 + struct dentry *h_dentry;
11773 + struct inode *h_inode;
11774 + struct au_dr_hino *ent;
11775 + struct au_drinfo_rev *rev, **p;
11777 + AuDbg("bindex %d\n", bindex);
11780 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11781 + if (unlikely(!ent))
11785 + br = au_sbr(sb, bindex);
11786 + dr = &br->br_dirren;
11787 + h_dentry = au_h_dptr(src, bindex);
11788 + h_inode = d_inode(h_dentry);
11789 + ino = h_inode->i_ino;
11790 + ent->dr_h_ino = ino;
11791 + already = au_dr_hino_test_add(dr, ino, ent);
11792 + AuDbg("b%d, hi%llu, already %d\n",
11793 + bindex, (unsigned long long)ino, already);
11795 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11800 + rev->already = already;
11801 + goto out; /* success */
11806 + au_dr_hino_del(dr, ent);
11807 + au_kfree_rcu(ent);
11814 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11816 + struct au_drinfo_rev *rev;
11817 + struct au_drinfo_rev_elm *elm;
11822 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11823 + dput(elm->info_dentry);
11824 + au_kfree_rcu(elm->info_last);
11826 + au_kfree_try_rcu(rev);
11829 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11832 + struct au_drinfo_store work;
11833 + struct au_drinfo_rev *rev = _rev;
11834 + struct super_block *sb;
11835 + struct au_branch *br;
11836 + struct inode *h_inode;
11837 + struct au_dr_br *dr;
11838 + struct au_dr_hino *ent;
11840 + err = au_drinfo_store_work_init(&work, btgt);
11841 + if (unlikely(err))
11845 + br = au_sbr(sb, btgt);
11846 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11847 + work.h_ppath.mnt = au_br_mnt(br);
11848 + au_drinfo_store_rev(rev, &work);
11849 + au_drinfo_store_work_fin(&work);
11850 + if (rev->already)
11853 + dr = &br->br_dirren;
11854 + h_inode = d_inode(work.h_ppath.dentry);
11855 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11857 + au_dr_hino_del(dr, ent);
11858 + au_kfree_rcu(ent);
11861 + au_kfree_try_rcu(rev);
11862 + if (unlikely(err))
11863 + pr_err("failed to remove dirren info\n");
11866 +/* ---------------------------------------------------------------------- */
11868 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11869 + char *whname, int whnamelen,
11870 + struct dentry **info_dentry)
11872 + struct au_drinfo *drinfo;
11874 + struct inode *h_dir;
11875 + struct path infopath;
11878 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11880 + *info_dentry = NULL;
11883 + h_dir = d_inode(h_ppath->dentry);
11884 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11885 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11886 + if (IS_ERR(infopath.dentry)) {
11887 + drinfo = (void *)infopath.dentry;
11891 + if (d_is_negative(infopath.dentry))
11892 + goto out_dput; /* success */
11894 + infopath.mnt = h_ppath->mnt;
11895 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11896 + inode_unlock_shared(h_dir);
11899 + drinfo = (void *)f;
11903 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11904 + if (IS_ERR_OR_NULL(drinfo))
11907 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11908 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11913 + dput(infopath.dentry);
11916 + inode_unlock_shared(h_dir);
11917 + AuTraceErrPtr(drinfo);
11921 +struct au_drinfo_do_load_args {
11922 + struct au_drinfo **drinfop;
11923 + struct path *h_ppath;
11926 + struct dentry **info_dentry;
11929 +static void au_call_drinfo_do_load(void *args)
11931 + struct au_drinfo_do_load_args *a = args;
11933 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11937 +struct au_drinfo_load {
11938 + struct path h_ppath;
11939 + struct qstr *qname;
11940 + unsigned char no_sio;
11942 + aufs_bindex_t ninfo;
11943 + struct au_drinfo **drinfo;
11946 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11947 + struct au_branch *br)
11949 + int err, wkq_err, whnamelen, e;
11950 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11951 + = AUFS_WH_DR_INFO_PFX;
11952 + struct au_drinfo *drinfo;
11953 + struct qstr oldname;
11954 + struct inode *h_dir, *delegated;
11955 + struct dentry *info_dentry;
11956 + struct path infopath;
11958 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11959 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11960 + sizeof(whname) - whnamelen);
11962 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11965 + struct au_drinfo_do_load_args args = {
11966 + .drinfop = &drinfo,
11967 + .h_ppath = &w->h_ppath,
11968 + .whname = whname,
11969 + .whnamelen = whnamelen,
11970 + .info_dentry = &info_dentry
11972 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11973 + if (unlikely(wkq_err))
11974 + drinfo = ERR_PTR(wkq_err);
11976 + err = PTR_ERR(drinfo);
11977 + if (IS_ERR_OR_NULL(drinfo))
11981 + oldname.len = drinfo->oldnamelen;
11982 + oldname.name = drinfo->oldname;
11983 + if (au_qstreq(w->qname, &oldname)) {
11984 + /* the name is renamed back */
11985 + au_kfree_rcu(drinfo);
11988 + infopath.dentry = info_dentry;
11989 + infopath.mnt = w->h_ppath.mnt;
11990 + h_dir = d_inode(w->h_ppath.dentry);
11991 + delegated = NULL;
11992 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11993 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11994 + inode_unlock(h_dir);
11996 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11997 + if (unlikely(e == -EWOULDBLOCK))
12000 + au_kfree_rcu(w->drinfo[bindex]);
12001 + w->drinfo[bindex] = drinfo;
12002 + dput(info_dentry);
12009 +/* ---------------------------------------------------------------------- */
12011 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12013 + struct au_drinfo **p = drinfo;
12016 + au_kfree_rcu(*drinfo++);
12017 + au_kfree_try_rcu(p);
12020 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12021 + aufs_bindex_t btgt)
12024 + struct au_drinfo_load w;
12025 + aufs_bindex_t bindex, bbot;
12026 + struct au_branch *br;
12027 + struct inode *h_dir;
12028 + struct au_dr_hino *ent;
12029 + struct super_block *sb;
12031 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12032 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12033 + AuLNPair(&lkup->whname), btgt);
12035 + sb = dentry->d_sb;
12036 + bbot = au_sbbot(sb);
12037 + w.ninfo = bbot + 1;
12038 + if (!lkup->dirren.drinfo) {
12039 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12040 + sizeof(*lkup->dirren.drinfo),
12042 + if (unlikely(!lkup->dirren.drinfo)) {
12046 + lkup->dirren.ninfo = w.ninfo;
12048 + w.drinfo = lkup->dirren.drinfo;
12049 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12050 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12051 + AuDebugOn(!w.h_ppath.dentry);
12052 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12053 + w.qname = &dentry->d_name;
12056 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12057 + br = au_sbr(sb, bindex);
12058 + err = au_drinfo_load(&w, bindex, br);
12059 + if (unlikely(err))
12061 + if (w.drinfo[bindex])
12065 + br = au_sbr(sb, btgt);
12066 + h_dir = d_inode(w.h_ppath.dentry);
12067 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12069 + au_dr_hino_del(&br->br_dirren, ent);
12070 + au_kfree_rcu(ent);
12072 + goto out; /* success */
12075 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12076 + lkup->dirren.ninfo = 0;
12077 + lkup->dirren.drinfo = NULL;
12083 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12085 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12088 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12091 + struct au_drinfo *drinfo;
12094 + if (!lkup->dirren.drinfo)
12096 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12097 + drinfo = lkup->dirren.drinfo[btgt];
12101 + au_kfree_try_rcu(lkup->whname.name);
12102 + lkup->whname.name = NULL;
12103 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12104 + lkup->dirren.dr_name.name = drinfo->oldname;
12105 + lkup->name = &lkup->dirren.dr_name;
12106 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12108 + AuDbg("name %.*s, whname %.*s, b%d\n",
12109 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12117 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12121 + struct au_drinfo *drinfo;
12124 + if (!lkup->dirren.drinfo)
12126 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12127 + drinfo = lkup->dirren.drinfo[bindex];
12131 + match = (drinfo->ino == h_ino);
12132 + AuDbg("match %d\n", match);
12138 +/* ---------------------------------------------------------------------- */
12140 +int au_dr_opt_set(struct super_block *sb)
12143 + aufs_bindex_t bindex, bbot;
12144 + struct au_branch *br;
12147 + bbot = au_sbbot(sb);
12148 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12149 + br = au_sbr(sb, bindex);
12150 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12156 +int au_dr_opt_flush(struct super_block *sb)
12159 + aufs_bindex_t bindex, bbot;
12160 + struct au_branch *br;
12163 + bbot = au_sbbot(sb);
12164 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12165 + br = au_sbr(sb, bindex);
12166 + if (au_br_writable(br->br_perm))
12167 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12173 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12176 + aufs_bindex_t bindex, bbot;
12177 + struct au_branch *br;
12181 + err = au_dr_opt_flush(sb);
12182 + if (unlikely(err))
12186 + bbot = au_sbbot(sb);
12187 + for (bindex = 0; bindex <= bbot; bindex++) {
12188 + br = au_sbr(sb, bindex);
12189 + au_dr_hino_free(&br->br_dirren);
12195 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12196 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12197 +++ linux/fs/aufs/dirren.h 2024-05-13 17:13:00.618070924 +0200
12199 +/* SPDX-License-Identifier: GPL-2.0 */
12201 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12203 + * This program is free software; you can redistribute it and/or modify
12204 + * it under the terms of the GNU General Public License as published by
12205 + * the Free Software Foundation; either version 2 of the License, or
12206 + * (at your option) any later version.
12208 + * This program is distributed in the hope that it will be useful,
12209 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12210 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12211 + * GNU General Public License for more details.
12213 + * You should have received a copy of the GNU General Public License
12214 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12218 + * renamed dir info
12221 +#ifndef __AUFS_DIRREN_H__
12222 +#define __AUFS_DIRREN_H__
12226 +#include <linux/dcache.h>
12227 +#include <linux/statfs.h>
12228 +#include <linux/uuid.h>
12231 +#define AuDirren_NHASH 100
12233 +#ifdef CONFIG_AUFS_DIRREN
12234 +enum au_brid_type {
12241 +struct au_dr_brid {
12242 + enum au_brid_type type;
12244 + uuid_t uuid; /* unimplemented yet */
12250 +/* 20 is the max digits length of ulong 64 */
12251 +/* brid-type "_" uuid "_" inum */
12252 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12253 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12255 +struct au_dr_hino {
12256 + struct hlist_bl_node dr_hnode;
12261 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12262 + struct au_dr_brid dr_brid;
12265 +struct au_dr_lookup {
12266 + /* dr_name is pointed by struct au_do_lookup_args.name */
12267 + struct qstr dr_name; /* subset of dr_info */
12268 + aufs_bindex_t ninfo;
12269 + struct au_drinfo **drinfo;
12272 +struct au_dr_hino;
12274 +struct au_dr_br { };
12275 +struct au_dr_lookup { };
12278 +/* ---------------------------------------------------------------------- */
12281 +struct au_do_lookup_args;
12283 +#ifdef CONFIG_AUFS_DIRREN
12284 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12285 + struct au_dr_hino *add_ent);
12286 +void au_dr_hino_free(struct au_dr_br *dr);
12287 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12288 + const struct path *path);
12289 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12290 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12291 + struct qstr *dst_name, void *_rev);
12292 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12293 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12294 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12295 + aufs_bindex_t bindex);
12296 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12297 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12299 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12300 +int au_dr_opt_set(struct super_block *sb);
12301 +int au_dr_opt_flush(struct super_block *sb);
12302 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12304 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12305 + struct au_dr_hino *add_ent);
12306 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12307 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12308 + const struct path *path);
12309 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12310 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12311 + struct qstr *dst_name, void *_rev);
12312 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12313 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12315 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12316 + aufs_bindex_t bindex);
12317 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12318 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12319 + aufs_bindex_t bindex, ino_t h_ino);
12320 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12321 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12322 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12323 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12326 +/* ---------------------------------------------------------------------- */
12328 +#ifdef CONFIG_AUFS_DIRREN
12329 +static inline int au_dr_ihash(ino_t h_ino)
12331 + return h_ino % AuDirren_NHASH;
12334 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12337 +#endif /* __KERNEL__ */
12338 +#endif /* __AUFS_DIRREN_H__ */
12339 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12340 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12341 +++ linux/fs/aufs/dynop.c 2024-05-13 17:13:00.618070924 +0200
12343 +// SPDX-License-Identifier: GPL-2.0
12345 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12347 + * This program is free software; you can redistribute it and/or modify
12348 + * it under the terms of the GNU General Public License as published by
12349 + * the Free Software Foundation; either version 2 of the License, or
12350 + * (at your option) any later version.
12352 + * This program is distributed in the hope that it will be useful,
12353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12355 + * GNU General Public License for more details.
12357 + * You should have received a copy of the GNU General Public License
12358 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12362 + * dynamically customizable operations for regular files
12367 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12370 + * How large will these lists be?
12371 + * Usually just a few elements, 20-30 at most for each, I guess.
12373 +static struct hlist_bl_head dynop[AuDyLast];
12375 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12376 + const void *h_op)
12378 + struct au_dykey *key, *tmp;
12379 + struct hlist_bl_node *pos;
12382 + hlist_bl_lock(hbl);
12383 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12384 + if (tmp->dk_op.dy_hop == h_op) {
12385 + if (kref_get_unless_zero(&tmp->dk_kref))
12389 + hlist_bl_unlock(hbl);
12394 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12396 + struct au_dykey **k, *found;
12397 + const void *h_op = key->dk_op.dy_hop;
12401 + k = br->br_dykey;
12402 + for (i = 0; i < AuBrDynOp; i++)
12404 + if (k[i]->dk_op.dy_hop == h_op) {
12411 + spin_lock(&br->br_dykey_lock);
12412 + for (; i < AuBrDynOp; i++)
12414 + if (k[i]->dk_op.dy_hop == h_op) {
12422 + spin_unlock(&br->br_dykey_lock);
12423 + BUG_ON(i == AuBrDynOp); /* expand the array */
12429 +/* kref_get() if @key is already added */
12430 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12432 + struct au_dykey *tmp, *found;
12433 + struct hlist_bl_node *pos;
12434 + const void *h_op = key->dk_op.dy_hop;
12437 + hlist_bl_lock(hbl);
12438 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12439 + if (tmp->dk_op.dy_hop == h_op) {
12440 + if (kref_get_unless_zero(&tmp->dk_kref))
12445 + hlist_bl_add_head(&key->dk_hnode, hbl);
12446 + hlist_bl_unlock(hbl);
12453 +static void dy_free_rcu(struct rcu_head *rcu)
12455 + struct au_dykey *key;
12457 + key = container_of(rcu, struct au_dykey, dk_rcu);
12462 +static void dy_free(struct kref *kref)
12464 + struct au_dykey *key;
12465 + struct hlist_bl_head *hbl;
12467 + key = container_of(kref, struct au_dykey, dk_kref);
12468 + hbl = dynop + key->dk_op.dy_type;
12469 + au_hbl_del(&key->dk_hnode, hbl);
12470 + call_rcu(&key->dk_rcu, dy_free_rcu);
12473 +void au_dy_put(struct au_dykey *key)
12475 + kref_put(&key->dk_kref, dy_free);
12478 +/* ---------------------------------------------------------------------- */
12480 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12482 +#ifdef CONFIG_AUFS_DEBUG
12483 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12484 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12486 +#define DyDbgDeclare(cnt) do {} while (0)
12487 +#define DyDbgInc(cnt) do {} while (0)
12490 +#define DySet(func, dst, src, h_op, h_sb) do { \
12492 + if (h_op->func) { \
12494 + dst.func = src.func; \
12496 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12500 +#define DySetForce(func, dst, src) do { \
12501 + AuDebugOn(!src.func); \
12503 + dst.func = src.func; \
12506 +#define DySetAop(func) \
12507 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12508 +#define DySetAopForce(func) \
12509 + DySetForce(func, dyaop->da_op, aufs_aop)
12511 +static void dy_aop(struct au_dykey *key, const void *h_op,
12512 + struct super_block *h_sb __maybe_unused)
12514 + struct au_dyaop *dyaop = (void *)key;
12515 + const struct address_space_operations *h_aop = h_op;
12516 + DyDbgDeclare(cnt);
12518 + AuDbg("%s\n", au_sbtype(h_sb));
12520 + DySetAop(writepage);
12521 + DySetAopForce(read_folio); /* force */
12522 + DySetAop(writepages);
12523 + DySetAop(dirty_folio);
12524 + DySetAop(invalidate_folio);
12525 + DySetAop(readahead);
12526 + DySetAop(write_begin);
12527 + DySetAop(write_end);
12529 + DySetAop(release_folio);
12530 + DySetAop(free_folio);
12531 + /* this one will be changed according to an aufs mount option */
12532 + DySetAop(direct_IO);
12533 + DySetAop(migrate_folio);
12534 + DySetAop(launder_folio);
12535 + DySetAop(is_partially_uptodate);
12536 + DySetAop(is_dirty_writeback);
12537 + DySetAop(error_remove_folio);
12538 + DySetAop(swap_activate);
12539 + DySetAop(swap_deactivate);
12540 + DySetAop(swap_rw);
12542 + DyDbgSize(cnt, *h_aop);
12545 +/* ---------------------------------------------------------------------- */
12547 +static void dy_bug(struct kref *kref)
12552 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12554 + struct au_dykey *key, *old;
12555 + struct hlist_bl_head *hbl;
12558 + void (*set)(struct au_dykey *key, const void *h_op,
12559 + struct super_block *h_sb __maybe_unused);
12561 + static const struct op a[] = {
12563 + .sz = sizeof(struct au_dyaop),
12567 + const struct op *p;
12569 + hbl = dynop + op->dy_type;
12570 + key = dy_gfind_get(hbl, op->dy_hop);
12572 + goto out_add; /* success */
12574 + p = a + op->dy_type;
12575 + key = kzalloc(p->sz, GFP_NOFS);
12576 + if (unlikely(!key)) {
12577 + key = ERR_PTR(-ENOMEM);
12581 + key->dk_op.dy_hop = op->dy_hop;
12582 + kref_init(&key->dk_kref);
12583 + p->set(key, op->dy_hop, au_br_sb(br));
12584 + old = dy_gadd(hbl, key);
12586 + au_kfree_rcu(key);
12591 + old = dy_bradd(br, key);
12593 + /* its ref-count should never be zero here */
12594 + kref_put(&key->dk_kref, dy_bug);
12599 +/* ---------------------------------------------------------------------- */
12601 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12602 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12603 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12604 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12605 + * See the aufs manual in detail.
12607 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12610 + dyaop->da_op.direct_IO = NULL;
12612 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12615 +static struct au_dyaop *dy_aget(struct au_branch *br,
12616 + const struct address_space_operations *h_aop,
12619 + struct au_dyaop *dyaop;
12620 + struct au_dynop op;
12622 + op.dy_type = AuDy_AOP;
12623 + op.dy_haop = h_aop;
12624 + dyaop = (void *)dy_get(&op, br);
12625 + if (IS_ERR(dyaop))
12627 + dy_adx(dyaop, do_dx);
12633 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12634 + struct inode *h_inode)
12637 + struct super_block *sb;
12638 + struct au_branch *br;
12639 + struct au_dyaop *dyaop;
12641 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12642 + IiMustWriteLock(inode);
12644 + sb = inode->i_sb;
12645 + br = au_sbr(sb, bindex);
12646 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12647 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12648 + err = PTR_ERR(dyaop);
12649 + if (IS_ERR(dyaop))
12650 + /* unnecessary to call dy_fput() */
12654 + inode->i_mapping->a_ops = &dyaop->da_op;
12661 + * Is it safe to replace a_ops during the inode/file is in operation?
12662 + * Yes, I hope so.
12664 +int au_dy_irefresh(struct inode *inode)
12667 + aufs_bindex_t btop;
12668 + struct inode *h_inode;
12671 + if (S_ISREG(inode->i_mode)) {
12672 + btop = au_ibtop(inode);
12673 + h_inode = au_h_iptr(inode, btop);
12674 + err = au_dy_iaop(inode, btop, h_inode);
12679 +void au_dy_arefresh(int do_dx)
12681 + struct hlist_bl_head *hbl;
12682 + struct hlist_bl_node *pos;
12683 + struct au_dykey *key;
12685 + hbl = dynop + AuDy_AOP;
12686 + hlist_bl_lock(hbl);
12687 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12688 + dy_adx((void *)key, do_dx);
12689 + hlist_bl_unlock(hbl);
12692 +/* ---------------------------------------------------------------------- */
12694 +void __init au_dy_init(void)
12698 + for (i = 0; i < AuDyLast; i++)
12699 + INIT_HLIST_BL_HEAD(dynop + i);
12702 +void au_dy_fin(void)
12706 + for (i = 0; i < AuDyLast; i++)
12707 + WARN_ON(!hlist_bl_empty(dynop + i));
12709 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12710 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12711 +++ linux/fs/aufs/dynop.h 2024-05-13 17:13:00.618070924 +0200
12713 +/* SPDX-License-Identifier: GPL-2.0 */
12715 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12717 + * This program is free software; you can redistribute it and/or modify
12718 + * it under the terms of the GNU General Public License as published by
12719 + * the Free Software Foundation; either version 2 of the License, or
12720 + * (at your option) any later version.
12722 + * This program is distributed in the hope that it will be useful,
12723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12725 + * GNU General Public License for more details.
12727 + * You should have received a copy of the GNU General Public License
12728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12732 + * dynamically customizable operations (for regular files only)
12735 +#ifndef __AUFS_DYNOP_H__
12736 +#define __AUFS_DYNOP_H__
12740 +#include <linux/fs.h>
12741 +#include <linux/kref.h>
12743 +enum {AuDy_AOP, AuDyLast};
12748 + const void *dy_hop;
12749 + const struct address_space_operations *dy_haop;
12755 + struct hlist_bl_node dk_hnode;
12756 + struct rcu_head dk_rcu;
12758 + struct au_dynop dk_op;
12761 + * during I am in the branch local array, kref is gotten. when the
12762 + * branch is removed, kref is put.
12764 + struct kref dk_kref;
12767 +/* stop unioning since their sizes are very different from each other */
12769 + struct au_dykey da_key;
12770 + struct address_space_operations da_op; /* not const */
12772 +/* make sure that 'struct au_dykey *' can be any type */
12773 +static_assert(!offsetof(struct au_dyaop, da_key));
12775 +/* ---------------------------------------------------------------------- */
12779 +void au_dy_put(struct au_dykey *key);
12780 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12781 + struct inode *h_inode);
12782 +int au_dy_irefresh(struct inode *inode);
12783 +void au_dy_arefresh(int do_dio);
12785 +void __init au_dy_init(void);
12786 +void au_dy_fin(void);
12788 +#endif /* __KERNEL__ */
12789 +#endif /* __AUFS_DYNOP_H__ */
12790 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12791 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12792 +++ linux/fs/aufs/export.c 2024-05-13 17:13:00.618070924 +0200
12794 +// SPDX-License-Identifier: GPL-2.0
12796 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12798 + * This program is free software; you can redistribute it and/or modify
12799 + * it under the terms of the GNU General Public License as published by
12800 + * the Free Software Foundation; either version 2 of the License, or
12801 + * (at your option) any later version.
12803 + * This program is distributed in the hope that it will be useful,
12804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12806 + * GNU General Public License for more details.
12808 + * You should have received a copy of the GNU General Public License
12809 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12816 +#include <linux/exportfs.h>
12817 +#include <linux/fs_struct.h>
12818 +#include <linux/nsproxy.h>
12819 +#include <linux/random.h>
12820 +#include <linux/writeback.h>
12824 +#ifdef CONFIG_AUFS_INO_T_64
12832 +static ino_t decode_ino(__u32 *a)
12836 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12838 +#ifdef CONFIG_AUFS_INO_T_64
12844 +static void encode_ino(__u32 *a, ino_t ino)
12850 +#ifdef CONFIG_AUFS_INO_T_64
12855 +/* NFS file handle */
12859 +#ifdef CONFIG_AUFS_INO_T_64
12860 + /* support 64bit inode number */
12873 + Fh_ino = Fh_ino1,
12874 + Fh_dir_ino = Fh_dir_ino1
12877 +static int au_test_anon(struct dentry *dentry)
12879 + /* note: read d_flags without d_lock */
12880 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12883 +int au_test_nfsd(void)
12886 + struct task_struct *tsk = current;
12887 + char comm[sizeof(tsk->comm)];
12890 + if (tsk->flags & PF_KTHREAD) {
12891 + get_task_comm(comm, tsk);
12892 + ret = !strcmp(comm, "nfsd");
12898 +/* ---------------------------------------------------------------------- */
12899 +/* inode generation external table */
12901 +void au_xigen_inc(struct inode *inode)
12906 + struct super_block *sb;
12907 + struct au_sbinfo *sbinfo;
12909 + sb = inode->i_sb;
12910 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12912 + sbinfo = au_sbi(sb);
12913 + pos = inode->i_ino;
12914 + pos *= sizeof(igen);
12915 + igen = inode->i_generation + 1;
12916 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12917 + if (sz == sizeof(igen))
12918 + return; /* success */
12920 + if (unlikely(sz >= 0))
12921 + AuIOErr("xigen error (%zd)\n", sz);
12924 +int au_xigen_new(struct inode *inode)
12929 + struct super_block *sb;
12930 + struct au_sbinfo *sbinfo;
12931 + struct file *file;
12934 + /* todo: dirty, at mount time */
12935 + if (inode->i_ino == AUFS_ROOT_INO)
12937 + sb = inode->i_sb;
12938 + SiMustAnyLock(sb);
12939 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12943 + pos = inode->i_ino;
12944 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12945 + AuIOErr1("too large i%lld\n", pos);
12948 + pos *= sizeof(inode->i_generation);
12951 + sbinfo = au_sbi(sb);
12952 + file = sbinfo->si_xigen;
12955 + if (vfsub_f_size_read(file)
12956 + < pos + sizeof(inode->i_generation)) {
12957 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12958 + sz = xino_fwrite(file, &inode->i_generation,
12959 + sizeof(inode->i_generation), &pos);
12961 + sz = xino_fread(file, &inode->i_generation,
12962 + sizeof(inode->i_generation), &pos);
12963 + if (sz == sizeof(inode->i_generation))
12964 + goto out; /* success */
12967 + if (unlikely(sz >= 0)) {
12969 + AuIOErr("xigen error (%zd)\n", sz);
12976 +int au_xigen_set(struct super_block *sb, struct path *path)
12979 + struct au_sbinfo *sbinfo;
12980 + struct file *file;
12982 + SiMustWriteLock(sb);
12984 + sbinfo = au_sbi(sb);
12985 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12986 + err = PTR_ERR(file);
12987 + if (IS_ERR(file))
12990 + if (sbinfo->si_xigen)
12991 + fput(sbinfo->si_xigen);
12992 + sbinfo->si_xigen = file;
12999 +void au_xigen_clr(struct super_block *sb)
13001 + struct au_sbinfo *sbinfo;
13003 + SiMustWriteLock(sb);
13005 + sbinfo = au_sbi(sb);
13006 + if (sbinfo->si_xigen) {
13007 + fput(sbinfo->si_xigen);
13008 + sbinfo->si_xigen = NULL;
13012 +/* ---------------------------------------------------------------------- */
13014 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13017 + struct dentry *dentry, *d;
13018 + struct inode *inode;
13019 + unsigned int sigen;
13022 + inode = ilookup(sb, ino);
13026 + dentry = ERR_PTR(-ESTALE);
13027 + sigen = au_sigen(sb);
13028 + if (unlikely(au_is_bad_inode(inode)
13029 + || IS_DEADDIR(inode)
13030 + || sigen != au_iigen(inode, NULL)))
13034 + if (!dir_ino || S_ISDIR(inode->i_mode))
13035 + dentry = d_find_alias(inode);
13037 + spin_lock(&inode->i_lock);
13038 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13039 + spin_lock(&d->d_lock);
13040 + if (!au_test_anon(d)
13041 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13042 + dentry = dget_dlock(d);
13043 + spin_unlock(&d->d_lock);
13046 + spin_unlock(&d->d_lock);
13048 + spin_unlock(&inode->i_lock);
13050 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13051 + /* need to refresh */
13059 + AuTraceErrPtr(dentry);
13063 +/* ---------------------------------------------------------------------- */
13065 +/* todo: dirty? */
13066 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13068 +struct au_compare_mnt_args {
13070 + struct super_block *sb;
13073 + struct vfsmount *mnt;
13076 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13078 + struct au_compare_mnt_args *a = arg;
13080 + if (mnt->mnt_sb != a->sb)
13082 + a->mnt = mntget(mnt);
13086 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13089 + struct path root;
13090 + struct vfsmount *mnt;
13091 + struct au_compare_mnt_args args = {
13095 + get_fs_root(current->fs, &root);
13097 + * as long as this sb is alive, this temporary unlock is safe.
13100 + si_read_unlock(sb);
13101 + mnt = collect_mounts(&root);
13102 + if (IS_ERR(mnt)) {
13108 + err = iterate_mounts(au_compare_mnt, &args, mnt);
13109 + rcu_read_unlock();
13110 + drop_collected_mounts(mnt);
13114 + si_noflush_read_lock(sb);
13115 + AuDebugOn(!args.mnt);
13120 +struct au_nfsd_si_lock {
13121 + unsigned int sigen;
13122 + aufs_bindex_t bindex, br_id;
13123 + unsigned char force_lock;
13126 +static int si_nfsd_read_lock(struct super_block *sb,
13127 + struct au_nfsd_si_lock *nsi_lock)
13130 + aufs_bindex_t bindex;
13132 + si_read_lock(sb, AuLock_FLUSH);
13134 + /* branch id may be wrapped around */
13136 + bindex = au_br_index(sb, nsi_lock->br_id);
13137 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13138 + goto out; /* success */
13142 + if (!nsi_lock->force_lock)
13143 + si_read_unlock(sb);
13146 + nsi_lock->bindex = bindex;
13150 +struct find_name_by_ino {
13151 + struct dir_context ctx;
13152 + int called, found;
13159 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13160 + loff_t offset, u64 ino, unsigned int d_type)
13162 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13166 + if (a->ino != ino)
13169 + memcpy(a->name, name, namelen);
13170 + a->namelen = namelen;
13175 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13176 + struct au_nfsd_si_lock *nsi_lock)
13178 + struct dentry *dentry, *parent;
13179 + struct file *file;
13180 + struct inode *dir;
13181 + struct find_name_by_ino arg = {
13183 + .actor = find_name_by_ino
13188 + parent = path->dentry;
13190 + si_read_unlock(parent->d_sb);
13191 + file = vfsub_dentry_open(path, au_dir_roflags);
13192 + dentry = (void *)file;
13193 + if (IS_ERR(file))
13196 + dentry = ERR_PTR(-ENOMEM);
13197 + arg.name = (void *)__get_free_page(GFP_NOFS);
13198 + if (unlikely(!arg.name))
13205 + err = vfsub_iterate_dir(file, &arg.ctx);
13206 + } while (!err && !arg.found && arg.called);
13207 + dentry = ERR_PTR(err);
13208 + if (unlikely(err))
13210 + /* instead of ENOENT */
13211 + dentry = ERR_PTR(-ESTALE);
13215 + /* do not call vfsub_lkup_one() */
13216 + dir = d_inode(parent);
13217 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13218 + AuTraceErrPtr(dentry);
13219 + if (IS_ERR(dentry))
13221 + AuDebugOn(au_test_anon(dentry));
13222 + if (unlikely(d_really_is_negative(dentry))) {
13224 + dentry = ERR_PTR(-ENOENT);
13228 + free_page((unsigned long)arg.name);
13232 + if (unlikely(nsi_lock
13233 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13234 + if (!IS_ERR(dentry)) {
13236 + dentry = ERR_PTR(-ESTALE);
13238 + AuTraceErrPtr(dentry);
13242 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13244 + struct au_nfsd_si_lock *nsi_lock)
13246 + struct dentry *dentry;
13247 + struct path path;
13249 + if (dir_ino != AUFS_ROOT_INO) {
13250 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13251 + dentry = path.dentry;
13252 + if (!path.dentry || IS_ERR(path.dentry))
13254 + AuDebugOn(au_test_anon(path.dentry));
13256 + path.dentry = dget(sb->s_root);
13258 + path.mnt = au_mnt_get(sb);
13259 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13263 + AuTraceErrPtr(dentry);
13267 +/* ---------------------------------------------------------------------- */
13269 +static int h_acceptable(void *expv, struct dentry *dentry)
13274 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13275 + char *buf, int len, struct super_block *sb)
13279 + struct path path;
13281 + p = d_path(h_rootpath, buf, len);
13286 + path.mnt = h_rootpath->mnt;
13287 + path.dentry = h_parent;
13288 + p = d_path(&path, buf, len);
13294 + path.mnt = au_mnt_get(sb);
13295 + path.dentry = sb->s_root;
13296 + p = d_path(&path, buf, len - strlen(p));
13297 + mntput(path.mnt);
13301 + p[strlen(p)] = '/';
13304 + AuTraceErrPtr(p);
13309 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13310 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13312 + struct dentry *dentry, *h_parent, *root;
13313 + struct super_block *h_sb;
13314 + char *pathname, *p;
13315 + struct vfsmount *h_mnt;
13316 + struct au_branch *br;
13318 + struct path path;
13320 + br = au_sbr(sb, nsi_lock->bindex);
13321 + h_mnt = au_br_mnt(br);
13322 + h_sb = h_mnt->mnt_sb;
13323 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13325 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13326 + fh_len - Fh_tail, fh[Fh_h_type],
13327 + h_acceptable, /*context*/NULL);
13329 + dentry = h_parent;
13330 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13331 + AuWarn1("%s decode_fh failed, %ld\n",
13332 + au_sbtype(h_sb), PTR_ERR(h_parent));
13336 + if (unlikely(au_test_anon(h_parent))) {
13337 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13338 + au_sbtype(h_sb));
13339 + goto out_h_parent;
13342 + dentry = ERR_PTR(-ENOMEM);
13343 + pathname = (void *)__get_free_page(GFP_NOFS);
13344 + if (unlikely(!pathname))
13345 + goto out_h_parent;
13347 + root = sb->s_root;
13348 + path.mnt = h_mnt;
13349 + di_read_lock_parent(root, !AuLock_IR);
13350 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13351 + di_read_unlock(root, !AuLock_IR);
13352 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13353 + dentry = (void *)p;
13355 + goto out_pathname;
13357 + si_read_unlock(sb);
13358 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13359 + dentry = ERR_PTR(err);
13360 + if (unlikely(err))
13363 + dentry = ERR_PTR(-ENOENT);
13364 + AuDebugOn(au_test_anon(path.dentry));
13365 + if (unlikely(d_really_is_negative(path.dentry)))
13368 + if (ino != d_inode(path.dentry)->i_ino)
13369 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13371 + dentry = dget(path.dentry);
13376 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13377 + if (!IS_ERR(dentry)) {
13379 + dentry = ERR_PTR(-ESTALE);
13382 + free_page((unsigned long)pathname);
13386 + AuTraceErrPtr(dentry);
13390 +/* ---------------------------------------------------------------------- */
13392 +static struct dentry *
13393 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13396 + struct dentry *dentry;
13397 + __u32 *fh = fid->raw;
13398 + struct au_branch *br;
13399 + ino_t ino, dir_ino;
13400 + struct au_nfsd_si_lock nsi_lock = {
13404 + dentry = ERR_PTR(-ESTALE);
13405 + /* it should never happen, but the file handle is unreliable */
13406 + if (unlikely(fh_len < Fh_tail))
13408 + nsi_lock.sigen = fh[Fh_sigen];
13409 + nsi_lock.br_id = fh[Fh_br_id];
13411 + /* branch id may be wrapped around */
13413 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13415 + nsi_lock.force_lock = 1;
13417 + /* is this inode still cached? */
13418 + ino = decode_ino(fh + Fh_ino);
13419 + /* it should never happen */
13420 + if (unlikely(ino == AUFS_ROOT_INO))
13423 + dir_ino = decode_ino(fh + Fh_dir_ino);
13424 + dentry = decode_by_ino(sb, ino, dir_ino);
13425 + if (IS_ERR(dentry))
13430 + /* is the parent dir cached? */
13431 + br = au_sbr(sb, nsi_lock.bindex);
13432 + au_lcnt_inc(&br->br_nfiles);
13433 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13434 + if (IS_ERR(dentry))
13439 + /* lookup path */
13440 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13441 + if (IS_ERR(dentry))
13443 + if (unlikely(!dentry))
13444 + /* todo?: make it ESTALE */
13448 + if (!au_digen_test(dentry, au_sigen(sb))
13449 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13450 + goto out_unlock; /* success */
13453 + dentry = ERR_PTR(-ESTALE);
13456 + au_lcnt_dec(&br->br_nfiles);
13457 + si_read_unlock(sb);
13459 + AuTraceErrPtr(dentry);
13463 +#if 0 /* reserved for future use */
13464 +/* support subtreecheck option */
13465 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13466 + int fh_len, int fh_type)
13468 + struct dentry *parent;
13469 + __u32 *fh = fid->raw;
13472 + dir_ino = decode_ino(fh + Fh_dir_ino);
13473 + parent = decode_by_ino(sb, dir_ino, 0);
13474 + if (IS_ERR(parent))
13477 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13478 + dir_ino, fh, fh_len);
13481 + AuTraceErrPtr(parent);
13486 +/* ---------------------------------------------------------------------- */
13488 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13489 + struct inode *dir)
13492 + aufs_bindex_t bindex;
13493 + struct super_block *sb, *h_sb;
13494 + struct dentry *dentry, *parent, *h_parent;
13495 + struct inode *h_dir;
13496 + struct au_branch *br;
13499 + if (unlikely(*max_len <= Fh_tail)) {
13500 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13504 + err = FILEID_ROOT;
13505 + if (inode->i_ino == AUFS_ROOT_INO) {
13506 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13511 + sb = inode->i_sb;
13512 + err = si_read_lock(sb, AuLock_FLUSH);
13513 + if (unlikely(err))
13516 +#ifdef CONFIG_AUFS_DEBUG
13517 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13518 + AuWarn1("NFS-exporting requires xino\n");
13522 + ii_read_lock_child(inode);
13523 + bindex = au_ibtop(inode);
13525 + dentry = d_find_any_alias(inode);
13526 + if (unlikely(!dentry))
13528 + AuDebugOn(au_test_anon(dentry));
13529 + parent = dget_parent(dentry);
13531 + if (unlikely(!parent))
13533 + if (d_really_is_positive(parent))
13534 + dir = d_inode(parent);
13537 + ii_read_lock_parent(dir);
13538 + h_dir = au_h_iptr(dir, bindex);
13539 + ii_read_unlock(dir);
13540 + if (unlikely(!h_dir))
13542 + h_parent = d_find_any_alias(h_dir);
13543 + if (unlikely(!h_parent))
13544 + goto out_hparent;
13547 + br = au_sbr(sb, bindex);
13548 + h_sb = au_br_sb(br);
13549 + if (unlikely(!h_sb->s_export_op)) {
13550 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13551 + goto out_hparent;
13554 + fh[Fh_br_id] = br->br_id;
13555 + fh[Fh_sigen] = au_sigen(sb);
13556 + encode_ino(fh + Fh_ino, inode->i_ino);
13557 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13558 + fh[Fh_igen] = inode->i_generation;
13560 + *max_len -= Fh_tail;
13561 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13563 + /*connectable or subtreecheck*/0);
13564 + err = fh[Fh_h_type];
13565 + *max_len += Fh_tail;
13566 + /* todo: macros? */
13567 + if (err != FILEID_INVALID)
13570 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13577 + ii_read_unlock(inode);
13578 + si_read_unlock(sb);
13580 + if (unlikely(err < 0))
13581 + err = FILEID_INVALID;
13585 +/* ---------------------------------------------------------------------- */
13587 +static int aufs_commit_metadata(struct inode *inode)
13590 + aufs_bindex_t bindex;
13591 + struct super_block *sb;
13592 + struct inode *h_inode;
13593 + int (*f)(struct inode *inode);
13595 + sb = inode->i_sb;
13596 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13597 + ii_write_lock_child(inode);
13598 + bindex = au_ibtop(inode);
13599 + AuDebugOn(bindex < 0);
13600 + h_inode = au_h_iptr(inode, bindex);
13602 + f = h_inode->i_sb->s_export_op->commit_metadata;
13604 + err = f(h_inode);
13606 + err = sync_inode_metadata(h_inode, /*wait*/1);
13608 + au_cpup_attr_timesizes(inode);
13609 + ii_write_unlock(inode);
13610 + si_read_unlock(sb);
13614 +/* ---------------------------------------------------------------------- */
13616 +static struct export_operations aufs_export_op = {
13617 + .fh_to_dentry = aufs_fh_to_dentry,
13618 + /* .fh_to_parent = aufs_fh_to_parent, */
13619 + .encode_fh = aufs_encode_fh,
13620 + .commit_metadata = aufs_commit_metadata
13623 +void au_export_init(struct super_block *sb)
13625 + struct au_sbinfo *sbinfo;
13628 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13629 + && IS_MODULE(CONFIG_EXPORTFS),
13630 + AUFS_NAME ": unsupported configuration "
13631 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13633 + sb->s_export_op = &aufs_export_op;
13634 + sbinfo = au_sbi(sb);
13635 + sbinfo->si_xigen = NULL;
13636 + get_random_bytes(&u, sizeof(u));
13637 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13638 + atomic_set(&sbinfo->si_xigen_next, u);
13640 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13641 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13642 +++ linux/fs/aufs/fhsm.c 2024-05-13 17:13:00.618070924 +0200
13644 +// SPDX-License-Identifier: GPL-2.0
13646 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13648 + * This program is free software; you can redistribute it and/or modify
13649 + * it under the terms of the GNU General Public License as published by
13650 + * the Free Software Foundation; either version 2 of the License, or
13651 + * (at your option) any later version.
13653 + * This program is distributed in the hope that it will be useful,
13654 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13656 + * GNU General Public License for more details.
13658 + * You should have received a copy of the GNU General Public License
13659 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13663 + * File-based Hierarchy Storage Management
13666 +#include <linux/anon_inodes.h>
13667 +#include <linux/poll.h>
13668 +#include <linux/seq_file.h>
13669 +#include <linux/statfs.h>
13672 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13674 + struct au_sbinfo *sbinfo;
13675 + struct au_fhsm *fhsm;
13677 + SiMustAnyLock(sb);
13679 + sbinfo = au_sbi(sb);
13680 + fhsm = &sbinfo->si_fhsm;
13681 + AuDebugOn(!fhsm);
13682 + return fhsm->fhsm_bottom;
13685 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13687 + struct au_sbinfo *sbinfo;
13688 + struct au_fhsm *fhsm;
13690 + SiMustWriteLock(sb);
13692 + sbinfo = au_sbi(sb);
13693 + fhsm = &sbinfo->si_fhsm;
13694 + AuDebugOn(!fhsm);
13695 + fhsm->fhsm_bottom = bindex;
13698 +/* ---------------------------------------------------------------------- */
13700 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13702 + struct au_br_fhsm *bf;
13704 + bf = br->br_fhsm;
13705 + MtxMustLock(&bf->bf_lock);
13707 + return !bf->bf_readable
13708 + || time_after(jiffies,
13709 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13712 +/* ---------------------------------------------------------------------- */
13714 +static void au_fhsm_notify(struct super_block *sb, int val)
13716 + struct au_sbinfo *sbinfo;
13717 + struct au_fhsm *fhsm;
13719 + SiMustAnyLock(sb);
13721 + sbinfo = au_sbi(sb);
13722 + fhsm = &sbinfo->si_fhsm;
13723 + if (au_fhsm_pid(fhsm)
13724 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13725 + atomic_set(&fhsm->fhsm_readable, val);
13727 + wake_up(&fhsm->fhsm_wqh);
13731 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13732 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13735 + struct au_branch *br;
13736 + struct au_br_fhsm *bf;
13738 + br = au_sbr(sb, bindex);
13739 + AuDebugOn(au_br_rdonly(br));
13740 + bf = br->br_fhsm;
13744 + mutex_lock(&bf->bf_lock);
13746 + MtxMustLock(&bf->bf_lock);
13748 + /* sb->s_root for NFS is unreliable */
13749 + err = au_br_stfs(br, &bf->bf_stfs);
13750 + if (unlikely(err)) {
13751 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13755 + bf->bf_jiffy = jiffies;
13756 + bf->bf_readable = 1;
13758 + au_fhsm_notify(sb, /*val*/1);
13760 + *rstfs = bf->bf_stfs;
13764 + mutex_unlock(&bf->bf_lock);
13765 + au_fhsm_notify(sb, /*val*/1);
13770 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13773 + struct au_sbinfo *sbinfo;
13774 + struct au_fhsm *fhsm;
13775 + struct au_branch *br;
13776 + struct au_br_fhsm *bf;
13778 + AuDbg("b%d, force %d\n", bindex, force);
13779 + SiMustAnyLock(sb);
13781 + sbinfo = au_sbi(sb);
13782 + fhsm = &sbinfo->si_fhsm;
13783 + if (!au_ftest_si(sbinfo, FHSM)
13784 + || fhsm->fhsm_bottom == bindex)
13787 + br = au_sbr(sb, bindex);
13788 + bf = br->br_fhsm;
13790 + mutex_lock(&bf->bf_lock);
13792 + || au_fhsm_pid(fhsm)
13793 + || au_fhsm_test_jiffy(sbinfo, br))
13794 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13796 + mutex_unlock(&bf->bf_lock);
13799 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13801 + aufs_bindex_t bindex, bbot;
13802 + struct au_branch *br;
13804 + /* exclude the bottom */
13805 + bbot = au_fhsm_bottom(sb);
13806 + for (bindex = 0; bindex < bbot; bindex++) {
13807 + br = au_sbr(sb, bindex);
13808 + if (au_br_fhsm(br->br_perm))
13809 + au_fhsm_wrote(sb, bindex, force);
13813 +/* ---------------------------------------------------------------------- */
13815 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13818 + struct au_sbinfo *sbinfo;
13819 + struct au_fhsm *fhsm;
13822 + sbinfo = file->private_data;
13823 + fhsm = &sbinfo->si_fhsm;
13824 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13825 + if (atomic_read(&fhsm->fhsm_readable))
13826 + mask = EPOLLIN /* | EPOLLRDNORM */;
13829 + AuDbg("mask 0x%x\n", mask);
13833 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13834 + struct aufs_stfs *stfs, __s16 brid)
13838 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13840 + err = __put_user(brid, &stbr->brid);
13841 + if (unlikely(err))
13847 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13848 + struct aufs_stbr __user *stbr, size_t count)
13852 + aufs_bindex_t bindex, bbot;
13853 + struct au_branch *br;
13854 + struct au_br_fhsm *bf;
13856 + /* except the bottom branch */
13859 + bbot = au_fhsm_bottom(sb);
13860 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13861 + br = au_sbr(sb, bindex);
13862 + if (!au_br_fhsm(br->br_perm))
13865 + bf = br->br_fhsm;
13866 + mutex_lock(&bf->bf_lock);
13867 + if (bf->bf_readable) {
13869 + if (count >= sizeof(*stbr))
13870 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13873 + bf->bf_readable = 0;
13874 + count -= sizeof(*stbr);
13878 + mutex_unlock(&bf->bf_lock);
13881 + err = sizeof(*stbr) * nstbr;
13886 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13891 + aufs_bindex_t nfhsm, bindex, bbot;
13892 + struct au_sbinfo *sbinfo;
13893 + struct au_fhsm *fhsm;
13894 + struct au_branch *br;
13895 + struct super_block *sb;
13898 + sbinfo = file->private_data;
13899 + fhsm = &sbinfo->si_fhsm;
13901 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13902 + if (!atomic_read(&fhsm->fhsm_readable)) {
13903 + if (vfsub_file_flags(file) & O_NONBLOCK)
13906 + err = wait_event_interruptible_locked_irq
13908 + atomic_read(&fhsm->fhsm_readable));
13910 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13911 + if (unlikely(err))
13914 + /* sb may already be dead */
13915 + au_rw_read_lock(&sbinfo->si_rwsem);
13916 + readable = atomic_read(&fhsm->fhsm_readable);
13917 + if (readable > 0) {
13918 + sb = sbinfo->si_sb;
13920 + /* exclude the bottom branch */
13922 + bbot = au_fhsm_bottom(sb);
13923 + for (bindex = 0; bindex < bbot; bindex++) {
13924 + br = au_sbr(sb, bindex);
13925 + if (au_br_fhsm(br->br_perm))
13929 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13930 + atomic_set(&fhsm->fhsm_readable, 0);
13931 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13935 + au_rw_read_unlock(&sbinfo->si_rwsem);
13943 +static int au_fhsm_release(struct inode *inode, struct file *file)
13945 + struct au_sbinfo *sbinfo;
13946 + struct au_fhsm *fhsm;
13948 + /* sb may already be dead */
13949 + sbinfo = file->private_data;
13950 + fhsm = &sbinfo->si_fhsm;
13951 + spin_lock(&fhsm->fhsm_spin);
13952 + fhsm->fhsm_pid = 0;
13953 + spin_unlock(&fhsm->fhsm_spin);
13954 + kobject_put(&sbinfo->si_kobj);
13959 +static const struct file_operations au_fhsm_fops = {
13960 + .owner = THIS_MODULE,
13961 + .llseek = noop_llseek,
13962 + .read = au_fhsm_read,
13963 + .poll = au_fhsm_poll,
13964 + .release = au_fhsm_release
13967 +int au_fhsm_fd(struct super_block *sb, int oflags)
13970 + struct au_sbinfo *sbinfo;
13971 + struct au_fhsm *fhsm;
13974 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13978 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13982 + sbinfo = au_sbi(sb);
13983 + fhsm = &sbinfo->si_fhsm;
13984 + spin_lock(&fhsm->fhsm_spin);
13985 + if (!fhsm->fhsm_pid)
13986 + fhsm->fhsm_pid = current->pid;
13989 + spin_unlock(&fhsm->fhsm_spin);
13990 + if (unlikely(err))
13993 + oflags |= O_RDONLY;
13994 + /* oflags |= FMODE_NONOTIFY; */
13995 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13997 + if (unlikely(fd < 0))
14000 + /* succeed regardless 'fhsm' status */
14001 + kobject_get(&sbinfo->si_kobj);
14002 + si_noflush_read_lock(sb);
14003 + if (au_ftest_si(sbinfo, FHSM))
14004 + au_fhsm_wrote_all(sb, /*force*/0);
14005 + si_read_unlock(sb);
14006 + goto out; /* success */
14009 + spin_lock(&fhsm->fhsm_spin);
14010 + fhsm->fhsm_pid = 0;
14011 + spin_unlock(&fhsm->fhsm_spin);
14017 +/* ---------------------------------------------------------------------- */
14019 +int au_fhsm_br_alloc(struct au_branch *br)
14024 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14026 + au_br_fhsm_init(br->br_fhsm);
14033 +/* ---------------------------------------------------------------------- */
14035 +void au_fhsm_fin(struct super_block *sb)
14037 + au_fhsm_notify(sb, /*val*/-1);
14040 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14042 + struct au_fhsm *fhsm;
14044 + fhsm = &sbinfo->si_fhsm;
14045 + spin_lock_init(&fhsm->fhsm_spin);
14046 + init_waitqueue_head(&fhsm->fhsm_wqh);
14047 + atomic_set(&fhsm->fhsm_readable, 0);
14048 + fhsm->fhsm_expire
14049 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14050 + fhsm->fhsm_bottom = -1;
14053 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14055 + sbinfo->si_fhsm.fhsm_expire
14056 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14059 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14063 + if (!au_ftest_si(sbinfo, FHSM))
14066 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14067 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14068 + seq_printf(seq, ",fhsm_sec=%u", u);
14070 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14071 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14072 +++ linux/fs/aufs/file.c 2024-05-13 17:13:00.618070924 +0200
14074 +// SPDX-License-Identifier: GPL-2.0
14076 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14078 + * This program is free software; you can redistribute it and/or modify
14079 + * it under the terms of the GNU General Public License as published by
14080 + * the Free Software Foundation; either version 2 of the License, or
14081 + * (at your option) any later version.
14083 + * This program is distributed in the hope that it will be useful,
14084 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14085 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14086 + * GNU General Public License for more details.
14088 + * You should have received a copy of the GNU General Public License
14089 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14093 + * handling file/dir, and address_space operation
14096 +#ifdef CONFIG_AUFS_DEBUG
14097 +#include <linux/migrate.h>
14099 +#include <linux/pagemap.h>
14102 +/* drop flags for writing */
14103 +unsigned int au_file_roflags(unsigned int flags)
14105 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14106 + flags |= O_RDONLY | O_NOATIME;
14110 +/* common functions to regular file and dir */
14111 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14112 + struct file *file, int force_wr)
14114 + struct file *h_file;
14115 + struct dentry *h_dentry;
14116 + struct inode *h_inode;
14117 + struct super_block *sb;
14118 + struct au_branch *br;
14119 + struct path h_path;
14122 + /* a race condition can happen between open and unlink/rmdir */
14123 + h_file = ERR_PTR(-ENOENT);
14124 + h_dentry = au_h_dptr(dentry, bindex);
14125 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14127 + h_inode = d_inode(h_dentry);
14128 + spin_lock(&h_dentry->d_lock);
14129 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14130 + /* || !d_inode(dentry)->i_nlink */
14132 + spin_unlock(&h_dentry->d_lock);
14133 + if (unlikely(err))
14136 + sb = dentry->d_sb;
14137 + br = au_sbr(sb, bindex);
14138 + err = au_br_test_oflag(flags, br);
14139 + h_file = ERR_PTR(err);
14140 + if (unlikely(err))
14143 + /* drop flags for writing */
14144 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14145 + if (force_wr && !(flags & O_WRONLY))
14147 + flags = au_file_roflags(flags);
14149 + h_file = ERR_PTR(-EROFS);
14150 + flags = au_file_roflags(flags);
14151 + if (unlikely(vfsub_native_ro(h_inode)
14152 + || IS_APPEND(h_inode)))
14154 + flags &= ~O_ACCMODE;
14155 + flags |= O_WRONLY;
14158 + flags &= ~O_CREAT;
14159 + au_lcnt_inc(&br->br_nfiles);
14160 + h_path.dentry = h_dentry;
14161 + h_path.mnt = au_br_mnt(br);
14163 + * vfs::backing_file_open() looks promising since it can get rid of
14164 + * mm::vm_prfile approach from my mind.
14165 + * but I keep current approach for a while.
14167 + h_file = vfsub_dentry_open(&h_path, flags);
14168 + if (IS_ERR(h_file))
14171 + if (flags & __FMODE_EXEC) {
14172 + err = deny_write_access(h_file);
14173 + if (unlikely(err)) {
14175 + h_file = ERR_PTR(err);
14179 + fsnotify_open(h_file);
14180 + goto out; /* success */
14183 + au_lcnt_dec(&br->br_nfiles);
14188 +static int au_cmoo(struct dentry *dentry)
14190 + int err, cmoo, matched;
14191 + unsigned int udba;
14192 + struct path h_path;
14193 + struct au_pin pin;
14194 + struct au_cp_generic cpg = {
14195 + .dentry = dentry,
14200 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14202 + struct inode *delegated;
14203 + struct super_block *sb;
14204 + struct au_sbinfo *sbinfo;
14205 + struct au_fhsm *fhsm;
14207 + struct au_branch *br;
14208 + struct dentry *parent;
14209 + struct au_hinode *hdir;
14211 + DiMustWriteLock(dentry);
14212 + IiMustWriteLock(d_inode(dentry));
14215 + if (IS_ROOT(dentry))
14217 + cpg.bsrc = au_dbtop(dentry);
14221 + sb = dentry->d_sb;
14222 + sbinfo = au_sbi(sb);
14223 + fhsm = &sbinfo->si_fhsm;
14224 + pid = au_fhsm_pid(fhsm);
14227 + && (current->pid == pid
14228 + || rcu_dereference(current->real_parent)->pid == pid));
14229 + rcu_read_unlock();
14233 + br = au_sbr(sb, cpg.bsrc);
14234 + cmoo = au_br_cmoo(br->br_perm);
14237 + if (!d_is_reg(dentry))
14238 + cmoo &= AuBrAttr_COO_ALL;
14242 + parent = dget_parent(dentry);
14243 + di_write_lock_parent(parent);
14244 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14246 + if (unlikely(err < 0)) {
14247 + err = 0; /* there is no upper writable branch */
14250 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14252 + /* do not respect the coo attrib for the target branch */
14253 + err = au_cpup_dirs(dentry, cpg.bdst);
14254 + if (unlikely(err))
14257 + di_downgrade_lock(parent, AuLock_IR);
14258 + udba = au_opt_udba(sb);
14259 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14260 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14261 + if (unlikely(err))
14264 + err = au_sio_cpup_simple(&cpg);
14266 + if (unlikely(err))
14268 + if (!(cmoo & AuBrWAttr_MOO))
14269 + goto out_parent; /* success */
14271 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14272 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14273 + if (unlikely(err))
14276 + h_path.mnt = au_br_mnt(br);
14277 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14278 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14279 + delegated = NULL;
14280 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14282 + /* todo: keep h_dentry or not? */
14283 + if (unlikely(err == -EWOULDBLOCK)) {
14284 + pr_warn("cannot retry for NFSv4 delegation"
14285 + " for an internal unlink\n");
14288 + if (unlikely(err)) {
14289 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14293 + goto out_parent; /* success */
14296 + di_downgrade_lock(parent, AuLock_IR);
14298 + di_read_unlock(parent, AuLock_IR);
14305 +int au_do_open(struct file *file, struct au_do_open_args *args)
14307 + int err, aopen = args->aopen;
14308 + struct dentry *dentry;
14309 + struct au_finfo *finfo;
14312 + err = au_finfo_init(file, args->fidir);
14315 + err = au_finfo_init(file, args->fidir);
14318 + if (unlikely(err))
14321 + dentry = file->f_path.dentry;
14322 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14323 + di_write_lock_child(dentry);
14324 + err = au_cmoo(dentry);
14327 + err = args->open(file, vfsub_file_flags(file),
14328 + au_di(dentry)->di_htmpfile);
14329 + di_write_unlock(dentry);
14331 + di_downgrade_lock(dentry, AuLock_IR);
14333 + err = args->open(file, vfsub_file_flags(file),
14336 + di_read_unlock(dentry, AuLock_IR);
14340 + finfo = au_fi(file);
14342 + finfo->fi_file = file;
14343 + au_hbl_add(&finfo->fi_hlist,
14344 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14347 + fi_write_unlock(file);
14350 + fi_write_unlock(file);
14353 + if (unlikely(err)) {
14354 + finfo->fi_hdir = NULL;
14355 + au_finfo_fin(file);
14363 +int au_reopen_nondir(struct file *file)
14366 + aufs_bindex_t btop;
14367 + struct dentry *dentry;
14368 + struct au_branch *br;
14369 + struct file *h_file, *h_file_tmp;
14371 + dentry = file->f_path.dentry;
14372 + btop = au_dbtop(dentry);
14373 + br = au_sbr(dentry->d_sb, btop);
14374 + h_file_tmp = NULL;
14375 + if (au_fbtop(file) == btop) {
14376 + h_file = au_hf_top(file);
14377 + if (file->f_mode == h_file->f_mode)
14378 + return 0; /* success */
14379 + h_file_tmp = h_file;
14380 + get_file(h_file_tmp);
14381 + au_lcnt_inc(&br->br_nfiles);
14382 + au_set_h_fptr(file, btop, NULL);
14384 + AuDebugOn(au_fi(file)->fi_hdir);
14387 + * file exists on both of rw and ro
14388 + * open --> dbtop and fbtop are both 0
14389 + * prepend a branch as rw, "rw" become ro
14391 + * delete the top branch, "rw" becomes rw again
14392 + * --> dbtop is 1, fbtop is still 0
14393 + * write --> fbtop is 0 but dbtop is 1
14395 + /* AuDebugOn(au_fbtop(file) < btop); */
14397 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14398 + file, /*force_wr*/0);
14399 + err = PTR_ERR(h_file);
14400 + if (IS_ERR(h_file)) {
14401 + if (h_file_tmp) {
14403 + au_set_h_fptr(file, btop, h_file_tmp);
14404 + h_file_tmp = NULL;
14406 + goto out; /* todo: close all? */
14410 + au_set_fbtop(file, btop);
14411 + au_set_h_fptr(file, btop, h_file);
14412 + au_update_figen(file);
14413 + /* todo: necessary? */
14414 + /* file->f_ra = h_file->f_ra; */
14417 + if (h_file_tmp) {
14418 + fput(h_file_tmp);
14419 + au_lcnt_dec(&br->br_nfiles);
14424 +/* ---------------------------------------------------------------------- */
14426 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14427 + struct dentry *hi_wh)
14430 + aufs_bindex_t btop;
14431 + struct au_dinfo *dinfo;
14432 + struct dentry *h_dentry;
14433 + struct au_hdentry *hdp;
14435 + dinfo = au_di(file->f_path.dentry);
14436 + AuRwMustWriteLock(&dinfo->di_rwsem);
14438 + btop = dinfo->di_btop;
14439 + dinfo->di_btop = btgt;
14440 + hdp = au_hdentry(dinfo, btgt);
14441 + h_dentry = hdp->hd_dentry;
14442 + hdp->hd_dentry = hi_wh;
14443 + err = au_reopen_nondir(file);
14444 + hdp->hd_dentry = h_dentry;
14445 + dinfo->di_btop = btop;
14450 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14451 + aufs_bindex_t bcpup, struct au_pin *pin)
14454 + struct inode *inode, *h_inode;
14455 + struct dentry *h_dentry, *hi_wh;
14456 + struct au_cp_generic cpg = {
14457 + .dentry = file->f_path.dentry,
14464 + au_update_dbtop(cpg.dentry);
14465 + inode = d_inode(cpg.dentry);
14467 + if (au_dbtop(cpg.dentry) <= bcpup
14468 + && au_dbbot(cpg.dentry) >= bcpup) {
14469 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14470 + if (h_dentry && d_is_positive(h_dentry))
14471 + h_inode = d_inode(h_dentry);
14473 + hi_wh = au_hi_wh(inode, bcpup);
14474 + if (!hi_wh && !h_inode)
14475 + err = au_sio_cpup_wh(&cpg, file);
14477 + /* already copied-up after unlink */
14478 + err = au_reopen_wh(file, bcpup, hi_wh);
14481 + && (inode->i_nlink > 1
14482 + || (inode->i_state & I_LINKABLE))
14483 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14484 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14490 + * prepare the @file for writing.
14492 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14495 + aufs_bindex_t dbtop;
14496 + struct dentry *parent;
14497 + struct inode *inode;
14498 + struct super_block *sb;
14499 + struct file *h_file;
14500 + struct au_cp_generic cpg = {
14501 + .dentry = file->f_path.dentry,
14506 + .flags = AuCpup_DTIME
14509 + sb = cpg.dentry->d_sb;
14510 + inode = d_inode(cpg.dentry);
14511 + cpg.bsrc = au_fbtop(file);
14512 + err = au_test_ro(sb, cpg.bsrc, inode);
14513 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14514 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14519 + /* need to cpup or reopen */
14520 + parent = dget_parent(cpg.dentry);
14521 + di_write_lock_parent(parent);
14522 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14524 + if (unlikely(err < 0))
14528 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14529 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14530 + if (unlikely(err))
14534 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14535 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14536 + if (unlikely(err))
14539 + dbtop = au_dbtop(cpg.dentry);
14540 + if (dbtop <= cpg.bdst)
14541 + cpg.bsrc = cpg.bdst;
14543 + if (dbtop <= cpg.bdst /* just reopen */
14544 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14546 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14547 + if (IS_ERR(h_file))
14548 + err = PTR_ERR(h_file);
14550 + di_downgrade_lock(parent, AuLock_IR);
14551 + if (dbtop > cpg.bdst)
14552 + err = au_sio_cpup_simple(&cpg);
14554 + err = au_reopen_nondir(file);
14555 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14557 + } else { /* copyup as wh and reopen */
14559 + * since writable hfsplus branch is not supported,
14560 + * h_open_pre/post() are unnecessary.
14562 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14563 + di_downgrade_lock(parent, AuLock_IR);
14567 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14568 + goto out_dput; /* success */
14574 + di_downgrade_lock(parent, AuLock_IR);
14576 + di_read_unlock(parent, AuLock_IR);
14583 +/* ---------------------------------------------------------------------- */
14585 +int au_do_flush(struct file *file, fl_owner_t id,
14586 + int (*flush)(struct file *file, fl_owner_t id))
14589 + struct super_block *sb;
14590 + struct inode *inode;
14592 + inode = file_inode(file);
14593 + sb = inode->i_sb;
14594 + si_noflush_read_lock(sb);
14595 + fi_read_lock(file);
14596 + ii_read_lock_child(inode);
14598 + err = flush(file, id);
14599 + au_cpup_attr_timesizes(inode);
14601 + ii_read_unlock(inode);
14602 + fi_read_unlock(file);
14603 + si_read_unlock(sb);
14607 +/* ---------------------------------------------------------------------- */
14609 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14612 + struct au_pin pin;
14613 + struct au_finfo *finfo;
14614 + struct dentry *parent, *hi_wh;
14615 + struct inode *inode;
14616 + struct super_block *sb;
14617 + struct au_cp_generic cpg = {
14618 + .dentry = file->f_path.dentry,
14623 + .flags = AuCpup_DTIME
14626 + FiMustWriteLock(file);
14629 + finfo = au_fi(file);
14630 + sb = cpg.dentry->d_sb;
14631 + inode = d_inode(cpg.dentry);
14632 + cpg.bdst = au_ibtop(inode);
14633 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14636 + parent = dget_parent(cpg.dentry);
14637 + if (au_test_ro(sb, cpg.bdst, inode)) {
14638 + di_read_lock_parent(parent, !AuLock_IR);
14639 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14641 + di_read_unlock(parent, !AuLock_IR);
14642 + if (unlikely(err < 0))
14647 + di_read_lock_parent(parent, AuLock_IR);
14648 + hi_wh = au_hi_wh(inode, cpg.bdst);
14649 + if (!S_ISDIR(inode->i_mode)
14650 + && au_opt_test(au_mntflags(sb), PLINK)
14651 + && au_plink_test(inode)
14652 + && !d_unhashed(cpg.dentry)
14653 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14654 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14655 + if (unlikely(err))
14658 + /* always superio. */
14659 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14660 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14662 + err = au_sio_cpup_simple(&cpg);
14665 + } else if (hi_wh) {
14666 + /* already copied-up after unlink */
14667 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14668 + *need_reopen = 0;
14672 + di_read_unlock(parent, AuLock_IR);
14679 +static void au_do_refresh_dir(struct file *file)
14681 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14682 + struct au_hfile *p, tmp, *q;
14683 + struct au_finfo *finfo;
14684 + struct super_block *sb;
14685 + struct au_fidir *fidir;
14687 + FiMustWriteLock(file);
14689 + sb = file->f_path.dentry->d_sb;
14690 + finfo = au_fi(file);
14691 + fidir = finfo->fi_hdir;
14692 + AuDebugOn(!fidir);
14693 + p = fidir->fd_hfile + finfo->fi_btop;
14694 + brid = p->hf_br->br_id;
14695 + bbot = fidir->fd_bbot;
14696 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14700 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14701 + if (new_bindex == bindex)
14703 + if (new_bindex < 0) {
14704 + au_set_h_fptr(file, bindex, NULL);
14708 + /* swap two lower inode, and loop again */
14709 + q = fidir->fd_hfile + new_bindex;
14713 + if (tmp.hf_file) {
14719 + p = fidir->fd_hfile;
14720 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14721 + bbot = au_sbbot(sb);
14722 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14723 + finfo->fi_btop++, p++)
14724 + if (p->hf_file) {
14725 + if (file_inode(p->hf_file))
14727 + au_hfput(p, /*execed*/0);
14730 + bbot = au_br_index(sb, brid);
14731 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14732 + finfo->fi_btop++, p++)
14734 + au_hfput(p, /*execed*/0);
14735 + bbot = au_sbbot(sb);
14738 + p = fidir->fd_hfile + bbot;
14739 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14740 + fidir->fd_bbot--, p--)
14741 + if (p->hf_file) {
14742 + if (file_inode(p->hf_file))
14744 + au_hfput(p, /*execed*/0);
14746 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14750 + * after branch manipulating, refresh the file.
14752 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14754 + int err, need_reopen, nbr;
14755 + aufs_bindex_t bbot, bindex;
14756 + struct dentry *dentry;
14757 + struct super_block *sb;
14758 + struct au_finfo *finfo;
14759 + struct au_hfile *hfile;
14761 + dentry = file->f_path.dentry;
14762 + sb = dentry->d_sb;
14763 + nbr = au_sbbot(sb) + 1;
14764 + finfo = au_fi(file);
14765 + if (!finfo->fi_hdir) {
14766 + hfile = &finfo->fi_htop;
14767 + AuDebugOn(!hfile->hf_file);
14768 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14769 + AuDebugOn(bindex < 0);
14770 + if (bindex != finfo->fi_btop)
14771 + au_set_fbtop(file, bindex);
14773 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14774 + if (unlikely(err))
14776 + au_do_refresh_dir(file);
14781 + if (!au_test_mmapped(file))
14782 + err = au_file_refresh_by_inode(file, &need_reopen);
14783 + if (finfo->fi_hdir)
14784 + /* harmless if err */
14785 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14786 + if (!err && need_reopen && !d_unlinked(dentry))
14787 + err = reopen(file);
14789 + au_update_figen(file);
14790 + goto out; /* success */
14793 + /* error, close all lower files */
14794 + if (finfo->fi_hdir) {
14795 + bbot = au_fbbot_dir(file);
14796 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14797 + au_set_h_fptr(file, bindex, NULL);
14804 +/* common function to regular file and dir */
14805 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14806 + int wlock, unsigned int fi_lsc)
14809 + unsigned int sigen, figen;
14810 + aufs_bindex_t btop;
14811 + unsigned char pseudo_link;
14812 + struct dentry *dentry;
14813 + struct inode *inode;
14816 + dentry = file->f_path.dentry;
14817 + inode = d_inode(dentry);
14818 + sigen = au_sigen(dentry->d_sb);
14819 + fi_write_lock_nested(file, fi_lsc);
14820 + figen = au_figen(file);
14822 + di_write_lock_child(dentry);
14824 + di_write_lock_child2(dentry);
14825 + btop = au_dbtop(dentry);
14826 + pseudo_link = (btop != au_ibtop(inode));
14827 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14829 + di_downgrade_lock(dentry, AuLock_IR);
14830 + fi_downgrade_lock(file);
14832 + goto out; /* success */
14835 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14836 + if (au_digen_test(dentry, sigen)) {
14837 + err = au_reval_dpath(dentry, sigen);
14838 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14842 + err = refresh_file(file, reopen);
14845 + di_downgrade_lock(dentry, AuLock_IR);
14846 + fi_downgrade_lock(file);
14849 + di_write_unlock(dentry);
14850 + fi_write_unlock(file);
14857 +/* ---------------------------------------------------------------------- */
14859 +/* cf. aufs_nopage() */
14860 +/* for madvise(2) */
14861 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14863 + folio_unlock(folio);
14867 +/* it will never be called, but necessary to support O_DIRECT */
14868 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14869 +{ BUG(); return 0; }
14871 +/* they will never be called. */
14872 +#ifdef CONFIG_AUFS_DEBUG
14873 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14874 + loff_t pos, unsigned len,
14875 + struct page **pagep, void **fsdata)
14876 +{ AuUnsupport(); return 0; }
14877 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14878 + loff_t pos, unsigned len, unsigned copied,
14879 + struct page *page, void *fsdata)
14880 +{ AuUnsupport(); return 0; }
14881 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14882 +{ AuUnsupport(); return 0; }
14884 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14885 +{ AuUnsupport(); return true; }
14886 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14887 +{ AuUnsupport(); }
14888 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14889 +{ AuUnsupport(); return true; }
14890 +#if 0 /* called by memory compaction regardless file */
14891 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14892 + struct folio *src, enum migrate_mode mode)
14893 +{ AuUnsupport(); return 0; }
14895 +static int aufs_launder_folio(struct folio *folio)
14896 +{ AuUnsupport(); return 0; }
14897 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14899 +{ AuUnsupport(); return true; }
14900 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14902 +{ AuUnsupport(); }
14903 +static int aufs_error_remove_folio(struct address_space *mapping,
14904 + struct folio *folio)
14905 +{ AuUnsupport(); return 0; }
14906 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14908 +{ AuUnsupport(); return 0; }
14909 +static void aufs_swap_deactivate(struct file *file)
14910 +{ AuUnsupport(); }
14911 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14912 +{ AuUnsupport(); return 0; }
14913 +#endif /* CONFIG_AUFS_DEBUG */
14915 +const struct address_space_operations aufs_aop = {
14916 + .read_folio = aufs_read_folio,
14917 + .direct_IO = aufs_direct_IO,
14918 +#ifdef CONFIG_AUFS_DEBUG
14919 + .writepage = aufs_writepage,
14920 + /* no writepages, because of writepage */
14921 + .dirty_folio = aufs_dirty_folio,
14922 + /* no readpages, because of readpage */
14923 + .write_begin = aufs_write_begin,
14924 + .write_end = aufs_write_end,
14925 + /* no bmap, no block device */
14926 + .invalidate_folio = aufs_invalidate_folio,
14927 + .release_folio = aufs_release_folio,
14928 + /* is fallback_migrate_page ok? */
14929 + /* .migrate_folio = aufs_migrate_folio, */
14930 + .launder_folio = aufs_launder_folio,
14931 + .is_partially_uptodate = aufs_is_partially_uptodate,
14932 + .is_dirty_writeback = aufs_is_dirty_writeback,
14933 + .error_remove_folio = aufs_error_remove_folio,
14934 + .swap_activate = aufs_swap_activate,
14935 + .swap_deactivate = aufs_swap_deactivate,
14936 + .swap_rw = aufs_swap_rw
14937 +#endif /* CONFIG_AUFS_DEBUG */
14939 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14940 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14941 +++ linux/fs/aufs/file.h 2024-05-13 17:13:00.618070924 +0200
14943 +/* SPDX-License-Identifier: GPL-2.0 */
14945 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14947 + * This program is free software; you can redistribute it and/or modify
14948 + * it under the terms of the GNU General Public License as published by
14949 + * the Free Software Foundation; either version 2 of the License, or
14950 + * (at your option) any later version.
14952 + * This program is distributed in the hope that it will be useful,
14953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14955 + * GNU General Public License for more details.
14957 + * You should have received a copy of the GNU General Public License
14958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14962 + * file operations
14965 +#ifndef __AUFS_FILE_H__
14966 +#define __AUFS_FILE_H__
14970 +#include <linux/file.h>
14971 +#include <linux/fs.h>
14972 +#include <linux/mm_types.h>
14973 +#include <linux/poll.h>
14974 +#include "rwsem.h"
14978 + struct file *hf_file;
14979 + struct au_branch *hf_br;
14984 + aufs_bindex_t fd_bbot;
14985 + aufs_bindex_t fd_nent;
14986 + struct au_vdir *fd_vdir_cache;
14987 + struct au_hfile fd_hfile[];
14990 +static inline int au_fidir_sz(int nent)
14992 + AuDebugOn(nent < 0);
14993 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14997 + atomic_t fi_generation;
14999 + struct au_rwsem fi_rwsem;
15000 + aufs_bindex_t fi_btop;
15002 + /* do not union them */
15003 + struct { /* for non-dir */
15004 + struct au_hfile fi_htop;
15005 + atomic_t fi_mmapped;
15007 + struct au_fidir *fi_hdir; /* for dir only */
15009 + struct hlist_bl_node fi_hlist;
15010 + struct file *fi_file; /* very ugly */
15011 + struct rcu_head rcu;
15012 +} ____cacheline_aligned_in_smp;
15014 +/* ---------------------------------------------------------------------- */
15017 +extern const struct address_space_operations aufs_aop;
15018 +unsigned int au_file_roflags(unsigned int flags);
15019 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15020 + struct file *file, int force_wr);
15021 +struct au_do_open_args {
15023 + int (*open)(struct file *file, int flags,
15024 + struct file *h_file);
15025 + struct au_fidir *fidir;
15026 + struct file *h_file;
15028 +int au_do_open(struct file *file, struct au_do_open_args *args);
15029 +int au_reopen_nondir(struct file *file);
15031 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15032 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15033 + int wlock, unsigned int fi_lsc);
15034 +int au_do_flush(struct file *file, fl_owner_t id,
15035 + int (*flush)(struct file *file, fl_owner_t id));
15038 +#ifdef CONFIG_AUFS_POLL
15039 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15042 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15044 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15046 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15047 + struct file *h_file);
15049 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15050 + aufs_bindex_t bindex, int force_wr)
15051 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15052 + struct file *h_file);
15056 +extern const struct file_operations aufs_file_fop;
15057 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15058 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15059 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15062 +void au_hfput(struct au_hfile *hf, int execed);
15063 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15064 + struct file *h_file);
15066 +void au_update_figen(struct file *file);
15067 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15068 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15070 +void au_fi_init_once(void *_fi);
15071 +void au_finfo_fin(struct file *file);
15072 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15075 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15076 +#ifdef CONFIG_COMPAT
15077 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15078 + unsigned long arg);
15079 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15080 + unsigned long arg);
15083 +/* ---------------------------------------------------------------------- */
15085 +static inline struct au_finfo *au_fi(struct file *file)
15087 + return file->private_data;
15090 +/* ---------------------------------------------------------------------- */
15092 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15093 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15094 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15095 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15097 +#define fi_read_trylock_nested(f) \
15098 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15099 +#define fi_write_trylock_nested(f) \
15100 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15103 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15104 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15105 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15107 +/* lock subclass for finfo */
15113 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15115 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15118 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15120 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15124 + * fi_read_lock_1, fi_write_lock_1,
15125 + * fi_read_lock_2, fi_write_lock_2
15127 +#define AuReadLockFunc(name) \
15128 +static inline void fi_read_lock_##name(struct file *f) \
15129 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15131 +#define AuWriteLockFunc(name) \
15132 +static inline void fi_write_lock_##name(struct file *f) \
15133 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15135 +#define AuRWLockFuncs(name) \
15136 + AuReadLockFunc(name) \
15137 + AuWriteLockFunc(name)
15142 +#undef AuReadLockFunc
15143 +#undef AuWriteLockFunc
15144 +#undef AuRWLockFuncs
15146 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15147 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15148 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15150 +/* ---------------------------------------------------------------------- */
15152 +/* todo: hard/soft set? */
15153 +static inline aufs_bindex_t au_fbtop(struct file *file)
15155 + FiMustAnyLock(file);
15156 + return au_fi(file)->fi_btop;
15159 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15161 + FiMustAnyLock(file);
15162 + AuDebugOn(!au_fi(file)->fi_hdir);
15163 + return au_fi(file)->fi_hdir->fd_bbot;
15166 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15168 + FiMustAnyLock(file);
15169 + AuDebugOn(!au_fi(file)->fi_hdir);
15170 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15173 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15175 + FiMustWriteLock(file);
15176 + au_fi(file)->fi_btop = bindex;
15179 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15181 + FiMustWriteLock(file);
15182 + AuDebugOn(!au_fi(file)->fi_hdir);
15183 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15186 +static inline void au_set_fvdir_cache(struct file *file,
15187 + struct au_vdir *vdir_cache)
15189 + FiMustWriteLock(file);
15190 + AuDebugOn(!au_fi(file)->fi_hdir);
15191 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15194 +static inline struct file *au_hf_top(struct file *file)
15196 + FiMustAnyLock(file);
15197 + AuDebugOn(au_fi(file)->fi_hdir);
15198 + return au_fi(file)->fi_htop.hf_file;
15201 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15203 + FiMustAnyLock(file);
15204 + AuDebugOn(!au_fi(file)->fi_hdir);
15205 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15208 +/* todo: memory barrier? */
15209 +static inline unsigned int au_figen(struct file *f)
15211 + return atomic_read(&au_fi(f)->fi_generation);
15214 +static inline void au_set_mmapped(struct file *f)
15216 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15218 + pr_warn("fi_mmapped wrapped around\n");
15219 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15223 +static inline void au_unset_mmapped(struct file *f)
15225 + atomic_dec(&au_fi(f)->fi_mmapped);
15228 +static inline int au_test_mmapped(struct file *f)
15230 + return atomic_read(&au_fi(f)->fi_mmapped);
15233 +/* customize vma->vm_file */
15235 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15236 + struct file *file)
15240 + f = vma->vm_file;
15242 + vma->vm_file = file;
15247 +#define AuDbgVmRegion(file, vma) do {} while (0)
15249 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15250 + struct file *file)
15252 + au_do_vm_file_reset(vma, file);
15255 +#define AuDbgVmRegion(file, vma) \
15256 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15258 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15259 + struct file *file)
15263 + au_do_vm_file_reset(vma, file);
15264 + f = vma->vm_region->vm_file;
15266 + vma->vm_region->vm_file = file;
15269 +#endif /* CONFIG_MMU */
15271 +/* handle vma->vm_prfile */
15272 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15273 + struct file *file)
15276 + vma->vm_prfile = file;
15277 +#ifndef CONFIG_MMU
15279 + vma->vm_region->vm_prfile = file;
15283 +#endif /* __KERNEL__ */
15284 +#endif /* __AUFS_FILE_H__ */
15285 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15286 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15287 +++ linux/fs/aufs/finfo.c 2024-05-13 17:13:00.618070924 +0200
15289 +// SPDX-License-Identifier: GPL-2.0
15291 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15293 + * This program is free software; you can redistribute it and/or modify
15294 + * it under the terms of the GNU General Public License as published by
15295 + * the Free Software Foundation; either version 2 of the License, or
15296 + * (at your option) any later version.
15298 + * This program is distributed in the hope that it will be useful,
15299 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15300 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15301 + * GNU General Public License for more details.
15303 + * You should have received a copy of the GNU General Public License
15304 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15308 + * file private data
15313 +void au_hfput(struct au_hfile *hf, int execed)
15316 + allow_write_access(hf->hf_file);
15317 + fput(hf->hf_file);
15318 + hf->hf_file = NULL;
15319 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15320 + hf->hf_br = NULL;
15323 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15325 + struct au_finfo *finfo = au_fi(file);
15326 + struct au_hfile *hf;
15327 + struct au_fidir *fidir;
15329 + fidir = finfo->fi_hdir;
15331 + AuDebugOn(finfo->fi_btop != bindex);
15332 + hf = &finfo->fi_htop;
15334 + hf = fidir->fd_hfile + bindex;
15336 + if (hf && hf->hf_file)
15337 + au_hfput(hf, vfsub_file_execed(file));
15339 + FiMustWriteLock(file);
15340 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15341 + hf->hf_file = val;
15342 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15346 +void au_update_figen(struct file *file)
15348 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15349 + /* smp_mb(); */ /* atomic_set */
15352 +/* ---------------------------------------------------------------------- */
15354 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15356 + struct au_fidir *fidir;
15359 + nbr = au_sbbot(sb) + 1;
15361 + nbr = 2; /* initial allocate for 2 branches */
15362 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15364 + fidir->fd_bbot = -1;
15365 + fidir->fd_nent = nbr;
15371 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15374 + struct au_fidir *fidir, *p;
15376 + AuRwMustWriteLock(&finfo->fi_rwsem);
15377 + fidir = finfo->fi_hdir;
15378 + AuDebugOn(!fidir);
15381 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15382 + GFP_NOFS, may_shrink);
15384 + p->fd_nent = nbr;
15385 + finfo->fi_hdir = p;
15392 +/* ---------------------------------------------------------------------- */
15394 +void au_finfo_fin(struct file *file)
15396 + struct au_finfo *finfo;
15398 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15400 + finfo = au_fi(file);
15401 + AuDebugOn(finfo->fi_hdir);
15402 + AuRwDestroy(&finfo->fi_rwsem);
15403 + au_cache_free_finfo(finfo);
15406 +void au_fi_init_once(void *_finfo)
15408 + struct au_finfo *finfo = _finfo;
15410 + au_rw_init(&finfo->fi_rwsem);
15413 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15416 + struct au_finfo *finfo;
15417 + struct dentry *dentry;
15420 + dentry = file->f_path.dentry;
15421 + finfo = au_cache_alloc_finfo();
15422 + if (unlikely(!finfo))
15426 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15427 + au_rw_write_lock(&finfo->fi_rwsem);
15428 + finfo->fi_btop = -1;
15429 + finfo->fi_hdir = fidir;
15430 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15431 + /* smp_mb(); */ /* atomic_set */
15433 + file->private_data = finfo;
15438 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15439 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15440 +++ linux/fs/aufs/f_op.c 2024-05-13 17:13:00.618070924 +0200
15442 +// SPDX-License-Identifier: GPL-2.0
15444 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15446 + * This program is free software; you can redistribute it and/or modify
15447 + * it under the terms of the GNU General Public License as published by
15448 + * the Free Software Foundation; either version 2 of the License, or
15449 + * (at your option) any later version.
15451 + * This program is distributed in the hope that it will be useful,
15452 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15453 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15454 + * GNU General Public License for more details.
15456 + * You should have received a copy of the GNU General Public License
15457 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15461 + * file and vm operations
15464 +#include <linux/aio.h>
15465 +#include <linux/fs_stack.h>
15466 +#include <linux/mman.h>
15467 +#include <linux/security.h>
15470 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15473 + aufs_bindex_t bindex;
15474 + struct dentry *dentry, *h_dentry;
15475 + struct au_finfo *finfo;
15476 + struct inode *h_inode;
15478 + FiMustWriteLock(file);
15481 + dentry = file->f_path.dentry;
15482 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15483 + finfo = au_fi(file);
15484 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15485 + atomic_set(&finfo->fi_mmapped, 0);
15486 + bindex = au_dbtop(dentry);
15488 + h_dentry = au_h_dptr(dentry, bindex);
15489 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15490 + if (unlikely(err))
15492 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15493 + if (IS_ERR(h_file)) {
15494 + err = PTR_ERR(h_file);
15498 + h_dentry = h_file->f_path.dentry;
15499 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15500 + if (unlikely(err))
15502 + /* br ref is already inc-ed */
15505 + if (flags & __O_TMPFILE) {
15506 + AuDebugOn(!h_file);
15507 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15508 + au_di(dentry)->di_htmpfile = NULL;
15510 + if (!(flags & O_EXCL)) {
15511 + h_inode = file_inode(h_file);
15512 + spin_lock(&h_inode->i_lock);
15513 + h_inode->i_state |= I_LINKABLE;
15514 + spin_unlock(&h_inode->i_lock);
15517 + au_set_fbtop(file, bindex);
15518 + au_set_h_fptr(file, bindex, h_file);
15519 + au_update_figen(file);
15520 + /* todo: necessary? */
15521 + /* file->f_ra = h_file->f_ra; */
15527 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15528 + struct file *file)
15531 + struct super_block *sb;
15532 + struct au_do_open_args args = {
15533 + .open = au_do_open_nondir
15536 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15537 + file, vfsub_file_flags(file), file->f_mode);
15539 + sb = file->f_path.dentry->d_sb;
15540 + si_read_lock(sb, AuLock_FLUSH);
15541 + err = au_do_open(file, &args);
15542 + si_read_unlock(sb);
15546 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15548 + struct au_finfo *finfo;
15549 + aufs_bindex_t bindex;
15551 + finfo = au_fi(file);
15552 + au_hbl_del(&finfo->fi_hlist,
15553 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15554 + bindex = finfo->fi_btop;
15556 + au_set_h_fptr(file, bindex, NULL);
15558 + au_finfo_fin(file);
15562 +/* ---------------------------------------------------------------------- */
15564 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15567 + struct file *h_file;
15570 + h_file = au_hf_top(file);
15572 + err = vfsub_flush(h_file, id);
15576 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15578 + return au_do_flush(file, id, au_do_flush_nondir);
15581 +/* ---------------------------------------------------------------------- */
15583 + * read and write functions acquire [fdi]_rwsem once, but release before
15584 + * mmap_sem. This is because to stop a race condition between mmap(2).
15585 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15586 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15587 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15590 +/* Callers should call au_read_post() or fput() in the end */
15591 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15593 + struct file *h_file;
15596 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15598 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15599 + h_file = au_hf_top(file);
15600 + get_file(h_file);
15602 + fi_read_unlock(file);
15604 + h_file = ERR_PTR(err);
15609 +static void au_read_post(struct inode *inode, struct file *h_file)
15611 + /* update without lock, I don't think it a problem */
15612 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15616 +struct au_write_pre {
15618 + unsigned int lsc;
15622 + aufs_bindex_t btop;
15626 + * return with iinfo is write-locked
15627 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15630 +static struct file *au_write_pre(struct file *file, int do_ready,
15631 + struct au_write_pre *wpre)
15633 + struct file *h_file;
15634 + struct dentry *dentry;
15636 + unsigned int lsc;
15637 + struct au_pin pin;
15642 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15643 + h_file = ERR_PTR(err);
15644 + if (unlikely(err))
15647 + dentry = file->f_path.dentry;
15649 + err = au_ready_to_write(file, -1, &pin);
15650 + if (unlikely(err)) {
15651 + h_file = ERR_PTR(err);
15652 + di_write_unlock(dentry);
15657 + di_downgrade_lock(dentry, /*flags*/0);
15659 + wpre->btop = au_fbtop(file);
15660 + h_file = au_hf_top(file);
15661 + get_file(h_file);
15663 + wpre->blks = file_inode(h_file)->i_blocks;
15666 + di_read_unlock(dentry, /*flags*/0);
15667 + vfsub_file_start_write(h_file);
15670 + fi_write_unlock(file);
15675 +static void au_write_post(struct inode *inode, struct file *h_file,
15676 + struct au_write_pre *wpre, ssize_t written)
15678 + struct inode *h_inode;
15680 + vfsub_file_end_write(h_file);
15681 + au_cpup_attr_timesizes(inode);
15682 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15683 + h_inode = file_inode(h_file);
15684 + inode->i_mode = h_inode->i_mode;
15685 + ii_write_unlock(inode);
15686 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15688 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15689 + /*force*/h_inode->i_blocks > wpre->blks);
15694 + * todo: very ugly
15695 + * it locks both of i_mutex and si_rwsem for read in safe.
15696 + * if the plink maintenance mode continues forever (that is the problem),
15697 + * may loop forever.
15699 +static void au_mtx_and_read_lock(struct inode *inode)
15702 + struct super_block *sb = inode->i_sb;
15705 + inode_lock(inode);
15706 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15709 + inode_unlock(inode);
15710 + si_read_lock(sb, AuLock_NOPLMW);
15711 + si_read_unlock(sb);
15715 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15716 + struct iov_iter *iov_iter)
15719 + struct file *file;
15720 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15722 + err = security_file_permission(h_file, rw);
15723 + if (unlikely(err))
15726 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15728 + if (rw == MAY_READ)
15729 + iter = h_file->f_op->read_iter;
15730 + else if (rw == MAY_WRITE)
15731 + iter = h_file->f_op->write_iter;
15733 + file = kio->ki_filp;
15734 + kio->ki_filp = h_file;
15737 + err = iter(kio, iov_iter);
15740 + /* currently there is no such fs */
15742 + kio->ki_filp = file;
15748 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15751 + struct file *file, *h_file;
15752 + struct inode *inode;
15753 + struct super_block *sb;
15755 + file = kio->ki_filp;
15756 + inode = file_inode(file);
15757 + sb = inode->i_sb;
15758 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15760 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15761 + err = PTR_ERR(h_file);
15762 + if (IS_ERR(h_file))
15765 + if (au_test_loopback_kthread()) {
15766 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15767 + if (file->f_mapping != h_file->f_mapping) {
15768 + file->f_mapping = h_file->f_mapping;
15769 + smp_mb(); /* unnecessary? */
15772 + fi_read_unlock(file);
15774 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15775 + /* todo: necessary? */
15776 + /* file->f_ra = h_file->f_ra; */
15777 + au_read_post(inode, h_file);
15780 + si_read_unlock(sb);
15784 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15787 + struct au_write_pre wpre;
15788 + struct inode *inode;
15789 + struct file *file, *h_file;
15791 + file = kio->ki_filp;
15792 + inode = file_inode(file);
15793 + au_mtx_and_read_lock(inode);
15796 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15797 + err = PTR_ERR(h_file);
15798 + if (IS_ERR(h_file))
15801 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15802 + au_write_post(inode, h_file, &wpre, err);
15805 + si_read_unlock(inode->i_sb);
15806 + inode_unlock(inode);
15811 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15812 + * don't have their own .splice_{read,write} implimentations, and they use
15813 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15814 + * simple converters to f_op->iter_read() and ->iter_write().
15815 + * But we keep our own implementations because some non-mainlined FSes may have
15816 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15817 + * away an opportunity to co-work with aufs from them.
15819 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15820 + struct pipe_inode_info *pipe, size_t len,
15821 + unsigned int flags)
15824 + struct file *h_file;
15825 + struct inode *inode;
15826 + struct super_block *sb;
15828 + inode = file_inode(file);
15829 + sb = inode->i_sb;
15830 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15832 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15833 + err = PTR_ERR(h_file);
15834 + if (IS_ERR(h_file))
15837 + err = vfsub_splice_read(h_file, ppos, pipe, len, flags);
15838 + /* todo: necessary? */
15839 + /* file->f_ra = h_file->f_ra; */
15840 + au_read_post(inode, h_file);
15843 + si_read_unlock(sb);
15848 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15849 + size_t len, unsigned int flags)
15852 + struct au_write_pre wpre;
15853 + struct inode *inode;
15854 + struct file *h_file;
15856 + inode = file_inode(file);
15857 + au_mtx_and_read_lock(inode);
15860 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15861 + err = PTR_ERR(h_file);
15862 + if (IS_ERR(h_file))
15865 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15866 + au_write_post(inode, h_file, &wpre, err);
15869 + si_read_unlock(inode->i_sb);
15870 + inode_unlock(inode);
15874 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15878 + struct au_write_pre wpre;
15879 + struct inode *inode;
15880 + struct file *h_file;
15882 + inode = file_inode(file);
15883 + au_mtx_and_read_lock(inode);
15886 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15887 + err = PTR_ERR(h_file);
15888 + if (IS_ERR(h_file))
15892 + err = vfs_fallocate(h_file, mode, offset, len);
15895 + * we don't need to call file_modifed() here since au_write_post()
15896 + * is equivalent and copies-up all timestamps and permission bits.
15898 + au_write_post(inode, h_file, &wpre, /*written*/1);
15901 + si_read_unlock(inode->i_sb);
15902 + inode_unlock(inode);
15906 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15907 + struct file *dst, loff_t dst_pos,
15908 + size_t len, unsigned int flags)
15911 + struct au_write_pre wpre;
15912 + enum { SRC, DST };
15914 + struct inode *inode;
15915 + struct file *h_file;
15916 + struct super_block *h_sb;
15918 +#define a_src a[SRC]
15919 +#define a_dst a[DST]
15922 + a_src.inode = file_inode(src);
15923 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15925 + a_dst.inode = file_inode(dst);
15926 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15929 + au_mtx_and_read_lock(a_dst.inode);
15931 + * in order to match the order in di_write_lock2_{child,parent}(),
15932 + * use f_path.dentry for this comparison.
15934 + if (src->f_path.dentry < dst->f_path.dentry) {
15935 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15936 + err = PTR_ERR(a_src.h_file);
15937 + if (IS_ERR(a_src.h_file))
15940 + wpre.lsc = AuLsc_FI_2;
15941 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15942 + err = PTR_ERR(a_dst.h_file);
15943 + if (IS_ERR(a_dst.h_file)) {
15944 + au_read_post(a_src.inode, a_src.h_file);
15948 + wpre.lsc = AuLsc_FI_1;
15949 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15950 + err = PTR_ERR(a_dst.h_file);
15951 + if (IS_ERR(a_dst.h_file))
15954 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15955 + err = PTR_ERR(a_src.h_file);
15956 + if (IS_ERR(a_src.h_file)) {
15957 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15964 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15965 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15966 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15972 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15973 + dst_pos, len, flags);
15976 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15977 + fi_read_unlock(src);
15978 + au_read_post(a_src.inode, a_src.h_file);
15980 + si_read_unlock(a_dst.inode->i_sb);
15981 + inode_unlock(a_dst.inode);
15988 +/* ---------------------------------------------------------------------- */
15991 + * The locking order around current->mmap_sem.
15992 + * - in most and regular cases
15993 + * file I/O syscall -- aufs_read() or something
15994 + * -- si_rwsem for read -- mmap_sem
15995 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15997 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15998 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15999 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
16000 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
16001 + * It means that when aufs acquires si_rwsem for write, the process should never
16002 + * acquire mmap_sem.
16004 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
16005 + * problem either since any directory is not able to be mmap-ed.
16006 + * The similar scenario is applied to aufs_readlink() too.
16009 +#if 0 /* stop calling security_file_mmap() */
16010 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
16011 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
16013 +static unsigned long au_arch_prot_conv(unsigned long flags)
16015 + /* currently ppc64 only */
16016 +#ifdef CONFIG_PPC64
16017 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16018 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16019 + return AuConv_VM_PROT(flags, SAO);
16021 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16026 +static unsigned long au_prot_conv(unsigned long flags)
16028 + return AuConv_VM_PROT(flags, READ)
16029 + | AuConv_VM_PROT(flags, WRITE)
16030 + | AuConv_VM_PROT(flags, EXEC)
16031 + | au_arch_prot_conv(flags);
16034 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16035 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16037 +static unsigned long au_flag_conv(unsigned long flags)
16039 + return AuConv_VM_MAP(flags, GROWSDOWN)
16040 + | AuConv_VM_MAP(flags, DENYWRITE)
16041 + | AuConv_VM_MAP(flags, LOCKED);
16045 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16048 + const unsigned char wlock
16049 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16050 + struct super_block *sb;
16051 + struct file *h_file;
16052 + struct inode *inode;
16054 + AuDbgVmRegion(file, vma);
16056 + inode = file_inode(file);
16057 + sb = inode->i_sb;
16059 + si_read_lock(sb, AuLock_NOPLMW);
16061 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16063 + err = PTR_ERR(h_file);
16064 + if (IS_ERR(h_file))
16068 + au_set_mmapped(file);
16069 + au_vm_file_reset(vma, h_file);
16071 + * we cannot call security_mmap_file() here since it may acquire
16072 + * mmap_sem or i_mutex.
16074 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16075 + * au_flag_conv(vma->vm_flags));
16078 + err = call_mmap(h_file, vma);
16080 + au_vm_prfile_set(vma, file);
16081 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16082 + goto out_fput; /* success */
16084 + au_unset_mmapped(file);
16085 + au_vm_file_reset(vma, file);
16089 + ii_write_unlock(inode);
16094 + si_read_unlock(sb);
16100 +/* ---------------------------------------------------------------------- */
16102 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16106 + struct au_write_pre wpre;
16107 + struct inode *inode;
16108 + struct file *h_file;
16110 + err = 0; /* -EBADF; */ /* posix? */
16111 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16114 + inode = file_inode(file);
16115 + au_mtx_and_read_lock(inode);
16118 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16119 + err = PTR_ERR(h_file);
16120 + if (IS_ERR(h_file))
16123 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16124 + au_write_post(inode, h_file, &wpre, /*written*/0);
16127 + si_read_unlock(inode->i_sb);
16128 + inode_unlock(inode);
16133 +static int aufs_fasync(int fd, struct file *file, int flag)
16136 + struct file *h_file;
16137 + struct super_block *sb;
16139 + sb = file->f_path.dentry->d_sb;
16140 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16142 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16143 + err = PTR_ERR(h_file);
16144 + if (IS_ERR(h_file))
16147 + if (h_file->f_op->fasync)
16148 + err = h_file->f_op->fasync(fd, h_file, flag);
16149 + fput(h_file); /* instead of au_read_post() */
16152 + si_read_unlock(sb);
16156 +static int aufs_setfl(struct file *file, unsigned long arg)
16159 + struct file *h_file;
16160 + struct super_block *sb;
16162 + sb = file->f_path.dentry->d_sb;
16163 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16165 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16166 + err = PTR_ERR(h_file);
16167 + if (IS_ERR(h_file))
16170 + /* stop calling h_file->fasync */
16171 + arg |= vfsub_file_flags(file) & FASYNC;
16172 + err = setfl(/*unused fd*/-1, h_file, arg);
16173 + fput(h_file); /* instead of au_read_post() */
16176 + si_read_unlock(sb);
16180 +/* ---------------------------------------------------------------------- */
16182 +const struct file_operations aufs_file_fop = {
16183 + .owner = THIS_MODULE,
16185 + .llseek = default_llseek,
16187 + .read_iter = aufs_read_iter,
16188 + .write_iter = aufs_write_iter,
16190 +#ifdef CONFIG_AUFS_POLL
16191 + .poll = aufs_poll,
16193 + .unlocked_ioctl = aufs_ioctl_nondir,
16194 +#ifdef CONFIG_COMPAT
16195 + .compat_ioctl = aufs_compat_ioctl_nondir,
16197 + .mmap = aufs_mmap,
16198 + .open = aufs_open_nondir,
16199 + .flush = aufs_flush_nondir,
16200 + .release = aufs_release_nondir,
16201 + .fsync = aufs_fsync_nondir,
16202 + .fasync = aufs_fasync,
16203 + .setfl = aufs_setfl,
16204 + .splice_write = aufs_splice_write,
16205 + .splice_read = aufs_splice_read,
16206 +#if 0 /* reserved for future use */
16207 + .aio_splice_write = aufs_aio_splice_write,
16208 + .aio_splice_read = aufs_aio_splice_read,
16210 + .fallocate = aufs_fallocate,
16211 + .copy_file_range = aufs_copy_file_range
16213 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16214 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16215 +++ linux/fs/aufs/fsctx.c 2024-05-13 17:13:00.618070924 +0200
16217 +// SPDX-License-Identifier: GPL-2.0
16219 + * Copyright (C) 2022 Junjiro R. Okajima
16221 + * This program is free software; you can redistribute it and/or modify
16222 + * it under the terms of the GNU General Public License as published by
16223 + * the Free Software Foundation; either version 2 of the License, or
16224 + * (at your option) any later version.
16226 + * This program is distributed in the hope that it will be useful,
16227 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16228 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16229 + * GNU General Public License for more details.
16231 + * You should have received a copy of the GNU General Public License
16232 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16236 + * fs context, aka new mount api
16239 +#include <linux/fs_context.h>
16242 +struct au_fsctx_opts {
16243 + aufs_bindex_t bindex;
16244 + unsigned char skipped;
16245 + struct au_opt *opt, *opt_tail;
16246 + struct super_block *sb;
16247 + struct au_sbinfo *sbinfo;
16248 + struct au_opts opts;
16251 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16252 +static int cvt_err(int err)
16266 +static int au_fsctx_reconfigure(struct fs_context *fc)
16269 + unsigned int mntflags;
16270 + struct dentry *root;
16271 + struct super_block *sb;
16272 + struct inode *inode;
16273 + struct au_fsctx_opts *a = fc->fs_private;
16275 + AuDbg("fc %p\n", fc);
16279 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16281 + di_write_lock_child(root);
16282 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16283 + aufs_write_unlock(root);
16286 + inode = d_inode(root);
16287 + inode_lock(inode);
16288 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16289 + if (unlikely(err))
16291 + di_write_lock_child(root);
16293 + /* au_opts_remount() may return an error */
16294 + err = au_opts_remount(sb, &a->opts);
16296 + if (au_ftest_opts(a->opts.flags, REFRESH))
16297 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16300 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16301 + mntflags = au_mntflags(sb);
16302 + do_dx = !!au_opt_test(mntflags, DIO);
16303 + au_dy_arefresh(do_dx);
16306 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16307 + aufs_write_unlock(root);
16310 + inode_unlock(inode);
16311 + err = cvt_err(err);
16317 +/* ---------------------------------------------------------------------- */
16319 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16322 + struct au_fsctx_opts *a = fc->fs_private;
16323 + struct au_sbinfo *sbinfo = a->sbinfo;
16324 + struct dentry *root;
16325 + struct inode *inode;
16327 + sbinfo->si_sb = sb;
16328 + sb->s_fs_info = sbinfo;
16329 + kobject_get(&sbinfo->si_kobj);
16331 + __si_write_lock(sb);
16333 + au_sbilist_add(sb);
16335 + /* all timestamps always follow the ones on the branch */
16336 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16337 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16338 + sb->s_op = &aufs_sop;
16339 + sb->s_d_op = &aufs_dop;
16340 + sb->s_magic = AUFS_SUPER_MAGIC;
16341 + sb->s_maxbytes = 0;
16342 + sb->s_stack_depth = 1;
16343 + au_export_init(sb);
16344 + au_xattr_init(sb);
16346 + err = au_alloc_root(sb);
16347 + if (unlikely(err)) {
16348 + si_write_unlock(sb);
16351 + root = sb->s_root;
16352 + inode = d_inode(root);
16353 + ii_write_lock_parent(inode);
16354 + aufs_write_unlock(root);
16356 + /* lock vfs_inode first, then aufs. */
16357 + inode_lock(inode);
16358 + aufs_write_lock(root);
16359 + err = au_opts_mount(sb, &a->opts);
16361 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16362 + sb->s_d_op = &aufs_dop_noreval;
16363 + /* infofc(fc, "%ps", sb->s_d_op); */
16364 + pr_info("%ps\n", sb->s_d_op);
16365 + au_refresh_dop(root, /*force_reval*/0);
16366 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16367 + au_refresh_iop(inode, /*force_getattr*/0);
16369 + aufs_write_unlock(root);
16370 + inode_unlock(inode);
16372 + goto out; /* success */
16375 + sb->s_root = NULL;
16378 + if (unlikely(err))
16379 + kobject_put(&sbinfo->si_kobj);
16381 + err = cvt_err(err);
16386 +static int au_fsctx_get_tree(struct fs_context *fc)
16390 + AuDbg("fc %p\n", fc);
16391 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16397 +/* ---------------------------------------------------------------------- */
16399 +static void au_fsctx_dump(struct au_opts *opts)
16401 +#ifdef CONFIG_AUFS_DEBUG
16402 + /* reduce stack space */
16404 + struct au_opt_add *add;
16405 + struct au_opt_del *del;
16406 + struct au_opt_mod *mod;
16407 + struct au_opt_xino *xino;
16408 + struct au_opt_xino_itrunc *xino_itrunc;
16409 + struct au_opt_wbr_create *create;
16411 + struct au_opt *opt;
16414 + while (opt->type != Opt_tail) {
16415 + switch (opt->type) {
16417 + u.add = &opt->add;
16418 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16419 + u.add->bindex, u.add->pathname, u.add->perm,
16420 + u.add->path.dentry);
16425 + u.del = &opt->del;
16426 + AuDbg("del {%s, %p}\n",
16427 + u.del->pathname, u.del->h_path.dentry);
16432 + u.mod = &opt->mod;
16433 + AuDbg("mod {%s, 0x%x, %p}\n",
16434 + u.mod->path, u.mod->perm, u.mod->h_root);
16437 + u.add = &opt->add;
16438 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16439 + u.add->bindex, u.add->pathname, u.add->perm,
16440 + u.add->path.dentry);
16442 + case Opt_prepend:
16443 + u.add = &opt->add;
16444 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16445 + u.add->bindex, u.add->pathname, u.add->perm,
16446 + u.add->path.dentry);
16450 + AuDbg("dirwh %d\n", opt->dirwh);
16452 + case Opt_rdcache:
16453 + AuDbg("rdcache %d\n", opt->rdcache);
16456 + AuDbg("rdblk %d\n", opt->rdblk);
16459 + AuDbg("rdhash %u\n", opt->rdhash);
16463 + u.xino = &opt->xino;
16464 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16467 +#define au_fsctx_TF(name) \
16468 + case Opt_##name: \
16472 + AuLabel(no##name); \
16475 + /* simple true/false flag */
16476 + au_fsctx_TF(trunc_xino);
16477 + au_fsctx_TF(trunc_xib);
16478 + au_fsctx_TF(dirperm1);
16479 + au_fsctx_TF(plink);
16480 + au_fsctx_TF(shwh);
16481 + au_fsctx_TF(dio);
16482 + au_fsctx_TF(warn_perm);
16483 + au_fsctx_TF(verbose);
16484 + au_fsctx_TF(sum);
16485 + au_fsctx_TF(dirren);
16486 + au_fsctx_TF(acl);
16487 +#undef au_fsctx_TF
16489 + case Opt_trunc_xino_path:
16491 + case Opt_itrunc_xino:
16492 + u.xino_itrunc = &opt->xino_itrunc;
16493 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16499 + case Opt_list_plink:
16500 + AuLabel(list_plink);
16503 + AuDbg("udba %d, %s\n",
16504 + opt->udba, au_optstr_udba(opt->udba));
16506 + case Opt_diropq_a:
16507 + AuLabel(diropq_a);
16509 + case Opt_diropq_w:
16510 + AuLabel(diropq_w);
16515 + case Opt_wbr_create:
16516 + u.create = &opt->wbr_create;
16517 + AuDbg("create %d, %s\n", u.create->wbr_create,
16518 + au_optstr_wbr_create(u.create->wbr_create));
16519 + switch (u.create->wbr_create) {
16520 + case AuWbrCreate_MFSV:
16522 + case AuWbrCreate_PMFSV:
16523 + AuDbg("%d sec\n", u.create->mfs_second);
16525 + case AuWbrCreate_MFSRR:
16527 + case AuWbrCreate_TDMFS:
16528 + AuDbg("%llu watermark\n",
16529 + u.create->mfsrr_watermark);
16531 + case AuWbrCreate_MFSRRV:
16533 + case AuWbrCreate_TDMFSV:
16535 + case AuWbrCreate_PMFSRRV:
16536 + AuDbg("%llu watermark, %d sec\n",
16537 + u.create->mfsrr_watermark,
16538 + u.create->mfs_second);
16542 + case Opt_wbr_copyup:
16543 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16544 + au_optstr_wbr_copyup(opt->wbr_copyup));
16546 + case Opt_fhsm_sec:
16547 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16551 + AuDbg("type %d\n", opt->type);
16559 +/* ---------------------------------------------------------------------- */
16562 + * For conditionally compiled mount options.
16563 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16565 +#define au_ignore_flag(name, action) \
16566 + fsparam_flag(name, action), \
16567 + fsparam_flag("no" name, Opt_ignore_silent)
16569 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16570 + fsparam_string("br", Opt_br),
16572 + /* "add=%d:%s" or "ins=%d:%s" */
16573 + fsparam_string("add", Opt_add),
16574 + fsparam_string("ins", Opt_add),
16575 + fsparam_path("append", Opt_append),
16576 + fsparam_path("prepend", Opt_prepend),
16578 + fsparam_path("del", Opt_del),
16579 + /* fsparam_s32("idel", Opt_idel), */
16580 + fsparam_path("mod", Opt_mod),
16581 + /* fsparam_string("imod", Opt_imod), */
16583 + fsparam_s32("dirwh", Opt_dirwh),
16585 + fsparam_path("xino", Opt_xino),
16586 + fsparam_flag("noxino", Opt_noxino),
16587 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16588 + /* "trunc_xino_v=%d:%d" */
16589 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16590 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16591 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16592 + /* fsparam_path("zxino", Opt_zxino), */
16593 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16595 +#ifdef CONFIG_PROC_FS
16596 + fsparam_flag_no("plink", Opt_plink),
16598 + au_ignore_flag("plink", Opt_ignore),
16601 +#ifdef CONFIG_AUFS_DEBUG
16602 + fsparam_flag("list_plink", Opt_list_plink),
16605 + fsparam_string("udba", Opt_udba),
16607 + fsparam_flag_no("dio", Opt_dio),
16609 +#ifdef CONFIG_AUFS_DIRREN
16610 + fsparam_flag_no("dirren", Opt_dirren),
16612 + au_ignore_flag("dirren", Opt_ignore),
16615 +#ifdef CONFIG_AUFS_FHSM
16616 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16618 + fsparam_s32("fhsm_sec", Opt_ignore),
16621 + /* always | a | whiteouted | w */
16622 + fsparam_string("diropq", Opt_diropq),
16624 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16626 +#ifdef CONFIG_AUFS_SHWH
16627 + fsparam_flag_no("shwh", Opt_shwh),
16629 + au_ignore_flag("shwh", Opt_err),
16632 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16634 + fsparam_flag_no("verbose", Opt_verbose),
16635 + fsparam_flag("v", Opt_verbose),
16636 + fsparam_flag("quiet", Opt_noverbose),
16637 + fsparam_flag("q", Opt_noverbose),
16638 + /* user-space may handle this */
16639 + fsparam_flag("silent", Opt_noverbose),
16641 + fsparam_flag_no("sum", Opt_sum),
16642 + fsparam_flag("wsum", Opt_wsum),
16644 + fsparam_s32("rdcache", Opt_rdcache),
16645 + /* "def" or s32 */
16646 + fsparam_string("rdblk", Opt_rdblk),
16647 + /* "def" or s32 */
16648 + fsparam_string("rdhash", Opt_rdhash),
16650 + fsparam_string("create", Opt_wbr_create),
16651 + fsparam_string("create_policy", Opt_wbr_create),
16652 + fsparam_string("cpup", Opt_wbr_copyup),
16653 + fsparam_string("copyup", Opt_wbr_copyup),
16654 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16656 + /* generic VFS flag */
16657 +#ifdef CONFIG_FS_POSIX_ACL
16658 + fsparam_flag_no("acl", Opt_acl),
16660 + au_ignore_flag("acl", Opt_ignore),
16663 + /* internal use for the scripts */
16664 + fsparam_string("si", Opt_ignore_silent),
16666 + /* obsoleted, keep them temporary */
16667 + fsparam_flag("nodlgt", Opt_ignore_silent),
16668 + fsparam_flag("clean_plink", Opt_ignore),
16669 + fsparam_string("dirs", Opt_br),
16670 + fsparam_u32("debug", Opt_ignore),
16671 + /* "whiteout" or "all" */
16672 + fsparam_string("delete", Opt_ignore),
16673 + fsparam_string("imap", Opt_ignore),
16675 + /* temporary workaround, due to old mount(8)? */
16676 + fsparam_flag("relatime", Opt_ignore_silent),
16681 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16682 + char *brspec, size_t speclen,
16683 + aufs_bindex_t bindex)
16688 + AuDbg("brspec %s\n", brspec);
16692 + speclen = strlen(brspec);
16693 + /* will be freed by au_fsctx_free() */
16694 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16695 + if (unlikely(!p)) {
16696 + errorfc(fc, "failed in %s", brspec);
16699 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16706 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16710 + struct au_fsctx_opts *a = fc->fs_private;
16711 + struct au_opt *opt = a->opt;
16712 + aufs_bindex_t bindex = a->bindex;
16714 + AuDbg("brspec %s\n", brspec);
16717 + while ((p = strsep(&brspec, ":")) && *p) {
16718 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16720 + if (unlikely(err))
16724 + if (unlikely(opt > a->opt_tail)) {
16730 + opt->type = Opt_tail;
16733 + a->bindex = bindex;
16740 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16744 + struct au_fsctx_opts *a = fc->fs_private;
16745 + struct au_opt *opt = a->opt;
16748 + p = strchr(addspec, ':');
16749 + if (unlikely(!p)) {
16750 + errorfc(fc, "bad arg in %s", addspec);
16754 + err = kstrtoint(addspec, 0, &n);
16755 + if (unlikely(err)) {
16756 + errorfc(fc, "bad integer in %s", addspec);
16759 + AuDbg("n %d\n", n);
16760 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16767 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16768 + struct fs_parameter *param)
16773 + /* will be freed by au_fsctx_free() */
16774 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16775 + if (unlikely(!del->pathname))
16777 + AuDbg("del %s\n", del->pathname);
16778 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16779 + if (unlikely(err))
16780 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16787 +#if 0 /* reserved for future use */
16788 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16789 + aufs_bindex_t bindex)
16792 + struct super_block *sb;
16793 + struct dentry *root;
16794 + struct au_fsctx_opts *a = fc->fs_private;
16800 + root = sb->s_root;
16801 + aufs_read_lock(root, AuLock_FLUSH);
16802 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16803 + errorfc(fc, "out of bounds, %d", bindex);
16808 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16809 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16812 + aufs_read_unlock(root, !AuLock_IR);
16818 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16819 + struct fs_parameter *param)
16822 + struct path path;
16826 + /* will be freed by au_fsctx_free() */
16827 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16828 + if (unlikely(!mod->path))
16832 + p = strchr(mod->path, '=');
16833 + if (unlikely(!p)) {
16834 + errorfc(fc, "no permission %s", mod->path);
16839 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16840 + if (unlikely(err)) {
16841 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16845 + mod->perm = au_br_perm_val(p);
16846 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16847 + mod->h_root = dget(path.dentry);
16855 +#if 0 /* reserved for future use */
16856 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16861 + struct super_block *sb;
16862 + struct dentry *root;
16863 + struct au_fsctx_opts *a = fc->fs_private;
16869 + p = strchr(ibrspec, ':');
16870 + if (unlikely(!p)) {
16871 + errorfc(fc, "no index, %s", ibrspec);
16875 + err = kstrtoint(ibrspec, 0, &n);
16876 + if (unlikely(err)) {
16877 + errorfc(fc, "bad integer in %s", ibrspec);
16880 + AuDbg("n %d\n", n);
16882 + root = sb->s_root;
16883 + aufs_read_lock(root, AuLock_FLUSH);
16884 + if (n < 0 || au_sbbot(sb) < n) {
16885 + errorfc(fc, "out of bounds, %d", bindex);
16890 + mod->perm = au_br_perm_val(p);
16891 + AuDbg("mod path %s, perm 0x%x, %s\n",
16892 + mod->path, mod->perm, p);
16893 + mod->h_root = dget(au_h_dptr(root, bindex));
16896 + aufs_read_unlock(root, !AuLock_IR);
16903 +static int au_fsctx_parse_xino(struct fs_context *fc,
16904 + struct au_opt_xino *xino,
16905 + struct fs_parameter *param)
16908 + struct au_fsctx_opts *a = fc->fs_private;
16911 + /* will be freed by au_opts_free() */
16912 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16913 + if (unlikely(!xino->path))
16915 + AuDbg("path %s\n", xino->path);
16917 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16919 + err = PTR_ERR(xino->file);
16920 + if (IS_ERR(xino->file)) {
16921 + xino->file = NULL;
16926 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16928 + errorfc(fc, "%s must be outside", xino->path);
16937 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16938 + struct au_opt_xino_itrunc *xino_itrunc,
16942 + aufs_bindex_t bbot, bindex;
16943 + struct path path;
16944 + struct dentry *root;
16945 + struct au_fsctx_opts *a = fc->fs_private;
16947 + AuDebugOn(!a->sb);
16949 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16950 + if (unlikely(err)) {
16951 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16955 + xino_itrunc->bindex = -1;
16956 + root = a->sb->s_root;
16957 + aufs_read_lock(root, AuLock_FLUSH);
16958 + bbot = au_sbbot(a->sb);
16959 + for (bindex = 0; bindex <= bbot; bindex++) {
16960 + if (au_h_dptr(root, bindex) == path.dentry) {
16961 + xino_itrunc->bindex = bindex;
16965 + aufs_read_unlock(root, !AuLock_IR);
16968 + if (unlikely(xino_itrunc->bindex < 0)) {
16970 + errorfc(fc, "no such branch %s", pathname);
16978 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16979 + struct au_opt_xino_itrunc *xino_itrunc,
16980 + unsigned int bindex)
16983 + aufs_bindex_t bbot;
16984 + struct super_block *sb;
16985 + struct au_fsctx_opts *a = fc->fs_private;
16991 + si_noflush_read_lock(sb);
16992 + bbot = au_sbbot(sb);
16993 + si_read_unlock(sb);
16994 + if (bindex <= bbot)
16995 + xino_itrunc->bindex = bindex;
16998 + errorfc(fc, "out of bounds, %u", bindex);
17005 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
17008 + struct fs_parse_result result;
17009 + struct au_fsctx_opts *a = fc->fs_private;
17010 + struct au_opt *opt = a->opt;
17012 + AuDbg("fc %p, param {key %s, string %s}\n",
17013 + fc, param->key, param->string);
17014 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
17015 + if (unlikely(err < 0))
17018 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
17019 + token, result.negated, result.uint_64);
17025 + err = au_fsctx_parse_br(fc, param->string);
17028 + err = au_fsctx_parse_add(fc, param->string);
17031 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17032 + /*dummy bindex*/1);
17034 + case Opt_prepend:
17035 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17040 + err = au_fsctx_parse_del(fc, &opt->del, param);
17042 +#if 0 /* reserved for future use */
17049 + del->pathname = "(indexed)";
17050 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17055 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17057 +#ifdef IMOD /* reserved for future use */
17064 + u.mod->path = "(indexed)";
17065 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17070 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17072 + case Opt_trunc_xino_path:
17074 + errorfc(fc, "no such branch %s", param->string);
17077 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17081 + case Opt_trunc_xino_v:
17087 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17091 + case Opt_itrunc_xino:
17093 + errorfc(fc, "out of bounds %s", param->string);
17096 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17102 + opt->dirwh = result.int_32;
17105 + case Opt_rdcache:
17106 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17107 + errorfc(fc, "rdcache must be smaller than %d",
17108 + AUFS_RDCACHE_MAX);
17112 + opt->rdcache = result.int_32;
17117 + opt->rdblk = AUFS_RDBLK_DEF;
17118 + if (!strcmp(param->string, "def"))
17121 + err = kstrtoint(param->string, 0, &result.int_32);
17122 + if (unlikely(err)) {
17123 + errorfc(fc, "bad value in %s", param->key);
17127 + if (unlikely(result.int_32 < 0
17128 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17129 + errorfc(fc, "bad value in %s", param->key);
17132 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17133 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17137 + opt->rdblk = result.int_32;
17142 + opt->rdhash = AUFS_RDHASH_DEF;
17143 + if (!strcmp(param->string, "def"))
17146 + err = kstrtoint(param->string, 0, &result.int_32);
17147 + if (unlikely(err)) {
17148 + errorfc(fc, "bad value in %s", param->key);
17151 + /* how about zero? */
17152 + if (result.int_32 < 0
17153 + || result.int_32 * sizeof(struct hlist_head)
17154 + > KMALLOC_MAX_SIZE) {
17156 + errorfc(fc, "bad integer in %s", param->key);
17159 + opt->rdhash = result.int_32;
17164 + * As other options, fs/aufs/opts.c can handle these strings by
17165 + * match_token(). But "diropq=" is deprecated now and will
17166 + * never have other value. So simple strcmp() is enough here.
17168 + if (!strcmp(param->string, "a") ||
17169 + !strcmp(param->string, "always")) {
17171 + opt->type = Opt_diropq_a;
17172 + } else if (!strcmp(param->string, "w") ||
17173 + !strcmp(param->string, "whiteouted")) {
17175 + opt->type = Opt_diropq_w;
17177 + errorfc(fc, "unknown value %s", param->string);
17181 + opt->udba = au_udba_val(param->string);
17182 + if (opt->udba >= 0)
17185 + errorf(fc, "wrong value, %s", param->string);
17188 + case Opt_wbr_create:
17189 + opt->wbr_create.wbr_create
17190 + = au_wbr_create_val(param->string, &opt->wbr_create);
17191 + if (opt->wbr_create.wbr_create >= 0)
17194 + errorf(fc, "wrong value, %s", param->key);
17197 + case Opt_wbr_copyup:
17198 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17199 + if (opt->wbr_copyup >= 0)
17202 + errorfc(fc, "wrong value, %s", param->key);
17205 + case Opt_fhsm_sec:
17206 + if (unlikely(result.int_32 < 0)) {
17207 + errorfc(fc, "bad integer in %s\n", param->key);
17212 + opt->fhsm_second = result.int_32;
17214 + warnfc(fc, "ignored %s %s", param->key, param->string);
17217 + /* simple true/false flag */
17218 +#define au_fsctx_TF(name) \
17219 + case Opt_##name: \
17221 + opt->tf = !result.negated; \
17223 + au_fsctx_TF(trunc_xino);
17224 + au_fsctx_TF(trunc_xib);
17225 + au_fsctx_TF(dirperm1);
17226 + au_fsctx_TF(plink);
17227 + au_fsctx_TF(shwh);
17228 + au_fsctx_TF(dio);
17229 + au_fsctx_TF(warn_perm);
17230 + au_fsctx_TF(verbose);
17231 + au_fsctx_TF(sum);
17232 + au_fsctx_TF(dirren);
17233 + au_fsctx_TF(acl);
17234 +#undef au_fsctx_TF
17236 + case Opt_noverbose:
17238 + opt->type = Opt_verbose;
17244 + case Opt_list_plink:
17251 + warnfc(fc, "ignored %s", param->key);
17253 + case Opt_ignore_silent:
17262 + if (unlikely(err))
17270 + case Opt_noverbose:
17275 + opt->type = token;
17279 + if (unlikely(opt > a->opt_tail)) {
17283 + opt->type = Opt_tail;
17291 + * these options accept both 'name=val' and 'name:val' form.
17292 + * some accept optional '=' in its value.
17293 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17295 +static inline unsigned int is_colonopt(char *str)
17297 +#define do_test(name) \
17298 + if (!strncmp(str, name ":", sizeof(name))) \
17299 + return sizeof(name) - 1
17303 + do_test("append");
17304 + do_test("prepend");
17306 + /* do_test("idel"); */
17308 + /* do_test("imod"); */
17314 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17319 + struct au_fsctx_opts *a = fc->fs_private;
17322 + AuDbg("str %s\n", str);
17324 + u = is_colonopt(str);
17327 + str = strchr(str, ',');
17333 + AuDbg("str %s\n", str);
17335 + err = generic_parse_monolithic(fc, str);
17337 + au_fsctx_dump(&a->opts);
17342 +/* ---------------------------------------------------------------------- */
17344 +static void au_fsctx_opts_free(struct au_opts *opts)
17346 + struct au_opt *opt;
17349 + while (opt->type != Opt_tail) {
17350 + switch (opt->type) {
17355 + case Opt_prepend:
17356 + kfree(opt->add.pathname);
17357 + path_put(&opt->add.path);
17360 + kfree(opt->del.pathname);
17363 + path_put(&opt->del.h_path);
17366 + kfree(opt->mod.path);
17369 + dput(opt->mod.h_root);
17372 + kfree(opt->xino.path);
17373 + fput(opt->xino.file);
17380 +static void au_fsctx_free(struct fs_context *fc)
17382 + struct au_fsctx_opts *a = fc->fs_private;
17384 + /* fs_type=%p, root=%pD */
17385 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17386 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17388 + kobject_put(&a->sbinfo->si_kobj);
17389 + au_fsctx_opts_free(&a->opts);
17390 + free_page((unsigned long)a->opts.opt);
17394 +static const struct fs_context_operations au_fsctx_ops = {
17395 + .free = au_fsctx_free,
17396 + .parse_param = au_fsctx_parse_param,
17397 + .parse_monolithic = au_fsctx_parse_monolithic,
17398 + .get_tree = au_fsctx_get_tree,
17399 + .reconfigure = au_fsctx_reconfigure
17401 + * nfs4 requires ->dup()? No.
17402 + * I don't know what is this ->dup() for.
17406 +int aufs_fsctx_init(struct fs_context *fc)
17409 + struct au_fsctx_opts *a;
17411 + /* fs_type=%p, root=%pD */
17412 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17413 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17415 + /* they will be freed by au_fsctx_free() */
17417 + a = kzalloc(sizeof(*a), GFP_NOFS);
17418 + if (unlikely(!a))
17421 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17422 + if (unlikely(!a->opts.opt))
17424 + a->opt = a->opts.opt;
17425 + a->opt->type = Opt_tail;
17426 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17427 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17428 + a->opts.sb_flags = fc->sb_flags;
17432 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17433 + a->opts.flags = AuOpts_REMOUNT;
17434 + a->sb = fc->root->d_sb;
17435 + a->sbinfo = au_sbi(a->sb);
17436 + kobject_get(&a->sbinfo->si_kobj);
17438 + a->sbinfo = au_si_alloc(a->sb);
17439 + AuDebugOn(!a->sbinfo);
17440 + err = PTR_ERR(a->sbinfo);
17441 + if (IS_ERR(a->sbinfo))
17443 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17447 + fc->fs_private = a;
17448 + fc->ops = &au_fsctx_ops;
17449 + goto out; /* success */
17452 + free_page((unsigned long)a->opts.opt);
17459 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17460 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17461 +++ linux/fs/aufs/fstype.h 2024-05-13 17:13:00.618070924 +0200
17463 +/* SPDX-License-Identifier: GPL-2.0 */
17465 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17467 + * This program is free software; you can redistribute it and/or modify
17468 + * it under the terms of the GNU General Public License as published by
17469 + * the Free Software Foundation; either version 2 of the License, or
17470 + * (at your option) any later version.
17472 + * This program is distributed in the hope that it will be useful,
17473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17475 + * GNU General Public License for more details.
17477 + * You should have received a copy of the GNU General Public License
17478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17482 + * judging filesystem type
17485 +#ifndef __AUFS_FSTYPE_H__
17486 +#define __AUFS_FSTYPE_H__
17490 +#include <linux/fs.h>
17491 +#include <linux/magic.h>
17492 +#include <linux/nfs_fs.h>
17493 +#include <linux/romfs_fs.h>
17495 +static inline int au_test_aufs(struct super_block *sb)
17497 + return sb->s_magic == AUFS_SUPER_MAGIC;
17500 +static inline const char *au_sbtype(struct super_block *sb)
17502 + return sb->s_type->name;
17505 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17507 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17508 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17514 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17516 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17517 + return sb->s_magic == ROMFS_MAGIC;
17523 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17525 +#if IS_ENABLED(CONFIG_CRAMFS)
17526 + return sb->s_magic == CRAMFS_MAGIC;
17531 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17533 +#if IS_ENABLED(CONFIG_NFS_FS)
17534 + return sb->s_magic == NFS_SUPER_MAGIC;
17540 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17542 +#if IS_ENABLED(CONFIG_FUSE_FS)
17543 + return sb->s_magic == FUSE_SUPER_MAGIC;
17549 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17551 +#if IS_ENABLED(CONFIG_XFS_FS)
17552 + return sb->s_magic == XFS_SB_MAGIC;
17558 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17560 +#ifdef CONFIG_TMPFS
17561 + return sb->s_magic == TMPFS_MAGIC;
17567 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17569 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17570 + return !strcmp(au_sbtype(sb), "ecryptfs");
17576 +static inline int au_test_ramfs(struct super_block *sb)
17578 + return sb->s_magic == RAMFS_MAGIC;
17581 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17583 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17584 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17590 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17592 +#ifdef CONFIG_PROC_FS
17593 + return sb->s_magic == PROC_SUPER_MAGIC;
17599 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17601 +#ifdef CONFIG_SYSFS
17602 + return sb->s_magic == SYSFS_MAGIC;
17608 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17610 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17611 + return sb->s_magic == CONFIGFS_MAGIC;
17617 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17619 +#if IS_ENABLED(CONFIG_MINIX_FS)
17620 + return sb->s_magic == MINIX3_SUPER_MAGIC
17621 + || sb->s_magic == MINIX2_SUPER_MAGIC
17622 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17623 + || sb->s_magic == MINIX_SUPER_MAGIC
17624 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17630 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17632 +#if IS_ENABLED(CONFIG_FAT_FS)
17633 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17639 +static inline int au_test_msdos(struct super_block *sb)
17641 + return au_test_fat(sb);
17644 +static inline int au_test_vfat(struct super_block *sb)
17646 + return au_test_fat(sb);
17649 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17651 +#ifdef CONFIG_SECURITYFS
17652 + return sb->s_magic == SECURITYFS_MAGIC;
17658 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17660 +#if IS_ENABLED(CONFIG_SQUASHFS)
17661 + return sb->s_magic == SQUASHFS_MAGIC;
17667 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17669 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17670 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17676 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17678 +#if IS_ENABLED(CONFIG_XENFS)
17679 + return sb->s_magic == XENFS_SUPER_MAGIC;
17685 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17687 +#ifdef CONFIG_DEBUG_FS
17688 + return sb->s_magic == DEBUGFS_MAGIC;
17694 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17696 +#if IS_ENABLED(CONFIG_NILFS)
17697 + return sb->s_magic == NILFS_SUPER_MAGIC;
17703 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17705 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17706 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17712 +/* ---------------------------------------------------------------------- */
17714 + * they can't be an aufs branch.
17716 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17719 +#ifndef CONFIG_AUFS_BR_RAMFS
17720 + au_test_ramfs(sb) ||
17722 + au_test_procfs(sb)
17723 + || au_test_sysfs(sb)
17724 + || au_test_configfs(sb)
17725 + || au_test_debugfs(sb)
17726 + || au_test_securityfs(sb)
17727 + || au_test_xenfs(sb)
17728 + || au_test_ecryptfs(sb)
17729 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17730 + || au_test_aufs(sb); /* will be supported in next version */
17733 +static inline int au_test_fs_remote(struct super_block *sb)
17735 + return !au_test_tmpfs(sb)
17736 +#ifdef CONFIG_AUFS_BR_RAMFS
17737 + && !au_test_ramfs(sb)
17739 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17742 +/* ---------------------------------------------------------------------- */
17745 + * Note: these functions (below) are created after reading ->getattr() in all
17746 + * filesystems under linux/fs. it means we have to do so in every update...
17750 + * some filesystems require getattr to refresh the inode attributes before
17752 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17753 + * and leave the work for d_revalidate()
17755 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17757 + return au_test_nfs(sb)
17758 + || au_test_fuse(sb)
17759 + /* || au_test_btrfs(sb) */ /* untested */
17764 + * filesystems which don't maintain i_size or i_blocks.
17766 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17768 + return au_test_xfs(sb)
17769 + || au_test_btrfs(sb)
17770 + || au_test_ubifs(sb)
17771 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17772 + /* || au_test_minix(sb) */ /* untested */
17777 + * filesystems which don't store the correct value in some of their inode
17780 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17782 + return au_test_fs_bad_iattr_size(sb)
17783 + || au_test_fat(sb)
17784 + || au_test_msdos(sb)
17785 + || au_test_vfat(sb);
17788 +/* they don't check i_nlink in link(2) */
17789 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17791 + return au_test_tmpfs(sb)
17792 +#ifdef CONFIG_AUFS_BR_RAMFS
17793 + || au_test_ramfs(sb)
17795 + || au_test_ubifs(sb)
17796 + || au_test_hfsplus(sb);
17800 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17802 +static inline int au_test_fs_notime(struct super_block *sb)
17804 + return au_test_nfs(sb)
17805 + || au_test_fuse(sb)
17806 + || au_test_ubifs(sb)
17810 +/* temporary support for i#1 in cramfs */
17811 +static inline int au_test_fs_unique_ino(struct inode *inode)
17813 + if (au_test_cramfs(inode->i_sb))
17814 + return inode->i_ino != 1;
17818 +/* ---------------------------------------------------------------------- */
17821 + * the filesystem where the xino files placed must support i/o after unlink and
17822 + * maintain i_size and i_blocks.
17824 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17826 + return au_test_fs_remote(sb)
17827 + || au_test_fs_bad_iattr_size(sb)
17828 + /* don't want unnecessary work for xino */
17829 + || au_test_aufs(sb)
17830 + || au_test_ecryptfs(sb)
17831 + || au_test_nilfs(sb);
17834 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17836 + return au_test_tmpfs(sb)
17837 + || au_test_ramfs(sb);
17841 + * test if the @sb is real-readonly.
17843 +static inline int au_test_fs_rr(struct super_block *sb)
17845 + return au_test_squashfs(sb)
17846 + || au_test_iso9660(sb)
17847 + || au_test_cramfs(sb)
17848 + || au_test_romfs(sb);
17852 + * test if the @inode is nfs with 'noacl' option
17853 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17855 +static inline int au_test_nfs_noacl(struct inode *inode)
17857 + return au_test_nfs(inode->i_sb)
17858 + /* && IS_POSIXACL(inode) */
17859 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17862 +#endif /* __KERNEL__ */
17863 +#endif /* __AUFS_FSTYPE_H__ */
17864 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17865 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17866 +++ linux/fs/aufs/hbl.h 2024-05-13 17:13:00.618070924 +0200
17868 +/* SPDX-License-Identifier: GPL-2.0 */
17870 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17872 + * This program is free software; you can redistribute it and/or modify
17873 + * it under the terms of the GNU General Public License as published by
17874 + * the Free Software Foundation; either version 2 of the License, or
17875 + * (at your option) any later version.
17877 + * This program is distributed in the hope that it will be useful,
17878 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17879 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17880 + * GNU General Public License for more details.
17882 + * You should have received a copy of the GNU General Public License
17883 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17887 + * helpers for hlist_bl.h
17890 +#ifndef __AUFS_HBL_H__
17891 +#define __AUFS_HBL_H__
17895 +#include <linux/list_bl.h>
17897 +static inline void au_hbl_add(struct hlist_bl_node *node,
17898 + struct hlist_bl_head *hbl)
17900 + hlist_bl_lock(hbl);
17901 + hlist_bl_add_head(node, hbl);
17902 + hlist_bl_unlock(hbl);
17905 +static inline void au_hbl_del(struct hlist_bl_node *node,
17906 + struct hlist_bl_head *hbl)
17908 + hlist_bl_lock(hbl);
17909 + hlist_bl_del(node);
17910 + hlist_bl_unlock(hbl);
17913 +#define au_hbl_for_each(pos, head) \
17914 + for (pos = hlist_bl_first(head); \
17918 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17920 + unsigned long cnt;
17921 + struct hlist_bl_node *pos;
17924 + hlist_bl_lock(hbl);
17925 + au_hbl_for_each(pos, hbl)
17927 + hlist_bl_unlock(hbl);
17931 +#endif /* __KERNEL__ */
17932 +#endif /* __AUFS_HBL_H__ */
17933 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17934 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17935 +++ linux/fs/aufs/hfsnotify.c 2024-05-13 17:13:00.618070924 +0200
17937 +// SPDX-License-Identifier: GPL-2.0
17939 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17941 + * This program is free software; you can redistribute it and/or modify
17942 + * it under the terms of the GNU General Public License as published by
17943 + * the Free Software Foundation; either version 2 of the License, or
17944 + * (at your option) any later version.
17946 + * This program is distributed in the hope that it will be useful,
17947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17949 + * GNU General Public License for more details.
17951 + * You should have received a copy of the GNU General Public License
17952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17956 + * fsnotify for the lower directories
17961 +/* FS_IN_IGNORED is unnecessary */
17962 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17963 + | FS_CREATE | FS_EVENT_ON_CHILD);
17964 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17965 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17967 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17969 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17971 + /* AuDbg("here\n"); */
17972 + au_cache_free_hnotify(hn);
17973 + smp_mb__before_atomic(); /* for atomic64_dec */
17974 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17975 + wake_up(&au_hfsn_wq);
17978 +static int au_hfsn_alloc(struct au_hinode *hinode)
17981 + struct au_hnotify *hn;
17982 + struct super_block *sb;
17983 + struct au_branch *br;
17984 + struct fsnotify_mark *mark;
17985 + aufs_bindex_t bindex;
17987 + hn = hinode->hi_notify;
17988 + sb = hn->hn_aufs_inode->i_sb;
17989 + bindex = au_br_index(sb, hinode->hi_id);
17990 + br = au_sbr(sb, bindex);
17991 + AuDebugOn(!br->br_hfsn);
17993 + mark = &hn->hn_mark;
17994 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17995 + mark->mask = AuHfsnMask;
17997 + * by udba rename or rmdir, aufs assign a new inode to the known
17998 + * h_inode, so specify 1 to allow dups.
18001 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
18007 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
18009 + struct fsnotify_mark *mark;
18010 + unsigned long long ull;
18011 + struct fsnotify_group *group;
18013 + ull = atomic64_inc_return(&au_hfsn_ifree);
18016 + mark = &hn->hn_mark;
18017 + spin_lock(&mark->lock);
18018 + group = mark->group;
18019 + fsnotify_get_group(group);
18020 + spin_unlock(&mark->lock);
18022 + fsnotify_destroy_mark(mark, group);
18023 + fsnotify_put_mark(mark);
18024 + fsnotify_put_group(group);
18027 + /* free hn by myself */
18031 +/* ---------------------------------------------------------------------- */
18033 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18035 + struct fsnotify_mark *mark;
18037 + mark = &hinode->hi_notify->hn_mark;
18038 + spin_lock(&mark->lock);
18040 + AuDebugOn(mark->mask & AuHfsnMask);
18041 + mark->mask |= AuHfsnMask;
18043 + AuDebugOn(!(mark->mask & AuHfsnMask));
18044 + mark->mask &= ~AuHfsnMask;
18046 + spin_unlock(&mark->lock);
18047 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18050 +/* ---------------------------------------------------------------------- */
18052 +/* #define AuDbgHnotify */
18053 +#ifdef AuDbgHnotify
18054 +static char *au_hfsn_name(u32 mask)
18056 +#ifdef CONFIG_AUFS_DEBUG
18057 +#define test_ret(flag) \
18059 + if (mask & flag) \
18062 + test_ret(FS_ACCESS);
18063 + test_ret(FS_MODIFY);
18064 + test_ret(FS_ATTRIB);
18065 + test_ret(FS_CLOSE_WRITE);
18066 + test_ret(FS_CLOSE_NOWRITE);
18067 + test_ret(FS_OPEN);
18068 + test_ret(FS_MOVED_FROM);
18069 + test_ret(FS_MOVED_TO);
18070 + test_ret(FS_CREATE);
18071 + test_ret(FS_DELETE);
18072 + test_ret(FS_DELETE_SELF);
18073 + test_ret(FS_MOVE_SELF);
18074 + test_ret(FS_UNMOUNT);
18075 + test_ret(FS_Q_OVERFLOW);
18076 + test_ret(FS_IN_IGNORED);
18077 + test_ret(FS_ISDIR);
18078 + test_ret(FS_IN_ONESHOT);
18079 + test_ret(FS_EVENT_ON_CHILD);
18088 +/* ---------------------------------------------------------------------- */
18090 +static void au_hfsn_free_group(struct fsnotify_group *group)
18092 + struct au_br_hfsnotify *hfsn = group->private;
18094 + /* AuDbg("here\n"); */
18095 + au_kfree_try_rcu(hfsn);
18098 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18099 + u32 mask, const void *data, int data_type,
18100 + struct inode *dir,
18101 + const struct qstr *file_name, u32 cookie,
18102 + struct fsnotify_iter_info *iter_info)
18105 + struct au_hnotify *hnotify;
18106 + struct inode *h_dir, *h_inode;
18107 + struct fsnotify_mark *inode_mark;
18109 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18110 + || data_type == FSNOTIFY_EVENT_DENTRY));
18113 + /* if FS_UNMOUNT happens, there must be another bug */
18114 + AuDebugOn(mask & FS_UNMOUNT);
18115 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18120 +#ifdef AuDbgHnotify
18122 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18123 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18124 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18125 + h_dir->i_ino, mask, au_hfsn_name(mask),
18126 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18127 + /* WARN_ON(1); */
18132 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18133 + AuDebugOn(!inode_mark);
18134 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18135 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18141 +static struct fsnotify_ops au_hfsn_ops = {
18142 + .handle_event = au_hfsn_handle_event,
18143 + .free_group_priv = au_hfsn_free_group,
18144 + .free_mark = au_hfsn_free_mark
18147 +/* ---------------------------------------------------------------------- */
18149 +static void au_hfsn_fin_br(struct au_branch *br)
18151 + struct au_br_hfsnotify *hfsn;
18153 + hfsn = br->br_hfsn;
18156 + fsnotify_put_group(hfsn->hfsn_group);
18161 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18164 + struct fsnotify_group *group;
18165 + struct au_br_hfsnotify *hfsn;
18168 + br->br_hfsn = NULL;
18169 + if (!au_br_hnotifyable(perm))
18173 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18174 + if (unlikely(!hfsn))
18178 + group = fsnotify_alloc_group(&au_hfsn_ops,
18179 + /*flags - not for userspace*/0);
18180 + if (IS_ERR(group)) {
18181 + err = PTR_ERR(group);
18182 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18186 + group->private = hfsn;
18187 + hfsn->hfsn_group = group;
18188 + br->br_hfsn = hfsn;
18189 + goto out; /* success */
18192 + au_kfree_try_rcu(hfsn);
18197 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18202 + if (!br->br_hfsn)
18203 + err = au_hfsn_init_br(br, perm);
18208 +/* ---------------------------------------------------------------------- */
18210 +static void au_hfsn_fin(void)
18212 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18213 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18216 +const struct au_hnotify_op au_hnotify_op = {
18217 + .ctl = au_hfsn_ctl,
18218 + .alloc = au_hfsn_alloc,
18219 + .free = au_hfsn_free,
18221 + .fin = au_hfsn_fin,
18223 + .reset_br = au_hfsn_reset_br,
18224 + .fin_br = au_hfsn_fin_br,
18225 + .init_br = au_hfsn_init_br
18227 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18228 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18229 +++ linux/fs/aufs/hfsplus.c 2024-05-13 17:13:00.618070924 +0200
18231 +// SPDX-License-Identifier: GPL-2.0
18233 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18235 + * This program is free software; you can redistribute it and/or modify
18236 + * it under the terms of the GNU General Public License as published by
18237 + * the Free Software Foundation; either version 2 of the License, or
18238 + * (at your option) any later version.
18240 + * This program is distributed in the hope that it will be useful,
18241 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18242 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18243 + * GNU General Public License for more details.
18245 + * You should have received a copy of the GNU General Public License
18246 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18250 + * special support for filesystems which acquires an inode mutex
18251 + * at final closing a file, eg, hfsplus.
18253 + * This trick is very simple and stupid, just to open the file before really
18254 + * necessary open to tell hfsplus that this is not the final closing.
18255 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18256 + * and au_h_open_post() after releasing it.
18261 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18264 + struct file *h_file;
18265 + struct dentry *h_dentry;
18267 + h_dentry = au_h_dptr(dentry, bindex);
18268 + AuDebugOn(!h_dentry);
18269 + AuDebugOn(d_is_negative(h_dentry));
18272 + if (au_test_hfsplus(h_dentry->d_sb)
18273 + && d_is_reg(h_dentry))
18274 + h_file = au_h_open(dentry, bindex,
18275 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18276 + /*file*/NULL, force_wr);
18280 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18281 + struct file *h_file)
18283 + struct au_branch *br;
18287 + br = au_sbr(dentry->d_sb, bindex);
18288 + au_lcnt_dec(&br->br_nfiles);
18291 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18292 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18293 +++ linux/fs/aufs/hnotify.c 2024-05-13 17:13:00.618070924 +0200
18295 +// SPDX-License-Identifier: GPL-2.0
18297 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18299 + * This program is free software; you can redistribute it and/or modify
18300 + * it under the terms of the GNU General Public License as published by
18301 + * the Free Software Foundation; either version 2 of the License, or
18302 + * (at your option) any later version.
18304 + * This program is distributed in the hope that it will be useful,
18305 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18306 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18307 + * GNU General Public License for more details.
18309 + * You should have received a copy of the GNU General Public License
18310 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18314 + * abstraction to notify the direct changes on lower directories
18317 +/* #include <linux/iversion.h> */
18320 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18323 + struct au_hnotify *hn;
18326 + hn = au_cache_alloc_hnotify();
18328 + hn->hn_aufs_inode = inode;
18329 + hinode->hi_notify = hn;
18330 + err = au_hnotify_op.alloc(hinode);
18332 + if (unlikely(err)) {
18333 + hinode->hi_notify = NULL;
18334 + au_cache_free_hnotify(hn);
18336 + * The upper dir was removed by udba, but the same named
18337 + * dir left. In this case, aufs assigns a new inode
18338 + * number and set the monitor again.
18339 + * For the lower dir, the old monitor is still left.
18341 + if (err == -EEXIST)
18350 +void au_hn_free(struct au_hinode *hinode)
18352 + struct au_hnotify *hn;
18354 + hn = hinode->hi_notify;
18356 + hinode->hi_notify = NULL;
18357 + if (au_hnotify_op.free(hinode, hn))
18358 + au_cache_free_hnotify(hn);
18362 +/* ---------------------------------------------------------------------- */
18364 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18366 + if (hinode->hi_notify)
18367 + au_hnotify_op.ctl(hinode, do_set);
18370 +void au_hn_reset(struct inode *inode, unsigned int flags)
18372 + aufs_bindex_t bindex, bbot;
18373 + struct inode *hi;
18374 + struct dentry *iwhdentry;
18376 + bbot = au_ibbot(inode);
18377 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18378 + hi = au_h_iptr(inode, bindex);
18382 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18383 + iwhdentry = au_hi_wh(inode, bindex);
18387 + au_set_h_iptr(inode, bindex, NULL, 0);
18388 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18389 + flags & ~AuHi_XINO);
18392 + /* inode_unlock(hi); */
18396 +/* ---------------------------------------------------------------------- */
18398 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18401 + aufs_bindex_t bindex, bbot, bfound, btop;
18402 + struct inode *h_i;
18405 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18406 + pr_warn("branch root dir was changed\n");
18411 + bbot = au_ibbot(inode);
18412 + btop = au_ibtop(inode);
18413 +#if 0 /* reserved for future use */
18414 + if (bindex == bbot) {
18415 + /* keep this ino in rename case */
18419 + for (bindex = btop; bindex <= bbot; bindex++)
18420 + if (au_h_iptr(inode, bindex) == h_inode) {
18427 + for (bindex = btop; bindex <= bbot; bindex++) {
18428 + h_i = au_h_iptr(inode, bindex);
18432 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18433 + /* ignore this error */
18434 + /* bad action? */
18437 + /* children inode number will be broken */
18444 +static int hn_gen_tree(struct dentry *dentry)
18446 + int err, i, j, ndentry;
18447 + struct au_dcsub_pages dpages;
18448 + struct au_dpage *dpage;
18449 + struct dentry **dentries;
18451 + err = au_dpages_init(&dpages, GFP_NOFS);
18452 + if (unlikely(err))
18454 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18455 + if (unlikely(err))
18458 + for (i = 0; i < dpages.ndpage; i++) {
18459 + dpage = dpages.dpages + i;
18460 + dentries = dpage->dentries;
18461 + ndentry = dpage->ndentry;
18462 + for (j = 0; j < ndentry; j++) {
18463 + struct dentry *d;
18470 + if (d_really_is_positive(d))
18471 + /* todo: reset children xino?
18472 + cached children only? */
18473 + au_iigen_dec(d_inode(d));
18478 + au_dpages_free(&dpages);
18484 + * return 0 if processed.
18486 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18487 + const unsigned int isdir)
18490 + struct dentry *d;
18491 + struct qstr *dname;
18494 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18495 + pr_warn("branch root dir was changed\n");
18501 + AuDebugOn(!name);
18502 + au_iigen_dec(inode);
18503 + spin_lock(&inode->i_lock);
18504 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18505 + spin_lock(&d->d_lock);
18506 + dname = &d->d_name;
18507 + if (dname->len != nlen
18508 + && memcmp(dname->name, name, nlen)) {
18509 + spin_unlock(&d->d_lock);
18514 + spin_unlock(&d->d_lock);
18517 + spin_unlock(&inode->i_lock);
18519 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18520 + d = d_find_any_alias(inode);
18522 + au_iigen_dec(inode);
18526 + spin_lock(&d->d_lock);
18527 + dname = &d->d_name;
18528 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18529 + spin_unlock(&d->d_lock);
18530 + err = hn_gen_tree(d);
18531 + spin_lock(&d->d_lock);
18533 + spin_unlock(&d->d_lock);
18542 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18546 + if (IS_ROOT(dentry)) {
18547 + pr_warn("branch root dir was changed\n");
18553 + au_digen_dec(dentry);
18554 + if (d_really_is_positive(dentry))
18555 + au_iigen_dec(d_inode(dentry));
18557 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18558 + if (d_really_is_positive(dentry))
18559 + err = hn_gen_tree(dentry);
18566 +/* ---------------------------------------------------------------------- */
18568 +/* hnotify job flags */
18569 +#define AuHnJob_XINO0 BIT(0)
18570 +#define AuHnJob_GEN BIT(1)
18571 +#define AuHnJob_DIRENT BIT(2)
18572 +#define AuHnJob_ISDIR BIT(3)
18573 +#define AuHnJob_TRYXINO0 BIT(4)
18574 +#define AuHnJob_MNTPNT BIT(5)
18575 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18576 +#define au_fset_hnjob(flags, name) \
18577 + do { (flags) |= AuHnJob_##name; } while (0)
18578 +#define au_fclr_hnjob(flags, name) \
18579 + do { (flags) &= ~AuHnJob_##name; } while (0)
18587 +struct au_hnotify_args {
18588 + struct inode *h_dir, *dir, *h_child_inode;
18590 + unsigned int flags[AuHnLast];
18591 + unsigned int h_child_nlen;
18592 + char h_child_name[];
18595 +struct hn_job_args {
18596 + unsigned int flags;
18597 + struct inode *inode, *h_inode, *dir, *h_dir;
18598 + struct dentry *dentry;
18603 +static int hn_job(struct hn_job_args *a)
18605 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18609 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18610 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18612 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18615 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18616 + if (!a->h_inode->i_nlink
18617 + && !(a->h_inode->i_state & I_LINKABLE))
18618 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18619 + inode_unlock_shared(a->h_inode);
18622 + /* make the generation obsolete */
18623 + if (au_ftest_hnjob(a->flags, GEN)) {
18626 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18628 + if (e && a->dentry)
18629 + hn_gen_by_name(a->dentry, isdir);
18630 + /* ignore this error */
18633 + /* make dir entries obsolete */
18634 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18635 + struct au_vdir *vdir;
18637 + vdir = au_ivdir(a->inode);
18639 + vdir->vd_jiffy = 0;
18640 + /* IMustLock(a->inode); */
18641 + /* inode_inc_iversion(a->inode); */
18644 + /* can do nothing but warn */
18645 + if (au_ftest_hnjob(a->flags, MNTPNT)
18647 + && d_mountpoint(a->dentry))
18648 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18653 +/* ---------------------------------------------------------------------- */
18655 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18656 + struct inode *dir)
18658 + struct dentry *dentry, *d, *parent;
18659 + struct qstr *dname;
18661 + parent = d_find_any_alias(dir);
18666 + spin_lock(&parent->d_lock);
18667 + hlist_for_each_entry(d, &parent->d_children, d_sib) {
18668 + /* AuDbg("%pd\n", d); */
18669 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18670 + dname = &d->d_name;
18671 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18672 + goto cont_unlock;
18676 + goto cont_unlock;
18677 + if (au_dcount(d) > 0) {
18678 + dentry = dget_dlock(d);
18679 + spin_unlock(&d->d_lock);
18684 + spin_unlock(&d->d_lock);
18686 + spin_unlock(&parent->d_lock);
18690 + di_write_lock_child(dentry);
18695 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18696 + aufs_bindex_t bindex, ino_t h_ino)
18698 + struct inode *inode;
18703 + err = au_xino_read(sb, bindex, h_ino, &ino);
18705 + inode = ilookup(sb, ino);
18709 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18710 + pr_warn("wrong root branch\n");
18716 + ii_write_lock_child(inode);
18722 +static void au_hn_bh(void *_args)
18724 + struct au_hnotify_args *a = _args;
18725 + struct super_block *sb;
18726 + aufs_bindex_t bindex, bbot, bfound;
18727 + unsigned char xino, try_iput;
18729 + struct inode *inode;
18731 + struct hn_job_args args;
18732 + struct dentry *dentry;
18733 + struct au_sbinfo *sbinfo;
18735 + AuDebugOn(!_args);
18736 + AuDebugOn(!a->h_dir);
18737 + AuDebugOn(!a->dir);
18738 + AuDebugOn(!a->mask);
18739 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18740 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18741 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18746 + * do not lock a->dir->i_mutex here
18747 + * because of d_revalidate() may cause a deadlock.
18749 + sb = a->dir->i_sb;
18751 + sbinfo = au_sbi(sb);
18752 + AuDebugOn(!sbinfo);
18753 + si_write_lock(sb, AuLock_NOPLMW);
18755 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18756 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18757 + case FS_MOVED_FROM:
18758 + case FS_MOVED_TO:
18759 + AuWarn1("DIRREN with UDBA may not work correctly "
18760 + "for the direct rename(2)\n");
18763 + ii_read_lock_parent(a->dir);
18765 + bbot = au_ibbot(a->dir);
18766 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18767 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18771 + ii_read_unlock(a->dir);
18772 + if (unlikely(bfound < 0))
18775 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18777 + if (a->h_child_inode)
18778 + h_ino = a->h_child_inode->i_ino;
18780 + if (a->h_child_nlen
18781 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18782 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18783 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18786 + if (dentry && d_really_is_positive(dentry))
18787 + inode = d_inode(dentry);
18788 + if (xino && !inode && h_ino
18789 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18790 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18791 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18792 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18796 + args.flags = a->flags[AuHn_CHILD];
18797 + args.dentry = dentry;
18798 + args.inode = inode;
18799 + args.h_inode = a->h_child_inode;
18800 + args.dir = a->dir;
18801 + args.h_dir = a->h_dir;
18802 + args.h_name = a->h_child_name;
18803 + args.h_nlen = a->h_child_nlen;
18804 + err = hn_job(&args);
18806 + if (au_di(dentry))
18807 + di_write_unlock(dentry);
18810 + if (inode && try_iput) {
18811 + ii_write_unlock(inode);
18815 + ii_write_lock_parent(a->dir);
18816 + args.flags = a->flags[AuHn_PARENT];
18817 + args.dentry = NULL;
18818 + args.inode = a->dir;
18819 + args.h_inode = a->h_dir;
18821 + args.h_dir = NULL;
18822 + args.h_name = NULL;
18824 + err = hn_job(&args);
18825 + ii_write_unlock(a->dir);
18828 + iput(a->h_child_inode);
18831 + si_write_unlock(sb);
18832 + au_nwt_done(&sbinfo->si_nowait);
18836 +/* ---------------------------------------------------------------------- */
18838 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18839 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18842 + unsigned int flags[AuHnLast], f;
18843 + unsigned char isdir, isroot, wh;
18844 + struct inode *dir;
18845 + struct au_hnotify_args *args;
18846 + char *p, *h_child_name;
18849 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18850 + dir = igrab(hnotify->hn_aufs_inode);
18854 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18856 + h_child_name = (void *)h_child_qstr->name;
18857 + len = h_child_qstr->len;
18858 + if (h_child_name) {
18859 + if (len > AUFS_WH_PFX_LEN
18860 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18861 + h_child_name += AUFS_WH_PFX_LEN;
18862 + len -= AUFS_WH_PFX_LEN;
18868 + if (h_child_inode)
18869 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18870 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18871 + flags[AuHn_CHILD] = 0;
18873 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18874 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18875 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18876 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18877 + case FS_MOVED_FROM:
18878 + case FS_MOVED_TO:
18879 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18880 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18883 + AuDebugOn(!h_child_name);
18888 + * aufs never be able to get this child inode.
18889 + * revalidation should be in d_revalidate()
18890 + * by checking i_nlink, i_generation or d_unhashed().
18892 + AuDebugOn(!h_child_name);
18893 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18894 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18902 + h_child_inode = NULL;
18905 + /* iput() and kfree() will be called in au_hnotify() */
18906 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18907 + if (unlikely(!args)) {
18908 + AuErr1("no memory\n");
18912 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18913 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18914 + args->mask = mask;
18916 + args->h_dir = igrab(h_dir);
18917 + if (h_child_inode)
18918 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18919 + args->h_child_inode = h_child_inode;
18920 + args->h_child_nlen = len;
18922 + p = (void *)args;
18923 + p += sizeof(*args);
18924 + memcpy(p, h_child_name, len);
18928 + /* NFS fires the event for silly-renamed one from kworker */
18930 + if (!dir->i_nlink
18931 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18933 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18934 + if (unlikely(err)) {
18935 + pr_err("wkq %d\n", err);
18936 + iput(args->h_child_inode);
18937 + iput(args->h_dir);
18939 + au_kfree_rcu(args);
18946 +/* ---------------------------------------------------------------------- */
18948 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18952 + AuDebugOn(!(udba & AuOptMask_UDBA));
18955 + if (au_hnotify_op.reset_br)
18956 + err = au_hnotify_op.reset_br(udba, br, perm);
18961 +int au_hnotify_init_br(struct au_branch *br, int perm)
18966 + if (au_hnotify_op.init_br)
18967 + err = au_hnotify_op.init_br(br, perm);
18972 +void au_hnotify_fin_br(struct au_branch *br)
18974 + if (au_hnotify_op.fin_br)
18975 + au_hnotify_op.fin_br(br);
18978 +static void au_hn_destroy_cache(void)
18980 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18981 + au_cache[AuCache_HNOTIFY] = NULL;
18984 +int __init au_hnotify_init(void)
18989 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18990 + if (au_cache[AuCache_HNOTIFY]) {
18992 + if (au_hnotify_op.init)
18993 + err = au_hnotify_op.init();
18994 + if (unlikely(err))
18995 + au_hn_destroy_cache();
19001 +void au_hnotify_fin(void)
19003 + if (au_hnotify_op.fin)
19004 + au_hnotify_op.fin();
19006 + /* cf. au_cache_fin() */
19007 + if (au_cache[AuCache_HNOTIFY])
19008 + au_hn_destroy_cache();
19010 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
19011 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
19012 +++ linux/fs/aufs/iinfo.c 2024-05-13 17:13:00.621404284 +0200
19014 +// SPDX-License-Identifier: GPL-2.0
19016 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19018 + * This program is free software; you can redistribute it and/or modify
19019 + * it under the terms of the GNU General Public License as published by
19020 + * the Free Software Foundation; either version 2 of the License, or
19021 + * (at your option) any later version.
19023 + * This program is distributed in the hope that it will be useful,
19024 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19025 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19026 + * GNU General Public License for more details.
19028 + * You should have received a copy of the GNU General Public License
19029 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19033 + * inode private data
19038 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19040 + struct inode *h_inode;
19041 + struct au_hinode *hinode;
19043 + IiMustAnyLock(inode);
19045 + hinode = au_hinode(au_ii(inode), bindex);
19046 + h_inode = hinode->hi_inode;
19047 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19051 +/* todo: hard/soft set? */
19052 +void au_hiput(struct au_hinode *hinode)
19054 + au_hn_free(hinode);
19055 + dput(hinode->hi_whdentry);
19056 + iput(hinode->hi_inode);
19059 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19061 + unsigned int flags;
19062 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19065 + if (au_opt_test(mnt_flags, XINO))
19066 + au_fset_hi(flags, XINO);
19067 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19068 + au_fset_hi(flags, HNOTIFY);
19072 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19073 + struct inode *h_inode, unsigned int flags)
19075 + struct au_hinode *hinode;
19076 + struct inode *hi;
19077 + struct au_iinfo *iinfo = au_ii(inode);
19079 + IiMustWriteLock(inode);
19081 + hinode = au_hinode(iinfo, bindex);
19082 + hi = hinode->hi_inode;
19083 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19086 + au_hiput(hinode);
19087 + hinode->hi_inode = h_inode;
19090 + struct super_block *sb = inode->i_sb;
19091 + struct au_branch *br;
19093 + AuDebugOn(inode->i_mode
19094 + && (h_inode->i_mode & S_IFMT)
19095 + != (inode->i_mode & S_IFMT));
19096 + if (bindex == iinfo->ii_btop)
19097 + au_cpup_igen(inode, h_inode);
19098 + br = au_sbr(sb, bindex);
19099 + hinode->hi_id = br->br_id;
19100 + if (au_ftest_hi(flags, XINO)) {
19101 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19103 + if (unlikely(err))
19104 + AuIOErr1("failed au_xino_write() %d\n", err);
19107 + if (au_ftest_hi(flags, HNOTIFY)
19108 + && au_br_hnotifyable(br->br_perm)) {
19109 + err = au_hn_alloc(hinode, inode);
19110 + if (unlikely(err))
19111 + AuIOErr1("au_hn_alloc() %d\n", err);
19116 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19117 + struct dentry *h_wh)
19119 + struct au_hinode *hinode;
19121 + IiMustWriteLock(inode);
19123 + hinode = au_hinode(au_ii(inode), bindex);
19124 + AuDebugOn(hinode->hi_whdentry);
19125 + hinode->hi_whdentry = h_wh;
19128 +void au_update_iigen(struct inode *inode, int half)
19130 + struct au_iinfo *iinfo;
19131 + struct au_iigen *iigen;
19132 + unsigned int sigen;
19134 + sigen = au_sigen(inode->i_sb);
19135 + iinfo = au_ii(inode);
19136 + iigen = &iinfo->ii_generation;
19137 + spin_lock(&iigen->ig_spin);
19138 + iigen->ig_generation = sigen;
19140 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19142 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19143 + spin_unlock(&iigen->ig_spin);
19146 +/* it may be called at remount time, too */
19147 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19149 + struct au_iinfo *iinfo;
19150 + aufs_bindex_t bindex, bbot;
19152 + AuDebugOn(au_is_bad_inode(inode));
19153 + IiMustWriteLock(inode);
19155 + iinfo = au_ii(inode);
19156 + if (do_put_zero && iinfo->ii_btop >= 0) {
19157 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19159 + struct inode *h_i;
19161 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19164 + && !(h_i->i_state & I_LINKABLE))
19165 + au_set_h_iptr(inode, bindex, NULL, 0);
19169 + iinfo->ii_btop = -1;
19170 + iinfo->ii_bbot = -1;
19171 + bbot = au_sbbot(inode->i_sb);
19172 + for (bindex = 0; bindex <= bbot; bindex++)
19173 + if (au_hinode(iinfo, bindex)->hi_inode) {
19174 + iinfo->ii_btop = bindex;
19177 + if (iinfo->ii_btop >= 0)
19178 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19179 + if (au_hinode(iinfo, bindex)->hi_inode) {
19180 + iinfo->ii_bbot = bindex;
19183 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19186 +/* ---------------------------------------------------------------------- */
19188 +void au_icntnr_init_once(void *_c)
19190 + struct au_icntnr *c = _c;
19191 + struct au_iinfo *iinfo = &c->iinfo;
19193 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19194 + au_rw_init(&iinfo->ii_rwsem);
19195 + inode_init_once(&c->vfs_inode);
19198 +void au_hinode_init(struct au_hinode *hinode)
19200 + hinode->hi_inode = NULL;
19201 + hinode->hi_id = -1;
19202 + au_hn_init(hinode);
19203 + hinode->hi_whdentry = NULL;
19206 +int au_iinfo_init(struct inode *inode)
19208 + struct au_iinfo *iinfo;
19209 + struct super_block *sb;
19210 + struct au_hinode *hi;
19213 + sb = inode->i_sb;
19214 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19215 + nbr = au_sbbot(sb) + 1;
19216 + if (unlikely(nbr <= 0))
19218 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19220 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19222 + iinfo->ii_hinode = hi;
19223 + for (i = 0; i < nbr; i++, hi++)
19224 + au_hinode_init(hi);
19226 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19227 + iinfo->ii_btop = -1;
19228 + iinfo->ii_bbot = -1;
19229 + iinfo->ii_vdir = NULL;
19235 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19238 + struct au_hinode *hip;
19240 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19243 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19246 + iinfo->ii_hinode = hip;
19247 + i = iinfo->ii_bbot + 1;
19249 + for (; i < nbr; i++, hip++)
19250 + au_hinode_init(hip);
19257 +void au_iinfo_fin(struct inode *inode)
19259 + struct au_iinfo *iinfo;
19260 + struct au_hinode *hi;
19261 + struct super_block *sb;
19262 + aufs_bindex_t bindex, bbot;
19263 + const unsigned char unlinked = !inode->i_nlink;
19265 + AuDebugOn(au_is_bad_inode(inode));
19267 + sb = inode->i_sb;
19268 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19269 + if (si_pid_test(sb))
19270 + au_xino_delete_inode(inode, unlinked);
19273 + * it is safe to hide the dependency between sbinfo and
19277 + si_noflush_read_lock(sb);
19278 + au_xino_delete_inode(inode, unlinked);
19279 + si_read_unlock(sb);
19283 + iinfo = au_ii(inode);
19284 + if (iinfo->ii_vdir)
19285 + au_vdir_free(iinfo->ii_vdir);
19287 + bindex = iinfo->ii_btop;
19288 + if (bindex >= 0) {
19289 + hi = au_hinode(iinfo, bindex);
19290 + bbot = iinfo->ii_bbot;
19291 + while (bindex++ <= bbot) {
19292 + if (hi->hi_inode)
19297 + au_kfree_rcu(iinfo->ii_hinode);
19298 + AuRwDestroy(&iinfo->ii_rwsem);
19300 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19301 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19302 +++ linux/fs/aufs/inode.c 2024-05-13 17:13:00.621404284 +0200
19304 +// SPDX-License-Identifier: GPL-2.0
19306 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19308 + * This program is free software; you can redistribute it and/or modify
19309 + * it under the terms of the GNU General Public License as published by
19310 + * the Free Software Foundation; either version 2 of the License, or
19311 + * (at your option) any later version.
19313 + * This program is distributed in the hope that it will be useful,
19314 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19315 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19316 + * GNU General Public License for more details.
19318 + * You should have received a copy of the GNU General Public License
19319 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19323 + * inode functions
19326 +#include <linux/iversion.h>
19329 +struct inode *au_igrab(struct inode *inode)
19332 + AuDebugOn(!atomic_read(&inode->i_count));
19338 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19340 + au_cpup_attr_all(inode, /*force*/0);
19341 + au_update_iigen(inode, /*half*/1);
19343 + inode_inc_iversion(inode);
19346 +static int au_ii_refresh(struct inode *inode, int *update)
19350 + aufs_bindex_t bindex, new_bindex;
19351 + struct super_block *sb;
19352 + struct au_iinfo *iinfo;
19353 + struct au_hinode *p, *q, tmp;
19355 + AuDebugOn(au_is_bad_inode(inode));
19356 + IiMustWriteLock(inode);
19359 + sb = inode->i_sb;
19360 + nbr = au_sbbot(sb) + 1;
19361 + type = inode->i_mode & S_IFMT;
19362 + iinfo = au_ii(inode);
19363 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19364 + if (unlikely(err))
19367 + AuDebugOn(iinfo->ii_btop < 0);
19368 + p = au_hinode(iinfo, iinfo->ii_btop);
19369 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19371 + if (!p->hi_inode)
19374 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19375 + new_bindex = au_br_index(sb, p->hi_id);
19376 + if (new_bindex == bindex)
19379 + if (new_bindex < 0) {
19382 + p->hi_inode = NULL;
19386 + if (new_bindex < iinfo->ii_btop)
19387 + iinfo->ii_btop = new_bindex;
19388 + if (iinfo->ii_bbot < new_bindex)
19389 + iinfo->ii_bbot = new_bindex;
19390 + /* swap two lower inode, and loop again */
19391 + q = au_hinode(iinfo, new_bindex);
19395 + if (tmp.hi_inode) {
19400 + au_update_ibrange(inode, /*do_put_zero*/0);
19401 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19402 + e = au_dy_irefresh(inode);
19403 + if (unlikely(e && !err))
19411 +void au_refresh_iop(struct inode *inode, int force_getattr)
19414 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19415 + const struct inode_operations *iop
19416 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19418 + if (inode->i_op == iop)
19421 + switch (inode->i_mode & S_IFMT) {
19423 + type = AuIop_DIR;
19426 + type = AuIop_SYMLINK;
19429 + type = AuIop_OTHER;
19433 + inode->i_op = iop + type;
19434 + /* unnecessary smp_wmb() */
19437 +int au_refresh_hinode_self(struct inode *inode)
19441 + err = au_ii_refresh(inode, &update);
19443 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19449 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19451 + int err, e, update;
19452 + unsigned int flags;
19454 + aufs_bindex_t bindex, bbot;
19455 + unsigned char isdir;
19456 + struct au_hinode *p;
19457 + struct au_iinfo *iinfo;
19459 + err = au_ii_refresh(inode, &update);
19460 + if (unlikely(err))
19464 + iinfo = au_ii(inode);
19465 + p = au_hinode(iinfo, iinfo->ii_btop);
19466 + mode = (inode->i_mode & S_IFMT);
19467 + isdir = S_ISDIR(mode);
19468 + flags = au_hi_flags(inode, isdir);
19469 + bbot = au_dbbot(dentry);
19470 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19471 + struct inode *h_i, *h_inode;
19472 + struct dentry *h_d;
19474 + h_d = au_h_dptr(dentry, bindex);
19475 + if (!h_d || d_is_negative(h_d))
19478 + h_inode = d_inode(h_d);
19479 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19480 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19481 + h_i = au_h_iptr(inode, bindex);
19483 + if (h_i == h_inode)
19489 + if (bindex < iinfo->ii_btop)
19490 + iinfo->ii_btop = bindex;
19491 + if (iinfo->ii_bbot < bindex)
19492 + iinfo->ii_bbot = bindex;
19493 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19496 + au_update_ibrange(inode, /*do_put_zero*/0);
19497 + e = au_dy_irefresh(inode);
19498 + if (unlikely(e && !err))
19501 + au_refresh_hinode_attr(inode, update && isdir);
19508 +static int set_inode(struct inode *inode, struct dentry *dentry)
19511 + unsigned int flags;
19513 + aufs_bindex_t bindex, btop, btail;
19514 + unsigned char isdir;
19515 + struct dentry *h_dentry;
19516 + struct inode *h_inode;
19517 + struct au_iinfo *iinfo;
19518 + const struct inode_operations *iop;
19520 + IiMustWriteLock(inode);
19524 + iop = au_sbi(inode->i_sb)->si_iop_array;
19525 + btop = au_dbtop(dentry);
19526 + h_dentry = au_h_dptr(dentry, btop);
19527 + h_inode = d_inode(h_dentry);
19528 + mode = h_inode->i_mode;
19529 + switch (mode & S_IFMT) {
19531 + btail = au_dbtail(dentry);
19532 + inode->i_op = iop + AuIop_OTHER;
19533 + inode->i_fop = &aufs_file_fop;
19534 + err = au_dy_iaop(inode, btop, h_inode);
19535 + if (unlikely(err))
19540 + btail = au_dbtaildir(dentry);
19541 + inode->i_op = iop + AuIop_DIR;
19542 + inode->i_fop = &aufs_dir_fop;
19545 + btail = au_dbtail(dentry);
19546 + inode->i_op = iop + AuIop_SYMLINK;
19552 + btail = au_dbtail(dentry);
19553 + inode->i_op = iop + AuIop_OTHER;
19554 + init_special_inode(inode, mode, h_inode->i_rdev);
19557 + AuIOErr("Unknown file type 0%o\n", mode);
19562 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19563 + flags = au_hi_flags(inode, isdir);
19564 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19565 + && au_ftest_hi(flags, HNOTIFY)
19566 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19567 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19568 + au_fclr_hi(flags, HNOTIFY);
19569 + iinfo = au_ii(inode);
19570 + iinfo->ii_btop = btop;
19571 + iinfo->ii_bbot = btail;
19572 + for (bindex = btop; bindex <= btail; bindex++) {
19573 + h_dentry = au_h_dptr(dentry, bindex);
19575 + au_set_h_iptr(inode, bindex,
19576 + au_igrab(d_inode(h_dentry)), flags);
19578 + au_cpup_attr_all(inode, /*force*/1);
19580 + * to force calling aufs_get_inode_acl() every time,
19581 + * do not call cache_no_acl() for aufs inode.
19589 + * successful returns with iinfo write_locked
19591 + * zero: success, matched
19592 + * plus: no error, but unmatched
19594 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19597 + unsigned int gen, igflags;
19598 + aufs_bindex_t bindex, bbot;
19599 + struct inode *h_inode, *h_dinode;
19600 + struct dentry *h_dentry;
19603 + * before this function, if aufs got any iinfo lock, it must be only
19604 + * one, the parent dir.
19605 + * it can happen by UDBA and the obsoleted inode number.
19608 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19612 + ii_write_lock_new_child(inode);
19613 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19614 + h_dinode = d_inode(h_dentry);
19615 + bbot = au_ibbot(inode);
19616 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19617 + h_inode = au_h_iptr(inode, bindex);
19618 + if (!h_inode || h_inode != h_dinode)
19622 + gen = au_iigen(inode, &igflags);
19623 + if (gen == au_digen(dentry)
19624 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19627 + /* fully refresh inode using dentry */
19628 + err = au_refresh_hinode(inode, dentry);
19630 + au_update_iigen(inode, /*half*/0);
19634 + if (unlikely(err))
19635 + ii_write_unlock(inode);
19640 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19641 + unsigned int d_type, ino_t *ino)
19644 + const int isnondir = d_type != DT_DIR;
19646 + /* prevent hardlinked inode number from race condition */
19648 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19649 + if (unlikely(err))
19653 + err = au_xino_read(sb, bindex, h_ino, ino);
19654 + if (unlikely(err))
19655 + goto out_xinondir;
19659 + *ino = au_xino_new_ino(sb);
19660 + if (unlikely(!*ino))
19661 + goto out_xinondir;
19662 + err = au_xino_write(sb, bindex, h_ino, *ino);
19663 + if (unlikely(err))
19664 + goto out_xinondir;
19668 + if (isnondir && idx >= 0)
19669 + au_xinondir_leave(sb, bindex, h_ino, idx);
19674 +/* successful returns with iinfo write_locked */
19675 +/* todo: return with unlocked? */
19676 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19678 + struct inode *inode, *h_inode;
19679 + struct dentry *h_dentry;
19680 + struct super_block *sb;
19681 + ino_t h_ino, ino;
19682 + int err, idx, hlinked;
19683 + aufs_bindex_t btop;
19685 + sb = dentry->d_sb;
19686 + btop = au_dbtop(dentry);
19687 + h_dentry = au_h_dptr(dentry, btop);
19688 + h_inode = d_inode(h_dentry);
19689 + h_ino = h_inode->i_ino;
19690 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19694 + * stop 'race'-ing between hardlinks under different
19698 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19699 + inode = ERR_PTR(err);
19700 + if (unlikely(err))
19704 + err = au_xino_read(sb, btop, h_ino, &ino);
19705 + inode = ERR_PTR(err);
19706 + if (unlikely(err))
19707 + goto out_xinondir;
19710 + ino = au_xino_new_ino(sb);
19711 + if (unlikely(!ino)) {
19712 + inode = ERR_PTR(-EIO);
19713 + goto out_xinondir;
19717 + AuDbg("i%lu\n", (unsigned long)ino);
19718 + inode = au_iget_locked(sb, ino);
19719 + err = PTR_ERR(inode);
19720 + if (IS_ERR(inode))
19721 + goto out_xinondir;
19723 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19724 + if (inode->i_state & I_NEW) {
19725 + ii_write_lock_new_child(inode);
19726 + err = set_inode(inode, dentry);
19728 + unlock_new_inode(inode);
19729 + goto out_xinondir; /* success */
19733 + * iget_failed() calls iput(), but we need to call
19734 + * ii_write_unlock() after iget_failed(). so dirty hack for
19737 + atomic_inc(&inode->i_count);
19738 + iget_failed(inode);
19739 + ii_write_unlock(inode);
19740 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19741 + /* ignore this error */
19743 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19745 + * horrible race condition between lookup, readdir and copyup
19746 + * (or something).
19748 + if (hlinked && idx >= 0)
19749 + au_xinondir_leave(sb, btop, h_ino, idx);
19750 + err = reval_inode(inode, dentry);
19751 + if (unlikely(err < 0)) {
19756 + goto out; /* success */
19757 + else if (hlinked && idx >= 0) {
19758 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19759 + if (unlikely(err)) {
19761 + inode = ERR_PTR(err);
19767 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19768 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19769 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19770 + btop, au_sbtype(h_dentry->d_sb), dentry,
19771 + (unsigned long)h_ino, (unsigned long)ino);
19773 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19776 + if (hlinked && idx >= 0)
19777 + au_xinondir_leave(sb, btop, h_ino, idx);
19783 + inode = ERR_PTR(err);
19785 + if (hlinked && idx >= 0)
19786 + au_xinondir_leave(sb, btop, h_ino, idx);
19791 +/* ---------------------------------------------------------------------- */
19793 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19794 + struct inode *inode)
19797 + struct inode *hi;
19799 + err = au_br_rdonly(au_sbr(sb, bindex));
19801 + /* pseudo-link after flushed may happen out of bounds */
19804 + && au_ibtop(inode) <= bindex
19805 + && bindex <= au_ibbot(inode)) {
19807 + * permission check is unnecessary since vfsub routine
19808 + * will be called later
19810 + hi = au_h_iptr(inode, bindex);
19812 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19818 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19821 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19823 + return inode_permission(h_idmap, h_inode, mask);
19826 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19829 + if (au_test_nfs(h_inode->i_sb)
19830 + && (mask & MAY_WRITE)
19831 + && S_ISDIR(h_inode->i_mode))
19832 + mask |= MAY_READ; /* force permission check */
19833 + return au_test_h_perm(h_idmap, h_inode, mask);
19835 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19836 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19837 +++ linux/fs/aufs/inode.h 2024-05-13 17:13:00.621404284 +0200
19839 +/* SPDX-License-Identifier: GPL-2.0 */
19841 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19843 + * This program is free software; you can redistribute it and/or modify
19844 + * it under the terms of the GNU General Public License as published by
19845 + * the Free Software Foundation; either version 2 of the License, or
19846 + * (at your option) any later version.
19848 + * This program is distributed in the hope that it will be useful,
19849 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19850 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19851 + * GNU General Public License for more details.
19853 + * You should have received a copy of the GNU General Public License
19854 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19858 + * inode operations
19861 +#ifndef __AUFS_INODE_H__
19862 +#define __AUFS_INODE_H__
19866 +#include <linux/fsnotify.h>
19867 +#include "rwsem.h"
19871 +struct au_hnotify {
19872 +#ifdef CONFIG_AUFS_HNOTIFY
19873 +#ifdef CONFIG_AUFS_HFSNOTIFY
19874 + /* never use fsnotify_add_vfsmount_mark() */
19875 + struct fsnotify_mark hn_mark;
19877 + struct inode *hn_aufs_inode; /* no get/put */
19878 + struct rcu_head rcu;
19880 +} ____cacheline_aligned_in_smp;
19882 +struct au_hinode {
19883 + struct inode *hi_inode;
19884 + aufs_bindex_t hi_id;
19885 +#ifdef CONFIG_AUFS_HNOTIFY
19886 + struct au_hnotify *hi_notify;
19889 + /* reference to the copied-up whiteout with get/put */
19890 + struct dentry *hi_whdentry;
19894 +#define AuIG_HALF_REFRESHED 1
19895 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19896 +#define au_ig_fset(flags, name) \
19897 + do { (flags) |= AuIG_##name; } while (0)
19898 +#define au_ig_fclr(flags, name) \
19899 + do { (flags) &= ~AuIG_##name; } while (0)
19902 + spinlock_t ig_spin;
19903 + __u32 ig_generation, ig_flags;
19908 + struct au_iigen ii_generation;
19909 + struct super_block *ii_hsb1; /* no get/put */
19911 + struct au_rwsem ii_rwsem;
19912 + aufs_bindex_t ii_btop, ii_bbot;
19914 + struct au_hinode *ii_hinode;
19915 + struct au_vdir *ii_vdir;
19918 +struct au_icntnr {
19919 + struct au_iinfo iinfo;
19920 + struct inode vfs_inode;
19921 + struct hlist_bl_node plink;
19922 + struct rcu_head rcu;
19923 +} ____cacheline_aligned_in_smp;
19925 +/* au_pin flags */
19926 +#define AuPin_DI_LOCKED BIT(0)
19927 +#define AuPin_MNT_WRITE BIT(1)
19928 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19929 +#define au_fset_pin(flags, name) \
19930 + do { (flags) |= AuPin_##name; } while (0)
19931 +#define au_fclr_pin(flags, name) \
19932 + do { (flags) &= ~AuPin_##name; } while (0)
19936 + struct dentry *dentry;
19937 + unsigned int udba;
19938 + unsigned char lsc_di, lsc_hi, flags;
19939 + aufs_bindex_t bindex;
19942 + struct dentry *parent;
19943 + struct au_hinode *hdir;
19944 + struct vfsmount *h_mnt;
19946 + /* temporary unlock/relock for copyup */
19947 + struct dentry *h_dentry, *h_parent;
19948 + struct au_branch *br;
19949 + struct task_struct *task;
19952 +void au_pin_hdir_unlock(struct au_pin *p);
19953 +int au_pin_hdir_lock(struct au_pin *p);
19954 +int au_pin_hdir_relock(struct au_pin *p);
19955 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19956 +void au_pin_hdir_release(struct au_pin *p);
19958 +/* ---------------------------------------------------------------------- */
19960 +static inline struct au_iinfo *au_ii(struct inode *inode)
19962 + BUG_ON(is_bad_inode(inode));
19963 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19966 +/* ---------------------------------------------------------------------- */
19969 +struct inode *au_igrab(struct inode *inode);
19970 +void au_refresh_iop(struct inode *inode, int force_getattr);
19971 +int au_refresh_hinode_self(struct inode *inode);
19972 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19973 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19974 + unsigned int d_type, ino_t *ino);
19975 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19976 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19977 + struct inode *inode);
19978 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19980 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19983 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19984 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19986 +#ifdef CONFIG_AUFS_SHWH
19987 + return au_ino(sb, bindex, h_ino, d_type, ino);
20000 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
20001 + aufs_iop_nogetattr[AuIop_Last];
20003 +/* au_wr_dir flags */
20004 +#define AuWrDir_ADD_ENTRY BIT(0)
20005 +#define AuWrDir_ISDIR BIT(1)
20006 +#define AuWrDir_TMPFILE BIT(2)
20007 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
20008 +#define au_fset_wrdir(flags, name) \
20009 + do { (flags) |= AuWrDir_##name; } while (0)
20010 +#define au_fclr_wrdir(flags, name) \
20011 + do { (flags) &= ~AuWrDir_##name; } while (0)
20013 +struct au_wr_dir_args {
20014 + aufs_bindex_t force_btgt;
20015 + unsigned char flags;
20017 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20018 + struct au_wr_dir_args *args);
20020 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
20021 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
20022 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
20023 + unsigned int udba, unsigned char flags);
20024 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
20025 + unsigned int udba, unsigned char flags) __must_check;
20026 +int au_do_pin(struct au_pin *pin) __must_check;
20027 +void au_unpin(struct au_pin *pin);
20028 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20030 +#define AuIcpup_DID_CPUP 1
20031 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20032 +#define au_fset_icpup(flags, name) \
20033 + do { (flags) |= AuIcpup_##name; } while (0)
20034 +#define au_fclr_icpup(flags, name) \
20035 + do { (flags) &= ~AuIcpup_##name; } while (0)
20037 +struct au_icpup_args {
20038 + unsigned char flags;
20039 + unsigned char pin_flags;
20040 + aufs_bindex_t btgt;
20041 + unsigned int udba;
20042 + struct au_pin pin;
20043 + struct path h_path;
20044 + struct inode *h_inode;
20047 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20048 + struct au_icpup_args *a);
20050 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20051 + struct path *h_path, int locked);
20054 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20055 + struct dentry *h_parent, int isdir);
20056 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
20057 + struct dentry *dentry, umode_t mode, dev_t dev);
20058 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
20059 + struct dentry *dentry, const char *symname);
20060 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
20061 + struct dentry *dentry, umode_t mode, bool want_excl);
20062 +struct vfsub_aopen_args;
20063 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20064 + struct vfsub_aopen_args *args);
20065 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
20066 + struct file *file, umode_t mode);
20067 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20068 + struct dentry *dentry);
20069 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
20070 + struct dentry *dentry, umode_t mode);
20073 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20074 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20075 + struct dentry *h_parent, int isdir);
20076 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20077 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20080 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20081 +int aufs_rename(struct mnt_idmap *idmap,
20082 + struct inode *_src_dir, struct dentry *_src_dentry,
20083 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20084 + unsigned int _flags);
20087 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20088 +void au_hiput(struct au_hinode *hinode);
20089 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20090 + struct dentry *h_wh);
20091 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20093 +/* hinode flags */
20094 +#define AuHi_XINO BIT(0)
20095 +#define AuHi_HNOTIFY BIT(1)
20096 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20097 +#define au_fset_hi(flags, name) \
20098 + do { (flags) |= AuHi_##name; } while (0)
20099 +#define au_fclr_hi(flags, name) \
20100 + do { (flags) &= ~AuHi_##name; } while (0)
20102 +#ifndef CONFIG_AUFS_HNOTIFY
20103 +#undef AuHi_HNOTIFY
20104 +#define AuHi_HNOTIFY 0
20107 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20108 + struct inode *h_inode, unsigned int flags);
20110 +void au_update_iigen(struct inode *inode, int half);
20111 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20113 +void au_icntnr_init_once(void *_c);
20114 +void au_hinode_init(struct au_hinode *hinode);
20115 +int au_iinfo_init(struct inode *inode);
20116 +void au_iinfo_fin(struct inode *inode);
20117 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20119 +#ifdef CONFIG_PROC_FS
20121 +int au_plink_maint(struct super_block *sb, int flags);
20123 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20124 +int au_plink_maint_enter(struct super_block *sb);
20125 +#ifdef CONFIG_AUFS_DEBUG
20126 +void au_plink_list(struct super_block *sb);
20128 +AuStubVoid(au_plink_list, struct super_block *sb)
20130 +int au_plink_test(struct inode *inode);
20131 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20132 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20133 + struct dentry *h_dentry);
20134 +void au_plink_put(struct super_block *sb, int verbose);
20135 +void au_plink_clean(struct super_block *sb, int verbose);
20136 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20138 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20139 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20140 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20141 +AuStubVoid(au_plink_list, struct super_block *sb);
20142 +AuStubInt0(au_plink_test, struct inode *inode);
20143 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20144 + struct inode *inode, aufs_bindex_t bindex);
20145 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20146 + struct dentry *h_dentry);
20147 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20148 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20149 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20150 +#endif /* CONFIG_PROC_FS */
20152 +#ifdef CONFIG_AUFS_XATTR
20154 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20155 + unsigned int verbose);
20156 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20157 +void au_xattr_init(struct super_block *sb);
20159 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20160 + int ignore_flags, unsigned int verbose);
20161 +AuStubVoid(au_xattr_init, struct super_block *sb);
20164 +#ifdef CONFIG_FS_POSIX_ACL
20165 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu);
20166 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
20167 + struct dentry *dentry, int type);
20168 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
20169 + struct posix_acl *acl, int type);
20172 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20178 +struct au_sxattr {
20182 + const char *name;
20183 + const void *value;
20188 + struct posix_acl *acl;
20193 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20194 + struct au_sxattr *arg);
20197 +/* ---------------------------------------------------------------------- */
20199 +/* lock subclass for iinfo */
20201 + AuLsc_II_CHILD, /* child first */
20202 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20203 + AuLsc_II_CHILD3, /* copyup dirs */
20204 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20205 + AuLsc_II_PARENT2,
20206 + AuLsc_II_PARENT3, /* copyup dirs */
20207 + AuLsc_II_NEW_CHILD
20211 + * ii_read_lock_child, ii_write_lock_child,
20212 + * ii_read_lock_child2, ii_write_lock_child2,
20213 + * ii_read_lock_child3, ii_write_lock_child3,
20214 + * ii_read_lock_parent, ii_write_lock_parent,
20215 + * ii_read_lock_parent2, ii_write_lock_parent2,
20216 + * ii_read_lock_parent3, ii_write_lock_parent3,
20217 + * ii_read_lock_new_child, ii_write_lock_new_child,
20219 +#define AuReadLockFunc(name, lsc) \
20220 +static inline void ii_read_lock_##name(struct inode *i) \
20222 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20225 +#define AuWriteLockFunc(name, lsc) \
20226 +static inline void ii_write_lock_##name(struct inode *i) \
20228 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20231 +#define AuRWLockFuncs(name, lsc) \
20232 + AuReadLockFunc(name, lsc) \
20233 + AuWriteLockFunc(name, lsc)
20235 +AuRWLockFuncs(child, CHILD);
20236 +AuRWLockFuncs(child2, CHILD2);
20237 +AuRWLockFuncs(child3, CHILD3);
20238 +AuRWLockFuncs(parent, PARENT);
20239 +AuRWLockFuncs(parent2, PARENT2);
20240 +AuRWLockFuncs(parent3, PARENT3);
20241 +AuRWLockFuncs(new_child, NEW_CHILD);
20243 +#undef AuReadLockFunc
20244 +#undef AuWriteLockFunc
20245 +#undef AuRWLockFuncs
20247 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20248 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20249 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20251 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20252 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20253 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20255 +/* ---------------------------------------------------------------------- */
20257 +static inline void au_icntnr_init(struct au_icntnr *c)
20259 +#ifdef CONFIG_AUFS_DEBUG
20260 + c->vfs_inode.i_mode = 0;
20264 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20266 + unsigned int gen;
20267 + struct au_iinfo *iinfo;
20268 + struct au_iigen *iigen;
20270 + iinfo = au_ii(inode);
20271 + iigen = &iinfo->ii_generation;
20272 + spin_lock(&iigen->ig_spin);
20274 + *igflags = iigen->ig_flags;
20275 + gen = iigen->ig_generation;
20276 + spin_unlock(&iigen->ig_spin);
20281 +/* tiny test for inode number */
20282 +/* tmpfs generation is too rough */
20283 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20285 + struct au_iinfo *iinfo;
20287 + iinfo = au_ii(inode);
20288 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20289 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20290 + && iinfo->ii_higen == h_inode->i_generation);
20293 +static inline void au_iigen_dec(struct inode *inode)
20295 + struct au_iinfo *iinfo;
20296 + struct au_iigen *iigen;
20298 + iinfo = au_ii(inode);
20299 + iigen = &iinfo->ii_generation;
20300 + spin_lock(&iigen->ig_spin);
20301 + iigen->ig_generation--;
20302 + spin_unlock(&iigen->ig_spin);
20305 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20310 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20316 +/* ---------------------------------------------------------------------- */
20318 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20319 + aufs_bindex_t bindex)
20321 + return iinfo->ii_hinode + bindex;
20324 +static inline int au_is_bad_inode(struct inode *inode)
20326 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20329 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20330 + aufs_bindex_t bindex)
20332 + IiMustAnyLock(inode);
20333 + return au_hinode(au_ii(inode), bindex)->hi_id;
20336 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20338 + IiMustAnyLock(inode);
20339 + return au_ii(inode)->ii_btop;
20342 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20344 + IiMustAnyLock(inode);
20345 + return au_ii(inode)->ii_bbot;
20348 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20350 + IiMustAnyLock(inode);
20351 + return au_ii(inode)->ii_vdir;
20354 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20356 + IiMustAnyLock(inode);
20357 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20360 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20362 + IiMustWriteLock(inode);
20363 + au_ii(inode)->ii_btop = bindex;
20366 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20368 + IiMustWriteLock(inode);
20369 + au_ii(inode)->ii_bbot = bindex;
20372 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20374 + IiMustWriteLock(inode);
20375 + au_ii(inode)->ii_vdir = vdir;
20378 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20380 + IiMustAnyLock(inode);
20381 + return au_hinode(au_ii(inode), bindex);
20384 +/* ---------------------------------------------------------------------- */
20386 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20389 + return pin->parent;
20393 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20395 + if (pin && pin->hdir)
20396 + return pin->hdir->hi_inode;
20400 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20403 + return pin->hdir;
20407 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20410 + pin->dentry = dentry;
20413 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20414 + unsigned char lflag)
20418 + au_fset_pin(pin->flags, DI_LOCKED);
20420 + au_fclr_pin(pin->flags, DI_LOCKED);
20424 +#if 0 /* reserved */
20425 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20428 + dput(pin->parent);
20429 + pin->parent = dget(parent);
20434 +/* ---------------------------------------------------------------------- */
20437 +#ifdef CONFIG_AUFS_HNOTIFY
20438 +struct au_hnotify_op {
20439 + void (*ctl)(struct au_hinode *hinode, int do_set);
20440 + int (*alloc)(struct au_hinode *hinode);
20443 + * if it returns true, the caller should free hinode->hi_notify,
20444 + * otherwise ->free() frees it.
20446 + int (*free)(struct au_hinode *hinode,
20447 + struct au_hnotify *hn) __must_check;
20449 + void (*fin)(void);
20450 + int (*init)(void);
20452 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20453 + void (*fin_br)(struct au_branch *br);
20454 + int (*init_br)(struct au_branch *br, int perm);
20458 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20459 +void au_hn_free(struct au_hinode *hinode);
20460 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20461 +void au_hn_reset(struct inode *inode, unsigned int flags);
20462 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20463 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20464 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20465 +int au_hnotify_init_br(struct au_branch *br, int perm);
20466 +void au_hnotify_fin_br(struct au_branch *br);
20467 +int __init au_hnotify_init(void);
20468 +void au_hnotify_fin(void);
20471 +extern const struct au_hnotify_op au_hnotify_op;
20474 +void au_hn_init(struct au_hinode *hinode)
20476 + hinode->hi_notify = NULL;
20479 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20481 + return hinode->hi_notify;
20485 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20486 + struct au_hinode *hinode __maybe_unused,
20487 + struct inode *inode __maybe_unused)
20488 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20489 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20490 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20491 + int do_set __maybe_unused)
20492 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20493 + unsigned int flags __maybe_unused)
20494 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20495 + struct au_branch *br __maybe_unused,
20496 + int perm __maybe_unused)
20497 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20498 + int perm __maybe_unused)
20499 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20500 +AuStubInt0(__init au_hnotify_init, void)
20501 +AuStubVoid(au_hnotify_fin, void)
20502 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20503 +#endif /* CONFIG_AUFS_HNOTIFY */
20505 +static inline void au_hn_suspend(struct au_hinode *hdir)
20507 + au_hn_ctl(hdir, /*do_set*/0);
20510 +static inline void au_hn_resume(struct au_hinode *hdir)
20512 + au_hn_ctl(hdir, /*do_set*/1);
20515 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20517 + inode_lock(hdir->hi_inode);
20518 + au_hn_suspend(hdir);
20521 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20522 + unsigned int sc __maybe_unused)
20524 + inode_lock_nested(hdir->hi_inode, sc);
20525 + au_hn_suspend(hdir);
20528 +#if 0 /* unused */
20529 +#include "vfsub.h"
20530 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20533 + inode_lock_shared_nested(hdir->hi_inode, sc);
20534 + au_hn_suspend(hdir);
20538 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20540 + au_hn_resume(hdir);
20541 + inode_unlock(hdir->hi_inode);
20544 +#endif /* __KERNEL__ */
20545 +#endif /* __AUFS_INODE_H__ */
20546 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20547 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20548 +++ linux/fs/aufs/ioctl.c 2024-05-13 17:13:00.621404284 +0200
20550 +// SPDX-License-Identifier: GPL-2.0
20552 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20554 + * This program is free software; you can redistribute it and/or modify
20555 + * it under the terms of the GNU General Public License as published by
20556 + * the Free Software Foundation; either version 2 of the License, or
20557 + * (at your option) any later version.
20559 + * This program is distributed in the hope that it will be useful,
20560 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20561 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20562 + * GNU General Public License for more details.
20564 + * You should have received a copy of the GNU General Public License
20565 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20570 + * plink-management and readdir in userspace.
20571 + * assist the pathconf(3) wrapper library.
20573 + * File-based Hierarchical Storage Management.
20576 +#include <linux/compat.h>
20577 +#include <linux/file.h>
20580 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20583 + aufs_bindex_t wbi, bindex, bbot;
20584 + struct file *h_file;
20585 + struct super_block *sb;
20586 + struct dentry *root;
20587 + struct au_branch *br;
20588 + struct aufs_wbr_fd wbrfd = {
20589 + .oflags = au_dir_roflags,
20592 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20593 + | O_NOATIME | O_CLOEXEC;
20595 + AuDebugOn(wbrfd.oflags & ~valid);
20598 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20599 + if (unlikely(err)) {
20605 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20606 + wbrfd.oflags |= au_dir_roflags;
20607 + AuDbg("0%o\n", wbrfd.oflags);
20608 + if (unlikely(wbrfd.oflags & ~valid))
20612 + fd = get_unused_fd_flags(0);
20614 + if (unlikely(fd < 0))
20617 + h_file = ERR_PTR(-EINVAL);
20620 + sb = path->dentry->d_sb;
20621 + root = sb->s_root;
20622 + aufs_read_lock(root, AuLock_IR);
20623 + bbot = au_sbbot(sb);
20624 + if (wbrfd.brid >= 0) {
20625 + wbi = au_br_index(sb, wbrfd.brid);
20626 + if (unlikely(wbi < 0 || wbi > bbot))
20630 + h_file = ERR_PTR(-ENOENT);
20631 + br = au_sbr(sb, wbi);
20632 + if (!au_br_writable(br->br_perm)) {
20636 + bindex = wbi + 1;
20638 + for (; bindex <= bbot; bindex++) {
20639 + br = au_sbr(sb, bindex);
20640 + if (au_br_writable(br->br_perm)) {
20642 + br = au_sbr(sb, wbi);
20647 + AuDbg("wbi %d\n", wbi);
20649 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20653 + aufs_read_unlock(root, AuLock_IR);
20654 + err = PTR_ERR(h_file);
20655 + if (IS_ERR(h_file))
20658 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20659 + fd_install(fd, h_file);
20661 + goto out; /* success */
20664 + put_unused_fd(fd);
20670 +/* ---------------------------------------------------------------------- */
20672 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20675 + struct dentry *dentry;
20678 + case AUFS_CTL_RDU:
20679 + case AUFS_CTL_RDU_INO:
20680 + err = au_rdu_ioctl(file, cmd, arg);
20683 + case AUFS_CTL_WBR_FD:
20684 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20687 + case AUFS_CTL_IBUSY:
20688 + err = au_ibusy_ioctl(file, arg);
20691 + case AUFS_CTL_BRINFO:
20692 + err = au_brinfo_ioctl(file, arg);
20695 + case AUFS_CTL_FHSM_FD:
20696 + dentry = file->f_path.dentry;
20697 + if (IS_ROOT(dentry))
20698 + err = au_fhsm_fd(dentry->d_sb, arg);
20704 + /* do not call the lower */
20705 + AuDbg("0x%x\n", cmd);
20713 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20718 + case AUFS_CTL_MVDOWN:
20719 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20722 + case AUFS_CTL_WBR_FD:
20723 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20727 + /* do not call the lower */
20728 + AuDbg("0x%x\n", cmd);
20736 +#ifdef CONFIG_COMPAT
20737 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20738 + unsigned long arg)
20743 + case AUFS_CTL_RDU:
20744 + case AUFS_CTL_RDU_INO:
20745 + err = au_rdu_compat_ioctl(file, cmd, arg);
20748 + case AUFS_CTL_IBUSY:
20749 + err = au_ibusy_compat_ioctl(file, arg);
20752 + case AUFS_CTL_BRINFO:
20753 + err = au_brinfo_compat_ioctl(file, arg);
20757 + err = aufs_ioctl_dir(file, cmd, arg);
20764 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20765 + unsigned long arg)
20767 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20770 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20771 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20772 +++ linux/fs/aufs/i_op_add.c 2024-05-13 17:13:00.618070924 +0200
20774 +// SPDX-License-Identifier: GPL-2.0
20776 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20778 + * This program is free software; you can redistribute it and/or modify
20779 + * it under the terms of the GNU General Public License as published by
20780 + * the Free Software Foundation; either version 2 of the License, or
20781 + * (at your option) any later version.
20783 + * This program is distributed in the hope that it will be useful,
20784 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20785 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20786 + * GNU General Public License for more details.
20788 + * You should have received a copy of the GNU General Public License
20789 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20793 + * inode operations (add entry)
20796 +#include <linux/iversion.h>
20800 + * final procedure of adding a new entry, except link(2).
20801 + * remove whiteout, instantiate, copyup the parent dir's times and size
20802 + * and update version.
20803 + * if it failed, re-create the removed whiteout.
20805 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20806 + struct dentry *wh_dentry, struct dentry *dentry)
20809 + aufs_bindex_t bwh;
20810 + struct path h_path;
20811 + struct super_block *sb;
20812 + struct inode *inode, *h_dir;
20813 + struct dentry *wh;
20818 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20819 + IMustLock(h_dir);
20820 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20821 + bwh = au_dbwh(dentry);
20822 + h_path.dentry = wh_dentry;
20823 + h_path.mnt = au_sbr_mnt(sb, bindex);
20824 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20826 + if (unlikely(err))
20830 + inode = au_new_inode(dentry, /*must_new*/1);
20831 + if (!IS_ERR(inode)) {
20832 + d_instantiate(dentry, inode);
20833 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20835 + au_dir_ts(dir, bindex);
20836 + inode_inc_iversion(dir);
20837 + au_fhsm_wrote(sb, bindex, /*force*/0);
20838 + return 0; /* success */
20841 + err = PTR_ERR(inode);
20846 + /* dir inode is locked */
20847 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20848 + rerr = PTR_ERR(wh);
20849 + if (IS_ERR(wh)) {
20850 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20851 + dentry, err, rerr);
20860 +static int au_d_may_add(struct dentry *dentry)
20865 + if (unlikely(d_unhashed(dentry)))
20867 + if (unlikely(d_really_is_positive(dentry)))
20873 + * simple tests for the adding inode operations.
20874 + * following the checks in vfs, plus the parent-child relationship.
20876 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20877 + struct dentry *h_parent, int isdir)
20881 + struct dentry *h_dentry;
20882 + struct inode *h_inode;
20884 + err = -ENAMETOOLONG;
20885 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20888 + h_dentry = au_h_dptr(dentry, bindex);
20889 + if (d_really_is_negative(dentry)) {
20891 + if (unlikely(d_is_positive(h_dentry)))
20894 + /* rename(2) case */
20896 + if (unlikely(d_is_negative(h_dentry)))
20898 + h_inode = d_inode(h_dentry);
20899 + if (unlikely(!h_inode->i_nlink))
20902 + h_mode = h_inode->i_mode;
20905 + if (unlikely(S_ISDIR(h_mode)))
20907 + } else if (unlikely(!S_ISDIR(h_mode))) {
20914 + /* expected parent dir is locked */
20915 + if (unlikely(h_parent != h_dentry->d_parent))
20924 + * initial procedure of adding a new entry.
20925 + * prepare writable branch and the parent dir, lock it,
20926 + * and lookup whiteout for the new entry.
20928 +static struct dentry*
20929 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20930 + struct dentry *src_dentry, struct au_pin *pin,
20931 + struct au_wr_dir_args *wr_dir_args)
20933 + struct dentry *wh_dentry, *h_parent;
20934 + struct super_block *sb;
20935 + struct au_branch *br;
20937 + unsigned int udba;
20938 + aufs_bindex_t bcpup;
20940 + AuDbg("%pd\n", dentry);
20942 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20944 + wh_dentry = ERR_PTR(err);
20945 + if (unlikely(err < 0))
20948 + sb = dentry->d_sb;
20949 + udba = au_opt_udba(sb);
20950 + err = au_pin(pin, dentry, bcpup, udba,
20951 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20952 + wh_dentry = ERR_PTR(err);
20953 + if (unlikely(err))
20956 + h_parent = au_pinned_h_parent(pin);
20957 + if (udba != AuOpt_UDBA_NONE
20958 + && au_dbtop(dentry) == bcpup)
20959 + err = au_may_add(dentry, bcpup, h_parent,
20960 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20961 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20962 + err = -ENAMETOOLONG;
20963 + wh_dentry = ERR_PTR(err);
20964 + if (unlikely(err))
20967 + br = au_sbr(sb, bcpup);
20969 + struct path tmp = {
20970 + .dentry = h_parent,
20971 + .mnt = au_br_mnt(br)
20973 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20976 + wh_dentry = NULL;
20977 + if (bcpup != au_dbwh(dentry))
20978 + goto out; /* success */
20981 + * ENAMETOOLONG here means that if we allowed create such name, then it
20982 + * would not be able to removed in the future. So we don't allow such
20983 + * name here and we don't handle ENAMETOOLONG differently here.
20985 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20988 + if (IS_ERR(wh_dentry))
20991 + return wh_dentry;
20994 +/* ---------------------------------------------------------------------- */
20996 +enum { Mknod, Symlink, Creat };
20997 +struct simple_arg {
21004 + struct vfsub_aopen_args *aopen;
21007 + const char *symname;
21016 +static int add_simple(struct inode *dir, struct dentry *dentry,
21017 + struct simple_arg *arg)
21020 + aufs_bindex_t btop;
21021 + unsigned char created;
21022 + const unsigned char try_aopen
21023 + = (arg->type == Creat && arg->u.c.try_aopen);
21024 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
21025 + struct dentry *wh_dentry, *parent;
21026 + struct inode *h_dir;
21027 + struct super_block *sb;
21028 + struct au_branch *br;
21029 + /* to reduce stack size */
21031 + struct au_dtime dt;
21032 + struct au_pin pin;
21033 + struct path h_path;
21034 + struct au_wr_dir_args wr_dir_args;
21037 + AuDbg("%pd\n", dentry);
21041 + a = kmalloc(sizeof(*a), GFP_NOFS);
21042 + if (unlikely(!a))
21044 + a->wr_dir_args.force_btgt = -1;
21045 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21047 + parent = dentry->d_parent; /* dir inode is locked */
21048 + if (!try_aopen) {
21049 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21050 + if (unlikely(err))
21053 + err = au_d_may_add(dentry);
21054 + if (unlikely(err))
21057 + di_write_lock_parent(parent);
21058 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21059 + &a->pin, &a->wr_dir_args);
21060 + err = PTR_ERR(wh_dentry);
21061 + if (IS_ERR(wh_dentry))
21064 + btop = au_dbtop(dentry);
21065 + sb = dentry->d_sb;
21066 + br = au_sbr(sb, btop);
21067 + a->h_path.dentry = au_h_dptr(dentry, btop);
21068 + a->h_path.mnt = au_br_mnt(br);
21069 + h_dir = au_pinned_h_dir(&a->pin);
21070 + switch (arg->type) {
21072 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21073 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21074 + arg->u.c.want_excl);
21076 + if (!err && try_aopen)
21077 + aopen->file->f_mode |= FMODE_CREATED;
21080 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21081 + AuDbg("err %d\n", err);
21082 + AuDbgFile(aopen->file);
21083 + created = err >= 0
21084 + && !!(aopen->file->f_mode & FMODE_CREATED);
21088 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21092 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21099 + if (unlikely(err < 0))
21102 + err = epilog(dir, btop, wh_dentry, dentry);
21104 + goto out_unpin; /* success */
21107 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21108 + /* no delegation since it is just created */
21109 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21112 + AuIOErr("%pd revert failure(%d, %d)\n",
21113 + dentry, err, rerr);
21116 + au_dtime_revert(&a->dt);
21118 + if (try_aopen && h_dir->i_op->atomic_open
21119 + && (aopen->file->f_mode & FMODE_OPENED))
21120 + /* aopen->file is still opened */
21121 + au_lcnt_dec(&aopen->br->br_nfiles);
21124 + au_unpin(&a->pin);
21128 + di_write_unlock(parent);
21130 + if (unlikely(err)) {
21131 + au_update_dbtop(dentry);
21135 + aufs_read_unlock(dentry, AuLock_DW);
21142 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
21143 + struct dentry *dentry, umode_t mode, dev_t dev)
21145 + struct simple_arg arg = {
21152 + return add_simple(dir, dentry, &arg);
21155 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
21156 + struct dentry *dentry, const char *symname)
21158 + struct simple_arg arg = {
21160 + .u.s.symname = symname
21162 + return add_simple(dir, dentry, &arg);
21165 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
21166 + struct dentry *dentry, umode_t mode, bool want_excl)
21168 + struct simple_arg arg = {
21172 + .want_excl = want_excl
21175 + return add_simple(dir, dentry, &arg);
21178 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21179 + struct vfsub_aopen_args *aopen_args)
21181 + struct simple_arg arg = {
21184 + .mode = aopen_args->create_mode,
21185 + .want_excl = aopen_args->open_flag & O_EXCL,
21186 + .try_aopen = true,
21187 + .aopen = aopen_args
21190 + return add_simple(dir, dentry, &arg);
21193 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
21194 + struct file *file, umode_t mode)
21197 + aufs_bindex_t bindex;
21198 + struct path h_ppath;
21199 + struct super_block *sb;
21200 + struct au_branch *br;
21201 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21202 + struct inode *h_dir, *inode;
21203 + struct vfsmount *h_mnt;
21204 + struct mnt_idmap *h_idmap;
21205 + struct file *h_file;
21206 + struct au_wr_dir_args wr_dir_args = {
21207 + .force_btgt = -1,
21208 + .flags = AuWrDir_TMPFILE
21211 + /* copy-up may happen */
21216 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21217 + if (unlikely(err))
21220 + dentry = file->f_path.dentry;
21221 + err = au_di_init(dentry);
21222 + if (unlikely(err))
21226 + parent = d_find_any_alias(dir);
21227 + AuDebugOn(!parent);
21228 + di_write_lock_parent(parent);
21229 + if (unlikely(d_inode(parent) != dir))
21232 + err = au_digen_test(parent, au_sigen(sb));
21233 + if (unlikely(err))
21236 + bindex = au_dbtop(parent);
21237 + au_set_dbtop(dentry, bindex);
21238 + au_set_dbbot(dentry, bindex);
21239 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21241 + if (unlikely(err < 0))
21244 + err = -EOPNOTSUPP;
21245 + h_dir = au_h_iptr(dir, bindex);
21246 + if (unlikely(!h_dir->i_op->tmpfile))
21249 + br = au_sbr(sb, bindex);
21250 + h_mnt = au_br_mnt(br);
21251 + err = vfsub_mnt_want_write(h_mnt);
21252 + if (unlikely(err))
21255 + h_idmap = mnt_idmap(h_mnt);
21256 + h_parent = au_h_dptr(parent, bindex);
21257 + h_ppath.mnt = h_mnt;
21258 + h_ppath.dentry = h_parent;
21259 + h_file = kernel_tmpfile_open(h_idmap, &h_ppath, mode, /*open_flag*/0,
21261 + if (IS_ERR(h_file)) {
21262 + err = PTR_ERR(h_file);
21267 + h_dentry = h_file->f_path.dentry;
21268 + au_set_dbtop(dentry, bindex);
21269 + au_set_dbbot(dentry, bindex);
21270 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21271 + inode = au_new_inode(dentry, /*must_new*/1);
21272 + if (IS_ERR(inode)) {
21273 + err = PTR_ERR(inode);
21274 + au_set_h_dptr(dentry, bindex, NULL);
21275 + au_set_dbtop(dentry, -1);
21276 + au_set_dbbot(dentry, -1);
21280 + if (!inode->i_nlink)
21281 + set_nlink(inode, 1);
21282 + d_tmpfile(file, inode);
21283 + au_di(dentry)->di_tmpfile = 1;
21284 + get_file(h_file);
21285 + au_di(dentry)->di_htmpfile = h_file;
21287 + /* update without i_mutex */
21288 + if (au_ibtop(dir) == au_dbtop(dentry))
21289 + au_cpup_attr_timesizes(dir);
21294 + vfsub_mnt_drop_write(h_mnt);
21296 + di_write_unlock(parent);
21298 + di_write_unlock(dentry);
21303 + au_di(dentry)->di_htmpfile = NULL;
21304 + au_di_fin(dentry);
21305 + dentry->d_fsdata = NULL;
21307 + si_read_unlock(sb);
21308 + if (!err && h_file) {
21310 + err = finish_open_simple(file, err);
21312 + au_lcnt_inc(&br->br_nfiles);
21315 + au_di(dentry)->di_htmpfile = NULL;
21316 + au_di_fin(dentry);
21317 + dentry->d_fsdata = NULL;
21321 + inode_unlock(dir);
21326 +/* ---------------------------------------------------------------------- */
21328 +struct au_link_args {
21329 + aufs_bindex_t bdst, bsrc;
21330 + struct au_pin pin;
21331 + struct path h_path;
21332 + struct dentry *src_parent, *parent;
21335 +static int au_cpup_before_link(struct dentry *src_dentry,
21336 + struct au_link_args *a)
21339 + struct dentry *h_src_dentry;
21340 + struct au_cp_generic cpg = {
21341 + .dentry = src_dentry,
21346 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21349 + di_read_lock_parent(a->src_parent, AuLock_IR);
21350 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21351 + if (unlikely(err))
21354 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21355 + err = au_pin(&a->pin, src_dentry, a->bdst,
21356 + au_opt_udba(src_dentry->d_sb),
21357 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21358 + if (unlikely(err))
21361 + err = au_sio_cpup_simple(&cpg);
21362 + au_unpin(&a->pin);
21365 + di_read_unlock(a->src_parent, AuLock_IR);
21369 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21370 + struct au_link_args *a)
21373 + unsigned char plink;
21374 + aufs_bindex_t bbot;
21375 + struct dentry *h_src_dentry;
21376 + struct inode *h_inode, *inode, *delegated;
21377 + struct super_block *sb;
21378 + struct file *h_file;
21382 + sb = src_dentry->d_sb;
21383 + inode = d_inode(src_dentry);
21384 + if (au_ibtop(inode) <= a->bdst)
21385 + h_inode = au_h_iptr(inode, a->bdst);
21386 + if (!h_inode || !h_inode->i_nlink) {
21387 + /* copyup src_dentry as the name of dentry. */
21388 + bbot = au_dbbot(dentry);
21389 + if (bbot < a->bsrc)
21390 + au_set_dbbot(dentry, a->bsrc);
21391 + au_set_h_dptr(dentry, a->bsrc,
21392 + dget(au_h_dptr(src_dentry, a->bsrc)));
21393 + dget(a->h_path.dentry);
21394 + au_set_h_dptr(dentry, a->bdst, NULL);
21395 + AuDbg("temporary d_inode...\n");
21396 + spin_lock(&dentry->d_lock);
21397 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21398 + spin_unlock(&dentry->d_lock);
21399 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21400 + if (IS_ERR(h_file))
21401 + err = PTR_ERR(h_file);
21403 + struct au_cp_generic cpg = {
21404 + .dentry = dentry,
21409 + .flags = AuCpup_KEEPLINO
21411 + err = au_sio_cpup_simple(&cpg);
21412 + au_h_open_post(dentry, a->bsrc, h_file);
21414 + dput(a->h_path.dentry);
21415 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21417 + au_set_h_dptr(dentry, a->bdst,
21418 + a->h_path.dentry);
21420 + spin_lock(&dentry->d_lock);
21421 + dentry->d_inode = NULL; /* restore */
21422 + spin_unlock(&dentry->d_lock);
21423 + AuDbg("temporary d_inode...done\n");
21424 + au_set_h_dptr(dentry, a->bsrc, NULL);
21425 + au_set_dbbot(dentry, bbot);
21427 + /* the inode of src_dentry already exists on a.bdst branch */
21428 + h_src_dentry = d_find_alias(h_inode);
21429 + if (!h_src_dentry && au_plink_test(inode)) {
21431 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21432 + err = PTR_ERR(h_src_dentry);
21433 + if (IS_ERR(h_src_dentry))
21436 + if (unlikely(d_is_negative(h_src_dentry))) {
21437 + dput(h_src_dentry);
21438 + h_src_dentry = NULL;
21442 + if (h_src_dentry) {
21443 + delegated = NULL;
21444 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21445 + &a->h_path, &delegated);
21446 + if (unlikely(err == -EWOULDBLOCK)) {
21447 + pr_warn("cannot retry for NFSv4 delegation"
21448 + " for an internal link\n");
21451 + dput(h_src_dentry);
21453 + AuIOErr("no dentry found for hi%lu on b%d\n",
21454 + h_inode->i_ino, a->bdst);
21459 + if (!err && !plink)
21460 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21467 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21468 + struct dentry *dentry)
21471 + struct au_dtime dt;
21472 + struct au_link_args *a;
21473 + struct dentry *wh_dentry, *h_src_dentry;
21474 + struct inode *inode, *delegated;
21475 + struct super_block *sb;
21476 + struct au_wr_dir_args wr_dir_args = {
21477 + /* .force_btgt = -1, */
21478 + .flags = AuWrDir_ADD_ENTRY
21482 + inode = d_inode(src_dentry);
21483 + IMustLock(inode);
21486 + a = kzalloc(sizeof(*a), GFP_NOFS);
21487 + if (unlikely(!a))
21490 + a->parent = dentry->d_parent; /* dir inode is locked */
21491 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21492 + AuLock_NOPLM | AuLock_GEN);
21493 + if (unlikely(err))
21495 + err = au_d_linkable(src_dentry);
21496 + if (unlikely(err))
21498 + err = au_d_may_add(dentry);
21499 + if (unlikely(err))
21502 + a->src_parent = dget_parent(src_dentry);
21503 + wr_dir_args.force_btgt = au_ibtop(inode);
21505 + di_write_lock_parent(a->parent);
21506 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21507 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21509 + err = PTR_ERR(wh_dentry);
21510 + if (IS_ERR(wh_dentry))
21514 + sb = dentry->d_sb;
21515 + a->bdst = au_dbtop(dentry);
21516 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21517 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21518 + a->bsrc = au_ibtop(inode);
21519 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21520 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21521 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21522 + if (!h_src_dentry) {
21523 + a->bsrc = au_dbtop(src_dentry);
21524 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21525 + AuDebugOn(!h_src_dentry);
21526 + } else if (IS_ERR(h_src_dentry)) {
21527 + err = PTR_ERR(h_src_dentry);
21532 + * aufs doesn't touch the credential so
21533 + * security_dentry_create_files_as() is unnecessary.
21535 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21536 + if (a->bdst < a->bsrc
21537 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21538 + err = au_cpup_or_link(src_dentry, dentry, a);
21540 + delegated = NULL;
21541 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21542 + &a->h_path, &delegated);
21543 + if (unlikely(err == -EWOULDBLOCK)) {
21544 + pr_warn("cannot retry for NFSv4 delegation"
21545 + " for an internal link\n");
21549 + dput(h_src_dentry);
21552 + * copyup src_dentry to the branch we process,
21553 + * and then link(2) to it.
21555 + dput(h_src_dentry);
21556 + if (a->bdst < a->bsrc
21557 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21558 + au_unpin(&a->pin);
21559 + di_write_unlock(a->parent);
21560 + err = au_cpup_before_link(src_dentry, a);
21561 + di_write_lock_parent(a->parent);
21563 + err = au_pin(&a->pin, dentry, a->bdst,
21565 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21566 + if (unlikely(err))
21570 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21572 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21573 + delegated = NULL;
21574 + err = vfsub_link(h_src_dentry,
21575 + au_pinned_h_dir(&a->pin),
21576 + &a->h_path, &delegated);
21577 + if (unlikely(err == -EWOULDBLOCK)) {
21578 + pr_warn("cannot retry"
21579 + " for NFSv4 delegation"
21580 + " for an internal link\n");
21586 + if (unlikely(err))
21590 + a->h_path.dentry = wh_dentry;
21591 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21593 + if (unlikely(err))
21597 + au_dir_ts(dir, a->bdst);
21598 + inode_inc_iversion(dir);
21599 + inc_nlink(inode);
21600 + inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
21601 + d_instantiate(dentry, au_igrab(inode));
21602 + if (d_unhashed(a->h_path.dentry))
21603 + /* some filesystem calls d_drop() */
21605 + /* some filesystems consume an inode even hardlink */
21606 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21607 + goto out_unpin; /* success */
21610 + /* no delegation since it is just created */
21611 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21612 + /*delegated*/NULL, /*force*/0);
21613 + if (unlikely(rerr)) {
21614 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21617 + au_dtime_revert(&dt);
21619 + au_unpin(&a->pin);
21623 + di_write_unlock(a->parent);
21624 + dput(a->src_parent);
21626 + if (unlikely(err)) {
21627 + au_update_dbtop(dentry);
21630 + aufs_read_and_write_unlock2(dentry, src_dentry);
21638 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
21639 + struct dentry *dentry, umode_t mode)
21642 + aufs_bindex_t bindex;
21643 + unsigned char diropq;
21644 + struct path h_path;
21645 + struct dentry *wh_dentry, *parent, *opq_dentry;
21646 + struct inode *h_inode;
21647 + struct super_block *sb;
21649 + struct au_pin pin;
21650 + struct au_dtime dt;
21651 + } *a; /* reduce the stack usage */
21652 + struct au_wr_dir_args wr_dir_args = {
21653 + .force_btgt = -1,
21654 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21660 + a = kmalloc(sizeof(*a), GFP_NOFS);
21661 + if (unlikely(!a))
21664 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21665 + if (unlikely(err))
21667 + err = au_d_may_add(dentry);
21668 + if (unlikely(err))
21671 + parent = dentry->d_parent; /* dir inode is locked */
21672 + di_write_lock_parent(parent);
21673 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21674 + &a->pin, &wr_dir_args);
21675 + err = PTR_ERR(wh_dentry);
21676 + if (IS_ERR(wh_dentry))
21679 + sb = dentry->d_sb;
21680 + bindex = au_dbtop(dentry);
21681 + h_path.dentry = au_h_dptr(dentry, bindex);
21682 + h_path.mnt = au_sbr_mnt(sb, bindex);
21683 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21684 + if (unlikely(err))
21687 + /* make the dir opaque */
21689 + h_inode = d_inode(h_path.dentry);
21691 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21692 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21693 + opq_dentry = au_diropq_create(dentry, bindex);
21694 + inode_unlock(h_inode);
21695 + err = PTR_ERR(opq_dentry);
21696 + if (IS_ERR(opq_dentry))
21698 + dput(opq_dentry);
21702 + err = epilog(dir, bindex, wh_dentry, dentry);
21705 + goto out_unpin; /* success */
21710 + AuLabel(revert opq);
21711 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21712 + rerr = au_diropq_remove(dentry, bindex);
21713 + inode_unlock(h_inode);
21715 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21716 + dentry, err, rerr);
21722 + AuLabel(revert dir);
21723 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21725 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21726 + dentry, err, rerr);
21729 + au_dtime_revert(&a->dt);
21731 + au_unpin(&a->pin);
21734 + di_write_unlock(parent);
21736 + if (unlikely(err)) {
21737 + au_update_dbtop(dentry);
21740 + aufs_read_unlock(dentry, AuLock_DW);
21746 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21747 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21748 +++ linux/fs/aufs/i_op.c 2024-05-13 17:13:00.618070924 +0200
21750 +// SPDX-License-Identifier: GPL-2.0
21752 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21754 + * This program is free software; you can redistribute it and/or modify
21755 + * it under the terms of the GNU General Public License as published by
21756 + * the Free Software Foundation; either version 2 of the License, or
21757 + * (at your option) any later version.
21759 + * This program is distributed in the hope that it will be useful,
21760 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21761 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21762 + * GNU General Public License for more details.
21764 + * You should have received a copy of the GNU General Public License
21765 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21769 + * inode operations (except add/del/rename)
21772 +#include <linux/device_cgroup.h>
21773 +#include <linux/filelock.h>
21774 +#include <linux/fs_stack.h>
21775 +#include <linux/iversion.h>
21776 +#include <linux/security.h>
21779 +static int h_permission(struct inode *h_inode, int mask,
21780 + struct path *h_path, int brperm)
21783 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21784 + struct mnt_idmap *h_idmap;
21787 + if (write_mask && IS_IMMUTABLE(h_inode))
21791 + if (((mask & MAY_EXEC)
21792 + && S_ISREG(h_inode->i_mode)
21793 + && (path_noexec(h_path)
21794 + || !(h_inode->i_mode & 0111))))
21798 + * - skip the lower fs test in the case of write to ro branch.
21799 + * - nfs dir permission write check is optimized, but a policy for
21800 + * link/rename requires a real check.
21801 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21802 + * in this case, generic_permission() returns -EOPNOTSUPP.
21804 + h_idmap = mnt_idmap(h_path->mnt);
21805 + if ((write_mask && !au_br_writable(brperm))
21806 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21807 + && write_mask && !(mask & MAY_READ))
21808 + || !h_inode->i_op->permission) {
21809 + /* AuLabel(generic_permission); */
21810 + /* AuDbg("get_inode_acl %ps\n",
21811 + h_inode->i_op->get_inode_acl); */
21812 + err = generic_permission(h_idmap, h_inode, mask);
21813 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21814 + err = h_inode->i_op->permission(h_idmap, h_inode,
21818 + /* AuLabel(h_inode->permission); */
21819 + err = h_inode->i_op->permission(h_idmap, h_inode, mask);
21824 + err = devcgroup_inode_permission(h_inode, mask);
21826 + err = security_inode_permission(h_inode, mask);
21832 +static int aufs_permission(struct mnt_idmap *idmap, struct inode *inode,
21836 + aufs_bindex_t bindex, bbot;
21837 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21838 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21839 + struct inode *h_inode;
21840 + struct super_block *sb;
21841 + struct au_branch *br;
21843 + /* todo: support rcu-walk? */
21844 + if (mask & MAY_NOT_BLOCK)
21847 + sb = inode->i_sb;
21848 + si_read_lock(sb, AuLock_FLUSH);
21849 + ii_read_lock_child(inode);
21850 +#if 0 /* reserved for future use */
21852 + * This test may be rather 'too much' since the test is essentially done
21853 + * in the aufs_lookup(). Theoretically it is possible that the inode
21854 + * generation doesn't match to the superblock's here. But it isn't a
21855 + * big deal I suppose.
21857 + err = au_iigen_test(inode, au_sigen(sb));
21858 + if (unlikely(err))
21864 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21865 + err = au_busy_or_stale();
21866 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21867 + if (unlikely(!h_inode
21868 + || (h_inode->i_mode & S_IFMT)
21869 + != (inode->i_mode & S_IFMT)))
21873 + bindex = au_ibtop(inode);
21874 + br = au_sbr(sb, bindex);
21875 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21878 + && !special_file(h_inode->i_mode)) {
21879 + /* test whether the upper writable branch exists */
21881 + for (; bindex >= 0; bindex--)
21882 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21890 + /* non-write to dir */
21892 + bbot = au_ibbot(inode);
21893 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21894 + h_inode = au_h_iptr(inode, bindex);
21896 + err = au_busy_or_stale();
21897 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21900 + br = au_sbr(sb, bindex);
21901 + err = h_permission(h_inode, mask, &br->br_path,
21907 + ii_read_unlock(inode);
21908 + si_read_unlock(sb);
21912 +/* ---------------------------------------------------------------------- */
21914 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21915 + unsigned int flags)
21917 + struct dentry *ret, *parent;
21918 + struct inode *inode;
21919 + struct super_block *sb;
21920 + int err, npositive;
21924 + /* todo: support rcu-walk? */
21925 + ret = ERR_PTR(-ECHILD);
21926 + if (flags & LOOKUP_RCU)
21929 + ret = ERR_PTR(-ENAMETOOLONG);
21930 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21934 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21935 + ret = ERR_PTR(err);
21936 + if (unlikely(err))
21939 + err = au_di_init(dentry);
21940 + ret = ERR_PTR(err);
21941 + if (unlikely(err))
21945 + npositive = 0; /* suppress a warning */
21946 + parent = dentry->d_parent; /* dir inode is locked */
21947 + di_read_lock_parent(parent, AuLock_IR);
21948 + err = au_alive_dir(parent);
21950 + err = au_digen_test(parent, au_sigen(sb));
21952 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21953 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21954 + AuLkup_ALLOW_NEG);
21957 + di_read_unlock(parent, AuLock_IR);
21958 + ret = ERR_PTR(err);
21959 + if (unlikely(err < 0))
21963 + inode = au_new_inode(dentry, /*must_new*/0);
21964 + if (IS_ERR(inode)) {
21965 + ret = (void *)inode;
21972 + atomic_inc(&inode->i_count);
21973 + ret = d_splice_alias(inode, dentry);
21974 +#if 0 /* reserved for future use */
21975 + if (unlikely(d_need_lookup(dentry))) {
21976 + spin_lock(&dentry->d_lock);
21977 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21978 + spin_unlock(&dentry->d_lock);
21982 + if (!IS_ERR(ret)) {
21984 + if (ret && ret != dentry)
21985 + ii_write_unlock(inode);
21987 + ii_write_unlock(inode);
21994 + di_write_unlock(dentry);
21996 + si_read_unlock(sb);
22001 +/* ---------------------------------------------------------------------- */
22004 + * very dirty and complicated aufs ->atomic_open().
22005 + * aufs_atomic_open()
22006 + * + au_aopen_or_create()
22008 + * + vfsub_atomic_open()
22009 + * + branch fs ->atomic_open()
22010 + * may call the actual 'open' for h_file
22011 + * + inc br_nfiles only if opened
22012 + * + au_aopen_no_open() or au_aopen_do_open()
22014 + * au_aopen_do_open()
22015 + * + finish_open()
22016 + * + au_do_aopen()
22017 + * + au_do_open() the body of all 'open'
22018 + * + au_do_open_nondir()
22019 + * set the passed h_file
22021 + * au_aopen_no_open()
22022 + * + finish_no_open()
22025 +struct aopen_node {
22026 + struct hlist_bl_node hblist;
22027 + struct file *file, *h_file;
22030 +static int au_do_aopen(struct inode *inode, struct file *file)
22032 + struct hlist_bl_head *aopen;
22033 + struct hlist_bl_node *pos;
22034 + struct aopen_node *node;
22035 + struct au_do_open_args args = {
22037 + .open = au_do_open_nondir
22040 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22041 + hlist_bl_lock(aopen);
22042 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22043 + if (node->file == file) {
22044 + args.h_file = node->h_file;
22047 + hlist_bl_unlock(aopen);
22048 + /* AuDebugOn(!args.h_file); */
22050 + return au_do_open(file, &args);
22053 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22054 + struct aopen_node *aopen_node)
22057 + struct hlist_bl_head *aopen;
22060 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22061 + au_hbl_add(&aopen_node->hblist, aopen);
22062 + err = finish_open(file, dentry, au_do_aopen);
22063 + au_hbl_del(&aopen_node->hblist, aopen);
22064 + /* AuDbgFile(file); */
22065 + AuDbg("%pd%s%s\n", dentry,
22066 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22067 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22073 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22079 + err = finish_no_open(file, dentry);
22085 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22086 + struct file *file, unsigned int open_flag,
22087 + umode_t create_mode)
22089 + int err, did_open;
22090 + unsigned int lkup_flags;
22091 + aufs_bindex_t bindex;
22092 + struct super_block *sb;
22093 + struct dentry *parent, *d;
22094 + struct vfsub_aopen_args args = {
22095 + .open_flag = open_flag,
22096 + .create_mode = create_mode
22098 + struct aopen_node aopen_node = {
22103 + AuDbg("open_flag 0%o\n", open_flag);
22104 + AuDbgDentry(dentry);
22107 + if (!au_di(dentry)) {
22108 + lkup_flags = LOOKUP_OPEN;
22109 + if (open_flag & O_CREAT)
22110 + lkup_flags |= LOOKUP_CREATE;
22111 + d = aufs_lookup(dir, dentry, lkup_flags);
22113 + err = PTR_ERR(d);
22118 + * obsoleted dentry found.
22119 + * another error will be returned later.
22125 + AuDbgDentry(dentry);
22128 + if (d_is_positive(dentry)
22129 + || d_unhashed(dentry)
22130 + || d_unlinked(dentry)
22131 + || !(open_flag & O_CREAT)) {
22132 + err = au_aopen_no_open(file, dentry);
22133 + goto out; /* success */
22136 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22137 + if (unlikely(err))
22140 + sb = dentry->d_sb;
22141 + parent = dentry->d_parent; /* dir is locked */
22142 + di_write_lock_parent(parent);
22143 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22144 + if (unlikely(err < 0))
22147 + AuDbgDentry(dentry);
22148 + if (d_is_positive(dentry)) {
22149 + err = au_aopen_no_open(file, dentry);
22150 + goto out_parent; /* success */
22153 + args.file = alloc_empty_file(file->f_flags, current_cred());
22154 + err = PTR_ERR(args.file);
22155 + if (IS_ERR(args.file))
22158 + bindex = au_dbtop(dentry);
22159 + err = au_aopen_or_create(dir, dentry, &args);
22161 + AuDbgFile(args.file);
22162 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22163 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22166 + args.file = NULL;
22168 + di_write_unlock(parent);
22169 + di_write_unlock(dentry);
22170 + if (unlikely(err < 0)) {
22177 + err = au_aopen_no_open(file, dentry);
22179 + aopen_node.h_file = args.file;
22180 + err = au_aopen_do_open(file, dentry, &aopen_node);
22182 + if (unlikely(err < 0)) {
22186 + au_lcnt_dec(&args.br->br_nfiles);
22188 + goto out_sb; /* success */
22191 + di_write_unlock(parent);
22192 + di_write_unlock(dentry);
22194 + si_read_unlock(sb);
22202 +/* ---------------------------------------------------------------------- */
22204 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22205 + const unsigned char add_entry, aufs_bindex_t bcpup,
22206 + aufs_bindex_t btop)
22209 + struct dentry *h_parent;
22210 + struct inode *h_dir;
22213 + IMustLock(d_inode(parent));
22215 + di_write_lock_parent(parent);
22218 + if (!au_h_dptr(parent, bcpup)) {
22219 + if (btop > bcpup)
22220 + err = au_cpup_dirs(dentry, bcpup);
22221 + else if (btop < bcpup)
22222 + err = au_cpdown_dirs(dentry, bcpup);
22226 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22227 + h_parent = au_h_dptr(parent, bcpup);
22228 + h_dir = d_inode(h_parent);
22229 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22230 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22231 + /* todo: no unlock here */
22232 + inode_unlock_shared(h_dir);
22234 + AuDbg("bcpup %d\n", bcpup);
22236 + if (d_really_is_negative(dentry))
22237 + au_set_h_dptr(dentry, btop, NULL);
22238 + au_update_dbrange(dentry, /*do_put_zero*/0);
22243 + di_write_unlock(parent);
22245 + err = bcpup; /* success */
22252 + * decide the branch and the parent dir where we will create a new entry.
22253 + * returns new bindex or an error.
22254 + * copyup the parent dir if needed.
22256 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22257 + struct au_wr_dir_args *args)
22260 + unsigned int flags;
22261 + aufs_bindex_t bcpup, btop, src_btop;
22262 + const unsigned char add_entry
22263 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22264 + | au_ftest_wrdir(args->flags, TMPFILE);
22265 + struct super_block *sb;
22266 + struct dentry *parent;
22267 + struct au_sbinfo *sbinfo;
22269 + sb = dentry->d_sb;
22270 + sbinfo = au_sbi(sb);
22271 + parent = dget_parent(dentry);
22272 + btop = au_dbtop(dentry);
22274 + if (args->force_btgt < 0) {
22275 + if (src_dentry) {
22276 + src_btop = au_dbtop(src_dentry);
22277 + if (src_btop < btop)
22278 + bcpup = src_btop;
22279 + } else if (add_entry) {
22281 + if (au_ftest_wrdir(args->flags, ISDIR))
22282 + au_fset_wbr(flags, DIR);
22283 + err = AuWbrCreate(sbinfo, dentry, flags);
22287 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22289 + err = AuWbrCopyup(sbinfo, dentry);
22291 + if (!IS_ROOT(dentry)) {
22292 + di_read_lock_parent(parent, !AuLock_IR);
22293 + err = AuWbrCopyup(sbinfo, dentry);
22294 + di_read_unlock(parent, !AuLock_IR);
22296 + err = AuWbrCopyup(sbinfo, dentry);
22299 + if (unlikely(err < 0))
22303 + bcpup = args->force_btgt;
22304 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22307 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22309 + if (bcpup == btop)
22310 + goto out; /* success */
22312 + /* copyup the new parent into the branch we process */
22313 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22315 + if (d_really_is_negative(dentry)) {
22316 + au_set_h_dptr(dentry, btop, NULL);
22317 + au_set_dbtop(dentry, bcpup);
22318 + au_set_dbbot(dentry, bcpup);
22320 + AuDebugOn(add_entry
22321 + && !au_ftest_wrdir(args->flags, TMPFILE)
22322 + && !au_h_dptr(dentry, bcpup));
22330 +/* ---------------------------------------------------------------------- */
22332 +void au_pin_hdir_unlock(struct au_pin *p)
22335 + au_hn_inode_unlock(p->hdir);
22338 +int au_pin_hdir_lock(struct au_pin *p)
22346 + /* even if an error happens later, keep this lock */
22347 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22350 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22355 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22356 + p->h_parent, p->br);
22362 +int au_pin_hdir_relock(struct au_pin *p)
22365 + struct inode *h_i;
22366 + struct dentry *h_d[] = {
22371 + err = au_pin_hdir_lock(p);
22372 + if (unlikely(err))
22375 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22378 + if (d_is_positive(h_d[i])) {
22379 + h_i = d_inode(h_d[i]);
22380 + err = !h_i->i_nlink;
22388 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22390 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22393 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22396 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22397 + p->lsc_hi, 0, NULL, _RET_IP_);
22398 + au_pin_hdir_set_owner(p, current);
22402 +void au_pin_hdir_release(struct au_pin *p)
22405 + au_pin_hdir_set_owner(p, p->task);
22406 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22410 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22412 + if (pin && pin->parent)
22413 + return au_h_dptr(pin->parent, pin->bindex);
22417 +void au_unpin(struct au_pin *p)
22420 + au_pin_hdir_unlock(p);
22421 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22422 + vfsub_mnt_drop_write(p->h_mnt);
22426 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22427 + di_read_unlock(p->parent, AuLock_IR);
22428 + iput(p->hdir->hi_inode);
22430 + p->parent = NULL;
22433 + /* do not clear p->task */
22436 +int au_do_pin(struct au_pin *p)
22439 + struct super_block *sb;
22440 + struct inode *h_dir;
22443 + sb = p->dentry->d_sb;
22444 + p->br = au_sbr(sb, p->bindex);
22445 + if (IS_ROOT(p->dentry)) {
22446 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22447 + p->h_mnt = au_br_mnt(p->br);
22448 + err = vfsub_mnt_want_write(p->h_mnt);
22449 + if (unlikely(err)) {
22450 + au_fclr_pin(p->flags, MNT_WRITE);
22457 + p->h_dentry = NULL;
22458 + if (p->bindex <= au_dbbot(p->dentry))
22459 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22461 + p->parent = dget_parent(p->dentry);
22462 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22463 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22466 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22467 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22469 + h_dir = p->hdir->hi_inode;
22473 + * if DI_LOCKED is not set, then p->parent may be different
22474 + * and h_parent can be NULL.
22476 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22478 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22479 + di_read_unlock(p->parent, AuLock_IR);
22481 + p->parent = NULL;
22485 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22486 + p->h_mnt = au_br_mnt(p->br);
22487 + err = vfsub_mnt_want_write(p->h_mnt);
22488 + if (unlikely(err)) {
22489 + au_fclr_pin(p->flags, MNT_WRITE);
22490 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22491 + di_read_unlock(p->parent, AuLock_IR);
22493 + p->parent = NULL;
22499 + err = au_pin_hdir_lock(p);
22501 + goto out; /* success */
22506 + pr_err("err %d\n", err);
22507 + err = au_busy_or_stale();
22512 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22513 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22514 + unsigned int udba, unsigned char flags)
22516 + p->dentry = dentry;
22518 + p->lsc_di = lsc_di;
22519 + p->lsc_hi = lsc_hi;
22520 + p->flags = flags;
22521 + p->bindex = bindex;
22523 + p->parent = NULL;
22527 + p->h_dentry = NULL;
22528 + p->h_parent = NULL;
22530 + p->task = current;
22533 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22534 + unsigned int udba, unsigned char flags)
22536 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22538 + return au_do_pin(pin);
22541 +/* ---------------------------------------------------------------------- */
22544 + * ->setattr() and ->getattr() are called in various cases.
22545 + * chmod, stat: dentry is revalidated.
22546 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22548 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22550 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22551 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22554 + struct dentry *parent;
22557 + if (au_digen_test(dentry, sigen)) {
22558 + parent = dget_parent(dentry);
22559 + di_read_lock_parent(parent, AuLock_IR);
22560 + err = au_refresh_dentry(dentry, parent);
22561 + di_read_unlock(parent, AuLock_IR);
22569 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22570 + struct au_icpup_args *a)
22574 + aufs_bindex_t btop, ibtop;
22575 + struct dentry *hi_wh, *parent;
22576 + struct inode *inode;
22577 + struct au_wr_dir_args wr_dir_args = {
22578 + .force_btgt = -1,
22582 + if (d_is_dir(dentry))
22583 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22584 + /* plink or hi_wh() case */
22585 + btop = au_dbtop(dentry);
22586 + inode = d_inode(dentry);
22587 + ibtop = au_ibtop(inode);
22588 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22589 + wr_dir_args.force_btgt = ibtop;
22590 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22591 + if (unlikely(err < 0))
22595 + au_fset_icpup(a->flags, DID_CPUP);
22598 + a->pin_flags = AuPin_MNT_WRITE;
22600 + if (!IS_ROOT(dentry)) {
22601 + au_fset_pin(a->pin_flags, DI_LOCKED);
22602 + parent = dget_parent(dentry);
22603 + di_write_lock_parent(parent);
22606 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22607 + if (unlikely(err))
22611 + a->h_path.dentry = au_h_dptr(dentry, btop);
22612 + a->h_inode = d_inode(a->h_path.dentry);
22613 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22614 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22615 + if (ia->ia_size < i_size_read(a->h_inode))
22616 + sz = ia->ia_size;
22617 + inode_unlock_shared(a->h_inode);
22621 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22622 + hi_wh = au_hi_wh(inode, a->btgt);
22624 + struct au_cp_generic cpg = {
22625 + .dentry = dentry,
22631 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22632 + if (unlikely(err))
22634 + hi_wh = au_hi_wh(inode, a->btgt);
22635 + /* todo: revalidate hi_wh? */
22640 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22641 + di_downgrade_lock(parent, AuLock_IR);
22645 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22646 + goto out; /* success */
22648 + if (!d_unhashed(dentry)) {
22649 + struct au_cp_generic cpg = {
22650 + .dentry = dentry,
22655 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22657 + err = au_sio_cpup_simple(&cpg);
22659 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22660 + } else if (!hi_wh)
22661 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22663 + a->h_path.dentry = hi_wh; /* do not dget here */
22666 + a->h_inode = d_inode(a->h_path.dentry);
22668 + goto out; /* success */
22669 + au_unpin(&a->pin);
22672 + di_write_unlock(parent);
22677 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22681 +static int aufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
22682 + struct iattr *ia)
22685 + struct inode *inode, *delegated;
22686 + struct super_block *sb;
22687 + struct file *file;
22688 + struct au_icpup_args *a;
22689 + struct mnt_idmap *h_idmap;
22691 + inode = d_inode(dentry);
22692 + IMustLock(inode);
22694 + err = setattr_prepare(idmap, dentry, ia);
22695 + if (unlikely(err))
22699 + a = kzalloc(sizeof(*a), GFP_NOFS);
22700 + if (unlikely(!a))
22703 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22704 + ia->ia_valid &= ~ATTR_MODE;
22707 + sb = dentry->d_sb;
22708 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22709 + if (unlikely(err))
22712 + if (ia->ia_valid & ATTR_FILE) {
22713 + /* currently ftruncate(2) only */
22714 + AuDebugOn(!d_is_reg(dentry));
22715 + file = ia->ia_file;
22716 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22718 + if (unlikely(err))
22720 + ia->ia_file = au_hf_top(file);
22721 + a->udba = AuOpt_UDBA_NONE;
22723 + /* fchmod() doesn't pass ia_file */
22724 + a->udba = au_opt_udba(sb);
22725 + di_write_lock_child(dentry);
22726 + /* no d_unlinked(), to set UDBA_NONE for root */
22727 + if (d_unhashed(dentry))
22728 + a->udba = AuOpt_UDBA_NONE;
22729 + if (a->udba != AuOpt_UDBA_NONE) {
22730 + AuDebugOn(IS_ROOT(dentry));
22731 + err = au_reval_for_attr(dentry, au_sigen(sb));
22732 + if (unlikely(err))
22737 + err = au_pin_and_icpup(dentry, ia, a);
22738 + if (unlikely(err < 0))
22740 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22741 + ia->ia_file = NULL;
22742 + ia->ia_valid &= ~ATTR_FILE;
22745 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22746 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22747 + == (ATTR_MODE | ATTR_CTIME)) {
22748 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22749 + if (unlikely(err))
22751 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22752 + && (ia->ia_valid & ATTR_CTIME)) {
22753 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22754 + if (unlikely(err))
22758 + if (ia->ia_valid & ATTR_SIZE) {
22761 + if (ia->ia_size < i_size_read(inode))
22763 + truncate_setsize(inode, ia->ia_size);
22766 + if (ia->ia_valid & ATTR_FILE)
22768 + inode_unlock(a->h_inode);
22769 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22770 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22772 + delegated = NULL;
22774 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22776 + err = break_deleg_wait(&delegated);
22784 + * regardless aufs 'acl' option setting.
22785 + * why don't all acl-aware fs call this func from their ->setattr()?
22787 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22788 + h_idmap = mnt_idmap(a->h_path.mnt);
22789 + err = vfsub_acl_chmod(h_idmap, a->h_path.dentry, ia->ia_mode);
22792 + au_cpup_attr_changeable(inode);
22795 + inode_unlock(a->h_inode);
22796 + au_unpin(&a->pin);
22797 + if (unlikely(err))
22798 + au_update_dbtop(dentry);
22800 + di_write_unlock(dentry);
22802 + fi_write_unlock(file);
22803 + ia->ia_file = file;
22804 + ia->ia_valid |= ATTR_FILE;
22807 + si_read_unlock(sb);
22815 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22816 +static int au_h_path_to_set_attr(struct dentry *dentry,
22817 + struct au_icpup_args *a, struct path *h_path)
22820 + struct super_block *sb;
22822 + sb = dentry->d_sb;
22823 + a->udba = au_opt_udba(sb);
22824 + /* no d_unlinked(), to set UDBA_NONE for root */
22825 + if (d_unhashed(dentry))
22826 + a->udba = AuOpt_UDBA_NONE;
22827 + if (a->udba != AuOpt_UDBA_NONE) {
22828 + AuDebugOn(IS_ROOT(dentry));
22829 + err = au_reval_for_attr(dentry, au_sigen(sb));
22830 + if (unlikely(err))
22833 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22834 + if (unlikely(err < 0))
22837 + h_path->dentry = a->h_path.dentry;
22838 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22844 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22845 + struct au_sxattr *arg)
22848 + struct path h_path;
22849 + struct super_block *sb;
22850 + struct au_icpup_args *a;
22851 + struct inode *h_inode;
22852 + struct mnt_idmap *h_idmap;
22854 + IMustLock(inode);
22857 + a = kzalloc(sizeof(*a), GFP_NOFS);
22858 + if (unlikely(!a))
22861 + sb = dentry->d_sb;
22862 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22863 + if (unlikely(err))
22866 + h_path.dentry = NULL; /* silence gcc */
22867 + di_write_lock_child(dentry);
22868 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22869 + if (unlikely(err))
22871 + h_idmap = mnt_idmap(h_path.mnt);
22873 + inode_unlock(a->h_inode);
22874 + switch (arg->type) {
22875 + case AU_XATTR_SET:
22876 + AuDebugOn(d_is_negative(h_path.dentry));
22877 + err = vfsub_setxattr(h_idmap, h_path.dentry,
22878 + arg->u.set.name, arg->u.set.value,
22879 + arg->u.set.size, arg->u.set.flags);
22882 + err = -EOPNOTSUPP;
22883 + h_inode = d_inode(h_path.dentry);
22884 + if (h_inode->i_op->set_acl) {
22885 + /* this will call posix_acl_update_mode */
22886 + err = h_inode->i_op->set_acl(h_idmap, h_path.dentry,
22887 + arg->u.acl_set.acl,
22888 + arg->u.acl_set.type);
22893 + au_cpup_attr_timesizes(inode);
22895 + au_unpin(&a->pin);
22896 + if (unlikely(err))
22897 + au_update_dbtop(dentry);
22900 + di_write_unlock(dentry);
22901 + si_read_unlock(sb);
22910 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22911 + unsigned int nlink)
22915 + inode->i_mode = st->mode;
22916 + /* don't i_[ug]id_write() here */
22917 + inode->i_uid = st->uid;
22918 + inode->i_gid = st->gid;
22919 + inode_set_atime_to_ts(inode, st->atime);
22920 + inode_set_mtime_to_ts(inode, st->mtime);
22921 + inode_set_ctime_to_ts(inode, st->ctime);
22923 + au_cpup_attr_nlink(inode, /*force*/0);
22924 + if (S_ISDIR(inode->i_mode)) {
22925 + n = inode->i_nlink;
22928 + smp_mb(); /* for i_nlink */
22929 + /* 0 can happen */
22930 + set_nlink(inode, n);
22933 + spin_lock(&inode->i_lock);
22934 + inode->i_blocks = st->blocks;
22935 + i_size_write(inode, st->size);
22936 + spin_unlock(&inode->i_lock);
22940 + * common routine for aufs_getattr() and au_getxattr().
22941 + * returns zero or negative (an error).
22942 + * @dentry will be read-locked in success.
22944 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22945 + struct path *h_path, int locked)
22948 + unsigned int mnt_flags, sigen;
22949 + unsigned char udba_none;
22950 + aufs_bindex_t bindex;
22951 + struct super_block *sb, *h_sb;
22953 + h_path->mnt = NULL;
22954 + h_path->dentry = NULL;
22957 + sb = dentry->d_sb;
22958 + mnt_flags = au_mntflags(sb);
22959 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22961 + if (unlikely(locked))
22962 + goto body; /* skip locking dinfo */
22964 + /* support fstat(2) */
22965 + if (!d_unlinked(dentry) && !udba_none) {
22966 + sigen = au_sigen(sb);
22967 + err = au_digen_test(dentry, sigen);
22969 + di_read_lock_child(dentry, AuLock_IR);
22970 + err = au_dbrange_test(dentry);
22971 + if (unlikely(err)) {
22972 + di_read_unlock(dentry, AuLock_IR);
22976 + AuDebugOn(IS_ROOT(dentry));
22977 + di_write_lock_child(dentry);
22978 + err = au_dbrange_test(dentry);
22980 + err = au_reval_for_attr(dentry, sigen);
22982 + di_downgrade_lock(dentry, AuLock_IR);
22984 + di_write_unlock(dentry);
22989 + di_read_lock_child(dentry, AuLock_IR);
22993 + inode = d_inode(dentry);
22994 + if (unlikely(!inode))
22997 + bindex = au_ibtop(inode);
22998 + h_path->mnt = au_sbr_mnt(sb, bindex);
22999 + h_sb = h_path->mnt->mnt_sb;
23001 + && !au_test_fs_bad_iattr(h_sb)
23003 + goto out; /* success */
23005 + if (au_dbtop(dentry) == bindex)
23006 + h_path->dentry = au_h_dptr(dentry, bindex);
23007 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
23008 + h_path->dentry = au_plink_lkup(inode, bindex);
23009 + if (IS_ERR(h_path->dentry))
23010 + /* pretending success */
23011 + h_path->dentry = NULL;
23013 + dput(h_path->dentry);
23020 +static int aufs_getattr(struct mnt_idmap *idmap, const struct path *path,
23021 + struct kstat *st, u32 request, unsigned int query)
23024 + unsigned char positive;
23025 + struct path h_path;
23026 + struct dentry *dentry;
23027 + struct inode *inode;
23028 + struct super_block *sb;
23030 + dentry = path->dentry;
23031 + inode = d_inode(dentry);
23032 + sb = dentry->d_sb;
23033 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23034 + if (unlikely(err))
23036 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23038 + if (unlikely(err))
23040 + if (unlikely(!h_path.dentry))
23041 + /* illegally overlapped or something */
23042 + goto out_fill; /* pretending success */
23044 + positive = d_is_positive(h_path.dentry);
23046 + /* no vfsub version */
23047 + if (query & AT_GETATTR_NOSEC)
23048 + err = vfs_getattr_nosec(&h_path, st, request, query);
23050 + err = vfs_getattr(&h_path, st, request, query);
23054 + au_refresh_iattr(inode, st,
23055 + d_inode(h_path.dentry)->i_nlink);
23056 + goto out_fill; /* success */
23062 + generic_fillattr(idmap, request, inode, st);
23064 + di_read_unlock(dentry, AuLock_IR);
23066 + si_read_unlock(sb);
23072 +/* ---------------------------------------------------------------------- */
23074 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23075 + struct delayed_call *done)
23078 + struct dentry *h_dentry;
23079 + struct inode *h_inode;
23081 + aufs_bindex_t bindex;
23083 + ret = NULL; /* suppress a warning */
23088 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23089 + if (unlikely(err))
23092 + err = au_d_hashed_positive(dentry);
23093 + if (unlikely(err))
23097 + inode = d_inode(dentry);
23098 + bindex = au_ibtop(inode);
23099 + h_inode = au_h_iptr(inode, bindex);
23100 + if (unlikely(!h_inode->i_op->get_link))
23105 + if (au_dbtop(dentry) <= bindex) {
23106 + h_dentry = au_h_dptr(dentry, bindex);
23111 + h_dentry = d_find_any_alias(h_inode);
23112 + if (IS_ERR(h_dentry)) {
23113 + err = PTR_ERR(h_dentry);
23117 + if (unlikely(!h_dentry))
23121 + AuDbg("%ps\n", h_inode->i_op->get_link);
23122 + AuDbgDentry(h_dentry);
23123 + ret = vfs_get_link(h_dentry, done);
23126 + err = PTR_ERR(ret);
23129 + aufs_read_unlock(dentry, AuLock_IR);
23131 + if (unlikely(err))
23132 + ret = ERR_PTR(err);
23133 + AuTraceErrPtr(ret);
23137 +/* ---------------------------------------------------------------------- */
23139 +static int au_is_special(struct inode *inode)
23141 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23144 +static int aufs_update_time(struct inode *inode, int flags)
23147 + aufs_bindex_t bindex;
23148 + struct super_block *sb;
23149 + struct inode *h_inode;
23150 + struct vfsmount *h_mnt;
23152 + sb = inode->i_sb;
23153 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23154 + "unexpected s_flags 0x%lx", sb->s_flags);
23156 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23158 + si_read_lock(sb, AuLock_FLUSH);
23159 + ii_write_lock_child(inode);
23162 + bindex = au_ibtop(inode);
23163 + h_inode = au_h_iptr(inode, bindex);
23164 + if (!au_test_ro(sb, bindex, inode)) {
23165 + h_mnt = au_sbr_mnt(sb, bindex);
23166 + err = vfsub_mnt_want_write(h_mnt);
23168 + err = vfsub_update_time(h_inode, flags);
23169 + vfsub_mnt_drop_write(h_mnt);
23171 + } else if (au_is_special(h_inode)) {
23173 + * Never copy-up here.
23174 + * These special files may already be opened and used for
23175 + * communicating. If we copied it up, then the communication
23176 + * would be corrupted.
23178 + AuWarn1("timestamps for i%lu are ignored "
23179 + "since it is on readonly branch (hi%lu).\n",
23180 + inode->i_ino, h_inode->i_ino);
23181 + } else if (flags & ~S_ATIME) {
23183 + AuIOErr1("unexpected flags 0x%x\n", flags);
23188 + au_cpup_attr_timesizes(inode);
23189 + ii_write_unlock(inode);
23190 + si_read_unlock(sb);
23193 + if (!err && (flags & S_VERSION))
23194 + inode_inc_iversion(inode);
23199 +/* ---------------------------------------------------------------------- */
23201 +/* no getattr version will be set by module.c:aufs_init() */
23202 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23204 + [AuIop_SYMLINK] = {
23205 + .permission = aufs_permission,
23206 +#ifdef CONFIG_FS_POSIX_ACL
23207 + .get_inode_acl = aufs_get_inode_acl,
23208 + .get_acl = aufs_get_acl,
23209 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23212 + .setattr = aufs_setattr,
23213 + .getattr = aufs_getattr,
23215 +#ifdef CONFIG_AUFS_XATTR
23216 + .listxattr = aufs_listxattr,
23219 + .get_link = aufs_get_link
23221 + /* .update_time = aufs_update_time */
23224 + .create = aufs_create,
23225 + .lookup = aufs_lookup,
23226 + .link = aufs_link,
23227 + .unlink = aufs_unlink,
23228 + .symlink = aufs_symlink,
23229 + .mkdir = aufs_mkdir,
23230 + .rmdir = aufs_rmdir,
23231 + .mknod = aufs_mknod,
23232 + .rename = aufs_rename,
23234 + .permission = aufs_permission,
23235 +#ifdef CONFIG_FS_POSIX_ACL
23236 + .get_inode_acl = aufs_get_inode_acl,
23237 + .get_acl = aufs_get_acl,
23238 + .set_acl = aufs_set_acl,
23241 + .setattr = aufs_setattr,
23242 + .getattr = aufs_getattr,
23244 +#ifdef CONFIG_AUFS_XATTR
23245 + .listxattr = aufs_listxattr,
23248 + .update_time = aufs_update_time,
23249 + .atomic_open = aufs_atomic_open,
23250 + .tmpfile = aufs_tmpfile
23252 + [AuIop_OTHER] = {
23253 + .permission = aufs_permission,
23254 +#ifdef CONFIG_FS_POSIX_ACL
23255 + .get_inode_acl = aufs_get_inode_acl,
23256 + .get_acl = aufs_get_acl,
23257 + .set_acl = aufs_set_acl,
23260 + .setattr = aufs_setattr,
23261 + .getattr = aufs_getattr,
23263 +#ifdef CONFIG_AUFS_XATTR
23264 + .listxattr = aufs_listxattr,
23267 + .update_time = aufs_update_time
23270 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23271 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23272 +++ linux/fs/aufs/i_op_del.c 2024-05-13 17:13:00.618070924 +0200
23274 +// SPDX-License-Identifier: GPL-2.0
23276 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23278 + * This program is free software; you can redistribute it and/or modify
23279 + * it under the terms of the GNU General Public License as published by
23280 + * the Free Software Foundation; either version 2 of the License, or
23281 + * (at your option) any later version.
23283 + * This program is distributed in the hope that it will be useful,
23284 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23285 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23286 + * GNU General Public License for more details.
23288 + * You should have received a copy of the GNU General Public License
23289 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23293 + * inode operations (del entry)
23296 +#include <linux/iversion.h>
23300 + * decide if a new whiteout for @dentry is necessary or not.
23301 + * when it is necessary, prepare the parent dir for the upper branch whose
23302 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23303 + * be done by caller.
23305 + * 0: wh is unnecessary
23306 + * plus: wh is necessary
23309 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23311 + int need_wh, err;
23312 + aufs_bindex_t btop;
23313 + struct super_block *sb;
23315 + sb = dentry->d_sb;
23316 + btop = au_dbtop(dentry);
23317 + if (*bcpup < 0) {
23319 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23320 + err = AuWbrCopyup(au_sbi(sb), dentry);
23322 + if (unlikely(err < 0))
23326 + AuDebugOn(btop < *bcpup
23327 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23328 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23330 + if (*bcpup != btop) {
23331 + err = au_cpup_dirs(dentry, *bcpup);
23332 + if (unlikely(err))
23336 + struct au_dinfo *dinfo, *tmp;
23338 + need_wh = -ENOMEM;
23339 + dinfo = au_di(dentry);
23340 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23342 + au_di_cp(tmp, dinfo);
23343 + au_di_swap(tmp, dinfo);
23344 + /* returns the number of positive dentries */
23345 + need_wh = au_lkup_dentry(dentry, btop + 1,
23346 + /* AuLkup_IGNORE_PERM */ 0);
23347 + au_di_swap(tmp, dinfo);
23348 + au_rw_write_unlock(&tmp->di_rwsem);
23352 + AuDbg("need_wh %d\n", need_wh);
23360 + * simple tests for the del-entry operations.
23361 + * following the checks in vfs, plus the parent-child relationship.
23363 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23364 + struct dentry *h_parent, int isdir)
23368 + struct dentry *h_dentry, *h_latest;
23369 + struct inode *h_inode;
23370 + struct path h_ppath;
23371 + struct super_block *sb;
23372 + struct au_branch *br;
23373 + struct mnt_idmap *h_idmap;
23375 + h_dentry = au_h_dptr(dentry, bindex);
23376 + if (d_really_is_positive(dentry)) {
23378 + if (unlikely(d_is_negative(h_dentry)))
23380 + h_inode = d_inode(h_dentry);
23381 + if (unlikely(!h_inode->i_nlink))
23384 + h_mode = h_inode->i_mode;
23387 + if (unlikely(S_ISDIR(h_mode)))
23389 + } else if (unlikely(!S_ISDIR(h_mode))) {
23394 + /* rename(2) case */
23396 + if (unlikely(d_is_positive(h_dentry)))
23401 + /* expected parent dir is locked */
23402 + if (unlikely(h_parent != h_dentry->d_parent))
23407 + * rmdir a dir may break the consistency on some filesystem.
23408 + * let's try heavy test.
23411 + sb = dentry->d_sb;
23412 + br = au_sbr(sb, bindex);
23413 + h_idmap = au_br_idmap(br);
23414 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23415 + && au_test_h_perm(h_idmap, d_inode(h_parent),
23416 + MAY_EXEC | MAY_WRITE)))
23419 + h_ppath.dentry = h_parent;
23420 + h_ppath.mnt = au_br_mnt(br);
23421 + h_latest = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
23423 + if (IS_ERR(h_latest))
23425 + if (h_latest == h_dentry)
23434 + * decide the branch where we operate for @dentry. the branch index will be set
23435 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23436 + * dir for reverting.
23437 + * when a new whiteout is necessary, create it.
23439 +static struct dentry*
23440 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23441 + struct au_dtime *dt, struct au_pin *pin)
23443 + struct dentry *wh_dentry;
23444 + struct super_block *sb;
23445 + struct path h_path;
23446 + int err, need_wh;
23447 + unsigned int udba;
23448 + aufs_bindex_t bcpup;
23450 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23451 + wh_dentry = ERR_PTR(need_wh);
23452 + if (unlikely(need_wh < 0))
23455 + sb = dentry->d_sb;
23456 + udba = au_opt_udba(sb);
23458 + err = au_pin(pin, dentry, bcpup, udba,
23459 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23460 + wh_dentry = ERR_PTR(err);
23461 + if (unlikely(err))
23464 + h_path.dentry = au_pinned_h_parent(pin);
23465 + if (udba != AuOpt_UDBA_NONE
23466 + && au_dbtop(dentry) == bcpup) {
23467 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23468 + wh_dentry = ERR_PTR(err);
23469 + if (unlikely(err))
23473 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23474 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23475 + wh_dentry = NULL;
23477 + goto out; /* success, no need to create whiteout */
23479 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23480 + if (IS_ERR(wh_dentry))
23483 + /* returns with the parent is locked and wh_dentry is dget-ed */
23484 + goto out; /* success */
23489 + return wh_dentry;
23493 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23494 + * in order to be revertible and save time for removing many child whiteouts
23496 + * returns 1 when there are too many child whiteout and caller should remove
23497 + * them asynchronously. returns 0 when the number of children is enough small to
23498 + * remove now or the branch fs is a remote fs.
23499 + * otherwise return an error.
23501 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23502 + struct au_nhash *whlist, struct inode *dir)
23504 + int rmdir_later, err, dirwh;
23505 + struct dentry *h_dentry;
23506 + struct super_block *sb;
23507 + struct inode *inode;
23509 + sb = dentry->d_sb;
23510 + SiMustAnyLock(sb);
23511 + h_dentry = au_h_dptr(dentry, bindex);
23512 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23513 + if (unlikely(err))
23516 + /* stop monitoring */
23517 + inode = d_inode(dentry);
23518 + au_hn_free(au_hi(inode, bindex));
23520 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23521 + dirwh = au_sbi(sb)->si_dirwh;
23522 + rmdir_later = (dirwh <= 1);
23523 + if (!rmdir_later)
23524 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23527 + return rmdir_later;
23530 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23531 + if (unlikely(err)) {
23532 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23533 + h_dentry, bindex, err);
23543 + * final procedure for deleting a entry.
23544 + * maintain dentry and iattr.
23546 +static void epilog(struct inode *dir, struct dentry *dentry,
23547 + aufs_bindex_t bindex)
23549 + struct inode *inode;
23551 + inode = d_inode(dentry);
23553 + inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
23555 + au_dir_ts(dir, bindex);
23556 + inode_inc_iversion(dir);
23560 + * when an error happened, remove the created whiteout and revert everything.
23562 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23563 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23564 + struct dentry *dentry, struct au_dtime *dt)
23567 + struct path h_path = {
23568 + .dentry = wh_dentry,
23569 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23572 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23574 + au_set_dbwh(dentry, bwh);
23575 + au_dtime_revert(dt);
23579 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23583 +/* ---------------------------------------------------------------------- */
23585 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23588 + aufs_bindex_t bwh, bindex, btop;
23589 + struct inode *inode, *h_dir, *delegated, *h_inode;
23590 + struct dentry *parent, *wh_dentry;
23591 + /* to reduce stack size */
23593 + struct au_dtime dt;
23594 + struct au_pin pin;
23595 + struct path h_path;
23601 + a = kmalloc(sizeof(*a), GFP_NOFS);
23602 + if (unlikely(!a))
23605 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23606 + if (unlikely(err))
23608 + err = au_d_hashed_positive(dentry);
23609 + if (unlikely(err))
23611 + inode = d_inode(dentry);
23612 + IMustLock(inode);
23614 + if (unlikely(d_is_dir(dentry)))
23615 + goto out_unlock; /* possible? */
23617 + btop = au_dbtop(dentry);
23618 + bwh = au_dbwh(dentry);
23620 + parent = dentry->d_parent; /* dir inode is locked */
23621 + di_write_lock_parent(parent);
23622 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23624 + err = PTR_ERR(wh_dentry);
23625 + if (IS_ERR(wh_dentry))
23628 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23629 + a->h_path.dentry = au_h_dptr(dentry, btop);
23630 + dget(a->h_path.dentry);
23631 + if (bindex == btop) {
23632 + h_dir = au_pinned_h_dir(&a->pin);
23633 + delegated = NULL;
23634 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23635 + if (unlikely(err == -EWOULDBLOCK)) {
23636 + pr_warn("cannot retry for NFSv4 delegation"
23637 + " for an internal unlink\n");
23641 + /* dir inode is locked */
23642 + h_dir = d_inode(wh_dentry->d_parent);
23643 + IMustLock(h_dir);
23648 + vfsub_drop_nlink(inode);
23649 + epilog(dir, dentry, bindex);
23651 + /* update target timestamps */
23652 + if (bindex == btop) {
23653 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23655 + h_inode = d_inode(a->h_path.dentry);
23656 + inode_set_ctime_to_ts(inode, inode_get_ctime(h_inode));
23658 + /* todo: this timestamp may be reverted later */
23659 + inode_set_ctime_to_ts(inode, inode_get_ctime(h_dir));
23660 + goto out_unpin; /* success */
23667 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23674 + au_unpin(&a->pin);
23676 + dput(a->h_path.dentry);
23678 + di_write_unlock(parent);
23680 + aufs_read_unlock(dentry, AuLock_DW);
23687 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23689 + int err, rmdir_later;
23690 + aufs_bindex_t bwh, bindex, btop;
23691 + struct inode *inode;
23692 + struct dentry *parent, *wh_dentry, *h_dentry;
23693 + struct au_whtmp_rmdir *args;
23694 + /* to reduce stack size */
23696 + struct au_dtime dt;
23697 + struct au_pin pin;
23703 + a = kmalloc(sizeof(*a), GFP_NOFS);
23704 + if (unlikely(!a))
23707 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23708 + if (unlikely(err))
23710 + err = au_alive_dir(dentry);
23711 + if (unlikely(err))
23713 + inode = d_inode(dentry);
23714 + IMustLock(inode);
23716 + if (unlikely(!d_is_dir(dentry)))
23717 + goto out_unlock; /* possible? */
23720 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23721 + if (unlikely(!args))
23724 + parent = dentry->d_parent; /* dir inode is locked */
23725 + di_write_lock_parent(parent);
23726 + err = au_test_empty(dentry, &args->whlist);
23727 + if (unlikely(err))
23730 + btop = au_dbtop(dentry);
23731 + bwh = au_dbwh(dentry);
23733 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23735 + err = PTR_ERR(wh_dentry);
23736 + if (IS_ERR(wh_dentry))
23739 + h_dentry = au_h_dptr(dentry, btop);
23742 + if (bindex == btop) {
23743 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23745 + rmdir_later = err;
23749 + /* stop monitoring */
23750 + au_hn_free(au_hi(inode, btop));
23752 + /* dir inode is locked */
23753 + IMustLock(d_inode(wh_dentry->d_parent));
23758 + vfsub_dead_dir(inode);
23759 + au_set_dbdiropq(dentry, -1);
23760 + epilog(dir, dentry, bindex);
23762 + if (rmdir_later) {
23763 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23767 + goto out_unpin; /* success */
23775 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23782 + au_unpin(&a->pin);
23786 + di_write_unlock(parent);
23788 + au_whtmp_rmdir_free(args);
23790 + aufs_read_unlock(dentry, AuLock_DW);
23797 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23798 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23799 +++ linux/fs/aufs/i_op_ren.c 2024-05-13 17:13:00.621404284 +0200
23801 +// SPDX-License-Identifier: GPL-2.0
23803 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23805 + * This program is free software; you can redistribute it and/or modify
23806 + * it under the terms of the GNU General Public License as published by
23807 + * the Free Software Foundation; either version 2 of the License, or
23808 + * (at your option) any later version.
23810 + * This program is distributed in the hope that it will be useful,
23811 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23812 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23813 + * GNU General Public License for more details.
23815 + * You should have received a copy of the GNU General Public License
23816 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23820 + * inode operation (rename entry)
23821 + * todo: this is crazy monster
23824 +#include <linux/iversion.h>
23827 +enum { AuSRC, AuDST, AuSrcDst };
23828 +enum { AuPARENT, AuCHILD, AuParentChild };
23830 +#define AuRen_ISDIR_SRC BIT(0)
23831 +#define AuRen_ISDIR_DST BIT(1)
23832 +#define AuRen_ISSAMEDIR BIT(2)
23833 +#define AuRen_WHSRC BIT(3)
23834 +#define AuRen_WHDST BIT(4)
23835 +#define AuRen_MNT_WRITE BIT(5)
23836 +#define AuRen_DT_DSTDIR BIT(6)
23837 +#define AuRen_DIROPQ_SRC BIT(7)
23838 +#define AuRen_DIROPQ_DST BIT(8)
23839 +#define AuRen_DIRREN BIT(9)
23840 +#define AuRen_DROPPED_SRC BIT(10)
23841 +#define AuRen_DROPPED_DST BIT(11)
23842 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23843 +#define au_fset_ren(flags, name) \
23844 + do { (flags) |= AuRen_##name; } while (0)
23845 +#define au_fclr_ren(flags, name) \
23846 + do { (flags) &= ~AuRen_##name; } while (0)
23848 +#ifndef CONFIG_AUFS_DIRREN
23849 +#undef AuRen_DIRREN
23850 +#define AuRen_DIRREN 0
23853 +struct au_ren_args {
23855 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23857 + struct inode *dir, *inode;
23858 + struct au_hinode *hdir, *hinode;
23859 + struct au_dtime dt[AuParentChild];
23860 + aufs_bindex_t btop, bdiropq;
23863 +#define src_dentry sd[AuSRC].dentry
23864 +#define src_dir sd[AuSRC].dir
23865 +#define src_inode sd[AuSRC].inode
23866 +#define src_h_dentry sd[AuSRC].h_dentry
23867 +#define src_parent sd[AuSRC].parent
23868 +#define src_h_parent sd[AuSRC].h_parent
23869 +#define src_wh_dentry sd[AuSRC].wh_dentry
23870 +#define src_hdir sd[AuSRC].hdir
23871 +#define src_hinode sd[AuSRC].hinode
23872 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23873 +#define src_dt sd[AuSRC].dt
23874 +#define src_btop sd[AuSRC].btop
23875 +#define src_bdiropq sd[AuSRC].bdiropq
23877 +#define dst_dentry sd[AuDST].dentry
23878 +#define dst_dir sd[AuDST].dir
23879 +#define dst_inode sd[AuDST].inode
23880 +#define dst_h_dentry sd[AuDST].h_dentry
23881 +#define dst_parent sd[AuDST].parent
23882 +#define dst_h_parent sd[AuDST].h_parent
23883 +#define dst_wh_dentry sd[AuDST].wh_dentry
23884 +#define dst_hdir sd[AuDST].hdir
23885 +#define dst_hinode sd[AuDST].hinode
23886 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23887 +#define dst_dt sd[AuDST].dt
23888 +#define dst_btop sd[AuDST].btop
23889 +#define dst_bdiropq sd[AuDST].bdiropq
23891 + struct dentry *h_trap;
23892 + struct au_branch *br;
23893 + struct path h_path;
23894 + struct au_nhash whlist;
23895 + aufs_bindex_t btgt, src_bwh;
23898 + unsigned short auren_flags;
23899 + unsigned char flags; /* syscall parameter */
23900 + unsigned char exchange;
23903 + struct au_whtmp_rmdir *thargs;
23904 + struct dentry *h_dst;
23905 + struct au_hinode *h_root;
23908 +/* ---------------------------------------------------------------------- */
23911 + * functions for reverting.
23912 + * when an error happened in a single rename systemcall, we should revert
23913 + * everything as if nothing happened.
23914 + * we don't need to revert the copied-up/down the parent dir since they are
23918 +#define RevertFailure(fmt, ...) do { \
23919 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23920 + ##__VA_ARGS__, err, rerr); \
23924 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23927 + struct dentry *d;
23928 +#define src_or_dst(member) a->sd[idx].member
23930 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23931 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23932 + rerr = au_diropq_remove(d, a->btgt);
23933 + au_hn_inode_unlock(src_or_dst(hinode));
23934 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23936 + RevertFailure("remove diropq %pd", d);
23938 +#undef src_or_dst_
23941 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23943 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23944 + au_ren_do_rev_diropq(err, a, AuSRC);
23945 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23946 + au_ren_do_rev_diropq(err, a, AuDST);
23949 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23952 + struct inode *delegated;
23953 + struct path h_ppath = {
23954 + .dentry = a->src_h_parent,
23955 + .mnt = a->h_path.mnt
23958 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23959 + rerr = PTR_ERR(a->h_path.dentry);
23960 + if (IS_ERR(a->h_path.dentry)) {
23961 + RevertFailure("lkup one %pd", a->src_dentry);
23965 + delegated = NULL;
23966 + rerr = vfsub_rename(a->dst_h_dir,
23967 + au_h_dptr(a->src_dentry, a->btgt),
23968 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23969 + if (unlikely(rerr == -EWOULDBLOCK)) {
23970 + pr_warn("cannot retry for NFSv4 delegation"
23971 + " for an internal rename\n");
23974 + d_drop(a->h_path.dentry);
23975 + dput(a->h_path.dentry);
23976 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23978 + RevertFailure("rename %pd", a->src_dentry);
23981 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23984 + struct inode *delegated;
23985 + struct path h_ppath = {
23986 + .dentry = a->dst_h_parent,
23987 + .mnt = a->h_path.mnt
23990 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23991 + rerr = PTR_ERR(a->h_path.dentry);
23992 + if (IS_ERR(a->h_path.dentry)) {
23993 + RevertFailure("lkup one %pd", a->dst_dentry);
23996 + if (d_is_positive(a->h_path.dentry)) {
23997 + d_drop(a->h_path.dentry);
23998 + dput(a->h_path.dentry);
24002 + delegated = NULL;
24003 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
24004 + &delegated, a->flags);
24005 + if (unlikely(rerr == -EWOULDBLOCK)) {
24006 + pr_warn("cannot retry for NFSv4 delegation"
24007 + " for an internal rename\n");
24010 + d_drop(a->h_path.dentry);
24011 + dput(a->h_path.dentry);
24013 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
24015 + RevertFailure("rename %pd", a->h_dst);
24018 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
24022 + a->h_path.dentry = a->src_wh_dentry;
24023 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
24024 + au_set_dbwh(a->src_dentry, a->src_bwh);
24026 + RevertFailure("unlink %pd", a->src_wh_dentry);
24028 +#undef RevertFailure
24030 +/* ---------------------------------------------------------------------- */
24033 + * when we have to copyup the renaming entry, do it with the rename-target name
24034 + * in order to minimize the cost (the later actual rename is unnecessary).
24035 + * otherwise rename it on the target branch.
24037 +static int au_ren_or_cpup(struct au_ren_args *a)
24040 + struct dentry *d;
24041 + struct inode *delegated;
24043 + d = a->src_dentry;
24044 + if (au_dbtop(d) == a->btgt) {
24045 + a->h_path.dentry = a->dst_h_dentry;
24046 + AuDebugOn(au_dbtop(d) != a->btgt);
24047 + delegated = NULL;
24048 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24049 + a->dst_h_dir, &a->h_path, &delegated,
24051 + if (unlikely(err == -EWOULDBLOCK)) {
24052 + pr_warn("cannot retry for NFSv4 delegation"
24053 + " for an internal rename\n");
24059 + if (!err && a->h_dst)
24060 + /* it will be set to dinfo later */
24066 +/* cf. aufs_rmdir() */
24067 +static int au_ren_del_whtmp(struct au_ren_args *a)
24070 + struct inode *dir;
24072 + dir = a->dst_dir;
24073 + SiMustAnyLock(dir->i_sb);
24074 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24075 + au_sbi(dir->i_sb)->si_dirwh)
24076 + || au_test_fs_remote(a->h_dst->d_sb)) {
24077 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24078 + if (unlikely(err))
24079 + pr_warn("failed removing whtmp dir %pd (%d), "
24080 + "ignored.\n", a->h_dst, err);
24082 + au_nhash_wh_free(&a->thargs->whlist);
24083 + a->thargs->whlist = a->whlist;
24084 + a->whlist.nh_num = 0;
24085 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24087 + a->thargs = NULL;
24093 +/* make it 'opaque' dir. */
24094 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24097 + struct dentry *d, *diropq;
24098 +#define src_or_dst(member) a->sd[idx].member
24101 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24102 + src_or_dst(bdiropq) = au_dbdiropq(d);
24103 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24104 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24105 + diropq = au_diropq_create(d, a->btgt);
24106 + au_hn_inode_unlock(src_or_dst(hinode));
24107 + if (IS_ERR(diropq))
24108 + err = PTR_ERR(diropq);
24112 +#undef src_or_dst_
24116 +static int au_ren_diropq(struct au_ren_args *a)
24119 + unsigned char always;
24120 + struct dentry *d;
24123 + d = a->dst_dentry; /* already renamed on the branch */
24124 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24125 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24126 + && !au_ftest_ren(a->auren_flags, DIRREN)
24127 + && a->btgt != au_dbdiropq(a->src_dentry)
24128 + && (a->dst_wh_dentry
24129 + || a->btgt <= au_dbdiropq(d)
24130 + /* hide the lower to keep xino */
24131 + /* the lowers may not be a dir, but we hide them anyway */
24132 + || a->btgt < au_dbbot(d)
24135 + err = au_ren_do_diropq(a, AuSRC);
24136 + if (unlikely(err))
24138 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24140 + if (!a->exchange)
24141 + goto out; /* success */
24143 + d = a->src_dentry; /* already renamed on the branch */
24144 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24145 + && a->btgt != au_dbdiropq(a->dst_dentry)
24146 + && (a->btgt < au_dbdiropq(d)
24147 + || a->btgt < au_dbbot(d)
24149 + AuDbgDentry(a->src_dentry);
24150 + AuDbgDentry(a->dst_dentry);
24151 + err = au_ren_do_diropq(a, AuDST);
24152 + if (unlikely(err))
24153 + goto out_rev_src;
24154 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24156 + goto out; /* success */
24159 + AuDbg("err %d, reverting src\n", err);
24160 + au_ren_rev_diropq(err, a);
24165 +static int do_rename(struct au_ren_args *a)
24168 + struct dentry *d, *h_d;
24169 + struct inode *h_inode;
24171 + if (!a->exchange) {
24172 + /* prepare workqueue args for asynchronous rmdir */
24173 + h_d = a->dst_h_dentry;
24174 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24175 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24176 + && d_is_positive(h_d)) {
24178 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24180 + if (unlikely(!a->thargs))
24182 + a->h_dst = dget(h_d);
24185 + /* create whiteout for src_dentry */
24186 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24187 + a->src_bwh = au_dbwh(a->src_dentry);
24188 + AuDebugOn(a->src_bwh >= 0);
24189 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24190 + a->src_h_parent);
24191 + err = PTR_ERR(a->src_wh_dentry);
24192 + if (IS_ERR(a->src_wh_dentry))
24196 + /* lookup whiteout for dentry */
24197 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24198 + h_d = au_wh_lkup(a->dst_h_parent,
24199 + &a->dst_dentry->d_name, a->br);
24200 + err = PTR_ERR(h_d);
24203 + if (d_is_negative(h_d))
24206 + a->dst_wh_dentry = h_d;
24209 + /* rename dentry to tmpwh */
24211 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24212 + if (unlikely(err))
24215 + d = a->dst_dentry;
24216 + au_set_h_dptr(d, a->btgt, NULL);
24217 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24218 + if (unlikely(err))
24220 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24224 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24225 +#if 0 /* debugging */
24226 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24227 + && d_is_positive(a->dst_h_dentry)
24228 + && a->src_btop != a->btgt);
24231 + /* rename by vfs_rename or cpup */
24232 + err = au_ren_or_cpup(a);
24233 + if (unlikely(err))
24234 + /* leave the copied-up one */
24237 + /* make dir opaque */
24238 + err = au_ren_diropq(a);
24239 + if (unlikely(err))
24242 + /* update target timestamps */
24243 + if (a->exchange) {
24244 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24245 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24246 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24247 + h_inode = d_inode(a->h_path.dentry);
24248 + inode_set_ctime_to_ts(a->dst_inode, inode_get_ctime(h_inode));
24250 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24251 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24252 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24253 + h_inode = d_inode(a->h_path.dentry);
24254 + inode_set_ctime_to_ts(a->src_inode, inode_get_ctime(h_inode));
24256 + if (!a->exchange) {
24257 + /* remove whiteout for dentry */
24258 + if (a->dst_wh_dentry) {
24259 + a->h_path.dentry = a->dst_wh_dentry;
24260 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24262 + if (unlikely(err))
24266 + /* remove whtmp */
24268 + au_ren_del_whtmp(a); /* ignore this error */
24270 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24273 + goto out_success;
24276 + au_ren_rev_diropq(err, a);
24278 + au_ren_rev_rename(err, a);
24282 + au_ren_rev_whtmp(err, a);
24284 + dput(a->dst_wh_dentry);
24285 + a->dst_wh_dentry = NULL;
24287 + if (a->src_wh_dentry)
24288 + au_ren_rev_whsrc(err, a);
24290 + dput(a->src_wh_dentry);
24291 + dput(a->dst_wh_dentry);
24295 + au_whtmp_rmdir_free(a->thargs);
24296 + a->thargs = NULL;
24302 +/* ---------------------------------------------------------------------- */
24305 + * test if @dentry dir can be rename destination or not.
24306 + * success means, it is a logically empty dir.
24308 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24310 + return au_test_empty(dentry, whlist);
24314 + * test if @a->src_dentry dir can be rename source or not.
24315 + * if it can, return 0.
24317 + * - it is a logically empty dir.
24318 + * - or, it exists on writable branch and has no children including whiteouts
24319 + * on the lower branch unless DIRREN is on.
24321 +static int may_rename_srcdir(struct au_ren_args *a)
24324 + unsigned int rdhash;
24325 + aufs_bindex_t btop, btgt;
24326 + struct dentry *dentry;
24327 + struct super_block *sb;
24328 + struct au_sbinfo *sbinfo;
24330 + dentry = a->src_dentry;
24331 + sb = dentry->d_sb;
24332 + sbinfo = au_sbi(sb);
24333 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24334 + au_fset_ren(a->auren_flags, DIRREN);
24337 + btop = au_dbtop(dentry);
24338 + if (btop != btgt) {
24339 + struct au_nhash whlist;
24341 + SiMustAnyLock(sb);
24342 + rdhash = sbinfo->si_rdhash;
24344 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24346 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24347 + if (unlikely(err))
24349 + err = au_test_empty(dentry, &whlist);
24350 + au_nhash_wh_free(&whlist);
24354 + if (btop == au_dbtaildir(dentry))
24355 + return 0; /* success */
24357 + err = au_test_empty_lower(dentry);
24360 + if (err == -ENOTEMPTY) {
24361 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24364 + AuWarn1("renaming dir who has child(ren) on multiple "
24365 + "branches, is not supported\n");
24372 +/* side effect: sets whlist and h_dentry */
24373 +static int au_ren_may_dir(struct au_ren_args *a)
24376 + unsigned int rdhash;
24377 + struct dentry *d;
24379 + d = a->dst_dentry;
24380 + SiMustAnyLock(d->d_sb);
24383 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24384 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24386 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24387 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24388 + if (unlikely(err))
24391 + if (!a->exchange) {
24392 + au_set_dbtop(d, a->dst_btop);
24393 + err = may_rename_dstdir(d, &a->whlist);
24394 + au_set_dbtop(d, a->btgt);
24396 + err = may_rename_srcdir(a);
24398 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24399 + if (unlikely(err))
24402 + d = a->src_dentry;
24403 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24404 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24405 + err = may_rename_srcdir(a);
24406 + if (unlikely(err)) {
24407 + au_nhash_wh_free(&a->whlist);
24408 + a->whlist.nh_num = 0;
24415 +/* ---------------------------------------------------------------------- */
24418 + * simple tests for rename.
24419 + * following the checks in vfs, plus the parent-child relationship.
24421 +static int au_may_ren(struct au_ren_args *a)
24424 + struct inode *h_inode;
24426 + if (a->src_btop == a->btgt) {
24427 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24428 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24429 + if (unlikely(err))
24432 + if (unlikely(a->src_h_dentry == a->h_trap))
24437 + if (a->dst_btop != a->btgt)
24440 + err = -ENOTEMPTY;
24441 + if (unlikely(a->dst_h_dentry == a->h_trap))
24445 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24446 + if (d_really_is_negative(a->dst_dentry)) {
24447 + if (d_is_negative(a->dst_h_dentry))
24448 + err = au_may_add(a->dst_dentry, a->btgt,
24449 + a->dst_h_parent, isdir);
24451 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24453 + h_inode = d_inode(a->dst_h_dentry);
24454 + if (h_inode->i_nlink)
24455 + err = au_may_del(a->dst_dentry, a->btgt,
24456 + a->dst_h_parent, isdir);
24460 + if (unlikely(err == -ENOENT || err == -EEXIST))
24466 +/* ---------------------------------------------------------------------- */
24471 + * - src_dir and dir by lock_rename()
24472 + * - inode if exists
24475 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24477 + * + di_write_lock2_child()
24478 + * + di_write_lock_child()
24479 + * + ii_write_lock_child()
24480 + * + di_write_lock_child2()
24481 + * + ii_write_lock_child2()
24482 + * + src_parent and parent
24483 + * + di_write_lock_parent()
24484 + * + ii_write_lock_parent()
24485 + * + di_write_lock_parent2()
24486 + * + ii_write_lock_parent2()
24487 + * + lower src_dir and dir by vfsub_lock_rename()
24488 + * + verify the every relationships between child and parent. if any
24489 + * of them failed, unlock all and return -EBUSY.
24491 +static void au_ren_unlock(struct au_ren_args *a)
24493 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24494 + a->dst_h_parent, a->dst_hdir);
24495 + if (au_ftest_ren(a->auren_flags, DIRREN)
24497 + au_hn_inode_unlock(a->h_root);
24498 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24499 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24502 +static int au_ren_lock(struct au_ren_args *a)
24505 + unsigned int udba;
24508 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24509 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24510 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24511 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24513 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24514 + if (unlikely(err))
24516 + au_fset_ren(a->auren_flags, MNT_WRITE);
24517 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24518 + struct dentry *root;
24519 + struct inode *dir;
24522 + * sbinfo is already locked, so this ii_read_lock is
24523 + * unnecessary. but our debugging feature checks it.
24525 + root = a->src_inode->i_sb->s_root;
24526 + if (root != a->src_parent && root != a->dst_parent) {
24527 + dir = d_inode(root);
24528 + ii_read_lock_parent3(dir);
24529 + a->h_root = au_hi(dir, a->btgt);
24530 + ii_read_unlock(dir);
24531 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24534 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24535 + a->dst_h_parent, a->dst_hdir);
24536 + if (IS_ERR(a->h_trap)) {
24537 + err = PTR_ERR(a->h_trap);
24540 + udba = au_opt_udba(a->src_dentry->d_sb);
24541 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24542 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24543 + err = au_busy_or_stale();
24544 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24545 + err = au_h_verify(a->src_h_dentry, udba,
24546 + d_inode(a->src_h_parent), a->src_h_parent,
24548 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24549 + err = au_h_verify(a->dst_h_dentry, udba,
24550 + d_inode(a->dst_h_parent), a->dst_h_parent,
24553 + goto out; /* success */
24555 + err = au_busy_or_stale();
24556 + au_ren_unlock(a);
24562 +/* ---------------------------------------------------------------------- */
24564 +static void au_ren_refresh_dir(struct au_ren_args *a)
24566 + struct inode *dir;
24568 + dir = a->dst_dir;
24569 + inode_inc_iversion(dir);
24570 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24571 + /* is this updating defined in POSIX? */
24572 + au_cpup_attr_timesizes(a->src_inode);
24573 + au_cpup_attr_nlink(dir, /*force*/1);
24575 + au_dir_ts(dir, a->btgt);
24577 + if (a->exchange) {
24578 + dir = a->src_dir;
24579 + inode_inc_iversion(dir);
24580 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24581 + /* is this updating defined in POSIX? */
24582 + au_cpup_attr_timesizes(a->dst_inode);
24583 + au_cpup_attr_nlink(dir, /*force*/1);
24585 + au_dir_ts(dir, a->btgt);
24588 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24591 + dir = a->src_dir;
24592 + inode_inc_iversion(dir);
24593 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24594 + au_cpup_attr_nlink(dir, /*force*/1);
24595 + au_dir_ts(dir, a->btgt);
24598 +static void au_ren_refresh(struct au_ren_args *a)
24600 + aufs_bindex_t bbot, bindex;
24601 + struct dentry *d, *h_d;
24602 + struct inode *i, *h_i;
24603 + struct super_block *sb;
24605 + d = a->dst_dentry;
24608 + /* already dget-ed by au_ren_or_cpup() */
24609 + au_set_h_dptr(d, a->btgt, a->h_dst);
24611 + i = a->dst_inode;
24613 + if (!a->exchange) {
24614 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24615 + vfsub_drop_nlink(i);
24617 + vfsub_dead_dir(i);
24618 + au_cpup_attr_timesizes(i);
24620 + au_update_dbrange(d, /*do_put_zero*/1);
24622 + au_cpup_attr_nlink(i, /*force*/1);
24625 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24626 + au_set_h_dptr(d, bindex, NULL);
24627 + bbot = au_dbbot(d);
24628 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24629 + au_set_h_dptr(d, bindex, NULL);
24630 + au_update_dbrange(d, /*do_put_zero*/0);
24634 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24635 + d_drop(a->src_dentry);
24636 + if (au_ftest_ren(a->auren_flags, DIRREN))
24637 + au_set_dbwh(a->src_dentry, -1);
24641 + d = a->src_dentry;
24642 + au_set_dbwh(d, -1);
24643 + bbot = au_dbbot(d);
24644 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24645 + h_d = au_h_dptr(d, bindex);
24647 + au_set_h_dptr(d, bindex, NULL);
24649 + au_set_dbbot(d, a->btgt);
24652 + i = a->src_inode;
24653 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24654 + return; /* success */
24656 + bbot = au_ibbot(i);
24657 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24658 + h_i = au_h_iptr(i, bindex);
24660 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24661 + /* ignore this error */
24662 + au_set_h_iptr(i, bindex, NULL, 0);
24665 + au_set_ibbot(i, a->btgt);
24668 +/* ---------------------------------------------------------------------- */
24670 +/* mainly for link(2) and rename(2) */
24671 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24673 + aufs_bindex_t bdiropq, bwh;
24674 + struct dentry *parent;
24675 + struct au_branch *br;
24677 + parent = dentry->d_parent;
24678 + IMustLock(d_inode(parent)); /* dir is locked */
24680 + bdiropq = au_dbdiropq(parent);
24681 + bwh = au_dbwh(dentry);
24682 + br = au_sbr(dentry->d_sb, btgt);
24683 + if (au_br_rdonly(br)
24684 + || (0 <= bdiropq && bdiropq < btgt)
24685 + || (0 <= bwh && bwh < btgt))
24688 + AuDbg("btgt %d\n", btgt);
24692 +/* sets src_btop, dst_btop and btgt */
24693 +static int au_ren_wbr(struct au_ren_args *a)
24696 + struct au_wr_dir_args wr_dir_args = {
24697 + /* .force_btgt = -1, */
24698 + .flags = AuWrDir_ADD_ENTRY
24701 + a->src_btop = au_dbtop(a->src_dentry);
24702 + a->dst_btop = au_dbtop(a->dst_dentry);
24703 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24704 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24705 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24706 + wr_dir_args.force_btgt = a->src_btop;
24707 + if (a->dst_inode && a->dst_btop < a->src_btop)
24708 + wr_dir_args.force_btgt = a->dst_btop;
24709 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24710 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24713 + au_update_dbtop(a->dst_dentry);
24718 +static void au_ren_dt(struct au_ren_args *a)
24720 + a->h_path.dentry = a->src_h_parent;
24721 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24722 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24723 + a->h_path.dentry = a->dst_h_parent;
24724 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24727 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24728 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24732 + a->h_path.dentry = a->src_h_dentry;
24733 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24734 + if (d_is_positive(a->dst_h_dentry)) {
24735 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24736 + a->h_path.dentry = a->dst_h_dentry;
24737 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24741 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24743 + struct dentry *h_d;
24744 + struct inode *h_inode;
24746 + au_dtime_revert(a->src_dt + AuPARENT);
24747 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24748 + au_dtime_revert(a->dst_dt + AuPARENT);
24750 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24751 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24752 + h_inode = d_inode(h_d);
24753 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24754 + au_dtime_revert(a->src_dt + AuCHILD);
24755 + inode_unlock(h_inode);
24757 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24758 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24759 + h_inode = d_inode(h_d);
24760 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24761 + au_dtime_revert(a->dst_dt + AuCHILD);
24762 + inode_unlock(h_inode);
24767 +/* ---------------------------------------------------------------------- */
24769 +int aufs_rename(struct mnt_idmap *idmap,
24770 + struct inode *_src_dir, struct dentry *_src_dentry,
24771 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24772 + unsigned int _flags)
24774 + int err, lock_flags;
24776 + /* reduce stack space */
24777 + struct au_ren_args *a;
24778 + struct au_pin pin;
24780 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24781 + IMustLock(_src_dir);
24782 + IMustLock(_dst_dir);
24785 + if (unlikely(_flags & RENAME_WHITEOUT))
24789 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24790 + a = kzalloc(sizeof(*a), GFP_NOFS);
24791 + if (unlikely(!a))
24794 + a->flags = _flags;
24795 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24796 + && RENAME_EXCHANGE > U8_MAX);
24797 + a->exchange = _flags & RENAME_EXCHANGE;
24798 + a->src_dir = _src_dir;
24799 + a->src_dentry = _src_dentry;
24800 + a->src_inode = NULL;
24801 + if (d_really_is_positive(a->src_dentry))
24802 + a->src_inode = d_inode(a->src_dentry);
24803 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24804 + a->dst_dir = _dst_dir;
24805 + a->dst_dentry = _dst_dentry;
24806 + a->dst_inode = NULL;
24807 + if (d_really_is_positive(a->dst_dentry))
24808 + a->dst_inode = d_inode(a->dst_dentry);
24809 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24810 + if (a->dst_inode) {
24812 + * if EXCHANGE && src is non-dir && dst is dir,
24813 + * dst is not locked.
24815 + /* IMustLock(a->dst_inode); */
24816 + au_igrab(a->dst_inode);
24820 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24821 + if (d_is_dir(a->src_dentry)) {
24822 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24823 + if (unlikely(!a->exchange
24824 + && d_really_is_positive(a->dst_dentry)
24825 + && !d_is_dir(a->dst_dentry)))
24827 + lock_flags |= AuLock_DIRS;
24829 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24830 + au_fset_ren(a->auren_flags, ISDIR_DST);
24831 + if (unlikely(!a->exchange
24832 + && d_really_is_positive(a->src_dentry)
24833 + && !d_is_dir(a->src_dentry)))
24835 + lock_flags |= AuLock_DIRS;
24837 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24839 + if (unlikely(err))
24842 + err = au_d_hashed_positive(a->src_dentry);
24843 + if (unlikely(err))
24846 + if (a->dst_inode) {
24848 + * If it is a dir, VFS unhash it before this
24849 + * function. It means we cannot rely upon d_unhashed().
24851 + if (unlikely(!a->dst_inode->i_nlink))
24853 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24854 + err = au_d_hashed_positive(a->dst_dentry);
24855 + if (unlikely(err && !a->exchange))
24857 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24859 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24863 + * is it possible?
24864 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24865 + * there may exist a problem somewhere else.
24868 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24871 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24872 + di_write_lock_parent(a->dst_parent);
24874 + /* which branch we process */
24875 + err = au_ren_wbr(a);
24876 + if (unlikely(err < 0))
24878 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24879 + a->h_path.mnt = au_br_mnt(a->br);
24881 + /* are they available to be renamed */
24882 + err = au_ren_may_dir(a);
24883 + if (unlikely(err))
24884 + goto out_children;
24886 + /* prepare the writable parent dir on the same branch */
24887 + if (a->dst_btop == a->btgt) {
24888 + au_fset_ren(a->auren_flags, WHDST);
24890 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24891 + if (unlikely(err))
24892 + goto out_children;
24896 + if (!a->exchange) {
24897 + if (a->src_dir != a->dst_dir) {
24899 + * this temporary unlock is safe,
24900 + * because both dir->i_mutex are locked.
24902 + di_write_unlock(a->dst_parent);
24903 + di_write_lock_parent(a->src_parent);
24904 + err = au_wr_dir_need_wh(a->src_dentry,
24905 + au_ftest_ren(a->auren_flags,
24908 + di_write_unlock(a->src_parent);
24909 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24911 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24913 + err = au_wr_dir_need_wh(a->src_dentry,
24914 + au_ftest_ren(a->auren_flags,
24918 + if (unlikely(err < 0))
24919 + goto out_children;
24921 + au_fset_ren(a->auren_flags, WHSRC);
24924 + if (a->src_btop != a->btgt) {
24925 + err = au_pin(&pin, a->src_dentry, a->btgt,
24926 + au_opt_udba(a->src_dentry->d_sb),
24927 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24929 + struct au_cp_generic cpg = {
24930 + .dentry = a->src_dentry,
24932 + .bsrc = a->src_btop,
24935 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24937 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24938 + err = au_sio_cpup_simple(&cpg);
24941 + if (unlikely(err))
24942 + goto out_children;
24943 + a->src_btop = a->btgt;
24944 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24945 + if (!a->exchange)
24946 + au_fset_ren(a->auren_flags, WHSRC);
24950 + if (a->exchange && a->dst_inode
24951 + && a->dst_btop != a->btgt) {
24952 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24953 + au_opt_udba(a->dst_dentry->d_sb),
24954 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24956 + struct au_cp_generic cpg = {
24957 + .dentry = a->dst_dentry,
24959 + .bsrc = a->dst_btop,
24962 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24964 + err = au_sio_cpup_simple(&cpg);
24967 + if (unlikely(err))
24968 + goto out_children;
24969 + a->dst_btop = a->btgt;
24970 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24973 + /* lock them all */
24974 + err = au_ren_lock(a);
24975 + if (unlikely(err))
24976 + /* leave the copied-up one */
24977 + goto out_children;
24979 + if (!a->exchange) {
24980 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24981 + err = au_may_ren(a);
24982 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24983 + err = -ENAMETOOLONG;
24984 + if (unlikely(err))
24988 + /* store timestamps to be revertible */
24991 + /* store dirren info */
24992 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24993 + err = au_dr_rename(a->src_dentry, a->btgt,
24994 + &a->dst_dentry->d_name, &rev);
24996 + if (unlikely(err))
25001 + err = do_rename(a);
25002 + if (unlikely(err))
25005 + if (au_ftest_ren(a->auren_flags, DIRREN))
25006 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
25008 + /* update dir attributes */
25009 + au_ren_refresh_dir(a);
25011 + /* dput/iput all lower dentries */
25012 + au_ren_refresh(a);
25014 + goto out_hdir; /* success */
25017 + if (au_ftest_ren(a->auren_flags, DIRREN))
25018 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
25020 + au_ren_rev_dt(err, a);
25022 + au_ren_unlock(a);
25024 + au_nhash_wh_free(&a->whlist);
25025 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
25026 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
25027 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
25028 + au_set_dbtop(a->dst_dentry, a->dst_btop);
25032 + if (d_unhashed(a->src_dentry))
25033 + au_fset_ren(a->auren_flags, DROPPED_SRC);
25034 + if (d_unhashed(a->dst_dentry))
25035 + au_fset_ren(a->auren_flags, DROPPED_DST);
25036 + if (!a->exchange)
25037 + d_move(a->src_dentry, a->dst_dentry);
25039 + d_exchange(a->src_dentry, a->dst_dentry);
25040 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
25041 + d_drop(a->dst_dentry);
25043 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
25044 + d_drop(a->src_dentry);
25046 + au_update_dbtop(a->dst_dentry);
25047 + if (!a->dst_inode)
25048 + d_drop(a->dst_dentry);
25050 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25051 + di_write_unlock(a->dst_parent);
25053 + di_write_unlock2(a->src_parent, a->dst_parent);
25055 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25057 + iput(a->dst_inode);
25059 + au_whtmp_rmdir_free(a->thargs);
25065 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25066 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25067 +++ linux/fs/aufs/Kconfig 2024-05-13 17:13:00.614737564 +0200
25069 +# SPDX-License-Identifier: GPL-2.0
25071 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25073 + Aufs is a stackable unification filesystem such as Unionfs,
25074 + which unifies several directories and provides a merged single
25076 + In the early days, aufs was entirely re-designed and
25077 + re-implemented Unionfs Version 1.x series. Introducing many
25078 + original ideas, approaches and improvements, it becomes totally
25079 + different from Unionfs while keeping the basic features.
25083 + prompt "Maximum number of branches"
25084 + default AUFS_BRANCH_MAX_127
25086 + Specifies the maximum number of branches (or member directories)
25087 + in a single aufs. The larger value consumes more system
25088 + resources and has a minor impact to performance.
25089 +config AUFS_BRANCH_MAX_127
25092 + Specifies the maximum number of branches (or member directories)
25093 + in a single aufs. The larger value consumes more system
25094 + resources and has a minor impact to performance.
25095 +config AUFS_BRANCH_MAX_511
25098 + Specifies the maximum number of branches (or member directories)
25099 + in a single aufs. The larger value consumes more system
25100 + resources and has a minor impact to performance.
25101 +config AUFS_BRANCH_MAX_1023
25104 + Specifies the maximum number of branches (or member directories)
25105 + in a single aufs. The larger value consumes more system
25106 + resources and has a minor impact to performance.
25107 +config AUFS_BRANCH_MAX_32767
25110 + Specifies the maximum number of branches (or member directories)
25111 + in a single aufs. The larger value consumes more system
25112 + resources and has a minor impact to performance.
25115 +config AUFS_SBILIST
25117 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25120 + Automatic configuration for internal use.
25121 + When aufs supports Magic SysRq or /proc, enabled automatically.
25123 +config AUFS_HNOTIFY
25124 + bool "Detect direct branch access (bypassing aufs)"
25126 + If you want to modify files on branches directly, eg. bypassing aufs,
25127 + and want aufs to detect the changes of them fully, then enable this
25128 + option and use 'udba=notify' mount option.
25129 + Currently there is only one available configuration, "fsnotify".
25130 + It will have a negative impact to the performance.
25131 + See detail in aufs.5.
25134 + prompt "method" if AUFS_HNOTIFY
25135 + default AUFS_HFSNOTIFY
25136 +config AUFS_HFSNOTIFY
25141 +config AUFS_EXPORT
25142 + bool "NFS-exportable aufs"
25143 + depends on EXPORTFS
25145 + If you want to export your mounted aufs via NFS, then enable this
25146 + option. There are several requirements for this configuration.
25147 + See detail in aufs.5.
25149 +config AUFS_INO_T_64
25151 + depends on AUFS_EXPORT
25152 + depends on 64BIT && !(ALPHA || S390)
25155 + Automatic configuration for internal use.
25156 + /* typedef unsigned long/int __kernel_ino_t */
25157 + /* alpha and s390x are int */
25160 + bool "support for XATTR/EA (including Security Labels)"
25162 + If your branch fs supports XATTR/EA and you want to make them
25163 + available in aufs too, then enable this opsion and specify the
25164 + branch attributes for EA.
25165 + See detail in aufs.5.
25168 + bool "File-based Hierarchical Storage Management"
25170 + Hierarchical Storage Management (or HSM) is a well-known feature
25171 + in the storage world. Aufs provides this feature as file-based.
25172 + with multiple branches.
25173 + These multiple branches are prioritized, ie. the topmost one
25174 + should be the fastest drive and be used heavily.
25177 + bool "Readdir in userspace"
25179 + Aufs has two methods to provide a merged view for a directory,
25180 + by a user-space library and by kernel-space natively. The latter
25181 + is always enabled but sometimes large and slow.
25182 + If you enable this option, install the library in aufs2-util
25183 + package, and set some environment variables for your readdir(3),
25184 + then the work will be handled in user-space which generally
25185 + shows better performance in most cases.
25186 + See detail in aufs.5.
25188 +config AUFS_DIRREN
25189 + bool "Workaround for rename(2)-ing a directory"
25191 + By default, aufs returns EXDEV error in renameing a dir who has
25192 + his child on the lower branch, since it is a bad idea to issue
25193 + rename(2) internally for every lower branch. But user may not
25194 + accept this behaviour. So here is a workaround to allow such
25195 + rename(2) and store some extra information on the writable
25196 + branch. Obviously this costs high (and I don't like it).
25197 + To use this feature, you need to enable this configuration AND
25198 + to specify the mount option `dirren.'
25199 + See details in aufs.5 and the design documents.
25202 + bool "Show whiteouts"
25204 + If you want to make the whiteouts in aufs visible, then enable
25205 + this option and specify 'shwh' mount option. Although it may
25206 + sounds like philosophy or something, but in technically it
25207 + simply shows the name of whiteout with keeping its behaviour.
25209 +config AUFS_BR_RAMFS
25210 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25212 + If you want to use ramfs as an aufs branch fs, then enable this
25213 + option. Generally tmpfs is recommended.
25214 + Aufs prohibited them to be a branch fs by default, because
25215 + initramfs becomes unusable after switch_root or something
25216 + generally. If you sets initramfs as an aufs branch and boot your
25217 + system by switch_root, you will meet a problem easily since the
25218 + files in initramfs may be inaccessible.
25219 + Unless you are going to use ramfs as an aufs branch fs without
25220 + switch_root or something, leave it N.
25222 +config AUFS_BR_FUSE
25223 + bool "Fuse fs as an aufs branch"
25224 + depends on FUSE_FS
25227 + If you want to use fuse-based userspace filesystem as an aufs
25228 + branch fs, then enable this option.
25229 + It implements the internal poll(2) operation which is
25230 + implemented by fuse only (curretnly).
25235 + Automatic configuration for internal use.
25237 +config AUFS_BR_HFSPLUS
25238 + bool "Hfsplus as an aufs branch"
25239 + depends on HFSPLUS_FS
25242 + If you want to use hfsplus fs as an aufs branch fs, then enable
25243 + this option. This option introduces a small overhead at
25244 + copying-up a file on hfsplus.
25246 +config AUFS_BDEV_LOOP
25248 + depends on BLK_DEV_LOOP
25251 + Automatic configuration for internal use.
25252 + Convert =[ym] into =y.
25255 + bool "Debug aufs"
25257 + Enable this to compile aufs internal debug code.
25258 + It will have a negative impact to the performance.
25260 +config AUFS_MAGIC_SYSRQ
25262 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25265 + Automatic configuration for internal use.
25266 + When aufs supports Magic SysRq, enabled automatically.
25268 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25269 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25270 +++ linux/fs/aufs/lcnt.h 2024-05-13 17:13:00.621404284 +0200
25272 +/* SPDX-License-Identifier: GPL-2.0 */
25274 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25276 + * This program is free software; you can redistribute it and/or modify
25277 + * it under the terms of the GNU General Public License as published by
25278 + * the Free Software Foundation; either version 2 of the License, or
25279 + * (at your option) any later version.
25281 + * This program is distributed in the hope that it will be useful,
25282 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25283 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25284 + * GNU General Public License for more details.
25286 + * You should have received a copy of the GNU General Public License
25287 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25291 + * simple long counter wrapper
25294 +#ifndef __AUFS_LCNT_H__
25295 +#define __AUFS_LCNT_H__
25299 +#include "debug.h"
25301 +#define AuLCntATOMIC 1
25302 +#define AuLCntPCPUCNT 2
25304 + * why does percpu_refcount require extra synchronize_rcu()s in
25305 + * au_br_do_free()
25307 +#define AuLCntPCPUREF 3
25309 +/* #define AuLCntChosen AuLCntATOMIC */
25310 +#define AuLCntChosen AuLCntPCPUCNT
25311 +/* #define AuLCntChosen AuLCntPCPUREF */
25313 +#if AuLCntChosen == AuLCntATOMIC
25314 +#include <linux/atomic.h>
25316 +typedef atomic_long_t au_lcnt_t;
25318 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25320 + atomic_long_set(cnt, 0);
25324 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25329 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25330 + int do_sync __maybe_unused)
25335 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25337 + atomic_long_inc(cnt);
25340 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25342 + atomic_long_dec(cnt);
25345 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25347 + return atomic_long_read(cnt);
25351 +#if AuLCntChosen == AuLCntPCPUCNT
25352 +#include <linux/percpu_counter.h>
25354 +typedef struct percpu_counter au_lcnt_t;
25356 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25358 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25361 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25366 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25368 + percpu_counter_destroy(cnt);
25371 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25373 + percpu_counter_inc(cnt);
25376 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25378 + percpu_counter_dec(cnt);
25381 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25385 + n = percpu_counter_sum(cnt);
25387 + if (LONG_MAX != LLONG_MAX
25389 + AuWarn1("%s\n", "wrap-around");
25395 +#if AuLCntChosen == AuLCntPCPUREF
25396 +#include <linux/percpu-refcount.h>
25398 +typedef struct percpu_ref au_lcnt_t;
25400 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25403 + release = percpu_ref_exit;
25404 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25407 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25409 + synchronize_rcu();
25412 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25414 + percpu_ref_kill(cnt);
25416 + au_lcnt_wait_for_fin(cnt);
25419 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25421 + percpu_ref_get(cnt);
25424 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25426 + percpu_ref_put(cnt);
25430 + * avoid calling this func as possible.
25432 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25436 + percpu_ref_switch_to_atomic_sync(cnt);
25437 + l = atomic_long_read(&cnt->count);
25439 + percpu_ref_switch_to_percpu(cnt);
25441 + /* percpu_ref is initialized by 1 instead of 0 */
25446 +#ifdef CONFIG_AUFS_DEBUG
25447 +#define AuLCntZero(val) do { \
25450 + AuDbg("%s = %ld\n", #val, l); \
25453 +#define AuLCntZero(val) do {} while (0)
25456 +#endif /* __KERNEL__ */
25457 +#endif /* __AUFS_LCNT_H__ */
25458 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25459 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25460 +++ linux/fs/aufs/loop.c 2024-05-13 17:13:00.621404284 +0200
25462 +// SPDX-License-Identifier: GPL-2.0
25464 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25466 + * This program is free software; you can redistribute it and/or modify
25467 + * it under the terms of the GNU General Public License as published by
25468 + * the Free Software Foundation; either version 2 of the License, or
25469 + * (at your option) any later version.
25471 + * This program is distributed in the hope that it will be useful,
25472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25474 + * GNU General Public License for more details.
25476 + * You should have received a copy of the GNU General Public License
25477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25481 + * support for loopback block device as a branch
25486 +/* added into drivers/block/loop.c */
25487 +static struct file *(*backing_file_func)(struct super_block *sb);
25490 + * test if two lower dentries have overlapping branches.
25492 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25494 + struct super_block *h_sb;
25495 + struct file *backing_file;
25497 + if (unlikely(!backing_file_func)) {
25498 + /* don't load "loop" module here */
25499 + backing_file_func = symbol_get(loop_backing_file);
25500 + if (unlikely(!backing_file_func))
25501 + /* "loop" module is not loaded */
25505 + h_sb = h_adding->d_sb;
25506 + backing_file = backing_file_func(h_sb);
25507 + if (!backing_file)
25510 + h_adding = backing_file->f_path.dentry;
25512 + * h_adding can be local NFS.
25513 + * in this case aufs cannot detect the loop.
25515 + if (unlikely(h_adding->d_sb == sb))
25517 + return !!au_test_subdir(h_adding, sb->s_root);
25520 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25521 +int au_test_loopback_kthread(void)
25524 + struct task_struct *tsk = current;
25525 + char c, comm[sizeof(tsk->comm)];
25528 + if (tsk->flags & PF_KTHREAD) {
25529 + get_task_comm(comm, tsk);
25531 + ret = ('0' <= c && c <= '9'
25532 + && !strncmp(comm, "loop", 4));
25538 +/* ---------------------------------------------------------------------- */
25540 +#define au_warn_loopback_step 16
25541 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25542 +static unsigned long *au_warn_loopback_array;
25544 +void au_warn_loopback(struct super_block *h_sb)
25546 + int i, new_nelem;
25547 + unsigned long *a, magic;
25548 + static DEFINE_SPINLOCK(spin);
25550 + magic = h_sb->s_magic;
25551 + spin_lock(&spin);
25552 + a = au_warn_loopback_array;
25553 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25554 + if (a[i] == magic) {
25555 + spin_unlock(&spin);
25559 + /* h_sb is new to us, print it */
25560 + if (i < au_warn_loopback_nelem) {
25565 + /* expand the array */
25566 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25567 + a = au_kzrealloc(au_warn_loopback_array,
25568 + au_warn_loopback_nelem * sizeof(unsigned long),
25569 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25570 + /*may_shrink*/0);
25572 + au_warn_loopback_nelem = new_nelem;
25573 + au_warn_loopback_array = a;
25578 + spin_unlock(&spin);
25579 + AuWarn1("realloc failed, ignored\n");
25583 + spin_unlock(&spin);
25584 + pr_warn("you may want to try another patch for loopback file "
25585 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25588 +int au_loopback_init(void)
25591 + struct super_block *sb __maybe_unused;
25593 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25596 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25597 + sizeof(unsigned long), GFP_NOFS);
25598 + if (unlikely(!au_warn_loopback_array))
25604 +void au_loopback_fin(void)
25606 + if (backing_file_func)
25607 + symbol_put(loop_backing_file);
25608 + au_kfree_try_rcu(au_warn_loopback_array);
25610 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25611 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25612 +++ linux/fs/aufs/loop.h 2024-05-13 17:13:00.621404284 +0200
25614 +/* SPDX-License-Identifier: GPL-2.0 */
25616 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25618 + * This program is free software; you can redistribute it and/or modify
25619 + * it under the terms of the GNU General Public License as published by
25620 + * the Free Software Foundation; either version 2 of the License, or
25621 + * (at your option) any later version.
25623 + * This program is distributed in the hope that it will be useful,
25624 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25625 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25626 + * GNU General Public License for more details.
25628 + * You should have received a copy of the GNU General Public License
25629 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25633 + * support for loopback mount as a branch
25636 +#ifndef __AUFS_LOOP_H__
25637 +#define __AUFS_LOOP_H__
25642 +struct super_block;
25644 +#ifdef CONFIG_AUFS_BDEV_LOOP
25645 +/* drivers/block/loop.c */
25646 +struct file *loop_backing_file(struct super_block *sb);
25649 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25650 +int au_test_loopback_kthread(void);
25651 +void au_warn_loopback(struct super_block *h_sb);
25653 +int au_loopback_init(void);
25654 +void au_loopback_fin(void);
25656 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25658 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25659 + struct dentry *h_adding)
25660 +AuStubInt0(au_test_loopback_kthread, void)
25661 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25663 +AuStubInt0(au_loopback_init, void)
25664 +AuStubVoid(au_loopback_fin, void)
25665 +#endif /* BLK_DEV_LOOP */
25667 +#endif /* __KERNEL__ */
25668 +#endif /* __AUFS_LOOP_H__ */
25669 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25670 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25671 +++ linux/fs/aufs/magic.mk 2024-05-13 17:13:00.621404284 +0200
25673 +# SPDX-License-Identifier: GPL-2.0
25675 +# defined in ${srctree}/fs/fuse/inode.c
25677 +ifdef CONFIG_FUSE_FS
25678 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25681 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25683 +ifdef CONFIG_XFS_FS
25684 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25687 +# defined in ${srctree}/fs/configfs/mount.c
25689 +ifdef CONFIG_CONFIGFS_FS
25690 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25693 +# defined in ${srctree}/fs/ubifs/ubifs.h
25695 +ifdef CONFIG_UBIFS_FS
25696 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25699 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25701 +ifdef CONFIG_HFSPLUS_FS
25702 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25704 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25705 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25706 +++ linux/fs/aufs/Makefile 2024-05-13 17:13:00.614737564 +0200
25708 +# SPDX-License-Identifier: GPL-2.0
25710 +include ${src}/magic.mk
25711 +ifeq (${CONFIG_AUFS_FS},m)
25712 +include ${src}/conf.mk
25714 +-include ${src}/priv_def.mk
25716 +# cf. include/linux/kernel.h
25718 +ccflags-y += -DDEBUG
25719 +# sparse requires the full pathname
25721 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25723 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25726 +obj-$(CONFIG_AUFS_FS) += aufs.o
25727 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25728 + wkq.o vfsub.o dcsub.o \
25729 + cpup.o whout.o wbr_policy.o \
25730 + dinfo.o dentry.o \
25732 + finfo.o file.o f_op.o \
25734 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25738 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25739 +aufs-$(CONFIG_SYSFS) += sysfs.o
25740 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25741 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25742 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25743 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25744 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25745 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25746 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25747 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25748 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25749 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25750 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25751 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25752 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25753 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25754 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25755 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25756 +++ linux/fs/aufs/module.c 2024-05-13 17:13:00.621404284 +0200
25758 +// SPDX-License-Identifier: GPL-2.0
25760 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25762 + * This program is free software; you can redistribute it and/or modify
25763 + * it under the terms of the GNU General Public License as published by
25764 + * the Free Software Foundation; either version 2 of the License, or
25765 + * (at your option) any later version.
25767 + * This program is distributed in the hope that it will be useful,
25768 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25769 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25770 + * GNU General Public License for more details.
25772 + * You should have received a copy of the GNU General Public License
25773 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25777 + * module global variables and operations
25780 +#include <linux/module.h>
25781 +#include <linux/seq_file.h>
25784 +/* shrinkable realloc */
25785 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25793 +#if 0 /* unused */
25800 + AuDebugOn(!new_sz);
25803 + diff = au_kmidx_sub(sz, new_sz);
25809 + /* expand or SLOB */
25810 + p = krealloc(p, new_sz, gfp);
25811 + else if (new_sz < sz && may_shrink) {
25815 + q = kmalloc(new_sz, gfp);
25818 + memcpy(q, p, new_sz);
25819 + au_kfree_try_rcu(p);
25830 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25833 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25834 + if (p && new_sz > nused)
25835 + memset(p + nused, 0, new_sz - nused);
25839 +/* ---------------------------------------------------------------------- */
25843 +struct kmem_cache *au_cache[AuCache_Last];
25845 +static void au_cache_fin(void)
25850 + * Make sure all delayed rcu free inodes are flushed before we
25855 + /* excluding AuCache_HNOTIFY */
25856 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25857 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25858 + kmem_cache_destroy(au_cache[i]);
25859 + au_cache[i] = NULL;
25863 +static int __init au_cache_init(void)
25865 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25866 + if (au_cache[AuCache_DINFO])
25867 + /* SLAB_DESTROY_BY_RCU */
25868 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25869 + au_icntnr_init_once);
25870 + if (au_cache[AuCache_ICNTNR])
25871 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25872 + au_fi_init_once);
25873 + if (au_cache[AuCache_FINFO])
25874 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25875 + if (au_cache[AuCache_VDIR])
25876 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25877 + if (au_cache[AuCache_DEHSTR])
25884 +/* ---------------------------------------------------------------------- */
25886 +int au_dir_roflags;
25888 +#ifdef CONFIG_AUFS_SBILIST
25890 + * iterate_supers_type() doesn't protect us from
25891 + * remounting (branch management)
25893 +struct hlist_bl_head au_sbilist;
25897 + * functions for module interface.
25899 +MODULE_LICENSE("GPL");
25900 +/* MODULE_LICENSE("GPL v2"); */
25901 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25902 +MODULE_DESCRIPTION(AUFS_NAME
25903 + " -- Advanced multi layered unification filesystem");
25904 +MODULE_VERSION(AUFS_VERSION);
25905 +MODULE_ALIAS_FS(AUFS_NAME);
25907 +/* this module parameter has no meaning when SYSFS is disabled */
25908 +int sysaufs_brs = 1;
25909 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25910 +module_param_named(brs, sysaufs_brs, int, 0444);
25912 +/* this module parameter has no meaning when USER_NS is disabled */
25914 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25915 +module_param_named(allow_userns, au_userns, bool, 0444);
25917 +/* ---------------------------------------------------------------------- */
25919 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25921 +int au_seq_path(struct seq_file *seq, struct path *path)
25925 + err = seq_path(seq, path, au_esc_chars);
25934 +/* ---------------------------------------------------------------------- */
25936 +static int __init aufs_init(void)
25941 + p = au_esc_chars;
25942 + for (i = 1; i <= ' '; i++)
25948 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25950 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25951 + for (i = 0; i < AuIop_Last; i++)
25952 + aufs_iop_nogetattr[i].getattr = NULL;
25954 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25956 + au_sbilist_init();
25957 + sysaufs_brs_init();
25960 + err = sysaufs_init();
25961 + if (unlikely(err))
25963 + err = dbgaufs_init();
25964 + if (unlikely(err))
25965 + goto out_sysaufs;
25966 + err = au_procfs_init();
25967 + if (unlikely(err))
25968 + goto out_dbgaufs;
25969 + err = au_wkq_init();
25970 + if (unlikely(err))
25972 + err = au_loopback_init();
25973 + if (unlikely(err))
25975 + err = au_hnotify_init();
25976 + if (unlikely(err))
25977 + goto out_loopback;
25978 + err = au_sysrq_init();
25979 + if (unlikely(err))
25981 + err = au_cache_init();
25982 + if (unlikely(err))
25985 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25986 + err = register_filesystem(&aufs_fs_type);
25987 + if (unlikely(err))
25990 + /* since we define pr_fmt, call printk directly */
25991 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25992 + goto out; /* success */
25999 + au_hnotify_fin();
26001 + au_loopback_fin();
26015 +static void __exit aufs_exit(void)
26017 + unregister_filesystem(&aufs_fs_type);
26020 + au_hnotify_fin();
26021 + au_loopback_fin();
26029 +module_init(aufs_init);
26030 +module_exit(aufs_exit);
26031 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
26032 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
26033 +++ linux/fs/aufs/module.h 2024-05-13 17:13:00.621404284 +0200
26035 +/* SPDX-License-Identifier: GPL-2.0 */
26037 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26039 + * This program is free software; you can redistribute it and/or modify
26040 + * it under the terms of the GNU General Public License as published by
26041 + * the Free Software Foundation; either version 2 of the License, or
26042 + * (at your option) any later version.
26044 + * This program is distributed in the hope that it will be useful,
26045 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26047 + * GNU General Public License for more details.
26049 + * You should have received a copy of the GNU General Public License
26050 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26054 + * module initialization and module-global
26057 +#ifndef __AUFS_MODULE_H__
26058 +#define __AUFS_MODULE_H__
26062 +#include <linux/slab.h>
26063 +#include "debug.h"
26064 +#include "dentry.h"
26067 +#include "inode.h"
26072 +/* module parameters */
26073 +extern int sysaufs_brs;
26074 +extern bool au_userns;
26076 +/* ---------------------------------------------------------------------- */
26078 +extern int au_dir_roflags;
26080 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26081 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26085 + * Comparing the size of the object with sizeof(struct rcu_head)
26086 + * case 1: object is always larger
26087 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26088 + * case 2: object is always smaller
26089 + * --> au_kfree_small()
26090 + * case 3: object can be any size
26091 + * --> au_kfree_try_rcu()
26094 +static inline void au_kfree_do_rcu(const void *p)
26097 + struct rcu_head rcu;
26098 + } *a = (void *)p;
26100 + kfree_rcu(a, rcu);
26103 +#define au_kfree_rcu(_p) do { \
26104 + typeof(_p) p = (_p); \
26105 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26107 + au_kfree_do_rcu(p); \
26110 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26111 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26113 +static inline void au_kfree_try_rcu(const void *p)
26117 + if (au_kfree_sz_test(p))
26118 + au_kfree_do_rcu(p);
26123 +static inline void au_kfree_small(const void *p)
26127 + AuDebugOn(au_kfree_sz_test(p));
26131 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26133 +#ifndef CONFIG_SLOB
26134 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26136 + return -1; /* SLOB is untested */
26140 +int au_seq_path(struct seq_file *seq, struct path *path);
26142 +#ifdef CONFIG_PROC_FS
26144 +int __init au_procfs_init(void);
26145 +void au_procfs_fin(void);
26147 +AuStubInt0(au_procfs_init, void);
26148 +AuStubVoid(au_procfs_fin, void);
26151 +/* ---------------------------------------------------------------------- */
26160 + AuCache_HNOTIFY, /* must be last */
26164 +extern struct kmem_cache *au_cache[AuCache_Last];
26166 +#define AuCacheFlags SLAB_RECLAIM_ACCOUNT
26167 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26168 +#define AuCacheCtor(type, ctor) \
26169 + kmem_cache_create(#type, sizeof(struct type), \
26170 + __alignof__(struct type), AuCacheFlags, ctor)
26172 +#define AuCacheFuncAlloc(name, index) \
26173 + static inline struct au_##name *au_cache_alloc_##name(void) \
26174 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26176 +#define AuCacheFuncs(name, index) \
26177 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26178 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26180 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26181 + { void *p = rcu; \
26182 + p -= offsetof(struct au_##name, rcu); \
26183 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26184 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26185 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26186 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26188 + static inline void au_cache_free_##name(struct au_##name *p) \
26189 + { /* au_cache_free_##name##_norcu(p); */ \
26190 + au_cache_free_##name##_rcu(p); }
26192 +AuCacheFuncs(dinfo, DINFO);
26193 +AuCacheFuncAlloc(dinfo, DINFO);
26195 +AuCacheFuncs(icntnr, ICNTNR);
26196 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26197 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26199 +AuCacheFuncs(finfo, FINFO);
26200 +AuCacheFuncAlloc(finfo, FINFO);
26202 +AuCacheFuncs(vdir, VDIR);
26203 +AuCacheFuncAlloc(vdir, VDIR);
26205 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26206 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26208 +#ifdef CONFIG_AUFS_HNOTIFY
26209 +AuCacheFuncs(hnotify, HNOTIFY);
26210 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26213 +#endif /* __KERNEL__ */
26214 +#endif /* __AUFS_MODULE_H__ */
26215 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26216 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26217 +++ linux/fs/aufs/mvdown.c 2024-05-13 17:13:00.621404284 +0200
26219 +// SPDX-License-Identifier: GPL-2.0
26221 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26223 + * This program is free software; you can redistribute it and/or modify
26224 + * it under the terms of the GNU General Public License as published by
26225 + * the Free Software Foundation; either version 2 of the License, or
26226 + * (at your option) any later version.
26228 + * This program is distributed in the hope that it will be useful,
26229 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26230 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26231 + * GNU General Public License for more details.
26233 + * You should have received a copy of the GNU General Public License
26234 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26238 + * move-down, opposite of copy-up
26243 +struct au_mvd_args {
26245 + struct super_block *h_sb;
26246 + struct dentry *h_parent;
26247 + struct au_hinode *hdir;
26248 + struct inode *h_dir, *h_inode;
26249 + struct au_pin pin;
26250 + } info[AUFS_MVDOWN_NARRAY];
26252 + struct aufs_mvdown mvdown;
26253 + struct dentry *dentry, *parent;
26254 + struct inode *inode, *dir;
26255 + struct super_block *sb;
26256 + aufs_bindex_t bopq, bwh, bfound;
26257 + unsigned char rename_lock;
26260 +#define mvd_errno mvdown.au_errno
26261 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26262 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26263 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26264 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26266 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26267 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26268 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26269 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26270 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26271 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26273 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26274 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26275 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26276 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26277 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26278 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26280 +#define AU_MVD_PR(flag, ...) do { \
26282 + pr_err(__VA_ARGS__); \
26285 +static int find_lower_writable(struct au_mvd_args *a)
26287 + struct super_block *sb;
26288 + aufs_bindex_t bindex, bbot;
26289 + struct au_branch *br;
26292 + bindex = a->mvd_bsrc;
26293 + bbot = au_sbbot(sb);
26294 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26295 + for (bindex++; bindex <= bbot; bindex++) {
26296 + br = au_sbr(sb, bindex);
26297 + if (au_br_fhsm(br->br_perm)
26298 + && !sb_rdonly(au_br_sb(br)))
26301 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26302 + for (bindex++; bindex <= bbot; bindex++) {
26303 + br = au_sbr(sb, bindex);
26304 + if (!au_br_rdonly(br))
26308 + for (bindex++; bindex <= bbot; bindex++) {
26309 + br = au_sbr(sb, bindex);
26310 + if (!sb_rdonly(au_br_sb(br))) {
26311 + if (au_br_rdonly(br))
26313 + |= AUFS_MVDOWN_ROLOWER_R;
26321 +/* make the parent dir on bdst */
26322 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26327 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26328 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26329 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26330 + a->mvd_h_dst_parent = NULL;
26331 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26332 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26333 + if (!a->mvd_h_dst_parent) {
26334 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26335 + if (unlikely(err)) {
26336 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26339 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26347 +/* lock them all */
26348 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26351 + struct dentry *h_trap;
26353 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26354 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26355 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26356 + au_opt_udba(a->sb),
26357 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26359 + if (unlikely(err)) {
26360 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26364 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26365 + a->rename_lock = 0;
26366 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26367 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26368 + au_opt_udba(a->sb),
26369 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26370 + err = au_do_pin(&a->mvd_pin_src);
26372 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26373 + if (unlikely(err)) {
26374 + AU_MVD_PR(dmsg, "pin_src failed\n");
26377 + goto out; /* success */
26380 + a->rename_lock = 1;
26381 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26382 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26383 + au_opt_udba(a->sb),
26384 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26386 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26387 + if (unlikely(err)) {
26388 + AU_MVD_PR(dmsg, "pin_src failed\n");
26389 + au_pin_hdir_lock(&a->mvd_pin_dst);
26392 + au_pin_hdir_unlock(&a->mvd_pin_src);
26393 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26394 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26395 + if (IS_ERR(h_trap)) {
26396 + err = PTR_ERR(h_trap);
26397 + au_pin_hdir_lock(&a->mvd_pin_src);
26398 + au_unpin(&a->mvd_pin_src);
26399 + au_pin_hdir_lock(&a->mvd_pin_dst);
26403 + err = (h_trap != a->mvd_h_src_parent);
26405 + err = (h_trap != a->mvd_h_dst_parent);
26407 + BUG_ON(err); /* it should never happen */
26408 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26411 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26412 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26413 + au_pin_hdir_lock(&a->mvd_pin_src);
26414 + au_unpin(&a->mvd_pin_src);
26415 + au_pin_hdir_lock(&a->mvd_pin_dst);
26418 + goto out; /* success */
26421 + au_unpin(&a->mvd_pin_dst);
26427 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26429 + if (!a->rename_lock)
26430 + au_unpin(&a->mvd_pin_src);
26432 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26433 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26434 + au_pin_hdir_lock(&a->mvd_pin_src);
26435 + au_unpin(&a->mvd_pin_src);
26436 + au_pin_hdir_lock(&a->mvd_pin_dst);
26438 + au_unpin(&a->mvd_pin_dst);
26441 +/* copy-down the file */
26442 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26445 + struct au_cp_generic cpg = {
26446 + .dentry = a->dentry,
26447 + .bdst = a->mvd_bdst,
26448 + .bsrc = a->mvd_bsrc,
26450 + .pin = &a->mvd_pin_dst,
26451 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26454 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26455 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26456 + au_fset_cpup(cpg.flags, OVERWRITE);
26457 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26458 + au_fset_cpup(cpg.flags, RWDST);
26459 + err = au_sio_cpdown_simple(&cpg);
26460 + if (unlikely(err))
26461 + AU_MVD_PR(dmsg, "cpdown failed\n");
26468 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26471 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26474 + struct path h_path;
26475 + struct au_branch *br;
26476 + struct inode *delegated;
26478 + br = au_sbr(a->sb, a->mvd_bdst);
26479 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26480 + err = PTR_ERR(h_path.dentry);
26481 + if (IS_ERR(h_path.dentry)) {
26482 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26487 + if (d_is_positive(h_path.dentry)) {
26488 + h_path.mnt = au_br_mnt(br);
26489 + delegated = NULL;
26490 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26491 + &delegated, /*force*/0);
26492 + if (unlikely(err == -EWOULDBLOCK)) {
26493 + pr_warn("cannot retry for NFSv4 delegation"
26494 + " for an internal unlink\n");
26497 + if (unlikely(err))
26498 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26500 + dput(h_path.dentry);
26508 + * unlink the topmost h_dentry
26510 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26513 + struct path h_path;
26514 + struct inode *delegated;
26516 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26517 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26518 + delegated = NULL;
26519 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26520 + if (unlikely(err == -EWOULDBLOCK)) {
26521 + pr_warn("cannot retry for NFSv4 delegation"
26522 + " for an internal unlink\n");
26525 + if (unlikely(err))
26526 + AU_MVD_PR(dmsg, "unlink failed\n");
26532 +/* Since mvdown succeeded, we ignore an error of this function */
26533 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26536 + struct au_branch *br;
26538 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26539 + br = au_sbr(a->sb, a->mvd_bsrc);
26540 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26542 + br = au_sbr(a->sb, a->mvd_bdst);
26543 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26544 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26547 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26549 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26553 + * copy-down the file and unlink the bsrc file.
26554 + * - unlink the bdst whout if exist
26555 + * - copy-down the file (with whtmp name and rename)
26556 + * - unlink the bsrc file
26558 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26562 + err = au_do_mkdir(dmsg, a);
26564 + err = au_do_lock(dmsg, a);
26565 + if (unlikely(err))
26569 + * do not revert the activities we made on bdst since they should be
26570 + * harmless in aufs.
26573 + err = au_do_cpdown(dmsg, a);
26575 + err = au_do_unlink_wh(dmsg, a);
26576 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26577 + err = au_do_unlink(dmsg, a);
26578 + if (unlikely(err))
26581 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26582 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26583 + if (find_lower_writable(a) < 0)
26584 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26586 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26587 + au_do_stfs(dmsg, a);
26589 + /* maintain internal array */
26590 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26591 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26592 + au_set_dbtop(a->dentry, a->mvd_bdst);
26593 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26594 + au_set_ibtop(a->inode, a->mvd_bdst);
26596 + /* hide the lower */
26597 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26598 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26599 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26600 + au_set_ibbot(a->inode, a->mvd_bsrc);
26602 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26603 + au_set_dbbot(a->dentry, a->mvd_bdst);
26604 + if (au_ibbot(a->inode) < a->mvd_bdst)
26605 + au_set_ibbot(a->inode, a->mvd_bdst);
26608 + au_do_unlock(dmsg, a);
26614 +/* ---------------------------------------------------------------------- */
26616 +/* make sure the file is idle */
26617 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26619 + int err, plinked;
26622 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26623 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26624 + && au_dcount(a->dentry) == 1
26625 + && atomic_read(&a->inode->i_count) == 1
26626 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26627 + && (!plinked || !au_plink_test(a->inode))
26628 + && a->inode->i_nlink == 1)
26633 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26634 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26635 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26636 + a->mvd_h_src_inode->i_nlink,
26637 + plinked, plinked ? au_plink_test(a->inode) : 0);
26644 +/* make sure the parent dir is fine */
26645 +static int au_mvd_args_parent(const unsigned char dmsg,
26646 + struct au_mvd_args *a)
26649 + aufs_bindex_t bindex;
26652 + if (unlikely(au_alive_dir(a->parent))) {
26654 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26658 + a->bopq = au_dbdiropq(a->parent);
26659 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26660 + AuDbg("b%d\n", bindex);
26661 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26662 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26664 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26665 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26666 + a->bopq, a->mvd_bdst);
26674 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26675 + struct au_mvd_args *a)
26678 + struct au_dinfo *dinfo, *tmp;
26680 + /* lookup the next lower positive entry */
26682 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26683 + if (unlikely(!tmp))
26688 + dinfo = au_di(a->dentry);
26689 + au_di_cp(tmp, dinfo);
26690 + au_di_swap(tmp, dinfo);
26692 + /* returns the number of positive dentries */
26693 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26694 + /* AuLkup_IGNORE_PERM */ 0);
26696 + a->bwh = au_dbwh(a->dentry);
26697 + else if (err > 0)
26698 + a->bfound = au_dbtop(a->dentry);
26700 + au_di_swap(tmp, dinfo);
26701 + au_rw_write_unlock(&tmp->di_rwsem);
26703 + if (unlikely(err < 0))
26704 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26707 + * here, we have these cases.
26709 + * no positive dentry under bsrc. there are more sub-cases.
26711 + * there no whiteout, we can safely move-down.
26714 + * bsrc < bwh && bwh < bdst
26715 + * there is a whiteout on RO branch. cannot proceed.
26717 + * there is a whiteout on the RW target branch. it should
26720 + * there is a whiteout somewhere unrelated branch.
26721 + * -1 < bfound && bfound <= bsrc
26724 + * found, but it is on RO branch between bsrc and bdst. cannot
26727 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26730 + * found, after we create the file on bdst, it will be hidden.
26733 + AuDebugOn(a->bfound == -1
26735 + && a->bwh <= a->mvd_bsrc);
26736 + AuDebugOn(-1 < a->bfound
26737 + && a->bfound <= a->mvd_bsrc);
26740 + if (a->bfound == -1
26741 + && a->mvd_bsrc < a->bwh
26743 + && a->bwh < a->mvd_bdst) {
26744 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26745 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26746 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26748 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26749 + a->mvd_errno = EAU_MVDOWN_UPPER;
26750 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26751 + a->mvd_bdst, a->bfound);
26755 + err = 0; /* success */
26762 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26767 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26768 + && a->bfound == a->mvd_bdst)
26774 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26777 + struct au_branch *br;
26780 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26784 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26785 + a->mvd_bsrc = au_ibtop(a->inode);
26787 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26788 + if (unlikely(a->mvd_bsrc < 0
26789 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26790 + || au_dbbot(a->dentry) < a->mvd_bsrc
26791 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26792 + || (a->mvd_bsrc < au_ibtop(a->inode)
26793 + || au_ibbot(a->inode) < a->mvd_bsrc
26794 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26795 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26796 + AU_MVD_PR(dmsg, "no upper\n");
26800 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26801 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26802 + AU_MVD_PR(dmsg, "on the bottom\n");
26805 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26806 + br = au_sbr(a->sb, a->mvd_bsrc);
26807 + err = au_br_rdonly(br);
26808 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26809 + if (unlikely(err))
26811 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26812 + || IS_APPEND(a->mvd_h_src_inode))) {
26814 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26820 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26821 + a->mvd_bdst = find_lower_writable(a);
26822 + if (unlikely(a->mvd_bdst < 0)) {
26823 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26824 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26828 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26829 + if (unlikely(a->mvd_bdst < 0
26830 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26831 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26832 + AU_MVD_PR(dmsg, "no lower brid\n");
26837 + err = au_mvd_args_busy(dmsg, a);
26839 + err = au_mvd_args_parent(dmsg, a);
26841 + err = au_mvd_args_intermediate(dmsg, a);
26843 + err = au_mvd_args_exist(dmsg, a);
26845 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26852 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26855 + unsigned char dmsg;
26856 + struct au_mvd_args *args;
26857 + struct inode *inode;
26859 + inode = d_inode(dentry);
26861 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26865 + args = kmalloc(sizeof(*args), GFP_NOFS);
26866 + if (unlikely(!args))
26869 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26871 + /* VERIFY_WRITE */
26872 + err = !access_ok(uarg, sizeof(*uarg));
26873 + if (unlikely(err)) {
26878 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26879 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26880 + args->mvdown.au_errno = 0;
26881 + args->dentry = dentry;
26882 + args->inode = inode;
26883 + args->sb = dentry->d_sb;
26886 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26887 + args->parent = dget_parent(dentry);
26888 + args->dir = d_inode(args->parent);
26889 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26890 + dput(args->parent);
26891 + if (unlikely(args->parent != dentry->d_parent)) {
26892 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26896 + inode_lock_nested(inode, I_MUTEX_CHILD);
26897 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26898 + if (unlikely(err))
26901 + di_write_lock_parent(args->parent);
26902 + err = au_mvd_args(dmsg, args);
26903 + if (unlikely(err))
26906 + err = au_do_mvdown(dmsg, args);
26907 + if (unlikely(err))
26910 + au_cpup_attr_timesizes(args->dir);
26911 + au_cpup_attr_timesizes(inode);
26912 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26913 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26914 + /* au_digen_dec(dentry); */
26917 + di_write_unlock(args->parent);
26918 + aufs_read_unlock(dentry, AuLock_DW);
26920 + inode_unlock(inode);
26922 + inode_unlock(args->dir);
26924 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26927 + au_kfree_rcu(args);
26932 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26933 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26934 +++ linux/fs/aufs/opts.c 2024-05-13 17:13:00.621404284 +0200
26936 +// SPDX-License-Identifier: GPL-2.0
26938 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26940 + * This program is free software; you can redistribute it and/or modify
26941 + * it under the terms of the GNU General Public License as published by
26942 + * the Free Software Foundation; either version 2 of the License, or
26943 + * (at your option) any later version.
26945 + * This program is distributed in the hope that it will be useful,
26946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26948 + * GNU General Public License for more details.
26950 + * You should have received a copy of the GNU General Public License
26951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26955 + * mount options/flags
26958 +#include <linux/types.h> /* a distribution requires */
26959 +#include <linux/parser.h>
26962 +/* ---------------------------------------------------------------------- */
26964 +static const char *au_parser_pattern(int val, match_table_t tbl)
26966 + struct match_token *p;
26969 + while (p->pattern) {
26970 + if (p->token == val)
26971 + return p->pattern;
26978 +static const char *au_optstr(int *val, match_table_t tbl)
26980 + struct match_token *p;
26987 + while (p->pattern) {
26989 + && (v & p->token) == p->token) {
26990 + *val &= ~p->token;
26991 + return p->pattern;
27000 +/* ---------------------------------------------------------------------- */
27002 +static match_table_t brperm = {
27003 + {AuBrPerm_RO, AUFS_BRPERM_RO},
27004 + {AuBrPerm_RR, AUFS_BRPERM_RR},
27005 + {AuBrPerm_RW, AUFS_BRPERM_RW},
27009 +static match_table_t brattr = {
27011 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
27012 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
27013 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
27014 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
27015 +#ifdef CONFIG_AUFS_FHSM
27016 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
27018 +#ifdef CONFIG_AUFS_XATTR
27019 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
27020 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
27021 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
27022 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
27023 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
27024 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
27027 + /* ro/rr branch */
27028 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
27031 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
27032 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
27037 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
27044 + p = strchr(str, '+');
27047 + v = match_token(str, table, args);
27049 + if (v & AuBrAttr_CMOO_Mask)
27050 + attr &= ~AuBrAttr_CMOO_Mask;
27055 + pr_warn("ignored branch attribute %s\n", str);
27065 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27073 + p = au_optstr(&perm, brattr);
27076 + memcpy(q, p, sz + 1);
27082 + p = au_optstr(&perm, brattr);
27086 + memcpy(q, p, sz + 1);
27092 + return q - str->a;
27095 +int au_br_perm_val(char *perm)
27097 + int val, bad, sz;
27099 + substring_t args[MAX_OPT_ARGS];
27100 + au_br_perm_str_t attr;
27102 + p = strchr(perm, '+');
27105 + val = match_token(perm, brperm, args);
27109 + pr_warn("ignored branch permission %s\n", perm);
27110 + val = AuBrPerm_RO;
27116 + val |= br_attr_val(p + 1, brattr, args);
27119 + switch (val & AuBrPerm_Mask) {
27120 + case AuBrPerm_RO:
27121 + case AuBrPerm_RR:
27122 + bad = val & AuBrWAttr_Mask;
27123 + val &= ~AuBrWAttr_Mask;
27125 + case AuBrPerm_RW:
27126 + bad = val & AuBrRAttr_Mask;
27127 + val &= ~AuBrRAttr_Mask;
27132 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27133 + * does not treat it as an error, just warning.
27134 + * this is a tiny guard for the user operation.
27136 + if (val & AuBrAttr_UNPIN) {
27137 + bad |= AuBrAttr_UNPIN;
27138 + val &= ~AuBrAttr_UNPIN;
27141 + if (unlikely(bad)) {
27142 + sz = au_do_optstr_br_attr(&attr, bad);
27144 + pr_warn("ignored branch attribute %s\n", attr.a);
27151 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27153 + au_br_perm_str_t attr;
27159 + p = au_optstr(&perm, brperm);
27160 + AuDebugOn(!p || !*p);
27162 + memcpy(q, p, sz + 1);
27165 + sz = au_do_optstr_br_attr(&attr, perm);
27168 + memcpy(q, attr.a, sz + 1);
27171 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27174 +/* ---------------------------------------------------------------------- */
27176 +static match_table_t udbalevel = {
27177 + {AuOpt_UDBA_REVAL, "reval"},
27178 + {AuOpt_UDBA_NONE, "none"},
27179 +#ifdef CONFIG_AUFS_HNOTIFY
27180 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27181 +#ifdef CONFIG_AUFS_HFSNOTIFY
27182 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27188 +int au_udba_val(char *str)
27190 + substring_t args[MAX_OPT_ARGS];
27192 + return match_token(str, udbalevel, args);
27195 +const char *au_optstr_udba(int udba)
27197 + return au_parser_pattern(udba, udbalevel);
27200 +/* ---------------------------------------------------------------------- */
27202 +static match_table_t au_wbr_create_policy = {
27203 + {AuWbrCreate_TDP, "tdp"},
27204 + {AuWbrCreate_TDP, "top-down-parent"},
27205 + {AuWbrCreate_RR, "rr"},
27206 + {AuWbrCreate_RR, "round-robin"},
27207 + {AuWbrCreate_MFS, "mfs"},
27208 + {AuWbrCreate_MFS, "most-free-space"},
27209 + {AuWbrCreate_MFSV, "mfs:%d"},
27210 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27212 + /* top-down regardless the parent, and then mfs */
27213 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27214 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27216 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27217 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27218 + {AuWbrCreate_PMFS, "pmfs"},
27219 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27220 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27221 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27226 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27227 + struct au_opt_wbr_create *create)
27230 + unsigned long long ull;
27233 + if (!match_u64(arg, &ull))
27234 + create->mfsrr_watermark = ull;
27236 + pr_err("bad integer in %s\n", str);
27243 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27244 + struct au_opt_wbr_create *create)
27249 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27250 + create->mfs_second = n;
27252 + pr_err("bad integer in %s\n", str);
27259 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27262 + substring_t args[MAX_OPT_ARGS];
27264 + err = match_token(str, au_wbr_create_policy, args);
27265 + create->wbr_create = err;
27267 + case AuWbrCreate_MFSRRV:
27268 + case AuWbrCreate_TDMFSV:
27269 + case AuWbrCreate_PMFSRRV:
27270 + e = au_wbr_mfs_wmark(&args[0], str, create);
27272 + e = au_wbr_mfs_sec(&args[1], str, create);
27276 + case AuWbrCreate_MFSRR:
27277 + case AuWbrCreate_TDMFS:
27278 + case AuWbrCreate_PMFSRR:
27279 + e = au_wbr_mfs_wmark(&args[0], str, create);
27280 + if (unlikely(e)) {
27285 + case AuWbrCreate_MFS:
27286 + case AuWbrCreate_PMFS:
27287 + create->mfs_second = AUFS_MFS_DEF_SEC;
27289 + case AuWbrCreate_MFSV:
27290 + case AuWbrCreate_PMFSV:
27291 + e = au_wbr_mfs_sec(&args[0], str, create);
27300 +const char *au_optstr_wbr_create(int wbr_create)
27302 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27305 +static match_table_t au_wbr_copyup_policy = {
27306 + {AuWbrCopyup_TDP, "tdp"},
27307 + {AuWbrCopyup_TDP, "top-down-parent"},
27308 + {AuWbrCopyup_BUP, "bup"},
27309 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27310 + {AuWbrCopyup_BU, "bu"},
27311 + {AuWbrCopyup_BU, "bottom-up"},
27315 +int au_wbr_copyup_val(char *str)
27317 + substring_t args[MAX_OPT_ARGS];
27319 + return match_token(str, au_wbr_copyup_policy, args);
27322 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27324 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27327 +/* ---------------------------------------------------------------------- */
27329 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27330 + aufs_bindex_t bindex)
27333 + struct au_opt_add *add = &opt->add;
27336 + add->bindex = bindex;
27337 + add->perm = AuBrPerm_RO;
27338 + add->pathname = opt_str;
27339 + p = strchr(opt_str, '=');
27343 + add->perm = au_br_perm_val(p);
27346 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27349 + add->perm = AuBrPerm_RO;
27350 + if (au_test_fs_rr(add->path.dentry->d_sb))
27351 + add->perm = AuBrPerm_RR;
27352 + else if (!bindex && !(sb_flags & SB_RDONLY))
27353 + add->perm = AuBrPerm_RW;
27355 + opt->type = Opt_add;
27358 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27365 +static int au_opt_wbr_create(struct super_block *sb,
27366 + struct au_opt_wbr_create *create)
27369 + struct au_sbinfo *sbinfo;
27371 + SiMustWriteLock(sb);
27373 + err = 1; /* handled */
27374 + sbinfo = au_sbi(sb);
27375 + if (sbinfo->si_wbr_create_ops->fin) {
27376 + err = sbinfo->si_wbr_create_ops->fin(sb);
27381 + sbinfo->si_wbr_create = create->wbr_create;
27382 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27383 + switch (create->wbr_create) {
27384 + case AuWbrCreate_MFSRRV:
27385 + case AuWbrCreate_MFSRR:
27386 + case AuWbrCreate_TDMFS:
27387 + case AuWbrCreate_TDMFSV:
27388 + case AuWbrCreate_PMFSRR:
27389 + case AuWbrCreate_PMFSRRV:
27390 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27392 + case AuWbrCreate_MFS:
27393 + case AuWbrCreate_MFSV:
27394 + case AuWbrCreate_PMFS:
27395 + case AuWbrCreate_PMFSV:
27396 + sbinfo->si_wbr_mfs.mfs_expire
27397 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27401 + if (sbinfo->si_wbr_create_ops->init)
27402 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27409 + * plus: processed without an error
27410 + * zero: unprocessed
27412 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27413 + struct au_opts *opts)
27416 + struct au_sbinfo *sbinfo;
27418 + SiMustWriteLock(sb);
27420 + err = 1; /* handled */
27421 + sbinfo = au_sbi(sb);
27422 + switch (opt->type) {
27424 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27425 + sbinfo->si_mntflags |= opt->udba;
27426 + opts->given_udba |= opt->udba;
27431 + au_opt_set(sbinfo->si_mntflags, PLINK);
27433 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27434 + au_plink_put(sb, /*verbose*/1);
27435 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27438 + case Opt_list_plink:
27439 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27440 + au_plink_list(sb);
27445 + au_opt_set(sbinfo->si_mntflags, DIO);
27446 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27448 + au_opt_clr(sbinfo->si_mntflags, DIO);
27449 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27453 + case Opt_fhsm_sec:
27454 + au_fhsm_set(sbinfo, opt->fhsm_second);
27457 + case Opt_diropq_a:
27458 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27460 + case Opt_diropq_w:
27461 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27464 + case Opt_warn_perm:
27466 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27468 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27471 + case Opt_verbose:
27473 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27475 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27480 + au_opt_set(sbinfo->si_mntflags, SUM);
27482 + au_opt_clr(sbinfo->si_mntflags, SUM);
27483 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27487 + au_opt_clr(sbinfo->si_mntflags, SUM);
27488 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27491 + case Opt_wbr_create:
27492 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27494 + case Opt_wbr_copyup:
27495 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27496 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27500 + sbinfo->si_dirwh = opt->dirwh;
27503 + case Opt_rdcache:
27504 + sbinfo->si_rdcache
27505 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27508 + sbinfo->si_rdblk = opt->rdblk;
27511 + sbinfo->si_rdhash = opt->rdhash;
27516 + au_opt_set(sbinfo->si_mntflags, SHWH);
27518 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27521 + case Opt_dirperm1:
27523 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27525 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27528 + case Opt_trunc_xino:
27530 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27532 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27535 + case Opt_trunc_xino_path:
27536 + case Opt_itrunc_xino:
27537 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27543 + case Opt_trunc_xib:
27545 + au_fset_opts(opts->flags, TRUNC_XIB);
27547 + au_fclr_opts(opts->flags, TRUNC_XIB);
27553 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27554 + err = au_dr_opt_set(sb);
27559 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27561 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27562 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27568 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27574 + sb->s_flags |= SB_POSIXACL;
27576 + sb->s_flags &= ~SB_POSIXACL;
27588 + * returns tri-state.
27589 + * plus: processed without an error
27590 + * zero: unprocessed
27593 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27594 + struct au_opts *opts)
27596 + int err, do_refresh;
27599 + switch (opt->type) {
27601 + opt->add.bindex = au_sbbot(sb) + 1;
27602 + if (opt->add.bindex < 0)
27603 + opt->add.bindex = 0;
27605 + /* Always goto add, not fallthrough */
27606 + case Opt_prepend:
27607 + opt->add.bindex = 0;
27610 + add: /* indented label */
27611 + err = au_br_add(sb, &opt->add,
27612 + au_ftest_opts(opts->flags, REMOUNT));
27615 + au_fset_opts(opts->flags, REFRESH);
27621 + err = au_br_del(sb, &opt->del,
27622 + au_ftest_opts(opts->flags, REMOUNT));
27625 + au_fset_opts(opts->flags, TRUNC_XIB);
27626 + au_fset_opts(opts->flags, REFRESH);
27632 + err = au_br_mod(sb, &opt->mod,
27633 + au_ftest_opts(opts->flags, REMOUNT),
27638 + au_fset_opts(opts->flags, REFRESH);
27645 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27646 + struct au_opt_xino **opt_xino,
27647 + struct au_opts *opts)
27652 + switch (opt->type) {
27654 + err = au_xino_set(sb, &opt->xino,
27655 + !!au_ftest_opts(opts->flags, REMOUNT));
27657 + *opt_xino = &opt->xino;
27661 + *opt_xino = (void *)-1;
27668 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27669 + unsigned int pending)
27672 + aufs_bindex_t bindex, bbot;
27673 + unsigned char do_plink, skip, do_free, can_no_dreval;
27674 + struct au_branch *br;
27675 + struct au_wbr *wbr;
27676 + struct dentry *root, *dentry;
27677 + struct inode *dir, *h_dir;
27678 + struct au_sbinfo *sbinfo;
27679 + struct au_hinode *hdir;
27681 + SiMustAnyLock(sb);
27683 + sbinfo = au_sbi(sb);
27684 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27686 + if (!(sb_flags & SB_RDONLY)) {
27687 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27688 + pr_warn("first branch should be rw\n");
27689 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27690 + pr_warn_once("shwh should be used with ro\n");
27693 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27694 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27695 + pr_warn_once("udba=*notify requires xino\n");
27697 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27698 + pr_warn_once("dirperm1 breaks the protection"
27699 + " by the permission bits on the lower branch\n");
27703 + root = sb->s_root;
27704 + dir = d_inode(root);
27705 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27706 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27708 + bbot = au_sbbot(sb);
27709 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27711 + h_dir = au_h_iptr(dir, bindex);
27712 + br = au_sbr(sb, bindex);
27714 + if ((br->br_perm & AuBrAttr_ICEX)
27715 + && !h_dir->i_op->listxattr)
27716 + br->br_perm &= ~AuBrAttr_ICEX;
27717 +#if 0 /* untested */
27718 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27719 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27720 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27724 + wbr = br->br_wbr;
27726 + wbr_wh_read_lock(wbr);
27728 + if (!au_br_writable(br->br_perm)) {
27731 + || (!wbr->wbr_whbase
27732 + && !wbr->wbr_plink
27733 + && !wbr->wbr_orph));
27734 + } else if (!au_br_wh_linkable(br->br_perm)) {
27735 + /* skip = (!br->br_whbase && !br->br_orph); */
27736 + skip = (!wbr || !wbr->wbr_whbase);
27737 + if (skip && wbr) {
27739 + skip = !!wbr->wbr_plink;
27741 + skip = !wbr->wbr_plink;
27744 + /* skip = (br->br_whbase && br->br_ohph); */
27745 + skip = (wbr && wbr->wbr_whbase);
27748 + skip = !!wbr->wbr_plink;
27750 + skip = !wbr->wbr_plink;
27754 + wbr_wh_read_unlock(wbr);
27756 + if (can_no_dreval) {
27757 + dentry = br->br_path.dentry;
27758 + spin_lock(&dentry->d_lock);
27759 + if (dentry->d_flags &
27760 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27761 + can_no_dreval = 0;
27762 + spin_unlock(&dentry->d_lock);
27765 + if (au_br_fhsm(br->br_perm)) {
27767 + AuDebugOn(!br->br_fhsm);
27773 + hdir = au_hi(dir, bindex);
27774 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27776 + wbr_wh_write_lock(wbr);
27777 + err = au_wh_init(br, sb);
27779 + wbr_wh_write_unlock(wbr);
27780 + au_hn_inode_unlock(hdir);
27782 + if (!err && do_free) {
27783 + au_kfree_rcu(wbr);
27784 + br->br_wbr = NULL;
27788 + if (can_no_dreval)
27789 + au_fset_si(sbinfo, NO_DREVAL);
27791 + au_fclr_si(sbinfo, NO_DREVAL);
27794 + au_fset_si(sbinfo, FHSM);
27795 + for (bindex = bbot; bindex >= 0; bindex--) {
27796 + br = au_sbr(sb, bindex);
27797 + if (au_br_fhsm(br->br_perm)) {
27798 + au_fhsm_set_bottom(sb, bindex);
27803 + au_fclr_si(sbinfo, FHSM);
27804 + au_fhsm_set_bottom(sb, -1);
27810 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27813 + unsigned int tmp;
27814 + aufs_bindex_t bindex, bbot;
27815 + struct au_opt *opt;
27816 + struct au_opt_xino *opt_xino, xino;
27817 + struct au_sbinfo *sbinfo;
27818 + struct au_branch *br;
27819 + struct inode *dir;
27821 + SiMustWriteLock(sb);
27826 + while (err >= 0 && opt->type != Opt_tail)
27827 + err = au_opt_simple(sb, opt++, opts);
27830 + else if (unlikely(err < 0))
27833 + /* disable xino and udba temporary */
27834 + sbinfo = au_sbi(sb);
27835 + tmp = sbinfo->si_mntflags;
27836 + au_opt_clr(sbinfo->si_mntflags, XINO);
27837 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27840 + while (err >= 0 && opt->type != Opt_tail)
27841 + err = au_opt_br(sb, opt++, opts);
27844 + else if (unlikely(err < 0))
27847 + bbot = au_sbbot(sb);
27848 + if (unlikely(bbot < 0)) {
27850 + pr_err("no branches\n");
27854 + if (au_opt_test(tmp, XINO))
27855 + au_opt_set(sbinfo->si_mntflags, XINO);
27857 + while (!err && opt->type != Opt_tail)
27858 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27859 + if (unlikely(err))
27862 + err = au_opts_verify(sb, sb->s_flags, tmp);
27863 + if (unlikely(err))
27866 + /* restore xino */
27867 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27868 + xino.file = au_xino_def(sb);
27869 + err = PTR_ERR(xino.file);
27870 + if (IS_ERR(xino.file))
27873 + err = au_xino_set(sb, &xino, /*remount*/0);
27875 + if (unlikely(err))
27879 + /* restore udba */
27880 + tmp &= AuOptMask_UDBA;
27881 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27882 + sbinfo->si_mntflags |= tmp;
27883 + bbot = au_sbbot(sb);
27884 + for (bindex = 0; bindex <= bbot; bindex++) {
27885 + br = au_sbr(sb, bindex);
27886 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27887 + if (unlikely(err))
27888 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27890 + /* go on even if err */
27892 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27893 + dir = d_inode(sb->s_root);
27894 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27901 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27904 + unsigned char no_dreval;
27905 + struct inode *dir;
27906 + struct au_opt_xino *opt_xino;
27907 + struct au_opt *opt;
27908 + struct au_sbinfo *sbinfo;
27910 + SiMustWriteLock(sb);
27912 + err = au_dr_opt_flush(sb);
27913 + if (unlikely(err))
27915 + au_fset_opts(opts->flags, DR_FLUSHED);
27917 + dir = d_inode(sb->s_root);
27918 + sbinfo = au_sbi(sb);
27921 + while (err >= 0 && opt->type != Opt_tail) {
27922 + err = au_opt_simple(sb, opt, opts);
27924 + err = au_opt_br(sb, opt, opts);
27926 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27932 + /* go on even err */
27934 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27935 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27936 + if (unlikely(rerr && !err))
27939 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27940 + au_fset_opts(opts->flags, REFRESH_IDOP);
27942 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27943 + rerr = au_xib_trunc(sb);
27944 + if (unlikely(rerr && !err))
27948 + /* will be handled by the caller */
27949 + if (!au_ftest_opts(opts->flags, REFRESH)
27950 + && (opts->given_udba
27951 + || au_opt_test(sbinfo->si_mntflags, XINO)
27952 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27954 + au_fset_opts(opts->flags, REFRESH);
27956 + AuDbg("status 0x%x\n", opts->flags);
27962 +/* ---------------------------------------------------------------------- */
27964 +unsigned int au_opt_udba(struct super_block *sb)
27966 + return au_mntflags(sb) & AuOptMask_UDBA;
27968 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27969 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27970 +++ linux/fs/aufs/opts.h 2024-05-13 17:13:00.621404284 +0200
27972 +/* SPDX-License-Identifier: GPL-2.0 */
27974 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27976 + * This program is free software; you can redistribute it and/or modify
27977 + * it under the terms of the GNU General Public License as published by
27978 + * the Free Software Foundation; either version 2 of the License, or
27979 + * (at your option) any later version.
27981 + * This program is distributed in the hope that it will be useful,
27982 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27983 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27984 + * GNU General Public License for more details.
27986 + * You should have received a copy of the GNU General Public License
27987 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27991 + * mount options/flags
27994 +#ifndef __AUFS_OPTS_H__
27995 +#define __AUFS_OPTS_H__
27999 +#include <linux/fs_parser.h>
28000 +#include <linux/namei.h>
28001 +#include <linux/path.h>
28005 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
28006 + Opt_idel, Opt_imod,
28007 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
28008 + Opt_xino, Opt_noxino,
28009 + Opt_trunc_xino, Opt_trunc_xino_v,
28010 + Opt_trunc_xino_path, Opt_itrunc_xino,
28013 + Opt_plink, Opt_list_plink,
28016 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
28018 + Opt_wbr_copyup, Opt_wbr_create,
28020 + Opt_verbose, Opt_noverbose,
28021 + Opt_sum, Opt_wsum,
28025 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
28028 +/* ---------------------------------------------------------------------- */
28031 +#define AuOpt_XINO BIT(0) /* external inode number bitmap
28032 + and translation table */
28033 +#define AuOpt_TRUNC_XINO BIT(1) /* truncate xino files */
28034 +#define AuOpt_UDBA_NONE BIT(2) /* users direct branch access */
28035 +#define AuOpt_UDBA_REVAL BIT(3)
28036 +#define AuOpt_UDBA_HNOTIFY BIT(4)
28037 +#define AuOpt_SHWH BIT(5) /* show whiteout */
28038 +#define AuOpt_PLINK BIT(6) /* pseudo-link */
28039 +#define AuOpt_DIRPERM1 BIT(7) /* ignore the lower dir's perm
28041 +#define AuOpt_ALWAYS_DIROPQ BIT(8) /* policy to creating diropq */
28042 +#define AuOpt_SUM BIT(9) /* summation for statfs(2) */
28043 +#define AuOpt_SUM_W BIT(10) /* unimplemented */
28044 +#define AuOpt_WARN_PERM BIT(11) /* warn when add-branch */
28045 +#define AuOpt_VERBOSE BIT(12) /* print the cause of error */
28046 +#define AuOpt_DIO BIT(13) /* direct io */
28047 +#define AuOpt_DIRREN BIT(14) /* directory rename */
28049 +#ifndef CONFIG_AUFS_HNOTIFY
28050 +#undef AuOpt_UDBA_HNOTIFY
28051 +#define AuOpt_UDBA_HNOTIFY 0
28053 +#ifndef CONFIG_AUFS_DIRREN
28054 +#undef AuOpt_DIRREN
28055 +#define AuOpt_DIRREN 0
28057 +#ifndef CONFIG_AUFS_SHWH
28059 +#define AuOpt_SHWH 0
28062 +#define AuOpt_Def (AuOpt_XINO \
28063 + | AuOpt_UDBA_REVAL \
28065 + /* | AuOpt_DIRPERM1 */ \
28066 + | AuOpt_WARN_PERM)
28067 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28068 + | AuOpt_UDBA_REVAL \
28069 + | AuOpt_UDBA_HNOTIFY)
28071 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28073 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28074 +#define au_opt_set(flags, name) do { \
28075 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28076 + ((flags) |= AuOpt_##name); \
28078 +#define au_opt_set_udba(flags, name) do { \
28079 + (flags) &= ~AuOptMask_UDBA; \
28080 + ((flags) |= AuOpt_##name); \
28082 +#define au_opt_clr(flags, name) do { \
28083 + ((flags) &= ~AuOpt_##name); \
28086 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28088 +#ifdef CONFIG_PROC_FS
28091 + return mntflags & ~AuOpt_PLINK;
28095 +/* ---------------------------------------------------------------------- */
28097 +/* policies to select one among multiple writable branches */
28099 + AuWbrCreate_TDP, /* top down parent */
28100 + AuWbrCreate_RR, /* round robin */
28101 + AuWbrCreate_MFS, /* most free space */
28102 + AuWbrCreate_MFSV, /* mfs with seconds */
28103 + AuWbrCreate_MFSRR, /* mfs then rr */
28104 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28105 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28106 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28107 + AuWbrCreate_PMFS, /* parent and mfs */
28108 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28109 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28110 + AuWbrCreate_PMFSRRV, /* plus seconds */
28112 + AuWbrCreate_Def = AuWbrCreate_TDP
28116 + AuWbrCopyup_TDP, /* top down parent */
28117 + AuWbrCopyup_BUP, /* bottom up parent */
28118 + AuWbrCopyup_BU, /* bottom up */
28120 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28123 +/* ---------------------------------------------------------------------- */
28127 +struct au_opt_add {
28128 + aufs_bindex_t bindex;
28131 + struct path path;
28134 +struct au_opt_del {
28136 + struct path h_path;
28139 +struct au_opt_mod {
28142 + struct dentry *h_root;
28145 +struct au_opt_xino {
28147 + struct file *file;
28150 +struct au_opt_xino_itrunc {
28151 + aufs_bindex_t bindex;
28154 +struct au_opt_wbr_create {
28157 + unsigned long long mfsrr_watermark;
28163 + struct au_opt_xino xino;
28164 + struct au_opt_xino_itrunc xino_itrunc;
28165 + struct au_opt_add add;
28166 + struct au_opt_del del;
28167 + struct au_opt_mod mod;
28170 + unsigned int rdblk;
28171 + unsigned int rdhash;
28173 + struct au_opt_wbr_create wbr_create;
28175 + unsigned int fhsm_second;
28176 + bool tf; /* generic flag, true or false */
28181 +#define AuOpts_REMOUNT BIT(0)
28182 +#define AuOpts_REFRESH BIT(1)
28183 +#define AuOpts_TRUNC_XIB BIT(2)
28184 +#define AuOpts_REFRESH_DYAOP BIT(3)
28185 +#define AuOpts_REFRESH_IDOP BIT(4)
28186 +#define AuOpts_DR_FLUSHED BIT(5)
28187 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28188 +#define au_fset_opts(flags, name) \
28189 + do { (flags) |= AuOpts_##name; } while (0)
28190 +#define au_fclr_opts(flags, name) \
28191 + do { (flags) &= ~AuOpts_##name; } while (0)
28193 +#ifndef CONFIG_AUFS_DIRREN
28194 +#undef AuOpts_DR_FLUSHED
28195 +#define AuOpts_DR_FLUSHED 0
28199 + struct au_opt *opt;
28202 + unsigned int given_udba;
28203 + unsigned int flags;
28204 + unsigned long sb_flags;
28207 +/* ---------------------------------------------------------------------- */
28210 +int au_br_perm_val(char *perm);
28211 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28212 +int au_udba_val(char *str);
28213 +const char *au_optstr_udba(int udba);
28214 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28215 +const char *au_optstr_wbr_create(int wbr_create);
28216 +int au_wbr_copyup_val(char *str);
28217 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28219 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28220 + aufs_bindex_t bindex);
28221 +struct super_block;
28222 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28223 + unsigned int pending);
28224 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28225 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28227 +unsigned int au_opt_udba(struct super_block *sb);
28230 +int aufs_fsctx_init(struct fs_context *fc);
28231 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28233 +#endif /* __KERNEL__ */
28234 +#endif /* __AUFS_OPTS_H__ */
28235 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28236 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28237 +++ linux/fs/aufs/plink.c 2024-05-13 17:13:00.621404284 +0200
28239 +// SPDX-License-Identifier: GPL-2.0
28241 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28243 + * This program is free software; you can redistribute it and/or modify
28244 + * it under the terms of the GNU General Public License as published by
28245 + * the Free Software Foundation; either version 2 of the License, or
28246 + * (at your option) any later version.
28248 + * This program is distributed in the hope that it will be useful,
28249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28251 + * GNU General Public License for more details.
28253 + * You should have received a copy of the GNU General Public License
28254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28264 + * the pseudo-link maintenance mode.
28265 + * during a user process maintains the pseudo-links,
28266 + * prohibit adding a new plink and branch manipulation.
28270 + * For entry functions which will handle plink, and i_mutex is already held
28272 + * They cannot wait and should return an error at once.
28273 + * Callers has to check the error.
28275 + * For entry functions which will handle plink, but i_mutex is not held
28277 + * They can wait the plink maintenance mode to finish.
28279 + * They behave like F_SETLK and F_SETLKW.
28280 + * If the caller never handle plink, then both flags are unnecessary.
28283 +int au_plink_maint(struct super_block *sb, int flags)
28287 + struct task_struct *parent, *prev;
28288 + struct au_sbinfo *sbi;
28290 + SiMustAnyLock(sb);
28293 + if (!au_opt_test(au_mntflags(sb), PLINK))
28296 + sbi = au_sbi(sb);
28297 + pid = sbi->si_plink_maint_pid;
28298 + if (!pid || pid == current->pid)
28301 + /* todo: it highly depends upon /sbin/mount.aufs */
28303 + parent = current;
28307 + parent = rcu_dereference(parent->real_parent);
28308 + if (parent == prev)
28310 + ppid = task_pid_vnr(parent);
28311 + if (pid == ppid) {
28312 + rcu_read_unlock();
28317 + rcu_read_unlock();
28319 + if (au_ftest_lock(flags, NOPLMW)) {
28320 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28321 + /* AuDebugOn(!lockdep_depth(current)); */
28322 + while (sbi->si_plink_maint_pid) {
28323 + si_read_unlock(sb);
28324 + /* gave up wake_up_bit() */
28325 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28327 + if (au_ftest_lock(flags, FLUSH))
28328 + au_nwt_flush(&sbi->si_nowait);
28329 + si_noflush_read_lock(sb);
28331 + } else if (au_ftest_lock(flags, NOPLM)) {
28332 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28340 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28342 + spin_lock(&sbinfo->si_plink_maint_lock);
28343 + sbinfo->si_plink_maint_pid = 0;
28344 + spin_unlock(&sbinfo->si_plink_maint_lock);
28345 + wake_up_all(&sbinfo->si_plink_wq);
28348 +int au_plink_maint_enter(struct super_block *sb)
28351 + struct au_sbinfo *sbinfo;
28354 + sbinfo = au_sbi(sb);
28355 + /* make sure i am the only one in this fs */
28356 + si_write_lock(sb, AuLock_FLUSH);
28357 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28358 + spin_lock(&sbinfo->si_plink_maint_lock);
28359 + if (!sbinfo->si_plink_maint_pid)
28360 + sbinfo->si_plink_maint_pid = current->pid;
28363 + spin_unlock(&sbinfo->si_plink_maint_lock);
28365 + si_write_unlock(sb);
28370 +/* ---------------------------------------------------------------------- */
28372 +#ifdef CONFIG_AUFS_DEBUG
28373 +void au_plink_list(struct super_block *sb)
28376 + struct au_sbinfo *sbinfo;
28377 + struct hlist_bl_head *hbl;
28378 + struct hlist_bl_node *pos;
28379 + struct au_icntnr *icntnr;
28381 + SiMustAnyLock(sb);
28383 + sbinfo = au_sbi(sb);
28384 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28385 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28387 + for (i = 0; i < AuPlink_NHASH; i++) {
28388 + hbl = sbinfo->si_plink + i;
28389 + hlist_bl_lock(hbl);
28390 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28391 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28392 + hlist_bl_unlock(hbl);
28397 +/* is the inode pseudo-linked? */
28398 +int au_plink_test(struct inode *inode)
28401 + struct au_sbinfo *sbinfo;
28402 + struct hlist_bl_head *hbl;
28403 + struct hlist_bl_node *pos;
28404 + struct au_icntnr *icntnr;
28406 + sbinfo = au_sbi(inode->i_sb);
28407 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28408 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28409 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28412 + i = au_plink_hash(inode->i_ino);
28413 + hbl = sbinfo->si_plink + i;
28414 + hlist_bl_lock(hbl);
28415 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28416 + if (&icntnr->vfs_inode == inode) {
28420 + hlist_bl_unlock(hbl);
28424 +/* ---------------------------------------------------------------------- */
28427 + * generate a name for plink.
28428 + * the file will be stored under AUFS_WH_PLINKDIR.
28430 +/* 20 is max digits length of ulong 64 */
28431 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28433 +static int plink_name(char *name, int len, struct inode *inode,
28434 + aufs_bindex_t bindex)
28437 + struct inode *h_inode;
28439 + h_inode = au_h_iptr(inode, bindex);
28440 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28444 +struct au_do_plink_lkup_args {
28445 + struct dentry **errp;
28446 + struct qstr *tgtname;
28447 + struct path *h_ppath;
28450 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28451 + struct path *h_ppath)
28453 + struct dentry *h_dentry;
28454 + struct inode *h_inode;
28456 + h_inode = d_inode(h_ppath->dentry);
28457 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28458 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28459 + inode_unlock_shared(h_inode);
28464 +static void au_call_do_plink_lkup(void *args)
28466 + struct au_do_plink_lkup_args *a = args;
28467 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28470 +/* lookup the plink-ed @inode under the branch at @bindex */
28471 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28473 + struct dentry *h_dentry;
28474 + struct au_branch *br;
28475 + struct path h_ppath;
28477 + char a[PLINK_NAME_LEN];
28478 + struct qstr tgtname = QSTR_INIT(a, 0);
28480 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28482 + br = au_sbr(inode->i_sb, bindex);
28483 + h_ppath.dentry = br->br_wbr->wbr_plink;
28484 + h_ppath.mnt = au_br_mnt(br);
28485 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28487 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28488 + struct au_do_plink_lkup_args args = {
28489 + .errp = &h_dentry,
28490 + .tgtname = &tgtname,
28491 + .h_ppath = &h_ppath
28494 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28495 + if (unlikely(wkq_err))
28496 + h_dentry = ERR_PTR(wkq_err);
28498 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28503 +/* create a pseudo-link */
28504 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28505 + struct dentry *h_dentry)
28508 + struct path h_path;
28509 + struct inode *h_dir, *delegated;
28511 + h_dir = d_inode(h_ppath->dentry);
28512 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28513 + h_path.mnt = h_ppath->mnt;
28515 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28516 + err = PTR_ERR(h_path.dentry);
28517 + if (IS_ERR(h_path.dentry))
28521 + /* wh.plink dir is not monitored */
28522 + /* todo: is it really safe? */
28523 + if (d_is_positive(h_path.dentry)
28524 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28525 + delegated = NULL;
28526 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28527 + if (unlikely(err == -EWOULDBLOCK)) {
28528 + pr_warn("cannot retry for NFSv4 delegation"
28529 + " for an internal unlink\n");
28532 + dput(h_path.dentry);
28533 + h_path.dentry = NULL;
28537 + if (!err && d_is_negative(h_path.dentry)) {
28538 + delegated = NULL;
28539 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28540 + if (unlikely(err == -EWOULDBLOCK)) {
28541 + pr_warn("cannot retry for NFSv4 delegation"
28542 + " for an internal link\n");
28546 + dput(h_path.dentry);
28549 + inode_unlock(h_dir);
28553 +struct do_whplink_args {
28555 + struct qstr *tgt;
28556 + struct path *h_ppath;
28557 + struct dentry *h_dentry;
28560 +static void call_do_whplink(void *args)
28562 + struct do_whplink_args *a = args;
28563 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28566 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28567 + aufs_bindex_t bindex)
28569 + int err, wkq_err;
28570 + struct au_branch *br;
28571 + struct au_wbr *wbr;
28572 + struct path h_ppath;
28573 + char a[PLINK_NAME_LEN];
28574 + struct qstr tgtname = QSTR_INIT(a, 0);
28576 + br = au_sbr(inode->i_sb, bindex);
28577 + wbr = br->br_wbr;
28578 + h_ppath.dentry = wbr->wbr_plink;
28579 + h_ppath.mnt = au_br_mnt(br);
28580 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28582 + /* always superio. */
28583 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28584 + struct do_whplink_args args = {
28587 + .h_ppath = &h_ppath,
28588 + .h_dentry = h_dentry
28590 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28591 + if (unlikely(wkq_err))
28594 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28600 + * create a new pseudo-link for @h_dentry on @bindex.
28601 + * the linked inode is held in aufs @inode.
28603 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28604 + struct dentry *h_dentry)
28606 + struct super_block *sb;
28607 + struct au_sbinfo *sbinfo;
28608 + struct hlist_bl_head *hbl;
28609 + struct hlist_bl_node *pos;
28610 + struct au_icntnr *icntnr;
28611 + int found, err, cnt, i;
28613 + sb = inode->i_sb;
28614 + sbinfo = au_sbi(sb);
28615 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28616 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28618 + found = au_plink_test(inode);
28622 + i = au_plink_hash(inode->i_ino);
28623 + hbl = sbinfo->si_plink + i;
28626 + hlist_bl_lock(hbl);
28627 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28628 + if (&icntnr->vfs_inode == inode) {
28634 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28635 + hlist_bl_add_head(&icntnr->plink, hbl);
28637 + hlist_bl_unlock(hbl);
28639 + cnt = au_hbl_count(hbl);
28640 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28641 + if (cnt > AUFS_PLINK_WARN)
28642 + AuWarn1(msg ", %d\n", cnt);
28644 + err = whplink(h_dentry, inode, bindex);
28645 + if (unlikely(err)) {
28646 + pr_warn("err %d, damaged pseudo link.\n", err);
28647 + au_hbl_del(&icntnr->plink, hbl);
28648 + iput(&icntnr->vfs_inode);
28651 + iput(&icntnr->vfs_inode);
28654 +/* free all plinks */
28655 +void au_plink_put(struct super_block *sb, int verbose)
28658 + struct au_sbinfo *sbinfo;
28659 + struct hlist_bl_head *hbl;
28660 + struct hlist_bl_node *pos, *tmp;
28661 + struct au_icntnr *icntnr;
28663 + SiMustWriteLock(sb);
28665 + sbinfo = au_sbi(sb);
28666 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28667 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28669 + /* no spin_lock since sbinfo is write-locked */
28671 + for (i = 0; i < AuPlink_NHASH; i++) {
28672 + hbl = sbinfo->si_plink + i;
28673 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28674 + pr_warn("pseudo-link is not flushed");
28677 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28678 + iput(&icntnr->vfs_inode);
28679 + INIT_HLIST_BL_HEAD(hbl);
28683 +void au_plink_clean(struct super_block *sb, int verbose)
28685 + struct dentry *root;
28687 + root = sb->s_root;
28688 + aufs_write_lock(root);
28689 + if (au_opt_test(au_mntflags(sb), PLINK))
28690 + au_plink_put(sb, verbose);
28691 + aufs_write_unlock(root);
28694 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28697 + aufs_bindex_t btop, bbot, bindex;
28700 + btop = au_ibtop(inode);
28701 + bbot = au_ibbot(inode);
28703 + for (bindex = btop; bindex <= bbot; bindex++) {
28704 + if (!au_h_iptr(inode, bindex)
28705 + || au_ii_br_id(inode, bindex) != br_id)
28707 + au_set_h_iptr(inode, bindex, NULL, 0);
28712 + for (bindex = btop; bindex <= bbot; bindex++)
28713 + if (au_h_iptr(inode, bindex)) {
28723 +/* free the plinks on a branch specified by @br_id */
28724 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28726 + struct au_sbinfo *sbinfo;
28727 + struct hlist_bl_head *hbl;
28728 + struct hlist_bl_node *pos, *tmp;
28729 + struct au_icntnr *icntnr;
28730 + struct inode *inode;
28733 + SiMustWriteLock(sb);
28735 + sbinfo = au_sbi(sb);
28736 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28737 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28739 + /* no bit_lock since sbinfo is write-locked */
28740 + for (i = 0; i < AuPlink_NHASH; i++) {
28741 + hbl = sbinfo->si_plink + i;
28742 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28743 + inode = au_igrab(&icntnr->vfs_inode);
28744 + ii_write_lock_child(inode);
28745 + do_put = au_plink_do_half_refresh(inode, br_id);
28747 + hlist_bl_del(&icntnr->plink);
28750 + ii_write_unlock(inode);
28755 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28756 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28757 +++ linux/fs/aufs/poll.c 2024-05-13 17:13:00.621404284 +0200
28759 +// SPDX-License-Identifier: GPL-2.0
28761 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28763 + * This program is free software; you can redistribute it and/or modify
28764 + * it under the terms of the GNU General Public License as published by
28765 + * the Free Software Foundation; either version 2 of the License, or
28766 + * (at your option) any later version.
28768 + * This program is distributed in the hope that it will be useful,
28769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28771 + * GNU General Public License for more details.
28773 + * You should have received a copy of the GNU General Public License
28774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28779 + * There is only one filesystem which implements ->poll operation, currently.
28784 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28787 + struct file *h_file;
28788 + struct super_block *sb;
28790 + /* We should pretend an error happened. */
28791 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28792 + sb = file->f_path.dentry->d_sb;
28793 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28795 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28796 + if (IS_ERR(h_file)) {
28797 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28801 + mask = vfs_poll(h_file, pt);
28802 + fput(h_file); /* instead of au_read_post() */
28805 + si_read_unlock(sb);
28806 + if (mask & EPOLLERR)
28807 + AuDbg("mask 0x%x\n", mask);
28810 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28811 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28812 +++ linux/fs/aufs/posix_acl.c 2024-05-13 17:13:00.621404284 +0200
28814 +// SPDX-License-Identifier: GPL-2.0
28816 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28818 + * This program is free software; you can redistribute it and/or modify
28819 + * it under the terms of the GNU General Public License as published by
28820 + * the Free Software Foundation; either version 2 of the License, or
28821 + * (at your option) any later version.
28823 + * This program is distributed in the hope that it will be useful,
28824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28826 + * GNU General Public License for more details.
28828 + * You should have received a copy of the GNU General Public License
28829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28833 + * posix acl operations
28836 +#include <linux/fs.h>
28839 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu)
28841 + struct posix_acl *acl;
28843 + aufs_bindex_t bindex;
28844 + struct inode *h_inode;
28845 + struct super_block *sb;
28847 + acl = ERR_PTR(-ECHILD);
28852 + sb = inode->i_sb;
28853 + si_read_lock(sb, AuLock_FLUSH);
28854 + ii_read_lock_child(inode);
28855 + if (!(sb->s_flags & SB_POSIXACL))
28858 + bindex = au_ibtop(inode);
28859 + h_inode = au_h_iptr(inode, bindex);
28860 + if (unlikely(!h_inode
28861 + || ((h_inode->i_mode & S_IFMT)
28862 + != (inode->i_mode & S_IFMT)))) {
28863 + err = au_busy_or_stale();
28864 + acl = ERR_PTR(err);
28868 + /* always topmost only */
28869 + acl = get_inode_acl(h_inode, type);
28871 + forget_cached_acl(inode, type);
28873 + set_cached_acl(inode, type, acl);
28876 + ii_read_unlock(inode);
28877 + si_read_unlock(sb);
28880 + AuTraceErrPtr(acl);
28884 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
28885 + struct dentry *dentry, int type)
28887 + struct posix_acl *acl;
28888 + struct inode *inode;
28890 + inode = d_inode(dentry);
28891 + acl = aufs_get_inode_acl(inode, type, /*rcu*/false);
28896 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
28897 + struct posix_acl *acl, int type)
28901 + struct inode *inode;
28902 + struct au_sxattr arg = {
28903 + .type = AU_ACL_SET,
28910 + inode = d_inode(dentry);
28911 + IMustLock(inode);
28913 + ssz = au_sxattr(dentry, inode, &arg);
28914 + /* forget even it if succeeds since the branch might set differently */
28915 + forget_cached_acl(inode, type);
28922 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28923 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28924 +++ linux/fs/aufs/procfs.c 2024-05-13 17:13:00.621404284 +0200
28926 +// SPDX-License-Identifier: GPL-2.0
28928 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28930 + * This program is free software; you can redistribute it and/or modify
28931 + * it under the terms of the GNU General Public License as published by
28932 + * the Free Software Foundation; either version 2 of the License, or
28933 + * (at your option) any later version.
28935 + * This program is distributed in the hope that it will be useful,
28936 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28937 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28938 + * GNU General Public License for more details.
28940 + * You should have received a copy of the GNU General Public License
28941 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28945 + * procfs interfaces
28948 +#include <linux/proc_fs.h>
28951 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28953 + struct au_sbinfo *sbinfo;
28955 + sbinfo = file->private_data;
28957 + au_plink_maint_leave(sbinfo);
28958 + kobject_put(&sbinfo->si_kobj);
28964 +static void au_procfs_plm_write_clean(struct file *file)
28966 + struct au_sbinfo *sbinfo;
28968 + sbinfo = file->private_data;
28970 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28973 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28976 + struct super_block *sb;
28977 + struct au_sbinfo *sbinfo;
28978 + struct hlist_bl_node *pos;
28981 + if (unlikely(file->private_data))
28985 + /* don't use au_sbilist_lock() here */
28986 + hlist_bl_lock(&au_sbilist);
28987 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28988 + if (id == sysaufs_si_id(sbinfo)) {
28989 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28990 + sb = sbinfo->si_sb;
28993 + hlist_bl_unlock(&au_sbilist);
28996 + if (unlikely(!sb))
28999 + err = au_plink_maint_enter(sb);
29001 + /* keep kobject_get() */
29002 + file->private_data = sbinfo;
29004 + kobject_put(&sbinfo->si_kobj);
29010 + * Accept a valid "si=xxxx" only.
29011 + * Once it is accepted successfully, accept "clean" too.
29013 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
29014 + size_t count, loff_t *ppos)
29017 + unsigned long id;
29018 + /* last newline is allowed */
29019 + char buf[3 + sizeof(unsigned long) * 2 + 1];
29022 + if (unlikely(!capable(CAP_SYS_ADMIN)))
29026 + if (unlikely(count > sizeof(buf)))
29029 + err = copy_from_user(buf, ubuf, count);
29030 + if (unlikely(err)) {
29037 + if (!strcmp("clean", buf)) {
29038 + au_procfs_plm_write_clean(file);
29039 + goto out_success;
29040 + } else if (unlikely(strncmp("si=", buf, 3)))
29043 + err = kstrtoul(buf + 3, 16, &id);
29044 + if (unlikely(err))
29047 + err = au_procfs_plm_write_si(file, id);
29048 + if (unlikely(err))
29052 + err = count; /* success */
29057 +static const struct proc_ops au_procfs_plm_op = {
29058 + .proc_write = au_procfs_plm_write,
29059 + .proc_release = au_procfs_plm_release
29062 +/* ---------------------------------------------------------------------- */
29064 +static struct proc_dir_entry *au_procfs_dir;
29066 +void au_procfs_fin(void)
29068 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29069 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29072 +int __init au_procfs_init(void)
29075 + struct proc_dir_entry *entry;
29078 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29079 + if (unlikely(!au_procfs_dir))
29082 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29083 + au_procfs_dir, &au_procfs_plm_op);
29084 + if (unlikely(!entry))
29088 + goto out; /* success */
29092 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29096 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29097 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29098 +++ linux/fs/aufs/rdu.c 2024-05-13 17:13:00.621404284 +0200
29100 +// SPDX-License-Identifier: GPL-2.0
29102 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29104 + * This program is free software; you can redistribute it and/or modify
29105 + * it under the terms of the GNU General Public License as published by
29106 + * the Free Software Foundation; either version 2 of the License, or
29107 + * (at your option) any later version.
29109 + * This program is distributed in the hope that it will be useful,
29110 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29111 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29112 + * GNU General Public License for more details.
29114 + * You should have received a copy of the GNU General Public License
29115 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29119 + * readdir in userspace.
29122 +#include <linux/compat.h>
29123 +#include <linux/fs_stack.h>
29124 +#include <linux/security.h>
29127 +/* bits for struct aufs_rdu.flags */
29128 +#define AuRdu_CALLED BIT(0)
29129 +#define AuRdu_CONT BIT(1)
29130 +#define AuRdu_FULL BIT(2)
29131 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29132 +#define au_fset_rdu(flags, name) \
29133 + do { (flags) |= AuRdu_##name; } while (0)
29134 +#define au_fclr_rdu(flags, name) \
29135 + do { (flags) &= ~AuRdu_##name; } while (0)
29137 +struct au_rdu_arg {
29138 + struct dir_context ctx;
29139 + struct aufs_rdu *rdu;
29140 + union au_rdu_ent_ul ent;
29141 + unsigned long end;
29143 + struct super_block *sb;
29147 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29148 + loff_t offset, u64 h_ino, unsigned int d_type)
29151 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29152 + struct aufs_rdu *rdu = arg->rdu;
29153 + struct au_rdu_ent ent;
29157 + au_fset_rdu(rdu->cookie.flags, CALLED);
29158 + len = au_rdu_len(nlen);
29159 + if (arg->ent.ul + len < arg->end) {
29161 + ent.bindex = rdu->cookie.bindex;
29162 + ent.type = d_type;
29164 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29165 + ent.type = DT_UNKNOWN;
29167 + /* unnecessary to support mmap_sem since this is a dir */
29169 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29171 + if (copy_to_user(arg->ent.e->name, name, nlen))
29173 + /* the terminating NULL */
29174 + if (__put_user(0, arg->ent.e->name + nlen))
29177 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29178 + arg->ent.ul += len;
29182 + au_fset_rdu(rdu->cookie.flags, FULL);
29184 + rdu->tail = arg->ent;
29188 + /* AuTraceErr(err); */
29192 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29196 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29198 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29199 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29201 + if (unlikely(offset != cookie->h_pos))
29207 + au_fclr_rdu(cookie->flags, CALLED);
29209 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29213 + && au_ftest_rdu(cookie->flags, CALLED)
29214 + && !au_ftest_rdu(cookie->flags, FULL));
29215 + cookie->h_pos = h_file->f_pos;
29222 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29225 + aufs_bindex_t bbot;
29226 + struct au_rdu_arg arg = {
29228 + .actor = au_rdu_fill
29231 + struct dentry *dentry;
29232 + struct inode *inode;
29233 + struct file *h_file;
29234 + struct au_rdu_cookie *cookie = &rdu->cookie;
29236 + /* VERIFY_WRITE */
29237 + err = !access_ok(rdu->ent.e, rdu->sz);
29238 + if (unlikely(err)) {
29244 + rdu->tail = rdu->ent;
29247 + arg.ent = rdu->ent;
29248 + arg.end = arg.ent.ul;
29249 + arg.end += rdu->sz;
29252 + if (unlikely(!file->f_op->iterate_shared))
29255 + err = security_file_permission(file, MAY_READ);
29257 + if (unlikely(err))
29260 + dentry = file->f_path.dentry;
29261 + inode = d_inode(dentry);
29262 + inode_lock_shared(inode);
29264 + arg.sb = inode->i_sb;
29265 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29266 + if (unlikely(err))
29268 + err = au_alive_dir(dentry);
29269 + if (unlikely(err))
29271 + /* todo: reval? */
29272 + fi_read_lock(file);
29275 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29276 + && cookie->generation != au_figen(file)))
29281 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29283 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29285 + bbot = au_fbtop(file);
29286 + if (cookie->bindex < bbot)
29287 + cookie->bindex = bbot;
29288 + bbot = au_fbbot_dir(file);
29289 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29290 + for (; !err && cookie->bindex <= bbot;
29291 + cookie->bindex++, cookie->h_pos = 0) {
29292 + h_file = au_hf_dir(file, cookie->bindex);
29296 + au_fclr_rdu(cookie->flags, FULL);
29297 + err = au_rdu_do(h_file, &arg);
29299 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29302 + AuDbg("rent %llu\n", rdu->rent);
29304 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29305 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29306 + au_fset_rdu(cookie->flags, CONT);
29307 + cookie->generation = au_figen(file);
29310 + ii_read_lock_child(inode);
29311 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29312 + ii_read_unlock(inode);
29315 + fi_read_unlock(file);
29317 + si_read_unlock(arg.sb);
29319 + inode_unlock_shared(inode);
29325 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29329 + unsigned long long nent;
29330 + union au_rdu_ent_ul *u;
29331 + struct au_rdu_ent ent;
29332 + struct super_block *sb;
29335 + nent = rdu->nent;
29337 + sb = file->f_path.dentry->d_sb;
29338 + si_read_lock(sb, AuLock_FLUSH);
29339 + while (nent-- > 0) {
29340 + /* unnecessary to support mmap_sem since this is a dir */
29341 + err = copy_from_user(&ent, u->e, sizeof(ent));
29343 + /* VERIFY_WRITE */
29344 + err = !access_ok(&u->e->ino, sizeof(ino));
29345 + if (unlikely(err)) {
29351 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29353 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29355 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29357 + if (unlikely(err)) {
29362 + err = __put_user(ino, &u->e->ino);
29363 + if (unlikely(err)) {
29368 + u->ul += au_rdu_len(ent.nlen);
29370 + si_read_unlock(sb);
29375 +/* ---------------------------------------------------------------------- */
29377 +static int au_rdu_verify(struct aufs_rdu *rdu)
29379 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29380 + "%llu, b%d, 0x%x, g%u}\n",
29381 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29383 + rdu->rent, rdu->shwh, rdu->full,
29384 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29385 + rdu->cookie.generation);
29387 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29391 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29395 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29398 + struct aufs_rdu rdu;
29399 + void __user *p = (void __user *)arg;
29401 + err = copy_from_user(&rdu, p, sizeof(rdu));
29402 + if (unlikely(err)) {
29407 + err = au_rdu_verify(&rdu);
29408 + if (unlikely(err))
29412 + case AUFS_CTL_RDU:
29413 + err = au_rdu(file, &rdu);
29414 + if (unlikely(err))
29417 + e = copy_to_user(p, &rdu, sizeof(rdu));
29418 + if (unlikely(e)) {
29423 + case AUFS_CTL_RDU_INO:
29424 + err = au_rdu_ino(file, &rdu);
29428 + /* err = -ENOTTY; */
29437 +#ifdef CONFIG_COMPAT
29438 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29441 + struct aufs_rdu rdu;
29442 + void __user *p = compat_ptr(arg);
29444 + /* todo: get_user()? */
29445 + err = copy_from_user(&rdu, p, sizeof(rdu));
29446 + if (unlikely(err)) {
29451 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29452 + err = au_rdu_verify(&rdu);
29453 + if (unlikely(err))
29457 + case AUFS_CTL_RDU:
29458 + err = au_rdu(file, &rdu);
29459 + if (unlikely(err))
29462 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29463 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29464 + e = copy_to_user(p, &rdu, sizeof(rdu));
29465 + if (unlikely(e)) {
29470 + case AUFS_CTL_RDU_INO:
29471 + err = au_rdu_ino(file, &rdu);
29475 + /* err = -ENOTTY; */
29484 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29485 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29486 +++ linux/fs/aufs/rwsem.h 2024-05-13 17:13:00.621404284 +0200
29488 +/* SPDX-License-Identifier: GPL-2.0 */
29490 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29492 + * This program is free software; you can redistribute it and/or modify
29493 + * it under the terms of the GNU General Public License as published by
29494 + * the Free Software Foundation; either version 2 of the License, or
29495 + * (at your option) any later version.
29497 + * This program is distributed in the hope that it will be useful,
29498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29500 + * GNU General Public License for more details.
29502 + * You should have received a copy of the GNU General Public License
29503 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29507 + * simple read-write semaphore wrappers
29510 +#ifndef __AUFS_RWSEM_H__
29511 +#define __AUFS_RWSEM_H__
29515 +#include "debug.h"
29517 +/* in the future, the name 'au_rwsem' will be totally gone */
29518 +#define au_rwsem rw_semaphore
29520 +/* to debug easier, do not make them inlined functions */
29521 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29523 +#ifdef CONFIG_LOCKDEP
29524 +/* rwsem_is_locked() is unusable */
29525 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29526 + && !lockdep_recursing(current) \
29528 + && !lockdep_is_held_type(rw, 1))
29529 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29530 + && !lockdep_recursing(current) \
29532 + && !lockdep_is_held_type(rw, 0))
29533 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29534 + && !lockdep_recursing(current) \
29536 + && !lockdep_is_held(rw))
29537 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29538 + && !lockdep_recursing(current) \
29540 + && lockdep_is_held(rw))
29542 +#define AuRwMustReadLock(rw) do {} while (0)
29543 +#define AuRwMustWriteLock(rw) do {} while (0)
29544 +#define AuRwMustAnyLock(rw) do {} while (0)
29545 +#define AuRwDestroy(rw) do {} while (0)
29548 +#define au_rw_init(rw) init_rwsem(rw)
29550 +#define au_rw_init_wlock(rw) do { \
29551 + au_rw_init(rw); \
29552 + down_write(rw); \
29555 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29556 + au_rw_init(rw); \
29557 + down_write_nested(rw, lsc); \
29560 +#define au_rw_read_lock(rw) down_read(rw)
29561 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29562 +#define au_rw_read_unlock(rw) up_read(rw)
29563 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29564 +#define au_rw_write_lock(rw) down_write(rw)
29565 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29566 +#define au_rw_write_unlock(rw) up_write(rw)
29567 +/* why is not _nested version defined? */
29568 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29569 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29571 +#endif /* __KERNEL__ */
29572 +#endif /* __AUFS_RWSEM_H__ */
29573 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29574 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29575 +++ linux/fs/aufs/sbinfo.c 2024-05-13 17:13:00.621404284 +0200
29577 +// SPDX-License-Identifier: GPL-2.0
29579 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29581 + * This program is free software; you can redistribute it and/or modify
29582 + * it under the terms of the GNU General Public License as published by
29583 + * the Free Software Foundation; either version 2 of the License, or
29584 + * (at your option) any later version.
29586 + * This program is distributed in the hope that it will be useful,
29587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29589 + * GNU General Public License for more details.
29591 + * You should have received a copy of the GNU General Public License
29592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29596 + * superblock private data
29599 +#include <linux/iversion.h>
29603 + * they are necessary regardless sysfs is disabled.
29605 +void au_si_free(struct kobject *kobj)
29608 + struct au_sbinfo *sbinfo;
29609 + char *locked __maybe_unused; /* debug only */
29611 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29612 + for (i = 0; i < AuPlink_NHASH; i++)
29613 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29614 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29616 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29617 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29618 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29619 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29621 + dbgaufs_si_fin(sbinfo);
29622 + au_rw_write_lock(&sbinfo->si_rwsem);
29623 + au_br_free(sbinfo);
29624 + au_rw_write_unlock(&sbinfo->si_rwsem);
29626 + au_kfree_try_rcu(sbinfo->si_branch);
29627 + mutex_destroy(&sbinfo->si_xib_mtx);
29628 + AuRwDestroy(&sbinfo->si_rwsem);
29630 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29631 + /* si_nfiles is waited too */
29632 + au_kfree_rcu(sbinfo);
29635 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29637 + struct au_sbinfo *sbinfo;
29641 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29642 + if (unlikely(!sbinfo))
29645 + /* will be reallocated separately */
29646 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29647 + if (unlikely(!sbinfo->si_branch))
29650 + err = sysaufs_si_init(sbinfo);
29652 + dbgaufs_si_null(sbinfo);
29653 + err = dbgaufs_si_init(sbinfo);
29654 + if (unlikely(err))
29655 + kobject_put(&sbinfo->si_kobj);
29657 + if (unlikely(err))
29660 + au_nwt_init(&sbinfo->si_nowait);
29661 + au_rw_init_wlock(&sbinfo->si_rwsem);
29663 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29664 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29666 + sbinfo->si_bbot = -1;
29667 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29669 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29670 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29671 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29672 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29674 + au_fhsm_init(sbinfo);
29676 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29678 + sbinfo->si_xino_jiffy = jiffies;
29679 + sbinfo->si_xino_expire
29680 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29681 + mutex_init(&sbinfo->si_xib_mtx);
29682 + /* leave si_xib_last_pindex and si_xib_next_bit */
29684 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29686 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29687 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29688 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29689 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29691 + for (i = 0; i < AuPlink_NHASH; i++)
29692 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29693 + init_waitqueue_head(&sbinfo->si_plink_wq);
29694 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29696 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29698 + /* with getattr by default */
29699 + sbinfo->si_iop_array = aufs_iop;
29701 + /* leave other members for sysaufs and si_mnt. */
29702 + sbinfo->si_sb = sb;
29704 + sb->s_fs_info = sbinfo;
29707 + return sbinfo; /* success */
29710 + au_kfree_try_rcu(sbinfo->si_branch);
29712 + au_kfree_rcu(sbinfo);
29714 + return ERR_PTR(err);
29717 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29720 + struct au_branch **brp;
29722 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29725 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29726 + if (unlikely(!sz))
29727 + sz = sizeof(*brp);
29728 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29731 + sbinfo->si_branch = brp;
29738 +/* ---------------------------------------------------------------------- */
29740 +unsigned int au_sigen_inc(struct super_block *sb)
29742 + unsigned int gen;
29743 + struct inode *inode;
29745 + SiMustWriteLock(sb);
29747 + gen = ++au_sbi(sb)->si_generation;
29748 + au_update_digen(sb->s_root);
29749 + inode = d_inode(sb->s_root);
29750 + au_update_iigen(inode, /*half*/0);
29751 + inode_inc_iversion(inode);
29755 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29757 + aufs_bindex_t br_id;
29759 + struct au_sbinfo *sbinfo;
29761 + SiMustWriteLock(sb);
29763 + sbinfo = au_sbi(sb);
29764 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29765 + br_id = ++sbinfo->si_last_br_id;
29766 + AuDebugOn(br_id < 0);
29767 + if (br_id && au_br_index(sb, br_id) < 0)
29774 +/* ---------------------------------------------------------------------- */
29776 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29777 +int si_read_lock(struct super_block *sb, int flags)
29782 + if (au_ftest_lock(flags, FLUSH))
29783 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29785 + si_noflush_read_lock(sb);
29786 + err = au_plink_maint(sb, flags);
29787 + if (unlikely(err))
29788 + si_read_unlock(sb);
29793 +int si_write_lock(struct super_block *sb, int flags)
29797 + if (au_ftest_lock(flags, FLUSH))
29798 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29800 + si_noflush_write_lock(sb);
29801 + err = au_plink_maint(sb, flags);
29802 + if (unlikely(err))
29803 + si_write_unlock(sb);
29808 +/* dentry and super_block lock. call at entry point */
29809 +int aufs_read_lock(struct dentry *dentry, int flags)
29812 + struct super_block *sb;
29814 + sb = dentry->d_sb;
29815 + err = si_read_lock(sb, flags);
29816 + if (unlikely(err))
29819 + if (au_ftest_lock(flags, DW))
29820 + di_write_lock_child(dentry);
29822 + di_read_lock_child(dentry, flags);
29824 + if (au_ftest_lock(flags, GEN)) {
29825 + err = au_digen_test(dentry, au_sigen(sb));
29826 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29827 + AuDebugOn(!err && au_dbrange_test(dentry));
29829 + err = au_dbrange_test(dentry);
29830 + if (unlikely(err))
29831 + aufs_read_unlock(dentry, flags);
29838 +void aufs_read_unlock(struct dentry *dentry, int flags)
29840 + if (au_ftest_lock(flags, DW))
29841 + di_write_unlock(dentry);
29843 + di_read_unlock(dentry, flags);
29844 + si_read_unlock(dentry->d_sb);
29847 +void aufs_write_lock(struct dentry *dentry)
29849 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29850 + di_write_lock_child(dentry);
29853 +void aufs_write_unlock(struct dentry *dentry)
29855 + di_write_unlock(dentry);
29856 + si_write_unlock(dentry->d_sb);
29859 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29862 + unsigned int sigen;
29863 + struct super_block *sb;
29866 + err = si_read_lock(sb, flags);
29867 + if (unlikely(err))
29870 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29872 + if (au_ftest_lock(flags, GEN)) {
29873 + sigen = au_sigen(sb);
29874 + err = au_digen_test(d1, sigen);
29875 + AuDebugOn(!err && au_dbrange_test(d1));
29877 + err = au_digen_test(d2, sigen);
29878 + AuDebugOn(!err && au_dbrange_test(d2));
29880 + if (unlikely(err))
29881 + aufs_read_and_write_unlock2(d1, d2);
29888 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29890 + di_write_unlock2(d1, d2);
29891 + si_read_unlock(d1->d_sb);
29893 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29894 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29895 +++ linux/fs/aufs/super.c 2024-05-13 17:13:00.621404284 +0200
29897 +// SPDX-License-Identifier: GPL-2.0
29899 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29901 + * This program is free software; you can redistribute it and/or modify
29902 + * it under the terms of the GNU General Public License as published by
29903 + * the Free Software Foundation; either version 2 of the License, or
29904 + * (at your option) any later version.
29906 + * This program is distributed in the hope that it will be useful,
29907 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29908 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29909 + * GNU General Public License for more details.
29911 + * You should have received a copy of the GNU General Public License
29912 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29916 + * mount and super_block operations
29919 +#include <linux/iversion.h>
29920 +#include <linux/mm.h>
29921 +#include <linux/seq_file.h>
29922 +#include <linux/statfs.h>
29923 +#include <linux/vmalloc.h>
29927 + * super_operations
29929 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29931 + struct au_icntnr *c;
29933 + c = au_cache_alloc_icntnr(sb);
29935 + au_icntnr_init(c);
29936 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29937 + c->iinfo.ii_hinode = NULL;
29938 + return &c->vfs_inode;
29943 +static void aufs_destroy_inode(struct inode *inode)
29945 + if (!au_is_bad_inode(inode))
29946 + au_iinfo_fin(inode);
29949 +static void aufs_free_inode(struct inode *inode)
29951 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29954 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29956 + struct inode *inode;
29959 + inode = iget_locked(sb, ino);
29960 + if (unlikely(!inode)) {
29961 + inode = ERR_PTR(-ENOMEM);
29964 + if (!(inode->i_state & I_NEW))
29967 + err = au_xigen_new(inode);
29969 + err = au_iinfo_init(inode);
29971 + inode_inc_iversion(inode);
29973 + iget_failed(inode);
29974 + inode = ERR_PTR(err);
29978 + /* never return NULL */
29979 + AuDebugOn(!inode);
29980 + AuTraceErrPtr(inode);
29984 +/* lock free root dinfo */
29985 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29988 + aufs_bindex_t bindex, bbot;
29989 + struct path path;
29990 + struct au_hdentry *hdp;
29991 + struct au_branch *br;
29992 + au_br_perm_str_t perm;
29995 + bbot = au_sbbot(sb);
29997 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29998 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29999 + br = au_sbr(sb, bindex);
30000 + path.mnt = au_br_mnt(br);
30001 + path.dentry = hdp->hd_dentry;
30002 + err = au_seq_path(seq, &path);
30004 + au_optstr_br_perm(&perm, br->br_perm);
30005 + seq_printf(seq, "=%s", perm.a);
30006 + if (bindex != bbot)
30007 + seq_putc(seq, ':');
30010 + if (unlikely(err || seq_has_overflowed(seq)))
30016 +static void au_gen_fmt(char *fmt, int len, const char *pat,
30017 + const char *append)
30022 + while (*pat != ':')
30025 + strscpy(p, append, len - (p - fmt));
30026 + AuDebugOn(strlen(fmt) >= len);
30029 +static void au_show_wbr_create(struct seq_file *m, int v,
30030 + struct au_sbinfo *sbinfo)
30034 + struct au_wbr_mfs *mfs;
30036 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30038 + seq_puts(m, ",create=");
30039 + pat = au_optstr_wbr_create(v);
30040 + mfs = &sbinfo->si_wbr_mfs;
30042 + case AuWbrCreate_TDP:
30043 + case AuWbrCreate_RR:
30044 + case AuWbrCreate_MFS:
30045 + case AuWbrCreate_PMFS:
30046 + seq_puts(m, pat);
30048 + case AuWbrCreate_MFSRR:
30049 + case AuWbrCreate_TDMFS:
30050 + case AuWbrCreate_PMFSRR:
30051 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30052 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30054 + case AuWbrCreate_MFSV:
30055 + case AuWbrCreate_PMFSV:
30056 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30057 + seq_printf(m, fmt,
30058 + jiffies_to_msecs(mfs->mfs_expire)
30061 + case AuWbrCreate_MFSRRV:
30062 + case AuWbrCreate_TDMFSV:
30063 + case AuWbrCreate_PMFSRRV:
30064 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30065 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30066 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30073 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30075 +#ifdef CONFIG_SYSFS
30079 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30080 + aufs_bindex_t bindex, brid;
30081 + struct qstr *name;
30083 + struct dentry *d, *h_root;
30084 + struct au_branch *br;
30086 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30089 + f = au_sbi(sb)->si_xib;
30093 + /* stop printing the default xino path on the first writable branch */
30095 + bindex = au_xi_root(sb, f->f_path.dentry);
30096 + if (bindex >= 0) {
30097 + br = au_sbr_sb(sb, bindex);
30098 + h_root = au_br_dentry(br);
30101 + d = f->f_path.dentry;
30102 + name = &d->d_name;
30103 + /* safe ->d_parent because the file is unlinked */
30104 + if (d->d_parent == h_root
30105 + && name->len == len
30106 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30109 + seq_puts(seq, ",xino=");
30110 + err = au_xino_path(seq, f);
30117 +/* seq_file will re-call me in case of too long string */
30118 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30121 + unsigned int mnt_flags, v;
30122 + struct super_block *sb;
30123 + struct au_sbinfo *sbinfo;
30125 +#define AuBool(name, str) do { \
30126 + v = au_opt_test(mnt_flags, name); \
30127 + if (v != au_opt_test(AuOpt_Def, name)) \
30128 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30131 +#define AuStr(name, str) do { \
30132 + v = mnt_flags & AuOptMask_##name; \
30133 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30134 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30137 +#define AuUInt(name, str, val) do { \
30138 + if (val != AUFS_##name##_DEF) \
30139 + seq_printf(m, "," #str "=%u", val); \
30142 + sb = dentry->d_sb;
30143 + if (sb->s_flags & SB_POSIXACL)
30144 + seq_puts(m, ",acl");
30145 +#if 0 /* reserved for future use */
30146 + if (sb->s_flags & SB_I_VERSION)
30147 + seq_puts(m, ",i_version");
30150 + /* lock free root dinfo */
30151 + si_noflush_read_lock(sb);
30152 + sbinfo = au_sbi(sb);
30153 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30155 + mnt_flags = au_mntflags(sb);
30156 + if (au_opt_test(mnt_flags, XINO)) {
30157 + err = au_show_xino(m, sb);
30158 + if (unlikely(err))
30161 + seq_puts(m, ",noxino");
30163 + AuBool(TRUNC_XINO, trunc_xino);
30164 + AuStr(UDBA, udba);
30165 + AuBool(SHWH, shwh);
30166 + AuBool(PLINK, plink);
30167 + AuBool(DIO, dio);
30168 + AuBool(DIRPERM1, dirperm1);
30170 + v = sbinfo->si_wbr_create;
30171 + if (v != AuWbrCreate_Def)
30172 + au_show_wbr_create(m, v, sbinfo);
30174 + v = sbinfo->si_wbr_copyup;
30175 + if (v != AuWbrCopyup_Def)
30176 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30178 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30179 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30180 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30182 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30184 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30185 + AuUInt(RDCACHE, rdcache, v);
30187 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30188 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30190 + au_fhsm_show(m, sbinfo);
30192 + AuBool(DIRREN, dirren);
30193 + AuBool(SUM, sum);
30194 + /* AuBool(SUM_W, wsum); */
30195 + AuBool(WARN_PERM, warn_perm);
30196 + AuBool(VERBOSE, verbose);
30199 + /* be sure to print "br:" last */
30200 + if (!sysaufs_brs) {
30201 + seq_puts(m, ",br:");
30202 + au_show_brs(m, sb);
30204 + si_read_unlock(sb);
30212 +/* ---------------------------------------------------------------------- */
30214 +/* sum mode which returns the summation for statfs(2) */
30216 +static u64 au_add_till_max(u64 a, u64 b)
30224 + return ULLONG_MAX;
30227 +static u64 au_mul_till_max(u64 a, long mul)
30235 + return ULLONG_MAX;
30238 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30241 + long bsize, factor;
30242 + u64 blocks, bfree, bavail, files, ffree;
30243 + aufs_bindex_t bbot, bindex, i;
30244 + unsigned char shared;
30245 + struct path h_path;
30246 + struct super_block *h_sb;
30249 + bsize = LONG_MAX;
30255 + bbot = au_sbbot(sb);
30256 + for (bindex = 0; bindex <= bbot; bindex++) {
30257 + h_path.mnt = au_sbr_mnt(sb, bindex);
30258 + h_sb = h_path.mnt->mnt_sb;
30260 + for (i = 0; !shared && i < bindex; i++)
30261 + shared = (au_sbr_sb(sb, i) == h_sb);
30265 + /* sb->s_root for NFS is unreliable */
30266 + h_path.dentry = h_path.mnt->mnt_root;
30267 + err = vfs_statfs(&h_path, buf);
30268 + if (unlikely(err))
30271 + if (bsize > buf->f_bsize) {
30273 + * we will reduce bsize, so we have to expand blocks
30274 + * etc. to match them again
30276 + factor = (bsize / buf->f_bsize);
30277 + blocks = au_mul_till_max(blocks, factor);
30278 + bfree = au_mul_till_max(bfree, factor);
30279 + bavail = au_mul_till_max(bavail, factor);
30280 + bsize = buf->f_bsize;
30283 + factor = (buf->f_bsize / bsize);
30284 + blocks = au_add_till_max(blocks,
30285 + au_mul_till_max(buf->f_blocks, factor));
30286 + bfree = au_add_till_max(bfree,
30287 + au_mul_till_max(buf->f_bfree, factor));
30288 + bavail = au_add_till_max(bavail,
30289 + au_mul_till_max(buf->f_bavail, factor));
30290 + files = au_add_till_max(files, buf->f_files);
30291 + ffree = au_add_till_max(ffree, buf->f_ffree);
30294 + buf->f_bsize = bsize;
30295 + buf->f_blocks = blocks;
30296 + buf->f_bfree = bfree;
30297 + buf->f_bavail = bavail;
30298 + buf->f_files = files;
30299 + buf->f_ffree = ffree;
30300 + buf->f_frsize = 0;
30306 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30309 + struct path h_path;
30310 + struct super_block *sb;
30312 + /* lock free root dinfo */
30313 + sb = dentry->d_sb;
30314 + si_noflush_read_lock(sb);
30315 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30316 + /* sb->s_root for NFS is unreliable */
30317 + h_path.mnt = au_sbr_mnt(sb, 0);
30318 + h_path.dentry = h_path.mnt->mnt_root;
30319 + err = vfs_statfs(&h_path, buf);
30321 + err = au_statfs_sum(sb, buf);
30322 + si_read_unlock(sb);
30325 + buf->f_type = AUFS_SUPER_MAGIC;
30326 + buf->f_namelen = AUFS_MAX_NAMELEN;
30327 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30329 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30334 +/* ---------------------------------------------------------------------- */
30336 +static int aufs_sync_fs(struct super_block *sb, int wait)
30339 + aufs_bindex_t bbot, bindex;
30340 + struct au_branch *br;
30341 + struct super_block *h_sb;
30344 + si_noflush_read_lock(sb);
30345 + bbot = au_sbbot(sb);
30346 + for (bindex = 0; bindex <= bbot; bindex++) {
30347 + br = au_sbr(sb, bindex);
30348 + if (!au_br_writable(br->br_perm))
30351 + h_sb = au_sbr_sb(sb, bindex);
30352 + e = vfsub_sync_filesystem(h_sb);
30353 + if (unlikely(e && !err))
30355 + /* go on even if an error happens */
30357 + si_read_unlock(sb);
30362 +/* ---------------------------------------------------------------------- */
30364 +/* final actions when unmounting a file system */
30365 +static void aufs_put_super(struct super_block *sb)
30367 + struct au_sbinfo *sbinfo;
30369 + sbinfo = au_sbi(sb);
30371 + kobject_put(&sbinfo->si_kobj);
30374 +/* ---------------------------------------------------------------------- */
30376 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30377 + struct super_block *sb, void *arg)
30380 + unsigned long long n, sz;
30387 + if (*hint > ULLONG_MAX / sizeof(array)) {
30388 + array = ERR_PTR(-EMFILE);
30389 + pr_err("hint %llu\n", *hint);
30393 + sz = sizeof(array) * *hint;
30394 + array = kzalloc(sz, GFP_NOFS);
30395 + if (unlikely(!array))
30396 + array = vzalloc(sz);
30397 + if (unlikely(!array)) {
30398 + array = ERR_PTR(-ENOMEM);
30402 + n = cb(sb, array, *hint, arg);
30403 + AuDebugOn(n > *hint);
30410 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30411 + unsigned long long max __maybe_unused,
30414 + unsigned long long n;
30415 + struct inode **p, *inode;
30416 + struct list_head *head;
30421 + spin_lock(&sb->s_inode_list_lock);
30422 + list_for_each_entry(inode, head, i_sb_list) {
30423 + if (!au_is_bad_inode(inode)
30424 + && au_ii(inode)->ii_btop >= 0) {
30425 + spin_lock(&inode->i_lock);
30426 + if (atomic_read(&inode->i_count)) {
30430 + AuDebugOn(n > max);
30432 + spin_unlock(&inode->i_lock);
30435 + spin_unlock(&sb->s_inode_list_lock);
30440 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30442 + struct au_sbinfo *sbi;
30444 + sbi = au_sbi(sb);
30445 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30446 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30449 +void au_iarray_free(struct inode **a, unsigned long long max)
30451 + unsigned long long ull;
30453 + for (ull = 0; ull < max; ull++)
30458 +/* ---------------------------------------------------------------------- */
30461 + * refresh dentry and inode at remount time.
30463 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30464 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30465 + struct dentry *parent)
30469 + di_write_lock_child(dentry);
30470 + di_read_lock_parent(parent, AuLock_IR);
30471 + err = au_refresh_dentry(dentry, parent);
30472 + if (!err && dir_flags)
30473 + au_hn_reset(d_inode(dentry), dir_flags);
30474 + di_read_unlock(parent, AuLock_IR);
30475 + di_write_unlock(dentry);
30480 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30481 + struct au_sbinfo *sbinfo,
30482 + const unsigned int dir_flags, unsigned int do_idop)
30485 + struct dentry *parent;
30488 + parent = dget_parent(dentry);
30489 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30490 + if (d_really_is_positive(dentry)) {
30491 + if (!d_is_dir(dentry))
30492 + err = au_do_refresh(dentry, /*dir_flags*/0,
30495 + err = au_do_refresh(dentry, dir_flags, parent);
30496 + if (unlikely(err))
30497 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30500 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30501 + AuDbgDentry(dentry);
30507 + au_refresh_dop(dentry, /*force_reval*/0);
30509 + au_refresh_dop(dentry, /*force_reval*/1);
30515 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30517 + int err, i, j, ndentry, e;
30518 + unsigned int sigen;
30519 + struct au_dcsub_pages dpages;
30520 + struct au_dpage *dpage;
30521 + struct dentry **dentries, *d;
30522 + struct au_sbinfo *sbinfo;
30523 + struct dentry *root = sb->s_root;
30524 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30527 + au_refresh_dop(root, /*force_reval*/0);
30529 + err = au_dpages_init(&dpages, GFP_NOFS);
30530 + if (unlikely(err))
30532 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30533 + if (unlikely(err))
30536 + sigen = au_sigen(sb);
30537 + sbinfo = au_sbi(sb);
30538 + for (i = 0; i < dpages.ndpage; i++) {
30539 + dpage = dpages.dpages + i;
30540 + dentries = dpage->dentries;
30541 + ndentry = dpage->ndentry;
30542 + for (j = 0; j < ndentry; j++) {
30544 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30546 + if (unlikely(e && !err))
30548 + /* go on even err */
30553 + au_dpages_free(&dpages);
30558 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30561 + unsigned int sigen;
30562 + unsigned long long max, ull;
30563 + struct inode *inode, **array;
30565 + array = au_iarray_alloc(sb, &max);
30566 + err = PTR_ERR(array);
30567 + if (IS_ERR(array))
30571 + sigen = au_sigen(sb);
30572 + for (ull = 0; ull < max; ull++) {
30573 + inode = array[ull];
30574 + if (unlikely(!inode))
30578 + ii_write_lock_child(inode);
30579 + if (au_iigen(inode, NULL) != sigen) {
30580 + e = au_refresh_hinode_self(inode);
30581 + if (unlikely(e)) {
30582 + au_refresh_iop(inode, /*force_getattr*/1);
30583 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30586 + /* go on even if err */
30589 + if (!e && do_idop)
30590 + au_refresh_iop(inode, /*force_getattr*/0);
30591 + ii_write_unlock(inode);
30594 + au_iarray_free(array, max);
30600 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30603 + unsigned int udba;
30604 + aufs_bindex_t bindex, bbot;
30605 + struct dentry *root;
30606 + struct inode *inode;
30607 + struct au_branch *br;
30608 + struct au_sbinfo *sbi;
30610 + au_sigen_inc(sb);
30611 + sbi = au_sbi(sb);
30612 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30614 + root = sb->s_root;
30615 + DiMustNoWaiters(root);
30616 + inode = d_inode(root);
30617 + IiMustNoWaiters(inode);
30619 + udba = au_opt_udba(sb);
30620 + bbot = au_sbbot(sb);
30621 + for (bindex = 0; bindex <= bbot; bindex++) {
30622 + br = au_sbr(sb, bindex);
30623 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30624 + if (unlikely(err))
30625 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30627 + /* go on even if err */
30629 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30632 + if (au_ftest_si(sbi, NO_DREVAL)) {
30633 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30634 + sb->s_d_op = &aufs_dop_noreval;
30635 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30636 + sbi->si_iop_array = aufs_iop_nogetattr;
30638 + AuDebugOn(sb->s_d_op == &aufs_dop);
30639 + sb->s_d_op = &aufs_dop;
30640 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30641 + sbi->si_iop_array = aufs_iop;
30643 + pr_info("reset to %ps and %ps\n",
30644 + sb->s_d_op, sbi->si_iop_array);
30647 + di_write_unlock(root);
30648 + err = au_refresh_d(sb, do_idop);
30649 + e = au_refresh_i(sb, do_idop);
30650 + if (unlikely(e && !err))
30652 + /* aufs_write_lock() calls ..._child() */
30653 + di_write_lock_child(root);
30655 + au_cpup_attr_all(inode, /*force*/1);
30657 + if (unlikely(err))
30658 + AuIOErr("refresh failed, ignored, %d\n", err);
30661 +const struct super_operations aufs_sop = {
30662 + .alloc_inode = aufs_alloc_inode,
30663 + .destroy_inode = aufs_destroy_inode,
30664 + .free_inode = aufs_free_inode,
30665 + /* always deleting, no clearing */
30666 + .drop_inode = generic_delete_inode,
30667 + .show_options = aufs_show_options,
30668 + .statfs = aufs_statfs,
30669 + .put_super = aufs_put_super,
30670 + .sync_fs = aufs_sync_fs
30673 +/* ---------------------------------------------------------------------- */
30675 +int au_alloc_root(struct super_block *sb)
30678 + struct inode *inode;
30679 + struct dentry *root;
30682 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30683 + err = PTR_ERR(inode);
30684 + if (IS_ERR(inode))
30687 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30688 + inode->i_fop = &aufs_dir_fop;
30689 + inode->i_mode = S_IFDIR;
30690 + set_nlink(inode, 2);
30691 + unlock_new_inode(inode);
30693 + root = d_make_root(inode);
30694 + if (unlikely(!root))
30696 + err = PTR_ERR(root);
30697 + if (IS_ERR(root))
30700 + err = au_di_init(root);
30702 + sb->s_root = root;
30703 + return 0; /* success */
30711 +/* ---------------------------------------------------------------------- */
30713 +static void aufs_kill_sb(struct super_block *sb)
30715 + struct au_sbinfo *sbinfo;
30716 + struct dentry *root;
30718 + sbinfo = au_sbi(sb);
30722 + au_sbilist_del(sb);
30724 + root = sb->s_root;
30726 + aufs_write_lock(root);
30728 + __si_write_lock(sb);
30731 + if (sbinfo->si_wbr_create_ops->fin)
30732 + sbinfo->si_wbr_create_ops->fin(sb);
30733 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30734 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30735 + au_remount_refresh(sb, /*do_idop*/0);
30737 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30738 + au_plink_put(sb, /*verbose*/1);
30741 + au_dr_opt_flush(sb);
30744 + aufs_write_unlock(root);
30746 + __si_write_unlock(sb);
30748 + sbinfo->si_sb = NULL;
30749 + au_nwt_flush(&sbinfo->si_nowait);
30752 + kill_anon_super(sb);
30755 +struct file_system_type aufs_fs_type = {
30756 + .name = AUFS_FSTYPE,
30757 + /* a race between rename and others */
30758 + .fs_flags = FS_RENAME_DOES_D_MOVE
30760 + /*| FS_ALLOW_IDMAP*/
30762 + .init_fs_context = aufs_fsctx_init,
30763 + .parameters = aufs_fsctx_paramspec,
30764 + .kill_sb = aufs_kill_sb,
30765 + /* no need to __module_get() and module_put(). */
30766 + .owner = THIS_MODULE,
30768 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30769 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30770 +++ linux/fs/aufs/super.h 2024-05-13 17:13:00.621404284 +0200
30772 +/* SPDX-License-Identifier: GPL-2.0 */
30774 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30776 + * This program is free software; you can redistribute it and/or modify
30777 + * it under the terms of the GNU General Public License as published by
30778 + * the Free Software Foundation; either version 2 of the License, or
30779 + * (at your option) any later version.
30781 + * This program is distributed in the hope that it will be useful,
30782 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30783 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30784 + * GNU General Public License for more details.
30786 + * You should have received a copy of the GNU General Public License
30787 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30791 + * super_block operations
30794 +#ifndef __AUFS_SUPER_H__
30795 +#define __AUFS_SUPER_H__
30799 +#include <linux/fs.h>
30800 +#include <linux/kobject.h>
30803 +#include "rwsem.h"
30806 +/* policies to select one among multiple writable branches */
30807 +struct au_wbr_copyup_operations {
30808 + int (*copyup)(struct dentry *dentry);
30811 +#define AuWbr_DIR BIT(0) /* target is a dir */
30812 +#define AuWbr_PARENT BIT(1) /* always require a parent */
30814 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30815 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30816 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30818 +struct au_wbr_create_operations {
30819 + int (*create)(struct dentry *dentry, unsigned int flags);
30820 + int (*init)(struct super_block *sb);
30821 + int (*fin)(struct super_block *sb);
30824 +struct au_wbr_mfs {
30825 + struct mutex mfs_lock; /* protect this structure */
30826 + unsigned long mfs_jiffy;
30827 + unsigned long mfs_expire;
30828 + aufs_bindex_t mfs_bindex;
30830 + unsigned long long mfsrr_bytes;
30831 + unsigned long long mfsrr_watermark;
30834 +#define AuPlink_NHASH 100
30835 +static inline int au_plink_hash(ino_t ino)
30837 + return ino % AuPlink_NHASH;
30840 +/* File-based Hierarchical Storage Management */
30842 +#ifdef CONFIG_AUFS_FHSM
30843 + /* allow only one process who can receive the notification */
30844 + spinlock_t fhsm_spin;
30846 + wait_queue_head_t fhsm_wqh;
30847 + atomic_t fhsm_readable;
30849 + /* these are protected by si_rwsem */
30850 + unsigned long fhsm_expire;
30851 + aufs_bindex_t fhsm_bottom;
30856 +struct au_sbinfo {
30857 + /* nowait tasks in the system-wide workqueue */
30858 + struct au_nowait_tasks si_nowait;
30861 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30862 + * rwsem for au_sbinfo is necessary.
30864 + struct au_rwsem si_rwsem;
30867 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30870 + au_lcnt_t si_ninodes, si_nfiles;
30872 + /* branch management */
30873 + unsigned int si_generation;
30875 + /* see AuSi_ flags */
30876 + unsigned char au_si_status;
30878 + aufs_bindex_t si_bbot;
30880 + /* dirty trick to keep br_id plus */
30881 + unsigned int si_last_br_id :
30882 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30883 + struct au_branch **si_branch;
30885 + /* policy to select a writable branch */
30886 + unsigned char si_wbr_copyup;
30887 + unsigned char si_wbr_create;
30888 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30889 + struct au_wbr_create_operations *si_wbr_create_ops;
30891 + /* round robin */
30892 + atomic_t si_wbr_rr_next;
30894 + /* most free space */
30895 + struct au_wbr_mfs si_wbr_mfs;
30897 + /* File-based Hierarchical Storage Management */
30898 + struct au_fhsm si_fhsm;
30900 + /* mount flags */
30901 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30902 + unsigned int si_mntflags;
30904 + /* external inode number (bitmap and translation table) */
30905 + loff_t si_ximaxent; /* max entries in a xino */
30907 + struct file *si_xib;
30908 + struct mutex si_xib_mtx; /* protect xib members */
30909 + unsigned long *si_xib_buf;
30910 + unsigned long si_xib_last_pindex;
30911 + int si_xib_next_bit;
30913 + unsigned long si_xino_jiffy;
30914 + unsigned long si_xino_expire;
30915 + /* reserved for future use */
30916 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30918 +#ifdef CONFIG_AUFS_EXPORT
30919 + /* i_generation */
30920 + /* todo: make xigen file an array to support many inode numbers */
30921 + struct file *si_xigen;
30922 + atomic_t si_xigen_next;
30925 + /* dirty trick to support atomic_open */
30926 + struct hlist_bl_head si_aopen;
30928 + /* vdir parameters */
30929 + unsigned long si_rdcache; /* max cache time in jiffies */
30930 + unsigned int si_rdblk; /* deblk size */
30931 + unsigned int si_rdhash; /* hash size */
30934 + * If the number of whiteouts are larger than si_dirwh, leave all of
30935 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30936 + * future fsck.aufs or kernel thread will remove them later.
30937 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30939 + unsigned int si_dirwh;
30941 + /* pseudo_link list */
30942 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30943 + wait_queue_head_t si_plink_wq;
30944 + spinlock_t si_plink_maint_lock;
30945 + pid_t si_plink_maint_pid;
30948 + struct hlist_bl_head si_files;
30950 + /* with/without getattr, brother of sb->s_d_op */
30951 + const struct inode_operations *si_iop_array;
30954 + * sysfs and lifetime management.
30955 + * this is not a small structure and it may be a waste of memory in case
30956 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30957 + * but using sysfs is majority.
30959 + struct kobject si_kobj;
30960 +#ifdef CONFIG_DEBUG_FS
30961 + struct dentry *si_dbgaufs;
30962 + struct dentry *si_dbgaufs_plink;
30963 + struct dentry *si_dbgaufs_xib;
30964 +#ifdef CONFIG_AUFS_EXPORT
30965 + struct dentry *si_dbgaufs_xigen;
30969 +#ifdef CONFIG_AUFS_SBILIST
30970 + struct hlist_bl_node si_list;
30973 + /* dirty, necessary for unmounting, sysfs and sysrq */
30974 + struct super_block *si_sb;
30977 +/* sbinfo status flags */
30979 + * set true when refresh_dirs() failed at remount time.
30980 + * then try refreshing dirs at access time again.
30981 + * if it is false, refreshing dirs at access time is unnecessary
30983 +#define AuSi_FAILED_REFRESH_DIR BIT(0)
30984 +#define AuSi_FHSM BIT(1) /* fhsm is active now */
30985 +#define AuSi_NO_DREVAL BIT(2) /* disable all d_revalidate */
30987 +#ifndef CONFIG_AUFS_FHSM
30989 +#define AuSi_FHSM 0
30992 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30993 + unsigned int flag)
30995 + AuRwMustAnyLock(&sbi->si_rwsem);
30996 + return sbi->au_si_status & flag;
30998 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30999 +#define au_fset_si(sbinfo, name) do { \
31000 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
31001 + (sbinfo)->au_si_status |= AuSi_##name; \
31003 +#define au_fclr_si(sbinfo, name) do { \
31004 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
31005 + (sbinfo)->au_si_status &= ~AuSi_##name; \
31008 +/* ---------------------------------------------------------------------- */
31010 +/* policy to select one among writable branches */
31011 +#define AuWbrCopyup(sbinfo, ...) \
31012 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
31013 +#define AuWbrCreate(sbinfo, ...) \
31014 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
31016 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
31017 +#define AuLock_DW BIT(0) /* write-lock dentry */
31018 +#define AuLock_IR BIT(1) /* read-lock inode */
31019 +#define AuLock_IW BIT(2) /* write-lock inode */
31020 +#define AuLock_FLUSH BIT(3) /* wait for 'nowait' tasks */
31021 +#define AuLock_DIRS BIT(4) /* target is a pair of dirs */
31022 + /* except RENAME_EXCHANGE */
31023 +#define AuLock_NOPLM BIT(5) /* return err in plm mode */
31024 +#define AuLock_NOPLMW BIT(6) /* wait for plm mode ends */
31025 +#define AuLock_GEN BIT(7) /* test digen/iigen */
31026 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
31027 +#define au_fset_lock(flags, name) \
31028 + do { (flags) |= AuLock_##name; } while (0)
31029 +#define au_fclr_lock(flags, name) \
31030 + do { (flags) &= ~AuLock_##name; } while (0)
31032 +/* ---------------------------------------------------------------------- */
31035 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
31037 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
31038 + unsigned long long max, void *arg);
31039 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
31040 + struct super_block *sb, void *arg);
31041 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
31042 +void au_iarray_free(struct inode **a, unsigned long long max);
31044 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
31045 +extern const struct super_operations aufs_sop;
31046 +int au_alloc_root(struct super_block *sb);
31047 +extern struct file_system_type aufs_fs_type;
31050 +void au_si_free(struct kobject *kobj);
31051 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31052 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31054 +unsigned int au_sigen_inc(struct super_block *sb);
31055 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31057 +int si_read_lock(struct super_block *sb, int flags);
31058 +int si_write_lock(struct super_block *sb, int flags);
31059 +int aufs_read_lock(struct dentry *dentry, int flags);
31060 +void aufs_read_unlock(struct dentry *dentry, int flags);
31061 +void aufs_write_lock(struct dentry *dentry);
31062 +void aufs_write_unlock(struct dentry *dentry);
31063 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31064 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31066 +/* wbr_policy.c */
31067 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31068 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31069 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31070 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31071 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31074 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31076 +#ifdef CONFIG_AUFS_FHSM
31079 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31083 + spin_lock(&fhsm->fhsm_spin);
31084 + pid = fhsm->fhsm_pid;
31085 + spin_unlock(&fhsm->fhsm_spin);
31090 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31091 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31092 +int au_fhsm_fd(struct super_block *sb, int oflags);
31093 +int au_fhsm_br_alloc(struct au_branch *br);
31094 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31095 +void au_fhsm_fin(struct super_block *sb);
31096 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31097 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31098 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31100 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31102 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31103 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31104 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31105 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31106 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31107 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31108 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31109 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31110 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31113 +/* ---------------------------------------------------------------------- */
31115 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31117 + return sb->s_fs_info;
31120 +/* ---------------------------------------------------------------------- */
31122 +#ifdef CONFIG_AUFS_EXPORT
31123 +int au_test_nfsd(void);
31124 +void au_export_init(struct super_block *sb);
31125 +void au_xigen_inc(struct inode *inode);
31126 +int au_xigen_new(struct inode *inode);
31127 +int au_xigen_set(struct super_block *sb, struct path *path);
31128 +void au_xigen_clr(struct super_block *sb);
31130 +static inline int au_busy_or_stale(void)
31132 + if (!au_test_nfsd())
31137 +AuStubInt0(au_test_nfsd, void)
31138 +AuStubVoid(au_export_init, struct super_block *sb)
31139 +AuStubVoid(au_xigen_inc, struct inode *inode)
31140 +AuStubInt0(au_xigen_new, struct inode *inode)
31141 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31142 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31143 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31144 +#endif /* CONFIG_AUFS_EXPORT */
31146 +/* ---------------------------------------------------------------------- */
31148 +#ifdef CONFIG_AUFS_SBILIST
31150 +extern struct hlist_bl_head au_sbilist;
31152 +static inline void au_sbilist_init(void)
31154 + INIT_HLIST_BL_HEAD(&au_sbilist);
31157 +static inline void au_sbilist_add(struct super_block *sb)
31159 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31162 +static inline void au_sbilist_del(struct super_block *sb)
31164 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31167 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31168 +static inline void au_sbilist_lock(void)
31170 + hlist_bl_lock(&au_sbilist);
31173 +static inline void au_sbilist_unlock(void)
31175 + hlist_bl_unlock(&au_sbilist);
31177 +#define AuGFP_SBILIST GFP_ATOMIC
31179 +AuStubVoid(au_sbilist_lock, void)
31180 +AuStubVoid(au_sbilist_unlock, void)
31181 +#define AuGFP_SBILIST GFP_NOFS
31182 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31184 +AuStubVoid(au_sbilist_init, void)
31185 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31186 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31187 +AuStubVoid(au_sbilist_lock, void)
31188 +AuStubVoid(au_sbilist_unlock, void)
31189 +#define AuGFP_SBILIST GFP_NOFS
31192 +/* ---------------------------------------------------------------------- */
31194 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31197 + * This function is a dynamic '__init' function actually,
31198 + * so the tiny check for si_rwsem is unnecessary.
31200 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31201 +#ifdef CONFIG_DEBUG_FS
31202 + sbinfo->si_dbgaufs = NULL;
31203 + sbinfo->si_dbgaufs_plink = NULL;
31204 + sbinfo->si_dbgaufs_xib = NULL;
31205 +#ifdef CONFIG_AUFS_EXPORT
31206 + sbinfo->si_dbgaufs_xigen = NULL;
31211 +/* ---------------------------------------------------------------------- */
31213 +/* current->atomic_flags */
31214 +/* this value should never corrupt the ones defined in linux/sched.h */
31215 +#define PFA_AUFS 0x10
31217 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31218 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31219 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31221 +static inline int si_pid_test(struct super_block *sb)
31223 + return !!task_test_aufs(current);
31226 +static inline void si_pid_clr(struct super_block *sb)
31228 + AuDebugOn(!task_test_aufs(current));
31229 + task_clear_aufs(current);
31232 +static inline void si_pid_set(struct super_block *sb)
31234 + AuDebugOn(task_test_aufs(current));
31235 + task_set_aufs(current);
31238 +/* ---------------------------------------------------------------------- */
31240 +/* lock superblock. mainly for entry point functions */
31241 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31242 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31243 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31244 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31246 +#define __si_read_trylock_nested(sb) \
31247 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31248 +#define __si_write_trylock_nested(sb) \
31249 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31252 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31253 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31254 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31256 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31257 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31258 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31260 +static inline void si_noflush_read_lock(struct super_block *sb)
31262 + __si_read_lock(sb);
31266 +static inline int si_noflush_read_trylock(struct super_block *sb)
31270 + locked = __si_read_trylock(sb);
31276 +static inline void si_noflush_write_lock(struct super_block *sb)
31278 + __si_write_lock(sb);
31282 +static inline int si_noflush_write_trylock(struct super_block *sb)
31286 + locked = __si_write_trylock(sb);
31292 +#if 0 /* reserved */
31293 +static inline int si_read_trylock(struct super_block *sb, int flags)
31295 + if (au_ftest_lock(flags, FLUSH))
31296 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31297 + return si_noflush_read_trylock(sb);
31301 +static inline void si_read_unlock(struct super_block *sb)
31304 + __si_read_unlock(sb);
31307 +#if 0 /* reserved */
31308 +static inline int si_write_trylock(struct super_block *sb, int flags)
31310 + if (au_ftest_lock(flags, FLUSH))
31311 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31312 + return si_noflush_write_trylock(sb);
31316 +static inline void si_write_unlock(struct super_block *sb)
31319 + __si_write_unlock(sb);
31322 +#if 0 /* reserved */
31323 +static inline void si_downgrade_lock(struct super_block *sb)
31325 + __si_downgrade_lock(sb);
31329 +/* ---------------------------------------------------------------------- */
31331 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31333 + SiMustAnyLock(sb);
31334 + return au_sbi(sb)->si_bbot;
31337 +static inline unsigned int au_mntflags(struct super_block *sb)
31339 + SiMustAnyLock(sb);
31340 + return au_sbi(sb)->si_mntflags;
31343 +static inline unsigned int au_sigen(struct super_block *sb)
31345 + SiMustAnyLock(sb);
31346 + return au_sbi(sb)->si_generation;
31349 +static inline struct au_branch *au_sbr(struct super_block *sb,
31350 + aufs_bindex_t bindex)
31352 + SiMustAnyLock(sb);
31353 + return au_sbi(sb)->si_branch[0 + bindex];
31356 +static inline loff_t au_xi_maxent(struct super_block *sb)
31358 + SiMustAnyLock(sb);
31359 + return au_sbi(sb)->si_ximaxent;
31362 +#endif /* __KERNEL__ */
31363 +#endif /* __AUFS_SUPER_H__ */
31364 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31365 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31366 +++ linux/fs/aufs/sysaufs.c 2024-05-13 17:13:00.621404284 +0200
31368 +// SPDX-License-Identifier: GPL-2.0
31370 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31372 + * This program is free software; you can redistribute it and/or modify
31373 + * it under the terms of the GNU General Public License as published by
31374 + * the Free Software Foundation; either version 2 of the License, or
31375 + * (at your option) any later version.
31377 + * This program is distributed in the hope that it will be useful,
31378 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31379 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31380 + * GNU General Public License for more details.
31382 + * You should have received a copy of the GNU General Public License
31383 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31387 + * sysfs interface and lifetime management
31388 + * they are necessary regardless sysfs is disabled.
31391 +#include <linux/random.h>
31394 +unsigned long sysaufs_si_mask;
31395 +struct kset *sysaufs_kset;
31397 +#define AuSiAttr(_name) { \
31398 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31399 + .show = sysaufs_si_##_name, \
31402 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31403 +struct attribute *sysaufs_si_attrs[] = {
31404 + &sysaufs_si_attr_xi_path.attr,
31407 +ATTRIBUTE_GROUPS(sysaufs_si);
31409 +static const struct sysfs_ops au_sbi_ops = {
31410 + .show = sysaufs_si_show
31413 +static const struct kobj_type au_sbi_ktype = {
31414 + .release = au_si_free,
31415 + .sysfs_ops = &au_sbi_ops,
31416 + .default_groups = sysaufs_si_groups
31419 +/* ---------------------------------------------------------------------- */
31421 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31425 + sbinfo->si_kobj.kset = sysaufs_kset;
31426 + /* cf. sysaufs_name() */
31427 + err = kobject_init_and_add
31428 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31429 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31434 +void sysaufs_fin(void)
31436 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31437 + kset_unregister(sysaufs_kset);
31440 +int __init sysaufs_init(void)
31445 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31446 + } while (!sysaufs_si_mask);
31449 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31450 + if (unlikely(!sysaufs_kset))
31452 + err = PTR_ERR(sysaufs_kset);
31453 + if (IS_ERR(sysaufs_kset))
31455 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31456 + if (unlikely(err))
31457 + kset_unregister(sysaufs_kset);
31462 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31463 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31464 +++ linux/fs/aufs/sysaufs.h 2024-05-13 17:13:00.621404284 +0200
31466 +/* SPDX-License-Identifier: GPL-2.0 */
31468 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31470 + * This program is free software; you can redistribute it and/or modify
31471 + * it under the terms of the GNU General Public License as published by
31472 + * the Free Software Foundation; either version 2 of the License, or
31473 + * (at your option) any later version.
31475 + * This program is distributed in the hope that it will be useful,
31476 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31477 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31478 + * GNU General Public License for more details.
31480 + * You should have received a copy of the GNU General Public License
31481 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31485 + * sysfs interface and mount lifetime management
31488 +#ifndef __SYSAUFS_H__
31489 +#define __SYSAUFS_H__
31493 +#include <linux/sysfs.h>
31494 +#include "module.h"
31496 +struct super_block;
31499 +struct sysaufs_si_attr {
31500 + struct attribute attr;
31501 + int (*show)(struct seq_file *seq, struct super_block *sb);
31504 +/* ---------------------------------------------------------------------- */
31507 +extern unsigned long sysaufs_si_mask;
31508 +extern struct kset *sysaufs_kset;
31509 +extern struct attribute *sysaufs_si_attrs[];
31510 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31511 +int __init sysaufs_init(void);
31512 +void sysaufs_fin(void);
31514 +/* ---------------------------------------------------------------------- */
31516 +/* some people doesn't like to show a pointer in kernel */
31517 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31519 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31522 +#define SysaufsSiNamePrefix "si_"
31523 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31524 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31526 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31527 + sysaufs_si_id(sbinfo));
31531 +#ifdef CONFIG_SYSFS
31533 +extern struct attribute_group *sysaufs_attr_group;
31535 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31536 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31538 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31539 +#ifdef CONFIG_COMPAT
31540 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31543 +void sysaufs_br_init(struct au_branch *br);
31544 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31545 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31547 +#define sysaufs_brs_init() do {} while (0)
31550 +#define sysaufs_attr_group NULL
31552 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31553 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31554 + struct attribute *attr, char *buf)
31555 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31556 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31557 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31559 +static inline void sysaufs_brs_init(void)
31564 +#endif /* CONFIG_SYSFS */
31566 +#endif /* __KERNEL__ */
31567 +#endif /* __SYSAUFS_H__ */
31568 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31569 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31570 +++ linux/fs/aufs/sysfs.c 2024-05-13 17:13:00.621404284 +0200
31572 +// SPDX-License-Identifier: GPL-2.0
31574 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31576 + * This program is free software; you can redistribute it and/or modify
31577 + * it under the terms of the GNU General Public License as published by
31578 + * the Free Software Foundation; either version 2 of the License, or
31579 + * (at your option) any later version.
31581 + * This program is distributed in the hope that it will be useful,
31582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31584 + * GNU General Public License for more details.
31586 + * You should have received a copy of the GNU General Public License
31587 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31591 + * sysfs interface
31594 +#include <linux/compat.h>
31595 +#include <linux/seq_file.h>
31598 +#ifdef CONFIG_AUFS_FS_MODULE
31599 +/* this entry violates the "one line per file" policy of sysfs */
31600 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31604 + static char *conf =
31605 +/* this file is generated at compiling */
31606 +#include "conf.str"
31609 + err = snprintf(buf, PAGE_SIZE, conf);
31610 + if (unlikely(err >= PAGE_SIZE))
31615 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31618 +static struct attribute *au_attr[] = {
31619 +#ifdef CONFIG_AUFS_FS_MODULE
31620 + &au_config_attr.attr,
31622 + NULL, /* need to NULL terminate the list of attributes */
31625 +static struct attribute_group sysaufs_attr_group_body = {
31629 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31631 +/* ---------------------------------------------------------------------- */
31633 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31637 + SiMustAnyLock(sb);
31640 + if (au_opt_test(au_mntflags(sb), XINO)) {
31641 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31642 + seq_putc(seq, '\n');
31648 + * the lifetime of branch is independent from the entry under sysfs.
31649 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31652 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31653 + aufs_bindex_t bindex, int idx)
31656 + struct path path;
31657 + struct dentry *root;
31658 + struct au_branch *br;
31659 + au_br_perm_str_t perm;
31661 + AuDbg("b%d\n", bindex);
31664 + root = sb->s_root;
31665 + di_read_lock_parent(root, !AuLock_IR);
31666 + br = au_sbr(sb, bindex);
31669 + case AuBrSysfs_BR:
31670 + path.mnt = au_br_mnt(br);
31671 + path.dentry = au_h_dptr(root, bindex);
31672 + err = au_seq_path(seq, &path);
31674 + au_optstr_br_perm(&perm, br->br_perm);
31675 + seq_printf(seq, "=%s\n", perm.a);
31678 + case AuBrSysfs_BRID:
31679 + seq_printf(seq, "%d\n", br->br_id);
31682 + di_read_unlock(root, !AuLock_IR);
31683 + if (unlikely(err || seq_has_overflowed(seq)))
31689 +/* ---------------------------------------------------------------------- */
31691 +static struct seq_file *au_seq(char *p, ssize_t len)
31693 + struct seq_file *seq;
31695 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31697 + /* mutex_init(&seq.lock); */
31700 + return seq; /* success */
31703 + seq = ERR_PTR(-ENOMEM);
31707 +#define SysaufsBr_PREFIX "br"
31708 +#define SysaufsBrid_PREFIX "brid"
31710 +/* todo: file size may exceed PAGE_SIZE */
31711 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31717 + aufs_bindex_t bbot;
31718 + struct au_sbinfo *sbinfo;
31719 + struct super_block *sb;
31720 + struct seq_file *seq;
31722 + struct attribute **cattr;
31724 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31725 + sb = sbinfo->si_sb;
31728 + * prevent a race condition between sysfs and aufs.
31729 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31730 + * prohibits maintaining the sysfs entries.
31731 + * hew we acquire read lock after sysfs_get_active_two().
31732 + * on the other hand, the remount process may maintain the sysfs/aufs
31733 + * entries after acquiring write lock.
31734 + * it can cause a deadlock.
31735 + * simply we gave up processing read here.
31738 + if (unlikely(!si_noflush_read_trylock(sb)))
31741 + seq = au_seq(buf, PAGE_SIZE);
31742 + err = PTR_ERR(seq);
31746 + name = (void *)attr->name;
31747 + cattr = sysaufs_si_attrs;
31749 + if (!strcmp(name, (*cattr)->name)) {
31750 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31757 + if (!strncmp(name, SysaufsBrid_PREFIX,
31758 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31759 + idx = AuBrSysfs_BRID;
31760 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31761 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31762 + sizeof(SysaufsBr_PREFIX) - 1)) {
31763 + idx = AuBrSysfs_BR;
31764 + name += sizeof(SysaufsBr_PREFIX) - 1;
31768 + err = kstrtol(name, 10, &l);
31770 + bbot = au_sbbot(sb);
31772 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31779 + err = seq->count;
31780 + /* sysfs limit */
31781 + if (unlikely(err == PAGE_SIZE))
31784 + au_kfree_rcu(seq);
31786 + si_read_unlock(sb);
31791 +/* ---------------------------------------------------------------------- */
31793 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31797 + aufs_bindex_t bindex, bbot;
31800 + struct seq_file *seq;
31801 + struct au_branch *br;
31803 + si_read_lock(sb, AuLock_FLUSH);
31804 + bbot = au_sbbot(sb);
31810 + buf = (void *)__get_free_page(GFP_NOFS);
31811 + if (unlikely(!buf))
31814 + seq = au_seq(buf, PAGE_SIZE);
31815 + err = PTR_ERR(seq);
31819 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31820 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31821 + /* VERIFY_WRITE */
31822 + err = !access_ok(arg, sizeof(*arg));
31823 + if (unlikely(err))
31826 + br = au_sbr(sb, bindex);
31827 + brid = br->br_id;
31828 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31829 + err = __put_user(brid, &arg->id);
31830 + if (unlikely(err))
31833 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31834 + err = __put_user(br->br_perm, &arg->perm);
31835 + if (unlikely(err))
31838 + err = au_seq_path(seq, &br->br_path);
31839 + if (unlikely(err))
31841 + seq_putc(seq, '\0');
31842 + if (!seq_has_overflowed(seq)) {
31843 + err = copy_to_user(arg->path, seq->buf, seq->count);
31845 + if (unlikely(err))
31852 + if (unlikely(err))
31856 + au_kfree_rcu(seq);
31858 + free_page((unsigned long)buf);
31860 + si_read_unlock(sb);
31864 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31866 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31869 +#ifdef CONFIG_COMPAT
31870 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31872 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31876 +/* ---------------------------------------------------------------------- */
31878 +void sysaufs_br_init(struct au_branch *br)
31881 + struct au_brsysfs *br_sysfs;
31882 + struct attribute *attr;
31884 + br_sysfs = br->br_sysfs;
31885 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31886 + attr = &br_sysfs->attr;
31887 + sysfs_attr_init(attr);
31888 + attr->name = br_sysfs->name;
31889 + attr->mode = 0444;
31894 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31896 + struct au_branch *br;
31897 + struct kobject *kobj;
31898 + struct au_brsysfs *br_sysfs;
31900 + aufs_bindex_t bbot;
31902 + if (!sysaufs_brs)
31905 + kobj = &au_sbi(sb)->si_kobj;
31906 + bbot = au_sbbot(sb);
31907 + for (; bindex <= bbot; bindex++) {
31908 + br = au_sbr(sb, bindex);
31909 + br_sysfs = br->br_sysfs;
31910 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31911 + sysfs_remove_file(kobj, &br_sysfs->attr);
31917 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31920 + aufs_bindex_t bbot;
31921 + struct kobject *kobj;
31922 + struct au_branch *br;
31923 + struct au_brsysfs *br_sysfs;
31925 + if (!sysaufs_brs)
31928 + kobj = &au_sbi(sb)->si_kobj;
31929 + bbot = au_sbbot(sb);
31930 + for (; bindex <= bbot; bindex++) {
31931 + br = au_sbr(sb, bindex);
31932 + br_sysfs = br->br_sysfs;
31933 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31934 + SysaufsBr_PREFIX "%d", bindex);
31935 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31936 + SysaufsBrid_PREFIX "%d", bindex);
31937 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31938 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31939 + if (unlikely(err))
31940 + pr_warn("failed %s under sysfs(%d)\n",
31941 + br_sysfs->name, err);
31946 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31947 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31948 +++ linux/fs/aufs/sysrq.c 2024-05-13 17:13:00.621404284 +0200
31950 +// SPDX-License-Identifier: GPL-2.0
31952 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31954 + * This program is free software; you can redistribute it and/or modify
31955 + * it under the terms of the GNU General Public License as published by
31956 + * the Free Software Foundation; either version 2 of the License, or
31957 + * (at your option) any later version.
31959 + * This program is distributed in the hope that it will be useful,
31960 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31961 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31962 + * GNU General Public License for more details.
31964 + * You should have received a copy of the GNU General Public License
31965 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31969 + * magic sysrq handler
31972 +/* #include <linux/sysrq.h> */
31973 +#include <linux/writeback.h>
31976 +/* ---------------------------------------------------------------------- */
31978 +static void sysrq_sb(struct super_block *sb)
31981 + struct au_sbinfo *sbinfo;
31982 + struct file *file;
31983 + struct hlist_bl_head *files;
31984 + struct hlist_bl_node *pos;
31985 + struct au_finfo *finfo;
31988 + plevel = au_plevel;
31989 + au_plevel = KERN_WARNING;
31991 + /* since we define pr_fmt, call printk directly */
31992 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31994 + sbinfo = au_sbi(sb);
31995 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31996 + pr("superblock\n");
31999 +#if 0 /* reserved */
32001 + int err, i, j, ndentry;
32002 + struct au_dcsub_pages dpages;
32003 + struct au_dpage *dpage;
32005 + err = au_dpages_init(&dpages, GFP_ATOMIC);
32006 + if (unlikely(err))
32008 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
32010 + for (i = 0; i < dpages.ndpage; i++) {
32011 + dpage = dpages.dpages + i;
32012 + ndentry = dpage->ndentry;
32013 + for (j = 0; j < ndentry; j++)
32014 + au_dpri_dentry(dpage->dentries[j]);
32016 + au_dpages_free(&dpages);
32020 + pr("isolated inode\n");
32021 + spin_lock(&sb->s_inode_list_lock);
32022 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
32023 + spin_lock(&i->i_lock);
32024 + if (hlist_empty(&i->i_dentry))
32025 + au_dpri_inode(i);
32026 + spin_unlock(&i->i_lock);
32028 + spin_unlock(&sb->s_inode_list_lock);
32031 + files = &au_sbi(sb)->si_files;
32032 + hlist_bl_lock(files);
32033 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
32036 + file = finfo->fi_file;
32037 + mode = file_inode(file)->i_mode;
32038 + if (!special_file(mode))
32039 + au_dpri_file(file);
32041 + hlist_bl_unlock(files);
32045 + au_plevel = plevel;
32048 +/* ---------------------------------------------------------------------- */
32050 +/* module parameter */
32051 +static char *aufs_sysrq_key = "a";
32052 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32053 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32055 +static void au_sysrq(u8 key __maybe_unused)
32057 + struct au_sbinfo *sbinfo;
32058 + struct hlist_bl_node *pos;
32061 + au_sbilist_lock();
32062 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32063 + sysrq_sb(sbinfo->si_sb);
32064 + au_sbilist_unlock();
32068 +static struct sysrq_key_op au_sysrq_op = {
32069 + .handler = au_sysrq,
32070 + .help_msg = "Aufs",
32071 + .action_msg = "Aufs",
32072 + .enable_mask = SYSRQ_ENABLE_DUMP
32075 +/* ---------------------------------------------------------------------- */
32077 +int __init au_sysrq_init(void)
32083 + key = *aufs_sysrq_key;
32084 + if ('a' <= key && key <= 'z')
32085 + err = register_sysrq_key(key, &au_sysrq_op);
32086 + if (unlikely(err))
32087 + pr_err("err %d, sysrq=%c\n", err, key);
32091 +void au_sysrq_fin(void)
32095 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32096 + if (unlikely(err))
32097 + pr_err("err %d (ignored)\n", err);
32099 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32100 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32101 +++ linux/fs/aufs/vdir.c 2024-05-13 17:13:00.621404284 +0200
32103 +// SPDX-License-Identifier: GPL-2.0
32105 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32107 + * This program is free software; you can redistribute it and/or modify
32108 + * it under the terms of the GNU General Public License as published by
32109 + * the Free Software Foundation; either version 2 of the License, or
32110 + * (at your option) any later version.
32112 + * This program is distributed in the hope that it will be useful,
32113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32115 + * GNU General Public License for more details.
32117 + * You should have received a copy of the GNU General Public License
32118 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32122 + * virtual or vertical directory
32125 +#include <linux/iversion.h>
32128 +static unsigned int calc_size(int nlen)
32130 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32133 +static int set_deblk_end(union au_vdir_deblk_p *p,
32134 + union au_vdir_deblk_p *deblk_end)
32136 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32137 + p->de->de_str.len = 0;
32141 + return -1; /* error */
32144 +/* returns true or false */
32145 +static int is_deblk_end(union au_vdir_deblk_p *p,
32146 + union au_vdir_deblk_p *deblk_end)
32148 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32149 + return !p->de->de_str.len;
32153 +static unsigned char *last_deblk(struct au_vdir *vdir)
32155 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32158 +/* ---------------------------------------------------------------------- */
32160 +/* estimate the appropriate size for name hash table */
32161 +unsigned int au_rdhash_est(loff_t sz)
32169 + if (sz < AUFS_RDHASH_DEF)
32170 + n = AUFS_RDHASH_DEF;
32171 + /* pr_info("n %u\n", n); */
32176 + * the allocated memory has to be freed by
32177 + * au_nhash_wh_free() or au_nhash_de_free().
32179 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32181 + struct hlist_head *head;
32185 + sz = sizeof(*nhash->nh_head) * num_hash;
32186 + head = kmalloc(sz, gfp);
32188 + nhash->nh_num = num_hash;
32189 + nhash->nh_head = head;
32190 + for (u = 0; u < num_hash; u++)
32191 + INIT_HLIST_HEAD(head++);
32192 + return 0; /* success */
32198 +static void nhash_count(struct hlist_head *head)
32200 +#if 0 /* debugging */
32202 + struct hlist_node *pos;
32205 + hlist_for_each(pos, head)
32207 + pr_info("%lu\n", n);
32211 +static void au_nhash_wh_do_free(struct hlist_head *head)
32213 + struct au_vdir_wh *pos;
32214 + struct hlist_node *node;
32216 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32217 + au_kfree_rcu(pos);
32220 +static void au_nhash_de_do_free(struct hlist_head *head)
32222 + struct au_vdir_dehstr *pos;
32223 + struct hlist_node *node;
32225 + hlist_for_each_entry_safe(pos, node, head, hash)
32226 + au_cache_free_vdir_dehstr(pos);
32229 +static void au_nhash_do_free(struct au_nhash *nhash,
32230 + void (*free)(struct hlist_head *head))
32233 + struct hlist_head *head;
32235 + n = nhash->nh_num;
32239 + head = nhash->nh_head;
32240 + while (n-- > 0) {
32241 + nhash_count(head);
32244 + au_kfree_try_rcu(nhash->nh_head);
32247 +void au_nhash_wh_free(struct au_nhash *whlist)
32249 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32252 +static void au_nhash_de_free(struct au_nhash *delist)
32254 + au_nhash_do_free(delist, au_nhash_de_do_free);
32257 +/* ---------------------------------------------------------------------- */
32259 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32263 + unsigned int u, n;
32264 + struct hlist_head *head;
32265 + struct au_vdir_wh *pos;
32268 + n = whlist->nh_num;
32269 + head = whlist->nh_head;
32270 + for (u = 0; u < n; u++, head++)
32271 + hlist_for_each_entry(pos, head, wh_hash)
32272 + if (pos->wh_bindex == btgt && ++num > limit)
32277 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32278 + unsigned char *name,
32279 + unsigned int len)
32282 + /* const unsigned int magic_bit = 12; */
32284 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32291 + /* v = hash_long(v, magic_bit); */
32292 + v %= nhash->nh_num;
32293 + return nhash->nh_head + v;
32296 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32299 + return str->len == nlen && !memcmp(str->name, name, nlen);
32302 +/* returns found or not */
32303 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32305 + struct hlist_head *head;
32306 + struct au_vdir_wh *pos;
32307 + struct au_vdir_destr *str;
32309 + head = au_name_hash(whlist, name, nlen);
32310 + hlist_for_each_entry(pos, head, wh_hash) {
32311 + str = &pos->wh_str;
32312 + AuDbg("%.*s\n", str->len, str->name);
32313 + if (au_nhash_test_name(str, name, nlen))
32319 +/* returns found(true) or not */
32320 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32322 + struct hlist_head *head;
32323 + struct au_vdir_dehstr *pos;
32324 + struct au_vdir_destr *str;
32326 + head = au_name_hash(delist, name, nlen);
32327 + hlist_for_each_entry(pos, head, hash) {
32329 + AuDbg("%.*s\n", str->len, str->name);
32330 + if (au_nhash_test_name(str, name, nlen))
32336 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32337 + unsigned char d_type)
32339 +#ifdef CONFIG_AUFS_SHWH
32340 + wh->wh_ino = ino;
32341 + wh->wh_type = d_type;
32345 +/* ---------------------------------------------------------------------- */
32347 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32348 + unsigned int d_type, aufs_bindex_t bindex,
32349 + unsigned char shwh)
32352 + struct au_vdir_destr *str;
32353 + struct au_vdir_wh *wh;
32355 + AuDbg("%.*s\n", nlen, name);
32356 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32359 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32360 + if (unlikely(!wh))
32364 + wh->wh_bindex = bindex;
32366 + au_shwh_init_wh(wh, ino, d_type);
32367 + str = &wh->wh_str;
32369 + memcpy(str->name, name, nlen);
32370 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32377 +static int append_deblk(struct au_vdir *vdir)
32380 + unsigned long ul;
32381 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32382 + union au_vdir_deblk_p p, deblk_end;
32383 + unsigned char **o;
32386 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32387 + GFP_NOFS, /*may_shrink*/0);
32388 + if (unlikely(!o))
32391 + vdir->vd_deblk = o;
32392 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32394 + ul = vdir->vd_nblk++;
32395 + vdir->vd_deblk[ul] = p.deblk;
32396 + vdir->vd_last.ul = ul;
32397 + vdir->vd_last.p.deblk = p.deblk;
32398 + deblk_end.deblk = p.deblk + deblk_sz;
32399 + err = set_deblk_end(&p, &deblk_end);
32406 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32407 + unsigned int d_type, struct au_nhash *delist)
32411 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32412 + union au_vdir_deblk_p p, *room, deblk_end;
32413 + struct au_vdir_dehstr *dehstr;
32415 + p.deblk = last_deblk(vdir);
32416 + deblk_end.deblk = p.deblk + deblk_sz;
32417 + room = &vdir->vd_last.p;
32418 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32419 + || !is_deblk_end(room, &deblk_end));
32421 + sz = calc_size(nlen);
32422 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32423 + err = append_deblk(vdir);
32424 + if (unlikely(err))
32427 + p.deblk = last_deblk(vdir);
32428 + deblk_end.deblk = p.deblk + deblk_sz;
32430 + AuDebugOn(room->deblk != p.deblk);
32434 + dehstr = au_cache_alloc_vdir_dehstr();
32435 + if (unlikely(!dehstr))
32438 + dehstr->str = &room->de->de_str;
32439 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32440 + room->de->de_ino = ino;
32441 + room->de->de_type = d_type;
32442 + room->de->de_str.len = nlen;
32443 + memcpy(room->de->de_str.name, name, nlen);
32446 + room->deblk += sz;
32447 + if (unlikely(set_deblk_end(room, &deblk_end)))
32448 + err = append_deblk(vdir);
32455 +/* ---------------------------------------------------------------------- */
32457 +void au_vdir_free(struct au_vdir *vdir)
32459 + unsigned char **deblk;
32461 + deblk = vdir->vd_deblk;
32462 + while (vdir->vd_nblk--)
32463 + au_kfree_try_rcu(*deblk++);
32464 + au_kfree_try_rcu(vdir->vd_deblk);
32465 + au_cache_free_vdir(vdir);
32468 +static struct au_vdir *alloc_vdir(struct file *file)
32470 + struct au_vdir *vdir;
32471 + struct super_block *sb;
32474 + sb = file->f_path.dentry->d_sb;
32475 + SiMustAnyLock(sb);
32478 + vdir = au_cache_alloc_vdir();
32479 + if (unlikely(!vdir))
32482 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32483 + if (unlikely(!vdir->vd_deblk))
32486 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32487 + if (!vdir->vd_deblk_sz) {
32488 + /* estimate the appropriate size for deblk */
32489 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32490 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32492 + vdir->vd_nblk = 0;
32493 + vdir->vd_version = 0;
32494 + vdir->vd_jiffy = 0;
32495 + err = append_deblk(vdir);
32497 + return vdir; /* success */
32499 + au_kfree_try_rcu(vdir->vd_deblk);
32502 + au_cache_free_vdir(vdir);
32504 + vdir = ERR_PTR(err);
32508 +static int reinit_vdir(struct au_vdir *vdir)
32511 + union au_vdir_deblk_p p, deblk_end;
32513 + while (vdir->vd_nblk > 1) {
32514 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32515 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32518 + p.deblk = vdir->vd_deblk[0];
32519 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32520 + err = set_deblk_end(&p, &deblk_end);
32521 + /* keep vd_dblk_sz */
32522 + vdir->vd_last.ul = 0;
32523 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32524 + vdir->vd_version = 0;
32525 + vdir->vd_jiffy = 0;
32530 +/* ---------------------------------------------------------------------- */
32532 +#define AuFillVdir_CALLED BIT(0)
32533 +#define AuFillVdir_WHABLE BIT(1)
32534 +#define AuFillVdir_SHWH BIT(2)
32535 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32536 +#define au_fset_fillvdir(flags, name) \
32537 + do { (flags) |= AuFillVdir_##name; } while (0)
32538 +#define au_fclr_fillvdir(flags, name) \
32539 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32541 +#ifndef CONFIG_AUFS_SHWH
32542 +#undef AuFillVdir_SHWH
32543 +#define AuFillVdir_SHWH 0
32546 +struct fillvdir_arg {
32547 + struct dir_context ctx;
32548 + struct file *file;
32549 + struct au_vdir *vdir;
32550 + struct au_nhash delist;
32551 + struct au_nhash whlist;
32552 + aufs_bindex_t bindex;
32553 + unsigned int flags;
32557 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32558 + loff_t offset __maybe_unused, u64 h_ino,
32559 + unsigned int d_type)
32561 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32562 + char *name = (void *)__name;
32563 + struct super_block *sb;
32565 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32568 + sb = arg->file->f_path.dentry->d_sb;
32569 + au_fset_fillvdir(arg->flags, CALLED);
32571 + if (nlen <= AUFS_WH_PFX_LEN
32572 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32573 + if (test_known(&arg->delist, name, nlen)
32574 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32575 + goto out; /* already exists or whiteouted */
32577 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32579 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32580 + d_type = DT_UNKNOWN;
32581 + arg->err = append_de(arg->vdir, name, nlen, ino,
32582 + d_type, &arg->delist);
32584 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32585 + name += AUFS_WH_PFX_LEN;
32586 + nlen -= AUFS_WH_PFX_LEN;
32587 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32588 + goto out; /* already whiteouted */
32590 + ino = 0; /* just to suppress a warning */
32592 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32595 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32596 + d_type = DT_UNKNOWN;
32597 + arg->err = au_nhash_append_wh
32598 + (&arg->whlist, name, nlen, ino, d_type,
32599 + arg->bindex, shwh);
32605 + arg->vdir->vd_jiffy = jiffies;
32607 + AuTraceErr(arg->err);
32608 + return !arg->err;
32611 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32612 + struct au_nhash *whlist, struct au_nhash *delist)
32614 +#ifdef CONFIG_AUFS_SHWH
32616 + unsigned int nh, u;
32617 + struct hlist_head *head;
32618 + struct au_vdir_wh *pos;
32619 + struct hlist_node *n;
32621 + struct au_vdir_destr *destr;
32623 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32626 + o = p = (void *)__get_free_page(GFP_NOFS);
32627 + if (unlikely(!p))
32631 + nh = whlist->nh_num;
32632 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32633 + p += AUFS_WH_PFX_LEN;
32634 + for (u = 0; u < nh; u++) {
32635 + head = whlist->nh_head + u;
32636 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32637 + destr = &pos->wh_str;
32638 + memcpy(p, destr->name, destr->len);
32639 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32640 + pos->wh_ino, pos->wh_type, delist);
32641 + if (unlikely(err))
32646 + free_page((unsigned long)o);
32656 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32659 + unsigned int rdhash;
32661 + aufs_bindex_t bbot, bindex, btop;
32662 + unsigned char shwh;
32663 + struct file *hf, *file;
32664 + struct super_block *sb;
32666 + file = arg->file;
32667 + sb = file->f_path.dentry->d_sb;
32668 + SiMustAnyLock(sb);
32670 + rdhash = au_sbi(sb)->si_rdhash;
32672 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32673 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32674 + if (unlikely(err))
32676 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32677 + if (unlikely(err))
32683 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32685 + au_fset_fillvdir(arg->flags, SHWH);
32687 + btop = au_fbtop(file);
32688 + bbot = au_fbbot_dir(file);
32689 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32690 + hf = au_hf_dir(file, bindex);
32694 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32696 + if (unlikely(offset))
32699 + arg->bindex = bindex;
32700 + au_fclr_fillvdir(arg->flags, WHABLE);
32702 + || (bindex != bbot
32703 + && au_br_whable(au_sbr_perm(sb, bindex))))
32704 + au_fset_fillvdir(arg->flags, WHABLE);
32707 + au_fclr_fillvdir(arg->flags, CALLED);
32709 + err = vfsub_iterate_dir(hf, &arg->ctx);
32712 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32715 + * dir_relax() may be good for concurrency, but aufs should not
32716 + * use it since it will cause a lockdep problem.
32720 + if (!err && shwh)
32721 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32723 + au_nhash_wh_free(&arg->whlist);
32726 + au_nhash_de_free(&arg->delist);
32731 +static int read_vdir(struct file *file, int may_read)
32734 + unsigned long expire;
32735 + unsigned char do_read;
32736 + struct fillvdir_arg arg = {
32738 + .actor = fillvdir
32741 + struct inode *inode;
32742 + struct au_vdir *vdir, *allocated;
32745 + inode = file_inode(file);
32746 + IMustLock(inode);
32747 + IiMustWriteLock(inode);
32748 + SiMustAnyLock(inode->i_sb);
32750 + allocated = NULL;
32752 + expire = au_sbi(inode->i_sb)->si_rdcache;
32753 + vdir = au_ivdir(inode);
32756 + vdir = alloc_vdir(file);
32757 + err = PTR_ERR(vdir);
32758 + if (IS_ERR(vdir))
32761 + allocated = vdir;
32762 + } else if (may_read
32763 + && (!inode_eq_iversion(inode, vdir->vd_version)
32764 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32766 + err = reinit_vdir(vdir);
32767 + if (unlikely(err))
32772 + return 0; /* success */
32776 + err = au_do_read_vdir(&arg);
32778 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32779 + vdir->vd_version = inode_query_iversion(inode);
32780 + vdir->vd_last.ul = 0;
32781 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32783 + au_set_ivdir(inode, allocated);
32784 + } else if (allocated)
32785 + au_vdir_free(allocated);
32791 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32794 + unsigned long ul, n;
32795 + const unsigned int deblk_sz = src->vd_deblk_sz;
32797 + AuDebugOn(tgt->vd_nblk != 1);
32800 + if (tgt->vd_nblk < src->vd_nblk) {
32801 + unsigned char **p;
32803 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32804 + GFP_NOFS, /*may_shrink*/0);
32805 + if (unlikely(!p))
32807 + tgt->vd_deblk = p;
32810 + if (tgt->vd_deblk_sz != deblk_sz) {
32811 + unsigned char *p;
32813 + tgt->vd_deblk_sz = deblk_sz;
32814 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32815 + /*may_shrink*/1);
32816 + if (unlikely(!p))
32818 + tgt->vd_deblk[0] = p;
32820 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32821 + tgt->vd_version = src->vd_version;
32822 + tgt->vd_jiffy = src->vd_jiffy;
32824 + n = src->vd_nblk;
32825 + for (ul = 1; ul < n; ul++) {
32826 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32828 + if (unlikely(!tgt->vd_deblk[ul]))
32832 + tgt->vd_nblk = n;
32833 + tgt->vd_last.ul = tgt->vd_last.ul;
32834 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32835 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32836 + - src->vd_deblk[src->vd_last.ul];
32838 + return 0; /* success */
32841 + rerr = reinit_vdir(tgt);
32846 +int au_vdir_init(struct file *file)
32849 + struct inode *inode;
32850 + struct au_vdir *vdir_cache, *allocated;
32852 + /* test file->f_pos here instead of ctx->pos */
32853 + err = read_vdir(file, !file->f_pos);
32854 + if (unlikely(err))
32857 + allocated = NULL;
32858 + vdir_cache = au_fvdir_cache(file);
32859 + if (!vdir_cache) {
32860 + vdir_cache = alloc_vdir(file);
32861 + err = PTR_ERR(vdir_cache);
32862 + if (IS_ERR(vdir_cache))
32864 + allocated = vdir_cache;
32865 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32866 + /* test file->f_pos here instead of ctx->pos */
32867 + err = reinit_vdir(vdir_cache);
32868 + if (unlikely(err))
32871 + return 0; /* success */
32873 + inode = file_inode(file);
32874 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32876 + file->f_version = inode_query_iversion(inode);
32878 + au_set_fvdir_cache(file, allocated);
32879 + } else if (allocated)
32880 + au_vdir_free(allocated);
32886 +static loff_t calc_offset(struct au_vdir *vdir)
32889 + union au_vdir_deblk_p p;
32891 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32892 + offset = vdir->vd_last.p.deblk - p.deblk;
32893 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32897 +/* returns true or false */
32898 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32901 + unsigned int deblk_sz;
32902 + unsigned long ul, n;
32904 + union au_vdir_deblk_p p, deblk_end;
32905 + struct au_vdir *vdir_cache;
32908 + vdir_cache = au_fvdir_cache(file);
32909 + offset = calc_offset(vdir_cache);
32910 + AuDbg("offset %lld\n", offset);
32911 + if (ctx->pos == offset)
32914 + vdir_cache->vd_last.ul = 0;
32915 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32920 + deblk_sz = vdir_cache->vd_deblk_sz;
32921 + ul = div64_u64(ctx->pos, deblk_sz);
32922 + AuDbg("ul %lu\n", ul);
32923 + if (ul >= vdir_cache->vd_nblk)
32926 + n = vdir_cache->vd_nblk;
32927 + for (; ul < n; ul++) {
32928 + p.deblk = vdir_cache->vd_deblk[ul];
32929 + deblk_end.deblk = p.deblk + deblk_sz;
32931 + offset *= deblk_sz;
32932 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32935 + l = calc_size(p.de->de_str.len);
32939 + if (!is_deblk_end(&p, &deblk_end)) {
32941 + vdir_cache->vd_last.ul = ul;
32942 + vdir_cache->vd_last.p = p;
32950 + AuDbg("valid %d\n", !valid);
32954 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32956 + unsigned int l, deblk_sz;
32957 + union au_vdir_deblk_p deblk_end;
32958 + struct au_vdir *vdir_cache;
32959 + struct au_vdir_de *de;
32961 + if (!seek_vdir(file, ctx))
32964 + vdir_cache = au_fvdir_cache(file);
32965 + deblk_sz = vdir_cache->vd_deblk_sz;
32967 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32968 + deblk_end.deblk += deblk_sz;
32969 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32970 + de = vdir_cache->vd_last.p.de;
32971 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32972 + de->de_str.len, de->de_str.name, ctx->pos,
32973 + (unsigned long)de->de_ino, de->de_type);
32974 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32975 + de->de_str.len, de->de_ino,
32977 + /* todo: ignore the error caused by udba? */
32978 + /* return err; */
32982 + l = calc_size(de->de_str.len);
32983 + vdir_cache->vd_last.p.deblk += l;
32986 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32987 + vdir_cache->vd_last.ul++;
32988 + vdir_cache->vd_last.p.deblk
32989 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32990 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32999 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
33000 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
33001 +++ linux/fs/aufs/vfsub.c 2024-05-13 17:13:00.621404284 +0200
33003 +// SPDX-License-Identifier: GPL-2.0
33005 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33007 + * This program is free software; you can redistribute it and/or modify
33008 + * it under the terms of the GNU General Public License as published by
33009 + * the Free Software Foundation; either version 2 of the License, or
33010 + * (at your option) any later version.
33012 + * This program is distributed in the hope that it will be useful,
33013 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33014 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33015 + * GNU General Public License for more details.
33017 + * You should have received a copy of the GNU General Public License
33018 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33022 + * sub-routines for VFS
33025 +#include <linux/mnt_namespace.h>
33026 +#include <linux/nsproxy.h>
33027 +#include <linux/security.h>
33028 +#include <linux/splice.h>
33031 +#ifdef CONFIG_AUFS_BR_FUSE
33032 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
33034 + if (!au_test_fuse(h_sb) || !au_userns)
33037 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
33041 +int vfsub_sync_filesystem(struct super_block *h_sb)
33046 + down_read(&h_sb->s_umount);
33047 + err = sync_filesystem(h_sb);
33048 + up_read(&h_sb->s_umount);
33054 +/* ---------------------------------------------------------------------- */
33056 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33060 + struct super_block *h_sb;
33063 + * Always needs h_path->mnt for LSM or FUSE branch.
33065 + AuDebugOn(!h_path->mnt);
33067 + /* for remote fs, leave work for its getattr or d_revalidate */
33068 + /* for bad i_attr fs, handle them in aufs_getattr() */
33069 + /* still some fs may acquire i_mutex. we need to skip them */
33073 + h_sb = h_path->dentry->d_sb;
33074 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33076 + err = vfsub_getattr(h_path, &st);
33081 +/* ---------------------------------------------------------------------- */
33083 +struct file *vfsub_dentry_open(struct path *path, int flags)
33085 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33089 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33091 + struct file *file;
33094 + file = filp_open(path,
33095 + oflags /* | __FMODE_NONOTIFY */,
33098 + if (IS_ERR(file))
33100 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33107 + * Ideally this function should call VFS:do_last() in order to keep all its
33108 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33109 + * structure such as nameidata. This is a second (or third) best approach.
33110 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33112 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33113 + struct vfsub_aopen_args *args)
33116 + struct au_branch *br = args->br;
33117 + struct file *file = args->file;
33118 + /* copied from linux/fs/namei.c:atomic_open() */
33119 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33122 + AuDebugOn(!dir->i_op->atomic_open);
33124 + err = au_br_test_oflag(args->open_flag, br);
33125 + if (unlikely(err))
33128 + au_lcnt_inc(&br->br_nfiles);
33129 + file->f_path.dentry = DENTRY_NOT_SET;
33130 + file->f_path.mnt = au_br_mnt(br);
33131 + AuDbg("%ps\n", dir->i_op->atomic_open);
33132 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33133 + args->create_mode);
33134 + if (unlikely(err < 0)) {
33135 + au_lcnt_dec(&br->br_nfiles);
33139 + /* temporary workaround for nfsv4 branch */
33140 + if (au_test_nfs(dir->i_sb))
33141 + nfs_mark_for_revalidate(dir);
33143 + if (file->f_mode & FMODE_CREATED)
33144 + fsnotify_create(dir, dentry);
33145 + if (!(file->f_mode & FMODE_OPENED)) {
33146 + au_lcnt_dec(&br->br_nfiles);
33150 + /* todo: call VFS:may_open() here */
33151 + /* todo: ima_file_check() too? */
33152 + if (!err && (args->open_flag & __FMODE_EXEC))
33153 + err = deny_write_access(file);
33155 + fsnotify_open(file);
33157 + au_lcnt_dec(&br->br_nfiles);
33158 + /* note that the file is created and still opened */
33164 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33168 + err = kern_path(name, flags, path);
33169 + if (!err && d_is_positive(path->dentry))
33170 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33174 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33175 + struct path *ppath, int len)
33177 + struct path path;
33179 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33180 + if (IS_ERR(path.dentry))
33182 + if (d_is_positive(path.dentry)) {
33183 + path.mnt = ppath->mnt;
33184 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33188 + AuTraceErrPtr(path.dentry);
33189 + return path.dentry;
33192 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33195 + struct path path;
33197 + /* VFS checks it too, but by WARN_ON_ONCE() */
33198 + IMustLock(d_inode(ppath->dentry));
33200 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33201 + if (IS_ERR(path.dentry))
33203 + if (d_is_positive(path.dentry)) {
33204 + path.mnt = ppath->mnt;
33205 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33209 + AuTraceErrPtr(path.dentry);
33210 + return path.dentry;
33213 +void vfsub_call_lkup_one(void *args)
33215 + struct vfsub_lkup_one_args *a = args;
33216 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33219 +/* ---------------------------------------------------------------------- */
33221 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33222 + struct dentry *d2, struct au_hinode *hdir2)
33224 + struct dentry *d;
33227 + d = lock_rename(d1, d2);
33231 + au_hn_suspend(hdir1);
33232 + if (hdir1 != hdir2)
33233 + au_hn_suspend(hdir2);
33239 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33240 + struct dentry *d2, struct au_hinode *hdir2)
33242 + au_hn_resume(hdir1);
33243 + if (hdir1 != hdir2)
33244 + au_hn_resume(hdir2);
33246 + unlock_rename(d1, d2);
33250 +/* ---------------------------------------------------------------------- */
33252 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33255 + struct dentry *d;
33256 + struct mnt_idmap *idmap;
33260 + d = path->dentry;
33261 + path->dentry = d->d_parent;
33262 + err = security_path_mknod(path, d, mode, 0);
33263 + path->dentry = d;
33264 + if (unlikely(err))
33266 + idmap = mnt_idmap(path->mnt);
33269 + err = vfs_create(idmap, dir, path->dentry, mode, want_excl);
33272 + struct path tmp = *path;
33275 + vfsub_update_h_iattr(&tmp, &did);
33277 + tmp.dentry = path->dentry->d_parent;
33278 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33287 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33290 + struct dentry *d;
33291 + struct mnt_idmap *idmap;
33295 + d = path->dentry;
33296 + path->dentry = d->d_parent;
33297 + err = security_path_symlink(path, d, symname);
33298 + path->dentry = d;
33299 + if (unlikely(err))
33301 + idmap = mnt_idmap(path->mnt);
33304 + err = vfs_symlink(idmap, dir, path->dentry, symname);
33307 + struct path tmp = *path;
33310 + vfsub_update_h_iattr(&tmp, &did);
33312 + tmp.dentry = path->dentry->d_parent;
33313 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33322 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33325 + struct dentry *d;
33326 + struct mnt_idmap *idmap;
33330 + d = path->dentry;
33331 + path->dentry = d->d_parent;
33332 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33333 + path->dentry = d;
33334 + if (unlikely(err))
33336 + idmap = mnt_idmap(path->mnt);
33339 + err = vfs_mknod(idmap, dir, path->dentry, mode, dev);
33342 + struct path tmp = *path;
33345 + vfsub_update_h_iattr(&tmp, &did);
33347 + tmp.dentry = path->dentry->d_parent;
33348 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33357 +static int au_test_nlink(struct inode *inode)
33359 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33361 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33362 + || inode->i_nlink < link_max)
33367 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33368 + struct inode **delegated_inode)
33371 + struct dentry *d;
33372 + struct mnt_idmap *idmap;
33376 + err = au_test_nlink(d_inode(src_dentry));
33377 + if (unlikely(err))
33380 + /* we don't call may_linkat() */
33381 + d = path->dentry;
33382 + path->dentry = d->d_parent;
33383 + err = security_path_link(src_dentry, path, d);
33384 + path->dentry = d;
33385 + if (unlikely(err))
33387 + idmap = mnt_idmap(path->mnt);
33390 + err = vfs_link(src_dentry, idmap, dir, path->dentry, delegated_inode);
33393 + struct path tmp = *path;
33396 + /* fuse has different memory inode for the same inumber */
33397 + vfsub_update_h_iattr(&tmp, &did);
33399 + tmp.dentry = path->dentry->d_parent;
33400 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33401 + tmp.dentry = src_dentry;
33402 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33411 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33412 + struct inode *dir, struct path *path,
33413 + struct inode **delegated_inode, unsigned int flags)
33416 + struct renamedata rd;
33417 + struct path tmp = {
33420 + struct dentry *d;
33423 + IMustLock(src_dir);
33425 + d = path->dentry;
33426 + path->dentry = d->d_parent;
33427 + tmp.dentry = src_dentry->d_parent;
33428 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33429 + path->dentry = d;
33430 + if (unlikely(err))
33433 + rd.old_mnt_idmap = mnt_idmap(path->mnt);
33434 + rd.old_dir = src_dir;
33435 + rd.old_dentry = src_dentry;
33436 + rd.new_mnt_idmap = rd.old_mnt_idmap;
33437 + rd.new_dir = dir;
33438 + rd.new_dentry = path->dentry;
33439 + rd.delegated_inode = delegated_inode;
33440 + rd.flags = flags;
33442 + err = vfs_rename(&rd);
33447 + tmp.dentry = d->d_parent;
33448 + vfsub_update_h_iattr(&tmp, &did);
33450 + tmp.dentry = src_dentry;
33451 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33452 + tmp.dentry = src_dentry->d_parent;
33453 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33462 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33465 + struct dentry *d;
33466 + struct mnt_idmap *idmap;
33470 + d = path->dentry;
33471 + path->dentry = d->d_parent;
33472 + err = security_path_mkdir(path, d, mode);
33473 + path->dentry = d;
33474 + if (unlikely(err))
33476 + idmap = mnt_idmap(path->mnt);
33479 + err = vfs_mkdir(idmap, dir, path->dentry, mode);
33482 + struct path tmp = *path;
33485 + vfsub_update_h_iattr(&tmp, &did);
33487 + tmp.dentry = path->dentry->d_parent;
33488 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33497 +int vfsub_rmdir(struct inode *dir, struct path *path)
33500 + struct dentry *d;
33501 + struct mnt_idmap *idmap;
33505 + d = path->dentry;
33506 + path->dentry = d->d_parent;
33507 + err = security_path_rmdir(path, d);
33508 + path->dentry = d;
33509 + if (unlikely(err))
33511 + idmap = mnt_idmap(path->mnt);
33514 + err = vfs_rmdir(idmap, dir, path->dentry);
33517 + struct path tmp = {
33518 + .dentry = path->dentry->d_parent,
33522 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33529 +/* ---------------------------------------------------------------------- */
33531 +/* todo: support mmap_sem? */
33532 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33538 + err = vfs_read(file, ubuf, count, ppos);
33541 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33545 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33551 + err = kernel_read(file, kbuf, count, ppos);
33555 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33559 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33565 + err = vfs_write(file, ubuf, count, ppos);
33568 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33572 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33577 + err = kernel_write(file, kbuf, count, ppos);
33580 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33584 +int vfsub_flush(struct file *file, fl_owner_t id)
33589 + if (file->f_op->flush) {
33590 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33591 + err = file->f_op->flush(file, id);
33594 + err = file->f_op->flush(file, id);
33598 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33604 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33608 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33611 + err = iterate_dir(file, ctx);
33614 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33619 +ssize_t vfsub_splice_read(struct file *in, loff_t *ppos,
33620 + struct pipe_inode_info *pipe, size_t len,
33621 + unsigned int flags)
33626 + err = vfs_splice_read(in, ppos, pipe, len, flags);
33628 + file_accessed(in);
33630 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33634 +ssize_t vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33635 + loff_t *ppos, size_t len, unsigned int flags)
33640 + err = do_splice_from(pipe, out, ppos, len, flags);
33643 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33647 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33651 + /* file can be NULL */
33653 + err = vfs_fsync(file, datasync);
33657 + AuDebugOn(!file);
33658 + path = &file->f_path;
33660 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33665 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33666 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33667 + struct file *h_file)
33670 + struct inode *h_inode;
33671 + struct super_block *h_sb;
33672 + struct mnt_idmap *h_idmap;
33675 + err = vfsub_truncate(h_path, length);
33679 + h_inode = d_inode(h_path->dentry);
33680 + h_sb = h_inode->i_sb;
33682 + sb_start_write(h_sb);
33684 + err = security_file_truncate(h_file);
33686 + h_idmap = mnt_idmap(h_path->mnt);
33688 + err = do_truncate(h_idmap, h_path->dentry, length, attr,
33693 + sb_end_write(h_sb);
33700 +/* ---------------------------------------------------------------------- */
33702 +struct au_vfsub_mkdir_args {
33704 + struct inode *dir;
33705 + struct path *path;
33709 +static void au_call_vfsub_mkdir(void *args)
33711 + struct au_vfsub_mkdir_args *a = args;
33712 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33715 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33717 + int err, do_sio, wkq_err;
33718 + struct mnt_idmap *idmap;
33720 + idmap = mnt_idmap(path->mnt);
33721 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33724 + err = vfsub_mkdir(dir, path, mode);
33727 + struct au_vfsub_mkdir_args args = {
33733 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33734 + if (unlikely(wkq_err))
33741 +struct au_vfsub_rmdir_args {
33743 + struct inode *dir;
33744 + struct path *path;
33747 +static void au_call_vfsub_rmdir(void *args)
33749 + struct au_vfsub_rmdir_args *a = args;
33750 + *a->errp = vfsub_rmdir(a->dir, a->path);
33753 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33755 + int err, do_sio, wkq_err;
33756 + struct mnt_idmap *idmap;
33758 + idmap = mnt_idmap(path->mnt);
33759 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33762 + err = vfsub_rmdir(dir, path);
33765 + struct au_vfsub_rmdir_args args = {
33770 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33771 + if (unlikely(wkq_err))
33778 +/* ---------------------------------------------------------------------- */
33780 +struct notify_change_args {
33782 + struct path *path;
33783 + struct iattr *ia;
33784 + struct inode **delegated_inode;
33787 +static void call_notify_change(void *args)
33789 + struct notify_change_args *a = args;
33790 + struct inode *h_inode;
33791 + struct mnt_idmap *idmap;
33793 + h_inode = d_inode(a->path->dentry);
33794 + IMustLock(h_inode);
33796 + *a->errp = -EPERM;
33797 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33798 + idmap = mnt_idmap(a->path->mnt);
33800 + *a->errp = notify_change(idmap, a->path->dentry, a->ia,
33801 + a->delegated_inode);
33804 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33806 + AuTraceErr(*a->errp);
33809 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33810 + struct inode **delegated_inode)
33813 + struct notify_change_args args = {
33817 + .delegated_inode = delegated_inode
33820 + call_notify_change(&args);
33825 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33826 + struct inode **delegated_inode)
33828 + int err, wkq_err;
33829 + struct notify_change_args args = {
33833 + .delegated_inode = delegated_inode
33836 + wkq_err = au_wkq_wait(call_notify_change, &args);
33837 + if (unlikely(wkq_err))
33843 +/* ---------------------------------------------------------------------- */
33845 +struct unlink_args {
33847 + struct inode *dir;
33848 + struct path *path;
33849 + struct inode **delegated_inode;
33852 +static void call_unlink(void *args)
33854 + struct unlink_args *a = args;
33855 + struct dentry *d = a->path->dentry;
33856 + struct inode *h_inode;
33857 + struct mnt_idmap *idmap;
33858 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33859 + && au_dcount(d) == 1);
33861 + IMustLock(a->dir);
33863 + a->path->dentry = d->d_parent;
33864 + *a->errp = security_path_unlink(a->path, d);
33865 + a->path->dentry = d;
33866 + if (unlikely(*a->errp))
33869 + if (!stop_sillyrename)
33872 + if (d_is_positive(d)) {
33873 + h_inode = d_inode(d);
33877 + idmap = mnt_idmap(a->path->mnt);
33879 + *a->errp = vfs_unlink(idmap, a->dir, d, a->delegated_inode);
33882 + struct path tmp = {
33883 + .dentry = d->d_parent,
33884 + .mnt = a->path->mnt
33886 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33889 + if (!stop_sillyrename)
33894 + AuTraceErr(*a->errp);
33898 + * @dir: must be locked.
33899 + * @dentry: target dentry.
33901 +int vfsub_unlink(struct inode *dir, struct path *path,
33902 + struct inode **delegated_inode, int force)
33905 + struct unlink_args args = {
33909 + .delegated_inode = delegated_inode
33913 + call_unlink(&args);
33917 + wkq_err = au_wkq_wait(call_unlink, &args);
33918 + if (unlikely(wkq_err))
33924 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33925 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33926 +++ linux/fs/aufs/vfsub.h 2024-05-13 17:13:00.621404284 +0200
33928 +/* SPDX-License-Identifier: GPL-2.0 */
33930 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33932 + * This program is free software; you can redistribute it and/or modify
33933 + * it under the terms of the GNU General Public License as published by
33934 + * the Free Software Foundation; either version 2 of the License, or
33935 + * (at your option) any later version.
33937 + * This program is distributed in the hope that it will be useful,
33938 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33939 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33940 + * GNU General Public License for more details.
33942 + * You should have received a copy of the GNU General Public License
33943 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33947 + * sub-routines for VFS
33950 +#ifndef __AUFS_VFSUB_H__
33951 +#define __AUFS_VFSUB_H__
33955 +#include <linux/fs.h>
33956 +#include <linux/mount.h>
33957 +#include <linux/posix_acl.h>
33958 +#include <linux/xattr.h>
33959 +#include "debug.h"
33961 +/* copied from linux/fs/internal.h */
33962 +/* todo: BAD approach!! */
33963 +extern struct file *alloc_empty_file(int, const struct cred *);
33965 +/* ---------------------------------------------------------------------- */
33967 +/* lock subclass for lower inode */
33968 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33969 +/* reduce? gave up. */
33971 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33972 + AuLsc_I_PARENT, /* lower inode, parent first */
33973 + AuLsc_I_PARENT2, /* copyup dirs */
33974 + AuLsc_I_PARENT3, /* copyup wh */
33980 +/* to debug easier, do not make them inlined functions */
33981 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33982 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33984 +/* ---------------------------------------------------------------------- */
33986 +static inline void vfsub_drop_nlink(struct inode *inode)
33988 + AuDebugOn(!inode->i_nlink);
33989 + drop_nlink(inode);
33992 +static inline void vfsub_dead_dir(struct inode *inode)
33994 + AuDebugOn(!S_ISDIR(inode->i_mode));
33995 + inode->i_flags |= S_DEAD;
33996 + clear_nlink(inode);
33999 +static inline int vfsub_native_ro(struct inode *inode)
34001 + return sb_rdonly(inode->i_sb)
34002 + || IS_RDONLY(inode)
34003 + /* || IS_APPEND(inode) */
34004 + || IS_IMMUTABLE(inode);
34007 +#ifdef CONFIG_AUFS_BR_FUSE
34008 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
34010 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
34013 +int vfsub_sync_filesystem(struct super_block *h_sb);
34015 +/* ---------------------------------------------------------------------- */
34017 +int vfsub_update_h_iattr(struct path *h_path, int *did);
34018 +struct file *vfsub_dentry_open(struct path *path, int flags);
34019 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
34021 +struct vfsub_aopen_args {
34022 + struct file *file;
34023 + unsigned int open_flag;
34024 + umode_t create_mode;
34025 + struct au_branch *br;
34027 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
34028 + struct vfsub_aopen_args *args);
34029 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
34031 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
34032 + struct path *ppath, int len);
34033 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
34036 +struct vfsub_lkup_one_args {
34037 + struct dentry **errp;
34038 + struct qstr *name;
34039 + struct path *ppath;
34042 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
34043 + struct path *ppath)
34045 + return vfsub_lookup_one_len(name->name, ppath, name->len);
34048 +void vfsub_call_lkup_one(void *args);
34050 +/* ---------------------------------------------------------------------- */
34052 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34057 + err = mnt_want_write(mnt);
34062 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34065 + mnt_drop_write(mnt);
34069 +#if 0 /* reserved */
34070 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34073 + mnt_drop_write_file(file);
34078 +static inline void vfsub_file_start_write(struct file *file)
34081 + file_start_write(file);
34085 +static inline void vfsub_file_end_write(struct file *file)
34088 + file_end_write(file);
34092 +/* ---------------------------------------------------------------------- */
34095 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34096 + struct dentry *d2, struct au_hinode *hdir2);
34097 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34098 + struct dentry *d2, struct au_hinode *hdir2);
34100 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34102 +int vfsub_symlink(struct inode *dir, struct path *path,
34103 + const char *symname);
34104 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34105 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34106 + struct path *path, struct inode **delegated_inode);
34107 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34108 + struct inode *hdir, struct path *path,
34109 + struct inode **delegated_inode, unsigned int flags);
34110 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34111 +int vfsub_rmdir(struct inode *dir, struct path *path);
34113 +/* ---------------------------------------------------------------------- */
34115 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34117 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34119 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34121 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34123 +int vfsub_flush(struct file *file, fl_owner_t id);
34124 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34126 +static inline loff_t vfsub_f_size_read(struct file *file)
34128 + return i_size_read(file_inode(file));
34131 +static inline unsigned int vfsub_file_flags(struct file *file)
34133 + unsigned int flags;
34135 + spin_lock(&file->f_lock);
34136 + flags = file->f_flags;
34137 + spin_unlock(&file->f_lock);
34142 +static inline int vfsub_file_execed(struct file *file)
34144 + /* todo: direct access f_flags */
34145 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34148 +#if 0 /* reserved */
34149 +static inline void vfsub_file_accessed(struct file *h_file)
34151 + file_accessed(h_file);
34152 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34156 +#if 0 /* reserved */
34157 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34158 + struct dentry *h_dentry)
34160 + struct path h_path = {
34161 + .dentry = h_dentry,
34164 + touch_atime(&h_path);
34165 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34169 +static inline int vfsub_update_time(struct inode *h_inode, int flags)
34171 + return inode_update_time(h_inode, flags);
34172 + /* no vfsub_update_h_iattr() since we don't have struct path */
34175 +#ifdef CONFIG_FS_POSIX_ACL
34176 +static inline int vfsub_acl_chmod(struct mnt_idmap *h_idmap,
34177 + struct dentry *h_dentry, umode_t h_mode)
34181 + err = posix_acl_chmod(h_idmap, h_dentry, h_mode);
34182 + if (err == -EOPNOTSUPP)
34187 +AuStubInt0(vfsub_acl_chmod, struct mnt_idmap *h_idmap,
34188 + struct dentry *h_dentry, umode_t h_mode);
34191 +ssize_t vfsub_splice_read(struct file *in, loff_t *ppos,
34192 + struct pipe_inode_info *pipe, size_t len,
34193 + unsigned int flags);
34194 +ssize_t vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34195 + loff_t *ppos, size_t len, unsigned int flags);
34197 +static inline long vfsub_truncate(struct path *path, loff_t length)
34202 + err = vfs_truncate(path, length);
34207 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34208 + struct file *h_file);
34209 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34212 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34215 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34221 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34227 +/* copy_file_range(2) is a systemcall */
34228 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34229 + struct file *dst, loff_t dst_pos,
34230 + size_t len, unsigned int flags)
34235 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34241 +/* ---------------------------------------------------------------------- */
34243 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34248 + err = vfs_llseek(file, offset, origin);
34253 +/* ---------------------------------------------------------------------- */
34255 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34256 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34257 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34258 + struct inode **delegated_inode);
34259 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34260 + struct inode **delegated_inode);
34261 +int vfsub_unlink(struct inode *dir, struct path *path,
34262 + struct inode **delegated_inode, int force);
34264 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34266 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34269 +/* ---------------------------------------------------------------------- */
34271 +static inline int vfsub_setxattr(struct mnt_idmap *idmap,
34272 + struct dentry *dentry, const char *name,
34273 + const void *value, size_t size, int flags)
34278 + err = vfs_setxattr(idmap, dentry, name, value, size, flags);
34284 +static inline int vfsub_removexattr(struct mnt_idmap *idmap,
34285 + struct dentry *dentry, const char *name)
34290 + err = vfs_removexattr(idmap, dentry, name);
34296 +#ifdef CONFIG_FS_POSIX_ACL
34297 +static inline int vfsub_set_acl(struct mnt_idmap *idmap,
34298 + struct dentry *dentry, const char *name,
34299 + struct posix_acl *acl)
34304 + err = vfs_set_acl(idmap, dentry, name, acl);
34310 +static inline int vfsub_remove_acl(struct mnt_idmap *idmap,
34311 + struct dentry *dentry, const char *name)
34316 + err = vfs_remove_acl(idmap, dentry, name);
34322 +AuStubInt0(vfsub_set_acl, struct mnt_idmap *idmap, struct dentry *dentry,
34323 + const char *name, struct posix_acl *acl);
34324 +AuStubInt0(vfsub_remove_acl, struct mnt_idmap *idmap,
34325 + struct dentry *dentry, const char *name);
34328 +#endif /* __KERNEL__ */
34329 +#endif /* __AUFS_VFSUB_H__ */
34330 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34331 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34332 +++ linux/fs/aufs/wbr_policy.c 2024-05-13 17:13:00.621404284 +0200
34334 +// SPDX-License-Identifier: GPL-2.0
34336 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34338 + * This program is free software; you can redistribute it and/or modify
34339 + * it under the terms of the GNU General Public License as published by
34340 + * the Free Software Foundation; either version 2 of the License, or
34341 + * (at your option) any later version.
34343 + * This program is distributed in the hope that it will be useful,
34344 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34345 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34346 + * GNU General Public License for more details.
34348 + * You should have received a copy of the GNU General Public License
34349 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34353 + * policies for selecting one among multiple writable branches
34356 +#include <linux/statfs.h>
34359 +/* subset of cpup_attr() */
34360 +static noinline_for_stack
34361 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34365 + struct inode *h_isrc;
34367 + h_isrc = d_inode(h_src);
34368 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34369 + ia.ia_mode = h_isrc->i_mode;
34370 + ia.ia_uid = h_isrc->i_uid;
34371 + ia.ia_gid = h_isrc->i_gid;
34372 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34373 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34374 + /* no delegation since it is just created */
34375 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34377 + /* is this nfs only? */
34378 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34379 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34380 + ia.ia_mode = h_isrc->i_mode;
34381 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34387 +#define AuCpdown_PARENT_OPQ BIT(0)
34388 +#define AuCpdown_WHED BIT(1)
34389 +#define AuCpdown_MADE_DIR BIT(2)
34390 +#define AuCpdown_DIROPQ BIT(3)
34391 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34392 +#define au_fset_cpdown(flags, name) \
34393 + do { (flags) |= AuCpdown_##name; } while (0)
34394 +#define au_fclr_cpdown(flags, name) \
34395 + do { (flags) &= ~AuCpdown_##name; } while (0)
34397 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34398 + unsigned int *flags)
34401 + struct dentry *opq_dentry;
34403 + opq_dentry = au_diropq_create(dentry, bdst);
34404 + err = PTR_ERR(opq_dentry);
34405 + if (IS_ERR(opq_dentry))
34407 + dput(opq_dentry);
34408 + au_fset_cpdown(*flags, DIROPQ);
34414 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34415 + struct inode *dir, aufs_bindex_t bdst)
34418 + struct path h_path;
34419 + struct au_branch *br;
34421 + br = au_sbr(dentry->d_sb, bdst);
34422 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34423 + err = PTR_ERR(h_path.dentry);
34424 + if (IS_ERR(h_path.dentry))
34428 + if (d_is_positive(h_path.dentry)) {
34429 + h_path.mnt = au_br_mnt(br);
34430 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34433 + dput(h_path.dentry);
34439 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34440 + struct au_pin *pin,
34441 + struct dentry *h_parent, void *arg)
34444 + aufs_bindex_t bopq, btop;
34445 + struct path h_path;
34446 + struct dentry *parent;
34447 + struct inode *h_dir, *h_inode, *inode, *dir;
34448 + unsigned int *flags = arg;
34450 + btop = au_dbtop(dentry);
34451 + /* dentry is di-locked */
34452 + parent = dget_parent(dentry);
34453 + dir = d_inode(parent);
34454 + h_dir = d_inode(h_parent);
34455 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34456 + IMustLock(h_dir);
34458 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34459 + if (unlikely(err < 0))
34461 + h_path.dentry = au_h_dptr(dentry, bdst);
34462 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34463 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34464 + if (unlikely(err))
34466 + au_fset_cpdown(*flags, MADE_DIR);
34468 + bopq = au_dbdiropq(dentry);
34469 + au_fclr_cpdown(*flags, WHED);
34470 + au_fclr_cpdown(*flags, DIROPQ);
34471 + if (au_dbwh(dentry) == bdst)
34472 + au_fset_cpdown(*flags, WHED);
34473 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34474 + au_fset_cpdown(*flags, PARENT_OPQ);
34475 + h_inode = d_inode(h_path.dentry);
34476 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34477 + if (au_ftest_cpdown(*flags, WHED)) {
34478 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34479 + if (unlikely(err)) {
34480 + inode_unlock(h_inode);
34485 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34486 + inode_unlock(h_inode);
34487 + if (unlikely(err))
34490 + if (au_ftest_cpdown(*flags, WHED)) {
34491 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34492 + if (unlikely(err))
34496 + inode = d_inode(dentry);
34497 + if (au_ibbot(inode) < bdst)
34498 + au_set_ibbot(inode, bdst);
34499 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34500 + au_hi_flags(inode, /*isdir*/1));
34501 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34502 + goto out; /* success */
34506 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34507 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34508 + rerr = au_diropq_remove(dentry, bdst);
34509 + inode_unlock(h_inode);
34510 + if (unlikely(rerr)) {
34511 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34512 + dentry, bdst, rerr);
34518 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34519 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34520 + if (unlikely(rerr)) {
34521 + AuIOErr("failed removing %pd b%d (%d)\n",
34522 + dentry, bdst, rerr);
34527 + au_set_h_dptr(dentry, bdst, NULL);
34528 + if (au_dbbot(dentry) == bdst)
34529 + au_update_dbbot(dentry);
34535 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34538 + unsigned int flags;
34541 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34546 +/* ---------------------------------------------------------------------- */
34548 +/* policies for create */
34550 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34552 + int err, i, j, ndentry;
34553 + aufs_bindex_t bopq;
34554 + struct au_dcsub_pages dpages;
34555 + struct au_dpage *dpage;
34556 + struct dentry **dentries, *parent, *d;
34558 + err = au_dpages_init(&dpages, GFP_NOFS);
34559 + if (unlikely(err))
34561 + parent = dget_parent(dentry);
34562 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34563 + if (unlikely(err))
34567 + for (i = 0; i < dpages.ndpage; i++) {
34568 + dpage = dpages.dpages + i;
34569 + dentries = dpage->dentries;
34570 + ndentry = dpage->ndentry;
34571 + for (j = 0; j < ndentry; j++) {
34573 + di_read_lock_parent2(d, !AuLock_IR);
34574 + bopq = au_dbdiropq(d);
34575 + di_read_unlock(d, !AuLock_IR);
34576 + if (bopq >= 0 && bopq < err)
34583 + au_dpages_free(&dpages);
34588 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34590 + for (; bindex >= 0; bindex--)
34591 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34596 +/* top down parent */
34597 +static int au_wbr_create_tdp(struct dentry *dentry,
34598 + unsigned int flags __maybe_unused)
34601 + aufs_bindex_t btop, bindex;
34602 + struct super_block *sb;
34603 + struct dentry *parent, *h_parent;
34605 + sb = dentry->d_sb;
34606 + btop = au_dbtop(dentry);
34608 + if (!au_br_rdonly(au_sbr(sb, btop)))
34612 + parent = dget_parent(dentry);
34613 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34614 + h_parent = au_h_dptr(parent, bindex);
34615 + if (!h_parent || d_is_negative(h_parent))
34618 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34625 + /* bottom up here */
34626 + if (unlikely(err < 0)) {
34627 + err = au_wbr_bu(sb, btop - 1);
34629 + err = au_wbr_nonopq(dentry, err);
34633 + AuDbg("b%d\n", err);
34637 +/* ---------------------------------------------------------------------- */
34639 +/* an exception for the policy other than tdp */
34640 +static int au_wbr_create_exp(struct dentry *dentry)
34643 + aufs_bindex_t bwh, bdiropq;
34644 + struct dentry *parent;
34647 + bwh = au_dbwh(dentry);
34648 + parent = dget_parent(dentry);
34649 + bdiropq = au_dbdiropq(parent);
34651 + if (bdiropq >= 0)
34652 + err = min(bdiropq, bwh);
34655 + AuDbg("%d\n", err);
34656 + } else if (bdiropq >= 0) {
34658 + AuDbg("%d\n", err);
34663 + err = au_wbr_nonopq(dentry, err);
34665 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34668 + AuDbg("%d\n", err);
34672 +/* ---------------------------------------------------------------------- */
34675 +static int au_wbr_create_init_rr(struct super_block *sb)
34679 + err = au_wbr_bu(sb, au_sbbot(sb));
34680 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34683 + AuDbg("b%d\n", err);
34687 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34691 + aufs_bindex_t bindex, bbot;
34692 + struct super_block *sb;
34695 + err = au_wbr_create_exp(dentry);
34699 + sb = dentry->d_sb;
34700 + next = &au_sbi(sb)->si_wbr_rr_next;
34701 + bbot = au_sbbot(sb);
34703 + for (bindex = 0; bindex <= bbot; bindex++) {
34704 + if (!au_ftest_wbr(flags, DIR)) {
34705 + err = atomic_dec_return(next) + 1;
34706 + /* modulo for 0 is meaningless */
34707 + if (unlikely(!err))
34708 + err = atomic_dec_return(next) + 1;
34710 + err = atomic_read(next);
34711 + AuDbg("%d\n", err);
34714 + AuDbg("%d\n", err);
34715 + if (!au_br_rdonly(au_sbr(sb, err)))
34721 + err = au_wbr_nonopq(dentry, err);
34724 + AuDbg("%d\n", err);
34728 +/* ---------------------------------------------------------------------- */
34730 +/* most free space */
34731 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34733 + struct super_block *sb;
34734 + struct au_branch *br;
34735 + struct au_wbr_mfs *mfs;
34736 + struct dentry *h_parent;
34737 + aufs_bindex_t bindex, bbot;
34739 + unsigned long long b, bavail;
34740 + struct path h_path;
34741 + /* reduce the stack usage */
34742 + struct kstatfs *st;
34744 + st = kmalloc(sizeof(*st), GFP_NOFS);
34745 + if (unlikely(!st)) {
34746 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34751 + sb = dentry->d_sb;
34752 + mfs = &au_sbi(sb)->si_wbr_mfs;
34753 + MtxMustLock(&mfs->mfs_lock);
34754 + mfs->mfs_bindex = -EROFS;
34755 + mfs->mfsrr_bytes = 0;
34758 + bbot = au_sbbot(sb);
34760 + bindex = au_dbtop(parent);
34761 + bbot = au_dbtaildir(parent);
34764 + for (; bindex <= bbot; bindex++) {
34766 + h_parent = au_h_dptr(parent, bindex);
34767 + if (!h_parent || d_is_negative(h_parent))
34770 + br = au_sbr(sb, bindex);
34771 + if (au_br_rdonly(br))
34774 + /* sb->s_root for NFS is unreliable */
34775 + h_path.mnt = au_br_mnt(br);
34776 + h_path.dentry = h_path.mnt->mnt_root;
34777 + err = vfs_statfs(&h_path, st);
34778 + if (unlikely(err)) {
34779 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34783 + /* when the available size is equal, select the lower one */
34784 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34785 + || sizeof(b) < sizeof(st->f_bsize));
34786 + b = st->f_bavail * st->f_bsize;
34787 + br->br_wbr->wbr_bytes = b;
34788 + if (b >= bavail) {
34790 + mfs->mfs_bindex = bindex;
34791 + mfs->mfs_jiffy = jiffies;
34795 + mfs->mfsrr_bytes = bavail;
34796 + AuDbg("b%d\n", mfs->mfs_bindex);
34797 + au_kfree_rcu(st);
34800 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34803 + struct dentry *parent;
34804 + struct super_block *sb;
34805 + struct au_wbr_mfs *mfs;
34807 + err = au_wbr_create_exp(dentry);
34811 + sb = dentry->d_sb;
34813 + if (au_ftest_wbr(flags, PARENT))
34814 + parent = dget_parent(dentry);
34815 + mfs = &au_sbi(sb)->si_wbr_mfs;
34816 + mutex_lock(&mfs->mfs_lock);
34817 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34818 + || mfs->mfs_bindex < 0
34819 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34820 + au_mfs(dentry, parent);
34821 + mutex_unlock(&mfs->mfs_lock);
34822 + err = mfs->mfs_bindex;
34826 + err = au_wbr_nonopq(dentry, err);
34829 + AuDbg("b%d\n", err);
34833 +static int au_wbr_create_init_mfs(struct super_block *sb)
34835 + struct au_wbr_mfs *mfs;
34837 + mfs = &au_sbi(sb)->si_wbr_mfs;
34838 + mutex_init(&mfs->mfs_lock);
34839 + mfs->mfs_jiffy = 0;
34840 + mfs->mfs_bindex = -EROFS;
34845 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34847 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34851 +/* ---------------------------------------------------------------------- */
34853 +/* top down regardless parent, and then mfs */
34854 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34855 + unsigned int flags __maybe_unused)
34858 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34859 + unsigned long long watermark;
34860 + struct super_block *sb;
34861 + struct au_wbr_mfs *mfs;
34862 + struct au_branch *br;
34863 + struct dentry *parent;
34865 + sb = dentry->d_sb;
34866 + mfs = &au_sbi(sb)->si_wbr_mfs;
34867 + mutex_lock(&mfs->mfs_lock);
34868 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34869 + || mfs->mfs_bindex < 0)
34870 + au_mfs(dentry, /*parent*/NULL);
34871 + watermark = mfs->mfsrr_watermark;
34872 + bmfs = mfs->mfs_bindex;
34873 + mutex_unlock(&mfs->mfs_lock);
34875 + /* another style of au_wbr_create_exp() */
34876 + bwh = au_dbwh(dentry);
34877 + parent = dget_parent(dentry);
34878 + btail = au_dbtaildir(parent);
34879 + if (bwh >= 0 && bwh < btail)
34882 + err = au_wbr_nonopq(dentry, btail);
34883 + if (unlikely(err < 0))
34887 + for (bindex = 0; bindex <= btail; bindex++) {
34888 + br = au_sbr(sb, bindex);
34889 + if (au_br_rdonly(br))
34891 + if (br->br_wbr->wbr_bytes > watermark) {
34902 + AuDbg("b%d\n", err);
34906 +/* ---------------------------------------------------------------------- */
34908 +/* most free space and then round robin */
34909 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34912 + struct au_wbr_mfs *mfs;
34914 + err = au_wbr_create_mfs(dentry, flags);
34916 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34917 + mutex_lock(&mfs->mfs_lock);
34918 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34919 + err = au_wbr_create_rr(dentry, flags);
34920 + mutex_unlock(&mfs->mfs_lock);
34923 + AuDbg("b%d\n", err);
34927 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34931 + au_wbr_create_init_mfs(sb); /* ignore */
34932 + err = au_wbr_create_init_rr(sb);
34937 +/* ---------------------------------------------------------------------- */
34939 +/* top down parent and most free space */
34940 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34943 + unsigned long long b;
34944 + aufs_bindex_t bindex, btop, bbot;
34945 + struct super_block *sb;
34946 + struct dentry *parent, *h_parent;
34947 + struct au_branch *br;
34949 + err = au_wbr_create_tdp(dentry, flags);
34950 + if (unlikely(err < 0))
34952 + parent = dget_parent(dentry);
34953 + btop = au_dbtop(parent);
34954 + bbot = au_dbtaildir(parent);
34955 + if (btop == bbot)
34956 + goto out_parent; /* success */
34958 + e2 = au_wbr_create_mfs(dentry, flags);
34960 + goto out_parent; /* success */
34962 + /* when the available size is equal, select upper one */
34963 + sb = dentry->d_sb;
34964 + br = au_sbr(sb, err);
34965 + b = br->br_wbr->wbr_bytes;
34966 + AuDbg("b%d, %llu\n", err, b);
34968 + for (bindex = btop; bindex <= bbot; bindex++) {
34969 + h_parent = au_h_dptr(parent, bindex);
34970 + if (!h_parent || d_is_negative(h_parent))
34973 + br = au_sbr(sb, bindex);
34974 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34975 + b = br->br_wbr->wbr_bytes;
34977 + AuDbg("b%d, %llu\n", err, b);
34982 + err = au_wbr_nonopq(dentry, err);
34987 + AuDbg("b%d\n", err);
34991 +/* ---------------------------------------------------------------------- */
34994 + * - top down parent
34995 + * - most free space with parent
34996 + * - most free space round-robin regardless parent
34998 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
35001 + unsigned long long watermark;
35002 + struct super_block *sb;
35003 + struct au_branch *br;
35004 + struct au_wbr_mfs *mfs;
35006 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
35007 + if (unlikely(err < 0))
35010 + sb = dentry->d_sb;
35011 + br = au_sbr(sb, err);
35012 + mfs = &au_sbi(sb)->si_wbr_mfs;
35013 + mutex_lock(&mfs->mfs_lock);
35014 + watermark = mfs->mfsrr_watermark;
35015 + mutex_unlock(&mfs->mfs_lock);
35016 + if (br->br_wbr->wbr_bytes < watermark)
35017 + /* regardless the parent dir */
35018 + err = au_wbr_create_mfsrr(dentry, flags);
35021 + AuDbg("b%d\n", err);
35025 +/* ---------------------------------------------------------------------- */
35027 +/* policies for copyup */
35029 +/* top down parent */
35030 +static int au_wbr_copyup_tdp(struct dentry *dentry)
35032 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
35035 +/* bottom up parent */
35036 +static int au_wbr_copyup_bup(struct dentry *dentry)
35039 + aufs_bindex_t bindex, btop;
35040 + struct dentry *parent, *h_parent;
35041 + struct super_block *sb;
35044 + sb = dentry->d_sb;
35045 + parent = dget_parent(dentry);
35046 + btop = au_dbtop(parent);
35047 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
35048 + h_parent = au_h_dptr(parent, bindex);
35049 + if (!h_parent || d_is_negative(h_parent))
35052 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
35059 + /* bottom up here */
35060 + if (unlikely(err < 0))
35061 + err = au_wbr_bu(sb, btop - 1);
35063 + AuDbg("b%d\n", err);
35068 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
35072 + err = au_wbr_bu(dentry->d_sb, btop);
35073 + AuDbg("b%d\n", err);
35075 + err = au_wbr_nonopq(dentry, err);
35077 + AuDbg("b%d\n", err);
35081 +static int au_wbr_copyup_bu(struct dentry *dentry)
35084 + aufs_bindex_t btop;
35086 + btop = au_dbtop(dentry);
35087 + err = au_wbr_do_copyup_bu(dentry, btop);
35091 +/* ---------------------------------------------------------------------- */
35093 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35094 + [AuWbrCopyup_TDP] = {
35095 + .copyup = au_wbr_copyup_tdp
35097 + [AuWbrCopyup_BUP] = {
35098 + .copyup = au_wbr_copyup_bup
35100 + [AuWbrCopyup_BU] = {
35101 + .copyup = au_wbr_copyup_bu
35105 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35106 + [AuWbrCreate_TDP] = {
35107 + .create = au_wbr_create_tdp
35109 + [AuWbrCreate_RR] = {
35110 + .create = au_wbr_create_rr,
35111 + .init = au_wbr_create_init_rr
35113 + [AuWbrCreate_MFS] = {
35114 + .create = au_wbr_create_mfs,
35115 + .init = au_wbr_create_init_mfs,
35116 + .fin = au_wbr_create_fin_mfs
35118 + [AuWbrCreate_MFSV] = {
35119 + .create = au_wbr_create_mfs,
35120 + .init = au_wbr_create_init_mfs,
35121 + .fin = au_wbr_create_fin_mfs
35123 + [AuWbrCreate_MFSRR] = {
35124 + .create = au_wbr_create_mfsrr,
35125 + .init = au_wbr_create_init_mfsrr,
35126 + .fin = au_wbr_create_fin_mfs
35128 + [AuWbrCreate_MFSRRV] = {
35129 + .create = au_wbr_create_mfsrr,
35130 + .init = au_wbr_create_init_mfsrr,
35131 + .fin = au_wbr_create_fin_mfs
35133 + [AuWbrCreate_TDMFS] = {
35134 + .create = au_wbr_create_tdmfs,
35135 + .init = au_wbr_create_init_mfs,
35136 + .fin = au_wbr_create_fin_mfs
35138 + [AuWbrCreate_TDMFSV] = {
35139 + .create = au_wbr_create_tdmfs,
35140 + .init = au_wbr_create_init_mfs,
35141 + .fin = au_wbr_create_fin_mfs
35143 + [AuWbrCreate_PMFS] = {
35144 + .create = au_wbr_create_pmfs,
35145 + .init = au_wbr_create_init_mfs,
35146 + .fin = au_wbr_create_fin_mfs
35148 + [AuWbrCreate_PMFSV] = {
35149 + .create = au_wbr_create_pmfs,
35150 + .init = au_wbr_create_init_mfs,
35151 + .fin = au_wbr_create_fin_mfs
35153 + [AuWbrCreate_PMFSRR] = {
35154 + .create = au_wbr_create_pmfsrr,
35155 + .init = au_wbr_create_init_mfsrr,
35156 + .fin = au_wbr_create_fin_mfs
35158 + [AuWbrCreate_PMFSRRV] = {
35159 + .create = au_wbr_create_pmfsrr,
35160 + .init = au_wbr_create_init_mfsrr,
35161 + .fin = au_wbr_create_fin_mfs
35164 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35165 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35166 +++ linux/fs/aufs/whout.c 2024-05-13 17:13:00.621404284 +0200
35168 +// SPDX-License-Identifier: GPL-2.0
35170 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35172 + * This program is free software; you can redistribute it and/or modify
35173 + * it under the terms of the GNU General Public License as published by
35174 + * the Free Software Foundation; either version 2 of the License, or
35175 + * (at your option) any later version.
35177 + * This program is distributed in the hope that it will be useful,
35178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35180 + * GNU General Public License for more details.
35182 + * You should have received a copy of the GNU General Public License
35183 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35187 + * whiteout for logical deletion and opaque directory
35192 +#define WH_MASK 0444
35195 + * If a directory contains this file, then it is opaque. We start with the
35196 + * .wh. flag so that it is blocked by lookup.
35198 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35199 + sizeof(AUFS_WH_DIROPQ) - 1);
35202 + * generate whiteout name, which is NOT terminated by NULL.
35203 + * @name: original d_name.name
35204 + * @len: original d_name.len
35205 + * @wh: whiteout qstr
35206 + * returns zero when succeeds, otherwise error.
35207 + * succeeded value as wh->name should be freed by kfree().
35209 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35213 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35214 + return -ENAMETOOLONG;
35216 + wh->len = name->len + AUFS_WH_PFX_LEN;
35217 + p = kmalloc(wh->len, GFP_NOFS);
35220 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35221 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35228 +/* ---------------------------------------------------------------------- */
35231 + * test if the @wh_name exists under @h_ppath.
35232 + * @try_sio specifies the necessary of super-io.
35234 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
35235 + struct qstr *wh_name, int try_sio)
35238 + struct dentry *wh_dentry;
35241 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35243 + wh_dentry = au_sio_lkup_one(h_idmap, wh_name, h_ppath);
35244 + err = PTR_ERR(wh_dentry);
35245 + if (IS_ERR(wh_dentry)) {
35246 + if (err == -ENAMETOOLONG)
35252 + if (d_is_negative(wh_dentry))
35253 + goto out_wh; /* success */
35256 + if (d_is_reg(wh_dentry))
35257 + goto out_wh; /* success */
35260 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35261 + wh_dentry, d_inode(wh_dentry)->i_mode);
35270 + * test if the @h_path->dentry sets opaque or not.
35272 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path)
35275 + struct inode *h_dir;
35277 + h_dir = d_inode(h_path->dentry);
35278 + err = au_wh_test(h_idmap, h_path, &diropq_name,
35279 + au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC));
35284 + * returns a negative dentry whose name is unique and temporary.
35286 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35287 + struct qstr *prefix)
35289 + struct dentry *dentry;
35291 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35293 + /* strict atomic_t is unnecessary here */
35294 + static unsigned short cnt;
35296 + struct path h_ppath;
35297 + struct mnt_idmap *h_idmap;
35299 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35302 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35303 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35304 + dentry = ERR_PTR(-ENAMETOOLONG);
35305 + if (unlikely(qs.len > NAME_MAX))
35307 + dentry = ERR_PTR(-ENOMEM);
35308 + name = kmalloc(qs.len + 1, GFP_NOFS);
35309 + if (unlikely(!name))
35313 + /* doubly whiteout-ed */
35314 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35315 + p = name + AUFS_WH_PFX_LEN * 2;
35316 + memcpy(p, prefix->name, prefix->len);
35317 + p += prefix->len;
35319 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35321 + h_ppath.dentry = h_parent;
35322 + h_ppath.mnt = au_br_mnt(br);
35323 + h_idmap = au_br_idmap(br);
35325 + for (i = 0; i < 3; i++) {
35326 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35327 + dentry = au_sio_lkup_one(h_idmap, &qs, &h_ppath);
35328 + if (IS_ERR(dentry) || d_is_negative(dentry))
35332 + /* pr_warn("could not get random name\n"); */
35333 + dentry = ERR_PTR(-EEXIST);
35334 + AuDbg("%.*s\n", AuLNPair(&qs));
35338 + if (name != defname)
35339 + au_kfree_try_rcu(name);
35341 + AuTraceErrPtr(dentry);
35346 + * rename the @h_dentry on @br to the whiteouted temporary name.
35348 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35351 + struct path h_path = {
35352 + .mnt = au_br_mnt(br)
35354 + struct inode *h_dir, *delegated;
35355 + struct dentry *h_parent;
35357 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35358 + h_dir = d_inode(h_parent);
35359 + IMustLock(h_dir);
35361 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35362 + err = PTR_ERR(h_path.dentry);
35363 + if (IS_ERR(h_path.dentry))
35366 + /* under the same dir, no need to lock_rename() */
35367 + delegated = NULL;
35368 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35371 + if (unlikely(err == -EWOULDBLOCK)) {
35372 + pr_warn("cannot retry for NFSv4 delegation"
35373 + " for an internal rename\n");
35376 + dput(h_path.dentry);
35383 +/* ---------------------------------------------------------------------- */
35385 + * functions for removing a whiteout
35388 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35391 + struct inode *delegated;
35394 + * forces superio when the dir has a sticky bit.
35395 + * this may be a violation of unix fs semantics.
35397 + force = (h_dir->i_mode & S_ISVTX)
35398 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35399 + delegated = NULL;
35400 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35401 + if (unlikely(err == -EWOULDBLOCK)) {
35402 + pr_warn("cannot retry for NFSv4 delegation"
35403 + " for an internal unlink\n");
35409 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35410 + struct dentry *dentry)
35414 + err = do_unlink_wh(h_dir, h_path);
35415 + if (!err && dentry)
35416 + au_set_dbwh(dentry, -1);
35421 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35424 + struct path h_path;
35427 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35428 + if (IS_ERR(h_path.dentry))
35429 + err = PTR_ERR(h_path.dentry);
35431 + if (d_is_reg(h_path.dentry)) {
35432 + h_path.mnt = h_ppath->mnt;
35433 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35435 + dput(h_path.dentry);
35441 +/* ---------------------------------------------------------------------- */
35443 + * initialize/clean whiteout for a branch
35446 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35450 + struct inode *delegated;
35452 + if (d_is_negative(whpath->dentry))
35456 + err = vfsub_rmdir(h_dir, whpath);
35458 + delegated = NULL;
35459 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35460 + if (unlikely(err == -EWOULDBLOCK)) {
35461 + pr_warn("cannot retry for NFSv4 delegation"
35462 + " for an internal unlink\n");
35466 + if (unlikely(err))
35467 + pr_warn("failed removing %pd (%d), ignored.\n",
35468 + whpath->dentry, err);
35471 +static int test_linkable(struct dentry *h_root)
35473 + struct inode *h_dir = d_inode(h_root);
35475 + if (h_dir->i_op->link)
35478 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35479 + h_root, au_sbtype(h_root->d_sb));
35480 + return -ENOSYS; /* the branch doesn't have its ->link() */
35483 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35484 +static int au_whdir(struct inode *h_dir, struct path *path)
35489 + if (d_is_negative(path->dentry)) {
35492 + if (au_test_nfs(path->dentry->d_sb))
35494 + err = vfsub_mkdir(h_dir, path, mode);
35495 + } else if (d_is_dir(path->dentry))
35498 + pr_err("unknown %pd exists\n", path->dentry);
35503 +struct au_wh_base {
35504 + const struct qstr *name;
35505 + struct dentry *dentry;
35508 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35509 + struct path *h_path)
35511 + h_path->dentry = base[AuBrWh_BASE].dentry;
35512 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35513 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35514 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35515 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35516 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35520 + * returns tri-state,
35521 + * minus: error, caller should print the message
35523 + * plus: error, caller should NOT print the message
35525 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35526 + int do_plink, struct au_wh_base base[],
35527 + struct path *h_path)
35530 + struct inode *h_dir;
35532 + h_dir = d_inode(h_root);
35533 + h_path->dentry = base[AuBrWh_BASE].dentry;
35534 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35535 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35537 + err = test_linkable(h_root);
35538 + if (unlikely(err)) {
35543 + err = au_whdir(h_dir, h_path);
35544 + if (unlikely(err))
35546 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35548 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35549 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35550 + err = au_whdir(h_dir, h_path);
35551 + if (unlikely(err))
35553 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35560 + * for the moment, aufs supports the branch filesystem which does not support
35561 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35562 + * copyup failed. finally, such filesystem will not be used as the writable
35565 + * returns tri-state, see above.
35567 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35568 + int do_plink, struct au_wh_base base[],
35569 + struct path *h_path)
35572 + struct inode *h_dir;
35574 + WbrWhMustWriteLock(wbr);
35576 + err = test_linkable(h_root);
35577 + if (unlikely(err)) {
35583 + * todo: should this create be done in /sbin/mount.aufs helper?
35586 + h_dir = d_inode(h_root);
35587 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35588 + h_path->dentry = base[AuBrWh_BASE].dentry;
35589 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35590 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35593 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35594 + if (unlikely(err))
35597 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35599 + err = au_whdir(h_dir, h_path);
35600 + if (unlikely(err))
35602 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35604 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35605 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35607 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35608 + err = au_whdir(h_dir, h_path);
35609 + if (unlikely(err))
35611 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35618 + * initialize the whiteout base file/dir for @br.
35620 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35623 + const unsigned char do_plink
35624 + = !!au_opt_test(au_mntflags(sb), PLINK);
35625 + struct inode *h_dir;
35626 + struct path path = br->br_path;
35627 + struct dentry *h_root = path.dentry;
35628 + struct au_wbr *wbr = br->br_wbr;
35629 + static const struct qstr base_name[] = {
35630 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35631 + sizeof(AUFS_BASE_NAME) - 1),
35632 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35633 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35634 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35635 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35637 + struct au_wh_base base[] = {
35638 + [AuBrWh_BASE] = {
35639 + .name = base_name + AuBrWh_BASE,
35642 + [AuBrWh_PLINK] = {
35643 + .name = base_name + AuBrWh_PLINK,
35646 + [AuBrWh_ORPH] = {
35647 + .name = base_name + AuBrWh_ORPH,
35653 + WbrWhMustWriteLock(wbr);
35655 + for (i = 0; i < AuBrWh_Last; i++) {
35656 + /* doubly whiteouted */
35657 + struct dentry *d;
35659 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35660 + err = PTR_ERR(d);
35664 + base[i].dentry = d;
35666 + && wbr->wbr_wh[i]
35667 + && wbr->wbr_wh[i] != base[i].dentry);
35671 + for (i = 0; i < AuBrWh_Last; i++) {
35672 + dput(wbr->wbr_wh[i]);
35673 + wbr->wbr_wh[i] = NULL;
35677 + if (!au_br_writable(br->br_perm)) {
35678 + h_dir = d_inode(h_root);
35679 + au_wh_init_ro(h_dir, base, &path);
35680 + } else if (!au_br_wh_linkable(br->br_perm)) {
35681 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35687 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35693 + goto out; /* success */
35696 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35697 + err, h_root, au_sbtype(h_root->d_sb));
35699 + for (i = 0; i < AuBrWh_Last; i++)
35700 + dput(base[i].dentry);
35704 +/* ---------------------------------------------------------------------- */
35706 + * whiteouts are all hard-linked usually.
35707 + * when its link count reaches a ceiling, we create a new whiteout base
35708 + * asynchronously.
35711 +struct reinit_br_wh {
35712 + struct super_block *sb;
35713 + struct au_branch *br;
35716 +static void reinit_br_wh(void *arg)
35719 + aufs_bindex_t bindex;
35720 + struct path h_path;
35721 + struct reinit_br_wh *a = arg;
35722 + struct au_wbr *wbr;
35723 + struct inode *dir, *delegated;
35724 + struct dentry *h_root;
35725 + struct au_hinode *hdir;
35728 + wbr = a->br->br_wbr;
35729 + /* big aufs lock */
35730 + si_noflush_write_lock(a->sb);
35731 + if (!au_br_writable(a->br->br_perm))
35733 + bindex = au_br_index(a->sb, a->br->br_id);
35734 + if (unlikely(bindex < 0))
35737 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35738 + dir = d_inode(a->sb->s_root);
35739 + hdir = au_hi(dir, bindex);
35740 + h_root = au_h_dptr(a->sb->s_root, bindex);
35741 + AuDebugOn(h_root != au_br_dentry(a->br));
35743 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35744 + wbr_wh_write_lock(wbr);
35745 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35748 + h_path.dentry = wbr->wbr_whbase;
35749 + h_path.mnt = au_br_mnt(a->br);
35750 + delegated = NULL;
35751 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35753 + if (unlikely(err == -EWOULDBLOCK)) {
35754 + pr_warn("cannot retry for NFSv4 delegation"
35755 + " for an internal unlink\n");
35759 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35762 + dput(wbr->wbr_whbase);
35763 + wbr->wbr_whbase = NULL;
35765 + err = au_wh_init(a->br, a->sb);
35766 + wbr_wh_write_unlock(wbr);
35767 + au_hn_inode_unlock(hdir);
35768 + di_read_unlock(a->sb->s_root, AuLock_IR);
35770 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35774 + atomic_dec(&wbr->wbr_wh_running);
35775 + au_lcnt_dec(&a->br->br_count);
35776 + si_write_unlock(a->sb);
35777 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35779 + if (unlikely(err))
35780 + AuIOErr("err %d\n", err);
35783 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35785 + int do_dec, wkq_err;
35786 + struct reinit_br_wh *arg;
35789 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35792 + /* ignore ENOMEM */
35793 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35796 + * dec(wh_running), kfree(arg) and dec(br_count)
35797 + * in reinit function
35801 + au_lcnt_inc(&br->br_count);
35802 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35803 + if (unlikely(wkq_err)) {
35804 + atomic_dec(&br->br_wbr->wbr_wh_running);
35805 + au_lcnt_dec(&br->br_count);
35806 + au_kfree_rcu(arg);
35813 + atomic_dec(&br->br_wbr->wbr_wh_running);
35816 +/* ---------------------------------------------------------------------- */
35819 + * create the whiteout @wh.
35821 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35822 + struct dentry *wh)
35825 + struct path h_path = {
35828 + struct au_branch *br;
35829 + struct au_wbr *wbr;
35830 + struct dentry *h_parent;
35831 + struct inode *h_dir, *delegated;
35833 + h_parent = wh->d_parent; /* dir inode is locked */
35834 + h_dir = d_inode(h_parent);
35835 + IMustLock(h_dir);
35837 + br = au_sbr(sb, bindex);
35838 + h_path.mnt = au_br_mnt(br);
35839 + wbr = br->br_wbr;
35840 + wbr_wh_read_lock(wbr);
35841 + if (wbr->wbr_whbase) {
35842 + delegated = NULL;
35843 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35844 + if (unlikely(err == -EWOULDBLOCK)) {
35845 + pr_warn("cannot retry for NFSv4 delegation"
35846 + " for an internal link\n");
35849 + if (!err || err != -EMLINK)
35852 + /* link count full. re-initialize br_whbase. */
35853 + kick_reinit_br_wh(sb, br);
35856 + /* return this error in this context */
35857 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35859 + au_fhsm_wrote(sb, bindex, /*force*/0);
35862 + wbr_wh_read_unlock(wbr);
35866 +/* ---------------------------------------------------------------------- */
35869 + * create or remove the diropq.
35871 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35872 + unsigned int flags)
35874 + struct dentry *opq_dentry;
35875 + struct super_block *sb;
35876 + struct au_branch *br;
35877 + struct path h_path;
35880 + sb = dentry->d_sb;
35881 + br = au_sbr(sb, bindex);
35882 + h_path.dentry = au_h_dptr(dentry, bindex);
35883 + h_path.mnt = au_br_mnt(br);
35884 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35885 + if (IS_ERR(opq_dentry))
35888 + if (au_ftest_diropq(flags, CREATE)) {
35889 + err = link_or_create_wh(sb, bindex, opq_dentry);
35891 + au_set_dbdiropq(dentry, bindex);
35892 + goto out; /* success */
35895 + h_path.dentry = opq_dentry;
35896 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35898 + au_set_dbdiropq(dentry, -1);
35900 + dput(opq_dentry);
35901 + opq_dentry = ERR_PTR(err);
35904 + return opq_dentry;
35907 +struct do_diropq_args {
35908 + struct dentry **errp;
35909 + struct dentry *dentry;
35910 + aufs_bindex_t bindex;
35911 + unsigned int flags;
35914 +static void call_do_diropq(void *args)
35916 + struct do_diropq_args *a = args;
35917 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35920 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35921 + unsigned int flags)
35923 + struct dentry *diropq, *h_dentry;
35924 + struct mnt_idmap *h_idmap;
35926 + h_idmap = au_sbr_idmap(dentry->d_sb, bindex);
35927 + h_dentry = au_h_dptr(dentry, bindex);
35928 + if (!au_test_h_perm_sio(h_idmap, d_inode(h_dentry),
35929 + MAY_EXEC | MAY_WRITE))
35930 + diropq = do_diropq(dentry, bindex, flags);
35933 + struct do_diropq_args args = {
35935 + .dentry = dentry,
35936 + .bindex = bindex,
35940 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35941 + if (unlikely(wkq_err))
35942 + diropq = ERR_PTR(wkq_err);
35948 +/* ---------------------------------------------------------------------- */
35951 + * lookup whiteout dentry.
35952 + * @h_parent: lower parent dentry which must exist and be locked
35953 + * @base_name: name of dentry which will be whiteouted
35954 + * returns dentry for whiteout.
35956 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35957 + struct au_branch *br)
35960 + struct qstr wh_name;
35961 + struct dentry *wh_dentry;
35962 + struct path h_path;
35964 + err = au_wh_name_alloc(&wh_name, base_name);
35965 + wh_dentry = ERR_PTR(err);
35967 + h_path.dentry = h_parent;
35968 + h_path.mnt = au_br_mnt(br);
35969 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35970 + au_kfree_try_rcu(wh_name.name);
35972 + return wh_dentry;
35976 + * link/create a whiteout for @dentry on @bindex.
35978 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35979 + struct dentry *h_parent)
35981 + struct dentry *wh_dentry;
35982 + struct super_block *sb;
35985 + sb = dentry->d_sb;
35986 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35987 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35988 + err = link_or_create_wh(sb, bindex, wh_dentry);
35990 + au_set_dbwh(dentry, bindex);
35991 + au_fhsm_wrote(sb, bindex, /*force*/0);
35994 + wh_dentry = ERR_PTR(err);
35998 + return wh_dentry;
36001 +/* ---------------------------------------------------------------------- */
36003 +/* Delete all whiteouts in this directory on branch bindex. */
36004 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
36005 + aufs_bindex_t bindex)
36008 + unsigned long ul, n;
36009 + struct qstr wh_name;
36011 + struct hlist_head *head;
36012 + struct au_vdir_wh *pos;
36013 + struct au_vdir_destr *str;
36016 + p = (void *)__get_free_page(GFP_NOFS);
36017 + wh_name.name = p;
36018 + if (unlikely(!wh_name.name))
36022 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
36023 + p += AUFS_WH_PFX_LEN;
36024 + n = whlist->nh_num;
36025 + head = whlist->nh_head;
36026 + for (ul = 0; !err && ul < n; ul++, head++) {
36027 + hlist_for_each_entry(pos, head, wh_hash) {
36028 + if (pos->wh_bindex != bindex)
36031 + str = &pos->wh_str;
36032 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
36033 + memcpy(p, str->name, str->len);
36034 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
36035 + err = unlink_wh_name(h_path, &wh_name);
36040 + AuIOErr("whiteout name too long %.*s\n",
36041 + str->len, str->name);
36046 + free_page((unsigned long)wh_name.name);
36052 +struct del_wh_children_args {
36054 + struct path *h_path;
36055 + struct au_nhash *whlist;
36056 + aufs_bindex_t bindex;
36059 +static void call_del_wh_children(void *args)
36061 + struct del_wh_children_args *a = args;
36062 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
36065 +/* ---------------------------------------------------------------------- */
36067 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
36069 + struct au_whtmp_rmdir *whtmp;
36071 + unsigned int rdhash;
36073 + SiMustAnyLock(sb);
36075 + whtmp = kzalloc(sizeof(*whtmp), gfp);
36076 + if (unlikely(!whtmp)) {
36077 + whtmp = ERR_PTR(-ENOMEM);
36081 + /* no estimation for dir size */
36082 + rdhash = au_sbi(sb)->si_rdhash;
36084 + rdhash = AUFS_RDHASH_DEF;
36085 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
36086 + if (unlikely(err)) {
36087 + au_kfree_rcu(whtmp);
36088 + whtmp = ERR_PTR(err);
36095 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36098 + au_lcnt_dec(&whtmp->br->br_count);
36099 + dput(whtmp->wh_dentry);
36100 + iput(whtmp->dir);
36101 + au_nhash_wh_free(&whtmp->whlist);
36102 + au_kfree_rcu(whtmp);
36106 + * rmdir the whiteouted temporary named dir @h_dentry.
36107 + * @whlist: whiteouted children.
36109 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36110 + struct dentry *wh_dentry, struct au_nhash *whlist)
36113 + unsigned int h_nlink;
36114 + struct path wh_path;
36115 + struct inode *wh_inode, *h_dir;
36116 + struct au_branch *br;
36117 + struct mnt_idmap *h_idmap;
36119 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36120 + IMustLock(h_dir);
36122 + br = au_sbr(dir->i_sb, bindex);
36123 + wh_path.dentry = wh_dentry;
36124 + wh_path.mnt = au_br_mnt(br);
36125 + h_idmap = au_br_idmap(br);
36126 + wh_inode = d_inode(wh_dentry);
36127 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36130 + * someone else might change some whiteouts while we were sleeping.
36131 + * it means this whlist may have an obsoleted entry.
36133 + if (!au_test_h_perm_sio(h_idmap, wh_inode, MAY_EXEC | MAY_WRITE))
36134 + err = del_wh_children(&wh_path, whlist, bindex);
36137 + struct del_wh_children_args args = {
36139 + .h_path = &wh_path,
36140 + .whlist = whlist,
36144 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36145 + if (unlikely(wkq_err))
36148 + inode_unlock(wh_inode);
36151 + h_nlink = h_dir->i_nlink;
36152 + err = vfsub_rmdir(h_dir, &wh_path);
36153 + /* some fs doesn't change the parent nlink in some cases */
36154 + h_nlink -= h_dir->i_nlink;
36158 + if (au_ibtop(dir) == bindex) {
36159 + /* todo: dir->i_mutex is necessary */
36160 + au_cpup_attr_timesizes(dir);
36162 + vfsub_drop_nlink(dir);
36164 + return 0; /* success */
36167 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36171 +static void call_rmdir_whtmp(void *args)
36174 + aufs_bindex_t bindex;
36175 + struct au_whtmp_rmdir *a = args;
36176 + struct super_block *sb;
36177 + struct dentry *h_parent;
36178 + struct inode *h_dir;
36179 + struct au_hinode *hdir;
36181 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36182 + /* inode_lock(a->dir); */
36184 + sb = a->dir->i_sb;
36185 + si_read_lock(sb, !AuLock_FLUSH);
36186 + if (!au_br_writable(a->br->br_perm))
36188 + bindex = au_br_index(sb, a->br->br_id);
36189 + if (unlikely(bindex < 0))
36193 + ii_write_lock_parent(a->dir);
36194 + h_parent = dget_parent(a->wh_dentry);
36195 + h_dir = d_inode(h_parent);
36196 + hdir = au_hi(a->dir, bindex);
36197 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36198 + if (unlikely(err))
36200 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36201 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36204 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36205 + au_hn_inode_unlock(hdir);
36206 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36210 + ii_write_unlock(a->dir);
36212 + /* inode_unlock(a->dir); */
36213 + au_whtmp_rmdir_free(a);
36214 + si_read_unlock(sb);
36215 + au_nwt_done(&au_sbi(sb)->si_nowait);
36216 + if (unlikely(err))
36217 + AuIOErr("err %d\n", err);
36220 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36221 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36224 + struct super_block *sb;
36228 + /* all post-process will be done in do_rmdir_whtmp(). */
36230 + args->dir = au_igrab(dir);
36231 + args->br = au_sbr(sb, bindex);
36232 + au_lcnt_inc(&args->br->br_count);
36233 + args->wh_dentry = dget(wh_dentry);
36234 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36235 + if (unlikely(wkq_err)) {
36236 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36237 + au_whtmp_rmdir_free(args);
36240 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36241 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36242 +++ linux/fs/aufs/whout.h 2024-05-13 17:13:00.621404284 +0200
36244 +/* SPDX-License-Identifier: GPL-2.0 */
36246 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36248 + * This program is free software; you can redistribute it and/or modify
36249 + * it under the terms of the GNU General Public License as published by
36250 + * the Free Software Foundation; either version 2 of the License, or
36251 + * (at your option) any later version.
36253 + * This program is distributed in the hope that it will be useful,
36254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36256 + * GNU General Public License for more details.
36258 + * You should have received a copy of the GNU General Public License
36259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36263 + * whiteout for logical deletion and opaque directory
36266 +#ifndef __AUFS_WHOUT_H__
36267 +#define __AUFS_WHOUT_H__
36274 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36275 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
36276 + struct qstr *wh_name, int try_sio);
36277 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path);
36279 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36280 + struct qstr *prefix);
36281 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36282 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36283 + struct dentry *dentry);
36284 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36286 +/* diropq flags */
36287 +#define AuDiropq_CREATE 1
36288 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36289 +#define au_fset_diropq(flags, name) \
36290 + do { (flags) |= AuDiropq_##name; } while (0)
36291 +#define au_fclr_diropq(flags, name) \
36292 + do { (flags) &= ~AuDiropq_##name; } while (0)
36294 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36295 + unsigned int flags);
36296 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36297 + struct au_branch *br);
36298 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36299 + struct dentry *h_parent);
36301 +/* real rmdir for the whiteout-ed dir */
36302 +struct au_whtmp_rmdir {
36303 + struct inode *dir;
36304 + struct au_branch *br;
36305 + struct dentry *wh_dentry;
36306 + struct au_nhash whlist;
36309 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36310 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36311 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36312 + struct dentry *wh_dentry, struct au_nhash *whlist);
36313 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36314 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36316 +/* ---------------------------------------------------------------------- */
36318 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36319 + aufs_bindex_t bindex)
36321 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36324 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36326 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36329 +#endif /* __KERNEL__ */
36330 +#endif /* __AUFS_WHOUT_H__ */
36331 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36332 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36333 +++ linux/fs/aufs/wkq.c 2024-05-13 17:13:00.621404284 +0200
36335 +// SPDX-License-Identifier: GPL-2.0
36337 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36339 + * This program is free software; you can redistribute it and/or modify
36340 + * it under the terms of the GNU General Public License as published by
36341 + * the Free Software Foundation; either version 2 of the License, or
36342 + * (at your option) any later version.
36344 + * This program is distributed in the hope that it will be useful,
36345 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36346 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36347 + * GNU General Public License for more details.
36349 + * You should have received a copy of the GNU General Public License
36350 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36354 + * workqueue for asynchronous/super-io operations
36355 + * todo: try new credential scheme
36358 +#include <linux/module.h>
36361 +/* internal workqueue named AUFS_WKQ_NAME */
36363 +static struct workqueue_struct *au_wkq;
36365 +struct au_wkinfo {
36366 + struct work_struct wk;
36367 + struct kobject *kobj;
36369 + unsigned int flags; /* see wkq.h */
36371 + au_wkq_func_t func;
36374 +#ifdef CONFIG_LOCKDEP
36376 + struct held_lock **hlock;
36379 + struct completion *comp;
36382 +/* ---------------------------------------------------------------------- */
36384 + * Aufs passes some operations to the workqueue such as the internal copyup.
36385 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36386 + * job run by workqueue depends upon the locks acquired in the other task.
36387 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36388 + * information too. And the job in the workqueue restores the info in order to
36389 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36390 + * correctly and expectedly.
36393 +#ifndef CONFIG_LOCKDEP
36394 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36395 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36396 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36397 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36398 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36400 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36402 + wkinfo->hlock = NULL;
36403 + wkinfo->dont_check = 0;
36410 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36412 + static DEFINE_SPINLOCK(spin);
36415 + struct lock_class_key *key;
36417 + { .name = "&sbinfo->si_rwsem" },
36418 + { .name = "&finfo->fi_rwsem" },
36419 + { .name = "&dinfo->di_rwsem" },
36420 + { .name = "&iinfo->ii_rwsem" }
36425 + /* lockless read from 'set.' see below */
36426 + if (set == ARRAY_SIZE(a)) {
36427 + for (i = 0; i < ARRAY_SIZE(a); i++)
36428 + if (a[i].key == key)
36433 + spin_lock(&spin);
36435 + for (i = 0; i < ARRAY_SIZE(a); i++)
36436 + if (a[i].key == key) {
36437 + spin_unlock(&spin);
36440 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36442 + if (unlikely(a[i].key == key)) { /* rare but possible */
36443 + spin_unlock(&spin);
36448 + if (strstr(a[i].name, name)) {
36450 + * the order of these three lines is important for the
36451 + * lockless read above.
36454 + spin_unlock(&spin);
36456 + /* AuDbg("%d, %s\n", set, name); */
36460 + spin_unlock(&spin);
36469 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36472 + struct task_struct *curr;
36473 + struct held_lock **hl, *held_locks, *p;
36477 + wkinfo->dont_check = lockdep_recursing(curr);
36478 + if (wkinfo->dont_check)
36480 + n = curr->lockdep_depth;
36485 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36486 + if (unlikely(!wkinfo->hlock))
36490 +#if 0 /* left for debugging */
36491 + if (0 && au_debug_test())
36492 + lockdep_print_held_locks(curr);
36494 + held_locks = curr->held_locks;
36495 + hl = wkinfo->hlock;
36497 + p = held_locks++;
36498 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36507 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36509 + au_kfree_try_rcu(wkinfo->hlock);
36512 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36514 + struct held_lock *p, **hl = wkinfo->hlock;
36517 + if (wkinfo->dont_check)
36521 + while ((p = *hl++)) { /* assignment */
36522 + subclass = lockdep_hlock_class(p)->subclass;
36523 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36525 + rwsem_acquire_read(p->instance, subclass, 0,
36526 + /*p->acquire_ip*/_RET_IP_);
36528 + rwsem_acquire(p->instance, subclass, 0,
36529 + /*p->acquire_ip*/_RET_IP_);
36533 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36535 + struct held_lock *p, **hl = wkinfo->hlock;
36537 + if (wkinfo->dont_check)
36541 + while ((p = *hl++)) /* assignment */
36542 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36546 +static void wkq_func(struct work_struct *wk)
36548 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36550 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36551 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36553 + au_wkq_lockdep_pre(wkinfo);
36554 + wkinfo->func(wkinfo->args);
36555 + au_wkq_lockdep_post(wkinfo);
36556 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36557 + complete(wkinfo->comp);
36559 + kobject_put(wkinfo->kobj);
36560 + module_put(THIS_MODULE); /* todo: ?? */
36561 + au_kfree_rcu(wkinfo);
36566 + * Since struct completion is large, try allocating it dynamically.
36568 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36570 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36572 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36574 + init_completion(*comp);
36575 + wkinfo->comp = *comp;
36581 +static void au_wkq_comp_free(struct completion *comp)
36583 + au_kfree_rcu(comp);
36586 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36588 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36589 + if (au_wkq_test()) {
36590 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36591 + " due to a dead dir by UDBA,"
36592 + " or async xino write?\n");
36593 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36596 + au_dbg_verify_kthread();
36598 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36599 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36600 + queue_work(au_wkq, &wkinfo->wk);
36602 + INIT_WORK(&wkinfo->wk, wkq_func);
36603 + schedule_work(&wkinfo->wk);
36608 + * Be careful. It is easy to make deadlock happen.
36609 + * processA: lock, wkq and wait
36610 + * processB: wkq and wait, lock in wkq
36613 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36616 + AuWkqCompDeclare(comp);
36617 + struct au_wkinfo wkinfo = {
36623 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36624 + if (unlikely(err))
36626 + err = au_wkq_lockdep_alloc(&wkinfo);
36627 + if (unlikely(err))
36630 + au_wkq_run(&wkinfo);
36631 + /* no timeout, no interrupt */
36632 + wait_for_completion(wkinfo.comp);
36634 + au_wkq_lockdep_free(&wkinfo);
36637 + au_wkq_comp_free(comp);
36639 + destroy_work_on_stack(&wkinfo.wk);
36644 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36645 + * problem in a concurrent umounting.
36647 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36648 + unsigned int flags)
36651 + struct au_wkinfo *wkinfo;
36653 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36656 + * wkq_func() must free this wkinfo.
36657 + * it highly depends upon the implementation of workqueue.
36660 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36662 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36663 + wkinfo->flags = flags & ~AuWkq_WAIT;
36664 + wkinfo->func = func;
36665 + wkinfo->args = args;
36666 + wkinfo->comp = NULL;
36667 + au_wkq_lockdep_init(wkinfo);
36668 + kobject_get(wkinfo->kobj);
36669 + __module_get(THIS_MODULE); /* todo: ?? */
36671 + au_wkq_run(wkinfo);
36674 + au_nwt_done(&au_sbi(sb)->si_nowait);
36680 +/* ---------------------------------------------------------------------- */
36682 +void au_nwt_init(struct au_nowait_tasks *nwt)
36684 + atomic_set(&nwt->nw_len, 0);
36685 + /* smp_mb(); */ /* atomic_set */
36686 + init_waitqueue_head(&nwt->nw_wq);
36689 +void au_wkq_fin(void)
36691 + destroy_workqueue(au_wkq);
36694 +int __init au_wkq_init(void)
36699 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36700 + if (IS_ERR(au_wkq))
36701 + err = PTR_ERR(au_wkq);
36702 + else if (!au_wkq)
36707 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36708 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36709 +++ linux/fs/aufs/wkq.h 2024-05-13 17:13:00.621404284 +0200
36711 +/* SPDX-License-Identifier: GPL-2.0 */
36713 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36715 + * This program is free software; you can redistribute it and/or modify
36716 + * it under the terms of the GNU General Public License as published by
36717 + * the Free Software Foundation; either version 2 of the License, or
36718 + * (at your option) any later version.
36720 + * This program is distributed in the hope that it will be useful,
36721 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36722 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36723 + * GNU General Public License for more details.
36725 + * You should have received a copy of the GNU General Public License
36726 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36730 + * workqueue for asynchronous/super-io operations
36731 + * todo: try new credentials management scheme
36734 +#ifndef __AUFS_WKQ_H__
36735 +#define __AUFS_WKQ_H__
36739 +#include <linux/wait.h>
36741 +struct super_block;
36743 +/* ---------------------------------------------------------------------- */
36746 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36748 +struct au_nowait_tasks {
36750 + wait_queue_head_t nw_wq;
36753 +/* ---------------------------------------------------------------------- */
36755 +typedef void (*au_wkq_func_t)(void *args);
36758 +#define AuWkq_WAIT BIT(0)
36759 +#define AuWkq_NEST BIT(1)
36760 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36761 +#define au_fset_wkq(flags, name) \
36762 + do { (flags) |= AuWkq_##name; } while (0)
36763 +#define au_fclr_wkq(flags, name) \
36764 + do { (flags) &= ~AuWkq_##name; } while (0)
36767 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36768 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36769 + unsigned int flags);
36770 +void au_nwt_init(struct au_nowait_tasks *nwt);
36771 +int __init au_wkq_init(void);
36772 +void au_wkq_fin(void);
36774 +/* ---------------------------------------------------------------------- */
36776 +static inline int au_wkq_test(void)
36778 + return current->flags & PF_WQ_WORKER;
36781 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36783 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36786 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36788 + if (atomic_dec_and_test(&nwt->nw_len))
36789 + wake_up_all(&nwt->nw_wq);
36792 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36794 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36798 +#endif /* __KERNEL__ */
36799 +#endif /* __AUFS_WKQ_H__ */
36800 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36801 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36802 +++ linux/fs/aufs/xattr.c 2024-05-13 17:13:00.621404284 +0200
36804 +// SPDX-License-Identifier: GPL-2.0
36806 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36808 + * This program is free software; you can redistribute it and/or modify
36809 + * it under the terms of the GNU General Public License as published by
36810 + * the Free Software Foundation; either version 2 of the License, or
36811 + * (at your option) any later version.
36813 + * This program is distributed in the hope that it will be useful,
36814 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36815 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36816 + * GNU General Public License for more details.
36818 + * You should have received a copy of the GNU General Public License
36819 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36823 + * handling xattr functions
36826 +#include <linux/fs.h>
36827 +#include <linux/xattr.h>
36830 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36832 + if (!ignore_flags)
36840 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36845 +#define cmp(brattr, prefix) do { \
36846 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36847 + XATTR_##prefix##_PREFIX_LEN)) { \
36848 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36854 + cmp(SEC, SECURITY);
36855 + cmp(SYS, SYSTEM);
36856 + cmp(TR, TRUSTED);
36860 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36867 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36869 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36870 + char *name, char **buf, unsigned int ignore_flags,
36871 + unsigned int verbose)
36875 + struct inode *h_idst;
36876 + struct dentry *h_dst_dentry, *h_src_dentry;
36877 + struct mnt_idmap *h_dst_idmap, *h_src_idmap;
36878 + struct posix_acl *acl;
36880 + is_acl = !!is_posix_acl_xattr(name);
36881 + h_src_idmap = mnt_idmap(h_src->mnt);
36882 + h_src_dentry = h_src->dentry;
36884 + acl = vfs_get_acl(h_src_idmap, h_src_dentry, name);
36886 + if (IS_ERR(acl)) {
36887 + err = PTR_ERR(acl);
36888 + if (err == -ENODATA)
36890 + else if (err == -EOPNOTSUPP
36891 + && au_test_nfs_noacl(d_inode(h_src_dentry)))
36893 + else if (verbose || au_debug_test())
36894 + pr_err("%s, err %d\n", name, err);
36898 + ssz = vfs_getxattr_alloc(h_src_idmap, h_src_dentry, name, buf,
36900 + if (unlikely(ssz <= 0)) {
36902 + if (err == -ENODATA)
36904 + else if (err == -EOPNOTSUPP
36905 + && (ignore_flags & au_xattr_out_of_list))
36907 + else if (err && (verbose || au_debug_test()))
36908 + pr_err("%s, err %d\n", name, err);
36913 + /* unlock it temporary */
36914 + h_dst_idmap = mnt_idmap(h_dst->mnt);
36915 + h_dst_dentry = h_dst->dentry;
36916 + h_idst = d_inode(h_dst_dentry);
36917 + inode_unlock(h_idst);
36919 + err = vfsub_set_acl(h_dst_idmap, h_dst_dentry, name, acl);
36920 + posix_acl_release(acl);
36922 + err = vfsub_setxattr(h_dst_idmap, h_dst_dentry, name, *buf,
36923 + ssz, /*flags*/0);
36924 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36925 + if (unlikely(err)) {
36926 + if (verbose || au_debug_test())
36927 + pr_err("%s, err %d\n", name, err);
36928 + err = au_xattr_ignore(err, name, ignore_flags);
36935 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36936 + unsigned int verbose)
36938 + int err, unlocked;
36940 + struct dentry *h_dst_dentry, *h_src_dentry;
36941 + struct inode *h_isrc, *h_idst;
36942 + char *value, *p, *o, *e;
36944 + /* try stopping to update the source inode while we are referencing */
36945 + /* there should not be the parent-child relationship between them */
36946 + h_dst_dentry = h_dst->dentry;
36947 + h_idst = d_inode(h_dst_dentry);
36948 + h_src_dentry = h_src->dentry;
36949 + h_isrc = d_inode(h_src_dentry);
36950 + inode_unlock(h_idst);
36951 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36952 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36955 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36956 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36958 + if (unlikely(err < 0)) {
36960 + if (err == -ENODATA
36961 + || err == -EOPNOTSUPP)
36962 + err = 0; /* ignore */
36971 + p = kmalloc(ssz, GFP_NOFS);
36973 + if (unlikely(!p))
36975 + err = vfs_listxattr(h_src_dentry, p, ssz);
36977 + inode_unlock_shared(h_isrc);
36979 + AuDbg("err %d, ssz %zd\n", err, ssz);
36980 + if (unlikely(err < 0))
36986 + ignore_flags |= au_xattr_out_of_list;
36987 + while (!err && p < e) {
36988 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36990 + p += strlen(p) + 1;
36992 + au_kfree_try_rcu(value);
36995 + au_kfree_try_rcu(o);
36998 + inode_unlock_shared(h_isrc);
37003 +/* ---------------------------------------------------------------------- */
37005 +static int au_smack_reentering(struct super_block *sb)
37007 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
37009 + * as a part of lookup, smack_d_instantiate() is called, and it calls
37010 + * i_op->getxattr(). ouch.
37012 + return si_pid_test(sb);
37023 +struct au_lgxattr {
37031 + const char *name;
37038 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
37039 + struct au_lgxattr *arg)
37043 + struct path h_path;
37044 + struct super_block *sb;
37046 + sb = dentry->d_sb;
37047 + reenter = au_smack_reentering(sb);
37049 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
37050 + if (unlikely(err))
37053 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
37054 + if (unlikely(err))
37056 + if (unlikely(!h_path.dentry))
37057 + /* illegally overlapped or something */
37058 + goto out_di; /* pretending success */
37060 + /* always topmost entry only */
37061 + switch (arg->type) {
37062 + case AU_XATTR_LIST:
37063 + err = vfs_listxattr(h_path.dentry,
37064 + arg->u.list.list, arg->u.list.size);
37066 + case AU_XATTR_GET:
37067 + AuDebugOn(d_is_negative(h_path.dentry));
37068 + err = vfs_getxattr(mnt_idmap(h_path.mnt), h_path.dentry,
37069 + arg->u.get.name, arg->u.get.value,
37070 + arg->u.get.size);
37076 + di_read_unlock(dentry, AuLock_IR);
37079 + si_read_unlock(sb);
37085 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37087 + struct au_lgxattr arg = {
37088 + .type = AU_XATTR_LIST,
37095 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37098 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37099 + const char *name, void *value, size_t size)
37101 + struct au_lgxattr arg = {
37102 + .type = AU_XATTR_GET,
37110 + return au_lgxattr(dentry, inode, &arg);
37113 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37114 + const char *name, const void *value, size_t size,
37117 + struct au_sxattr arg = {
37118 + .type = AU_XATTR_SET,
37127 + return au_sxattr(dentry, inode, &arg);
37130 +/* ---------------------------------------------------------------------- */
37132 +static int au_xattr_get(const struct xattr_handler *handler,
37133 + struct dentry *dentry, struct inode *inode,
37134 + const char *name, void *buffer, size_t size)
37136 + return au_getxattr(dentry, inode, name, buffer, size);
37139 +static int au_xattr_set(const struct xattr_handler *handler,
37140 + struct mnt_idmap *idmap,
37141 + struct dentry *dentry, struct inode *inode,
37142 + const char *name, const void *value, size_t size,
37145 + return au_setxattr(dentry, inode, name, value, size, flags);
37148 +static const struct xattr_handler au_xattr_handler = {
37151 + .get = au_xattr_get,
37152 + .set = au_xattr_set
37155 +static const struct xattr_handler *au_xattr_handlers[] = {
37156 + &au_xattr_handler, /* must be last */
37160 +void au_xattr_init(struct super_block *sb)
37162 + sb->s_xattr = au_xattr_handlers;
37164 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37165 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37166 +++ linux/fs/aufs/xino.c 2024-05-13 17:13:00.624737645 +0200
37168 +// SPDX-License-Identifier: GPL-2.0
37170 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37172 + * This program is free software; you can redistribute it and/or modify
37173 + * it under the terms of the GNU General Public License as published by
37174 + * the Free Software Foundation; either version 2 of the License, or
37175 + * (at your option) any later version.
37177 + * This program is distributed in the hope that it will be useful,
37178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37180 + * GNU General Public License for more details.
37182 + * You should have received a copy of the GNU General Public License
37183 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37187 + * external inode number translation table and bitmap
37189 + * things to consider
37191 + * + au_xino object
37192 + * + XINO files (xino, xib, xigen)
37193 + * + dynamic debugfs entries (xiN)
37194 + * + static debugfs entries (xib, xigen)
37195 + * + static sysfs entry (xi_path)
37196 + * - several entry points to handle them.
37197 + * + mount(2) without xino option (default)
37198 + * + mount(2) with xino option
37199 + * + mount(2) with noxino option
37201 + * + remount with add/del branches
37202 + * + remount with xino/noxino options
37205 +#include <linux/seq_file.h>
37206 +#include <linux/statfs.h>
37209 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37210 + aufs_bindex_t bbot,
37211 + struct super_block *h_sb)
37213 + /* todo: try binary-search if the branches are many */
37214 + for (; btop <= bbot; btop++)
37215 + if (h_sb == au_sbr_sb(sb, btop))
37221 + * find another branch who is on the same filesystem of the specified
37222 + * branch{@btgt}. search until @bbot.
37224 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37225 + aufs_bindex_t bbot)
37227 + aufs_bindex_t bindex;
37228 + struct super_block *tgt_sb;
37230 + tgt_sb = au_sbr_sb(sb, btgt);
37231 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37233 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37238 +/* ---------------------------------------------------------------------- */
37241 + * stop unnecessary notify events at creating xino files
37244 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37246 + aufs_bindex_t bfound, bindex, bbot;
37247 + struct dentry *parent;
37248 + struct au_branch *br;
37251 + parent = dentry->d_parent; /* safe d_parent access */
37252 + bbot = au_sbbot(sb);
37253 + for (bindex = 0; bindex <= bbot; bindex++) {
37254 + br = au_sbr(sb, bindex);
37255 + if (au_br_dentry(br) == parent) {
37261 + AuDbg("bfound b%d\n", bfound);
37265 +struct au_xino_lock_dir {
37266 + struct au_hinode *hdir;
37267 + struct dentry *parent;
37268 + struct inode *dir;
37271 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37272 + unsigned int lsc)
37274 + struct dentry *parent;
37275 + struct inode *dir;
37277 + parent = dget_parent(dentry);
37278 + dir = d_inode(parent);
37279 + inode_lock_nested(dir, lsc);
37280 +#if 0 /* it should not happen */
37281 + spin_lock(&dentry->d_lock);
37282 + if (unlikely(dentry->d_parent != parent)) {
37283 + spin_unlock(&dentry->d_lock);
37284 + inode_unlock(dir);
37289 + spin_unlock(&dentry->d_lock);
37296 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37297 + struct au_xino_lock_dir *ldir)
37299 + aufs_bindex_t bindex;
37301 + ldir->hdir = NULL;
37302 + bindex = au_xi_root(sb, xipath->dentry);
37303 + if (bindex >= 0) {
37304 + /* rw branch root */
37305 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37306 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37309 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37311 + ldir->dir = d_inode(ldir->parent);
37315 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37318 + au_hn_inode_unlock(ldir->hdir);
37320 + inode_unlock(ldir->dir);
37321 + dput(ldir->parent);
37325 +/* ---------------------------------------------------------------------- */
37328 + * create and set a new xino file
37330 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37333 + struct file *file;
37334 + struct dentry *h_parent, *d;
37335 + struct inode *h_dir, *inode;
37337 + static DEFINE_MUTEX(mtx);
37340 + * at mount-time, and the xino file is the default path,
37341 + * hnotify is disabled so we have no notify events to ignore.
37342 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37345 + mutex_lock(&mtx);
37346 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37347 + /* | __FMODE_NONOTIFY */,
37349 + if (IS_ERR(file)) {
37351 + mutex_unlock(&mtx);
37353 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37357 + /* keep file count */
37359 + d = file->f_path.dentry;
37360 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37362 + mutex_unlock(&mtx);
37363 + /* mnt_want_write() is unnecessary here */
37364 + h_dir = d_inode(h_parent);
37365 + inode = file_inode(file);
37366 + /* no delegation since it is just created */
37367 + if (inode->i_nlink)
37368 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37370 + inode_unlock(h_dir);
37372 + if (unlikely(err)) {
37374 + pr_err("unlink %s(%d)\n", fpath, err);
37379 + if (unlikely(sb && sb == d->d_sb)) {
37381 + pr_err("%s must be outside\n", fpath);
37384 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37386 + pr_err("xino doesn't support %s(%s)\n",
37387 + fpath, au_sbtype(d->d_sb));
37390 + return file; /* success */
37394 + file = ERR_PTR(err);
37399 + * create a new xinofile at the same place/path as @base.
37401 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37402 + struct file *copy_src)
37404 + struct file *file;
37405 + struct dentry *dentry;
37406 + struct inode *dir, *delegated;
37407 + struct qstr *name;
37408 + struct path ppath, path;
37409 + int err, do_unlock;
37410 + struct au_xino_lock_dir ldir;
37413 + au_xino_lock_dir(sb, base, &ldir);
37414 + dentry = base->dentry;
37415 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37416 + ppath.mnt = base->mnt;
37417 + dir = d_inode(ppath.dentry);
37420 + name = &dentry->d_name;
37421 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37422 + if (IS_ERR(path.dentry)) {
37423 + file = (void *)path.dentry;
37424 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37428 + /* no need to mnt_want_write() since we call dentry_open() later */
37429 + err = vfs_create(mnt_idmap(base->mnt), dir, path.dentry, 0666, NULL);
37430 + if (unlikely(err)) {
37431 + file = ERR_PTR(err);
37432 + pr_err("%pd create err %d\n", dentry, err);
37436 + path.mnt = base->mnt;
37437 + file = vfsub_dentry_open(&path,
37438 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37439 + /* | __FMODE_NONOTIFY */);
37440 + if (IS_ERR(file)) {
37441 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37445 + delegated = NULL;
37446 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37447 + au_xino_unlock_dir(&ldir);
37449 + if (unlikely(err == -EWOULDBLOCK)) {
37450 + pr_warn("cannot retry for NFSv4 delegation"
37451 + " for an internal unlink\n");
37454 + if (unlikely(err)) {
37455 + pr_err("%pd unlink err %d\n", dentry, err);
37460 + /* no one can touch copy_src xino */
37461 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37462 + if (unlikely(err)) {
37463 + pr_err("%pd copy err %d\n", dentry, err);
37467 + goto out_dput; /* success */
37471 + file = ERR_PTR(err);
37473 + dput(path.dentry);
37476 + au_xino_unlock_dir(&ldir);
37480 +struct file *au_xino_file1(struct au_xino *xi)
37482 + struct file *file;
37483 + unsigned int u, nfile;
37486 + nfile = xi->xi_nfile;
37487 + for (u = 0; u < nfile; u++) {
37488 + file = xi->xi_file[u];
37496 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37507 + if (idx < xi->xi_nfile) {
37508 + f = xi->xi_file[idx];
37512 + p = au_kzrealloc(xi->xi_file,
37513 + sizeof(*xi->xi_file) * xi->xi_nfile,
37514 + sizeof(*xi->xi_file) * (idx + 1),
37515 + GFP_NOFS, /*may_shrink*/0);
37517 + MtxMustLock(&xi->xi_mtx);
37519 + xi->xi_nfile = idx + 1;
37527 + xi->xi_file[idx] = file;
37534 + * if @xinew->xi is not set, then create new xigen file.
37536 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37538 + struct file *file;
37541 + SiMustAnyLock(sb);
37543 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37544 + if (IS_ERR(file)) {
37545 + err = PTR_ERR(file);
37546 + pr_err("%s[%d], err %d\n",
37547 + xinew->xi ? "xino" : "xigen",
37548 + xinew->idx, err);
37553 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37556 + /* todo: make xigen file an array */
37557 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37560 + if (unlikely(err))
37561 + file = ERR_PTR(err);
37567 +/* ---------------------------------------------------------------------- */
37570 + * truncate xino files
37572 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37573 + int idx, struct kstatfs *st)
37577 + struct file *file, *new_xino;
37578 + struct au_xi_new xinew = {
37583 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37584 + file = au_xino_file(xinew.xi, idx);
37588 + xinew.base = &file->f_path;
37589 + err = vfs_statfs(xinew.base, st);
37590 + if (unlikely(err)) {
37591 + AuErr1("statfs err %d, ignored\n", err);
37596 + blocks = file_inode(file)->i_blocks;
37597 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37598 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37600 + xinew.copy_src = file;
37601 + new_xino = au_xi_new(sb, &xinew);
37602 + if (IS_ERR(new_xino)) {
37603 + err = PTR_ERR(new_xino);
37604 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37608 + err = vfs_statfs(&new_xino->f_path, st);
37610 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37611 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37612 + st->f_bfree, st->f_blocks);
37614 + AuErr1("statfs err %d, ignored\n", err);
37622 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37625 + unsigned long jiffy;
37626 + aufs_bindex_t bbot;
37627 + struct kstatfs *st;
37628 + struct au_branch *br;
37629 + struct au_xino *xi;
37632 + st = kmalloc(sizeof(*st), GFP_NOFS);
37633 + if (unlikely(!st))
37637 + bbot = au_sbbot(sb);
37638 + if (unlikely(bindex < 0 || bbot < bindex))
37643 + br = au_sbr(sb, bindex);
37644 + xi = br->br_xino;
37645 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37646 + err = au_xino_do_trunc(sb, bindex, i, st);
37648 + au_sbi(sb)->si_xino_jiffy = jiffy;
37651 + au_kfree_rcu(st);
37656 +struct xino_do_trunc_args {
37657 + struct super_block *sb;
37658 + struct au_branch *br;
37662 +static void xino_do_trunc(void *_args)
37664 + struct xino_do_trunc_args *args = _args;
37665 + struct super_block *sb;
37666 + struct au_branch *br;
37667 + struct inode *dir;
37669 + aufs_bindex_t bindex;
37673 + dir = d_inode(sb->s_root);
37677 + si_noflush_write_lock(sb);
37678 + ii_read_lock_parent(dir);
37679 + bindex = au_br_index(sb, br->br_id);
37680 + err = au_xino_trunc(sb, bindex, idx);
37681 + ii_read_unlock(dir);
37682 + if (unlikely(err))
37683 + pr_warn("err b%d, (%d)\n", bindex, err);
37684 + atomic_dec(&br->br_xino->xi_truncating);
37685 + au_lcnt_dec(&br->br_count);
37686 + si_write_unlock(sb);
37687 + au_nwt_done(&au_sbi(sb)->si_nowait);
37688 + au_kfree_rcu(args);
37692 + * returns the index in the xi_file array whose corresponding file is necessary
37693 + * to truncate, or -1 which means no need to truncate.
37695 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37699 + struct kstatfs st;
37700 + struct au_sbinfo *sbinfo;
37701 + struct au_xino *xi;
37702 + struct file *file;
37704 + /* todo: si_xino_expire and the ratio should be customizable */
37705 + sbinfo = au_sbi(sb);
37706 + if (time_before(jiffies,
37707 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37710 + /* truncation border */
37711 + xi = br->br_xino;
37712 + for (u = 0; u < xi->xi_nfile; u++) {
37713 + file = au_xino_file(xi, u);
37717 + err = vfs_statfs(&file->f_path, &st);
37718 + if (unlikely(err)) {
37719 + AuErr1("statfs err %d, ignored\n", err);
37722 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37723 + >= AUFS_XINO_DEF_TRUNC)
37730 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37733 + struct xino_do_trunc_args *args;
37736 + idx = xino_trunc_test(sb, br);
37740 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37743 + /* lock and kfree() will be called in trunc_xino() */
37744 + args = kmalloc(sizeof(*args), GFP_NOFS);
37745 + if (unlikely(!args)) {
37746 + AuErr1("no memory\n");
37750 + au_lcnt_inc(&br->br_count);
37754 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37756 + return; /* success */
37758 + pr_err("wkq %d\n", wkq_err);
37759 + au_lcnt_dec(&br->br_count);
37760 + au_kfree_rcu(args);
37763 + atomic_dec(&br->br_xino->xi_truncating);
37766 +/* ---------------------------------------------------------------------- */
37768 +struct au_xi_calc {
37773 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37774 + struct au_xi_calc *calc)
37778 + maxent = au_xi_maxent(sb);
37779 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37780 + calc->pos *= sizeof(ino_t);
37783 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37784 + struct au_xi_calc *calc)
37787 + struct file *file;
37788 + struct au_xino *xi = br->br_xino;
37789 + struct au_xi_new xinew = {
37793 + SiMustAnyLock(sb);
37799 + mutex_lock(&xi->xi_mtx);
37800 + file = au_xino_file(xi, calc->idx);
37804 + file = au_xino_file(xi, /*idx*/-1);
37805 + AuDebugOn(!file);
37806 + xinew.idx = calc->idx;
37807 + xinew.base = &file->f_path;
37808 + /* xinew.copy_src = NULL; */
37809 + file = au_xi_new(sb, &xinew);
37810 + if (IS_ERR(file))
37811 + err = PTR_ERR(file);
37814 + mutex_unlock(&xi->xi_mtx);
37819 +struct au_xino_do_new_async_args {
37820 + struct super_block *sb;
37821 + struct au_branch *br;
37822 + struct au_xi_calc calc;
37826 +struct au_xi_writing {
37827 + struct hlist_bl_node node;
37828 + ino_t h_ino, ino;
37831 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37834 +static void au_xino_call_do_new_async(void *args)
37836 + struct au_xino_do_new_async_args *a = args;
37837 + struct au_branch *br;
37838 + struct super_block *sb;
37839 + struct au_sbinfo *sbi;
37840 + struct inode *root;
37841 + struct file *file;
37842 + struct au_xi_writing *del, *p;
37843 + struct hlist_bl_head *hbl;
37844 + struct hlist_bl_node *pos;
37849 + sbi = au_sbi(sb);
37850 + si_noflush_read_lock(sb);
37851 + root = d_inode(sb->s_root);
37852 + ii_read_lock_child(root);
37853 + err = au_xino_do_new_async(sb, br, &a->calc);
37854 + if (unlikely(err)) {
37855 + AuIOErr("err %d\n", err);
37859 + file = au_xino_file(br->br_xino, a->calc.idx);
37860 + AuDebugOn(!file);
37861 + err = au_xino_do_write(file, &a->calc, a->ino);
37862 + if (unlikely(err)) {
37863 + AuIOErr("err %d\n", err);
37868 + hbl = &br->br_xino->xi_writing;
37869 + hlist_bl_lock(hbl);
37870 + au_hbl_for_each(pos, hbl) {
37871 + p = container_of(pos, struct au_xi_writing, node);
37872 + if (p->ino == a->ino) {
37874 + hlist_bl_del(&p->node);
37878 + hlist_bl_unlock(hbl);
37879 + au_kfree_rcu(del);
37882 + au_lcnt_dec(&br->br_count);
37883 + ii_read_unlock(root);
37884 + si_read_unlock(sb);
37885 + au_nwt_done(&sbi->si_nowait);
37890 + * create a new xino file asynchronously
37892 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37893 + struct au_xi_calc *calc, ino_t ino)
37896 + struct au_xino_do_new_async_args *arg;
37899 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37900 + if (unlikely(!arg))
37905 + arg->calc = *calc;
37907 + au_lcnt_inc(&br->br_count);
37908 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37909 + if (unlikely(err)) {
37910 + pr_err("wkq %d\n", err);
37911 + au_lcnt_dec(&br->br_count);
37912 + au_kfree_rcu(arg);
37920 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37921 + * at the position of @h_ino.
37923 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37928 + struct au_xi_calc calc;
37929 + struct au_sbinfo *sbinfo;
37930 + struct file *file;
37931 + struct au_xino *xi;
37932 + struct hlist_bl_head *hbl;
37933 + struct hlist_bl_node *pos;
37934 + struct au_xi_writing *p;
37937 + if (!au_opt_test(au_mntflags(sb), XINO))
37938 + return 0; /* no xino */
37941 + au_xi_calc(sb, h_ino, &calc);
37942 + xi = au_sbr(sb, bindex)->br_xino;
37943 + file = au_xino_file(xi, calc.idx);
37945 + hbl = &xi->xi_writing;
37946 + hlist_bl_lock(hbl);
37947 + au_hbl_for_each(pos, hbl) {
37948 + p = container_of(pos, struct au_xi_writing, node);
37949 + if (p->h_ino == h_ino) {
37950 + AuDbg("hi%llu, i%llu, found\n",
37951 + (u64)p->h_ino, (u64)p->ino);
37956 + hlist_bl_unlock(hbl);
37958 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37959 + return 0; /* no xino */
37961 + sbinfo = au_sbi(sb);
37962 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37963 + if (sz == sizeof(*ino))
37964 + return 0; /* success */
37967 + if (unlikely(sz >= 0)) {
37969 + AuIOErr("xino read error (%zd)\n", sz);
37974 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37979 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37980 + if (sz == sizeof(ino))
37981 + return 0; /* success */
37983 + AuIOErr("write failed (%zd)\n", sz);
37988 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37989 + * at the position of @h_ino.
37990 + * even if @ino is zero, it is written to the xinofile and means no entry.
37991 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37992 + * try truncating it.
37994 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37998 + unsigned int mnt_flags;
37999 + struct au_xi_calc calc;
38000 + struct file *file;
38001 + struct au_branch *br;
38002 + struct au_xino *xi;
38003 + struct au_xi_writing *p;
38005 + SiMustAnyLock(sb);
38007 + mnt_flags = au_mntflags(sb);
38008 + if (!au_opt_test(mnt_flags, XINO))
38011 + au_xi_calc(sb, h_ino, &calc);
38012 + br = au_sbr(sb, bindex);
38013 + xi = br->br_xino;
38014 + file = au_xino_file(xi, calc.idx);
38016 + /* store the inum pair into the list */
38017 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
38018 + p->h_ino = h_ino;
38020 + au_hbl_add(&p->node, &xi->xi_writing);
38022 + /* create and write a new xino file asynchronously */
38023 + err = au_xino_new_async(sb, br, &calc, ino);
38025 + return 0; /* success */
38029 + err = au_xino_do_write(file, &calc, ino);
38031 + br = au_sbr(sb, bindex);
38032 + if (au_opt_test(mnt_flags, TRUNC_XINO)
38033 + && au_test_fs_trunc_xino(au_br_sb(br)))
38034 + xino_try_trunc(sb, br);
38035 + return 0; /* success */
38039 + AuIOErr("write failed (%d)\n", err);
38043 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38046 +/* todo: unnecessary to support mmap_sem since kernel-space? */
38047 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
38051 + const int prevent_endless = 10;
38055 + err = vfsub_read_k(file, kbuf, size, pos);
38056 + if (err == -EINTR
38057 + && !au_wkq_test()
38058 + && fatal_signal_pending(current)) {
38059 + err = xino_fread_wkq(file, kbuf, size, pos);
38060 + BUG_ON(err == -EINTR);
38062 + } while (i++ < prevent_endless
38063 + && (err == -EAGAIN || err == -EINTR));
38065 +#if 0 /* reserved for future use */
38067 + fsnotify_access(file->f_path.dentry);
38073 +struct xino_fread_args {
38075 + struct file *file;
38081 +static void call_xino_fread(void *args)
38083 + struct xino_fread_args *a = args;
38084 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38087 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38092 + struct xino_fread_args args = {
38100 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38101 + if (unlikely(wkq_err))
38107 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38110 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38115 + const int prevent_endless = 10;
38119 + err = vfsub_write_k(file, kbuf, size, pos);
38120 + if (err == -EINTR
38121 + && !au_wkq_test()
38122 + && fatal_signal_pending(current)) {
38123 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38124 + BUG_ON(err == -EINTR);
38126 + } while (i++ < prevent_endless
38127 + && (err == -EAGAIN || err == -EINTR));
38129 +#if 0 /* reserved for future use */
38131 + fsnotify_modify(file->f_path.dentry);
38137 +struct do_xino_fwrite_args {
38139 + struct file *file;
38145 +static void call_do_xino_fwrite(void *args)
38147 + struct do_xino_fwrite_args *a = args;
38148 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38151 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38156 + struct do_xino_fwrite_args args = {
38165 + * it breaks RLIMIT_FSIZE and normal user's limit,
38166 + * users should care about quota and real 'filesystem full.'
38168 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38169 + if (unlikely(wkq_err))
38175 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38179 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38181 + err = do_xino_fwrite(file, buf, size, pos);
38185 + err = xino_fwrite_wkq(file, buf, size, pos);
38192 +/* ---------------------------------------------------------------------- */
38195 + * inode number bitmap
38197 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38198 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38202 + AuDebugOn(bit < 0 || page_bits <= bit);
38203 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38207 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38209 + AuDebugOn(ino < AUFS_FIRST_INO);
38210 + ino -= AUFS_FIRST_INO;
38211 + *pindex = ino / page_bits;
38212 + *bit = ino % page_bits;
38215 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38220 + struct au_sbinfo *sbinfo;
38221 + struct file *xib;
38222 + unsigned long *p;
38224 + sbinfo = au_sbi(sb);
38225 + MtxMustLock(&sbinfo->si_xib_mtx);
38226 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38227 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38229 + if (pindex == sbinfo->si_xib_last_pindex)
38232 + xib = sbinfo->si_xib;
38233 + p = sbinfo->si_xib_buf;
38234 + pos = sbinfo->si_xib_last_pindex;
38235 + pos *= PAGE_SIZE;
38236 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38237 + if (unlikely(sz != PAGE_SIZE))
38241 + pos *= PAGE_SIZE;
38242 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38243 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38245 + memset(p, 0, PAGE_SIZE);
38246 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38248 + if (sz == PAGE_SIZE) {
38249 + sbinfo->si_xib_last_pindex = pindex;
38250 + return 0; /* success */
38254 + AuIOErr1("write failed (%zd)\n", sz);
38261 +static void au_xib_clear_bit(struct inode *inode)
38264 + unsigned long pindex;
38265 + struct super_block *sb;
38266 + struct au_sbinfo *sbinfo;
38268 + AuDebugOn(inode->i_nlink);
38270 + sb = inode->i_sb;
38271 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38272 + AuDebugOn(page_bits <= bit);
38273 + sbinfo = au_sbi(sb);
38274 + mutex_lock(&sbinfo->si_xib_mtx);
38275 + err = xib_pindex(sb, pindex);
38277 + clear_bit(bit, sbinfo->si_xib_buf);
38278 + sbinfo->si_xib_next_bit = bit;
38280 + mutex_unlock(&sbinfo->si_xib_mtx);
38283 +/* ---------------------------------------------------------------------- */
38286 + * truncate a xino bitmap file
38290 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38294 + unsigned long pindex;
38295 + loff_t pos, pend;
38296 + struct au_sbinfo *sbinfo;
38298 + unsigned long *p;
38301 + sbinfo = au_sbi(sb);
38302 + MtxMustLock(&sbinfo->si_xib_mtx);
38303 + p = sbinfo->si_xib_buf;
38304 + pend = vfsub_f_size_read(file);
38306 + while (pos < pend) {
38307 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38309 + if (unlikely(sz <= 0))
38313 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38314 + if (unlikely(*ino < AUFS_FIRST_INO))
38317 + xib_calc_bit(*ino, &pindex, &bit);
38318 + AuDebugOn(page_bits <= bit);
38319 + err = xib_pindex(sb, pindex);
38331 +static int xib_restore(struct super_block *sb)
38334 + unsigned int nfile;
38335 + aufs_bindex_t bindex, bbot;
38337 + struct au_branch *br;
38338 + struct au_xino *xi;
38339 + struct file *file;
38342 + page = (void *)__get_free_page(GFP_NOFS);
38343 + if (unlikely(!page))
38347 + bbot = au_sbbot(sb);
38348 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38349 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38350 + br = au_sbr(sb, bindex);
38351 + xi = br->br_xino;
38352 + nfile = xi->xi_nfile;
38353 + for (i = 0; i < nfile; i++) {
38354 + file = au_xino_file(xi, i);
38356 + err = do_xib_restore(sb, file, page);
38359 + AuDbg("skip shared b%d\n", bindex);
38360 + free_page((unsigned long)page);
38366 +int au_xib_trunc(struct super_block *sb)
38371 + struct au_sbinfo *sbinfo;
38372 + unsigned long *p;
38373 + struct file *file;
38375 + SiMustWriteLock(sb);
38378 + sbinfo = au_sbi(sb);
38379 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38382 + file = sbinfo->si_xib;
38383 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38386 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38387 + err = PTR_ERR(file);
38388 + if (IS_ERR(file))
38390 + fput(sbinfo->si_xib);
38391 + sbinfo->si_xib = file;
38393 + p = sbinfo->si_xib_buf;
38394 + memset(p, 0, PAGE_SIZE);
38396 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38397 + if (unlikely(sz != PAGE_SIZE)) {
38399 + AuIOErr("err %d\n", err);
38405 + mutex_lock(&sbinfo->si_xib_mtx);
38406 + /* mnt_want_write() is unnecessary here */
38407 + err = xib_restore(sb);
38408 + mutex_unlock(&sbinfo->si_xib_mtx);
38414 +/* ---------------------------------------------------------------------- */
38416 +struct au_xino *au_xino_alloc(unsigned int nfile)
38418 + struct au_xino *xi;
38420 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38421 + if (unlikely(!xi))
38423 + xi->xi_nfile = nfile;
38424 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38425 + if (unlikely(!xi->xi_file))
38428 + xi->xi_nondir.total = 8; /* initial size */
38429 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38431 + if (unlikely(!xi->xi_nondir.array))
38434 + spin_lock_init(&xi->xi_nondir.spin);
38435 + init_waitqueue_head(&xi->xi_nondir.wqh);
38436 + mutex_init(&xi->xi_mtx);
38437 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38438 + atomic_set(&xi->xi_truncating, 0);
38439 + kref_init(&xi->xi_kref);
38440 + goto out; /* success */
38443 + au_kfree_try_rcu(xi->xi_file);
38445 + au_kfree_rcu(xi);
38451 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38454 + struct au_xino *xi;
38457 + xi = au_xino_alloc(idx + 1);
38458 + if (unlikely(!xi)) {
38465 + xi->xi_file[idx] = file;
38466 + AuDebugOn(br->br_xino);
38467 + br->br_xino = xi;
38473 +static void au_xino_release(struct kref *kref)
38475 + struct au_xino *xi;
38477 + unsigned long ul;
38478 + struct hlist_bl_head *hbl;
38479 + struct hlist_bl_node *pos, *n;
38480 + struct au_xi_writing *p;
38482 + xi = container_of(kref, struct au_xino, xi_kref);
38483 + for (i = 0; i < xi->xi_nfile; i++)
38484 + if (xi->xi_file[i])
38485 + fput(xi->xi_file[i]);
38486 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38487 + AuDebugOn(xi->xi_nondir.array[i]);
38488 + mutex_destroy(&xi->xi_mtx);
38489 + hbl = &xi->xi_writing;
38490 + ul = au_hbl_count(hbl);
38491 + if (unlikely(ul)) {
38492 + pr_warn("xi_writing %lu\n", ul);
38493 + hlist_bl_lock(hbl);
38494 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38495 + hlist_bl_del(&p->node);
38496 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38499 + hlist_bl_unlock(hbl);
38501 + au_kfree_try_rcu(xi->xi_file);
38502 + au_kfree_try_rcu(xi->xi_nondir.array);
38503 + au_kfree_rcu(xi);
38506 +int au_xino_put(struct au_branch *br)
38509 + struct au_xino *xi;
38512 + xi = br->br_xino;
38514 + br->br_xino = NULL;
38515 + ret = kref_put(&xi->xi_kref, au_xino_release);
38521 +/* ---------------------------------------------------------------------- */
38524 + * xino mount option handlers
38528 +static void xino_clear_xib(struct super_block *sb)
38530 + struct au_sbinfo *sbinfo;
38532 + SiMustWriteLock(sb);
38534 + sbinfo = au_sbi(sb);
38535 + if (sbinfo->si_xib)
38536 + fput(sbinfo->si_xib);
38537 + sbinfo->si_xib = NULL;
38538 + if (sbinfo->si_xib_buf)
38539 + free_page((unsigned long)sbinfo->si_xib_buf);
38540 + sbinfo->si_xib_buf = NULL;
38543 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38547 + struct au_sbinfo *sbinfo;
38548 + struct file *file;
38549 + struct super_block *xi_sb;
38551 + SiMustWriteLock(sb);
38553 + sbinfo = au_sbi(sb);
38554 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38555 + err = PTR_ERR(file);
38556 + if (IS_ERR(file))
38558 + if (sbinfo->si_xib)
38559 + fput(sbinfo->si_xib);
38560 + sbinfo->si_xib = file;
38561 + xi_sb = file_inode(file)->i_sb;
38562 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38563 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38565 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38566 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38569 + sbinfo->si_ximaxent /= sizeof(ino_t);
38572 + if (!sbinfo->si_xib_buf)
38573 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38574 + if (unlikely(!sbinfo->si_xib_buf))
38577 + sbinfo->si_xib_last_pindex = 0;
38578 + sbinfo->si_xib_next_bit = 0;
38579 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38581 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38582 + if (unlikely(err != PAGE_SIZE))
38586 + goto out; /* success */
38589 + if (sbinfo->si_xib_buf)
38590 + free_page((unsigned long)sbinfo->si_xib_buf);
38591 + sbinfo->si_xib_buf = NULL;
38595 + fput(sbinfo->si_xib);
38596 + sbinfo->si_xib = NULL;
38602 +/* xino for each branch */
38603 +static void xino_clear_br(struct super_block *sb)
38605 + aufs_bindex_t bindex, bbot;
38606 + struct au_branch *br;
38608 + bbot = au_sbbot(sb);
38609 + for (bindex = 0; bindex <= bbot; bindex++) {
38610 + br = au_sbr(sb, bindex);
38616 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38617 + aufs_bindex_t bshared)
38619 + struct au_branch *brshared;
38621 + brshared = au_sbr(sb, bshared);
38622 + AuDebugOn(!brshared->br_xino);
38623 + AuDebugOn(!brshared->br_xino->xi_file);
38624 + if (br->br_xino != brshared->br_xino) {
38625 + au_xino_get(brshared);
38627 + br->br_xino = brshared->br_xino;
38631 +struct au_xino_do_set_br {
38632 + struct au_branch *br;
38634 + aufs_bindex_t bshared;
38637 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38638 + struct au_xino_do_set_br *args)
38641 + struct au_xi_calc calc;
38642 + struct file *file;
38643 + struct au_branch *br;
38644 + struct au_xi_new xinew = {
38649 + xinew.xi = br->br_xino;
38650 + au_xi_calc(sb, args->h_ino, &calc);
38651 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38652 + if (args->bshared >= 0)
38653 + /* shared xino */
38654 + au_xino_set_br_shared(sb, br, args->bshared);
38655 + else if (!xinew.xi) {
38657 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38658 + if (unlikely(err))
38662 + /* force re-creating */
38663 + xinew.xi = br->br_xino;
38664 + xinew.idx = calc.idx;
38665 + mutex_lock(&xinew.xi->xi_mtx);
38666 + file = au_xi_new(sb, &xinew);
38667 + mutex_unlock(&xinew.xi->xi_mtx);
38668 + err = PTR_ERR(file);
38669 + if (IS_ERR(file))
38671 + AuDebugOn(!file);
38673 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38674 + if (unlikely(err))
38682 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38685 + aufs_bindex_t bindex, bbot;
38686 + struct au_xino_do_set_br args;
38687 + struct inode *inode;
38689 + SiMustWriteLock(sb);
38691 + bbot = au_sbbot(sb);
38692 + inode = d_inode(sb->s_root);
38693 + for (bindex = 0; bindex <= bbot; bindex++) {
38694 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38695 + args.br = au_sbr(sb, bindex);
38696 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38697 + err = au_xino_do_set_br(sb, path, &args);
38698 + if (unlikely(err))
38706 +void au_xino_clr(struct super_block *sb)
38708 + struct au_sbinfo *sbinfo;
38710 + au_xigen_clr(sb);
38711 + xino_clear_xib(sb);
38712 + xino_clear_br(sb);
38713 + dbgaufs_brs_del(sb, 0);
38714 + sbinfo = au_sbi(sb);
38715 + /* lvalue, do not call au_mntflags() */
38716 + au_opt_clr(sbinfo->si_mntflags, XINO);
38719 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38722 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38723 + struct qstr *dname, *cur_name;
38724 + struct file *cur_xino;
38725 + struct au_sbinfo *sbinfo;
38726 + struct path *path, *cur_path;
38728 + SiMustWriteLock(sb);
38731 + sbinfo = au_sbi(sb);
38732 + path = &xiopt->file->f_path;
38733 + dentry = path->dentry;
38734 + parent = dget_parent(dentry);
38737 + cur_xino = sbinfo->si_xib;
38739 + cur_path = &cur_xino->f_path;
38740 + cur_dentry = cur_path->dentry;
38741 + cur_parent = dget_parent(cur_dentry);
38742 + cur_name = &cur_dentry->d_name;
38743 + dname = &dentry->d_name;
38744 + skip = (cur_parent == parent
38745 + && au_qstreq(dname, cur_name));
38746 + dput(cur_parent);
38752 + au_opt_set(sbinfo->si_mntflags, XINO);
38753 + err = au_xino_set_xib(sb, path);
38754 + /* si_x{read,write} are set */
38756 + err = au_xigen_set(sb, path);
38758 + err = au_xino_set_br(sb, path);
38760 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38761 + goto out; /* success */
38765 + AuIOErr("failed setting xino(%d).\n", err);
38774 + * create a xinofile at the default place/path.
38776 +struct file *au_xino_def(struct super_block *sb)
38778 + struct file *file;
38780 + struct au_branch *br;
38781 + struct super_block *h_sb;
38782 + struct path path;
38783 + aufs_bindex_t bbot, bindex, bwr;
38786 + bbot = au_sbbot(sb);
38788 + for (bindex = 0; bindex <= bbot; bindex++) {
38789 + br = au_sbr(sb, bindex);
38790 + if (au_br_writable(br->br_perm)
38791 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38798 + file = ERR_PTR(-ENOMEM);
38799 + page = (void *)__get_free_page(GFP_NOFS);
38800 + if (unlikely(!page))
38802 + path.mnt = au_br_mnt(br);
38803 + path.dentry = au_h_dptr(sb->s_root, bwr);
38804 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38805 + file = (void *)p;
38806 + if (!IS_ERR(p)) {
38807 + strcat(p, "/" AUFS_XINO_FNAME);
38808 + AuDbg("%s\n", p);
38809 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38811 + free_page((unsigned long)page);
38813 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38815 + if (IS_ERR(file))
38817 + h_sb = file->f_path.dentry->d_sb;
38818 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38819 + pr_err("xino doesn't support %s(%s)\n",
38820 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38822 + file = ERR_PTR(-EINVAL);
38830 +/* ---------------------------------------------------------------------- */
38833 + * initialize the xinofile for the specified branch @br
38834 + * at the place/path where @base_file indicates.
38835 + * test whether another branch is on the same filesystem or not,
38836 + * if found then share the xinofile with another branch.
38838 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38839 + struct path *base)
38842 + struct au_xino_do_set_br args = {
38847 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38849 + err = au_xino_do_set_br(sb, base, &args);
38850 + if (unlikely(err))
38856 +/* ---------------------------------------------------------------------- */
38859 + * get an unused inode number from bitmap
38861 +ino_t au_xino_new_ino(struct super_block *sb)
38864 + unsigned long *p, pindex, ul, pend;
38865 + struct au_sbinfo *sbinfo;
38866 + struct file *file;
38867 + int free_bit, err;
38869 + if (!au_opt_test(au_mntflags(sb), XINO))
38870 + return iunique(sb, AUFS_FIRST_INO);
38872 + sbinfo = au_sbi(sb);
38873 + mutex_lock(&sbinfo->si_xib_mtx);
38874 + p = sbinfo->si_xib_buf;
38875 + free_bit = sbinfo->si_xib_next_bit;
38876 + if (free_bit < page_bits && !test_bit(free_bit, p))
38877 + goto out; /* success */
38878 + free_bit = find_first_zero_bit(p, page_bits);
38879 + if (free_bit < page_bits)
38880 + goto out; /* success */
38882 + pindex = sbinfo->si_xib_last_pindex;
38883 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38884 + err = xib_pindex(sb, ul);
38885 + if (unlikely(err))
38887 + free_bit = find_first_zero_bit(p, page_bits);
38888 + if (free_bit < page_bits)
38889 + goto out; /* success */
38892 + file = sbinfo->si_xib;
38893 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38894 + for (ul = pindex + 1; ul <= pend; ul++) {
38895 + err = xib_pindex(sb, ul);
38896 + if (unlikely(err))
38898 + free_bit = find_first_zero_bit(p, page_bits);
38899 + if (free_bit < page_bits)
38900 + goto out; /* success */
38905 + set_bit(free_bit, p);
38906 + sbinfo->si_xib_next_bit = free_bit + 1;
38907 + pindex = sbinfo->si_xib_last_pindex;
38908 + mutex_unlock(&sbinfo->si_xib_mtx);
38909 + ino = xib_calc_ino(pindex, free_bit);
38910 + AuDbg("i%lu\n", (unsigned long)ino);
38913 + mutex_unlock(&sbinfo->si_xib_mtx);
38918 +/* for s_op->delete_inode() */
38919 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38922 + unsigned int mnt_flags;
38923 + aufs_bindex_t bindex, bbot, bi;
38924 + unsigned char try_trunc;
38925 + struct au_iinfo *iinfo;
38926 + struct super_block *sb;
38927 + struct au_hinode *hi;
38928 + struct inode *h_inode;
38929 + struct au_branch *br;
38930 + struct au_xi_calc calc;
38931 + struct file *file;
38933 + AuDebugOn(au_is_bad_inode(inode));
38935 + sb = inode->i_sb;
38936 + mnt_flags = au_mntflags(sb);
38937 + if (!au_opt_test(mnt_flags, XINO)
38938 + || inode->i_ino == AUFS_ROOT_INO)
38942 + au_xigen_inc(inode);
38943 + au_xib_clear_bit(inode);
38946 + iinfo = au_ii(inode);
38947 + bindex = iinfo->ii_btop;
38951 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38952 + hi = au_hinode(iinfo, bindex);
38953 + bbot = iinfo->ii_bbot;
38954 + for (; bindex <= bbot; bindex++, hi++) {
38955 + h_inode = hi->hi_inode;
38957 + || (!unlinked && h_inode->i_nlink))
38960 + /* inode may not be revalidated */
38961 + bi = au_br_index(sb, hi->hi_id);
38965 + br = au_sbr(sb, bi);
38966 + au_xi_calc(sb, h_inode->i_ino, &calc);
38967 + file = au_xino_file(br->br_xino, calc.idx);
38968 + if (IS_ERR_OR_NULL(file))
38971 + err = au_xino_do_write(file, &calc, /*ino*/0);
38972 + if (!err && try_trunc
38973 + && au_test_fs_trunc_xino(au_br_sb(br)))
38974 + xino_try_trunc(sb, br);
38978 +/* ---------------------------------------------------------------------- */
38980 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38982 + int found, total, i;
38985 + total = xi->xi_nondir.total;
38986 + for (i = 0; i < total; i++) {
38987 + if (xi->xi_nondir.array[i] != h_ino)
38996 +static int au_xinondir_expand(struct au_xino *xi)
39001 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
39004 + sz = xi->xi_nondir.total * sizeof(ino_t);
39005 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
39007 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
39008 + /*may_shrink*/0);
39010 + xi->xi_nondir.array = p;
39011 + xi->xi_nondir.total <<= 1;
39012 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
39020 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
39021 + ino_t h_ino, int idx)
39023 + struct au_xino *xi;
39025 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
39026 + xi = au_sbr(sb, bindex)->br_xino;
39027 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
39029 + spin_lock(&xi->xi_nondir.spin);
39030 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
39031 + xi->xi_nondir.array[idx] = 0;
39032 + spin_unlock(&xi->xi_nondir.spin);
39033 + wake_up_all(&xi->xi_nondir.wqh);
39036 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
39039 + int err, found, empty;
39040 + struct au_xino *xi;
39044 + if (!au_opt_test(au_mntflags(sb), XINO))
39045 + goto out; /* no xino */
39047 + xi = au_sbr(sb, bindex)->br_xino;
39050 + spin_lock(&xi->xi_nondir.spin);
39051 + found = au_xinondir_find(xi, h_ino);
39052 + if (found == -1) {
39053 + empty = au_xinondir_find(xi, /*h_ino*/0);
39054 + if (empty == -1) {
39055 + empty = xi->xi_nondir.total;
39056 + err = au_xinondir_expand(xi);
39057 + if (unlikely(err))
39060 + xi->xi_nondir.array[empty] = h_ino;
39063 + spin_unlock(&xi->xi_nondir.spin);
39064 + wait_event(xi->xi_nondir.wqh,
39065 + xi->xi_nondir.array[found] != h_ino);
39070 + spin_unlock(&xi->xi_nondir.spin);
39075 +/* ---------------------------------------------------------------------- */
39077 +int au_xino_path(struct seq_file *seq, struct file *file)
39081 + err = au_seq_path(seq, &file->f_path);
39082 + if (unlikely(err))
39085 +#define Deleted "\\040(deleted)"
39086 + seq->count -= sizeof(Deleted) - 1;
39087 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39088 + sizeof(Deleted) - 1));
39094 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39095 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39096 +++ linux/include/uapi/linux/aufs_type.h 2024-05-13 17:13:00.624737645 +0200
39098 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39100 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39102 + * This program is free software; you can redistribute it and/or modify
39103 + * it under the terms of the GNU General Public License as published by
39104 + * the Free Software Foundation; either version 2 of the License, or
39105 + * (at your option) any later version.
39107 + * This program is distributed in the hope that it will be useful,
39108 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39109 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39110 + * GNU General Public License for more details.
39112 + * You should have received a copy of the GNU General Public License
39113 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39116 +#ifndef __AUFS_TYPE_H__
39117 +#define __AUFS_TYPE_H__
39119 +#define AUFS_NAME "aufs"
39123 + * define it before including all other headers.
39124 + * sched.h may use pr_* macros before defining "current", so define the
39125 + * no-current version first, and re-define later.
39127 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39128 +#include <linux/sched.h>
39130 +#define pr_fmt(fmt) \
39131 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39132 + (int)sizeof(current->comm), current->comm, current->pid
39133 +#include <linux/limits.h>
39135 +#include <stdint.h>
39136 +#include <sys/types.h>
39137 +#include <limits.h>
39138 +#endif /* __KERNEL__ */
39140 +#define AUFS_VERSION "6.x-rcN-20240401"
39142 +/* todo? move this to linux-2.6.19/include/magic.h */
39143 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39145 +/* ---------------------------------------------------------------------- */
39148 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39149 +typedef int8_t aufs_bindex_t;
39150 +#define AUFS_BRANCH_MAX 127
39152 +typedef int16_t aufs_bindex_t;
39153 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39154 +#define AUFS_BRANCH_MAX 511
39155 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39156 +#define AUFS_BRANCH_MAX 1023
39157 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39158 +#define AUFS_BRANCH_MAX 32767
39162 +#ifndef AUFS_BRANCH_MAX
39163 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39165 +#endif /* __KERNEL__ */
39167 +/* ---------------------------------------------------------------------- */
39169 +#define AUFS_FSTYPE AUFS_NAME
39171 +#define AUFS_ROOT_INO 2
39172 +#define AUFS_FIRST_INO 11
39174 +#define AUFS_WH_PFX ".wh."
39175 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39176 +#define AUFS_WH_TMP_LEN 4
39177 +/* a limit for rmdir/rename a dir and copyup */
39178 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39179 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39181 + - AUFS_WH_TMP_LEN) /* hex */
39182 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39183 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39184 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39185 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39186 +#define AUFS_DIRWH_DEF 3
39187 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39188 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39189 +#define AUFS_RDBLK_DEF 512 /* bytes */
39190 +#define AUFS_RDHASH_DEF 32
39191 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39192 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39193 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39194 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39195 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39197 +/* pseudo-link maintenace under /proc */
39198 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39199 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39200 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39202 +/* dirren, renamed dir */
39203 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39204 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39205 +/* whiteouted doubly */
39206 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39207 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39209 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39210 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39212 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39213 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39214 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39216 +/* doubly whiteouted */
39217 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39218 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39219 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39221 +/* branch permissions and attributes */
39222 +#define AUFS_BRPERM_RW "rw"
39223 +#define AUFS_BRPERM_RO "ro"
39224 +#define AUFS_BRPERM_RR "rr"
39225 +#define AUFS_BRATTR_COO_REG "coo_reg"
39226 +#define AUFS_BRATTR_COO_ALL "coo_all"
39227 +#define AUFS_BRATTR_FHSM "fhsm"
39228 +#define AUFS_BRATTR_UNPIN "unpin"
39229 +#define AUFS_BRATTR_ICEX "icex"
39230 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39231 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39232 +#define AUFS_BRATTR_ICEX_TR "icextr"
39233 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39234 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39235 +#define AUFS_BRRATTR_WH "wh"
39236 +#define AUFS_BRWATTR_NLWH "nolwh"
39237 +#define AUFS_BRWATTR_MOO "moo"
39239 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39240 +#define AuBrPerm_RO (1 << 1) /* readonly */
39241 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39242 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39244 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39245 +#define AuBrAttr_COO_ALL (1 << 4)
39246 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39248 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39249 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39250 + branch. meaningless since
39251 + linux-3.18-rc1 */
39253 +/* ignore error in copying XATTR */
39254 +#define AuBrAttr_ICEX_SEC (1 << 7)
39255 +#define AuBrAttr_ICEX_SYS (1 << 8)
39256 +#define AuBrAttr_ICEX_TR (1 << 9)
39257 +#define AuBrAttr_ICEX_USR (1 << 10)
39258 +#define AuBrAttr_ICEX_OTH (1 << 11)
39259 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39260 + | AuBrAttr_ICEX_SYS \
39261 + | AuBrAttr_ICEX_TR \
39262 + | AuBrAttr_ICEX_USR \
39263 + | AuBrAttr_ICEX_OTH)
39265 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39266 +#define AuBrRAttr_Mask AuBrRAttr_WH
39268 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39269 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39270 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39272 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39274 +/* #warning test userspace */
39276 +#ifndef CONFIG_AUFS_FHSM
39277 +#undef AuBrAttr_FHSM
39278 +#define AuBrAttr_FHSM 0
39280 +#ifndef CONFIG_AUFS_XATTR
39281 +#undef AuBrAttr_ICEX
39282 +#define AuBrAttr_ICEX 0
39283 +#undef AuBrAttr_ICEX_SEC
39284 +#define AuBrAttr_ICEX_SEC 0
39285 +#undef AuBrAttr_ICEX_SYS
39286 +#define AuBrAttr_ICEX_SYS 0
39287 +#undef AuBrAttr_ICEX_TR
39288 +#define AuBrAttr_ICEX_TR 0
39289 +#undef AuBrAttr_ICEX_USR
39290 +#define AuBrAttr_ICEX_USR 0
39291 +#undef AuBrAttr_ICEX_OTH
39292 +#define AuBrAttr_ICEX_OTH 0
39296 +/* the longest combination */
39297 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39298 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39299 + "+" AUFS_BRATTR_COO_REG \
39300 + "+" AUFS_BRATTR_FHSM \
39301 + "+" AUFS_BRATTR_UNPIN \
39302 + "+" AUFS_BRATTR_ICEX_SEC \
39303 + "+" AUFS_BRATTR_ICEX_SYS \
39304 + "+" AUFS_BRATTR_ICEX_USR \
39305 + "+" AUFS_BRATTR_ICEX_OTH \
39306 + "+" AUFS_BRWATTR_NLWH)
39309 + char a[AuBrPermStrSz];
39310 +} au_br_perm_str_t;
39312 +static inline int au_br_writable(int brperm)
39314 + return brperm & AuBrPerm_RW;
39317 +static inline int au_br_whable(int brperm)
39319 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39322 +static inline int au_br_wh_linkable(int brperm)
39324 + return !(brperm & AuBrWAttr_NoLinkWH);
39327 +static inline int au_br_cmoo(int brperm)
39329 + return brperm & AuBrAttr_CMOO_Mask;
39332 +static inline int au_br_fhsm(int brperm)
39334 + return brperm & AuBrAttr_FHSM;
39337 +/* ---------------------------------------------------------------------- */
39341 + /* readdir in userspace */
39345 + AuCtl_WBR_FD, /* pathconf wrapper */
39346 + AuCtl_IBUSY, /* busy inode */
39347 + AuCtl_MVDOWN, /* move-down */
39348 + AuCtl_BR, /* info about branches */
39349 + AuCtl_FHSM_FD /* connection for fhsm */
39352 +/* borrowed from linux/include/linux/kernel.h */
39354 +#ifdef _GNU_SOURCE
39355 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39357 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39359 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39362 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39364 +#define __aligned(x) __attribute__((aligned(x)))
39369 +#define __packed __attribute__((packed))
39373 +struct au_rdu_cookie {
39378 + uint32_t generation;
39381 +struct au_rdu_ent {
39390 +static inline int au_rdu_len(int nlen)
39392 + /* include the terminating NULL */
39393 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39394 + sizeof(uint64_t));
39397 +union au_rdu_ent_ul {
39398 + struct au_rdu_ent __user *e;
39410 + uint64_t sz; /* AuCtl_RDU */
39411 + uint64_t nent; /* AuCtl_RDU_INO */
39413 + union au_rdu_ent_ul ent;
39414 + uint16_t verify[AufsCtlRduV_End];
39416 + /* input/output */
39420 + union au_rdu_ent_ul tail;
39421 + /* number of entries which were added in a single call */
39426 + struct au_rdu_cookie cookie;
39429 +/* ---------------------------------------------------------------------- */
39431 +/* dirren. the branch is identified by the filename who contains this */
39432 +struct au_drinfo {
39435 + uint8_t oldnamelen;
39436 + uint64_t _padding;
39438 + uint8_t oldname[];
39441 +struct au_drinfo_fdata {
39443 + struct au_drinfo drinfo;
39446 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39448 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39450 +/* ---------------------------------------------------------------------- */
39452 +struct aufs_wbr_fd {
39457 +/* ---------------------------------------------------------------------- */
39459 +struct aufs_ibusy {
39460 + uint64_t ino, h_ino;
39464 +/* ---------------------------------------------------------------------- */
39466 +/* error code for move-down */
39467 +/* the actual message strings are implemented in aufs-util.git */
39469 + EAU_MVDOWN_OPAQUE = 1,
39470 + EAU_MVDOWN_WHITEOUT,
39471 + EAU_MVDOWN_UPPER,
39472 + EAU_MVDOWN_BOTTOM,
39473 + EAU_MVDOWN_NOUPPER,
39474 + EAU_MVDOWN_NOLOWERBR,
39478 +/* flags for move-down */
39479 +#define AUFS_MVDOWN_DMSG 1
39480 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39481 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39482 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39483 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39484 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39485 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39486 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39487 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39488 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39489 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39490 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39491 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39493 +/* index for move-down */
39495 + AUFS_MVDOWN_UPPER,
39496 + AUFS_MVDOWN_LOWER,
39497 + AUFS_MVDOWN_NARRAY
39501 + * additional info of move-down
39502 + * number of free blocks and inodes.
39503 + * subset of struct kstatfs, but smaller and always 64bit.
39505 +struct aufs_stfs {
39506 + uint64_t f_blocks;
39507 + uint64_t f_bavail;
39508 + uint64_t f_files;
39509 + uint64_t f_ffree;
39512 +struct aufs_stbr {
39513 + int16_t brid; /* optional input */
39514 + int16_t bindex; /* output */
39515 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39518 +struct aufs_mvdown {
39519 + uint32_t flags; /* input/output */
39520 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39521 + int8_t au_errno; /* output */
39524 +/* ---------------------------------------------------------------------- */
39526 +union aufs_brinfo {
39527 + /* PATH_MAX may differ between kernel-space and user-space */
39528 + char _spacer[4096];
39536 +/* ---------------------------------------------------------------------- */
39538 +#define AuCtlType 'A'
39539 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39540 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39541 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39542 + struct aufs_wbr_fd)
39543 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39544 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39545 + struct aufs_mvdown)
39546 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39547 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39549 +#endif /* __AUFS_TYPE_H__ */
39550 SPDX-License-Identifier: GPL-2.0
39551 aufs6.x-rcN loopback patch
39553 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39554 index 6bd18fb1e53a..a93fab1797e2 100644
39555 --- a/drivers/block/loop.c
39556 +++ b/drivers/block/loop.c
39557 @@ -54,7 +54,7 @@ struct loop_device {
39559 char lo_file_name[LO_NAME_SIZE];
39561 - struct file * lo_backing_file;
39562 + struct file *lo_backing_file, *lo_backing_virt_file;
39563 struct block_device *lo_device;
39565 gfp_t old_gfp_mask;
39566 @@ -506,6 +506,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39570 +static struct file *loop_real_file(struct file *file)
39572 + struct file *f = NULL;
39574 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39575 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39579 static void loop_reread_partitions(struct loop_device *lo)
39582 @@ -563,6 +572,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39584 struct file *file = fget(arg);
39585 struct file *old_file;
39586 + struct file *f, *virt_file = NULL, *old_virt_file;
39590 @@ -586,11 +596,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39591 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39594 + f = loop_real_file(file);
39596 + virt_file = file;
39601 error = loop_validate_file(file, bdev);
39605 old_file = lo->lo_backing_file;
39606 + old_virt_file = lo->lo_backing_virt_file;
39610 @@ -603,6 +621,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39611 blk_mq_freeze_queue(lo->lo_queue);
39612 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39613 lo->lo_backing_file = file;
39614 + lo->lo_backing_virt_file = virt_file;
39615 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39616 mapping_set_gfp_mask(file->f_mapping,
39617 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39618 @@ -625,6 +644,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39622 + if (old_virt_file)
39623 + fput(old_virt_file);
39625 loop_reread_partitions(lo);
39627 @@ -638,6 +659,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39628 loop_global_unlock(lo, is_loop);
39636 @@ -1014,6 +1037,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39637 const struct loop_config *config)
39639 struct file *file = fget(config->fd);
39640 + struct file *f, *virt_file = NULL;
39641 struct inode *inode;
39642 struct address_space *mapping;
39644 @@ -1029,6 +1053,13 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39645 /* This is safe, since we have a reference from open(). */
39646 __module_get(THIS_MODULE);
39648 + f = loop_real_file(file);
39650 + virt_file = file;
39656 * If we don't hold exclusive handle for the device, upgrade to it
39657 * here to avoid changing device under exclusive owner.
39658 @@ -1092,6 +1123,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39659 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39660 lo->lo_device = bdev;
39661 lo->lo_backing_file = file;
39662 + lo->lo_backing_virt_file = virt_file;
39663 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39664 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39666 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39667 bd_abort_claiming(bdev, loop_configure);
39672 /* This is safe: open() is still holding a reference. */
39673 module_put(THIS_MODULE);
39675 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39676 static void __loop_clr_fd(struct loop_device *lo, bool release)
39679 + struct file *virt_filp = lo->lo_backing_virt_file;
39680 gfp_t gfp = lo->old_gfp_mask;
39682 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39683 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39684 spin_lock_irq(&lo->lo_lock);
39685 filp = lo->lo_backing_file;
39686 lo->lo_backing_file = NULL;
39687 + lo->lo_backing_virt_file = NULL;
39688 spin_unlock_irq(&lo->lo_lock);
39690 lo->lo_device = NULL;
39691 @@ -1230,6 +1266,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39692 * fput can take open_mutex which is usually taken before lo_mutex.
39699 static int loop_clr_fd(struct loop_device *lo)
39700 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39701 index fa8a517ffd0c..c18f7bcef81b 100644
39702 --- a/fs/aufs/f_op.c
39703 +++ b/fs/aufs/f_op.c
39704 @@ -311,7 +311,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39705 if (IS_ERR(h_file))
39708 - if (au_test_loopback_kthread()) {
39709 + if (0 && au_test_loopback_kthread()) {
39710 au_warn_loopback(h_file->f_path.dentry->d_sb);
39711 if (file->f_mapping != h_file->f_mapping) {
39712 file->f_mapping = h_file->f_mapping;
39713 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39714 index 58043e31e5f3..e2bfae6f9d59 100644
39715 --- a/fs/aufs/loop.c
39716 +++ b/fs/aufs/loop.c
39717 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39718 symbol_put(loop_backing_file);
39719 au_kfree_try_rcu(au_warn_loopback_array);
39722 +/* ---------------------------------------------------------------------- */
39724 +/* support the loopback block device insude aufs */
39726 +struct file *aufs_real_loop(struct file *file)
39730 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39731 + fi_read_lock(file);
39732 + f = au_hf_top(file);
39733 + fi_read_unlock(file);
39737 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39738 index 03d4908a6c03..34d356e181d5 100644
39739 --- a/fs/aufs/loop.h
39740 +++ b/fs/aufs/loop.h
39741 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39743 int au_loopback_init(void);
39744 void au_loopback_fin(void);
39746 +struct file *aufs_real_loop(struct file *file);
39748 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39750 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39752 AuStubInt0(au_loopback_init, void)
39753 AuStubVoid(au_loopback_fin, void)
39755 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39756 #endif /* BLK_DEV_LOOP */
39758 #endif /* __KERNEL__ */
39759 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39760 index 07d3412e950f..c4a00f620e57 100644
39761 --- a/fs/aufs/super.c
39762 +++ b/fs/aufs/super.c
39763 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39764 .show_options = aufs_show_options,
39765 .statfs = aufs_statfs,
39766 .put_super = aufs_put_super,
39767 - .sync_fs = aufs_sync_fs
39768 + .sync_fs = aufs_sync_fs,
39769 +#ifdef CONFIG_AUFS_BDEV_LOOP
39770 + .real_loop = aufs_real_loop
39774 /* ---------------------------------------------------------------------- */
39775 diff --git a/include/linux/fs.h b/include/linux/fs.h
39776 index b3a73aed62b8..97aa5e94fa31 100644
39777 --- a/include/linux/fs.h
39778 +++ b/include/linux/fs.h
39779 @@ -2188,6 +2188,11 @@ struct super_operations {
39780 long (*free_cached_objects)(struct super_block *,
39781 struct shrink_control *);
39782 void (*shutdown)(struct super_block *sb);
39784 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39786 + struct file *(*real_loop)(struct file *);