1 SPDX-License-Identifier: GPL-2.0
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index 18d034ec7953..3159bcb16918 100644
8 @@ -316,6 +316,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 e513aaee0603..acdea5771285 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
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index 4cc6bf79fdd8..5578e44ad7e2 100644
32 @@ -3310,6 +3310,19 @@ F: include/uapi/linux/audit.h
36 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
37 +M: "J. R. Okajima" <hooanon05g@gmail.com>
38 +L: aufs-users@lists.sourceforge.net (members only)
39 +L: linux-unionfs@vger.kernel.org
41 +W: http://aufs.sourceforge.net
42 +T: git://github.com/sfjro/aufs4-linux.git
43 +F: Documentation/ABI/testing/debugfs-aufs
44 +F: Documentation/ABI/testing/sysfs-aufs
45 +F: Documentation/filesystems/aufs/
47 +F: include/uapi/linux/aufs_type.h
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 637c5bda2387..cbefd23beb44 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -645,6 +645,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index 52e6d5fdab6b..519321f32f95 100644
85 @@ -1345,7 +1345,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index b622be119706..9ea58b7bb580 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -64,6 +64,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/namespace.c b/fs/namespace.c
117 index e157efc54023..6c57487f126b 100644
120 @@ -872,6 +872,12 @@ static inline int check_mnt(struct mount *mnt)
121 return mnt->mnt_ns == current->nsproxy->mnt_ns;
124 +/* for aufs, CONFIG_AUFS_BR_FUSE */
125 +int is_current_mnt_ns(struct vfsmount *mnt)
127 + return check_mnt(real_mount(mnt));
131 * vfsmount lock must be held for write
133 diff --git a/fs/splice.c b/fs/splice.c
134 index 3e2a31e1ce6a..a724fe9ccb80 100644
137 @@ -928,8 +928,8 @@ static int warn_unsupported(struct file *file, const char *op)
139 * Attempt to initiate a splice from pipe to file.
141 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
142 - loff_t *ppos, size_t len, unsigned int flags)
143 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
144 + loff_t *ppos, size_t len, unsigned int flags)
146 if (unlikely(!out->f_op->splice_write))
147 return warn_unsupported(out, "write");
148 diff --git a/include/linux/fs.h b/include/linux/fs.h
149 index 562f2623c9c9..5a2db7b8eca5 100644
150 --- a/include/linux/fs.h
151 +++ b/include/linux/fs.h
152 @@ -1068,6 +1068,7 @@ extern void fasync_free(struct fasync_struct *);
153 /* can be called from interrupts */
154 extern void kill_fasync(struct fasync_struct **, int, int);
156 +extern int setfl(int fd, struct file *filp, unsigned long arg);
157 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
158 extern int f_setown(struct file *filp, unsigned long arg, int force);
159 extern void f_delown(struct file *filp);
160 @@ -1794,6 +1795,7 @@ struct file_operations {
161 int (*lock) (struct file *, int, struct file_lock *);
162 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
163 int (*check_flags)(int);
164 + int (*setfl)(struct file *, unsigned long);
165 int (*flock) (struct file *, int, struct file_lock *);
166 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
167 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
168 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
169 index 310f85903c91..46ff52c1a522 100644
170 --- a/include/linux/lockdep.h
171 +++ b/include/linux/lockdep.h
172 @@ -249,6 +249,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
173 return lock->key == key;
176 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
181 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
182 index 8f882f5881e8..6b9808f09843 100644
183 --- a/include/linux/mnt_namespace.h
184 +++ b/include/linux/mnt_namespace.h
185 @@ -7,12 +7,15 @@ struct mnt_namespace;
187 struct user_namespace;
191 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
192 struct user_namespace *, struct fs_struct *);
193 extern void put_mnt_ns(struct mnt_namespace *ns);
194 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
196 +extern int is_current_mnt_ns(struct vfsmount *mnt);
198 extern const struct file_operations proc_mounts_operations;
199 extern const struct file_operations proc_mountinfo_operations;
200 extern const struct file_operations proc_mountstats_operations;
201 diff --git a/include/linux/splice.h b/include/linux/splice.h
202 index 6c461573434d..7416cf375ad1 100644
203 --- a/include/linux/splice.h
204 +++ b/include/linux/splice.h
205 @@ -99,4 +99,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
207 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
208 extern const struct pipe_buf_operations default_pipe_buf_ops;
210 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
211 + loff_t *ppos, size_t len, unsigned int flags);
212 +extern long do_splice_to(struct file *in, loff_t *ppos,
213 + struct pipe_inode_info *pipe, size_t len,
214 + unsigned int flags);
216 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
217 index 111607d91489..22af30abc781 100644
218 --- a/kernel/locking/lockdep.c
219 +++ b/kernel/locking/lockdep.c
220 @@ -218,7 +218,7 @@ unsigned long max_lock_class_idx;
221 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
222 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
224 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
225 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
227 unsigned int class_idx = hlock->class_idx;
229 @@ -239,6 +239,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
231 return lock_classes + class_idx;
233 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
235 #ifdef CONFIG_LOCK_STAT
236 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
237 SPDX-License-Identifier: GPL-2.0
240 diff --git a/fs/proc/base.c b/fs/proc/base.c
241 index 9df3f4839662..102a56aebeef 100644
244 @@ -2218,7 +2218,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
246 vma = find_exact_vma(mm, vm_start, vm_end);
247 if (vma && vma->vm_file) {
248 - *path = vma->vm_file->f_path;
249 + *path = vma_pr_or_file(vma)->f_path;
253 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
254 index 4d3493579458..42edd9a42c78 100644
255 --- a/fs/proc/nommu.c
256 +++ b/fs/proc/nommu.c
257 @@ -39,7 +39,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
258 file = region->vm_file;
261 - struct inode *inode = file_inode(region->vm_file);
262 + struct inode *inode;
264 + file = vmr_pr_or_file(region);
265 + inode = file_inode(file);
266 dev = inode->i_sb->s_dev;
269 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
270 index fafff1bd34cd..4387f43addcd 100644
271 --- a/fs/proc/task_mmu.c
272 +++ b/fs/proc/task_mmu.c
273 @@ -285,7 +285,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
274 const char *name = NULL;
277 - struct inode *inode = file_inode(vma->vm_file);
278 + struct inode *inode;
280 + file = vma_pr_or_file(vma);
281 + inode = file_inode(file);
282 dev = inode->i_sb->s_dev;
284 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
285 @@ -1950,7 +1953,7 @@ static int show_numa_map(struct seq_file *m, void *v)
286 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
287 struct vm_area_struct *vma = v;
288 struct numa_maps *md = &numa_priv->md;
289 - struct file *file = vma->vm_file;
290 + struct file *file = vma_pr_or_file(vma);
291 struct mm_struct *mm = vma->vm_mm;
292 struct mempolicy *pol;
294 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
295 index 2c8b62265981..9f65138246a8 100644
296 --- a/fs/proc/task_nommu.c
297 +++ b/fs/proc/task_nommu.c
298 @@ -150,7 +150,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
302 - struct inode *inode = file_inode(vma->vm_file);
303 + struct inode *inode;
305 + file = vma_pr_or_file(vma);
306 + inode = file_inode(file);
307 dev = inode->i_sb->s_dev;
309 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
310 diff --git a/include/linux/mm.h b/include/linux/mm.h
311 index 34f9dba17c1a..0f01f02a3112 100644
312 --- a/include/linux/mm.h
313 +++ b/include/linux/mm.h
314 @@ -2387,6 +2387,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
315 static inline struct vm_area_struct *vma_lookup(struct mm_struct *mm,
318 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
319 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
320 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
322 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
323 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
325 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
327 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
329 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
330 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
333 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
334 +extern void vmr_do_fput(struct vm_region *, const char[], int);
336 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
338 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
339 +#endif /* !CONFIG_MMU */
343 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
344 +#define vma_pr_or_file(vma) (vma)->vm_file
345 +#define vma_get_file(vma) get_file((vma)->vm_file)
346 +#define vma_fput(vma) fput((vma)->vm_file)
349 +#define vmr_pr_or_file(region) (region)->vm_file
350 +#define vmr_fput(region) fput((region)->vm_file)
351 +#endif /* !CONFIG_MMU */
353 +#endif /* CONFIG_AUFS_FS */
355 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
356 void *buf, int len, unsigned int gup_flags);
357 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
358 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
359 index 7d30dc4ff0ff..5a712268b2d7 100644
360 --- a/include/linux/mm_types.h
361 +++ b/include/linux/mm_types.h
362 @@ -449,6 +449,9 @@ struct vm_region {
363 unsigned long vm_top; /* region allocated to here */
364 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
365 struct file *vm_file; /* the backing file or NULL */
366 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
367 + struct file *vm_prfile; /* the virtual backing file or NULL */
370 int vm_usage; /* region usage count (access under nommu_region_sem) */
371 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
372 @@ -562,6 +565,9 @@ struct vm_area_struct {
373 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
375 struct file * vm_file; /* File we map to (can be NULL). */
376 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
377 + struct file *vm_prfile; /* shadow of vm_file */
379 void * vm_private_data; /* was vm_pte (shared mem) */
381 #ifdef CONFIG_ANON_VMA_NAME
382 diff --git a/kernel/fork.c b/kernel/fork.c
383 index d2e12b6d2b18..39da83472c1d 100644
386 @@ -731,7 +731,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
388 struct address_space *mapping = file->f_mapping;
392 i_mmap_lock_write(mapping);
393 if (tmp->vm_flags & VM_SHARED)
394 mapping_allow_writable(mapping);
395 diff --git a/mm/Makefile b/mm/Makefile
396 index 678530a07326..ce3cbfef4a61 100644
399 @@ -139,3 +139,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
400 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
401 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
402 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
404 diff --git a/mm/filemap.c b/mm/filemap.c
405 index 9e44a49bbd74..334425b2903b 100644
408 @@ -3580,7 +3580,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
409 vm_fault_t ret = VM_FAULT_LOCKED;
411 sb_start_pagefault(mapping->host->i_sb);
412 - file_update_time(vmf->vma->vm_file);
413 + vma_file_update_time(vmf->vma);
415 if (folio->mapping != mapping) {
417 diff --git a/mm/mmap.c b/mm/mmap.c
418 index 3937479d0e07..db30d8a8cea3 100644
421 @@ -140,7 +140,7 @@ static void remove_vma(struct vm_area_struct *vma, bool unreachable)
422 if (vma->vm_ops && vma->vm_ops->close)
423 vma->vm_ops->close(vma);
425 - fput(vma->vm_file);
427 mpol_put(vma_policy(vma));
430 @@ -575,7 +575,7 @@ static inline void vma_complete(struct vma_prepare *vp,
432 uprobe_munmap(vp->remove, vp->remove->vm_start,
437 if (vp->remove->anon_vma)
438 anon_vma_merge(vp->vma, vp->remove);
439 @@ -2365,7 +2365,7 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
443 - get_file(new->vm_file);
446 if (new->vm_ops && new->vm_ops->open)
447 new->vm_ops->open(new);
448 @@ -2778,7 +2778,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
449 * and cause general protection fault
452 - fput(vma->vm_file);
456 /* Update vm_flags to pick up the change. */
457 @@ -2875,7 +2875,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
459 if (file || vma->vm_file) {
461 - fput(vma->vm_file);
465 /* Undo any partial mapping done by a device driver. */
466 @@ -2936,6 +2936,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
467 unsigned long populate = 0;
468 unsigned long ret = -EINVAL;
470 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
471 + struct file *prfile;
474 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
475 current->comm, current->pid);
476 @@ -2994,10 +2997,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
477 if (vma->vm_flags & VM_LOCKED)
480 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
482 + file = vma->vm_file;
483 + prfile = vma->vm_prfile;
484 + ret = do_mmap(vma->vm_file, start, size,
485 + prot, flags, pgoff, &populate, NULL);
486 + if (!IS_ERR_VALUE(ret) && file && prfile) {
487 + struct vm_area_struct *new_vma;
489 + new_vma = find_vma(mm, ret);
490 + if (!new_vma->vm_prfile)
491 + new_vma->vm_prfile = prfile;
496 + * two fput()s instead of vma_fput(vma),
497 + * coz vma may not be available anymore.
503 file = get_file(vma->vm_file);
504 ret = do_mmap(vma->vm_file, start, size,
505 prot, flags, pgoff, &populate, NULL);
507 +#endif /* CONFIG_AUFS_FS */
509 mmap_write_unlock(mm);
511 @@ -3342,7 +3369,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
512 if (anon_vma_clone(new_vma, vma))
513 goto out_free_mempol;
514 if (new_vma->vm_file)
515 - get_file(new_vma->vm_file);
516 + vma_get_file(new_vma);
517 if (new_vma->vm_ops && new_vma->vm_ops->open)
518 new_vma->vm_ops->open(new_vma);
519 vma_start_write(new_vma);
520 @@ -3358,7 +3385,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
521 new_vma->vm_ops->close(new_vma);
523 if (new_vma->vm_file)
524 - fput(new_vma->vm_file);
527 unlink_anon_vmas(new_vma);
529 diff --git a/mm/nommu.c b/mm/nommu.c
530 index c072a660ec2c..62e67267f79d 100644
533 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
534 up_write(&nommu_region_sem);
537 - fput(region->vm_file);
540 /* IO memory and memory shared directly out of the pagecache
541 * from ramfs/tmpfs mustn't be released here */
542 @@ -602,7 +602,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
543 if (vma->vm_ops && vma->vm_ops->close)
544 vma->vm_ops->close(vma);
546 - fput(vma->vm_file);
548 put_nommu_region(vma->vm_region);
551 @@ -1137,7 +1137,7 @@ unsigned long do_mmap(struct file *file,
552 goto error_just_free;
555 - fput(region->vm_file);
557 kmem_cache_free(vm_region_jar, region);
560 @@ -1219,10 +1219,10 @@ unsigned long do_mmap(struct file *file,
564 - fput(region->vm_file);
566 kmem_cache_free(vm_region_jar, region);
568 - fput(vma->vm_file);
573 diff --git a/mm/prfile.c b/mm/prfile.c
575 index 000000000000..8f820a235364
579 +// SPDX-License-Identifier: GPL-2.0
581 + * Mainly for aufs which mmap(2) different file and wants to print different
582 + * path in /proc/PID/maps.
583 + * Call these functions via macros defined in linux/mm.h.
585 + * See Documentation/filesystems/aufs/design/06mmap.txt
587 + * Copyright (c) 2014-2022 Junjro R. Okajima
588 + * Copyright (c) 2014 Ian Campbell
591 +#include <linux/mm.h>
592 +#include <linux/file.h>
593 +#include <linux/fs.h>
595 +/* #define PRFILE_TRACE */
596 +static inline void prfile_trace(struct file *f, struct file *pr,
597 + const char func[], int line, const char func2[])
601 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
605 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
608 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
610 + prfile_trace(f, pr, func, line, __func__);
611 + file_update_time(f);
613 + file_update_time(pr);
616 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
619 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
621 + prfile_trace(f, pr, func, line, __func__);
622 + return (f && pr) ? pr : f;
625 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
627 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
629 + prfile_trace(f, pr, func, line, __func__);
635 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
637 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
639 + prfile_trace(f, pr, func, line, __func__);
646 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
649 + struct file *f = region->vm_file, *pr = region->vm_prfile;
651 + prfile_trace(f, pr, func, line, __func__);
652 + return (f && pr) ? pr : f;
655 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
657 + struct file *f = region->vm_file, *pr = region->vm_prfile;
659 + prfile_trace(f, pr, func, line, __func__);
664 +#endif /* !CONFIG_MMU */
665 SPDX-License-Identifier: GPL-2.0
666 aufs6.5 standalone patch
668 diff --git a/fs/dcache.c b/fs/dcache.c
669 index 519321f32f95..267e0c65914a 100644
672 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
676 +EXPORT_SYMBOL_GPL(d_walk);
679 struct vfsmount *mnt;
680 @@ -3052,6 +3053,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
682 write_sequnlock(&rename_lock);
684 +EXPORT_SYMBOL_GPL(d_exchange);
687 * d_ancestor - search for an ancestor
688 diff --git a/fs/exec.c b/fs/exec.c
689 index 1a827d55ba94..d7b12f1e7af2 100644
692 @@ -112,6 +112,7 @@ bool path_noexec(const struct path *path)
693 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
694 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
696 +EXPORT_SYMBOL_GPL(path_noexec);
700 diff --git a/fs/fcntl.c b/fs/fcntl.c
701 index 9ea58b7bb580..99fef189bcd6 100644
704 @@ -87,6 +87,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
708 +EXPORT_SYMBOL_GPL(setfl);
710 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
712 diff --git a/fs/file_table.c b/fs/file_table.c
713 index fc7d677ff5ad..a2fbedb58c0a 100644
714 --- a/fs/file_table.c
715 +++ b/fs/file_table.c
716 @@ -225,6 +225,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
718 return ERR_PTR(-ENFILE);
720 +EXPORT_SYMBOL_GPL(alloc_empty_file);
723 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
724 diff --git a/fs/namespace.c b/fs/namespace.c
725 index 6c57487f126b..16be9ac1c734 100644
728 @@ -466,6 +466,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
729 mnt_dec_writers(real_mount(mnt));
732 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
735 * mnt_drop_write - give up write access to a mount
736 @@ -877,6 +878,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
738 return check_mnt(real_mount(mnt));
740 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
743 * vfsmount lock must be held for write
744 @@ -2152,6 +2154,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
748 +EXPORT_SYMBOL_GPL(iterate_mounts);
750 static void lock_mnt_tree(struct mount *mnt)
752 diff --git a/fs/notify/group.c b/fs/notify/group.c
753 index 1de6631a3925..3008eb37a18d 100644
754 --- a/fs/notify/group.c
755 +++ b/fs/notify/group.c
756 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
758 refcount_inc(&group->refcnt);
760 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
763 * Drop a reference to a group. Free it if it's through.
764 diff --git a/fs/open.c b/fs/open.c
765 index e6ead0f19964..1f4deda436ec 100644
768 @@ -67,6 +67,7 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
769 inode_unlock(dentry->d_inode);
772 +EXPORT_SYMBOL_GPL(do_truncate);
774 long vfs_truncate(const struct path *path, loff_t length)
776 diff --git a/fs/read_write.c b/fs/read_write.c
777 index b07de77ef126..e07fadb4afe2 100644
778 --- a/fs/read_write.c
779 +++ b/fs/read_write.c
780 @@ -477,6 +477,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
784 +EXPORT_SYMBOL_GPL(vfs_read);
786 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
788 @@ -592,6 +593,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
789 file_end_write(file);
792 +EXPORT_SYMBOL_GPL(vfs_write);
794 /* file_ppos returns &file->f_pos or NULL if file is stream */
795 static inline loff_t *file_ppos(struct file *file)
796 diff --git a/fs/splice.c b/fs/splice.c
797 index a724fe9ccb80..ebb2c4ceb598 100644
800 @@ -935,6 +935,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
801 return warn_unsupported(out, "write");
802 return out->f_op->splice_write(pipe, out, ppos, len, flags);
804 +EXPORT_SYMBOL_GPL(do_splice_from);
807 * Indicate to the caller that there was a premature EOF when reading from the
808 diff --git a/fs/xattr.c b/fs/xattr.c
809 index e7bbb7f57557..edb0190da4d5 100644
812 @@ -406,6 +406,7 @@ vfs_getxattr_alloc(struct mnt_idmap *idmap, struct dentry *dentry,
813 *xattr_value = value;
816 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
819 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
820 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
821 index 22af30abc781..eaf4e02bcb4d 100644
822 --- a/kernel/locking/lockdep.c
823 +++ b/kernel/locking/lockdep.c
824 @@ -239,6 +239,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
826 return lock_classes + class_idx;
828 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
829 #define hlock_class(hlock) lockdep_hlock_class(hlock)
831 #ifdef CONFIG_LOCK_STAT
832 diff --git a/kernel/task_work.c b/kernel/task_work.c
833 index 065e1ef8fc8d..c623c6f0c645 100644
834 --- a/kernel/task_work.c
835 +++ b/kernel/task_work.c
836 @@ -182,3 +182,4 @@ void task_work_run(void)
840 +EXPORT_SYMBOL_GPL(task_work_run);
841 diff --git a/security/security.c b/security/security.c
842 index b720424ca37d..635ee0582e05 100644
843 --- a/security/security.c
844 +++ b/security/security.c
845 @@ -1711,6 +1711,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
847 return call_int_hook(path_rmdir, 0, dir, dentry);
849 +EXPORT_SYMBOL_GPL(security_path_rmdir);
852 * security_path_unlink() - Check if removing a hard link is allowed
853 @@ -1746,6 +1747,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
855 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
857 +EXPORT_SYMBOL_GPL(security_path_symlink);
860 * security_path_link - Check if creating a hard link is allowed
861 @@ -1764,6 +1766,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
863 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
865 +EXPORT_SYMBOL_GPL(security_path_link);
868 * security_path_rename() - Check if renaming a file is allowed
869 @@ -1825,6 +1828,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
871 return call_int_hook(path_chmod, 0, path, mode);
873 +EXPORT_SYMBOL_GPL(security_path_chmod);
876 * security_path_chown() - Check if changing the file's owner/group is allowed
877 @@ -1842,6 +1846,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
879 return call_int_hook(path_chown, 0, path, uid, gid);
881 +EXPORT_SYMBOL_GPL(security_path_chown);
884 * security_path_chroot() - Check if changing the root directory is allowed
885 @@ -2071,6 +2076,7 @@ int security_inode_permission(struct inode *inode, int mask)
887 return call_int_hook(inode_permission, 0, inode, mask);
889 +EXPORT_SYMBOL_GPL(security_inode_permission);
892 * security_inode_setattr() - Check if setting file attributes is allowed
893 @@ -2549,6 +2555,7 @@ int security_file_permission(struct file *file, int mask)
895 return fsnotify_perm(file, mask);
897 +EXPORT_SYMBOL_GPL(security_file_permission);
900 * security_file_alloc() - Allocate and init a file's LSM blob
901 @@ -2815,6 +2822,7 @@ int security_file_truncate(struct file *file)
903 return call_int_hook(file_truncate, 0, file);
905 +EXPORT_SYMBOL_GPL(security_file_truncate);
908 * security_task_alloc() - Allocate a task's LSM blob
909 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
910 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
911 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-11-05 23:02:18.955889283 +0100
913 +What: /debug/aufs/si_<id>/
915 +Contact: J. R. Okajima <hooanon05g@gmail.com>
917 + Under /debug/aufs, a directory named si_<id> is created
918 + per aufs mount, where <id> is a unique id generated
921 +What: /debug/aufs/si_<id>/plink
923 +Contact: J. R. Okajima <hooanon05g@gmail.com>
925 + It has three lines and shows the information about the
926 + pseudo-link. The first line is a single number
927 + representing a number of buckets. The second line is a
928 + number of pseudo-links per buckets (separated by a
929 + blank). The last line is a single number representing a
930 + total number of psedo-links.
931 + When the aufs mount option 'noplink' is specified, it
932 + will show "1\n0\n0\n".
934 +What: /debug/aufs/si_<id>/xib
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + It shows the consumed blocks by xib (External Inode Number
939 + Bitmap), its block size and file size.
940 + When the aufs mount option 'noxino' is specified, it
941 + will be empty. About XINO files, see the aufs manual.
943 +What: /debug/aufs/si_<id>/xi<branch-index>
945 +Contact: J. R. Okajima <hooanon05g@gmail.com>
947 + It shows the consumed blocks by xino (External Inode Number
948 + Translation Table), its link count, block size and file
950 + Due to the file size limit, there may exist multiple
951 + xino files per branch. In this case, "-N" is added to
952 + the filename and it corresponds to the index of the
953 + internal xino array. "-0" is omitted.
954 + When the aufs mount option 'noxino' is specified, Those
955 + entries won't exist. About XINO files, see the aufs
958 +What: /debug/aufs/si_<id>/xigen
960 +Contact: J. R. Okajima <hooanon05g@gmail.com>
962 + It shows the consumed blocks by xigen (External Inode
963 + Generation Table), its block size and file size.
964 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
966 + When the aufs mount option 'noxino' is specified, it
967 + will be empty. About XINO files, see the aufs manual.
968 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
969 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
970 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-11-05 23:02:18.955889283 +0100
972 +What: /sys/fs/aufs/si_<id>/
974 +Contact: J. R. Okajima <hooanon05g@gmail.com>
976 + Under /sys/fs/aufs, a directory named si_<id> is created
977 + per aufs mount, where <id> is a unique id generated
980 +What: /sys/fs/aufs/si_<id>/br<idx>
982 +Contact: J. R. Okajima <hooanon05g@gmail.com>
984 + It shows the abolute path of a member directory (which
985 + is called branch) in aufs, and its permission.
987 +What: /sys/fs/aufs/si_<id>/brid<idx>
989 +Contact: J. R. Okajima <hooanon05g@gmail.com>
991 + It shows the id of a member directory (which is called
994 +What: /sys/fs/aufs/si_<id>/xi_path
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It shows the abolute path of XINO (External Inode Number
999 + Bitmap, Translation Table and Generation Table) file
1000 + even if it is the default path.
1001 + When the aufs mount option 'noxino' is specified, it
1002 + will be empty. About XINO files, see the aufs manual.
1003 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1004 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1005 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-11-05 23:02:18.955889283 +0100
1008 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1010 +# This program is free software; you can redistribute it and/or modify
1011 +# it under the terms of the GNU General Public License as published by
1012 +# the Free Software Foundation; either version 2 of the License, or
1013 +# (at your option) any later version.
1015 +# This program is distributed in the hope that it will be useful,
1016 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1017 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1018 +# GNU General Public License for more details.
1020 +# You should have received a copy of the GNU General Public License
1021 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1024 +----------------------------------------
1026 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1027 +1. abbrev. for "advanced multi-layered unification filesystem".
1028 +2. abbrev. for "another unionfs".
1029 +3. abbrev. for "auf das" in German which means "on the" in English.
1030 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1031 + But "Filesystem aufs Filesystem" is hard to understand.
1032 +4. abbrev. for "African Urban Fashion Show".
1034 +AUFS is a filesystem with features:
1035 +- multi layered stackable unification filesystem, the member directory
1036 + is called as a branch.
1037 +- branch permission and attribute, 'readonly', 'real-readonly',
1038 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1040 +- internal "file copy-on-write".
1041 +- logical deletion, whiteout.
1042 +- dynamic branch manipulation, adding, deleting and changing permission.
1043 +- allow bypassing aufs, user's direct branch access.
1044 +- external inode number translation table and bitmap which maintains the
1045 + persistent aufs inode number.
1046 +- seekable directory, including NFS readdir.
1047 +- file mapping, mmap and sharing pages.
1048 +- pseudo-link, hardlink over branches.
1049 +- loopback mounted filesystem as a branch.
1050 +- several policies to select one among multiple writable branches.
1051 +- revert a single systemcall when an error occurs in aufs.
1055 +Multi Layered Stackable Unification Filesystem
1056 +----------------------------------------------------------------------
1057 +Most people already knows what it is.
1058 +It is a filesystem which unifies several directories and provides a
1059 +merged single directory. When users access a file, the access will be
1060 +passed/re-directed/converted (sorry, I am not sure which English word is
1061 +correct) to the real file on the member filesystem. The member
1062 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1063 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1064 +readonly branch is handled by creating 'whiteout' on the upper writable
1067 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1068 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1069 +different approaches to implement the merged-view.
1070 +The former tries putting it into VFS, and the latter implements as a
1071 +separate filesystem.
1072 +(If I misunderstand about these implementations, please let me know and
1073 +I shall correct it. Because it is a long time ago when I read their
1074 +source files last time).
1076 +UnionMount's approach will be able to small, but may be hard to share
1077 +branches between several UnionMount since the whiteout in it is
1078 +implemented in the inode on branch filesystem and always
1079 +shared. According to Bharata's post, readdir does not seems to be
1081 +There are several missing features known in this implementations such as
1082 +- for users, the inode number may change silently. eg. copy-up.
1083 +- link(2) may break by copy-up.
1084 +- read(2) may get an obsoleted filedata (fstat(2) too).
1085 +- fcntl(F_SETLK) may be broken by copy-up.
1086 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1089 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1090 +merged into mainline. This is another implementation of UnionMount as a
1091 +separated filesystem. All the limitations and known problems which
1092 +UnionMount are equally inherited to "overlay" filesystem.
1094 +Unionfs has a longer history. When I started implementing a stackable
1095 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1096 +inode, dentry and file objects and they have an array pointing lower
1097 +same kind objects. After contributing many patches for Unionfs, I
1098 +re-started my project AUFS (Jun 2006).
1100 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1101 +implemented my own ideas, approaches and enhancements and it became
1102 +totally different one.
1104 +Comparing DM snapshot and fs based implementation
1105 +- the number of bytes to be copied between devices is much smaller.
1106 +- the type of filesystem must be one and only.
1107 +- the fs must be writable, no readonly fs, even for the lower original
1108 + device. so the compression fs will not be usable. but if we use
1109 + loopback mount, we may address this issue.
1111 + mount /cdrom/squashfs.img /sq
1112 + losetup /sq/ext2.img
1113 + losetup /somewhere/cow
1114 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1115 +- it will be difficult (or needs more operations) to extract the
1116 + difference between the original device and COW.
1117 +- DM snapshot-merge may help a lot when users try merging. in the
1118 + fs-layer union, users will use rsync(1).
1120 +You may want to read my old paper "Filesystems in LiveCD"
1121 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1124 +Several characters/aspects/persona of aufs
1125 +----------------------------------------------------------------------
1127 +Aufs has several characters, aspects or persona.
1128 +1. a filesystem, callee of VFS helper
1129 +2. sub-VFS, caller of VFS helper for branches
1130 +3. a virtual filesystem which maintains persistent inode number
1131 +4. reader/writer of files on branches such like an application
1133 +1. Callee of VFS Helper
1134 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1135 +unlink(2) from an application reaches sys_unlink() kernel function and
1136 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1137 +calls filesystem specific unlink operation. Actually aufs implements the
1138 +unlink operation but it behaves like a redirector.
1140 +2. Caller of VFS Helper for Branches
1141 +aufs_unlink() passes the unlink request to the branch filesystem as if
1142 +it were called from VFS. So the called unlink operation of the branch
1143 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1144 +every necessary pre/post operation for the branch filesystem.
1145 +- acquire the lock for the parent dir on a branch
1146 +- lookup in a branch
1147 +- revalidate dentry on a branch
1148 +- mnt_want_write() for a branch
1149 +- vfs_unlink() for a branch
1150 +- mnt_drop_write() for a branch
1151 +- release the lock on a branch
1153 +3. Persistent Inode Number
1154 +One of the most important issue for a filesystem is to maintain inode
1155 +numbers. This is particularly important to support exporting a
1156 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1157 +backend block device for its own. But some storage is necessary to
1158 +keep and maintain the inode numbers. It may be a large space and may not
1159 +suit to keep in memory. Aufs rents some space from its first writable
1160 +branch filesystem (by default) and creates file(s) on it. These files
1161 +are created by aufs internally and removed soon (currently) keeping
1163 +Note: Because these files are removed, they are totally gone after
1164 + unmounting aufs. It means the inode numbers are not persistent
1165 + across unmount or reboot. I have a plan to make them really
1166 + persistent which will be important for aufs on NFS server.
1168 +4. Read/Write Files Internally (copy-on-write)
1169 +Because a branch can be readonly, when you write a file on it, aufs will
1170 +"copy-up" it to the upper writable branch internally. And then write the
1171 +originally requested thing to the file. Generally kernel doesn't
1172 +open/read/write file actively. In aufs, even a single write may cause a
1173 +internal "file copy". This behaviour is very similar to cp(1) command.
1175 +Some people may think it is better to pass such work to user space
1176 +helper, instead of doing in kernel space. Actually I am still thinking
1177 +about it. But currently I have implemented it in kernel space.
1178 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1179 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1180 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-11-05 23:02:18.955889283 +0100
1183 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1185 +# This program is free software; you can redistribute it and/or modify
1186 +# it under the terms of the GNU General Public License as published by
1187 +# the Free Software Foundation; either version 2 of the License, or
1188 +# (at your option) any later version.
1190 +# This program is distributed in the hope that it will be useful,
1191 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1192 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1193 +# GNU General Public License for more details.
1195 +# You should have received a copy of the GNU General Public License
1196 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1198 +Basic Aufs Internal Structure
1200 +Superblock/Inode/Dentry/File Objects
1201 +----------------------------------------------------------------------
1202 +As like an ordinary filesystem, aufs has its own
1203 +superblock/inode/dentry/file objects. All these objects have a
1204 +dynamically allocated array and store the same kind of pointers to the
1205 +lower filesystem, branch.
1206 +For example, when you build a union with one readwrite branch and one
1207 +readonly, mounted /au, /rw and /ro respectively.
1209 +- /ro/fileA exists but /rw/fileA
1211 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1212 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1213 +- [0] = NULL (because /rw/fileA doesn't exist)
1216 +This style of an array is essentially same to the aufs
1217 +superblock/inode/dentry/file objects.
1219 +Because aufs supports manipulating branches, ie. add/delete/change
1220 +branches dynamically, these objects has its own generation. When
1221 +branches are changed, the generation in aufs superblock is
1222 +incremented. And a generation in other object are compared when it is
1223 +accessed. When a generation in other objects are obsoleted, aufs
1224 +refreshes the internal array.
1228 +----------------------------------------------------------------------
1229 +Additionally aufs superblock has some data for policies to select one
1230 +among multiple writable branches, XIB files, pseudo-links and kobject.
1231 +See below in detail.
1232 +About the policies which supports copy-down a directory, see
1233 +wbr_policy.txt too.
1236 +Branch and XINO(External Inode Number Translation Table)
1237 +----------------------------------------------------------------------
1238 +Every branch has its own xino (external inode number translation table)
1239 +file. The xino file is created and unlinked by aufs internally. When two
1240 +members of a union exist on the same filesystem, they share the single
1242 +The struct of a xino file is simple, just a sequence of aufs inode
1243 +numbers which is indexed by the lower inode number.
1244 +In the above sample, assume the inode number of /ro/fileA is i111 and
1245 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1246 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1248 +When the inode numbers are not contiguous, the xino file will be sparse
1249 +which has a hole in it and doesn't consume as much disk space as it
1250 +might appear. If your branch filesystem consumes disk space for such
1251 +holes, then you should specify 'xino=' option at mounting aufs.
1253 +Aufs has a mount option to free the disk blocks for such holes in XINO
1254 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1255 +meet a problem of disk shortage due to XINO files, then you should try
1256 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1257 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1258 +the holes in XINO files.
1260 +Also a writable branch has three kinds of "whiteout bases". All these
1261 +are existed when the branch is joined to aufs, and their names are
1262 +whiteout-ed doubly, so that users will never see their names in aufs
1264 +1. a regular file which will be hardlinked to all whiteouts.
1265 +2. a directory to store a pseudo-link.
1266 +3. a directory to store an "orphan"-ed file temporary.
1269 + When you remove a file on a readonly branch, aufs handles it as a
1270 + logical deletion and creates a whiteout on the upper writable branch
1271 + as a hardlink of this file in order not to consume inode on the
1274 + See below, Pseudo-link.
1276 + When "fileC" exists on the lower readonly branch only and it is
1277 + opened and removed with its parent dir, and then user writes
1278 + something into it, then aufs copies-up fileC to this
1279 + directory. Because there is no other dir to store fileC. After
1280 + creating a file under this dir, the file is unlinked.
1282 +Because aufs supports manipulating branches, ie. add/delete/change
1283 +dynamically, a branch has its own id. When the branch order changes,
1284 +aufs finds the new index by searching the branch id.
1288 +----------------------------------------------------------------------
1289 +Assume "fileA" exists on the lower readonly branch only and it is
1290 +hardlinked to "fileB" on the branch. When you write something to fileA,
1291 +aufs copies-up it to the upper writable branch. Additionally aufs
1292 +creates a hardlink under the Pseudo-link Directory of the writable
1293 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1294 +simple list. If fileB is read after unlinking fileA, aufs returns
1295 +filedata from the pseudo-link instead of the lower readonly
1296 +branch. Because the pseudo-link is based upon the inode, to keep the
1297 +inode number by xino (see above) is essentially necessary.
1299 +All the hardlinks under the Pseudo-link Directory of the writable branch
1300 +should be restored in a proper location later. Aufs provides a utility
1301 +to do this. The userspace helpers executed at remounting and unmounting
1303 +During this utility is running, it puts aufs into the pseudo-link
1304 +maintenance mode. In this mode, only the process which began the
1305 +maintenance mode (and its child processes) is allowed to operate in
1306 +aufs. Some other processes which are not related to the pseudo-link will
1307 +be allowed to run too, but the rest have to return an error or wait
1308 +until the maintenance mode ends. If a process already acquires an inode
1309 +mutex (in VFS), it has to return an error.
1312 +XIB(external inode number bitmap)
1313 +----------------------------------------------------------------------
1314 +Addition to the xino file per a branch, aufs has an external inode number
1315 +bitmap in a superblock object. It is also an internal file such like a
1317 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1319 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1321 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1322 +reduce the number of consumed disk blocks for these files.
1325 +Virtual or Vertical Dir, and Readdir in Userspace
1326 +----------------------------------------------------------------------
1327 +In order to support multiple layers (branches), aufs readdir operation
1328 +constructs a virtual dir block on memory. For readdir, aufs calls
1329 +vfs_readdir() internally for each dir on branches, merges their entries
1330 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1331 +object. So the file object has its entry list until it is closed. The
1332 +entry list will be updated when the file position is zero and becomes
1333 +obsoleted. This decision is made in aufs automatically.
1335 +The dynamically allocated memory block for the name of entries has a
1336 +unit of 512 bytes (by default) and stores the names contiguously (no
1337 +padding). Another block for each entry is handled by kmem_cache too.
1338 +During building dir blocks, aufs creates hash list and judging whether
1339 +the entry is whiteouted by its upper branch or already listed.
1340 +The merged result is cached in the corresponding inode object and
1341 +maintained by a customizable life-time option.
1343 +Some people may call it can be a security hole or invite DoS attack
1344 +since the opened and once readdir-ed dir (file object) holds its entry
1345 +list and becomes a pressure for system memory. But I'd say it is similar
1346 +to files under /proc or /sys. The virtual files in them also holds a
1347 +memory page (generally) while they are opened. When an idea to reduce
1348 +memory for them is introduced, it will be applied to aufs too.
1349 +For those who really hate this situation, I've developed readdir(3)
1350 +library which operates this merging in userspace. You just need to set
1351 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1352 +kernel space for readdir(3).
1356 +----------------------------------------------------------------------
1357 +Aufs sometimes requires privilege access to a branch. For instance,
1358 +in copy-up/down operation. When a user process is going to make changes
1359 +to a file which exists in the lower readonly branch only, and the mode
1360 +of one of ancestor directories may not be writable by a user
1361 +process. Here aufs copy-up the file with its ancestors and they may
1362 +require privilege to set its owner/group/mode/etc.
1363 +This is a typical case of a application character of aufs (see
1366 +Aufs uses workqueue synchronously for this case. It creates its own
1367 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1368 +passes the request to call mkdir or write (for example), and wait for
1369 +its completion. This approach solves a problem of a signal handler
1371 +If aufs didn't adopt the workqueue and changed the privilege of the
1372 +process, then the process may receive the unexpected SIGXFSZ or other
1375 +Also aufs uses the system global workqueue ("events" kernel thread) too
1376 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1377 +whiteout base and etc. This is unrelated to a privilege.
1378 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1379 +superblock at the beginning, at the same time waits for the completion
1380 +of all queued asynchronous tasks.
1384 +----------------------------------------------------------------------
1385 +The whiteout in aufs is very similar to Unionfs's. That is represented
1386 +by its filename. UnionMount takes an approach of a file mode, but I am
1387 +afraid several utilities (find(1) or something) will have to support it.
1389 +Basically the whiteout represents "logical deletion" which stops aufs to
1390 +lookup further, but also it represents "dir is opaque" which also stop
1393 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1394 +In order to make several functions in a single systemcall to be
1395 +revertible, aufs adopts an approach to rename a directory to a temporary
1396 +unique whiteouted name.
1397 +For example, in rename(2) dir where the target dir already existed, aufs
1398 +renames the target dir to a temporary unique whiteouted name before the
1399 +actual rename on a branch, and then handles other actions (make it opaque,
1400 +update the attributes, etc). If an error happens in these actions, aufs
1401 +simply renames the whiteouted name back and returns an error. If all are
1402 +succeeded, aufs registers a function to remove the whiteouted unique
1403 +temporary name completely and asynchronously to the system global
1408 +----------------------------------------------------------------------
1409 +It is a well-known feature or concept.
1410 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1411 +internally and makes change to the new file on the upper writable branch.
1412 +When the trigger systemcall does not update the timestamps of the parent
1413 +dir, aufs reverts it after copy-up.
1416 +Move-down (aufs3.9 and later)
1417 +----------------------------------------------------------------------
1418 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1419 +the lower readonly branch to the upper writable branch when a user
1420 +changes something about the file.
1421 +"Move-down" is an opposite action of copy-up. Basically this action is
1422 +ran manually instead of automatically and internally.
1423 +For desgin and implementation, aufs has to consider these issues.
1424 +- whiteout for the file may exist on the lower branch.
1425 +- ancestor directories may not exist on the lower branch.
1426 +- diropq for the ancestor directories may exist on the upper branch.
1427 +- free space on the lower branch will reduce.
1428 +- another access to the file may happen during moving-down, including
1429 + UDBA (see "Revalidate Dentry and UDBA").
1430 +- the file should not be hard-linked nor pseudo-linked. they should be
1431 + handled by auplink utility later.
1433 +Sometimes users want to move-down a file from the upper writable branch
1434 +to the lower readonly or writable branch. For instance,
1435 +- the free space of the upper writable branch is going to run out.
1436 +- create a new intermediate branch between the upper and lower branch.
1439 +For this purpose, use "aumvdown" command in aufs-util.git.
1440 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1441 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1442 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-11-05 23:02:18.955889283 +0100
1445 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1447 +# This program is free software; you can redistribute it and/or modify
1448 +# it under the terms of the GNU General Public License as published by
1449 +# the Free Software Foundation; either version 2 of the License, or
1450 +# (at your option) any later version.
1452 +# This program is distributed in the hope that it will be useful,
1453 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1454 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1455 +# GNU General Public License for more details.
1457 +# You should have received a copy of the GNU General Public License
1458 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1460 +Support for a branch who has its ->atomic_open()
1461 +----------------------------------------------------------------------
1462 +The filesystems who implement its ->atomic_open() are not majority. For
1463 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1464 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1465 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1466 +sure whether all filesystems who have ->atomic_open() behave like this,
1467 +but NFSv4 surely returns the error.
1469 +In order to support ->atomic_open() for aufs, there are a few
1472 +A. Introduce aufs_atomic_open()
1473 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1475 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1476 + an aufs user Pip Cet's approach
1477 + - calls aufs_create(), VFS finish_open() and notify_change().
1478 + - pass fake-mode to finish_open(), and then correct the mode by
1480 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1481 + - no aufs_atomic_open().
1482 + - aufs_lookup() registers the TID to an aufs internal object.
1483 + - aufs_create() does nothing when the matching TID is registered, but
1484 + registers the mode.
1485 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1486 + TID is registered.
1487 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1489 + - no aufs_atomic_open().
1490 + - aufs_create() registers the TID to an internal object. this info
1491 + represents "this process created this file just now."
1492 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1493 + registered TID and re-try open() with superuser's credential.
1495 +Pros and cons for each approach.
1498 + - straightforward but highly depends upon VFS internal.
1499 + - the atomic behavaiour is kept.
1500 + - some of parameters such as nameidata are hard to reproduce for
1504 + - easy to implement.
1505 + - the atomic behavaiour is lost.
1507 + - the atomic behavaiour is kept.
1508 + - dirty and tricky.
1509 + - VFS checks whether the file is created correctly after calling
1510 + ->create(), which means this approach doesn't work.
1512 + - easy to implement.
1513 + - the atomic behavaiour is lost.
1514 + - to open a file with superuser's credential and give it to a user
1515 + process is a bad idea, since the file object keeps the credential
1516 + in it. It may affect LSM or something. This approach doesn't work
1519 +The approach A is ideal, but it hard to implement. So here is a
1520 +variation of A, which is to be implemented.
1522 +A-1. Introduce aufs_atomic_open()
1523 + - calls branch fs ->atomic_open() if exists. otherwise calls
1524 + vfs_create() and finish_open().
1525 + - the demerit is that the several checks after branch fs
1526 + ->atomic_open() are lost. in the ordinary case, the checks are
1527 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1528 + be implemented in aufs, but not all I am afraid.
1529 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1530 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1531 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-11-05 23:02:18.959222617 +0100
1534 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1536 +# This program is free software; you can redistribute it and/or modify
1537 +# it under the terms of the GNU General Public License as published by
1538 +# the Free Software Foundation; either version 2 of the License, or
1539 +# (at your option) any later version.
1541 +# This program is distributed in the hope that it will be useful,
1542 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1543 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1544 +# GNU General Public License for more details.
1546 +# You should have received a copy of the GNU General Public License
1547 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1550 +----------------------------------------------------------------------
1551 +Since aufs has a character of sub-VFS (see Introduction), it operates
1552 +lookup for branches as VFS does. It may be a heavy work. But almost all
1553 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1554 +directly connected to its parent. Digging down the directory hierarchy
1555 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1558 +When a branch is a remote filesystem, aufs basically relies upon its
1559 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1561 +For d_revalidate, aufs implements three levels of revalidate tests. See
1562 +"Revalidate Dentry and UDBA" in detail.
1565 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1566 +----------------------------------------------------------------------
1567 +Let's try case study.
1568 +- aufs has two branches, upper readwrite and lower readonly.
1570 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1571 +- user invoked "chmod a+rx /au/dirA"
1572 +- the internal copy-up is activated and "/rw/dirA" is created and its
1573 + permission bits are set to world readable.
1574 +- then "/au/dirA" becomes world readable?
1576 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1577 +or it may be a natively readonly filesystem. If aufs respects the lower
1578 +branch, it should not respond readdir request from other users. But user
1579 +allowed it by chmod. Should really aufs rejects showing the entries
1582 +To be honest, I don't have a good solution for this case. So aufs
1583 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1585 +When dirperm1 is specified, aufs checks only the highest one for the
1586 +directory permission, and shows the entries. Otherwise, as usual, checks
1587 +every dir existing on all branches and rejects the request.
1589 +As a side effect, dirperm1 option improves the performance of aufs
1590 +because the number of permission check is reduced when the number of
1594 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1595 +----------------------------------------------------------------------
1596 +Generally VFS helpers re-validate a dentry as a part of lookup.
1597 +0. digging down the directory hierarchy.
1598 +1. lock the parent dir by its i_mutex.
1599 +2. lookup the final (child) entry.
1601 +4. call the actual operation (create, unlink, etc.)
1602 +5. unlock the parent dir
1604 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1605 +called. Actually aufs implements it and checks the dentry on a branch is
1607 +But it is not enough. Because aufs has to release the lock for the
1608 +parent dir on a branch at the end of ->lookup() (step 2) and
1609 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1611 +If the file on a branch is changed directly, eg. bypassing aufs, after
1612 +aufs released the lock, then the subsequent operation may cause
1613 +something unpleasant result.
1615 +This situation is a result of VFS architecture, ->lookup() and
1616 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1617 +design from VFS's point of view. It is just not suitable for sub-VFS
1620 +Aufs supports such case by three level of revalidation which is
1621 +selectable by user.
1622 +1. Simple Revalidate
1623 + Addition to the native flow in VFS's, confirm the child-parent
1624 + relationship on the branch just after locking the parent dir on the
1625 + branch in the "actual operation" (step 4). When this validation
1626 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1627 + checks the validation of the dentry on branches.
1628 +2. Monitor Changes Internally by Inotify/Fsnotify
1629 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1630 + the dentry on the branch, and returns EBUSY if it finds different
1632 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1633 + during it is in cache. When the event is notified, aufs registers a
1634 + function to kernel 'events' thread by schedule_work(). And the
1635 + function sets some special status to the cached aufs dentry and inode
1636 + private data. If they are not cached, then aufs has nothing to
1637 + do. When the same file is accessed through aufs (step 0-3) later,
1638 + aufs will detect the status and refresh all necessary data.
1639 + In this mode, aufs has to ignore the event which is fired by aufs
1641 +3. No Extra Validation
1642 + This is the simplest test and doesn't add any additional revalidation
1643 + test, and skip the revalidation in step 4. It is useful and improves
1644 + aufs performance when system surely hide the aufs branches from user,
1645 + by over-mounting something (or another method).
1646 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1647 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1648 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-11-05 23:02:18.959222617 +0100
1651 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1653 +# This program is free software; you can redistribute it and/or modify
1654 +# it under the terms of the GNU General Public License as published by
1655 +# the Free Software Foundation; either version 2 of the License, or
1656 +# (at your option) any later version.
1658 +# This program is distributed in the hope that it will be useful,
1659 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1660 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1661 +# GNU General Public License for more details.
1663 +# You should have received a copy of the GNU General Public License
1664 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1666 +Branch Manipulation
1668 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1669 +and changing its permission/attribute, there are a lot of works to do.
1673 +----------------------------------------------------------------------
1674 +o Confirm the adding dir exists outside of aufs, including loopback
1675 + mount, and its various attributes.
1676 +o Initialize the xino file and whiteout bases if necessary.
1679 +o Check the owner/group/mode of the directory
1680 + When the owner/group/mode of the adding directory differs from the
1681 + existing branch, aufs issues a warning because it may impose a
1683 + For example, when a upper writable branch has a world writable empty
1684 + top directory, a malicious user can create any files on the writable
1685 + branch directly, like copy-up and modify manually. If something like
1686 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1687 + writable branch, and the writable branch is world-writable, then a
1688 + malicious guy may create /etc/passwd on the writable branch directly
1689 + and the infected file will be valid in aufs.
1690 + I am afraid it can be a security issue, but aufs can do nothing except
1691 + producing a warning.
1695 +----------------------------------------------------------------------
1696 +o Confirm the deleting branch is not busy
1697 + To be general, there is one merit to adopt "remount" interface to
1698 + manipulate branches. It is to discard caches. At deleting a branch,
1699 + aufs checks the still cached (and connected) dentries and inodes. If
1700 + there are any, then they are all in-use. An inode without its
1701 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1703 + For the cached one, aufs checks whether the same named entry exists on
1705 + If the cached one is a directory, because aufs provides a merged view
1706 + to users, as long as one dir is left on any branch aufs can show the
1707 + dir to users. In this case, the branch can be removed from aufs.
1708 + Otherwise aufs rejects deleting the branch.
1710 + If any file on the deleting branch is opened by aufs, then aufs
1714 +Modify the Permission of a Branch
1715 +----------------------------------------------------------------------
1716 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1719 +o rw --> ro: Confirm the modifying branch is not busy
1720 + Aufs rejects the request if any of these conditions are true.
1721 + - a file on the branch is mmap-ed.
1722 + - a regular file on the branch is opened for write and there is no
1723 + same named entry on the upper branch.
1724 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1725 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1726 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-11-05 23:02:18.959222617 +0100
1729 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1731 +# This program is free software; you can redistribute it and/or modify
1732 +# it under the terms of the GNU General Public License as published by
1733 +# the Free Software Foundation; either version 2 of the License, or
1734 +# (at your option) any later version.
1736 +# This program is distributed in the hope that it will be useful,
1737 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1738 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1739 +# GNU General Public License for more details.
1741 +# You should have received a copy of the GNU General Public License
1742 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1744 +Policies to Select One among Multiple Writable Branches
1745 +----------------------------------------------------------------------
1746 +When the number of writable branch is more than one, aufs has to decide
1747 +the target branch for file creation or copy-up. By default, the highest
1748 +writable branch which has the parent (or ancestor) dir of the target
1749 +file is chosen (top-down-parent policy).
1750 +By user's request, aufs implements some other policies to select the
1751 +writable branch, for file creation several policies, round-robin,
1752 +most-free-space, and other policies. For copy-up, top-down-parent,
1753 +bottom-up-parent, bottom-up and others.
1755 +As expected, the round-robin policy selects the branch in circular. When
1756 +you have two writable branches and creates 10 new files, 5 files will be
1757 +created for each branch. mkdir(2) systemcall is an exception. When you
1758 +create 10 new directories, all will be created on the same branch.
1759 +And the most-free-space policy selects the one which has most free
1760 +space among the writable branches. The amount of free space will be
1761 +checked by aufs internally, and users can specify its time interval.
1763 +The policies for copy-up is more simple,
1764 +top-down-parent is equivalent to the same named on in create policy,
1765 +bottom-up-parent selects the writable branch where the parent dir
1766 +exists and the nearest upper one from the copyup-source,
1767 +bottom-up selects the nearest upper writable branch from the
1768 +copyup-source, regardless the existence of the parent dir.
1770 +There are some rules or exceptions to apply these policies.
1771 +- If there is a readonly branch above the policy-selected branch and
1772 + the parent dir is marked as opaque (a variation of whiteout), or the
1773 + target (creating) file is whiteout-ed on the upper readonly branch,
1774 + then the result of the policy is ignored and the target file will be
1775 + created on the nearest upper writable branch than the readonly branch.
1776 +- If there is a writable branch above the policy-selected branch and
1777 + the parent dir is marked as opaque or the target file is whiteouted
1778 + on the branch, then the result of the policy is ignored and the target
1779 + file will be created on the highest one among the upper writable
1780 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1782 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1783 + They try selecting the branch where the source exists as possible
1784 + since copyup a large file will take long time. If it can't be,
1785 + ie. the branch where the source exists is readonly, then they will
1786 + follow the copyup policy.
1787 +- There is an exception for rename(2) when the target exists.
1788 + If the rename target exists, aufs compares the index of the branches
1789 + where the source and the target exists and selects the higher
1790 + one. If the selected branch is readonly, then aufs follows the
1792 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1793 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1794 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-11-05 23:02:18.959222617 +0100
1797 +// to view this graph, run dot(1) command in GRAPHVIZ.
1799 +// This program is free software; you can redistribute it and/or modify
1800 +// it under the terms of the GNU General Public License as published by
1801 +// the Free Software Foundation; either version 2 of the License, or
1802 +// (at your option) any later version.
1804 +// This program is distributed in the hope that it will be useful,
1805 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1806 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1807 +// GNU General Public License for more details.
1809 +// You should have received a copy of the GNU General Public License
1810 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1814 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1818 +aufs_rename -> whinfo [label="store/remove"];
1821 +inode_list [label="h_inum list in branch\ncache"];
1824 +whinode [label="h_inum list file"];
1827 +brmgmt [label="br_add/del/mod/umount"];
1829 +brmgmt -> inode_list [label="create/remove"];
1830 +brmgmt -> whinode [label="load/store"];
1832 +inode_list -> whinode [style=dashed,dir=both];
1834 +aufs_rename -> inode_list [label="add/del"];
1836 +aufs_lookup -> inode_list [label="search"];
1838 +aufs_lookup -> whinfo [label="load/remove"];
1840 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1841 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1842 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-11-05 23:02:18.959222617 +0100
1845 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1847 +# This program is free software; you can redistribute it and/or modify
1848 +# it under the terms of the GNU General Public License as published by
1849 +# the Free Software Foundation; either version 2 of the License, or
1850 +# (at your option) any later version.
1852 +# This program is distributed in the hope that it will be useful,
1853 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1854 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1855 +# GNU General Public License for more details.
1857 +# You should have received a copy of the GNU General Public License
1858 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1860 +Special handling for renaming a directory (DIRREN)
1861 +----------------------------------------------------------------------
1862 +First, let's assume we have a simple usecase.
1866 +- /ro/dirA and /ro/dirA/file exist too
1867 +- there is no dirB on both branches
1868 +- a user issues rename("dirA", "dirB")
1870 +Now, what should aufs behave against this rename(2)?
1871 +There are a few possible cases.
1874 + since dirA exists on a readonly branch which cannot be renamed.
1876 + it is possible to copy-up dirA (only the dir itself), but the child
1877 + entries ("file" in this case) should not be. it must be a bad
1878 + approach to copy-up recursively.
1879 +C. returns a success.
1880 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1881 + is a violation of aufs' policy.
1882 +D. construct an extra information which indicates that /ro/dirA should
1883 + be handled as the name of dirB.
1884 + overlayfs has a similar feature called REDIRECT.
1886 +Until now, aufs implements the case B only which returns EXDEV, and
1887 +expects the userspace application behaves like mv(1) which tries
1888 +issueing rename(2) recursively.
1890 +A new aufs feature called DIRREN is introduced which implements the case
1891 +D. There are several "extra information" added.
1893 +1. detailed info per renamed directory
1894 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1895 +2. the inode-number list of directories on a branch
1896 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1898 +The filename of "detailed info per directory" represents the lower
1899 +branch, and its format is
1900 +- a type of the branch id
1902 + + uuid (not implemented yet)
1905 +- the inode-number of the branch root dir
1907 +And it contains these info in a single regular file.
1909 +- branch's inode-number of the logically renamed dir
1910 +- the name of the before-renamed dir
1912 +The "detailed info per directory" file is created in aufs rename(2), and
1913 +loaded in any lookup.
1914 +The info is considered in lookup for the matching case only. Here
1915 +"matching" means that the root of branch (in the info filename) is same
1916 +to the current looking-up branch. After looking-up the before-renamed
1917 +name, the inode-number is compared. And the matched dentry is used.
1919 +The "inode-number list of directories" is a regular file which contains
1920 +simply the inode-numbers on the branch. The file is created or updated
1921 +in removing the branch, and loaded in adding the branch. Its lifetime is
1922 +equal to the branch.
1923 +The list is referred in lookup, and when the current target inode is
1924 +found in the list, the aufs tries loading the "detailed info per
1925 +directory" and get the changed and valid name of the dir.
1927 +Theoretically these "extra informaiton" may be able to be put into XATTR
1928 +in the dir inode. But aufs doesn't choose this way because
1929 +1. XATTR may not be supported by the branch (or its configuration)
1930 +2. XATTR may have its size limit.
1931 +3. XATTR may be less easy to convert than a regular file, when the
1932 + format of the info is changed in the future.
1933 +At the same time, I agree that the regular file approach is much slower
1934 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1937 +This DIRREN feature is enabled by aufs configuration, and is activated
1938 +by a new mount option.
1940 +For the more complicated case, there is a work with UDBA option, which
1941 +is to dected the direct access to the branches (by-passing aufs) and to
1942 +maintain the cashes in aufs. Since a single cached aufs dentry may
1943 +contains two names, before- and after-rename, the name comparision in
1944 +UDBA handler may not work correctly. In this case, the behaviour will be
1945 +equivalen to udba=reval case.
1946 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1947 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1948 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-11-05 23:02:18.959222617 +0100
1951 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1953 +# This program is free software; you can redistribute it and/or modify
1954 +# it under the terms of the GNU General Public License as published by
1955 +# the Free Software Foundation; either version 2 of the License, or
1956 +# (at your option) any later version.
1958 +# This program is distributed in the hope that it will be useful,
1959 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1960 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1961 +# GNU General Public License for more details.
1963 +# You should have received a copy of the GNU General Public License
1964 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1966 +File-based Hierarchical Storage Management (FHSM)
1967 +----------------------------------------------------------------------
1968 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1969 +storage world. Aufs provides this feature as file-based with multiple
1970 +writable branches, based upon the principle of "Colder, the Lower".
1971 +Here the word "colder" means that the less used files, and "lower" means
1972 +that the position in the order of the stacked branches vertically.
1973 +These multiple writable branches are prioritized, ie. the topmost one
1974 +should be the fastest drive and be used heavily.
1976 +o Characters in aufs FHSM story
1977 +- aufs itself and a new branch attribute.
1978 +- a new ioctl interface to move-down and to establish a connection with
1979 + the daemon ("move-down" is a converse of "copy-up").
1980 +- userspace tool and daemon.
1982 +The userspace daemon establishes a connection with aufs and waits for
1983 +the notification. The notified information is very similar to struct
1984 +statfs containing the number of consumed blocks and inodes.
1985 +When the consumed blocks/inodes of a branch exceeds the user-specified
1986 +upper watermark, the daemon activates its move-down process until the
1987 +consumed blocks/inodes reaches the user-specified lower watermark.
1989 +The actual move-down is done by aufs based upon the request from
1990 +user-space since we need to maintain the inode number and the internal
1991 +pointer arrays in aufs.
1993 +Currently aufs FHSM handles the regular files only. Additionally they
1994 +must not be hard-linked nor pseudo-linked.
1997 +o Cowork of aufs and the user-space daemon
1998 + During the userspace daemon established the connection, aufs sends a
1999 + small notification to it whenever aufs writes something into the
2000 + writable branch. But it may cost high since aufs issues statfs(2)
2001 + internally. So user can specify a new option to cache the
2002 + info. Actually the notification is controlled by these factors.
2003 + + the specified cache time.
2004 + + classified as "force" by aufs internally.
2005 + Until the specified time expires, aufs doesn't send the info
2006 + except the forced cases. When aufs decide forcing, the info is always
2007 + notified to userspace.
2008 + For example, the number of free inodes is generally large enough and
2009 + the shortage of it happens rarely. So aufs doesn't force the
2010 + notification when creating a new file, directory and others. This is
2011 + the typical case which aufs doesn't force.
2012 + When aufs writes the actual filedata and the files consumes any of new
2013 + blocks, the aufs forces notifying.
2016 +o Interfaces in aufs
2017 +- New branch attribute.
2019 + Specifies that the branch is managed by FHSM feature. In other word,
2020 + participant in the FHSM.
2021 + When nofhsm is set to the branch, it will not be the source/target
2022 + branch of the move-down operation. This attribute is set
2023 + independently from coo and moo attributes, and if you want full
2024 + FHSM, you should specify them as well.
2025 +- New mount option.
2027 + Specifies a second to suppress many less important info to be
2030 + + AUFS_CTL_FHSM_FD
2031 + create a new file descriptor which userspace can read the notification
2032 + (a subset of struct statfs) from aufs.
2033 +- Module parameter 'brs'
2034 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2036 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2037 + When there are two or more branches with fhsm attributes,
2038 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2039 + terminates it. As a result of remounting and branch-manipulation, the
2040 + number of branches with fhsm attribute can be one. In this case,
2041 + /sbin/mount.aufs will terminate the user-space daemon.
2044 +Finally the operation is done as these steps in kernel-space.
2046 + + no one else is using the file.
2047 + + the file is not hard-linked.
2048 + + the file is not pseudo-linked.
2049 + + the file is a regular file.
2050 + + the parent dir is not opaqued.
2051 +- find the target writable branch.
2052 +- make sure the file is not whiteout-ed by the upper (than the target)
2054 +- make the parent dir on the target branch.
2055 +- mutex lock the inode on the branch.
2056 +- unlink the whiteout on the target branch (if exists).
2057 +- lookup and create the whiteout-ed temporary name on the target branch.
2058 +- copy the file as the whiteout-ed temporary name on the target branch.
2059 +- rename the whiteout-ed temporary name to the original name.
2060 +- unlink the file on the source branch.
2061 +- maintain the internal pointer array and the external inode number
2063 +- maintain the timestamps and other attributes of the parent dir and the
2066 +And of course, in every step, an error may happen. So the operation
2067 +should restore the original file state after an error happens.
2068 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2069 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2070 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-11-05 23:02:18.959222617 +0100
2073 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2075 +# This program is free software; you can redistribute it and/or modify
2076 +# it under the terms of the GNU General Public License as published by
2077 +# the Free Software Foundation; either version 2 of the License, or
2078 +# (at your option) any later version.
2080 +# This program is distributed in the hope that it will be useful,
2081 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2082 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2083 +# GNU General Public License for more details.
2085 +# You should have received a copy of the GNU General Public License
2086 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2088 +mmap(2) -- File Memory Mapping
2089 +----------------------------------------------------------------------
2090 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2091 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2093 +This approach is simple and good, but there is one problem.
2094 +Under /proc, several entries show the mmapped files by its path (with
2095 +device and inode number), and the printed path will be the path on the
2096 +branch fs's instead of virtual aufs's.
2097 +This is not a problem in most cases, but some utilities lsof(1) (and its
2098 +user) may expect the path on aufs.
2100 +To address this issue, aufs adds a new member called vm_prfile in struct
2101 +vm_area_struct (and struct vm_region). The original vm_file points to
2102 +the file on the branch fs in order to handle everything correctly as
2103 +usual. The new vm_prfile points to a virtual file in aufs, and the
2104 +show-functions in procfs refers to vm_prfile if it is set.
2105 +Also we need to maintain several other places where touching vm_file
2107 +- fork()/clone() copies vma and the reference count of vm_file is
2109 +- merging vma maintains the ref count too.
2111 +This is not a good approach. It just fakes the printed path. But it
2112 +leaves all behaviour around f_mapping unchanged. This is surely an
2114 +Actually aufs had adopted another complicated approach which calls
2115 +generic_file_mmap() and handles struct vm_operations_struct. In this
2116 +approach, aufs met a hard problem and I could not solve it without
2117 +switching the approach.
2119 +There may be one more another approach which is
2120 +- bind-mount the branch-root onto the aufs-root internally
2121 +- grab the new vfsmount (ie. struct mount)
2122 +- lazy-umount the branch-root internally
2123 +- in open(2) the aufs-file, open the branch-file with the hidden
2124 + vfsmount (instead of the original branch's vfsmount)
2125 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2126 + but it may be possible from userspace by the mount helper.
2128 +Adding the internal hidden vfsmount and using it in opening a file, the
2129 +file path under /proc will be printed correctly. This approach looks
2130 +smarter, but is not possible I am afraid.
2131 +- aufs-root may be bind-mount later. when it happens, another hidden
2132 + vfsmount will be required.
2133 +- it is hard to get the chance to bind-mount and lazy-umount
2134 + + in kernel-space, FS can have vfsmount in open(2) via
2135 + file->f_path, and aufs can know its vfsmount. But several locks are
2136 + already acquired, and if aufs tries to bind-mount and lazy-umount
2137 + here, then it may cause a deadlock.
2138 + + in user-space, bind-mount doesn't invoke the mount helper.
2139 +- since /proc shows dev and ino, aufs has to give vma these info. it
2140 + means a new member vm_prinode will be necessary. this is essentially
2141 + equivalent to vm_prfile described above.
2143 +I have to give up this "looks-smater" approach.
2144 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2145 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2146 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-11-05 23:02:18.959222617 +0100
2149 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2151 +# This program is free software; you can redistribute it and/or modify
2152 +# it under the terms of the GNU General Public License as published by
2153 +# the Free Software Foundation; either version 2 of the License, or
2154 +# (at your option) any later version.
2156 +# This program is distributed in the hope that it will be useful,
2157 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2158 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2159 +# GNU General Public License for more details.
2161 +# You should have received a copy of the GNU General Public License
2162 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2164 +Listing XATTR/EA and getting the value
2165 +----------------------------------------------------------------------
2166 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2167 +shows the values from the topmost existing file. This behaviour is good
2168 +for the non-dir entries since the bahaviour exactly matches the shown
2169 +information. But for the directories, aufs considers all the same named
2170 +entries on the lower branches. Which means, if one of the lower entry
2171 +rejects readdir call, then aufs returns an error even if the topmost
2172 +entry allows it. This behaviour is necessary to respect the branch fs's
2173 +security, but can make users confused since the user-visible standard
2174 +attributes don't match the behaviour.
2175 +To address this issue, aufs has a mount option called dirperm1 which
2176 +checks the permission for the topmost entry only, and ignores the lower
2177 +entry's permission.
2179 +A similar issue can happen around XATTR.
2180 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2181 +always set. Otherwise these very unpleasant situation would happen.
2182 +- listxattr(2) may return the duplicated entries.
2183 +- users may not be able to remove or reset the XATTR forever,
2186 +XATTR/EA support in the internal (copy,move)-(up,down)
2187 +----------------------------------------------------------------------
2188 +Generally the extended attributes of inode are categorized as these.
2189 +- "security" for LSM and capability.
2190 +- "system" for posix ACL, 'acl' mount option is required for the branch
2192 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2193 +- "user" for userspace, 'user_xattr' mount option is required for the
2194 + branch fs generally.
2196 +Moreover there are some other categories. Aufs handles these rather
2197 +unpopular categories as the ordinary ones, ie. there is no special
2198 +condition nor exception.
2200 +In copy-up, the support for XATTR on the dst branch may differ from the
2201 +src branch. In this case, the copy-up operation will get an error and
2202 +the original user operation which triggered the copy-up will fail. It
2203 +can happen that even all copy-up will fail.
2204 +When both of src and dst branches support XATTR and if an error occurs
2205 +during copying XATTR, then the copy-up should fail obviously. That is a
2206 +good reason and aufs should return an error to userspace. But when only
2207 +the src branch support that XATTR, aufs should not return an error.
2208 +For example, the src branch supports ACL but the dst branch doesn't
2209 +because the dst branch may natively un-support it or temporary
2210 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2211 +may NOT return an error even if the XATTR is not supported. It is
2212 +totally up to the branch fs.
2214 +Anyway when the aufs internal copy-up gets an error from the dst branch
2215 +fs, then aufs tries removing the just copied entry and returns the error
2216 +to the userspace. The worst case of this situation will be all copy-up
2219 +For the copy-up operation, there two basic approaches.
2220 +- copy the specified XATTR only (by category above), and return the
2221 + error unconditionally if it happens.
2222 +- copy all XATTR, and ignore the error on the specified category only.
2224 +In order to support XATTR and to implement the correct behaviour, aufs
2225 +chooses the latter approach and introduces some new branch attributes,
2226 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2227 +They correspond to the XATTR namespaces (see above). Additionally, to be
2228 +convenient, "icex" is also provided which means all "icex*" attributes
2229 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2231 +The meaning of these attributes is to ignore the error from setting
2232 +XATTR on that branch.
2233 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2234 +error from the dst branch according to the specified attributes.
2236 +Some XATTR may have its default value. The default value may come from
2237 +the parent dir or the environment. If the default value is set at the
2238 +file creating-time, it will be overwritten by copy-up.
2239 +Some contradiction may happen I am afraid.
2240 +Do we need another attribute to stop copying XATTR? I am unsure. For
2241 +now, aufs implements the branch attributes to ignore the error.
2242 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2243 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2244 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-11-05 23:02:18.959222617 +0100
2247 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2249 +# This program is free software; you can redistribute it and/or modify
2250 +# it under the terms of the GNU General Public License as published by
2251 +# the Free Software Foundation; either version 2 of the License, or
2252 +# (at your option) any later version.
2254 +# This program is distributed in the hope that it will be useful,
2255 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2256 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2257 +# GNU General Public License for more details.
2259 +# You should have received a copy of the GNU General Public License
2260 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2262 +Export Aufs via NFS
2263 +----------------------------------------------------------------------
2264 +Here is an approach.
2265 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2267 +- iget_locked(): initialize aufs inode generation for a new inode, and
2268 + store it in xigen file.
2269 +- destroy_inode(): increment aufs inode generation and store it in xigen
2270 + file. it is necessary even if it is not unlinked, because any data of
2271 + inode may be changed by UDBA.
2272 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2273 + build file handle by
2274 + + branch id (4 bytes)
2275 + + superblock generation (4 bytes)
2276 + + inode number (4 or 8 bytes)
2277 + + parent dir inode number (4 or 8 bytes)
2278 + + inode generation (4 bytes))
2279 + + return value of exportfs_encode_fh() for the parent on a branch (4
2281 + + file handle for a branch (by exportfs_encode_fh())
2283 + + find the index of a branch from its id in handle, and check it is
2284 + still exist in aufs.
2285 + + 1st level: get the inode number from handle and search it in cache.
2286 + + 2nd level: if not found in cache, get the parent inode number from
2287 + the handle and search it in cache. and then open the found parent
2288 + dir, find the matching inode number by vfs_readdir() and get its
2289 + name, and call lookup_one_len() for the target dentry.
2290 + + 3rd level: if the parent dir is not cached, call
2291 + exportfs_decode_fh() for a branch and get the parent on a branch,
2292 + build a pathname of it, convert it a pathname in aufs, call
2293 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2295 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2296 + for every branch, but not itself. to get this, (currently) aufs
2297 + searches in current->nsproxy->mnt_ns list. it may not be a good
2298 + idea, but I didn't get other approach.
2299 + + test the generation of the gotten inode.
2300 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2301 + convert it into ESTALE for NFSD.
2302 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2303 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2304 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2305 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2306 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-11-05 23:02:18.959222617 +0100
2309 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2311 +# This program is free software; you can redistribute it and/or modify
2312 +# it under the terms of the GNU General Public License as published by
2313 +# the Free Software Foundation; either version 2 of the License, or
2314 +# (at your option) any later version.
2316 +# This program is distributed in the hope that it will be useful,
2317 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2318 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2319 +# GNU General Public License for more details.
2321 +# You should have received a copy of the GNU General Public License
2322 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2324 +Show Whiteout Mode (shwh)
2325 +----------------------------------------------------------------------
2326 +Generally aufs hides the name of whiteouts. But in some cases, to show
2327 +them is very useful for users. For instance, creating a new middle layer
2328 +(branch) by merging existing layers.
2330 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2331 +When you have three branches,
2332 +- Bottom: 'system', squashfs (underlying base system), read-only
2333 +- Middle: 'mods', squashfs, read-only
2334 +- Top: 'overlay', ram (tmpfs), read-write
2336 +The top layer is loaded at boot time and saved at shutdown, to preserve
2337 +the changes made to the system during the session.
2338 +When larger changes have been made, or smaller changes have accumulated,
2339 +the size of the saved top layer data grows. At this point, it would be
2340 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2341 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2342 +restoring save and load speed.
2344 +This merging is simplified by the use of another aufs mount, of just the
2345 +two overlay branches using the 'shwh' option.
2346 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2347 + aufs /livesys/merge_union
2349 +A merged view of these two branches is then available at
2350 +/livesys/merge_union, and the new feature is that the whiteouts are
2352 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2353 +writing to all branches. Also the default mode for all branches is 'ro'.
2354 +It is now possible to save the combined contents of the two overlay
2355 +branches to a new squashfs, e.g.:
2356 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2358 +This new squashfs archive can be stored on the boot device and the
2359 +initramfs will use it to replace the old one at the next boot.
2360 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2361 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2362 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-11-05 23:02:18.959222617 +0100
2365 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2367 +# This program is free software; you can redistribute it and/or modify
2368 +# it under the terms of the GNU General Public License as published by
2369 +# the Free Software Foundation; either version 2 of the License, or
2370 +# (at your option) any later version.
2372 +# This program is distributed in the hope that it will be useful,
2373 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2374 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2375 +# GNU General Public License for more details.
2377 +# You should have received a copy of the GNU General Public License
2378 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2380 +Dynamically customizable FS operations
2381 +----------------------------------------------------------------------
2382 +Generally FS operations (struct inode_operations, struct
2383 +address_space_operations, struct file_operations, etc.) are defined as
2384 +"static const", but it never means that FS have only one set of
2385 +operation. Some FS have multiple sets of them. For instance, ext2 has
2386 +three sets, one for XIP, for NOBH, and for normal.
2387 +Since aufs overrides and redirects these operations, sometimes aufs has
2388 +to change its behaviour according to the branch FS type. More importantly
2389 +VFS acts differently if a function (member in the struct) is set or
2390 +not. It means aufs should have several sets of operations and select one
2391 +among them according to the branch FS definition.
2393 +In order to solve this problem and not to affect the behaviour of VFS,
2394 +aufs defines these operations dynamically. For instance, aufs defines
2395 +dummy direct_IO function for struct address_space_operations, but it may
2396 +not be set to the address_space_operations actually. When the branch FS
2397 +doesn't have it, aufs doesn't set it to its address_space_operations
2398 +while the function definition itself is still alive. So the behaviour
2399 +itself will not change, and it will return an error when direct_IO is
2402 +The lifetime of these dynamically generated operation object is
2403 +maintained by aufs branch object. When the branch is removed from aufs,
2404 +the reference counter of the object is decremented. When it reaches
2405 +zero, the dynamically generated operation object will be freed.
2407 +This approach is designed to support AIO (io_submit), Direct I/O and
2409 +Currently this approach is applied to address_space_operations for
2410 +regular files only.
2411 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2412 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2413 +++ linux/Documentation/filesystems/aufs/README 2023-09-02 12:00:06.376642958 +0200
2416 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2422 +----------------------------------------
2423 +In the early days, aufs was entirely re-designed and re-implemented
2424 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2425 +improvements and implementations, it became totally different from
2426 +Unionfs while keeping the basic features.
2427 +Later, Unionfs Version 2.x series began taking some of the same
2428 +approaches to aufs1's.
2429 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2430 +University and his team.
2432 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2433 +aufs-linux.git or aufs-standalone.git.
2434 +If you want older kernel version support,
2435 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2436 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2437 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2438 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2439 + or aufs1 from CVS on SourceForge.
2441 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2442 + were changed. Now they are aufs-linux.git and
2443 + aufs-standalone.git and they contain aufs5 and later branches.
2445 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2446 + According to Christoph Hellwig, linux rejects all union-type
2447 + filesystems but UnionMount.
2448 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2450 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2451 + UnionMount, and he pointed out an issue around a directory mutex
2452 + lock and aufs addressed it. But it is still unsure whether aufs will
2453 + be merged (or any other union solution).
2454 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2458 +----------------------------------------
2459 +- unite several directories into a single virtual filesystem. The member
2460 + directory is called as a branch.
2461 +- you can specify the permission flags to the branch, which are 'readonly',
2462 + 'readwrite' and 'whiteout-able.'
2463 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2464 + readonly branch are modifiable logically.
2465 +- dynamic branch manipulation, add, del.
2468 +Also there are many enhancements in aufs, such as:
2469 +- test only the highest one for the directory permission (dirperm1)
2470 +- copyup on open (coo=)
2471 +- 'move' policy for copy-up between two writable branches, after
2472 + checking free space.
2474 +- readdir(3) in userspace.
2475 +- keep inode number by external inode number table
2476 +- keep the timestamps of file/dir in internal copyup operation
2477 +- seekable directory, supporting NFS readdir.
2478 +- whiteout is hardlinked in order to reduce the consumption of inodes
2480 +- do not copyup, nor create a whiteout when it is unnecessary
2481 +- revert a single systemcall when an error occurs in aufs
2482 +- remount interface instead of ioctl
2483 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2484 +- loopback mounted filesystem as a branch
2485 +- kernel thread for removing the dir who has a plenty of whiteouts
2486 +- support copyup sparse file (a file which has a 'hole' in it)
2487 +- default permission flags for branches
2488 +- selectable permission flags for ro branch, whether whiteout can
2491 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2492 +- support multiple writable branches, some policies to select one
2493 + among multiple writable branches.
2494 +- a new semantics for link(2) and rename(2) to support multiple
2495 + writable branches.
2496 +- no glibc changes are required.
2497 +- pseudo hardlink (hardlink over branches)
2498 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2499 + including NFS or remote filesystem branch.
2500 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2503 +Currently these features are dropped temporary from aufs6.
2504 +See design/08plan.txt in detail.
2505 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2507 +- statistics of aufs thread (/sys/fs/aufs/stat)
2509 +Features or just an idea in the future (see also design/*.txt),
2510 +- reorder the branch index without del/re-add.
2511 +- permanent xino files for NFSD
2512 +- an option for refreshing the opened files after add/del branches
2513 +- light version, without branch manipulation. (unnecessary?)
2514 +- copyup in userspace
2515 +- inotify in userspace
2520 +----------------------------------------
2521 +There are three GIT trees for aufs6, aufs-linux.git,
2522 +aufs-standalone.git, and aufs-util.git.
2523 +While the aufs-util is always necessary, you need either of aufs-linux
2524 +or aufs-standalone.
2526 +The aufs-linux tree includes the whole linux mainline GIT tree,
2527 +git://git.kernel.org/.../torvalds/linux.git.
2528 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2529 +build aufs6 as an external kernel module.
2530 +Several extra patches are not included in this tree. Only
2531 +aufs-standalone tree contains them. They are described in the later
2532 +section "Configuration and Compilation."
2534 +On the other hand, the aufs-standalone tree has only aufs source files
2535 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2536 +But you need to apply all aufs patches manually.
2538 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2539 +represents the linux kernel version, "linux-6.x". For instance,
2540 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2541 +"aufs6.x-rcN" branch.
2544 +$ git clone --reference /your/linux/git/tree \
2545 + git://github.com/sfjro/aufs-linux.git aufs-linux.git
2546 +- if you don't have linux GIT tree, then remove "--reference ..."
2547 +$ cd aufs-linux.git
2548 +$ git checkout origin/aufs6.0
2550 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2551 +leave the patch-work to GIT.
2552 +$ cd /your/linux/git/tree
2553 +$ git remote add aufs git://github.com/sfjro/aufs-linux.git
2555 +$ git checkout -b my6.0 v6.0
2556 +$ (add your local change...)
2557 +$ git pull aufs aufs6.0
2558 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2559 +- you may need to solve some conflicts between your_changes and
2560 + aufs6.0. in this case, git-rerere is recommended so that you can
2561 + solve the similar conflicts automatically when you upgrade to 6.1 or
2562 + later in the future.
2564 +o aufs-standalone tree
2565 +$ git clone git://github.com/sfjro/aufs-standalone.git aufs-standalone.git
2566 +$ cd aufs-standalone.git
2567 +$ git checkout origin/aufs6.0
2570 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2571 +- note that the public aufs-util.git is on SourceForge instead of
2574 +$ git checkout origin/aufs6.0
2576 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2577 +The minor version number, 'x' in '6.x', of aufs may not always
2578 +follow the minor version number of the kernel.
2579 +Because changes in the kernel that cause the use of a new
2580 +minor version number do not always require changes to aufs-util.
2582 +Since aufs-util has its own minor version number, you may not be
2583 +able to find a GIT branch in aufs-util for your kernel's
2584 +exact minor version number.
2585 +In this case, you should git-checkout the branch for the
2586 +nearest lower number.
2588 +For (an unreleased) example:
2589 +If you are using "linux-6.10" and the "aufs6.10" branch
2590 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2591 +or something numerically smaller is the branch for your kernel.
2593 +Also you can view all branches by
2597 +3. Configuration and Compilation
2598 +----------------------------------------
2599 +Make sure you have git-checkout'ed the correct branch.
2601 +For aufs-linux tree,
2602 +- enable CONFIG_AUFS_FS.
2603 +- set other aufs configurations if necessary.
2604 +- for aufs5.13 and later
2605 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2606 + also a caller of VFS functions for branch filesystems, subclassing of
2607 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2608 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2609 + need to customize some LOCKDEP numbers. Here are what I use on my
2611 + CONFIG_LOCKDEP_BITS=21
2612 + CONFIG_LOCKDEP_CHAINS_BITS=21
2613 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2614 + Also you will need to expand some constant values in LOCKDEP. Refer
2615 + to lockdep-debug.patch in aufs-standalone.git.
2617 +For aufs-standalone tree,
2618 +There are several ways to build.
2621 +- apply ./aufs6-kbuild.patch to your kernel source files.
2622 +- apply ./aufs6-base.patch too.
2623 +- apply ./aufs6-mmap.patch too.
2624 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2625 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs-standalone.patch.
2626 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2627 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2628 +- enable CONFIG_AUFS_FS, you can select either
2630 +- and build your kernel as usual.
2631 +- install the built kernel.
2632 +- install the header files too by "make headers_install" to the
2633 + directory where you specify. By default, it is $PWD/usr.
2634 + "make help" shows a brief note for headers_install.
2635 +- and reboot your system.
2638 +- module only (CONFIG_AUFS_FS=m).
2639 +- apply ./aufs6-base.patch to your kernel source files.
2640 +- apply ./aufs6-mmap.patch too.
2641 +- apply ./aufs6-standalone.patch too.
2642 +- build your kernel, don't forget "make headers_install", and reboot.
2643 +- edit ./config.mk and set other aufs configurations if necessary.
2644 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2645 + every aufs configurations.
2646 +- build the module by simple "make".
2647 +- you can specify ${KDIR} make variable which points to your kernel
2649 +- install the files
2650 + + run "make install" to install the aufs module, or copy the built
2651 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2652 + + run "make install_headers" (instead of headers_install) to install
2653 + the modified aufs header file (you can specify DESTDIR which is
2654 + available in aufs standalone version's Makefile only), or copy
2655 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2656 + you like manually. By default, the target directory is $PWD/usr.
2657 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2658 + kernel source tree.
2660 +Note: The header file aufs_type.h is necessary to build aufs-util
2661 + as well as "make headers_install" in the kernel source tree.
2662 + headers_install is subject to be forgotten, but it is essentially
2663 + necessary, not only for building aufs-util.
2664 + You may not meet problems without headers_install in some older
2668 +- read README in aufs-util, build and install it
2669 +- note that your distribution may contain an obsoleted version of
2670 + aufs_type.h in /usr/include/linux or something. When you build aufs
2671 + utilities, make sure that your compiler refers the correct aufs header
2672 + file which is built by "make headers_install."
2673 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2674 + then run "make install_ulib" too. And refer to the aufs manual in
2677 +There several other patches in aufs-standalone.git. They are all
2678 +optional. When you meet some problems, they will help you.
2679 +- aufs6-loopback.patch
2680 + Supports a nested loopback mount in a branch-fs. This patch is
2681 + unnecessary until aufs produces a message like "you may want to try
2682 + another patch for loopback file".
2684 + Modifies a system global kernel internal function get_next_ino() in
2685 + order to stop assigning 0 for an inode-number. Not directly related to
2686 + aufs, but recommended generally.
2688 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2689 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2690 + duplication of inode number, which is important for backup tools and
2691 + other utilities. When you find aufs XINO files for tmpfs branch
2692 + growing too much, try this patch.
2693 +- lockdep-debug.patch
2694 + Similar to some kernel configurations for LOCKDEP (see the top of
2695 + this section), you will need expand some constants in LOCKDEP for
2696 + aufs if you enable CONFIG_LOCKDEP.
2700 +----------------------------------------
2701 +At first, make sure aufs-util are installed, and please read the aufs
2702 +manual, aufs.5 in aufs-util.git tree.
2706 +$ mkdir /tmp/rw /tmp/aufs
2707 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2709 +Here is another example. The result is equivalent.
2710 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2712 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2713 +# mount -o remount,append:${HOME} /tmp/aufs
2715 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2716 +you modify a file under /tmp/aufs, the one on your home directory is
2717 +not affected, instead the same named file will be newly created under
2718 +/tmp/rw. And all of your modification to a file will be applied to
2719 +the one under /tmp/rw. This is called the file based Copy on Write
2721 +Aufs mount options are described in aufs.5.
2722 +If you run chroot or something and make your aufs as a root directory,
2723 +then you need to customize the shutdown script. See the aufs manual in
2726 +Additionally, there are some sample usages of aufs which are a
2727 +diskless system with network booting, and LiveCD over NFS.
2728 +See sample dir in CVS tree on SourceForge.
2732 +----------------------------------------
2733 +When you have any problems or strange behaviour in aufs, please let me
2735 +- /proc/mounts (instead of the output of mount(8))
2736 +- /sys/module/aufs/*
2737 +- /sys/fs/aufs/* (if you have them)
2738 +- /debug/aufs/* (if you have them)
2739 +- linux kernel version
2740 + if your kernel is not plain, for example modified by distributor,
2741 + the url where i can download its source is necessary too.
2742 +- aufs version which was printed at loading the module or booting the
2743 + system, instead of the date you downloaded.
2744 +- configuration (define/undefine CONFIG_AUFS_xxx)
2745 +- kernel configuration or /proc/config.gz (if you have it)
2746 +- LSM (linux security module, if you are using)
2747 +- behaviour which you think to be incorrect
2748 +- actual operation, reproducible one is better
2749 +- mailto: aufs-users at lists.sourceforge.net
2751 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2752 +and Feature Requests) on SourceForge. Please join and write to
2756 +6. Acknowledgements
2757 +----------------------------------------
2758 +Thanks to everyone who have tried and are using aufs, whoever
2759 +have reported a bug or any feedback.
2761 +Especially donators:
2762 +Tomas Matejicek(slax.org) made a donation (much more than once).
2763 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2764 + scripts) is making "doubling" donations.
2765 + Unfortunately I cannot list all of the donators, but I really
2767 + It ends Aug 2010, but the ordinary donation URL is still available.
2768 + <http://sourceforge.net/donate/index.php?group_id=167503>
2769 +Dai Itasaka made a donation (2007/8).
2770 +Chuck Smith made a donation (2008/4, 10 and 12).
2771 +Henk Schoneveld made a donation (2008/9).
2772 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2773 +Francois Dupoux made a donation (2008/11).
2774 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2775 + aufs2 GIT tree (2009/2).
2776 +William Grant made a donation (2009/3).
2777 +Patrick Lane made a donation (2009/4).
2778 +The Mail Archive (mail-archive.com) made donations (2009/5).
2779 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2780 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2781 +Pavel Pronskiy made a donation (2011/2).
2782 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2783 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2784 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2786 +Sam Liddicott made a donation (2011/9).
2787 +Era Scarecrow made a donation (2013/4).
2788 +Bor Ratajc made a donation (2013/4).
2789 +Alessandro Gorreta made a donation (2013/4).
2790 +POIRETTE Marc made a donation (2013/4).
2791 +Alessandro Gorreta made a donation (2013/4).
2792 +lauri kasvandik made a donation (2013/5).
2793 +"pemasu from Finland" made a donation (2013/7).
2794 +The Parted Magic Project made a donation (2013/9 and 11).
2795 +Pavel Barta made a donation (2013/10).
2796 +Nikolay Pertsev made a donation (2014/5).
2797 +James B made a donation (2014/7, 2015/7, and 2021/12).
2798 +Stefano Di Biase made a donation (2014/8).
2799 +Daniel Epellei made a donation (2015/1).
2800 +OmegaPhil made a donation (2016/1, 2018/4).
2801 +Tomasz Szewczyk made a donation (2016/4).
2802 +James Burry made a donation (2016/12).
2803 +Carsten Rose made a donation (2018/9).
2804 +Porteus Kiosk made a donation (2018/10).
2805 +huronOS team: Enya Quetzalli made donations (2022/5, 2023/5 and 8).
2806 +Vasily Mikhaylichenko made a donation (2023/5).
2808 +Thank you very much.
2809 +Donations are always, including future donations, very important and
2810 +helpful for me to keep on developing aufs.
2814 +----------------------------------------
2815 +If you are an experienced user, no explanation is needed. Aufs is
2816 +just a linux filesystem.
2821 +# Local variables: ;
2824 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2825 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2826 +++ linux/fs/aufs/aufs.h 2022-11-05 23:02:18.959222617 +0100
2828 +/* SPDX-License-Identifier: GPL-2.0 */
2830 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2832 + * This program is free software; you can redistribute it and/or modify
2833 + * it under the terms of the GNU General Public License as published by
2834 + * the Free Software Foundation; either version 2 of the License, or
2835 + * (at your option) any later version.
2837 + * This program is distributed in the hope that it will be useful,
2838 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2839 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2840 + * GNU General Public License for more details.
2842 + * You should have received a copy of the GNU General Public License
2843 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2847 + * all header files
2855 +#define AuStub(type, name, body, ...) \
2856 + static inline type name(__VA_ARGS__) { body; }
2858 +#define AuStubVoid(name, ...) \
2859 + AuStub(void, name, , __VA_ARGS__)
2860 +#define AuStubInt0(name, ...) \
2861 + AuStub(int, name, return 0, __VA_ARGS__)
2865 +#include "branch.h"
2868 +#include "dbgaufs.h"
2869 +#include "dentry.h"
2871 +#include "dirren.h"
2874 +#include "fstype.h"
2879 +#include "module.h"
2883 +#include "sysaufs.h"
2888 +#endif /* __KERNEL__ */
2889 +#endif /* __AUFS_H__ */
2890 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2891 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2892 +++ linux/fs/aufs/branch.c 2022-11-05 23:02:18.959222617 +0100
2894 +// SPDX-License-Identifier: GPL-2.0
2896 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2898 + * This program is free software; you can redistribute it and/or modify
2899 + * it under the terms of the GNU General Public License as published by
2900 + * the Free Software Foundation; either version 2 of the License, or
2901 + * (at your option) any later version.
2903 + * This program is distributed in the hope that it will be useful,
2904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2906 + * GNU General Public License for more details.
2908 + * You should have received a copy of the GNU General Public License
2909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2913 + * branch management
2916 +#include <linux/compat.h>
2917 +#include <linux/statfs.h>
2921 + * free a single branch
2923 +static void au_br_do_free(struct au_branch *br)
2926 + struct au_wbr *wbr;
2927 + struct au_dykey **key;
2929 + au_hnotify_fin_br(br);
2930 + /* always, regardless the mount option */
2931 + au_dr_hino_free(&br->br_dirren);
2934 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2935 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2936 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2937 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2941 + for (i = 0; i < AuBrWh_Last; i++)
2942 + dput(wbr->wbr_wh[i]);
2943 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2944 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2947 + if (br->br_fhsm) {
2948 + au_br_fhsm_fin(br->br_fhsm);
2949 + au_kfree_try_rcu(br->br_fhsm);
2952 + key = br->br_dykey;
2953 + for (i = 0; i < AuBrDynOp; i++, key++)
2959 + /* recursive lock, s_umount of branch's */
2960 + /* synchronize_rcu(); */ /* why? */
2962 + path_put(&br->br_path);
2964 + au_kfree_rcu(wbr);
2965 + au_lcnt_wait_for_fin(&br->br_nfiles);
2966 + au_lcnt_wait_for_fin(&br->br_count);
2967 + /* I don't know why, but percpu_refcount requires this */
2968 + /* synchronize_rcu(); */
2973 + * frees all branches
2975 +void au_br_free(struct au_sbinfo *sbinfo)
2977 + aufs_bindex_t bmax;
2978 + struct au_branch **br;
2980 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2982 + bmax = sbinfo->si_bbot + 1;
2983 + br = sbinfo->si_branch;
2985 + au_br_do_free(*br++);
2989 + * find the index of a branch which is specified by @br_id.
2991 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2993 + aufs_bindex_t bindex, bbot;
2995 + bbot = au_sbbot(sb);
2996 + for (bindex = 0; bindex <= bbot; bindex++)
2997 + if (au_sbr_id(sb, bindex) == br_id)
3002 +/* ---------------------------------------------------------------------- */
3008 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3009 + struct dentry *h_root)
3011 + if (unlikely(h_adding == h_root
3012 + || au_test_loopback_overlap(sb, h_adding)))
3014 + if (h_adding->d_sb != h_root->d_sb)
3016 + return au_test_subdir(h_adding, h_root)
3017 + || au_test_subdir(h_root, h_adding);
3021 + * returns a newly allocated branch. @new_nbranch is a number of branches
3022 + * after adding a branch.
3024 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3027 + struct au_branch *add_branch;
3028 + struct dentry *root;
3029 + struct inode *inode;
3033 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3034 + if (unlikely(!add_branch))
3036 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3037 + if (unlikely(!add_branch->br_xino))
3039 + err = au_hnotify_init_br(add_branch, perm);
3040 + if (unlikely(err))
3043 + if (au_br_writable(perm)) {
3044 + /* may be freed separately at changing the branch permission */
3045 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3047 + if (unlikely(!add_branch->br_wbr))
3051 + if (au_br_fhsm(perm)) {
3052 + err = au_fhsm_br_alloc(add_branch);
3053 + if (unlikely(err))
3057 + root = sb->s_root;
3058 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3060 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3062 + inode = d_inode(root);
3063 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3067 + return add_branch; /* success */
3070 + au_kfree_rcu(add_branch->br_wbr);
3072 + au_hnotify_fin_br(add_branch);
3074 + au_xino_put(add_branch);
3076 + au_kfree_rcu(add_branch);
3078 + return ERR_PTR(err);
3082 + * test if the branch permission is legal or not.
3084 +static int test_br(struct inode *inode, int brperm, char *path)
3088 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3093 + pr_err("write permission for readonly mount or inode, %s\n", path);
3101 + * 0: success, the caller will add it
3102 + * plus: success, it is already unified, the caller should ignore it
3105 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3108 + aufs_bindex_t bbot, bindex;
3109 + struct dentry *root, *h_dentry;
3110 + struct inode *inode, *h_inode;
3112 + root = sb->s_root;
3113 + bbot = au_sbbot(sb);
3114 + if (unlikely(bbot >= 0
3115 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3119 + pr_err("%s duplicated\n", add->pathname);
3124 + err = -ENOSPC; /* -E2BIG; */
3125 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3126 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3127 + pr_err("number of branches exceeded %s\n", add->pathname);
3132 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3133 + pr_err("bad index %d\n", add->bindex);
3137 + inode = d_inode(add->path.dentry);
3139 + if (unlikely(!inode->i_nlink)) {
3140 + pr_err("no existence %s\n", add->pathname);
3145 + if (unlikely(inode->i_sb == sb)) {
3146 + pr_err("%s must be outside\n", add->pathname);
3150 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3151 + pr_err("unsupported filesystem, %s (%s)\n",
3152 + add->pathname, au_sbtype(inode->i_sb));
3156 + if (unlikely(inode->i_sb->s_stack_depth)) {
3157 + pr_err("already stacked, %s (%s)\n",
3158 + add->pathname, au_sbtype(inode->i_sb));
3162 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3163 + if (unlikely(err))
3167 + return 0; /* success */
3170 + for (bindex = 0; bindex <= bbot; bindex++)
3171 + if (unlikely(test_overlap(sb, add->path.dentry,
3172 + au_h_dptr(root, bindex)))) {
3173 + pr_err("%s is overlapped\n", add->pathname);
3178 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3179 + h_dentry = au_h_dptr(root, 0);
3180 + h_inode = d_inode(h_dentry);
3181 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3182 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3183 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3184 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3186 + i_uid_read(inode), i_gid_read(inode),
3187 + (inode->i_mode & S_IALLUGO),
3188 + i_uid_read(h_inode), i_gid_read(h_inode),
3189 + (h_inode->i_mode & S_IALLUGO));
3197 + * initialize or clean the whiteouts for an adding branch
3199 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3202 + int err, old_perm;
3203 + aufs_bindex_t bindex;
3204 + struct inode *h_inode;
3205 + struct au_wbr *wbr;
3206 + struct au_hinode *hdir;
3207 + struct dentry *h_dentry;
3209 + err = vfsub_mnt_want_write(au_br_mnt(br));
3210 + if (unlikely(err))
3214 + old_perm = br->br_perm;
3215 + br->br_perm = new_perm;
3218 + bindex = au_br_index(sb, br->br_id);
3219 + if (0 <= bindex) {
3220 + hdir = au_hi(d_inode(sb->s_root), bindex);
3221 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3223 + h_dentry = au_br_dentry(br);
3224 + h_inode = d_inode(h_dentry);
3225 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3228 + err = au_wh_init(br, sb);
3230 + wbr_wh_write_lock(wbr);
3231 + err = au_wh_init(br, sb);
3232 + wbr_wh_write_unlock(wbr);
3235 + au_hn_inode_unlock(hdir);
3237 + inode_unlock(h_inode);
3238 + vfsub_mnt_drop_write(au_br_mnt(br));
3239 + br->br_perm = old_perm;
3241 + if (!err && wbr && !au_br_writable(new_perm)) {
3242 + au_kfree_rcu(wbr);
3243 + br->br_wbr = NULL;
3250 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3254 + struct kstatfs kst;
3255 + struct au_wbr *wbr;
3258 + au_rw_init(&wbr->wbr_wh_rwsem);
3259 + atomic_set(&wbr->wbr_wh_running, 0);
3262 + * a limit for rmdir/rename a dir
3263 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3265 + err = vfs_statfs(&br->br_path, &kst);
3266 + if (unlikely(err))
3269 + if (kst.f_namelen >= NAME_MAX)
3270 + err = au_br_init_wh(sb, br, perm);
3272 + pr_err("%pd(%s), unsupported namelen %ld\n",
3274 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3280 +/* initialize a new branch */
3281 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3282 + struct au_opt_add *add)
3285 + struct au_branch *brbase;
3287 + struct inode *h_inode;
3290 + br->br_perm = add->perm;
3291 + br->br_path = add->path; /* set first, path_get() later */
3292 + spin_lock_init(&br->br_dykey_lock);
3293 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3294 + au_lcnt_init(&br->br_count, /*release*/NULL);
3295 + br->br_id = au_new_br_id(sb);
3296 + AuDebugOn(br->br_id < 0);
3298 + /* always, regardless the given option */
3299 + err = au_dr_br_init(sb, br, &add->path);
3300 + if (unlikely(err))
3303 + if (au_br_writable(add->perm)) {
3304 + err = au_wbr_init(br, sb, add->perm);
3305 + if (unlikely(err))
3309 + if (au_opt_test(au_mntflags(sb), XINO)) {
3310 + brbase = au_sbr(sb, 0);
3311 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3313 + h_inode = d_inode(add->path.dentry);
3314 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3315 + if (unlikely(err)) {
3316 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3321 + sysaufs_br_init(br);
3322 + path_get(&br->br_path);
3323 + goto out; /* success */
3326 + memset(&br->br_path, 0, sizeof(br->br_path));
3331 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3332 + struct au_branch *br, aufs_bindex_t bbot,
3333 + aufs_bindex_t amount)
3335 + struct au_branch **brp;
3337 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3339 + brp = sbinfo->si_branch + bindex;
3340 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3342 + sbinfo->si_bbot++;
3343 + if (unlikely(bbot < 0))
3344 + sbinfo->si_bbot = 0;
3347 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3348 + aufs_bindex_t bbot, aufs_bindex_t amount)
3350 + struct au_hdentry *hdp;
3352 + AuRwMustWriteLock(&dinfo->di_rwsem);
3354 + hdp = au_hdentry(dinfo, bindex);
3355 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3356 + au_h_dentry_init(hdp);
3358 + if (unlikely(bbot < 0))
3359 + dinfo->di_btop = 0;
3362 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3363 + aufs_bindex_t bbot, aufs_bindex_t amount)
3365 + struct au_hinode *hip;
3367 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3369 + hip = au_hinode(iinfo, bindex);
3370 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3371 + au_hinode_init(hip);
3373 + if (unlikely(bbot < 0))
3374 + iinfo->ii_btop = 0;
3377 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3378 + aufs_bindex_t bindex)
3380 + struct dentry *root, *h_dentry;
3381 + struct inode *root_inode, *h_inode;
3382 + aufs_bindex_t bbot, amount;
3384 + root = sb->s_root;
3385 + root_inode = d_inode(root);
3386 + bbot = au_sbbot(sb);
3387 + amount = bbot + 1 - bindex;
3388 + h_dentry = au_br_dentry(br);
3389 + au_sbilist_lock();
3390 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3391 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3392 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3393 + au_set_h_dptr(root, bindex, dget(h_dentry));
3394 + h_inode = d_inode(h_dentry);
3395 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3396 + au_sbilist_unlock();
3399 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3402 + aufs_bindex_t bbot, add_bindex;
3403 + struct dentry *root, *h_dentry;
3404 + struct inode *root_inode;
3405 + struct au_branch *add_branch;
3407 + root = sb->s_root;
3408 + root_inode = d_inode(root);
3409 + IMustLock(root_inode);
3410 + IiMustWriteLock(root_inode);
3411 + err = test_add(sb, add, remount);
3412 + if (unlikely(err < 0))
3416 + goto out; /* success */
3419 + bbot = au_sbbot(sb);
3420 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3421 + err = PTR_ERR(add_branch);
3422 + if (IS_ERR(add_branch))
3425 + err = au_br_init(add_branch, sb, add);
3426 + if (unlikely(err)) {
3427 + au_br_do_free(add_branch);
3431 + add_bindex = add->bindex;
3432 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3433 + au_br_do_add(sb, add_branch, add_bindex);
3434 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3435 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3437 + h_dentry = add->path.dentry;
3438 + if (!add_bindex) {
3439 + au_cpup_attr_all(root_inode, /*force*/1);
3440 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3442 + au_add_nlink(root_inode, d_inode(h_dentry));
3448 +/* ---------------------------------------------------------------------- */
3450 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3451 + unsigned long long max __maybe_unused,
3454 + unsigned long long n;
3455 + struct file **p, *f;
3456 + struct hlist_bl_head *files;
3457 + struct hlist_bl_node *pos;
3458 + struct au_finfo *finfo;
3462 + files = &au_sbi(sb)->si_files;
3463 + hlist_bl_lock(files);
3464 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3465 + f = finfo->fi_file;
3467 + && !special_file(file_inode(f)->i_mode)) {
3471 + AuDebugOn(n > max);
3474 + hlist_bl_unlock(files);
3479 +static struct file **au_farray_alloc(struct super_block *sb,
3480 + unsigned long long *max)
3482 + struct au_sbinfo *sbi;
3485 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3486 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3489 +static void au_farray_free(struct file **a, unsigned long long max)
3491 + unsigned long long ull;
3493 + for (ull = 0; ull < max; ull++)
3499 +/* ---------------------------------------------------------------------- */
3505 +/* to show the line number, do not make it inlined function */
3506 +#define AuVerbose(do_info, fmt, ...) do { \
3508 + pr_info(fmt, ##__VA_ARGS__); \
3511 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3512 + aufs_bindex_t bbot)
3514 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3517 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3518 + aufs_bindex_t bbot)
3520 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3524 + * test if the branch is deletable or not.
3526 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3527 + unsigned int sigen, const unsigned int verbose)
3529 + int err, i, j, ndentry;
3530 + aufs_bindex_t btop, bbot;
3531 + struct au_dcsub_pages dpages;
3532 + struct au_dpage *dpage;
3535 + err = au_dpages_init(&dpages, GFP_NOFS);
3536 + if (unlikely(err))
3538 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3539 + if (unlikely(err))
3542 + for (i = 0; !err && i < dpages.ndpage; i++) {
3543 + dpage = dpages.dpages + i;
3544 + ndentry = dpage->ndentry;
3545 + for (j = 0; !err && j < ndentry; j++) {
3546 + d = dpage->dentries[j];
3547 + AuDebugOn(au_dcount(d) <= 0);
3548 + if (!au_digen_test(d, sigen)) {
3549 + di_read_lock_child(d, AuLock_IR);
3550 + if (unlikely(au_dbrange_test(d))) {
3551 + di_read_unlock(d, AuLock_IR);
3555 + di_write_lock_child(d);
3556 + if (unlikely(au_dbrange_test(d))) {
3557 + di_write_unlock(d);
3560 + err = au_reval_dpath(d, sigen);
3562 + di_downgrade_lock(d, AuLock_IR);
3564 + di_write_unlock(d);
3569 + /* AuDbgDentry(d); */
3570 + btop = au_dbtop(d);
3571 + bbot = au_dbbot(d);
3572 + if (btop <= bindex
3574 + && au_h_dptr(d, bindex)
3575 + && au_test_dbusy(d, btop, bbot)) {
3577 + AuVerbose(verbose, "busy %pd\n", d);
3580 + di_read_unlock(d, AuLock_IR);
3585 + au_dpages_free(&dpages);
3590 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3591 + unsigned int sigen, const unsigned int verbose)
3594 + unsigned long long max, ull;
3595 + struct inode *i, **array;
3596 + aufs_bindex_t btop, bbot;
3598 + array = au_iarray_alloc(sb, &max);
3599 + err = PTR_ERR(array);
3600 + if (IS_ERR(array))
3604 + AuDbg("b%d\n", bindex);
3605 + for (ull = 0; !err && ull < max; ull++) {
3609 + if (i->i_ino == AUFS_ROOT_INO)
3612 + /* AuDbgInode(i); */
3613 + if (au_iigen(i, NULL) == sigen)
3614 + ii_read_lock_child(i);
3616 + ii_write_lock_child(i);
3617 + err = au_refresh_hinode_self(i);
3620 + ii_downgrade_lock(i);
3622 + ii_write_unlock(i);
3627 + btop = au_ibtop(i);
3628 + bbot = au_ibbot(i);
3629 + if (btop <= bindex
3631 + && au_h_iptr(i, bindex)
3632 + && au_test_ibusy(i, btop, bbot)) {
3634 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3637 + ii_read_unlock(i);
3639 + au_iarray_free(array, max);
3645 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3646 + const unsigned int verbose)
3649 + unsigned int sigen;
3651 + sigen = au_sigen(root->d_sb);
3652 + DiMustNoWaiters(root);
3653 + IiMustNoWaiters(d_inode(root));
3654 + di_write_unlock(root);
3655 + err = test_dentry_busy(root, bindex, sigen, verbose);
3657 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3658 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3663 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3664 + struct file **to_free, int *idx)
3667 + unsigned char matched, root;
3668 + aufs_bindex_t bindex, bbot;
3669 + struct au_fidir *fidir;
3670 + struct au_hfile *hfile;
3673 + root = IS_ROOT(file->f_path.dentry);
3676 + to_free[*idx] = file;
3682 + fidir = au_fi(file)->fi_hdir;
3683 + AuDebugOn(!fidir);
3684 + bbot = au_fbbot_dir(file);
3685 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3686 + hfile = fidir->fd_hfile + bindex;
3687 + if (!hfile->hf_file)
3690 + if (hfile->hf_br->br_id == br_id) {
3702 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3703 + struct file **to_free, int opened)
3706 + unsigned long long ull, max;
3707 + aufs_bindex_t btop;
3708 + struct file *file, **array;
3709 + struct dentry *root;
3710 + struct au_hfile *hfile;
3712 + array = au_farray_alloc(sb, &max);
3713 + err = PTR_ERR(array);
3714 + if (IS_ERR(array))
3719 + root = sb->s_root;
3720 + di_write_unlock(root);
3721 + for (ull = 0; ull < max; ull++) {
3722 + file = array[ull];
3723 + if (unlikely(!file))
3726 + /* AuDbg("%pD\n", file); */
3727 + fi_read_lock(file);
3728 + btop = au_fbtop(file);
3729 + if (!d_is_dir(file->f_path.dentry)) {
3730 + hfile = &au_fi(file)->fi_htop;
3731 + if (hfile->hf_br->br_id == br_id)
3734 + err = test_dir_busy(file, br_id, to_free, &idx);
3735 + fi_read_unlock(file);
3736 + if (unlikely(err))
3739 + di_write_lock_child(root);
3740 + au_farray_free(array, max);
3741 + AuDebugOn(idx > opened);
3747 +static void br_del_file(struct file **to_free, unsigned long long opened,
3748 + aufs_bindex_t br_id)
3750 + unsigned long long ull;
3751 + aufs_bindex_t bindex, btop, bbot, bfound;
3752 + struct file *file;
3753 + struct au_fidir *fidir;
3754 + struct au_hfile *hfile;
3756 + for (ull = 0; ull < opened; ull++) {
3757 + file = to_free[ull];
3758 + if (unlikely(!file))
3761 + /* AuDbg("%pD\n", file); */
3762 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3764 + fidir = au_fi(file)->fi_hdir;
3765 + AuDebugOn(!fidir);
3766 + fi_write_lock(file);
3767 + btop = au_fbtop(file);
3768 + bbot = au_fbbot_dir(file);
3769 + for (bindex = btop; bindex <= bbot; bindex++) {
3770 + hfile = fidir->fd_hfile + bindex;
3771 + if (!hfile->hf_file)
3774 + if (hfile->hf_br->br_id == br_id) {
3779 + AuDebugOn(bfound < 0);
3780 + au_set_h_fptr(file, bfound, NULL);
3781 + if (bfound == btop) {
3782 + for (btop++; btop <= bbot; btop++)
3783 + if (au_hf_dir(file, btop)) {
3784 + au_set_fbtop(file, btop);
3788 + fi_write_unlock(file);
3792 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3793 + const aufs_bindex_t bindex,
3794 + const aufs_bindex_t bbot)
3796 + struct au_branch **brp, **p;
3798 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3800 + brp = sbinfo->si_branch + bindex;
3801 + if (bindex < bbot)
3802 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3803 + sbinfo->si_branch[0 + bbot] = NULL;
3804 + sbinfo->si_bbot--;
3806 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3809 + sbinfo->si_branch = p;
3810 + /* harmless error */
3813 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3814 + const aufs_bindex_t bbot)
3816 + struct au_hdentry *hdp, *p;
3818 + AuRwMustWriteLock(&dinfo->di_rwsem);
3820 + hdp = au_hdentry(dinfo, bindex);
3821 + if (bindex < bbot)
3822 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3823 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3826 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3829 + dinfo->di_hdentry = p;
3830 + /* harmless error */
3833 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3834 + const aufs_bindex_t bbot)
3836 + struct au_hinode *hip, *p;
3838 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3840 + hip = au_hinode(iinfo, bindex);
3841 + if (bindex < bbot)
3842 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3843 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3846 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3849 + iinfo->ii_hinode = p;
3850 + /* harmless error */
3853 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3854 + struct au_branch *br)
3856 + aufs_bindex_t bbot;
3857 + struct au_sbinfo *sbinfo;
3858 + struct dentry *root, *h_root;
3859 + struct inode *inode, *h_inode;
3860 + struct au_hinode *hinode;
3862 + SiMustWriteLock(sb);
3864 + root = sb->s_root;
3865 + inode = d_inode(root);
3866 + sbinfo = au_sbi(sb);
3867 + bbot = sbinfo->si_bbot;
3869 + h_root = au_h_dptr(root, bindex);
3870 + hinode = au_hi(inode, bindex);
3871 + h_inode = au_igrab(hinode->hi_inode);
3874 + au_sbilist_lock();
3875 + au_br_do_del_brp(sbinfo, bindex, bbot);
3876 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3877 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3878 + au_sbilist_unlock();
3880 + /* ignore an error */
3881 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3885 + au_br_do_free(br);
3888 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3889 + unsigned long long max, void *arg)
3894 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3897 + unsigned long long opened;
3898 + unsigned int mnt_flags;
3899 + aufs_bindex_t bindex, bbot, br_id;
3900 + unsigned char do_wh, verbose;
3901 + struct au_branch *br;
3902 + struct au_wbr *wbr;
3903 + struct dentry *root;
3904 + struct file **to_free;
3909 + root = sb->s_root;
3910 + bindex = au_find_dbindex(root, del->h_path.dentry);
3913 + goto out; /* success */
3915 + pr_err("%s no such branch\n", del->pathname);
3918 + AuDbg("bindex b%d\n", bindex);
3921 + mnt_flags = au_mntflags(sb);
3922 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3923 + bbot = au_sbbot(sb);
3924 + if (unlikely(!bbot)) {
3925 + AuVerbose(verbose, "no more branches left\n");
3929 + br = au_sbr(sb, bindex);
3930 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3931 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3932 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3936 + br_id = br->br_id;
3937 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3938 + if (unlikely(opened)) {
3939 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3940 + err = PTR_ERR(to_free);
3941 + if (IS_ERR(to_free))
3944 + err = test_file_busy(sb, br_id, to_free, opened);
3945 + if (unlikely(err)) {
3946 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3952 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3954 + /* instead of WbrWhMustWriteLock(wbr) */
3955 + SiMustWriteLock(sb);
3956 + for (i = 0; i < AuBrWh_Last; i++) {
3957 + dput(wbr->wbr_wh[i]);
3958 + wbr->wbr_wh[i] = NULL;
3962 + err = test_children_busy(root, bindex, verbose);
3963 + if (unlikely(err)) {
3972 + * now we confirmed the branch is deletable.
3973 + * let's free the remaining opened dirs on the branch.
3975 + di_write_unlock(root);
3976 + br_del_file(to_free, opened, br_id);
3977 + di_write_lock_child(root);
3980 + sysaufs_brs_del(sb, bindex); /* remove successors */
3981 + dbgaufs_xino_del(br); /* remove one */
3982 + au_br_do_del(sb, bindex, br);
3983 + sysaufs_brs_add(sb, bindex); /* append successors */
3984 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3987 + au_cpup_attr_all(d_inode(root), /*force*/1);
3988 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3990 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3991 + if (au_opt_test(mnt_flags, PLINK))
3992 + au_plink_half_refresh(sb, br_id);
3994 + goto out; /* success */
3998 + rerr = au_br_init_wh(sb, br, br->br_perm);
4000 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4001 + del->pathname, rerr);
4004 + au_farray_free(to_free, opened);
4008 +/* ---------------------------------------------------------------------- */
4010 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4013 + aufs_bindex_t btop, bbot;
4014 + struct aufs_ibusy ibusy;
4015 + struct inode *inode, *h_inode;
4018 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4021 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4023 + /* VERIFY_WRITE */
4024 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4025 + if (unlikely(err)) {
4032 + si_read_lock(sb, AuLock_FLUSH);
4033 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4037 + ibusy.h_ino = 0; /* invalid */
4038 + inode = ilookup(sb, ibusy.ino);
4040 + || inode->i_ino == AUFS_ROOT_INO
4041 + || au_is_bad_inode(inode))
4044 + ii_read_lock_child(inode);
4045 + btop = au_ibtop(inode);
4046 + bbot = au_ibbot(inode);
4047 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4048 + h_inode = au_h_iptr(inode, ibusy.bindex);
4049 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4050 + ibusy.h_ino = h_inode->i_ino;
4052 + ii_read_unlock(inode);
4056 + si_read_unlock(sb);
4058 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4059 + if (unlikely(err)) {
4068 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4070 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4073 +#ifdef CONFIG_COMPAT
4074 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4076 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4080 +/* ---------------------------------------------------------------------- */
4083 + * change a branch permission
4086 +static void au_warn_ima(void)
4089 + /* since it doesn't support mark_files_ro() */
4090 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4094 +static int do_need_sigen_inc(int a, int b)
4096 + return au_br_whable(a) && !au_br_whable(b);
4099 +static int need_sigen_inc(int old, int new)
4101 + return do_need_sigen_inc(old, new)
4102 + || do_need_sigen_inc(new, old);
4105 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4108 + unsigned int mnt_flags;
4109 + unsigned long long ull, max;
4110 + aufs_bindex_t br_id;
4111 + unsigned char verbose, writer;
4112 + struct file *file, *hf, **array;
4113 + struct au_hfile *hfile;
4114 + struct inode *h_inode;
4116 + mnt_flags = au_mntflags(sb);
4117 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4119 + array = au_farray_alloc(sb, &max);
4120 + err = PTR_ERR(array);
4121 + if (IS_ERR(array))
4125 + br_id = au_sbr_id(sb, bindex);
4126 + for (ull = 0; ull < max; ull++) {
4127 + file = array[ull];
4128 + if (unlikely(!file))
4131 + /* AuDbg("%pD\n", file); */
4132 + fi_read_lock(file);
4133 + if (unlikely(au_test_mmapped(file))) {
4135 + AuVerbose(verbose, "mmapped %pD\n", file);
4137 + FiMustNoWaiters(file);
4138 + fi_read_unlock(file);
4142 + hfile = &au_fi(file)->fi_htop;
4143 + hf = hfile->hf_file;
4144 + if (!d_is_reg(file->f_path.dentry)
4145 + || !(file->f_mode & FMODE_WRITE)
4146 + || hfile->hf_br->br_id != br_id
4147 + || !(hf->f_mode & FMODE_WRITE))
4148 + array[ull] = NULL;
4154 + FiMustNoWaiters(file);
4155 + fi_read_unlock(file);
4163 + for (ull = 0; ull < max; ull++) {
4164 + file = array[ull];
4168 + /* todo: already flushed? */
4170 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4171 + * approach which resets f_mode and calls mnt_drop_write() and
4172 + * file_release_write() for each file, because the branch
4173 + * attribute in aufs world is totally different from the native
4176 + /* fi_read_lock(file); */
4177 + hfile = &au_fi(file)->fi_htop;
4178 + hf = hfile->hf_file;
4179 + /* fi_read_unlock(file); */
4180 + spin_lock(&hf->f_lock);
4181 + writer = !!(hf->f_mode & FMODE_WRITER);
4182 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4183 + spin_unlock(&hf->f_lock);
4185 + h_inode = file_inode(hf);
4186 + if (hf->f_mode & FMODE_READ)
4187 + i_readcount_inc(h_inode);
4188 + put_write_access(h_inode);
4189 + __mnt_drop_write(hf->f_path.mnt);
4194 + au_farray_free(array, max);
4200 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4204 + aufs_bindex_t bindex;
4205 + struct dentry *root;
4206 + struct au_branch *br;
4207 + struct au_br_fhsm *bf;
4209 + root = sb->s_root;
4210 + bindex = au_find_dbindex(root, mod->h_root);
4213 + return 0; /* success */
4215 + pr_err("%s no such branch\n", mod->path);
4218 + AuDbg("bindex b%d\n", bindex);
4220 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4221 + if (unlikely(err))
4224 + br = au_sbr(sb, bindex);
4225 + AuDebugOn(mod->h_root != au_br_dentry(br));
4226 + if (br->br_perm == mod->perm)
4227 + return 0; /* success */
4229 + /* pre-allocate for non-fhsm --> fhsm */
4231 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4232 + err = au_fhsm_br_alloc(br);
4233 + if (unlikely(err))
4236 + br->br_fhsm = NULL;
4239 + if (au_br_writable(br->br_perm)) {
4240 + /* remove whiteout base */
4241 + err = au_br_init_wh(sb, br, mod->perm);
4242 + if (unlikely(err))
4245 + if (!au_br_writable(mod->perm)) {
4246 + /* rw --> ro, file might be mmapped */
4247 + DiMustNoWaiters(root);
4248 + IiMustNoWaiters(d_inode(root));
4249 + di_write_unlock(root);
4250 + err = au_br_mod_files_ro(sb, bindex);
4251 + /* aufs_write_lock() calls ..._child() */
4252 + di_write_lock_child(root);
4254 + if (unlikely(err)) {
4256 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4259 + rerr = au_wbr_init(br, sb, br->br_perm);
4260 + if (unlikely(rerr)) {
4261 + AuIOErr("nested error %d (%d)\n",
4263 + br->br_perm = mod->perm;
4267 + } else if (au_br_writable(mod->perm)) {
4270 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4272 + err = au_wbr_init(br, sb, mod->perm);
4273 + if (unlikely(err)) {
4274 + au_kfree_rcu(br->br_wbr);
4275 + br->br_wbr = NULL;
4279 + if (unlikely(err))
4282 + if (au_br_fhsm(br->br_perm)) {
4283 + if (!au_br_fhsm(mod->perm)) {
4284 + /* fhsm --> non-fhsm */
4285 + au_br_fhsm_fin(br->br_fhsm);
4286 + au_kfree_rcu(br->br_fhsm);
4287 + br->br_fhsm = NULL;
4289 + } else if (au_br_fhsm(mod->perm))
4290 + /* non-fhsm --> fhsm */
4293 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4294 + br->br_perm = mod->perm;
4295 + goto out; /* success */
4298 + au_kfree_try_rcu(bf);
4304 +/* ---------------------------------------------------------------------- */
4306 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4309 + struct kstatfs kstfs;
4311 + err = vfs_statfs(&br->br_path, &kstfs);
4313 + stfs->f_blocks = kstfs.f_blocks;
4314 + stfs->f_bavail = kstfs.f_bavail;
4315 + stfs->f_files = kstfs.f_files;
4316 + stfs->f_ffree = kstfs.f_ffree;
4321 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4322 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4323 +++ linux/fs/aufs/branch.h 2023-09-03 02:21:58.856637674 +0200
4325 +/* SPDX-License-Identifier: GPL-2.0 */
4327 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4329 + * This program is free software; you can redistribute it and/or modify
4330 + * it under the terms of the GNU General Public License as published by
4331 + * the Free Software Foundation; either version 2 of the License, or
4332 + * (at your option) any later version.
4334 + * This program is distributed in the hope that it will be useful,
4335 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4336 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4337 + * GNU General Public License for more details.
4339 + * You should have received a copy of the GNU General Public License
4340 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4344 + * branch filesystems and xino for them
4347 +#ifndef __AUFS_BRANCH_H__
4348 +#define __AUFS_BRANCH_H__
4352 +#include <linux/mount.h>
4353 +#include "dirren.h"
4359 +/* ---------------------------------------------------------------------- */
4363 + struct file **xi_file;
4364 + unsigned int xi_nfile;
4370 + /* reserved for future use */
4371 + /* unsigned long *bitmap; */
4372 + wait_queue_head_t wqh;
4375 + struct mutex xi_mtx; /* protects xi_file array */
4376 + struct hlist_bl_head xi_writing;
4378 + atomic_t xi_truncating;
4380 + struct kref xi_kref;
4383 +/* File-based Hierarchical Storage Management */
4384 +struct au_br_fhsm {
4385 +#ifdef CONFIG_AUFS_FHSM
4386 + struct mutex bf_lock;
4387 + unsigned long bf_jiffy;
4388 + struct aufs_stfs bf_stfs;
4393 +/* members for writable branch only */
4394 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4396 + struct au_rwsem wbr_wh_rwsem;
4397 + struct dentry *wbr_wh[AuBrWh_Last];
4398 + atomic_t wbr_wh_running;
4399 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4400 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4401 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4404 + unsigned long long wbr_bytes;
4407 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4408 +#define AuBrDynOp (AuDyLast * 4)
4410 +#ifdef CONFIG_AUFS_HFSNOTIFY
4411 +/* support for asynchronous destruction */
4412 +struct au_br_hfsnotify {
4413 + struct fsnotify_group *hfsn_group;
4417 +/* sysfs entries */
4418 +struct au_brsysfs {
4420 + struct attribute attr;
4429 +/* protected by superblock rwsem */
4431 + struct au_xino *br_xino;
4433 + aufs_bindex_t br_id;
4436 + struct path br_path;
4437 + spinlock_t br_dykey_lock;
4438 + struct au_dykey *br_dykey[AuBrDynOp];
4439 + au_lcnt_t br_nfiles; /* opened files */
4440 + au_lcnt_t br_count; /* in-use for other */
4442 + struct au_wbr *br_wbr;
4443 + struct au_br_fhsm *br_fhsm;
4445 +#ifdef CONFIG_AUFS_HFSNOTIFY
4446 + struct au_br_hfsnotify *br_hfsn;
4449 +#ifdef CONFIG_SYSFS
4450 + /* entries under sysfs per mount-point */
4451 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4454 +#ifdef CONFIG_DEBUG_FS
4455 + struct dentry *br_dbgaufs; /* xino */
4458 + struct au_dr_br br_dirren;
4461 +/* ---------------------------------------------------------------------- */
4463 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4465 + return br->br_path.mnt;
4468 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4470 + return br->br_path.dentry;
4473 +static inline struct mnt_idmap *au_br_idmap(struct au_branch *br)
4475 + return mnt_idmap(br->br_path.mnt);
4478 +static inline struct super_block *au_br_sb(struct au_branch *br)
4480 + return au_br_mnt(br)->mnt_sb;
4483 +static inline int au_br_rdonly(struct au_branch *br)
4485 + return (sb_rdonly(au_br_sb(br))
4486 + || !au_br_writable(br->br_perm))
4490 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4492 +#ifdef CONFIG_AUFS_HNOTIFY
4493 + return !(brperm & AuBrPerm_RR);
4499 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4501 + int err, exec_flag;
4504 + exec_flag = oflag & __FMODE_EXEC;
4505 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4511 +static inline void au_xino_get(struct au_branch *br)
4513 + struct au_xino *xi;
4517 + kref_get(&xi->xi_kref);
4520 +static inline int au_xino_count(struct au_branch *br)
4523 + struct au_xino *xi;
4528 + v = kref_read(&xi->xi_kref);
4533 +/* ---------------------------------------------------------------------- */
4537 +void au_br_free(struct au_sbinfo *sinfo);
4538 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4540 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4542 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4543 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4544 +#ifdef CONFIG_COMPAT
4545 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4548 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4551 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4554 +static const loff_t au_loff_max = LLONG_MAX;
4556 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4557 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4559 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4560 + struct file *copy_src);
4562 + struct au_xino *xi; /* switch between xino and xigen */
4564 + struct path *base;
4565 + struct file *copy_src;
4567 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4569 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4571 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4573 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4574 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4576 +int au_xib_trunc(struct super_block *sb);
4577 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4579 +struct au_xino *au_xino_alloc(unsigned int nfile);
4580 +int au_xino_put(struct au_branch *br);
4581 +struct file *au_xino_file1(struct au_xino *xi);
4583 +struct au_opt_xino;
4584 +void au_xino_clr(struct super_block *sb);
4585 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4586 +struct file *au_xino_def(struct super_block *sb);
4587 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4588 + struct path *base);
4590 +ino_t au_xino_new_ino(struct super_block *sb);
4591 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4593 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4594 + ino_t h_ino, int idx);
4595 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4598 +int au_xino_path(struct seq_file *seq, struct file *file);
4600 +/* ---------------------------------------------------------------------- */
4602 +/* @idx is signed to accept -1 meaning the first file */
4603 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4605 + struct file *file;
4612 + if (idx < xi->xi_nfile)
4613 + file = xi->xi_file[idx];
4615 + file = au_xino_file1(xi);
4621 +/* ---------------------------------------------------------------------- */
4623 +/* Superblock to branch */
4625 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4627 + return au_sbr(sb, bindex)->br_id;
4631 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4633 + return au_br_mnt(au_sbr(sb, bindex));
4637 +struct mnt_idmap *au_sbr_idmap(struct super_block *sb, aufs_bindex_t bindex)
4639 + return au_br_idmap(au_sbr(sb, bindex));
4643 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4645 + return au_br_sb(au_sbr(sb, bindex));
4648 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4650 + return au_sbr(sb, bindex)->br_perm;
4653 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4655 + return au_br_whable(au_sbr_perm(sb, bindex));
4658 +/* ---------------------------------------------------------------------- */
4660 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4661 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4662 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4663 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4665 +#define wbr_wh_read_trylock_nested(wbr) \
4666 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4667 +#define wbr_wh_write_trylock_nested(wbr) \
4668 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4671 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4672 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4673 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4675 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4676 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4677 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4679 +/* ---------------------------------------------------------------------- */
4681 +#ifdef CONFIG_AUFS_FHSM
4682 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4684 + mutex_init(&brfhsm->bf_lock);
4685 + brfhsm->bf_jiffy = 0;
4686 + brfhsm->bf_readable = 0;
4689 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4691 + mutex_destroy(&brfhsm->bf_lock);
4694 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4695 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4698 +#endif /* __KERNEL__ */
4699 +#endif /* __AUFS_BRANCH_H__ */
4700 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4701 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4702 +++ linux/fs/aufs/conf.mk 2022-11-05 23:02:18.959222617 +0100
4704 +# SPDX-License-Identifier: GPL-2.0
4706 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4710 +AuConfStr += ${1}=${${1}}
4714 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4716 + HNOTIFY HFSNOTIFY \
4728 +$(foreach i, ${AuConfAll}, \
4729 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4731 +AuConfName = ${obj}/conf.str
4732 +${AuConfName}.tmp: FORCE
4733 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4734 +${AuConfName}: ${AuConfName}.tmp
4735 + @diff -q $< $@ > /dev/null 2>&1 || { \
4736 + echo ' GEN ' $@; \
4740 +clean-files += ${AuConfName} ${AuConfName}.tmp
4741 +${obj}/sysfs.o: ${AuConfName}
4743 +-include ${srctree}/${src}/conf_priv.mk
4744 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4745 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4746 +++ linux/fs/aufs/cpup.c 2023-09-03 02:21:58.859971007 +0200
4748 +// SPDX-License-Identifier: GPL-2.0
4750 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4752 + * This program is free software; you can redistribute it and/or modify
4753 + * it under the terms of the GNU General Public License as published by
4754 + * the Free Software Foundation; either version 2 of the License, or
4755 + * (at your option) any later version.
4757 + * This program is distributed in the hope that it will be useful,
4758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4760 + * GNU General Public License for more details.
4762 + * You should have received a copy of the GNU General Public License
4763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4767 + * copy-up functions, see wbr_policy.c for copy-down
4770 +#include <linux/fs_stack.h>
4771 +#include <linux/mm.h>
4772 +#include <linux/task_work.h>
4775 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4777 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4778 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4780 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4782 + dst->i_flags |= iflags & ~mask;
4783 + if (au_test_fs_notime(dst->i_sb))
4784 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4787 +void au_cpup_attr_timesizes(struct inode *inode)
4789 + struct inode *h_inode;
4791 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4792 + fsstack_copy_attr_times(inode, h_inode);
4793 + fsstack_copy_inode_size(inode, h_inode);
4796 +void au_cpup_attr_nlink(struct inode *inode, int force)
4798 + struct inode *h_inode;
4799 + struct super_block *sb;
4800 + aufs_bindex_t bindex, bbot;
4803 + bindex = au_ibtop(inode);
4804 + h_inode = au_h_iptr(inode, bindex);
4806 + && !S_ISDIR(h_inode->i_mode)
4807 + && au_opt_test(au_mntflags(sb), PLINK)
4808 + && au_plink_test(inode))
4812 + * 0 can happen in revalidating.
4813 + * h_inode->i_mutex may not be held here, but it is harmless since once
4814 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4816 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4817 + * the incorrect link count.
4819 + set_nlink(inode, h_inode->i_nlink);
4822 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4823 + * it may includes whplink directory.
4825 + if (S_ISDIR(h_inode->i_mode)) {
4826 + bbot = au_ibbot(inode);
4827 + for (bindex++; bindex <= bbot; bindex++) {
4828 + h_inode = au_h_iptr(inode, bindex);
4830 + au_add_nlink(inode, h_inode);
4835 +void au_cpup_attr_changeable(struct inode *inode)
4837 + struct inode *h_inode;
4839 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4840 + inode->i_mode = h_inode->i_mode;
4841 + inode->i_uid = h_inode->i_uid;
4842 + inode->i_gid = h_inode->i_gid;
4843 + au_cpup_attr_timesizes(inode);
4844 + au_cpup_attr_flags(inode, h_inode->i_flags);
4847 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4849 + struct au_iinfo *iinfo = au_ii(inode);
4851 + IiMustWriteLock(inode);
4853 + iinfo->ii_higen = h_inode->i_generation;
4854 + iinfo->ii_hsb1 = h_inode->i_sb;
4857 +void au_cpup_attr_all(struct inode *inode, int force)
4859 + struct inode *h_inode;
4861 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4862 + au_cpup_attr_changeable(inode);
4863 + if (inode->i_nlink > 0)
4864 + au_cpup_attr_nlink(inode, force);
4865 + inode->i_rdev = h_inode->i_rdev;
4866 + inode->i_blkbits = h_inode->i_blkbits;
4867 + au_cpup_igen(inode, h_inode);
4870 +/* ---------------------------------------------------------------------- */
4872 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4874 +/* keep the timestamps of the parent dir when cpup */
4875 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4876 + struct path *h_path)
4878 + struct inode *h_inode;
4880 + dt->dt_dentry = dentry;
4881 + dt->dt_h_path = *h_path;
4882 + h_inode = d_inode(h_path->dentry);
4883 + dt->dt_atime = h_inode->i_atime;
4884 + dt->dt_mtime = h_inode->i_mtime;
4888 +void au_dtime_revert(struct au_dtime *dt)
4890 + struct iattr attr;
4893 + attr.ia_atime = dt->dt_atime;
4894 + attr.ia_mtime = dt->dt_mtime;
4895 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4896 + | ATTR_ATIME | ATTR_ATIME_SET;
4898 + /* no delegation since this is a directory */
4899 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4900 + if (unlikely(err))
4901 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4904 +/* ---------------------------------------------------------------------- */
4906 +/* internal use only */
4907 +struct au_cpup_reg_attr {
4910 + unsigned int iflags; /* inode->i_flags */
4913 +static noinline_for_stack
4914 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4915 + struct au_cpup_reg_attr *h_src_attr)
4917 + int err, sbits, icex;
4918 + unsigned int mnt_flags;
4919 + unsigned char verbose;
4921 + struct path h_path;
4922 + struct inode *h_isrc, *h_idst;
4923 + struct kstat *h_st;
4924 + struct au_branch *br;
4926 + br = au_sbr(dst->d_sb, bindex);
4927 + h_path.mnt = au_br_mnt(br);
4928 + h_path.dentry = au_h_dptr(dst, bindex);
4929 + h_idst = d_inode(h_path.dentry);
4930 + h_isrc = d_inode(h_src->dentry);
4931 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4932 + | ATTR_ATIME | ATTR_MTIME
4933 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4934 + if (h_src_attr && h_src_attr->valid) {
4935 + h_st = &h_src_attr->st;
4936 + ia.ia_uid = h_st->uid;
4937 + ia.ia_gid = h_st->gid;
4938 + ia.ia_atime = h_st->atime;
4939 + ia.ia_mtime = h_st->mtime;
4940 + if (h_idst->i_mode != h_st->mode
4941 + && !S_ISLNK(h_idst->i_mode)) {
4942 + ia.ia_valid |= ATTR_MODE;
4943 + ia.ia_mode = h_st->mode;
4945 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4946 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4948 + ia.ia_uid = h_isrc->i_uid;
4949 + ia.ia_gid = h_isrc->i_gid;
4950 + ia.ia_atime = h_isrc->i_atime;
4951 + ia.ia_mtime = h_isrc->i_mtime;
4952 + if (h_idst->i_mode != h_isrc->i_mode
4953 + && !S_ISLNK(h_idst->i_mode)) {
4954 + ia.ia_valid |= ATTR_MODE;
4955 + ia.ia_mode = h_isrc->i_mode;
4957 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4958 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4960 + /* no delegation since it is just created */
4961 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4963 + /* is this nfs only? */
4964 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4965 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4966 + ia.ia_mode = h_isrc->i_mode;
4967 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4970 + icex = br->br_perm & AuBrAttr_ICEX;
4972 + mnt_flags = au_mntflags(dst->d_sb);
4973 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4974 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4980 +/* ---------------------------------------------------------------------- */
4982 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4983 + char *buf, unsigned long blksize)
4986 + size_t sz, rbytes, wbytes;
4987 + unsigned char all_zero;
4989 + struct inode *h_inode;
4990 + /* reduce stack usage */
4993 + zp = page_address(ZERO_PAGE(0));
4994 + if (unlikely(!zp))
4995 + return -ENOMEM; /* possible? */
5000 + AuDbg("len %lld\n", len);
5002 + if (len < blksize)
5006 + /* todo: signal_pending? */
5007 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5008 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5011 + if (unlikely(err < 0))
5015 + if (len >= rbytes && rbytes == blksize)
5016 + all_zero = !memcmp(buf, zp, rbytes);
5023 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5025 + /* todo: signal_pending? */
5026 + if (unlikely(err == -EAGAIN || err == -EINTR))
5028 + if (unlikely(err < 0))
5033 + if (unlikely(err < 0))
5039 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5041 + if (unlikely(res < 0))
5048 + /* the last block may be a hole */
5049 + if (!err && all_zero) {
5050 + AuLabel(last hole);
5053 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5054 + /* nfs requires this step to make last hole */
5055 + /* is this only nfs? */
5057 + /* todo: signal_pending? */
5058 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5059 + } while (err == -EAGAIN || err == -EINTR);
5066 + ia->ia_size = dst->f_pos;
5067 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5068 + ia->ia_file = dst;
5069 + h_inode = file_inode(dst);
5070 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5071 + /* no delegation since it is just created */
5072 + err = vfsub_notify_change(&dst->f_path, ia,
5073 + /*delegated*/NULL);
5074 + inode_unlock(h_inode);
5081 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5084 + unsigned long blksize;
5085 + unsigned char do_kfree;
5087 + struct super_block *h_sb;
5090 + h_sb = file_inode(dst)->i_sb;
5091 + blksize = h_sb->s_blocksize;
5092 + if (!blksize || PAGE_SIZE < blksize)
5093 + blksize = PAGE_SIZE;
5094 + AuDbg("blksize %lu\n", blksize);
5095 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5097 + buf = kmalloc(blksize, GFP_NOFS);
5099 + buf = (void *)__get_free_page(GFP_NOFS);
5100 + if (unlikely(!buf))
5103 + if (len > (1 << 22))
5104 + AuDbg("copying a large file %lld\n", (long long)len);
5108 + err = au_do_copy_file(dst, src, len, buf, blksize);
5110 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5111 + au_kfree_do_rcu(buf);
5113 + free_page((unsigned long)buf);
5119 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5122 + struct super_block *h_src_sb;
5123 + struct inode *h_src_inode;
5125 + h_src_inode = file_inode(src);
5126 + h_src_sb = h_src_inode->i_sb;
5128 + /* XFS acquires inode_lock */
5129 + if (!au_test_xfs(h_src_sb))
5130 + err = au_copy_file(dst, src, len);
5132 + inode_unlock_shared(h_src_inode);
5133 + err = au_copy_file(dst, src, len);
5134 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5140 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5144 + struct super_block *h_src_sb;
5145 + struct inode *h_src_inode;
5147 + h_src_inode = file_inode(src);
5148 + h_src_sb = h_src_inode->i_sb;
5149 + if (h_src_sb != file_inode(dst)->i_sb
5150 + || !dst->f_op->remap_file_range) {
5151 + err = au_do_copy(dst, src, len);
5155 + if (!au_test_nfs(h_src_sb)) {
5156 + inode_unlock_shared(h_src_inode);
5157 + lo = vfsub_clone_file_range(src, dst, len);
5158 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5160 + lo = vfsub_clone_file_range(src, dst, len);
5163 + goto out; /* success */
5164 + } else if (lo >= 0)
5165 + /* todo: possible? */
5166 + /* paritially succeeded */
5167 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5168 + else if (lo != -EOPNOTSUPP) {
5169 + /* older XFS has a condition in cloning */
5174 + /* the backend fs on NFS may not support cloning */
5175 + err = au_do_copy(dst, src, len);
5183 + * to support a sparse file which is opened with O_APPEND,
5184 + * we need to close the file.
5186 +static int au_cp_regular(struct au_cp_generic *cpg)
5189 + enum { SRC, DST };
5191 + aufs_bindex_t bindex;
5192 + unsigned int flags;
5193 + struct dentry *dentry;
5195 + struct file *file;
5198 + .bindex = cpg->bsrc,
5199 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5202 + .bindex = cpg->bdst,
5203 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5204 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5207 + struct au_branch *br;
5208 + struct super_block *sb, *h_src_sb;
5209 + struct inode *h_src_inode;
5210 + struct task_struct *tsk = current;
5212 + /* bsrc branch can be ro/rw. */
5213 + sb = cpg->dentry->d_sb;
5215 + for (i = 0; i < 2; i++, f++) {
5216 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5217 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5218 + /*file*/NULL, f->force_wr);
5219 + if (IS_ERR(f->file)) {
5220 + err = PTR_ERR(f->file);
5228 + /* try stopping to update while we copyup */
5229 + h_src_inode = d_inode(file[SRC].dentry);
5230 + h_src_sb = h_src_inode->i_sb;
5231 + if (!au_test_nfs(h_src_sb))
5232 + IMustLock(h_src_inode);
5233 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5235 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5236 + if (tsk->flags & PF_KTHREAD)
5237 + __fput_sync(file[DST].file);
5239 + /* it happened actually */
5240 + fput(file[DST].file);
5243 + * we have to call both since we don't know which place the file
5247 + flush_delayed_fput();
5249 + br = au_sbr(sb, file[DST].bindex);
5250 + au_lcnt_dec(&br->br_nfiles);
5253 + fput(file[SRC].file);
5254 + br = au_sbr(sb, file[SRC].bindex);
5255 + au_lcnt_dec(&br->br_nfiles);
5260 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5261 + struct au_cpup_reg_attr *h_src_attr)
5265 + struct path h_path;
5266 + struct inode *h_src_inode, *h_dst_inode;
5269 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5270 + l = i_size_read(h_src_inode);
5271 + if (cpg->len == -1 || l < cpg->len)
5274 + /* try stopping to update while we are referencing */
5275 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5276 + au_pin_hdir_unlock(cpg->pin);
5278 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5279 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5280 + h_src_attr->iflags = h_src_inode->i_flags;
5281 + if (!au_test_nfs(h_src_inode->i_sb))
5282 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5284 + inode_unlock_shared(h_src_inode);
5285 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5286 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5288 + if (unlikely(err)) {
5289 + inode_unlock_shared(h_src_inode);
5292 + h_src_attr->valid = 1;
5293 + if (!au_test_nfs(h_src_inode->i_sb)) {
5294 + err = au_cp_regular(cpg);
5295 + inode_unlock_shared(h_src_inode);
5297 + inode_unlock_shared(h_src_inode);
5298 + err = au_cp_regular(cpg);
5300 + rerr = au_pin_hdir_relock(cpg->pin);
5304 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5305 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5306 + h_dst_inode = d_inode(h_path.dentry);
5307 + spin_lock(&h_dst_inode->i_lock);
5308 + h_dst_inode->i_state |= I_LINKABLE;
5309 + spin_unlock(&h_dst_inode->i_lock);
5316 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5317 + struct inode *h_dir)
5320 + DEFINE_DELAYED_CALL(done);
5323 + sym = vfs_get_link(h_src, &done);
5324 + err = PTR_ERR(sym);
5328 + err = vfsub_symlink(h_dir, h_path, sym);
5331 + do_delayed_call(&done);
5336 + * regardless 'acl' option, reset all ACL.
5337 + * All ACL will be copied up later from the original entry on the lower branch.
5339 +static int au_reset_acl(struct path *h_path, umode_t mode)
5342 + struct dentry *h_dentry;
5343 + /* struct inode *h_inode; */
5344 + struct mnt_idmap *h_idmap;
5346 + h_idmap = mnt_idmap(h_path->mnt);
5347 + h_dentry = h_path->dentry;
5348 + /* h_inode = d_inode(h_dentry); */
5349 + /* forget_all_cached_acls(h_inode)); */
5350 + err = vfsub_remove_acl(h_idmap, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5352 + if (err == -EOPNOTSUPP)
5355 + err = vfsub_acl_chmod(h_idmap, h_dentry, mode);
5361 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5362 + struct inode *h_dir, struct path *h_path)
5365 + struct inode *dir, *inode;
5366 + struct mnt_idmap *h_idmap;
5368 + h_idmap = mnt_idmap(h_path->mnt);
5369 + err = vfsub_remove_acl(h_idmap, h_path->dentry,
5370 + XATTR_NAME_POSIX_ACL_DEFAULT);
5372 + if (err == -EOPNOTSUPP)
5374 + if (unlikely(err))
5378 + * strange behaviour from the users view,
5379 + * particularly setattr case
5381 + dir = d_inode(dst_parent);
5382 + if (au_ibtop(dir) == cpg->bdst)
5383 + au_cpup_attr_nlink(dir, /*force*/1);
5384 + inode = d_inode(cpg->dentry);
5385 + au_cpup_attr_nlink(inode, /*force*/1);
5391 +static noinline_for_stack
5392 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5393 + struct au_cpup_reg_attr *h_src_attr)
5397 + unsigned int mnt_flags;
5398 + unsigned char isdir, isreg, force;
5399 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5400 + struct au_dtime dt;
5401 + struct path h_path;
5402 + struct dentry *h_src, *h_dst, *h_parent;
5403 + struct inode *h_inode, *h_dir;
5404 + struct super_block *sb;
5406 + /* bsrc branch can be ro/rw. */
5407 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5408 + h_inode = d_inode(h_src);
5409 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5411 + /* try stopping to be referenced while we are creating */
5412 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5413 + if (au_ftest_cpup(cpg->flags, RENAME))
5414 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5415 + AUFS_WH_PFX_LEN));
5416 + h_parent = h_dst->d_parent; /* dir inode is locked */
5417 + h_dir = d_inode(h_parent);
5419 + AuDebugOn(h_parent != h_dst->d_parent);
5421 + sb = cpg->dentry->d_sb;
5422 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5424 + h_path.dentry = h_parent;
5425 + au_dtime_store(&dt, dst_parent, &h_path);
5427 + h_path.dentry = h_dst;
5431 + mode = h_inode->i_mode;
5432 + switch (mode & S_IFMT) {
5435 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5437 + err = au_do_cpup_regular(cpg, h_src_attr);
5441 + err = vfsub_mkdir(h_dir, &h_path, mode);
5443 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5446 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5450 + AuDebugOn(!capable(CAP_MKNOD));
5454 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5457 + AuIOErr("Unknown inode type 0%o\n", mode);
5461 + err = au_reset_acl(&h_path, mode);
5463 + mnt_flags = au_mntflags(sb);
5464 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5466 + && au_opt_test(mnt_flags, XINO)
5467 + && (h_inode->i_nlink == 1
5468 + || (h_inode->i_state & I_LINKABLE))
5469 + /* todo: unnecessary? */
5470 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5471 + && cpg->bdst < cpg->bsrc
5472 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5473 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5474 + /* ignore this error */
5479 + force = !!cpg->len;
5480 + if (cpg->len == -1)
5481 + force = !!i_size_read(h_inode);
5483 + au_fhsm_wrote(sb, cpg->bdst, force);
5487 + au_dtime_revert(&dt);
5491 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5494 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5495 + struct path h_ppath;
5496 + struct inode *h_dir;
5497 + aufs_bindex_t bdst;
5499 + dentry = cpg->dentry;
5501 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5502 + h_dentry = au_h_dptr(dentry, bdst);
5503 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5505 + au_set_h_dptr(dentry, bdst, NULL);
5506 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5508 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5509 + au_set_h_dptr(dentry, bdst, h_dentry);
5512 + parent = dget_parent(dentry);
5513 + h_ppath.dentry = au_h_dptr(parent, bdst);
5515 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5516 + if (IS_ERR(h_path->dentry))
5517 + err = PTR_ERR(h_path->dentry);
5519 + if (unlikely(err))
5522 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5523 + h_dir = d_inode(h_parent);
5525 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5526 + /* no delegation since it is just created */
5527 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5529 + dput(h_path->dentry);
5536 + * copyup the @dentry from @bsrc to @bdst.
5537 + * the caller must set the both of lower dentries.
5538 + * @len is for truncating when it is -1 copyup the entire file.
5539 + * in link/rename cases, @dst_parent may be different from the real one.
5540 + * basic->bsrc can be larger than basic->bdst.
5541 + * aufs doesn't touch the credential so
5542 + * security_inode_copy_up{,_xattr}() are unnecessary.
5544 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5547 + aufs_bindex_t old_ibtop;
5548 + unsigned char isdir, plink;
5549 + struct dentry *h_src, *h_dst, *h_parent;
5550 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5551 + struct super_block *sb;
5552 + struct au_branch *br;
5553 + struct path h_src_path;
5554 + /* to reduce stack size */
5556 + struct au_dtime dt;
5557 + struct path h_path;
5558 + struct au_cpup_reg_attr h_src_attr;
5562 + a = kmalloc(sizeof(*a), GFP_NOFS);
5565 + a->h_src_attr.valid = 0;
5567 + sb = cpg->dentry->d_sb;
5568 + br = au_sbr(sb, cpg->bdst);
5569 + a->h_path.mnt = au_br_mnt(br);
5570 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5571 + h_parent = h_dst->d_parent; /* dir inode is locked */
5572 + h_dir = d_inode(h_parent);
5575 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5576 + inode = d_inode(cpg->dentry);
5579 + dst_parent = dget_parent(cpg->dentry);
5583 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5584 + dst_inode = au_h_iptr(inode, cpg->bdst);
5586 + if (unlikely(!plink)) {
5588 + AuIOErr("hi%lu(i%lu) exists on b%d "
5589 + "but plink is disabled\n",
5590 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5594 + if (dst_inode->i_nlink) {
5595 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5597 + h_src = au_plink_lkup(inode, cpg->bdst);
5598 + err = PTR_ERR(h_src);
5599 + if (IS_ERR(h_src))
5601 + if (unlikely(d_is_negative(h_src))) {
5603 + AuIOErr("i%lu exists on b%d "
5604 + "but not pseudo-linked\n",
5605 + inode->i_ino, cpg->bdst);
5611 + a->h_path.dentry = h_parent;
5612 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5615 + a->h_path.dentry = h_dst;
5617 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5618 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5619 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5621 + au_dtime_revert(&a->dt);
5622 + if (unlikely(err == -EWOULDBLOCK)) {
5623 + pr_warn("cannot retry for NFSv4 delegation"
5624 + " for an internal link\n");
5630 + /* todo: cpup_wh_file? */
5632 + au_update_ibrange(inode, /*do_put_zero*/1);
5635 + isdir = S_ISDIR(inode->i_mode);
5636 + old_ibtop = au_ibtop(inode);
5637 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5638 + if (unlikely(err))
5640 + dst_inode = d_inode(h_dst);
5641 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5642 + /* todo: necessary? */
5643 + /* au_pin_hdir_unlock(cpg->pin); */
5645 + h_src_path.dentry = h_src;
5646 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5647 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5648 + if (unlikely(err)) {
5649 + /* todo: necessary? */
5650 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5651 + inode_unlock(dst_inode);
5655 + if (cpg->bdst < old_ibtop) {
5656 + if (S_ISREG(inode->i_mode)) {
5657 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5658 + if (unlikely(err)) {
5659 + /* ignore an error */
5660 + /* au_pin_hdir_relock(cpg->pin); */
5661 + inode_unlock(dst_inode);
5665 + au_set_ibtop(inode, cpg->bdst);
5667 + au_set_ibbot(inode, cpg->bdst);
5668 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5669 + au_hi_flags(inode, isdir));
5671 + /* todo: necessary? */
5672 + /* err = au_pin_hdir_relock(cpg->pin); */
5673 + inode_unlock(dst_inode);
5674 + if (unlikely(err))
5677 + src_inode = d_inode(h_src);
5679 + && (src_inode->i_nlink > 1
5680 + || src_inode->i_state & I_LINKABLE)
5682 + au_plink_append(inode, cpg->bdst, h_dst);
5684 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5685 + a->h_path.dentry = h_dst;
5686 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5689 + goto out_parent; /* success */
5693 + a->h_path.dentry = h_parent;
5694 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5695 + a->h_path.dentry = h_dst;
5697 + if (d_is_positive(h_dst)) {
5699 + /* no delegation since it is just created */
5700 + rerr = vfsub_unlink(h_dir, &a->h_path,
5701 + /*delegated*/NULL, /*force*/0);
5703 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5705 + au_dtime_revert(&a->dt);
5707 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5717 +#if 0 /* reserved */
5718 +struct au_cpup_single_args {
5720 + struct au_cp_generic *cpg;
5721 + struct dentry *dst_parent;
5724 +static void au_call_cpup_single(void *args)
5726 + struct au_cpup_single_args *a = args;
5728 + au_pin_hdir_acquire_nest(a->cpg->pin);
5729 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5730 + au_pin_hdir_release(a->cpg->pin);
5735 + * prevent SIGXFSZ in copy-up.
5736 + * testing CAP_MKNOD is for generic fs,
5737 + * but CAP_FSETID is for xfs only, currently.
5739 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5742 + struct super_block *sb;
5743 + struct inode *h_dir;
5746 + sb = au_pinned_parent(pin)->d_sb;
5747 + if (!au_wkq_test()
5748 + && (!au_sbi(sb)->si_plink_maint_pid
5749 + || au_plink_maint(sb, AuLock_NOPLM))) {
5750 + switch (mode & S_IFMT) {
5752 + /* no condition about RLIMIT_FSIZE and the file size */
5757 + do_sio = !capable(CAP_MKNOD);
5761 + do_sio = ((mode & (S_ISUID | S_ISGID))
5762 + && !capable(CAP_FSETID));
5763 + /* this workaround may be removed in the future */
5765 + h_dir = au_pinned_h_dir(pin);
5766 + do_sio = h_dir->i_mode & S_ISVTX;
5773 +#if 0 /* reserved */
5774 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5777 + struct dentry *h_dentry;
5779 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5780 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5781 + err = au_cpup_single(cpg, dst_parent);
5783 + struct au_cpup_single_args args = {
5786 + .dst_parent = dst_parent
5788 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5789 + if (unlikely(wkq_err))
5798 + * copyup the @dentry from the first active lower branch to @bdst,
5799 + * using au_cpup_single().
5801 +static int au_cpup_simple(struct au_cp_generic *cpg)
5804 + unsigned int flags_orig;
5805 + struct dentry *dentry;
5807 + AuDebugOn(cpg->bsrc < 0);
5809 + dentry = cpg->dentry;
5810 + DiMustWriteLock(dentry);
5812 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5814 + flags_orig = cpg->flags;
5815 + au_fset_cpup(cpg->flags, RENAME);
5816 + err = au_cpup_single(cpg, NULL);
5817 + cpg->flags = flags_orig;
5819 + return 0; /* success */
5822 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5823 + au_set_dbtop(dentry, cpg->bsrc);
5829 +struct au_cpup_simple_args {
5831 + struct au_cp_generic *cpg;
5834 +static void au_call_cpup_simple(void *args)
5836 + struct au_cpup_simple_args *a = args;
5838 + au_pin_hdir_acquire_nest(a->cpg->pin);
5839 + *a->errp = au_cpup_simple(a->cpg);
5840 + au_pin_hdir_release(a->cpg->pin);
5843 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5846 + struct dentry *dentry, *parent;
5847 + struct file *h_file;
5848 + struct inode *h_dir;
5849 + struct mnt_idmap *h_idmap;
5851 + dentry = cpg->dentry;
5853 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5854 + AuDebugOn(cpg->bsrc < 0);
5855 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5856 + err = PTR_ERR(h_file);
5857 + if (IS_ERR(h_file))
5861 + parent = dget_parent(dentry);
5862 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5863 + h_idmap = au_sbr_idmap(dentry->d_sb, cpg->bdst);
5864 + if (!au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC | MAY_WRITE)
5865 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5866 + err = au_cpup_simple(cpg);
5868 + struct au_cpup_simple_args args = {
5872 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5873 + if (unlikely(wkq_err))
5879 + au_h_open_post(dentry, cpg->bsrc, h_file);
5885 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5887 + aufs_bindex_t bsrc, bbot;
5888 + struct dentry *dentry, *h_dentry;
5890 + if (cpg->bsrc < 0) {
5891 + dentry = cpg->dentry;
5892 + bbot = au_dbbot(dentry);
5893 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5894 + h_dentry = au_h_dptr(dentry, bsrc);
5896 + AuDebugOn(d_is_negative(h_dentry));
5900 + AuDebugOn(bsrc > bbot);
5903 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5904 + return au_do_sio_cpup_simple(cpg);
5907 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5909 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5910 + return au_do_sio_cpup_simple(cpg);
5913 +/* ---------------------------------------------------------------------- */
5916 + * copyup the deleted file for writing.
5918 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5919 + struct file *file)
5922 + unsigned int flags_orig;
5923 + aufs_bindex_t bsrc_orig;
5924 + struct au_dinfo *dinfo;
5926 + struct au_hdentry *hd;
5927 + struct dentry *h_dentry;
5930 + dinfo = au_di(cpg->dentry);
5931 + AuRwMustWriteLock(&dinfo->di_rwsem);
5933 + bsrc_orig = cpg->bsrc;
5934 + cpg->bsrc = dinfo->di_btop;
5935 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5936 + hdst.h_dentry = hdst.hd->hd_dentry;
5937 + hdst.hd->hd_dentry = wh_dentry;
5938 + dinfo->di_btop = cpg->bdst;
5940 + hsrc.h_dentry = NULL;
5942 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5943 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5944 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5946 + flags_orig = cpg->flags;
5947 + cpg->flags = !AuCpup_DTIME;
5948 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5949 + cpg->flags = flags_orig;
5952 + err = au_reopen_nondir(file);
5953 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5955 + hdst.hd->hd_dentry = hdst.h_dentry;
5956 + dinfo->di_btop = cpg->bsrc;
5957 + cpg->bsrc = bsrc_orig;
5962 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5965 + aufs_bindex_t bdst;
5966 + struct au_dtime dt;
5967 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5968 + struct au_branch *br;
5969 + struct path h_path;
5971 + dentry = cpg->dentry;
5973 + br = au_sbr(dentry->d_sb, bdst);
5974 + parent = dget_parent(dentry);
5975 + h_parent = au_h_dptr(parent, bdst);
5976 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5977 + err = PTR_ERR(wh_dentry);
5978 + if (IS_ERR(wh_dentry))
5981 + h_path.dentry = h_parent;
5982 + h_path.mnt = au_br_mnt(br);
5983 + au_dtime_store(&dt, parent, &h_path);
5984 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5985 + if (unlikely(err))
5989 + h_path.dentry = wh_dentry;
5990 + if (!d_is_dir(wh_dentry)) {
5991 + /* no delegation since it is just created */
5992 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5993 + /*delegated*/NULL, /*force*/0);
5995 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5996 + if (unlikely(err)) {
5997 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6001 + au_dtime_revert(&dt);
6002 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6011 +struct au_cpup_wh_args {
6013 + struct au_cp_generic *cpg;
6014 + struct file *file;
6017 +static void au_call_cpup_wh(void *args)
6019 + struct au_cpup_wh_args *a = args;
6021 + au_pin_hdir_acquire_nest(a->cpg->pin);
6022 + *a->errp = au_cpup_wh(a->cpg, a->file);
6023 + au_pin_hdir_release(a->cpg->pin);
6026 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6029 + aufs_bindex_t bdst;
6030 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6031 + struct inode *dir, *h_dir, *h_tmpdir;
6032 + struct au_wbr *wbr;
6033 + struct au_pin wh_pin, *pin_orig;
6034 + struct mnt_idmap *h_idmap;
6036 + dentry = cpg->dentry;
6038 + parent = dget_parent(dentry);
6039 + dir = d_inode(parent);
6042 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6045 + if (!h_dir->i_nlink) {
6046 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6047 + h_orph = wbr->wbr_orph;
6049 + h_parent = dget(au_h_dptr(parent, bdst));
6050 + au_set_h_dptr(parent, bdst, dget(h_orph));
6051 + h_tmpdir = d_inode(h_orph);
6052 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6054 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6055 + /* todo: au_h_open_pre()? */
6057 + pin_orig = cpg->pin;
6058 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6059 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6060 + cpg->pin = &wh_pin;
6063 + h_idmap = au_sbr_idmap(dentry->d_sb, bdst);
6064 + if (!au_test_h_perm_sio(h_idmap, h_tmpdir, MAY_EXEC | MAY_WRITE)
6065 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6066 + err = au_cpup_wh(cpg, file);
6068 + struct au_cpup_wh_args args = {
6073 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6074 + if (unlikely(wkq_err))
6079 + inode_unlock(h_tmpdir);
6080 + /* todo: au_h_open_post()? */
6081 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6082 + au_set_h_dptr(parent, bdst, h_parent);
6083 + AuDebugOn(!pin_orig);
6084 + cpg->pin = pin_orig;
6092 +/* ---------------------------------------------------------------------- */
6095 + * generic routine for both of copy-up and copy-down.
6097 +/* cf. revalidate function in file.c */
6098 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6099 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6100 + struct au_pin *pin,
6101 + struct dentry *h_parent, void *arg),
6105 + struct au_pin pin;
6106 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6109 + parent = dget_parent(dentry);
6110 + if (IS_ROOT(parent))
6113 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6114 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6116 + /* do not use au_dpage */
6117 + real_parent = parent;
6120 + parent = dget_parent(dentry);
6121 + h_parent = au_h_dptr(parent, bdst);
6123 + goto out; /* success */
6125 + /* find top dir which is necessary to cpup */
6129 + parent = dget_parent(d);
6130 + di_read_lock_parent3(parent, !AuLock_IR);
6131 + h_parent = au_h_dptr(parent, bdst);
6132 + di_read_unlock(parent, !AuLock_IR);
6133 + } while (!h_parent);
6135 + if (d != real_parent)
6136 + di_write_lock_child3(d);
6138 + /* somebody else might create while we were sleeping */
6139 + h_dentry = au_h_dptr(d, bdst);
6140 + if (!h_dentry || d_is_negative(h_dentry)) {
6142 + au_update_dbtop(d);
6144 + au_pin_set_dentry(&pin, d);
6145 + err = au_do_pin(&pin);
6147 + err = cp(d, bdst, &pin, h_parent, arg);
6152 + if (d != real_parent)
6153 + di_write_unlock(d);
6154 + if (unlikely(err))
6163 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6164 + struct au_pin *pin,
6165 + struct dentry *h_parent __maybe_unused,
6166 + void *arg __maybe_unused)
6168 + struct au_cp_generic cpg = {
6174 + .flags = AuCpup_DTIME
6176 + return au_sio_cpup_simple(&cpg);
6179 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6181 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6184 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6187 + struct dentry *parent;
6188 + struct inode *dir;
6190 + parent = dget_parent(dentry);
6191 + dir = d_inode(parent);
6193 + if (au_h_iptr(dir, bdst))
6196 + di_read_unlock(parent, AuLock_IR);
6197 + di_write_lock_parent(parent);
6198 + /* someone else might change our inode while we were sleeping */
6199 + if (!au_h_iptr(dir, bdst))
6200 + err = au_cpup_dirs(dentry, bdst);
6201 + di_downgrade_lock(parent, AuLock_IR);
6207 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6208 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6209 +++ linux/fs/aufs/cpup.h 2022-11-05 23:02:18.962555950 +0100
6211 +/* SPDX-License-Identifier: GPL-2.0 */
6213 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6215 + * This program is free software; you can redistribute it and/or modify
6216 + * it under the terms of the GNU General Public License as published by
6217 + * the Free Software Foundation; either version 2 of the License, or
6218 + * (at your option) any later version.
6220 + * This program is distributed in the hope that it will be useful,
6221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6223 + * GNU General Public License for more details.
6225 + * You should have received a copy of the GNU General Public License
6226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6230 + * copy-up/down functions
6233 +#ifndef __AUFS_CPUP_H__
6234 +#define __AUFS_CPUP_H__
6238 +#include <linux/path.h>
6244 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6245 +void au_cpup_attr_timesizes(struct inode *inode);
6246 +void au_cpup_attr_nlink(struct inode *inode, int force);
6247 +void au_cpup_attr_changeable(struct inode *inode);
6248 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6249 +void au_cpup_attr_all(struct inode *inode, int force);
6251 +/* ---------------------------------------------------------------------- */
6253 +struct au_cp_generic {
6254 + struct dentry *dentry;
6255 + aufs_bindex_t bdst, bsrc;
6257 + struct au_pin *pin;
6258 + unsigned int flags;
6262 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6263 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6265 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6266 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6268 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6270 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6271 + the branch is marked as RO */
6273 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6274 +#undef AuCpup_HOPEN
6275 +#define AuCpup_HOPEN 0
6278 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6279 +#define au_fset_cpup(flags, name) \
6280 + do { (flags) |= AuCpup_##name; } while (0)
6281 +#define au_fclr_cpup(flags, name) \
6282 + do { (flags) &= ~AuCpup_##name; } while (0)
6284 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6285 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6286 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6287 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6289 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6290 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6291 + struct au_pin *pin,
6292 + struct dentry *h_parent, void *arg),
6294 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6295 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6297 +/* ---------------------------------------------------------------------- */
6299 +/* keep timestamps when copyup */
6301 + struct dentry *dt_dentry;
6302 + struct path dt_h_path;
6303 + struct timespec64 dt_atime, dt_mtime;
6305 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6306 + struct path *h_path);
6307 +void au_dtime_revert(struct au_dtime *dt);
6309 +#endif /* __KERNEL__ */
6310 +#endif /* __AUFS_CPUP_H__ */
6311 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6312 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6313 +++ linux/fs/aufs/dbgaufs.c 2022-11-05 23:02:18.962555950 +0100
6315 +// SPDX-License-Identifier: GPL-2.0
6317 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6319 + * This program is free software; you can redistribute it and/or modify
6320 + * it under the terms of the GNU General Public License as published by
6321 + * the Free Software Foundation; either version 2 of the License, or
6322 + * (at your option) any later version.
6324 + * This program is distributed in the hope that it will be useful,
6325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6327 + * GNU General Public License for more details.
6329 + * You should have received a copy of the GNU General Public License
6330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6334 + * debugfs interface
6337 +#include <linux/debugfs.h>
6340 +#ifndef CONFIG_SYSFS
6341 +#error DEBUG_FS depends upon SYSFS
6344 +static struct dentry *dbgaufs;
6345 +static const mode_t dbgaufs_mode = 0444;
6347 +/* 20 is max digits length of ulong 64 */
6348 +struct dbgaufs_arg {
6354 + * common function for all XINO files
6356 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6357 + struct file *file)
6361 + p = file->private_data;
6363 + /* this is struct dbgaufs_arg */
6364 + AuDebugOn(!au_kfree_sz_test(p));
6365 + au_kfree_do_rcu(p);
6370 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6375 + struct dbgaufs_arg *p;
6378 + p = kmalloc(sizeof(*p), GFP_NOFS);
6384 + file->private_data = p;
6388 + err = vfsub_getattr(&xf->f_path, &st);
6392 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6393 + cnt, st.blocks, st.blksize,
6394 + (long long)st.size);
6396 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6397 + st.blocks, st.blksize,
6398 + (long long)st.size);
6399 + AuDebugOn(p->n >= sizeof(p->a));
6401 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6409 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6410 + size_t count, loff_t *ppos)
6412 + struct dbgaufs_arg *p;
6414 + p = file->private_data;
6415 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6418 +/* ---------------------------------------------------------------------- */
6420 +struct dbgaufs_plink_arg {
6425 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6426 + struct file *file)
6428 + free_page((unsigned long)file->private_data);
6432 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6434 + int err, i, limit;
6435 + unsigned long n, sum;
6436 + struct dbgaufs_plink_arg *p;
6437 + struct au_sbinfo *sbinfo;
6438 + struct super_block *sb;
6439 + struct hlist_bl_head *hbl;
6442 + p = (void *)get_zeroed_page(GFP_NOFS);
6447 + sbinfo = inode->i_private;
6448 + sb = sbinfo->si_sb;
6449 + si_noflush_read_lock(sb);
6450 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6451 + limit = PAGE_SIZE - sizeof(p->n);
6453 + /* the number of buckets */
6454 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6459 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6461 + n = au_hbl_count(hbl);
6464 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6467 + if (unlikely(limit <= 0))
6470 + p->a[p->n - 1] = '\n';
6472 + /* the sum of plinks */
6473 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6476 + if (unlikely(limit <= 0))
6479 +#define str "1\n0\n0\n"
6480 + p->n = sizeof(str) - 1;
6481 + strcpy(p->a, str);
6484 + si_read_unlock(sb);
6487 + file->private_data = p;
6488 + goto out; /* success */
6491 + free_page((unsigned long)p);
6496 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6497 + size_t count, loff_t *ppos)
6499 + struct dbgaufs_plink_arg *p;
6501 + p = file->private_data;
6502 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6505 +static const struct file_operations dbgaufs_plink_fop = {
6506 + .owner = THIS_MODULE,
6507 + .open = dbgaufs_plink_open,
6508 + .release = dbgaufs_plink_release,
6509 + .read = dbgaufs_plink_read
6512 +/* ---------------------------------------------------------------------- */
6514 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6517 + struct au_sbinfo *sbinfo;
6518 + struct super_block *sb;
6520 + sbinfo = inode->i_private;
6521 + sb = sbinfo->si_sb;
6522 + si_noflush_read_lock(sb);
6523 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6524 + si_read_unlock(sb);
6528 +static const struct file_operations dbgaufs_xib_fop = {
6529 + .owner = THIS_MODULE,
6530 + .open = dbgaufs_xib_open,
6531 + .release = dbgaufs_xi_release,
6532 + .read = dbgaufs_xi_read
6535 +/* ---------------------------------------------------------------------- */
6537 +#define DbgaufsXi_PREFIX "xi"
6539 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6543 + aufs_bindex_t bindex;
6544 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6545 + struct au_sbinfo *sbinfo;
6546 + struct super_block *sb;
6547 + struct au_xino *xi;
6549 + struct qstr *name;
6550 + struct au_branch *br;
6553 + name = &file->f_path.dentry->d_name;
6554 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6555 + || memcmp(name->name, DbgaufsXi_PREFIX,
6556 + sizeof(DbgaufsXi_PREFIX) - 1)))
6559 + AuDebugOn(name->len >= sizeof(a));
6560 + memcpy(a, name->name, name->len);
6561 + a[name->len] = '\0';
6562 + p = strchr(a, '-');
6565 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6566 + if (unlikely(err))
6571 + err = kstrtol(p + 1, 10, &l);
6572 + if (unlikely(err))
6578 + sbinfo = inode->i_private;
6579 + sb = sbinfo->si_sb;
6580 + si_noflush_read_lock(sb);
6581 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6583 + br = au_sbr(sb, bindex);
6585 + if (unlikely(idx >= xi->xi_nfile))
6587 + xf = au_xino_file(xi, idx);
6589 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6590 + au_xino_count(br));
6593 + si_read_unlock(sb);
6599 +static const struct file_operations dbgaufs_xino_fop = {
6600 + .owner = THIS_MODULE,
6601 + .open = dbgaufs_xino_open,
6602 + .release = dbgaufs_xi_release,
6603 + .read = dbgaufs_xi_read
6606 +void dbgaufs_xino_del(struct au_branch *br)
6608 + struct dentry *dbgaufs;
6610 + dbgaufs = br->br_dbgaufs;
6614 + br->br_dbgaufs = NULL;
6615 + /* debugfs acquires the parent i_mutex */
6617 + debugfs_remove(dbgaufs);
6621 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6623 + aufs_bindex_t bbot;
6624 + struct au_branch *br;
6626 + if (!au_sbi(sb)->si_dbgaufs)
6629 + bbot = au_sbbot(sb);
6630 + for (; bindex <= bbot; bindex++) {
6631 + br = au_sbr(sb, bindex);
6632 + dbgaufs_xino_del(br);
6636 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6637 + unsigned int idx, struct dentry *parent,
6638 + struct au_sbinfo *sbinfo)
6640 + struct au_branch *br;
6642 + /* "xi" bindex(5) "-" idx(2) NULL */
6643 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6646 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6648 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6650 + br = au_sbr(sb, bindex);
6651 + if (br->br_dbgaufs) {
6652 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6654 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6655 + /* debugfs acquires the parent i_mutex */
6657 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6661 + pr_warn("failed renaming %pd/%s, ignored.\n",
6666 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6667 + sbinfo, &dbgaufs_xino_fop);
6669 + if (unlikely(!br->br_dbgaufs))
6670 + pr_warn("failed creating %pd/%s, ignored.\n",
6675 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6676 + struct dentry *parent, struct au_sbinfo *sbinfo)
6678 + struct au_branch *br;
6679 + struct au_xino *xi;
6682 + br = au_sbr(sb, bindex);
6684 + for (u = 0; u < xi->xi_nfile; u++)
6685 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6688 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6690 + struct au_sbinfo *sbinfo;
6691 + struct dentry *parent;
6692 + aufs_bindex_t bbot;
6694 + if (!au_opt_test(au_mntflags(sb), XINO))
6697 + sbinfo = au_sbi(sb);
6698 + parent = sbinfo->si_dbgaufs;
6702 + bbot = au_sbbot(sb);
6704 + for (; bindex <= bbot; bindex++)
6705 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6707 + for (; bbot >= bindex; bbot--)
6708 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6711 +/* ---------------------------------------------------------------------- */
6713 +#ifdef CONFIG_AUFS_EXPORT
6714 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6717 + struct au_sbinfo *sbinfo;
6718 + struct super_block *sb;
6720 + sbinfo = inode->i_private;
6721 + sb = sbinfo->si_sb;
6722 + si_noflush_read_lock(sb);
6723 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6724 + si_read_unlock(sb);
6728 +static const struct file_operations dbgaufs_xigen_fop = {
6729 + .owner = THIS_MODULE,
6730 + .open = dbgaufs_xigen_open,
6731 + .release = dbgaufs_xi_release,
6732 + .read = dbgaufs_xi_read
6735 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6740 + * This function is a dynamic '__init' function actually,
6741 + * so the tiny check for si_rwsem is unnecessary.
6743 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6746 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6747 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6748 + &dbgaufs_xigen_fop);
6749 + if (sbinfo->si_dbgaufs_xigen)
6755 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6759 +#endif /* CONFIG_AUFS_EXPORT */
6761 +/* ---------------------------------------------------------------------- */
6763 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6766 + * This function is a dynamic '__fin' function actually,
6767 + * so the tiny check for si_rwsem is unnecessary.
6769 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6771 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6772 + sbinfo->si_dbgaufs = NULL;
6775 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6778 + char name[SysaufsSiNameLen];
6781 + * This function is a dynamic '__init' function actually,
6782 + * so the tiny check for si_rwsem is unnecessary.
6784 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6788 + AuErr1("/debug/aufs is uninitialized\n");
6793 + sysaufs_name(sbinfo, name);
6794 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6795 + if (unlikely(!sbinfo->si_dbgaufs))
6798 + /* regardless plink/noplink option */
6799 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6800 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6801 + &dbgaufs_plink_fop);
6802 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6805 + /* regardless xino/noxino option */
6806 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6807 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6808 + &dbgaufs_xib_fop);
6809 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6812 + err = dbgaufs_xigen_init(sbinfo);
6814 + goto out; /* success */
6817 + dbgaufs_si_fin(sbinfo);
6819 + if (unlikely(err))
6820 + pr_err("debugfs/aufs failed\n");
6824 +/* ---------------------------------------------------------------------- */
6826 +void dbgaufs_fin(void)
6828 + debugfs_remove(dbgaufs);
6831 +int __init dbgaufs_init(void)
6836 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6841 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6842 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6843 +++ linux/fs/aufs/dbgaufs.h 2022-11-05 23:02:18.962555950 +0100
6845 +/* SPDX-License-Identifier: GPL-2.0 */
6847 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6849 + * This program is free software; you can redistribute it and/or modify
6850 + * it under the terms of the GNU General Public License as published by
6851 + * the Free Software Foundation; either version 2 of the License, or
6852 + * (at your option) any later version.
6854 + * This program is distributed in the hope that it will be useful,
6855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6857 + * GNU General Public License for more details.
6859 + * You should have received a copy of the GNU General Public License
6860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6864 + * debugfs interface
6867 +#ifndef __DBGAUFS_H__
6868 +#define __DBGAUFS_H__
6872 +struct super_block;
6876 +#ifdef CONFIG_DEBUG_FS
6878 +void dbgaufs_xino_del(struct au_branch *br);
6879 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6880 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6881 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6882 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6883 +void dbgaufs_fin(void);
6884 +int __init dbgaufs_init(void);
6886 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6887 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6888 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6890 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6891 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6892 +AuStubVoid(dbgaufs_fin, void)
6893 +AuStubInt0(__init dbgaufs_init, void)
6894 +#endif /* CONFIG_DEBUG_FS */
6896 +#endif /* __KERNEL__ */
6897 +#endif /* __DBGAUFS_H__ */
6898 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6899 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6900 +++ linux/fs/aufs/dcsub.c 2022-11-05 23:02:18.962555950 +0100
6902 +// SPDX-License-Identifier: GPL-2.0
6904 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6906 + * This program is free software; you can redistribute it and/or modify
6907 + * it under the terms of the GNU General Public License as published by
6908 + * the Free Software Foundation; either version 2 of the License, or
6909 + * (at your option) any later version.
6911 + * This program is distributed in the hope that it will be useful,
6912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6914 + * GNU General Public License for more details.
6916 + * You should have received a copy of the GNU General Public License
6917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6921 + * sub-routines for dentry cache
6926 +static void au_dpage_free(struct au_dpage *dpage)
6929 + struct dentry **p;
6931 + p = dpage->dentries;
6932 + for (i = 0; i < dpage->ndentry; i++)
6934 + free_page((unsigned long)dpage->dentries);
6937 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6943 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6944 + if (unlikely(!dpages->dpages))
6947 + p = (void *)__get_free_page(gfp);
6951 + dpages->dpages[0].ndentry = 0;
6952 + dpages->dpages[0].dentries = p;
6953 + dpages->ndpage = 1;
6954 + return 0; /* success */
6957 + au_kfree_try_rcu(dpages->dpages);
6962 +void au_dpages_free(struct au_dcsub_pages *dpages)
6965 + struct au_dpage *p;
6967 + p = dpages->dpages;
6968 + for (i = 0; i < dpages->ndpage; i++)
6969 + au_dpage_free(p++);
6970 + au_kfree_try_rcu(dpages->dpages);
6973 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6974 + struct dentry *dentry, gfp_t gfp)
6977 + struct au_dpage *dpage;
6980 + dpage = dpages->dpages + dpages->ndpage - 1;
6981 + sz = PAGE_SIZE / sizeof(dentry);
6982 + if (unlikely(dpage->ndentry >= sz)) {
6983 + AuLabel(new dpage);
6985 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6986 + p = au_kzrealloc(dpages->dpages, sz,
6987 + sz + sizeof(*dpages->dpages), gfp,
6992 + dpages->dpages = p;
6993 + dpage = dpages->dpages + dpages->ndpage;
6994 + p = (void *)__get_free_page(gfp);
6998 + dpage->ndentry = 0;
6999 + dpage->dentries = p;
7003 + AuDebugOn(au_dcount(dentry) <= 0);
7004 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7005 + return 0; /* success */
7011 +/* todo: BAD approach */
7012 +/* copied from linux/fs/dcache.c */
7020 +extern void d_walk(struct dentry *parent, void *data,
7021 + enum d_walk_ret (*enter)(void *, struct dentry *));
7023 +struct ac_dpages_arg {
7025 + struct au_dcsub_pages *dpages;
7026 + struct super_block *sb;
7027 + au_dpages_test test;
7031 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7033 + enum d_walk_ret ret;
7034 + struct ac_dpages_arg *arg = _arg;
7036 + ret = D_WALK_CONTINUE;
7037 + if (dentry->d_sb == arg->sb
7038 + && !IS_ROOT(dentry)
7039 + && au_dcount(dentry) > 0
7041 + && (!arg->test || arg->test(dentry, arg->arg))) {
7042 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7043 + if (unlikely(arg->err))
7044 + ret = D_WALK_QUIT;
7050 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7051 + au_dpages_test test, void *arg)
7053 + struct ac_dpages_arg args = {
7061 + d_walk(root, &args, au_call_dpages_append);
7066 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7067 + int do_include, au_dpages_test test, void *arg)
7072 + write_seqlock(&rename_lock);
7073 + spin_lock(&dentry->d_lock);
7075 + && au_dcount(dentry) > 0
7076 + && (!test || test(dentry, arg)))
7077 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7078 + spin_unlock(&dentry->d_lock);
7079 + if (unlikely(err))
7083 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7086 + while (!IS_ROOT(dentry)) {
7087 + dentry = dentry->d_parent; /* rename_lock is locked */
7088 + spin_lock(&dentry->d_lock);
7089 + if (au_dcount(dentry) > 0
7090 + && (!test || test(dentry, arg)))
7091 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7092 + spin_unlock(&dentry->d_lock);
7093 + if (unlikely(err))
7098 + write_sequnlock(&rename_lock);
7102 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7104 + return au_di(dentry) && dentry->d_sb == arg;
7107 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7108 + struct dentry *dentry, int do_include)
7110 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7111 + au_dcsub_dpages_aufs, dentry->d_sb);
7114 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7116 + struct path path[2] = {
7125 + return path_is_under(path + 0, path + 1);
7127 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7128 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7129 +++ linux/fs/aufs/dcsub.h 2022-11-05 23:02:18.962555950 +0100
7131 +/* SPDX-License-Identifier: GPL-2.0 */
7133 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7135 + * This program is free software; you can redistribute it and/or modify
7136 + * it under the terms of the GNU General Public License as published by
7137 + * the Free Software Foundation; either version 2 of the License, or
7138 + * (at your option) any later version.
7140 + * This program is distributed in the hope that it will be useful,
7141 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7142 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7143 + * GNU General Public License for more details.
7145 + * You should have received a copy of the GNU General Public License
7146 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7150 + * sub-routines for dentry cache
7153 +#ifndef __AUFS_DCSUB_H__
7154 +#define __AUFS_DCSUB_H__
7158 +#include <linux/dcache.h>
7159 +#include <linux/fs.h>
7163 + struct dentry **dentries;
7166 +struct au_dcsub_pages {
7168 + struct au_dpage *dpages;
7171 +/* ---------------------------------------------------------------------- */
7174 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7175 +void au_dpages_free(struct au_dcsub_pages *dpages);
7176 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7177 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7178 + au_dpages_test test, void *arg);
7179 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7180 + int do_include, au_dpages_test test, void *arg);
7181 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7182 + struct dentry *dentry, int do_include);
7183 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7185 +/* ---------------------------------------------------------------------- */
7188 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7189 + * include/linux/dcache.h. Try them (in the future).
7192 +static inline int au_d_hashed_positive(struct dentry *d)
7195 + struct inode *inode = d_inode(d);
7198 + if (unlikely(d_unhashed(d)
7199 + || d_is_negative(d)
7200 + || !inode->i_nlink))
7205 +static inline int au_d_linkable(struct dentry *d)
7208 + struct inode *inode = d_inode(d);
7210 + err = au_d_hashed_positive(d);
7212 + && d_is_positive(d)
7213 + && (inode->i_state & I_LINKABLE))
7218 +static inline int au_d_alive(struct dentry *d)
7221 + struct inode *inode;
7225 + err = au_d_hashed_positive(d);
7227 + inode = d_inode(d);
7228 + if (unlikely(d_unlinked(d)
7229 + || d_is_negative(d)
7230 + || !inode->i_nlink))
7236 +static inline int au_alive_dir(struct dentry *d)
7240 + err = au_d_alive(d);
7241 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7246 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7248 + return a->len == b->len
7249 + && !memcmp(a->name, b->name, a->len);
7254 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7256 + * the type of d_lockref.count became int, but the inlined function d_count()
7257 + * still returns unsigned int.
7258 + * I don't know why. Maybe it is for every d_count() users?
7259 + * Anyway au_dcount() lives on.
7261 +static inline int au_dcount(struct dentry *d)
7263 + return (int)d_count(d);
7266 +#endif /* __KERNEL__ */
7267 +#endif /* __AUFS_DCSUB_H__ */
7268 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7269 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7270 +++ linux/fs/aufs/debug.c 2023-09-03 02:21:58.859971007 +0200
7272 +// SPDX-License-Identifier: GPL-2.0
7274 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7276 + * This program is free software; you can redistribute it and/or modify
7277 + * it under the terms of the GNU General Public License as published by
7278 + * the Free Software Foundation; either version 2 of the License, or
7279 + * (at your option) any later version.
7281 + * This program is distributed in the hope that it will be useful,
7282 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7283 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7284 + * GNU General Public License for more details.
7286 + * You should have received a copy of the GNU General Public License
7287 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7291 + * debug print functions
7294 +#include <linux/iversion.h>
7297 +/* Returns 0, or -errno. arg is in kp->arg. */
7298 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7302 + err = kstrtoint(val, 0, &n);
7312 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7313 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7318 + return sprintf(buffer, "%d", atomic_read(a));
7321 +static const struct kernel_param_ops param_ops_atomic_t = {
7322 + .set = param_atomic_t_set,
7323 + .get = param_atomic_t_get
7324 + /* void (*free)(void *arg) */
7327 +atomic_t aufs_debug = ATOMIC_INIT(0);
7328 +MODULE_PARM_DESC(debug, "debug print");
7329 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7331 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7332 +char *au_plevel = KERN_DEBUG;
7333 +#define dpri(fmt, ...) do { \
7335 + && strcmp(au_plevel, KERN_DEBUG)) \
7336 + || au_debug_test()) \
7337 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7340 +/* ---------------------------------------------------------------------- */
7342 +void au_dpri_whlist(struct au_nhash *whlist)
7344 + unsigned long ul, n;
7345 + struct hlist_head *head;
7346 + struct au_vdir_wh *pos;
7348 + n = whlist->nh_num;
7349 + head = whlist->nh_head;
7350 + for (ul = 0; ul < n; ul++) {
7351 + hlist_for_each_entry(pos, head, wh_hash)
7352 + dpri("b%d, %.*s, %d\n",
7354 + pos->wh_str.len, pos->wh_str.name,
7360 +void au_dpri_vdir(struct au_vdir *vdir)
7363 + union au_vdir_deblk_p p;
7366 + if (!vdir || IS_ERR(vdir)) {
7367 + dpri("err %ld\n", PTR_ERR(vdir));
7371 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7372 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7373 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7374 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7375 + p.deblk = vdir->vd_deblk[ul];
7377 + dpri("[%lu]: %p\n", ul, o);
7381 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7382 + struct dentry *wh)
7387 + if (!inode || IS_ERR(inode)) {
7388 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7392 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7393 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7394 + && sizeof(inode->i_blocks) != sizeof(u64));
7396 + n = (void *)wh->d_name.name;
7397 + l = wh->d_name.len;
7400 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7401 + " acl %p, def_acl %p,"
7402 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7404 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7405 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7406 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7407 + inode->i_acl, inode->i_default_acl,
7408 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7409 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7410 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7411 + inode->i_generation,
7412 + l ? ", wh " : "", l, n);
7416 +void au_dpri_inode(struct inode *inode)
7418 + struct au_iinfo *iinfo;
7419 + struct au_hinode *hi;
7420 + aufs_bindex_t bindex;
7423 + err = do_pri_inode(-1, inode, -1, NULL);
7424 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7427 + iinfo = au_ii(inode);
7428 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7429 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7430 + if (iinfo->ii_btop < 0)
7433 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7434 + hi = au_hinode(iinfo, bindex);
7436 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7440 +void au_dpri_dalias(struct inode *inode)
7444 + spin_lock(&inode->i_lock);
7445 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7446 + au_dpri_dentry(d);
7447 + spin_unlock(&inode->i_lock);
7450 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7452 + struct dentry *wh = NULL;
7454 + struct inode *inode;
7455 + struct au_iinfo *iinfo;
7456 + struct au_hinode *hi;
7458 + if (!dentry || IS_ERR(dentry)) {
7459 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7462 + /* do not call dget_parent() here */
7463 + /* note: access d_xxx without d_lock */
7464 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7465 + bindex, dentry, dentry,
7466 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7467 + au_dcount(dentry), dentry->d_flags,
7468 + d_unhashed(dentry) ? "un" : "");
7471 + if (d_is_positive(dentry))
7472 + inode = d_inode(dentry);
7474 + && au_test_aufs(dentry->d_sb)
7476 + && !au_is_bad_inode(inode)) {
7477 + iinfo = au_ii(inode);
7478 + hi = au_hinode(iinfo, bindex);
7480 + wh = hi->hi_whdentry;
7482 + do_pri_inode(bindex, inode, hn, wh);
7486 +void au_dpri_dentry(struct dentry *dentry)
7488 + struct au_dinfo *dinfo;
7489 + aufs_bindex_t bindex;
7492 + err = do_pri_dentry(-1, dentry);
7493 + if (err || !au_test_aufs(dentry->d_sb))
7496 + dinfo = au_di(dentry);
7499 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7500 + dinfo->di_btop, dinfo->di_bbot,
7501 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7502 + dinfo->di_tmpfile);
7503 + if (dinfo->di_btop < 0)
7505 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7506 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7509 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7513 + if (!file || IS_ERR(file)) {
7514 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7519 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7520 + && au_test_aufs(file->f_path.dentry->d_sb)
7522 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7523 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7524 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7525 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7526 + file->f_version, file->f_pos, a);
7527 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7528 + do_pri_dentry(bindex, file->f_path.dentry);
7532 +void au_dpri_file(struct file *file)
7534 + struct au_finfo *finfo;
7535 + struct au_fidir *fidir;
7536 + struct au_hfile *hfile;
7537 + aufs_bindex_t bindex;
7540 + err = do_pri_file(-1, file);
7542 + || IS_ERR_OR_NULL(file->f_path.dentry)
7543 + || !au_test_aufs(file->f_path.dentry->d_sb))
7546 + finfo = au_fi(file);
7549 + if (finfo->fi_btop < 0)
7551 + fidir = finfo->fi_hdir;
7553 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7555 + for (bindex = finfo->fi_btop;
7556 + bindex >= 0 && bindex <= fidir->fd_bbot;
7558 + hfile = fidir->fd_hfile + bindex;
7559 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7563 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7565 + struct vfsmount *mnt;
7566 + struct super_block *sb;
7568 + if (!br || IS_ERR(br))
7570 + mnt = au_br_mnt(br);
7571 + if (!mnt || IS_ERR(mnt))
7574 + if (!sb || IS_ERR(sb))
7577 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7578 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7580 + bindex, br->br_perm, br->br_id, br->br_wbr,
7581 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7582 + sb->s_flags, sb->s_count,
7583 + atomic_read(&sb->s_active),
7584 + !!au_xino_file(br->br_xino, /*idx*/-1));
7588 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7592 +void au_dpri_sb(struct super_block *sb)
7594 + struct au_sbinfo *sbinfo;
7595 + aufs_bindex_t bindex;
7597 + /* to reduce stack size */
7599 + struct vfsmount mnt;
7600 + struct au_branch fake;
7603 + /* this function can be called from magic sysrq */
7604 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7605 + if (unlikely(!a)) {
7606 + dpri("no memory\n");
7610 + a->mnt.mnt_sb = sb;
7611 + a->fake.br_path.mnt = &a->mnt;
7612 + err = do_pri_br(-1, &a->fake);
7614 + dpri("dev 0x%x\n", sb->s_dev);
7615 + if (err || !au_test_aufs(sb))
7618 + sbinfo = au_sbi(sb);
7621 + dpri("nw %d, gen %u, kobj %d\n",
7622 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7623 + kref_read(&sbinfo->si_kobj.kref));
7624 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7625 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7628 +/* ---------------------------------------------------------------------- */
7630 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7632 + struct inode *h_inode, *inode = d_inode(dentry);
7633 + struct dentry *h_dentry;
7634 + aufs_bindex_t bindex, bbot, bi;
7636 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7639 + bbot = au_dbbot(dentry);
7640 + bi = au_ibbot(inode);
7643 + bindex = au_dbtop(dentry);
7644 + bi = au_ibtop(inode);
7648 + for (; bindex <= bbot; bindex++) {
7649 + h_dentry = au_h_dptr(dentry, bindex);
7652 + h_inode = au_h_iptr(inode, bindex);
7653 + if (unlikely(h_inode != d_inode(h_dentry))) {
7655 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7656 + AuDbgDentry(dentry);
7657 + AuDbgInode(inode);
7659 + if (au_test_fuse(h_inode->i_sb))
7667 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7670 + struct au_dcsub_pages dpages;
7671 + struct au_dpage *dpage;
7672 + struct dentry **dentries;
7674 + err = au_dpages_init(&dpages, GFP_NOFS);
7676 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7678 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7679 + dpage = dpages.dpages + i;
7680 + dentries = dpage->dentries;
7681 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7682 + AuDebugOn(au_digen_test(dentries[j], sigen));
7684 + au_dpages_free(&dpages);
7687 +void au_dbg_verify_kthread(void)
7689 + if (au_wkq_test()) {
7692 + * It may be recursive, but udba=notify between two aufs mounts,
7693 + * where a single ro branch is shared, is not a problem.
7699 +/* ---------------------------------------------------------------------- */
7701 +int __init au_debug_init(void)
7703 + aufs_bindex_t bindex;
7704 + struct au_vdir_destr destr;
7707 + AuDebugOn(bindex >= 0);
7710 + AuDebugOn(destr.len < NAME_MAX);
7712 +#ifdef CONFIG_4KSTACKS
7713 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7718 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7719 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7720 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7722 +/* SPDX-License-Identifier: GPL-2.0 */
7724 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7726 + * This program is free software; you can redistribute it and/or modify
7727 + * it under the terms of the GNU General Public License as published by
7728 + * the Free Software Foundation; either version 2 of the License, or
7729 + * (at your option) any later version.
7731 + * This program is distributed in the hope that it will be useful,
7732 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7733 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7734 + * GNU General Public License for more details.
7736 + * You should have received a copy of the GNU General Public License
7737 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7741 + * debug print functions
7744 +#ifndef __AUFS_DEBUG_H__
7745 +#define __AUFS_DEBUG_H__
7749 +#include <linux/atomic.h>
7750 +#include <linux/module.h>
7751 +#include <linux/kallsyms.h>
7752 +#include <linux/sysrq.h>
7754 +#ifdef CONFIG_AUFS_DEBUG
7755 +#define AuDebugOn(a) BUG_ON(a)
7757 +/* module parameter */
7758 +extern atomic_t aufs_debug;
7759 +static inline void au_debug_on(void)
7761 + atomic_inc(&aufs_debug);
7763 +static inline void au_debug_off(void)
7765 + atomic_dec_if_positive(&aufs_debug);
7768 +static inline int au_debug_test(void)
7770 + return atomic_read(&aufs_debug) > 0;
7773 +#define AuDebugOn(a) do {} while (0)
7774 +AuStubVoid(au_debug_on, void)
7775 +AuStubVoid(au_debug_off, void)
7776 +AuStubInt0(au_debug_test, void)
7777 +#endif /* CONFIG_AUFS_DEBUG */
7779 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7781 +/* ---------------------------------------------------------------------- */
7785 +#define AuDbg(fmt, ...) do { \
7786 + if (au_debug_test()) \
7787 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7789 +#define AuLabel(l) AuDbg(#l "\n")
7790 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7791 +#define AuWarn1(fmt, ...) do { \
7792 + static unsigned char _c; \
7794 + pr_warn(fmt, ##__VA_ARGS__); \
7797 +#define AuErr1(fmt, ...) do { \
7798 + static unsigned char _c; \
7800 + pr_err(fmt, ##__VA_ARGS__); \
7803 +#define AuIOErr1(fmt, ...) do { \
7804 + static unsigned char _c; \
7806 + AuIOErr(fmt, ##__VA_ARGS__); \
7809 +#define AuUnsupportMsg "This operation is not supported." \
7810 + " Please report this application to aufs-users ML."
7811 +#define AuUnsupport(fmt, ...) do { \
7812 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7816 +#define AuTraceErr(e) do { \
7817 + if (unlikely((e) < 0)) \
7818 + AuDbg("err %d\n", (int)(e)); \
7821 +#define AuTraceErrPtr(p) do { \
7823 + AuDbg("err %ld\n", PTR_ERR(p)); \
7826 +/* dirty macros for debug print, use with "%.*s" and caution */
7827 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7829 +/* ---------------------------------------------------------------------- */
7832 +#ifdef CONFIG_AUFS_DEBUG
7833 +extern struct mutex au_dbg_mtx;
7834 +extern char *au_plevel;
7836 +void au_dpri_whlist(struct au_nhash *whlist);
7838 +void au_dpri_vdir(struct au_vdir *vdir);
7840 +void au_dpri_inode(struct inode *inode);
7841 +void au_dpri_dalias(struct inode *inode);
7842 +void au_dpri_dentry(struct dentry *dentry);
7844 +void au_dpri_file(struct file *filp);
7845 +struct super_block;
7846 +void au_dpri_sb(struct super_block *sb);
7848 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7849 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7850 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7851 +void au_dbg_verify_kthread(void);
7853 +int __init au_debug_init(void);
7855 +#define AuDbgWhlist(w) do { \
7856 + mutex_lock(&au_dbg_mtx); \
7858 + au_dpri_whlist(w); \
7859 + mutex_unlock(&au_dbg_mtx); \
7862 +#define AuDbgVdir(v) do { \
7863 + mutex_lock(&au_dbg_mtx); \
7865 + au_dpri_vdir(v); \
7866 + mutex_unlock(&au_dbg_mtx); \
7869 +#define AuDbgInode(i) do { \
7870 + mutex_lock(&au_dbg_mtx); \
7872 + au_dpri_inode(i); \
7873 + mutex_unlock(&au_dbg_mtx); \
7876 +#define AuDbgDAlias(i) do { \
7877 + mutex_lock(&au_dbg_mtx); \
7879 + au_dpri_dalias(i); \
7880 + mutex_unlock(&au_dbg_mtx); \
7883 +#define AuDbgDentry(d) do { \
7884 + mutex_lock(&au_dbg_mtx); \
7886 + au_dpri_dentry(d); \
7887 + mutex_unlock(&au_dbg_mtx); \
7890 +#define AuDbgFile(f) do { \
7891 + mutex_lock(&au_dbg_mtx); \
7893 + au_dpri_file(f); \
7894 + mutex_unlock(&au_dbg_mtx); \
7897 +#define AuDbgSb(sb) do { \
7898 + mutex_lock(&au_dbg_mtx); \
7899 + AuDbg(#sb "\n"); \
7901 + mutex_unlock(&au_dbg_mtx); \
7904 +#define AuDbgSym(addr) do { \
7905 + char sym[KSYM_SYMBOL_LEN]; \
7906 + sprint_symbol(sym, (unsigned long)addr); \
7907 + AuDbg("%s\n", sym); \
7910 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7911 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7912 +AuStubVoid(au_dbg_verify_kthread, void)
7913 +AuStubInt0(__init au_debug_init, void)
7915 +#define AuDbgWhlist(w) do {} while (0)
7916 +#define AuDbgVdir(v) do {} while (0)
7917 +#define AuDbgInode(i) do {} while (0)
7918 +#define AuDbgDAlias(i) do {} while (0)
7919 +#define AuDbgDentry(d) do {} while (0)
7920 +#define AuDbgFile(f) do {} while (0)
7921 +#define AuDbgSb(sb) do {} while (0)
7922 +#define AuDbgSym(addr) do {} while (0)
7923 +#endif /* CONFIG_AUFS_DEBUG */
7925 +/* ---------------------------------------------------------------------- */
7927 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7928 +int __init au_sysrq_init(void);
7929 +void au_sysrq_fin(void);
7931 +#ifdef CONFIG_HW_CONSOLE
7932 +#define au_dbg_blocked() do { \
7934 + handle_sysrq('w'); \
7937 +AuStubVoid(au_dbg_blocked, void)
7941 +AuStubInt0(__init au_sysrq_init, void)
7942 +AuStubVoid(au_sysrq_fin, void)
7943 +AuStubVoid(au_dbg_blocked, void)
7944 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7946 +#endif /* __KERNEL__ */
7947 +#endif /* __AUFS_DEBUG_H__ */
7948 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7949 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7950 +++ linux/fs/aufs/dentry.c 2023-09-03 02:21:58.859971007 +0200
7952 +// SPDX-License-Identifier: GPL-2.0
7954 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7956 + * This program is free software; you can redistribute it and/or modify
7957 + * it under the terms of the GNU General Public License as published by
7958 + * the Free Software Foundation; either version 2 of the License, or
7959 + * (at your option) any later version.
7961 + * This program is distributed in the hope that it will be useful,
7962 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7963 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7964 + * GNU General Public License for more details.
7966 + * You should have received a copy of the GNU General Public License
7967 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7971 + * lookup and dentry operations
7974 +#include <linux/iversion.h>
7978 + * returns positive/negative dentry, NULL or an error.
7979 + * NULL means whiteout-ed or not-found.
7981 +static struct dentry*
7982 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7983 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7985 + struct dentry *h_dentry;
7986 + struct inode *h_inode;
7987 + struct au_branch *br;
7988 + struct mnt_idmap *h_idmap;
7989 + struct path h_path;
7990 + int wh_found, opq;
7991 + unsigned char wh_able;
7992 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7993 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7997 + br = au_sbr(dentry->d_sb, bindex);
7998 + h_path.dentry = h_parent;
7999 + h_path.mnt = au_br_mnt(br);
8000 + h_idmap = au_br_idmap(br);
8001 + wh_able = !!au_br_whable(br->br_perm);
8003 + wh_found = au_wh_test(h_idmap, &h_path, &args->whname,
8005 + h_dentry = ERR_PTR(wh_found);
8008 + if (unlikely(wh_found < 0))
8011 + /* We found a whiteout */
8012 + /* au_set_dbbot(dentry, bindex); */
8013 + au_set_dbwh(dentry, bindex);
8015 + return NULL; /* success */
8019 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8021 + h_dentry = au_sio_lkup_one(h_idmap, args->name, &h_path);
8022 + if (IS_ERR(h_dentry)) {
8023 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8029 + h_inode = d_inode(h_dentry);
8030 + if (d_is_negative(h_dentry)) {
8033 + } else if (wh_found
8034 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8036 + else if (au_ftest_lkup(args->flags, DIRREN)
8038 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8039 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8040 + (unsigned long long)h_inode->i_ino);
8044 + if (au_dbbot(dentry) <= bindex)
8045 + au_set_dbbot(dentry, bindex);
8046 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8047 + au_set_dbtop(dentry, bindex);
8048 + au_set_h_dptr(dentry, bindex, h_dentry);
8050 + if (!d_is_dir(h_dentry)
8052 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8053 + goto out; /* success */
8055 + h_path.dentry = h_dentry;
8056 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8057 + opq = au_diropq_test(h_idmap, &h_path);
8058 + inode_unlock_shared(h_inode);
8060 + au_set_dbdiropq(dentry, bindex);
8061 + else if (unlikely(opq < 0)) {
8062 + au_set_h_dptr(dentry, bindex, NULL);
8063 + h_dentry = ERR_PTR(opq);
8074 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8076 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8077 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8083 + * returns the number of lower positive dentries,
8084 + * otherwise an error.
8085 + * can be called at unlinking with @type is zero.
8087 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8088 + unsigned int flags)
8090 + int npositive, err;
8091 + aufs_bindex_t bindex, btail, bdiropq;
8092 + unsigned char isdir, dirperm1, dirren;
8093 + struct au_do_lookup_args args = {
8095 + .name = &dentry->d_name
8097 + struct dentry *parent;
8098 + struct super_block *sb;
8100 + sb = dentry->d_sb;
8101 + err = au_test_shwh(sb, args.name);
8102 + if (unlikely(err))
8105 + err = au_wh_name_alloc(&args.whname, args.name);
8106 + if (unlikely(err))
8109 + isdir = !!d_is_dir(dentry);
8110 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8111 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8113 + au_fset_lkup(args.flags, DIRREN);
8116 + parent = dget_parent(dentry);
8117 + btail = au_dbtaildir(parent);
8118 + for (bindex = btop; bindex <= btail; bindex++) {
8119 + struct dentry *h_parent, *h_dentry;
8120 + struct inode *h_inode, *h_dir;
8121 + struct au_branch *br;
8123 + h_dentry = au_h_dptr(dentry, bindex);
8125 + if (d_is_positive(h_dentry))
8129 + h_parent = au_h_dptr(parent, bindex);
8130 + if (!h_parent || !d_is_dir(h_parent))
8134 + /* if the inum matches, then use the prepared name */
8135 + err = au_dr_lkup_name(&args, bindex);
8136 + if (unlikely(err))
8140 + h_dir = d_inode(h_parent);
8141 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8142 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8143 + inode_unlock_shared(h_dir);
8144 + err = PTR_ERR(h_dentry);
8145 + if (IS_ERR(h_dentry))
8148 + au_fclr_lkup(args.flags, ALLOW_NEG);
8150 + au_fset_lkup(args.flags, IGNORE_PERM);
8152 + if (au_dbwh(dentry) == bindex)
8156 + if (d_is_negative(h_dentry))
8158 + h_inode = d_inode(h_dentry);
8161 + args.type = h_inode->i_mode & S_IFMT;
8162 + if (args.type != S_IFDIR)
8165 + /* the type of lower may be different */
8166 + bdiropq = au_dbdiropq(dentry);
8167 + if (bdiropq >= 0 && bdiropq <= bindex)
8170 + br = au_sbr(sb, bindex);
8172 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8173 + /*add_ent*/NULL)) {
8174 + /* prepare next name to lookup */
8175 + err = au_dr_lkup(&args, dentry, bindex);
8176 + if (unlikely(err))
8182 + AuLabel(positive);
8183 + au_update_dbtop(dentry);
8186 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8187 + && au_dbtop(dentry) < 0)) {
8189 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8195 + au_kfree_try_rcu(args.whname.name);
8197 + au_dr_lkup_fin(&args);
8202 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
8203 + struct path *ppath)
8205 + struct dentry *dentry;
8208 + if (!au_test_h_perm_sio(idmap, d_inode(ppath->dentry), MAY_EXEC))
8209 + dentry = vfsub_lkup_one(name, ppath);
8211 + struct vfsub_lkup_one_args args = {
8217 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8218 + if (unlikely(wkq_err))
8219 + dentry = ERR_PTR(wkq_err);
8226 + * lookup @dentry on @bindex which should be negative.
8228 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8231 + struct dentry *parent, *h_dentry;
8232 + struct au_branch *br;
8233 + struct mnt_idmap *h_idmap;
8234 + struct path h_ppath;
8236 + parent = dget_parent(dentry);
8237 + br = au_sbr(dentry->d_sb, bindex);
8238 + h_ppath.dentry = au_h_dptr(parent, bindex);
8239 + h_ppath.mnt = au_br_mnt(br);
8240 + h_idmap = au_br_idmap(br);
8242 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8244 + h_dentry = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
8245 + err = PTR_ERR(h_dentry);
8246 + if (IS_ERR(h_dentry))
8248 + if (unlikely(d_is_positive(h_dentry))) {
8250 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8256 + if (bindex < au_dbtop(dentry))
8257 + au_set_dbtop(dentry, bindex);
8258 + if (au_dbbot(dentry) < bindex)
8259 + au_set_dbbot(dentry, bindex);
8260 + au_set_h_dptr(dentry, bindex, h_dentry);
8267 +/* ---------------------------------------------------------------------- */
8269 +/* subset of struct inode */
8271 + unsigned long i_ino;
8272 + /* unsigned int i_nlink; */
8278 + blkcnt_t i_blocks;
8283 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8285 + ia->i_ino = h_inode->i_ino;
8286 + /* ia->i_nlink = h_inode->i_nlink; */
8287 + ia->i_uid = h_inode->i_uid;
8288 + ia->i_gid = h_inode->i_gid;
8289 + ia->i_version = inode_query_iversion(h_inode);
8291 + ia->i_size = h_inode->i_size;
8292 + ia->i_blocks = h_inode->i_blocks;
8294 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8297 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8299 + return ia->i_ino != h_inode->i_ino
8300 + /* || ia->i_nlink != h_inode->i_nlink */
8301 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8302 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8303 + || !inode_eq_iversion(h_inode, ia->i_version)
8305 + || ia->i_size != h_inode->i_size
8306 + || ia->i_blocks != h_inode->i_blocks
8308 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8311 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8312 + struct au_branch *br)
8315 + struct au_iattr ia;
8316 + struct inode *h_inode;
8317 + struct dentry *h_d;
8318 + struct super_block *h_sb;
8319 + struct path h_ppath;
8322 + memset(&ia, -1, sizeof(ia));
8323 + h_sb = h_dentry->d_sb;
8325 + if (d_is_positive(h_dentry)) {
8326 + h_inode = d_inode(h_dentry);
8327 + au_iattr_save(&ia, h_inode);
8328 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8329 + /* nfs d_revalidate may return 0 for negative dentry */
8330 + /* fuse d_revalidate always return 0 for negative dentry */
8333 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8334 + h_ppath.dentry = h_parent;
8335 + h_ppath.mnt = au_br_mnt(br);
8336 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8337 + err = PTR_ERR(h_d);
8342 + if (unlikely(h_d != h_dentry
8343 + || d_inode(h_d) != h_inode
8344 + || (h_inode && au_iattr_test(&ia, h_inode))))
8345 + err = au_busy_or_stale();
8353 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8354 + struct dentry *h_parent, struct au_branch *br)
8359 + if (udba == AuOpt_UDBA_REVAL
8360 + && !au_test_fs_remote(h_dentry->d_sb)) {
8362 + err = (d_inode(h_dentry->d_parent) != h_dir);
8363 + } else if (udba != AuOpt_UDBA_NONE)
8364 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8369 +/* ---------------------------------------------------------------------- */
8371 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8374 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8375 + struct au_hdentry tmp, *p, *q;
8376 + struct au_dinfo *dinfo;
8377 + struct super_block *sb;
8379 + DiMustWriteLock(dentry);
8381 + sb = dentry->d_sb;
8382 + dinfo = au_di(dentry);
8383 + bbot = dinfo->di_bbot;
8384 + bwh = dinfo->di_bwh;
8385 + bdiropq = dinfo->di_bdiropq;
8386 + bindex = dinfo->di_btop;
8387 + p = au_hdentry(dinfo, bindex);
8388 + for (; bindex <= bbot; bindex++, p++) {
8389 + if (!p->hd_dentry)
8392 + new_bindex = au_br_index(sb, p->hd_id);
8393 + if (new_bindex == bindex)
8396 + if (dinfo->di_bwh == bindex)
8398 + if (dinfo->di_bdiropq == bindex)
8399 + bdiropq = new_bindex;
8400 + if (new_bindex < 0) {
8402 + p->hd_dentry = NULL;
8406 + /* swap two lower dentries, and loop again */
8407 + q = au_hdentry(dinfo, new_bindex);
8411 + if (tmp.hd_dentry) {
8417 + dinfo->di_bwh = -1;
8418 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8419 + dinfo->di_bwh = bwh;
8421 + dinfo->di_bdiropq = -1;
8423 + && bdiropq <= au_sbbot(sb)
8424 + && au_sbr_whable(sb, bdiropq))
8425 + dinfo->di_bdiropq = bdiropq;
8428 + dinfo->di_btop = -1;
8429 + dinfo->di_bbot = -1;
8430 + bbot = au_dbbot(parent);
8432 + p = au_hdentry(dinfo, bindex);
8433 + for (; bindex <= bbot; bindex++, p++)
8434 + if (p->hd_dentry) {
8435 + dinfo->di_btop = bindex;
8439 + if (dinfo->di_btop >= 0) {
8441 + p = au_hdentry(dinfo, bindex);
8442 + for (; bindex >= 0; bindex--, p--)
8443 + if (p->hd_dentry) {
8444 + dinfo->di_bbot = bindex;
8453 +static void au_do_hide(struct dentry *dentry)
8455 + struct inode *inode;
8457 + if (d_really_is_positive(dentry)) {
8458 + inode = d_inode(dentry);
8459 + if (!d_is_dir(dentry)) {
8460 + if (inode->i_nlink && !d_unhashed(dentry))
8461 + drop_nlink(inode);
8463 + clear_nlink(inode);
8464 + /* stop next lookup */
8465 + inode->i_flags |= S_DEAD;
8467 + smp_mb(); /* necessary? */
8472 +static int au_hide_children(struct dentry *parent)
8474 + int err, i, j, ndentry;
8475 + struct au_dcsub_pages dpages;
8476 + struct au_dpage *dpage;
8477 + struct dentry *dentry;
8479 + err = au_dpages_init(&dpages, GFP_NOFS);
8480 + if (unlikely(err))
8482 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8483 + if (unlikely(err))
8486 + /* in reverse order */
8487 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8488 + dpage = dpages.dpages + i;
8489 + ndentry = dpage->ndentry;
8490 + for (j = ndentry - 1; j >= 0; j--) {
8491 + dentry = dpage->dentries[j];
8492 + if (dentry != parent)
8493 + au_do_hide(dentry);
8498 + au_dpages_free(&dpages);
8503 +static void au_hide(struct dentry *dentry)
8507 + AuDbgDentry(dentry);
8508 + if (d_is_dir(dentry)) {
8509 + /* shrink_dcache_parent(dentry); */
8510 + err = au_hide_children(dentry);
8511 + if (unlikely(err))
8512 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8515 + au_do_hide(dentry);
8519 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8521 + * a dirty branch is added
8522 + * - on the top of layers
8523 + * - in the middle of layers
8524 + * - to the bottom of layers
8526 + * on the added branch there exists
8529 + * - a same named entry
8531 + * * negative --> positive
8532 + * * positive --> positive
8533 + * - type is unchanged
8534 + * - type is changed
8536 + * * negative --> negative
8537 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8540 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8541 + struct au_dinfo *tmp)
8544 + aufs_bindex_t bindex, bbot;
8546 + struct dentry *dentry;
8547 + struct inode *inode;
8549 + } orig_h, tmp_h = {
8552 + struct au_hdentry *hd;
8553 + struct inode *inode, *h_inode;
8554 + struct dentry *h_dentry;
8557 + AuDebugOn(dinfo->di_btop < 0);
8559 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8560 + orig_h.inode = NULL;
8561 + if (d_is_positive(orig_h.dentry)) {
8562 + orig_h.inode = d_inode(orig_h.dentry);
8563 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8565 + if (tmp->di_btop >= 0) {
8566 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8567 + if (d_is_positive(tmp_h.dentry)) {
8568 + tmp_h.inode = d_inode(tmp_h.dentry);
8569 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8574 + if (d_really_is_positive(dentry))
8575 + inode = d_inode(dentry);
8576 + if (!orig_h.inode) {
8577 + AuDbg("negative originally\n");
8583 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8584 + AuDebugOn(dinfo->di_bdiropq != -1);
8586 + if (!tmp_h.inode) {
8587 + AuDbg("negative --> negative\n");
8588 + /* should have only one negative lower */
8589 + if (tmp->di_btop >= 0
8590 + && tmp->di_btop < dinfo->di_btop) {
8591 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8592 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8593 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8594 + au_di_cp(dinfo, tmp);
8595 + hd = au_hdentry(tmp, tmp->di_btop);
8596 + au_set_h_dptr(dentry, tmp->di_btop,
8597 + dget(hd->hd_dentry));
8599 + au_dbg_verify_dinode(dentry);
8601 + AuDbg("negative --> positive\n");
8603 + * similar to the behaviour of creating with bypassing
8605 + * unhash it in order to force an error in the
8606 + * succeeding create operation.
8607 + * we should not set S_DEAD here.
8610 + /* au_di_swap(tmp, dinfo); */
8611 + au_dbg_verify_dinode(dentry);
8614 + AuDbg("positive originally\n");
8615 + /* inode may be NULL */
8616 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8617 + if (!tmp_h.inode) {
8618 + AuDbg("positive --> negative\n");
8619 + /* or bypassing aufs */
8621 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8622 + dinfo->di_bwh = tmp->di_bwh;
8624 + err = au_refresh_hinode_self(inode);
8625 + au_dbg_verify_dinode(dentry);
8626 + } else if (orig_h.mode == tmp_h.mode) {
8627 + AuDbg("positive --> positive, same type\n");
8628 + if (!S_ISDIR(orig_h.mode)
8629 + && dinfo->di_btop > tmp->di_btop) {
8631 + * similar to the behaviour of removing and
8636 + err = au_refresh_hinode_self(inode);
8637 + au_dbg_verify_dinode(dentry);
8639 + /* fill empty slots */
8640 + if (dinfo->di_btop > tmp->di_btop)
8641 + dinfo->di_btop = tmp->di_btop;
8642 + if (dinfo->di_bbot < tmp->di_bbot)
8643 + dinfo->di_bbot = tmp->di_bbot;
8644 + dinfo->di_bwh = tmp->di_bwh;
8645 + dinfo->di_bdiropq = tmp->di_bdiropq;
8646 + bbot = dinfo->di_bbot;
8647 + bindex = tmp->di_btop;
8648 + hd = au_hdentry(tmp, bindex);
8649 + for (; bindex <= bbot; bindex++, hd++) {
8650 + if (au_h_dptr(dentry, bindex))
8652 + h_dentry = hd->hd_dentry;
8655 + AuDebugOn(d_is_negative(h_dentry));
8656 + h_inode = d_inode(h_dentry);
8657 + AuDebugOn(orig_h.mode
8658 + != (h_inode->i_mode
8660 + au_set_h_dptr(dentry, bindex,
8664 + err = au_refresh_hinode(inode, dentry);
8665 + au_dbg_verify_dinode(dentry);
8668 + AuDbg("positive --> positive, different type\n");
8669 + /* similar to the behaviour of removing and creating */
8672 + err = au_refresh_hinode_self(inode);
8673 + au_dbg_verify_dinode(dentry);
8681 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8683 + const struct dentry_operations *dop
8684 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8685 + static const unsigned int mask
8686 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8688 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8690 + if (dentry->d_op == dop)
8693 + AuDbg("%pd\n", dentry);
8694 + spin_lock(&dentry->d_lock);
8695 + if (dop == &aufs_dop)
8696 + dentry->d_flags |= mask;
8698 + dentry->d_flags &= ~mask;
8699 + dentry->d_op = dop;
8700 + spin_unlock(&dentry->d_lock);
8703 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8705 + int err, ebrange, nbr;
8706 + unsigned int sigen;
8707 + struct au_dinfo *dinfo, *tmp;
8708 + struct super_block *sb;
8709 + struct inode *inode;
8711 + DiMustWriteLock(dentry);
8712 + AuDebugOn(IS_ROOT(dentry));
8713 + AuDebugOn(d_really_is_negative(parent));
8715 + sb = dentry->d_sb;
8716 + sigen = au_sigen(sb);
8717 + err = au_digen_test(parent, sigen);
8718 + if (unlikely(err))
8721 + nbr = au_sbbot(sb) + 1;
8722 + dinfo = au_di(dentry);
8723 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8724 + if (unlikely(err))
8726 + ebrange = au_dbrange_test(dentry);
8728 + ebrange = au_do_refresh_hdentry(dentry, parent);
8730 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8731 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8732 + if (d_really_is_positive(dentry)) {
8733 + inode = d_inode(dentry);
8734 + err = au_refresh_hinode_self(inode);
8736 + au_dbg_verify_dinode(dentry);
8738 + goto out_dgen; /* success */
8742 + /* temporary dinfo */
8743 + AuDbgDentry(dentry);
8745 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8746 + if (unlikely(!tmp))
8748 + au_di_swap(tmp, dinfo);
8749 + /* returns the number of positive dentries */
8751 + * if current working dir is removed, it returns an error.
8752 + * but the dentry is legal.
8754 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8755 + AuDbgDentry(dentry);
8756 + au_di_swap(tmp, dinfo);
8757 + if (err == -ENOENT)
8760 + /* compare/refresh by dinfo */
8761 + AuDbgDentry(dentry);
8762 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8763 + au_dbg_verify_dinode(dentry);
8766 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8767 + au_rw_write_unlock(&tmp->di_rwsem);
8769 + if (unlikely(err))
8773 + au_update_digen(dentry);
8775 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8776 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8777 + AuDbgDentry(dentry);
8783 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8784 + struct dentry *dentry, aufs_bindex_t bindex)
8789 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8792 + AuDbg("b%d\n", bindex);
8794 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8795 + * due to whiteout and branch permission.
8797 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8798 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8799 + /* it may return tri-state */
8800 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8802 + if (unlikely(valid < 0))
8812 +/* todo: remove this */
8813 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8814 + unsigned int flags, int do_udba, int dirren)
8817 + umode_t mode, h_mode;
8818 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8819 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8820 + struct inode *h_inode, *h_cached_inode;
8821 + struct dentry *h_dentry;
8822 + struct qstr *name, *h_name;
8829 + unhashed = !!d_unhashed(dentry);
8830 + is_root = !!IS_ROOT(dentry);
8831 + name = &dentry->d_name;
8832 + tmpfile = au_di(dentry)->di_tmpfile;
8835 + * Theoretically, REVAL test should be unnecessary in case of
8837 + * But {fs,i}notify doesn't fire some necessary events,
8838 + * IN_ATTRIB for atime/nlink/pageio
8839 + * Let's do REVAL test too.
8841 + if (do_udba && inode) {
8842 + mode = (inode->i_mode & S_IFMT);
8843 + plus = (inode->i_nlink > 0);
8844 + ibs = au_ibtop(inode);
8845 + ibe = au_ibbot(inode);
8848 + btop = au_dbtop(dentry);
8850 + if (inode && S_ISDIR(inode->i_mode))
8851 + btail = au_dbtaildir(dentry);
8852 + for (bindex = btop; bindex <= btail; bindex++) {
8853 + h_dentry = au_h_dptr(dentry, bindex);
8857 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8858 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8859 + spin_lock(&h_dentry->d_lock);
8860 + h_name = &h_dentry->d_name;
8861 + if (unlikely(do_udba
8864 + && (unhashed != !!d_unhashed(h_dentry)
8865 + || (!tmpfile && !dirren
8866 + && !au_qstreq(name, h_name))
8869 + && !(flags & LOOKUP_OPEN)
8870 + && (h_dentry->d_flags
8871 + & DCACHE_NFSFS_RENAMED)))
8875 + h_unhashed = d_unhashed(h_dentry);
8876 + spin_unlock(&h_dentry->d_lock);
8877 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8878 + unhashed, h_unhashed, dentry, h_dentry);
8881 + spin_unlock(&h_dentry->d_lock);
8883 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8884 + if (unlikely(err))
8885 + /* do not goto err, to keep the errno */
8888 + /* todo: plink too? */
8893 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8897 + if (d_is_positive(h_dentry))
8898 + h_inode = d_inode(h_dentry);
8901 + h_cached_inode = h_inode;
8903 + h_mode = (h_inode->i_mode & S_IFMT);
8904 + h_plus = (h_inode->i_nlink > 0);
8906 + if (inode && ibs <= bindex && bindex <= ibe)
8907 + h_cached_inode = au_h_iptr(inode, bindex);
8910 + if (unlikely(plus != h_plus && !tmpfile))
8913 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8915 + && !IS_ROOT(h_dentry)
8916 + && unhashed != d_unhashed(h_dentry)))
8919 + if (unlikely(mode != h_mode
8920 + || h_cached_inode != h_inode))
8933 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8934 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8937 + struct dentry *parent;
8939 + if (!au_digen_test(dentry, sigen))
8942 + parent = dget_parent(dentry);
8943 + di_read_lock_parent(parent, AuLock_IR);
8944 + AuDebugOn(au_digen_test(parent, sigen));
8945 + au_dbg_verify_gen(parent, sigen);
8946 + err = au_refresh_dentry(dentry, parent);
8947 + di_read_unlock(parent, AuLock_IR);
8953 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8956 + struct dentry *d, *parent;
8958 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8959 + return simple_reval_dpath(dentry, sigen);
8961 + /* slow loop, keep it simple and stupid */
8962 + /* cf: au_cpup_dirs() */
8965 + while (au_digen_test(dentry, sigen)) {
8969 + parent = dget_parent(d);
8970 + if (!au_digen_test(parent, sigen))
8976 + di_write_lock_child2(d);
8978 + /* someone might update our dentry while we were sleeping */
8979 + if (au_digen_test(d, sigen)) {
8981 + * todo: consolidate with simple_reval_dpath(),
8982 + * do_refresh() and au_reval_for_attr().
8984 + di_read_lock_parent(parent, AuLock_IR);
8985 + err = au_refresh_dentry(d, parent);
8986 + di_read_unlock(parent, AuLock_IR);
8990 + di_write_unlock(d);
8992 + if (unlikely(err))
9000 + * if valid returns 1, otherwise 0.
9002 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9005 + unsigned int sigen;
9006 + unsigned char do_udba, dirren;
9007 + struct super_block *sb;
9008 + struct inode *inode;
9010 + /* todo: support rcu-walk? */
9011 + if (flags & LOOKUP_RCU)
9015 + if (unlikely(!au_di(dentry)))
9019 + sb = dentry->d_sb;
9022 + * i_mutex of parent dir may be held,
9023 + * but we should not return 'invalid' due to busy.
9025 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9026 + if (unlikely(err)) {
9032 + if (d_really_is_positive(dentry))
9033 + inode = d_inode(dentry);
9034 + if (unlikely(inode && au_is_bad_inode(inode))) {
9039 + if (unlikely(au_dbrange_test(dentry))) {
9045 + sigen = au_sigen(sb);
9046 + if (au_digen_test(dentry, sigen)) {
9047 + AuDebugOn(IS_ROOT(dentry));
9048 + err = au_reval_dpath(dentry, sigen);
9049 + if (unlikely(err)) {
9054 + di_downgrade_lock(dentry, AuLock_IR);
9057 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9059 + && !(inode->i_state && I_LINKABLE)
9060 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9065 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9066 + if (do_udba && inode) {
9067 + aufs_bindex_t btop = au_ibtop(inode);
9068 + struct inode *h_inode;
9071 + h_inode = au_h_iptr(inode, btop);
9072 + if (h_inode && au_test_higen(inode, h_inode)) {
9079 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9080 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9081 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9083 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9089 + di_downgrade_lock(dentry, AuLock_IR);
9091 + aufs_read_unlock(dentry, AuLock_IR);
9096 + AuDbg("%pd invalid, %d\n", dentry, valid);
9102 +static void aufs_d_release(struct dentry *dentry)
9104 + if (au_di(dentry)) {
9105 + au_di_fin(dentry);
9106 + au_hn_di_reinit(dentry);
9110 +const struct dentry_operations aufs_dop = {
9111 + .d_revalidate = aufs_d_revalidate,
9112 + .d_weak_revalidate = aufs_d_revalidate,
9113 + .d_release = aufs_d_release
9116 +/* aufs_dop without d_revalidate */
9117 +const struct dentry_operations aufs_dop_noreval = {
9118 + .d_release = aufs_d_release
9120 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9121 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9122 +++ linux/fs/aufs/dentry.h 2023-09-03 02:21:58.859971007 +0200
9124 +/* SPDX-License-Identifier: GPL-2.0 */
9126 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9128 + * This program is free software; you can redistribute it and/or modify
9129 + * it under the terms of the GNU General Public License as published by
9130 + * the Free Software Foundation; either version 2 of the License, or
9131 + * (at your option) any later version.
9133 + * This program is distributed in the hope that it will be useful,
9134 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9135 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9136 + * GNU General Public License for more details.
9138 + * You should have received a copy of the GNU General Public License
9139 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9143 + * lookup and dentry operations
9146 +#ifndef __AUFS_DENTRY_H__
9147 +#define __AUFS_DENTRY_H__
9151 +#include <linux/dcache.h>
9152 +#include "dirren.h"
9155 +struct au_hdentry {
9156 + struct dentry *hd_dentry;
9157 + aufs_bindex_t hd_id;
9161 + atomic_t di_generation;
9163 + struct au_rwsem di_rwsem;
9164 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9165 + unsigned char di_tmpfile; /* to allow the different name */
9166 + struct au_hdentry *di_hdentry;
9167 + struct file *di_htmpfile;
9168 + struct rcu_head rcu;
9169 +} ____cacheline_aligned_in_smp;
9171 +/* ---------------------------------------------------------------------- */
9173 +/* flags for au_lkup_dentry() */
9174 +#define AuLkup_ALLOW_NEG 1
9175 +#define AuLkup_IGNORE_PERM (1 << 1)
9176 +#define AuLkup_DIRREN (1 << 2)
9177 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9178 +#define au_fset_lkup(flags, name) \
9179 + do { (flags) |= AuLkup_##name; } while (0)
9180 +#define au_fclr_lkup(flags, name) \
9181 + do { (flags) &= ~AuLkup_##name; } while (0)
9183 +#ifndef CONFIG_AUFS_DIRREN
9184 +#undef AuLkup_DIRREN
9185 +#define AuLkup_DIRREN 0
9188 +struct au_do_lookup_args {
9189 + unsigned int flags;
9191 + struct qstr whname, *name;
9192 + struct au_dr_lookup dirren;
9195 +/* ---------------------------------------------------------------------- */
9198 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9200 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
9201 + struct path *ppath);
9202 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9203 + struct dentry *h_parent, struct au_branch *br);
9205 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9206 + unsigned int flags);
9207 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9208 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9209 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9210 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9213 +void au_di_init_once(void *_di);
9214 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9215 +void au_di_free(struct au_dinfo *dinfo);
9216 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9217 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9218 +int au_di_init(struct dentry *dentry);
9219 +void au_di_fin(struct dentry *dentry);
9220 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9222 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9223 +void di_read_unlock(struct dentry *d, int flags);
9224 +void di_downgrade_lock(struct dentry *d, int flags);
9225 +void di_write_lock(struct dentry *d, unsigned int lsc);
9226 +void di_write_unlock(struct dentry *d);
9227 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9228 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9229 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9231 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9232 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9233 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9234 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9236 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9237 + struct dentry *h_dentry);
9238 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9239 +int au_dbrange_test(struct dentry *dentry);
9240 +void au_update_digen(struct dentry *dentry);
9241 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9242 +void au_update_dbtop(struct dentry *dentry);
9243 +void au_update_dbbot(struct dentry *dentry);
9244 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9246 +/* ---------------------------------------------------------------------- */
9248 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9250 + return dentry->d_fsdata;
9253 +/* ---------------------------------------------------------------------- */
9255 +/* lock subclass for dinfo */
9257 + AuLsc_DI_CHILD, /* child first */
9258 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9259 + AuLsc_DI_CHILD3, /* copyup dirs */
9263 + AuLsc_DI_TMP /* temp for replacing dinfo */
9267 + * di_read_lock_child, di_write_lock_child,
9268 + * di_read_lock_child2, di_write_lock_child2,
9269 + * di_read_lock_child3, di_write_lock_child3,
9270 + * di_read_lock_parent, di_write_lock_parent,
9271 + * di_read_lock_parent2, di_write_lock_parent2,
9272 + * di_read_lock_parent3, di_write_lock_parent3,
9274 +#define AuReadLockFunc(name, lsc) \
9275 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9276 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9278 +#define AuWriteLockFunc(name, lsc) \
9279 +static inline void di_write_lock_##name(struct dentry *d) \
9280 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9282 +#define AuRWLockFuncs(name, lsc) \
9283 + AuReadLockFunc(name, lsc) \
9284 + AuWriteLockFunc(name, lsc)
9286 +AuRWLockFuncs(child, CHILD);
9287 +AuRWLockFuncs(child2, CHILD2);
9288 +AuRWLockFuncs(child3, CHILD3);
9289 +AuRWLockFuncs(parent, PARENT);
9290 +AuRWLockFuncs(parent2, PARENT2);
9291 +AuRWLockFuncs(parent3, PARENT3);
9293 +#undef AuReadLockFunc
9294 +#undef AuWriteLockFunc
9295 +#undef AuRWLockFuncs
9297 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9298 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9299 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9301 +/* ---------------------------------------------------------------------- */
9303 +/* todo: memory barrier? */
9304 +static inline unsigned int au_digen(struct dentry *d)
9306 + return atomic_read(&au_di(d)->di_generation);
9309 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9311 + hdentry->hd_dentry = NULL;
9314 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9315 + aufs_bindex_t bindex)
9317 + return di->di_hdentry + bindex;
9320 +static inline void au_hdput(struct au_hdentry *hd)
9323 + dput(hd->hd_dentry);
9326 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9328 + DiMustAnyLock(dentry);
9329 + return au_di(dentry)->di_btop;
9332 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9334 + DiMustAnyLock(dentry);
9335 + return au_di(dentry)->di_bbot;
9338 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9340 + DiMustAnyLock(dentry);
9341 + return au_di(dentry)->di_bwh;
9344 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9346 + DiMustAnyLock(dentry);
9347 + return au_di(dentry)->di_bdiropq;
9350 +/* todo: hard/soft set? */
9351 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9353 + DiMustWriteLock(dentry);
9354 + au_di(dentry)->di_btop = bindex;
9357 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9359 + DiMustWriteLock(dentry);
9360 + au_di(dentry)->di_bbot = bindex;
9363 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9365 + DiMustWriteLock(dentry);
9366 + /* dbwh can be outside of btop - bbot range */
9367 + au_di(dentry)->di_bwh = bindex;
9370 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9372 + DiMustWriteLock(dentry);
9373 + au_di(dentry)->di_bdiropq = bindex;
9376 +/* ---------------------------------------------------------------------- */
9378 +#ifdef CONFIG_AUFS_HNOTIFY
9379 +static inline void au_digen_dec(struct dentry *d)
9381 + atomic_dec(&au_di(d)->di_generation);
9384 +static inline void au_hn_di_reinit(struct dentry *dentry)
9386 + dentry->d_fsdata = NULL;
9389 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9390 +#endif /* CONFIG_AUFS_HNOTIFY */
9392 +#endif /* __KERNEL__ */
9393 +#endif /* __AUFS_DENTRY_H__ */
9394 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9395 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9396 +++ linux/fs/aufs/dinfo.c 2022-12-17 09:21:34.796521861 +0100
9398 +// SPDX-License-Identifier: GPL-2.0
9400 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9402 + * This program is free software; you can redistribute it and/or modify
9403 + * it under the terms of the GNU General Public License as published by
9404 + * the Free Software Foundation; either version 2 of the License, or
9405 + * (at your option) any later version.
9407 + * This program is distributed in the hope that it will be useful,
9408 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9409 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9410 + * GNU General Public License for more details.
9412 + * You should have received a copy of the GNU General Public License
9413 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9417 + * dentry private data
9422 +void au_di_init_once(void *_dinfo)
9424 + struct au_dinfo *dinfo = _dinfo;
9426 + au_rw_init(&dinfo->di_rwsem);
9429 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9431 + struct au_dinfo *dinfo;
9434 + dinfo = au_cache_alloc_dinfo();
9435 + if (unlikely(!dinfo))
9438 + nbr = au_sbbot(sb) + 1;
9441 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9442 + if (dinfo->di_hdentry) {
9443 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9444 + dinfo->di_btop = -1;
9445 + dinfo->di_bbot = -1;
9446 + dinfo->di_bwh = -1;
9447 + dinfo->di_bdiropq = -1;
9448 + dinfo->di_tmpfile = 0;
9449 + for (i = 0; i < nbr; i++)
9450 + dinfo->di_hdentry[i].hd_id = -1;
9451 + dinfo->di_htmpfile = NULL;
9455 + au_cache_free_dinfo(dinfo);
9462 +void au_di_free(struct au_dinfo *dinfo)
9464 + struct au_hdentry *p;
9465 + aufs_bindex_t bbot, bindex;
9467 + /* dentry may not be revalidated */
9468 + bindex = dinfo->di_btop;
9469 + if (bindex >= 0) {
9470 + bbot = dinfo->di_bbot;
9471 + p = au_hdentry(dinfo, bindex);
9472 + while (bindex++ <= bbot)
9475 + au_kfree_try_rcu(dinfo->di_hdentry);
9476 + au_cache_free_dinfo(dinfo);
9479 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9481 + struct au_hdentry *p;
9484 + AuRwMustWriteLock(&a->di_rwsem);
9485 + AuRwMustWriteLock(&b->di_rwsem);
9487 +#define DiSwap(v, name) \
9489 + v = a->di_##name; \
9490 + a->di_##name = b->di_##name; \
9491 + b->di_##name = v; \
9494 + DiSwap(p, hdentry);
9498 + DiSwap(bi, bdiropq);
9504 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9506 + AuRwMustWriteLock(&dst->di_rwsem);
9507 + AuRwMustWriteLock(&src->di_rwsem);
9509 + dst->di_btop = src->di_btop;
9510 + dst->di_bbot = src->di_bbot;
9511 + dst->di_bwh = src->di_bwh;
9512 + dst->di_bdiropq = src->di_bdiropq;
9516 +int au_di_init(struct dentry *dentry)
9519 + struct super_block *sb;
9520 + struct au_dinfo *dinfo;
9523 + sb = dentry->d_sb;
9524 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9526 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9527 + /* smp_mb(); */ /* atomic_set */
9528 + dentry->d_fsdata = dinfo;
9535 +void au_di_fin(struct dentry *dentry)
9537 + struct au_dinfo *dinfo;
9539 + dinfo = au_di(dentry);
9540 + AuRwDestroy(&dinfo->di_rwsem);
9541 + au_di_free(dinfo);
9544 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9547 + struct au_hdentry *hdp;
9549 + AuRwMustWriteLock(&dinfo->di_rwsem);
9552 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9554 + sz = sizeof(*hdp);
9555 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9558 + dinfo->di_hdentry = hdp;
9565 +/* ---------------------------------------------------------------------- */
9567 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9570 + case AuLsc_DI_CHILD:
9571 + ii_write_lock_child(inode);
9573 + case AuLsc_DI_CHILD2:
9574 + ii_write_lock_child2(inode);
9576 + case AuLsc_DI_CHILD3:
9577 + ii_write_lock_child3(inode);
9579 + case AuLsc_DI_PARENT:
9580 + ii_write_lock_parent(inode);
9582 + case AuLsc_DI_PARENT2:
9583 + ii_write_lock_parent2(inode);
9585 + case AuLsc_DI_PARENT3:
9586 + ii_write_lock_parent3(inode);
9593 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9596 + case AuLsc_DI_CHILD:
9597 + ii_read_lock_child(inode);
9599 + case AuLsc_DI_CHILD2:
9600 + ii_read_lock_child2(inode);
9602 + case AuLsc_DI_CHILD3:
9603 + ii_read_lock_child3(inode);
9605 + case AuLsc_DI_PARENT:
9606 + ii_read_lock_parent(inode);
9608 + case AuLsc_DI_PARENT2:
9609 + ii_read_lock_parent2(inode);
9611 + case AuLsc_DI_PARENT3:
9612 + ii_read_lock_parent3(inode);
9619 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9621 + struct inode *inode;
9623 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9624 + if (d_really_is_positive(d)) {
9625 + inode = d_inode(d);
9626 + if (au_ftest_lock(flags, IW))
9627 + do_ii_write_lock(inode, lsc);
9628 + else if (au_ftest_lock(flags, IR))
9629 + do_ii_read_lock(inode, lsc);
9633 +void di_read_unlock(struct dentry *d, int flags)
9635 + struct inode *inode;
9637 + if (d_really_is_positive(d)) {
9638 + inode = d_inode(d);
9639 + if (au_ftest_lock(flags, IW)) {
9640 + au_dbg_verify_dinode(d);
9641 + ii_write_unlock(inode);
9642 + } else if (au_ftest_lock(flags, IR)) {
9643 + au_dbg_verify_dinode(d);
9644 + ii_read_unlock(inode);
9647 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9650 +void di_downgrade_lock(struct dentry *d, int flags)
9652 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9653 + ii_downgrade_lock(d_inode(d));
9654 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9657 +void di_write_lock(struct dentry *d, unsigned int lsc)
9659 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9660 + if (d_really_is_positive(d))
9661 + do_ii_write_lock(d_inode(d), lsc);
9664 +void di_write_unlock(struct dentry *d)
9666 + au_dbg_verify_dinode(d);
9667 + if (d_really_is_positive(d))
9668 + ii_write_unlock(d_inode(d));
9669 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9672 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9674 + AuDebugOn(d1 == d2
9675 + || d_inode(d1) == d_inode(d2)
9676 + || d1->d_sb != d2->d_sb);
9678 + if ((isdir && au_test_subdir(d1, d2))
9680 + di_write_lock_child(d1);
9681 + di_write_lock_child2(d2);
9683 + di_write_lock_child(d2);
9684 + di_write_lock_child2(d1);
9688 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9690 + AuDebugOn(d1 == d2
9691 + || d_inode(d1) == d_inode(d2)
9692 + || d1->d_sb != d2->d_sb);
9694 + if ((isdir && au_test_subdir(d1, d2))
9696 + di_write_lock_parent(d1);
9697 + di_write_lock_parent2(d2);
9699 + di_write_lock_parent(d2);
9700 + di_write_lock_parent2(d1);
9704 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9706 + di_write_unlock(d1);
9707 + if (d_inode(d1) == d_inode(d2))
9708 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9710 + di_write_unlock(d2);
9713 +/* ---------------------------------------------------------------------- */
9715 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9719 + DiMustAnyLock(dentry);
9721 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9723 + AuDebugOn(bindex < 0);
9724 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9725 + AuDebugOn(d && au_dcount(d) <= 0);
9730 + * extended version of au_h_dptr().
9731 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9734 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9736 + struct dentry *h_dentry;
9737 + struct inode *inode, *h_inode;
9739 + AuDebugOn(d_really_is_negative(dentry));
9742 + if (au_dbtop(dentry) <= bindex
9743 + && bindex <= au_dbbot(dentry))
9744 + h_dentry = au_h_dptr(dentry, bindex);
9745 + if (h_dentry && !au_d_linkable(h_dentry)) {
9747 + goto out; /* success */
9750 + inode = d_inode(dentry);
9751 + AuDebugOn(bindex < au_ibtop(inode));
9752 + AuDebugOn(au_ibbot(inode) < bindex);
9753 + h_inode = au_h_iptr(inode, bindex);
9754 + h_dentry = d_find_alias(h_inode);
9756 + if (!IS_ERR(h_dentry)) {
9757 + if (!au_d_linkable(h_dentry))
9758 + goto out; /* success */
9764 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9765 + h_dentry = au_plink_lkup(inode, bindex);
9766 + AuDebugOn(!h_dentry);
9767 + if (!IS_ERR(h_dentry)) {
9768 + if (!au_d_hashed_positive(h_dentry))
9769 + goto out; /* success */
9776 + AuDbgDentry(h_dentry);
9780 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9782 + aufs_bindex_t bbot, bwh;
9784 + bbot = au_dbbot(dentry);
9786 + bwh = au_dbwh(dentry);
9789 + if (0 < bwh && bwh < bbot)
9795 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9797 + aufs_bindex_t bbot, bopq;
9799 + bbot = au_dbtail(dentry);
9801 + bopq = au_dbdiropq(dentry);
9802 + if (0 <= bopq && bopq < bbot)
9808 +/* ---------------------------------------------------------------------- */
9810 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9811 + struct dentry *h_dentry)
9813 + struct au_dinfo *dinfo;
9814 + struct au_hdentry *hd;
9815 + struct au_branch *br;
9817 + DiMustWriteLock(dentry);
9819 + dinfo = au_di(dentry);
9820 + hd = au_hdentry(dinfo, bindex);
9822 + hd->hd_dentry = h_dentry;
9824 + br = au_sbr(dentry->d_sb, bindex);
9825 + hd->hd_id = br->br_id;
9829 +int au_dbrange_test(struct dentry *dentry)
9832 + aufs_bindex_t btop, bbot;
9835 + btop = au_dbtop(dentry);
9836 + bbot = au_dbbot(dentry);
9838 + AuDebugOn(bbot < 0 && btop > bbot);
9841 + AuDebugOn(bbot >= 0);
9847 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9852 + if (unlikely(au_digen(dentry) != sigen
9853 + || au_iigen_test(d_inode(dentry), sigen)))
9859 +void au_update_digen(struct dentry *dentry)
9861 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9862 + /* smp_mb(); */ /* atomic_set */
9865 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9867 + struct au_dinfo *dinfo;
9868 + struct dentry *h_d;
9869 + struct au_hdentry *hdp;
9870 + aufs_bindex_t bindex, bbot;
9872 + DiMustWriteLock(dentry);
9874 + dinfo = au_di(dentry);
9875 + if (!dinfo || dinfo->di_btop < 0)
9878 + if (do_put_zero) {
9879 + bbot = dinfo->di_bbot;
9880 + bindex = dinfo->di_btop;
9881 + hdp = au_hdentry(dinfo, bindex);
9882 + for (; bindex <= bbot; bindex++, hdp++) {
9883 + h_d = hdp->hd_dentry;
9884 + if (h_d && d_is_negative(h_d))
9885 + au_set_h_dptr(dentry, bindex, NULL);
9889 + dinfo->di_btop = 0;
9890 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9891 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9892 + if (hdp->hd_dentry)
9894 + if (dinfo->di_btop > dinfo->di_bbot) {
9895 + dinfo->di_btop = -1;
9896 + dinfo->di_bbot = -1;
9900 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9901 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9902 + if (hdp->hd_dentry)
9904 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9907 +void au_update_dbtop(struct dentry *dentry)
9909 + aufs_bindex_t bindex, bbot;
9910 + struct dentry *h_dentry;
9912 + bbot = au_dbbot(dentry);
9913 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9914 + h_dentry = au_h_dptr(dentry, bindex);
9917 + if (d_is_positive(h_dentry)) {
9918 + au_set_dbtop(dentry, bindex);
9921 + au_set_h_dptr(dentry, bindex, NULL);
9925 +void au_update_dbbot(struct dentry *dentry)
9927 + aufs_bindex_t bindex, btop;
9928 + struct dentry *h_dentry;
9930 + btop = au_dbtop(dentry);
9931 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9932 + h_dentry = au_h_dptr(dentry, bindex);
9935 + if (d_is_positive(h_dentry)) {
9936 + au_set_dbbot(dentry, bindex);
9939 + au_set_h_dptr(dentry, bindex, NULL);
9943 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9945 + aufs_bindex_t bindex, bbot;
9947 + bbot = au_dbbot(dentry);
9948 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9949 + if (au_h_dptr(dentry, bindex) == h_dentry)
9953 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9954 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9955 +++ linux/fs/aufs/dir.c 2023-09-03 02:21:58.859971007 +0200
9957 +// SPDX-License-Identifier: GPL-2.0
9959 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9961 + * This program is free software; you can redistribute it and/or modify
9962 + * it under the terms of the GNU General Public License as published by
9963 + * the Free Software Foundation; either version 2 of the License, or
9964 + * (at your option) any later version.
9966 + * This program is distributed in the hope that it will be useful,
9967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9969 + * GNU General Public License for more details.
9971 + * You should have received a copy of the GNU General Public License
9972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9976 + * directory operations
9979 +#include <linux/fs_stack.h>
9980 +#include <linux/iversion.h>
9983 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9985 + unsigned int nlink;
9987 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9989 + nlink = dir->i_nlink;
9990 + nlink += h_dir->i_nlink - 2;
9991 + if (h_dir->i_nlink < 2)
9993 + smp_mb(); /* for i_nlink */
9994 + /* 0 can happen in revaliding */
9995 + set_nlink(dir, nlink);
9998 +void au_sub_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 + /* nlink == 0 means the branch-fs is broken */
10010 + set_nlink(dir, nlink);
10013 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10016 + aufs_bindex_t bindex, bbot;
10017 + struct file *h_file;
10018 + struct dentry *h_dentry;
10022 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10024 + bbot = au_fbbot_dir(file);
10025 + for (bindex = au_fbtop(file);
10026 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10028 + h_file = au_hf_dir(file, bindex);
10029 + if (h_file && file_inode(h_file))
10030 + sz += vfsub_f_size_read(h_file);
10033 + AuDebugOn(!dentry);
10034 + AuDebugOn(!d_is_dir(dentry));
10036 + bbot = au_dbtaildir(dentry);
10037 + for (bindex = au_dbtop(dentry);
10038 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10040 + h_dentry = au_h_dptr(dentry, bindex);
10041 + if (h_dentry && d_is_positive(h_dentry))
10042 + sz += i_size_read(d_inode(h_dentry));
10045 + if (sz < KMALLOC_MAX_SIZE)
10046 + sz = roundup_pow_of_two(sz);
10047 + if (sz > KMALLOC_MAX_SIZE)
10048 + sz = KMALLOC_MAX_SIZE;
10049 + else if (sz < NAME_MAX) {
10050 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10051 + sz = AUFS_RDBLK_DEF;
10056 +struct au_dir_ts_arg {
10057 + struct dentry *dentry;
10058 + aufs_bindex_t brid;
10061 +static void au_do_dir_ts(void *arg)
10063 + struct au_dir_ts_arg *a = arg;
10064 + struct au_dtime dt;
10065 + struct path h_path;
10066 + struct inode *dir, *h_dir;
10067 + struct super_block *sb;
10068 + struct au_branch *br;
10069 + struct au_hinode *hdir;
10071 + aufs_bindex_t btop, bindex;
10073 + sb = a->dentry->d_sb;
10074 + if (d_really_is_negative(a->dentry))
10076 + /* no dir->i_mutex lock */
10077 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10079 + dir = d_inode(a->dentry);
10080 + btop = au_ibtop(dir);
10081 + bindex = au_br_index(sb, a->brid);
10082 + if (bindex < btop)
10085 + br = au_sbr(sb, bindex);
10086 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10087 + if (!h_path.dentry)
10089 + h_path.mnt = au_br_mnt(br);
10090 + au_dtime_store(&dt, a->dentry, &h_path);
10092 + br = au_sbr(sb, btop);
10093 + if (!au_br_writable(br->br_perm))
10095 + h_path.dentry = au_h_dptr(a->dentry, btop);
10096 + h_path.mnt = au_br_mnt(br);
10097 + err = vfsub_mnt_want_write(h_path.mnt);
10100 + hdir = au_hi(dir, btop);
10101 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10102 + h_dir = au_h_iptr(dir, btop);
10103 + if (h_dir->i_nlink
10104 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10105 + dt.dt_h_path = h_path;
10106 + au_dtime_revert(&dt);
10108 + au_hn_inode_unlock(hdir);
10109 + vfsub_mnt_drop_write(h_path.mnt);
10110 + au_cpup_attr_timesizes(dir);
10113 + aufs_read_unlock(a->dentry, AuLock_DW);
10116 + au_nwt_done(&au_sbi(sb)->si_nowait);
10117 + au_kfree_try_rcu(arg);
10120 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10122 + int perm, wkq_err;
10123 + aufs_bindex_t btop;
10124 + struct au_dir_ts_arg *arg;
10125 + struct dentry *dentry;
10126 + struct super_block *sb;
10130 + dentry = d_find_any_alias(dir);
10131 + AuDebugOn(!dentry);
10132 + sb = dentry->d_sb;
10133 + btop = au_ibtop(dir);
10134 + if (btop == bindex) {
10135 + au_cpup_attr_timesizes(dir);
10139 + perm = au_sbr_perm(sb, btop);
10140 + if (!au_br_writable(perm))
10143 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10147 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10148 + arg->brid = au_sbr_id(sb, bindex);
10149 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10150 + if (unlikely(wkq_err)) {
10151 + pr_err("wkq %d\n", wkq_err);
10153 + au_kfree_try_rcu(arg);
10160 +/* ---------------------------------------------------------------------- */
10162 +static int reopen_dir(struct file *file)
10165 + unsigned int flags;
10166 + aufs_bindex_t bindex, btail, btop;
10167 + struct dentry *dentry, *h_dentry;
10168 + struct file *h_file;
10170 + /* open all lower dirs */
10171 + dentry = file->f_path.dentry;
10172 + btop = au_dbtop(dentry);
10173 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10174 + au_set_h_fptr(file, bindex, NULL);
10175 + au_set_fbtop(file, btop);
10177 + btail = au_dbtaildir(dentry);
10178 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10179 + au_set_h_fptr(file, bindex, NULL);
10180 + au_set_fbbot_dir(file, btail);
10182 + flags = vfsub_file_flags(file);
10183 + for (bindex = btop; bindex <= btail; bindex++) {
10184 + h_dentry = au_h_dptr(dentry, bindex);
10187 + h_file = au_hf_dir(file, bindex);
10191 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10192 + err = PTR_ERR(h_file);
10193 + if (IS_ERR(h_file))
10194 + goto out; /* close all? */
10195 + au_set_h_fptr(file, bindex, h_file);
10197 + au_update_figen(file);
10198 + /* todo: necessary? */
10199 + /* file->f_ra = h_file->f_ra; */
10206 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10209 + aufs_bindex_t bindex, btail;
10210 + struct dentry *dentry, *h_dentry;
10211 + struct vfsmount *mnt;
10213 + FiMustWriteLock(file);
10214 + AuDebugOn(h_file);
10217 + mnt = file->f_path.mnt;
10218 + dentry = file->f_path.dentry;
10219 + file->f_version = inode_query_iversion(d_inode(dentry));
10220 + bindex = au_dbtop(dentry);
10221 + au_set_fbtop(file, bindex);
10222 + btail = au_dbtaildir(dentry);
10223 + au_set_fbbot_dir(file, btail);
10224 + for (; !err && bindex <= btail; bindex++) {
10225 + h_dentry = au_h_dptr(dentry, bindex);
10229 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10230 + if (unlikely(err))
10232 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10233 + if (IS_ERR(h_file)) {
10234 + err = PTR_ERR(h_file);
10237 + au_set_h_fptr(file, bindex, h_file);
10239 + au_update_figen(file);
10240 + /* todo: necessary? */
10241 + /* file->f_ra = h_file->f_ra; */
10243 + return 0; /* success */
10246 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10247 + au_set_h_fptr(file, bindex, NULL);
10248 + au_set_fbtop(file, -1);
10249 + au_set_fbbot_dir(file, -1);
10254 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10255 + struct file *file)
10258 + struct super_block *sb;
10259 + struct au_fidir *fidir;
10262 + sb = file->f_path.dentry->d_sb;
10263 + si_read_lock(sb, AuLock_FLUSH);
10264 + fidir = au_fidir_alloc(sb);
10266 + struct au_do_open_args args = {
10267 + .open = do_open_dir,
10270 + err = au_do_open(file, &args);
10271 + if (unlikely(err))
10272 + au_kfree_rcu(fidir);
10274 + si_read_unlock(sb);
10278 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10279 + struct file *file)
10281 + struct au_vdir *vdir_cache;
10282 + struct au_finfo *finfo;
10283 + struct au_fidir *fidir;
10284 + struct au_hfile *hf;
10285 + aufs_bindex_t bindex, bbot;
10287 + finfo = au_fi(file);
10288 + fidir = finfo->fi_hdir;
10290 + au_hbl_del(&finfo->fi_hlist,
10291 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10292 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10294 + au_vdir_free(vdir_cache);
10296 + bindex = finfo->fi_btop;
10297 + if (bindex >= 0) {
10298 + hf = fidir->fd_hfile + bindex;
10300 + * calls fput() instead of filp_close(),
10301 + * since no dnotify or lock for the lower file.
10303 + bbot = fidir->fd_bbot;
10304 + for (; bindex <= bbot; bindex++, hf++)
10306 + au_hfput(hf, /*execed*/0);
10308 + au_kfree_rcu(fidir);
10309 + finfo->fi_hdir = NULL;
10311 + au_finfo_fin(file);
10315 +/* ---------------------------------------------------------------------- */
10317 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10320 + aufs_bindex_t bindex, bbot;
10321 + struct file *h_file;
10324 + bbot = au_fbbot_dir(file);
10325 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10326 + h_file = au_hf_dir(file, bindex);
10328 + err = vfsub_flush(h_file, id);
10333 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10335 + return au_do_flush(file, id, au_do_flush_dir);
10338 +/* ---------------------------------------------------------------------- */
10340 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10343 + aufs_bindex_t bbot, bindex;
10344 + struct inode *inode;
10345 + struct super_block *sb;
10348 + sb = dentry->d_sb;
10349 + inode = d_inode(dentry);
10350 + IMustLock(inode);
10351 + bbot = au_dbbot(dentry);
10352 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10353 + struct path h_path;
10355 + if (au_test_ro(sb, bindex, inode))
10357 + h_path.dentry = au_h_dptr(dentry, bindex);
10358 + if (!h_path.dentry)
10361 + h_path.mnt = au_sbr_mnt(sb, bindex);
10362 + err = vfsub_fsync(NULL, &h_path, datasync);
10368 +static int au_do_fsync_dir(struct file *file, int datasync)
10371 + aufs_bindex_t bbot, bindex;
10372 + struct file *h_file;
10373 + struct super_block *sb;
10374 + struct inode *inode;
10376 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10377 + if (unlikely(err))
10380 + inode = file_inode(file);
10381 + sb = inode->i_sb;
10382 + bbot = au_fbbot_dir(file);
10383 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10384 + h_file = au_hf_dir(file, bindex);
10385 + if (!h_file || au_test_ro(sb, bindex, inode))
10388 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10396 + * @file may be NULL
10398 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10402 + struct dentry *dentry;
10403 + struct inode *inode;
10404 + struct super_block *sb;
10407 + dentry = file->f_path.dentry;
10408 + inode = d_inode(dentry);
10409 + inode_lock(inode);
10410 + sb = dentry->d_sb;
10411 + si_noflush_read_lock(sb);
10413 + err = au_do_fsync_dir(file, datasync);
10415 + di_write_lock_child(dentry);
10416 + err = au_do_fsync_dir_no_file(dentry, datasync);
10418 + au_cpup_attr_timesizes(inode);
10419 + di_write_unlock(dentry);
10421 + fi_write_unlock(file);
10423 + si_read_unlock(sb);
10424 + inode_unlock(inode);
10428 +/* ---------------------------------------------------------------------- */
10430 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10433 + struct dentry *dentry;
10434 + struct inode *inode, *h_inode;
10435 + struct super_block *sb;
10437 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10439 + dentry = file->f_path.dentry;
10440 + inode = d_inode(dentry);
10441 + IMustLock(inode);
10443 + sb = dentry->d_sb;
10444 + si_read_lock(sb, AuLock_FLUSH);
10445 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10446 + if (unlikely(err))
10448 + err = au_alive_dir(dentry);
10450 + err = au_vdir_init(file);
10451 + di_downgrade_lock(dentry, AuLock_IR);
10452 + if (unlikely(err))
10455 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10456 + if (!au_test_nfsd()) {
10457 + err = au_vdir_fill_de(file, ctx);
10458 + fsstack_copy_attr_atime(inode, h_inode);
10461 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10462 + * encode_fh() and others.
10464 + atomic_inc(&h_inode->i_count);
10465 + di_read_unlock(dentry, AuLock_IR);
10466 + si_read_unlock(sb);
10467 + err = au_vdir_fill_de(file, ctx);
10468 + fsstack_copy_attr_atime(inode, h_inode);
10469 + fi_write_unlock(file);
10477 + di_read_unlock(dentry, AuLock_IR);
10478 + fi_write_unlock(file);
10480 + si_read_unlock(sb);
10484 +/* ---------------------------------------------------------------------- */
10486 +#define AuTestEmpty_WHONLY 1
10487 +#define AuTestEmpty_CALLED (1 << 1)
10488 +#define AuTestEmpty_SHWH (1 << 2)
10489 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10490 +#define au_fset_testempty(flags, name) \
10491 + do { (flags) |= AuTestEmpty_##name; } while (0)
10492 +#define au_fclr_testempty(flags, name) \
10493 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10495 +#ifndef CONFIG_AUFS_SHWH
10496 +#undef AuTestEmpty_SHWH
10497 +#define AuTestEmpty_SHWH 0
10500 +struct test_empty_arg {
10501 + struct dir_context ctx;
10502 + struct au_nhash *whlist;
10503 + unsigned int flags;
10505 + aufs_bindex_t bindex;
10508 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10509 + int namelen, loff_t offset __maybe_unused, u64 ino,
10510 + unsigned int d_type)
10512 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10514 + char *name = (void *)__name;
10517 + au_fset_testempty(arg->flags, CALLED);
10519 + if (name[0] == '.'
10520 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10521 + goto out; /* success */
10523 + if (namelen <= AUFS_WH_PFX_LEN
10524 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10525 + if (au_ftest_testempty(arg->flags, WHONLY)
10526 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10527 + arg->err = -ENOTEMPTY;
10531 + name += AUFS_WH_PFX_LEN;
10532 + namelen -= AUFS_WH_PFX_LEN;
10533 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10534 + arg->err = au_nhash_append_wh
10535 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10536 + au_ftest_testempty(arg->flags, SHWH));
10540 + AuTraceErr(arg->err);
10541 + return !arg->err;
10544 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10547 + struct file *h_file;
10548 + struct au_branch *br;
10550 + h_file = au_h_open(dentry, arg->bindex,
10551 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10552 + /*file*/NULL, /*force_wr*/0);
10553 + err = PTR_ERR(h_file);
10554 + if (IS_ERR(h_file))
10558 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10559 + && !file_inode(h_file)->i_nlink)
10564 + au_fclr_testempty(arg->flags, CALLED);
10566 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10569 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10573 + br = au_sbr(dentry->d_sb, arg->bindex);
10574 + au_lcnt_dec(&br->br_nfiles);
10579 +struct do_test_empty_args {
10581 + struct dentry *dentry;
10582 + struct test_empty_arg *arg;
10585 +static void call_do_test_empty(void *args)
10587 + struct do_test_empty_args *a = args;
10588 + *a->errp = do_test_empty(a->dentry, a->arg);
10591 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10593 + int err, wkq_err;
10594 + struct dentry *h_dentry;
10595 + struct inode *h_inode;
10596 + struct mnt_idmap *h_idmap;
10598 + h_idmap = au_sbr_idmap(dentry->d_sb, arg->bindex);
10599 + h_dentry = au_h_dptr(dentry, arg->bindex);
10600 + h_inode = d_inode(h_dentry);
10601 + /* todo: i_mode changes anytime? */
10602 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10603 + err = au_test_h_perm_sio(h_idmap, h_inode, MAY_EXEC | MAY_READ);
10604 + inode_unlock_shared(h_inode);
10606 + err = do_test_empty(dentry, arg);
10608 + struct do_test_empty_args args = {
10610 + .dentry = dentry,
10613 + unsigned int flags = arg->flags;
10615 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10616 + if (unlikely(wkq_err))
10618 + arg->flags = flags;
10624 +int au_test_empty_lower(struct dentry *dentry)
10627 + unsigned int rdhash;
10628 + aufs_bindex_t bindex, btop, btail;
10629 + struct au_nhash whlist;
10630 + struct test_empty_arg arg = {
10632 + .actor = test_empty_cb
10635 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10637 + SiMustAnyLock(dentry->d_sb);
10639 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10641 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10642 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10643 + if (unlikely(err))
10647 + arg.whlist = &whlist;
10648 + btop = au_dbtop(dentry);
10649 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10650 + au_fset_testempty(arg.flags, SHWH);
10651 + test_empty = do_test_empty;
10652 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10653 + test_empty = sio_test_empty;
10654 + arg.bindex = btop;
10655 + err = test_empty(dentry, &arg);
10656 + if (unlikely(err))
10659 + au_fset_testempty(arg.flags, WHONLY);
10660 + btail = au_dbtaildir(dentry);
10661 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10662 + struct dentry *h_dentry;
10664 + h_dentry = au_h_dptr(dentry, bindex);
10665 + if (h_dentry && d_is_positive(h_dentry)) {
10666 + arg.bindex = bindex;
10667 + err = test_empty(dentry, &arg);
10672 + au_nhash_wh_free(&whlist);
10677 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10680 + struct test_empty_arg arg = {
10682 + .actor = test_empty_cb
10685 + aufs_bindex_t bindex, btail;
10688 + arg.whlist = whlist;
10689 + arg.flags = AuTestEmpty_WHONLY;
10690 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10691 + au_fset_testempty(arg.flags, SHWH);
10692 + btail = au_dbtaildir(dentry);
10693 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10694 + struct dentry *h_dentry;
10696 + h_dentry = au_h_dptr(dentry, bindex);
10697 + if (h_dentry && d_is_positive(h_dentry)) {
10698 + arg.bindex = bindex;
10699 + err = sio_test_empty(dentry, &arg);
10706 +/* ---------------------------------------------------------------------- */
10708 +const struct file_operations aufs_dir_fop = {
10709 + .owner = THIS_MODULE,
10710 + .llseek = default_llseek,
10711 + .read = generic_read_dir,
10712 + .iterate_shared = aufs_iterate_shared,
10713 + .unlocked_ioctl = aufs_ioctl_dir,
10714 +#ifdef CONFIG_COMPAT
10715 + .compat_ioctl = aufs_compat_ioctl_dir,
10717 + .open = aufs_open_dir,
10718 + .release = aufs_release_dir,
10719 + .flush = aufs_flush_dir,
10720 + .fsync = aufs_fsync_dir
10722 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10723 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10724 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10726 +/* SPDX-License-Identifier: GPL-2.0 */
10728 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10730 + * This program is free software; you can redistribute it and/or modify
10731 + * it under the terms of the GNU General Public License as published by
10732 + * the Free Software Foundation; either version 2 of the License, or
10733 + * (at your option) any later version.
10735 + * This program is distributed in the hope that it will be useful,
10736 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10737 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10738 + * GNU General Public License for more details.
10740 + * You should have received a copy of the GNU General Public License
10741 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10745 + * directory operations
10748 +#ifndef __AUFS_DIR_H__
10749 +#define __AUFS_DIR_H__
10753 +#include <linux/fs.h>
10755 +/* ---------------------------------------------------------------------- */
10757 +/* need to be faster and smaller */
10760 + unsigned int nh_num;
10761 + struct hlist_head *nh_head;
10764 +struct au_vdir_destr {
10765 + unsigned char len;
10766 + unsigned char name[];
10769 +struct au_vdir_dehstr {
10770 + struct hlist_node hash;
10771 + struct au_vdir_destr *str;
10772 + struct rcu_head rcu;
10773 +} ____cacheline_aligned_in_smp;
10775 +struct au_vdir_de {
10777 + unsigned char de_type;
10778 + /* caution: packed */
10779 + struct au_vdir_destr de_str;
10782 +struct au_vdir_wh {
10783 + struct hlist_node wh_hash;
10784 +#ifdef CONFIG_AUFS_SHWH
10786 + aufs_bindex_t wh_bindex;
10787 + unsigned char wh_type;
10789 + aufs_bindex_t wh_bindex;
10791 + /* caution: packed */
10792 + struct au_vdir_destr wh_str;
10795 +union au_vdir_deblk_p {
10796 + unsigned char *deblk;
10797 + struct au_vdir_de *de;
10801 + unsigned char **vd_deblk;
10802 + unsigned long vd_nblk;
10804 + unsigned long ul;
10805 + union au_vdir_deblk_p p;
10809 + unsigned int vd_deblk_sz;
10810 + unsigned long vd_jiffy;
10811 + struct rcu_head rcu;
10812 +} ____cacheline_aligned_in_smp;
10814 +/* ---------------------------------------------------------------------- */
10817 +extern const struct file_operations aufs_dir_fop;
10818 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10819 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10820 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10821 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10822 +int au_test_empty_lower(struct dentry *dentry);
10823 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10826 +unsigned int au_rdhash_est(loff_t sz);
10827 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10828 +void au_nhash_wh_free(struct au_nhash *whlist);
10829 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10831 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10832 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10833 + unsigned int d_type, aufs_bindex_t bindex,
10834 + unsigned char shwh);
10835 +void au_vdir_free(struct au_vdir *vdir);
10836 +int au_vdir_init(struct file *file);
10837 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10840 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10842 +#ifdef CONFIG_AUFS_RDU
10844 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10845 +#ifdef CONFIG_COMPAT
10846 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10847 + unsigned long arg);
10850 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10851 + unsigned int cmd, unsigned long arg)
10852 +#ifdef CONFIG_COMPAT
10853 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10854 + unsigned int cmd, unsigned long arg)
10858 +#endif /* __KERNEL__ */
10859 +#endif /* __AUFS_DIR_H__ */
10860 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10861 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10862 +++ linux/fs/aufs/dirren.c 2022-11-05 23:02:18.962555950 +0100
10864 +// SPDX-License-Identifier: GPL-2.0
10866 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10868 + * This program is free software; you can redistribute it and/or modify
10869 + * it under the terms of the GNU General Public License as published by
10870 + * the Free Software Foundation; either version 2 of the License, or
10871 + * (at your option) any later version.
10873 + * This program is distributed in the hope that it will be useful,
10874 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10875 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10876 + * GNU General Public License for more details.
10878 + * You should have received a copy of the GNU General Public License
10879 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10883 + * special handling in renaming a directory
10884 + * in order to support looking-up the before-renamed name on the lower readonly
10888 +#include <linux/byteorder/generic.h>
10891 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10895 + idx = au_dr_ihash(ent->dr_h_ino);
10896 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10899 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10902 + struct hlist_bl_head *hbl;
10905 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10906 + hbl = dr->dr_h_ino + i;
10907 + hlist_bl_lock(hbl);
10908 + ret &= hlist_bl_empty(hbl);
10909 + hlist_bl_unlock(hbl);
10915 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10917 + struct au_dr_hino *found, *ent;
10918 + struct hlist_bl_head *hbl;
10919 + struct hlist_bl_node *pos;
10923 + idx = au_dr_ihash(ino);
10924 + hbl = dr->dr_h_ino + idx;
10925 + hlist_bl_lock(hbl);
10926 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10927 + if (ent->dr_h_ino == ino) {
10931 + hlist_bl_unlock(hbl);
10936 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10937 + struct au_dr_hino *add_ent)
10940 + struct hlist_bl_head *hbl;
10941 + struct hlist_bl_node *pos;
10942 + struct au_dr_hino *ent;
10945 + idx = au_dr_ihash(ino);
10946 + hbl = dr->dr_h_ino + idx;
10947 +#if 0 /* debug print */
10949 + struct hlist_bl_node *tmp;
10951 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10952 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10955 + hlist_bl_lock(hbl);
10956 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10957 + if (ent->dr_h_ino == ino) {
10961 + if (!found && add_ent)
10962 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10963 + hlist_bl_unlock(hbl);
10965 + if (!found && add_ent)
10966 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10971 +void au_dr_hino_free(struct au_dr_br *dr)
10974 + struct hlist_bl_head *hbl;
10975 + struct hlist_bl_node *pos, *tmp;
10976 + struct au_dr_hino *ent;
10978 + /* SiMustWriteLock(sb); */
10980 + for (i = 0; i < AuDirren_NHASH; i++) {
10981 + hbl = dr->dr_h_ino + i;
10982 + /* no spinlock since sbinfo must be write-locked */
10983 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10984 + au_kfree_rcu(ent);
10985 + INIT_HLIST_BL_HEAD(hbl);
10989 +/* returns the number of inodes or an error */
10990 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10991 + struct file *hinofile)
10995 + loff_t pos, oldsize;
10997 + struct inode *hinoinode;
10998 + struct hlist_bl_head *hbl;
10999 + struct hlist_bl_node *n1, *n2;
11000 + struct au_dr_hino *ent;
11002 + SiMustWriteLock(sb);
11003 + AuDebugOn(!au_br_writable(br->br_perm));
11005 + hinoinode = file_inode(hinofile);
11006 + oldsize = i_size_read(hinoinode);
11010 + hbl = br->br_dirren.dr_h_ino;
11011 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11012 + /* no bit-lock since sbinfo must be write-locked */
11013 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11014 + AuDbg("hi%llu, %pD2\n",
11015 + (unsigned long long)ent->dr_h_ino, hinofile);
11016 + u64 = cpu_to_be64(ent->dr_h_ino);
11017 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11018 + if (ssz == sizeof(u64))
11021 + /* write error */
11022 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11029 + /* regardless the error */
11030 + if (pos < oldsize) {
11031 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11039 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11046 + struct au_dr_hino *ent;
11047 + struct inode *hinoinode;
11048 + struct hlist_bl_head *hbl;
11052 + hbl = dr->dr_h_ino;
11053 + hinoinode = file_inode(hinofile);
11054 + sz = i_size_read(hinoinode);
11055 + AuDebugOn(sz % sizeof(u64));
11056 + n = sz / sizeof(u64);
11058 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11059 + if (unlikely(ssz != sizeof(u64))) {
11060 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11067 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11073 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11074 + AuDbg("hi%llu, %pD2\n",
11075 + (unsigned long long)ent->dr_h_ino, hinofile);
11076 + hidx = au_dr_ihash(ent->dr_h_ino);
11077 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11079 + goto out; /* success */
11082 + au_dr_hino_free(dr);
11089 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11090 + * @path is a switch to distinguish load and store.
11092 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11093 + struct au_branch *br, const struct path *path)
11096 + unsigned char load, suspend;
11097 + struct file *hinofile;
11098 + struct au_hinode *hdir;
11099 + struct inode *dir, *delegated;
11100 + struct path hinopath;
11101 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11102 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11104 + AuDebugOn(bindex < 0 && !br);
11105 + AuDebugOn(bindex >= 0 && br);
11110 + br = au_sbr(sb, bindex);
11113 + path = &br->br_path;
11114 + AuDebugOn(!au_br_writable(br->br_perm));
11115 + if (unlikely(!au_br_writable(br->br_perm)))
11121 + dir = d_inode(sb->s_root);
11122 + hdir = au_hinode(au_ii(dir), bindex);
11123 + dir = hdir->hi_inode;
11124 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11126 + dir = d_inode(path->dentry);
11127 + inode_lock_nested(dir, AuLsc_I_CHILD);
11129 + hinopath.mnt = path->mnt;
11130 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11131 + err = PTR_ERR(hinopath.dentry);
11132 + if (IS_ERR(hinopath.dentry))
11136 + flags = O_RDONLY;
11138 + if (d_is_negative(hinopath.dentry))
11139 + goto out_dput; /* success */
11141 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11142 + if (d_is_positive(hinopath.dentry)) {
11143 + delegated = NULL;
11144 + err = vfsub_unlink(dir, &hinopath, &delegated,
11147 + if (unlikely(err))
11148 + pr_err("ignored err %d, %pd2\n",
11149 + err, hinopath.dentry);
11150 + if (unlikely(err == -EWOULDBLOCK))
11155 + } else if (!d_is_positive(hinopath.dentry)) {
11156 + err = vfsub_create(dir, &hinopath, 0600,
11157 + /*want_excl*/false);
11159 + if (unlikely(err))
11162 + flags = O_WRONLY;
11164 + hinofile = vfsub_dentry_open(&hinopath, flags);
11166 + au_hn_inode_unlock(hdir);
11168 + inode_unlock(dir);
11169 + dput(hinopath.dentry);
11170 + AuTraceErrPtr(hinofile);
11171 + if (IS_ERR(hinofile)) {
11172 + err = PTR_ERR(hinofile);
11177 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11179 + err = au_dr_hino_store(sb, br, hinofile);
11184 + dput(hinopath.dentry);
11187 + au_hn_inode_unlock(hdir);
11189 + inode_unlock(dir);
11195 +/* ---------------------------------------------------------------------- */
11197 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11200 + struct kstatfs kstfs;
11202 + struct dentry *dentry;
11203 + struct super_block *sb;
11205 + err = vfs_statfs((void *)path, &kstfs);
11207 + if (unlikely(err))
11210 + /* todo: support for UUID */
11212 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11213 + brid->type = AuBrid_FSID;
11214 + brid->fsid = kstfs.f_fsid;
11216 + dentry = path->dentry;
11217 + sb = dentry->d_sb;
11220 + brid->type = AuBrid_DEV;
11229 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11230 + const struct path *path)
11233 + struct au_dr_br *dr;
11234 + struct hlist_bl_head *hbl;
11236 + dr = &br->br_dirren;
11237 + hbl = dr->dr_h_ino;
11238 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11239 + INIT_HLIST_BL_HEAD(hbl);
11241 + err = au_dr_brid_init(&dr->dr_brid, path);
11242 + if (unlikely(err))
11245 + if (au_opt_test(au_mntflags(sb), DIRREN))
11246 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11253 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11258 + if (au_br_writable(br->br_perm))
11259 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11261 + au_dr_hino_free(&br->br_dirren);
11266 +/* ---------------------------------------------------------------------- */
11268 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11269 + char *buf, size_t sz)
11272 + unsigned int major, minor;
11276 + err = snprintf(p, sz, "%d_", brid->type);
11277 + AuDebugOn(err > sz);
11280 + switch (brid->type) {
11281 + case AuBrid_Unset:
11283 + case AuBrid_UUID:
11284 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11286 + case AuBrid_FSID:
11287 + err = snprintf(p, sz, "%08x-%08x",
11288 + brid->fsid.val[0], brid->fsid.val[1]);
11291 + major = MAJOR(brid->dev);
11292 + minor = MINOR(brid->dev);
11293 + if (major <= 0xff && minor <= 0xff)
11294 + err = snprintf(p, sz, "%02x%02x", major, minor);
11296 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11299 + AuDebugOn(err > sz);
11302 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11303 + AuDebugOn(err > sz);
11310 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11313 + struct dentry *br_dentry;
11314 + struct inode *br_inode;
11316 + br_dentry = au_br_dentry(br);
11317 + br_inode = d_inode(br_dentry);
11318 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11319 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11320 + AuDebugOn(rlen > len);
11325 +/* ---------------------------------------------------------------------- */
11328 + * from the given @h_dentry, construct drinfo at @*fdata.
11329 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11332 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11333 + struct dentry *h_dentry,
11334 + unsigned char *allocated)
11337 + struct au_drinfo_fdata *f, *p;
11338 + struct au_drinfo *drinfo;
11339 + struct inode *h_inode;
11340 + struct qstr *qname;
11344 + h_inode = d_inode(h_dentry);
11345 + qname = &h_dentry->d_name;
11346 + drinfo = &f->drinfo;
11347 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11348 + drinfo->oldnamelen = qname->len;
11349 + if (*allocated < sizeof(*f) + qname->len) {
11350 + v = roundup_pow_of_two(*allocated + qname->len);
11351 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11352 + if (unlikely(!p)) {
11360 + drinfo = &f->drinfo;
11362 + memcpy(drinfo->oldname, qname->name, qname->len);
11363 + AuDbg("i%llu, %.*s\n",
11364 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11365 + drinfo->oldname);
11372 +/* callers have to free the return value */
11373 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11375 + struct au_drinfo *ret, *drinfo;
11376 + struct au_drinfo_fdata fdata;
11381 + ret = ERR_PTR(-EIO);
11383 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11384 + if (unlikely(ssz != sizeof(fdata))) {
11385 + AuIOErr("ssz %zd, %u, %pD2\n",
11386 + ssz, (unsigned int)sizeof(fdata), file);
11390 + fdata.magic = ntohl((__force __be32)fdata.magic);
11391 + switch (fdata.magic) {
11392 + case AUFS_DRINFO_MAGIC_V1:
11395 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11396 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11400 + drinfo = &fdata.drinfo;
11401 + len = drinfo->oldnamelen;
11403 + AuIOErr("broken drinfo %pD2\n", file);
11408 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11409 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11410 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11411 + (unsigned long long)drinfo->ino,
11412 + (unsigned long long)h_ino, file);
11413 + goto out; /* success */
11416 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11417 + if (unlikely(!ret)) {
11418 + ret = ERR_PTR(-ENOMEM);
11419 + AuTraceErrPtr(ret);
11424 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11425 + if (unlikely(ssz != len)) {
11426 + au_kfree_rcu(ret);
11427 + ret = ERR_PTR(-EIO);
11428 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11432 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11438 +/* ---------------------------------------------------------------------- */
11440 +/* in order to be revertible */
11441 +struct au_drinfo_rev_elm {
11443 + struct dentry *info_dentry;
11444 + struct au_drinfo *info_last;
11447 +struct au_drinfo_rev {
11448 + unsigned char already;
11449 + aufs_bindex_t nelm;
11450 + struct au_drinfo_rev_elm elm[];
11453 +/* todo: isn't it too large? */
11454 +struct au_drinfo_store {
11455 + struct path h_ppath;
11456 + struct dentry *h_dentry;
11457 + struct au_drinfo_fdata *fdata;
11458 + char *infoname; /* inside of whname, just after PFX */
11459 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11460 + aufs_bindex_t btgt, btail;
11461 + unsigned char no_sio,
11462 + allocated, /* current size of *fdata */
11463 + infonamelen, /* room size for p */
11464 + whnamelen, /* length of the generated name */
11465 + renameback; /* renamed back */
11468 +/* on rename(2) error, the caller should revert it using @elm */
11469 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11470 + struct au_drinfo_rev_elm *elm)
11475 + struct path infopath = {
11476 + .mnt = w->h_ppath.mnt
11478 + struct inode *h_dir, *h_inode, *delegated;
11479 + struct file *infofile;
11480 + struct qstr *qname;
11483 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11485 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11487 + AuTraceErrPtr(infopath.dentry);
11488 + if (IS_ERR(infopath.dentry)) {
11489 + err = PTR_ERR(infopath.dentry);
11494 + h_dir = d_inode(w->h_ppath.dentry);
11495 + if (elm && d_is_negative(infopath.dentry)) {
11496 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11498 + if (unlikely(err))
11500 + elm->created = 1;
11501 + elm->info_dentry = dget(infopath.dentry);
11504 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11505 + AuTraceErrPtr(infofile);
11506 + if (IS_ERR(infofile)) {
11507 + err = PTR_ERR(infofile);
11511 + h_inode = d_inode(infopath.dentry);
11512 + if (elm && i_size_read(h_inode)) {
11513 + h_inode = d_inode(w->h_dentry);
11514 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11515 + AuTraceErrPtr(elm->info_last);
11516 + if (IS_ERR(elm->info_last)) {
11517 + err = PTR_ERR(elm->info_last);
11518 + elm->info_last = NULL;
11519 + AuDebugOn(elm->info_dentry);
11524 + if (elm && w->renameback) {
11525 + delegated = NULL;
11526 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11528 + if (unlikely(err == -EWOULDBLOCK))
11534 + qname = &w->h_dentry->d_name;
11535 + len = sizeof(*w->fdata) + qname->len;
11537 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11538 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11539 + if (ssz == len) {
11540 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11541 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11542 + goto out_fput; /* success */
11547 + /* the caller should revert it using @elm */
11553 + dput(infopath.dentry);
11559 +struct au_call_drinfo_do_store_args {
11561 + struct au_drinfo_store *w;
11562 + struct au_drinfo_rev_elm *elm;
11565 +static void au_call_drinfo_do_store(void *args)
11567 + struct au_call_drinfo_do_store_args *a = args;
11569 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11572 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11573 + struct au_drinfo_rev_elm *elm)
11575 + int err, wkq_err;
11578 + err = au_drinfo_do_store(w, elm);
11580 + struct au_call_drinfo_do_store_args a = {
11585 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11586 + if (unlikely(wkq_err))
11594 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11595 + aufs_bindex_t btgt)
11599 + memset(w, 0, sizeof(*w));
11600 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11601 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11602 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11603 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11605 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11608 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11609 + if (unlikely(!w->fdata)) {
11613 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11620 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11622 + au_kfree_rcu(w->fdata);
11625 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11626 + struct au_drinfo_store *w)
11628 + struct au_drinfo_rev_elm *elm;
11629 + struct inode *h_dir, *delegated;
11631 + struct path infopath = {
11632 + .mnt = w->h_ppath.mnt
11635 + h_dir = d_inode(w->h_ppath.dentry);
11636 + IMustLock(h_dir);
11640 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11641 + AuDebugOn(elm->created && elm->info_last);
11642 + if (elm->created) {
11644 + delegated = NULL;
11645 + infopath.dentry = elm->info_dentry;
11646 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11649 + if (unlikely(err == -EWOULDBLOCK))
11651 + dput(elm->info_dentry);
11652 + } else if (elm->info_last) {
11654 + w->fdata->drinfo = *elm->info_last;
11655 + memcpy(w->fdata->drinfo.oldname,
11656 + elm->info_last->oldname,
11657 + elm->info_last->oldnamelen);
11658 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11659 + au_kfree_rcu(elm->info_last);
11661 + if (unlikely(err))
11662 + AuIOErr("%d, %s\n", err, w->whname);
11663 + /* go on even if err */
11667 +/* caller has to call au_dr_rename_fin() later */
11668 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11669 + struct qstr *dst_name, void *_rev)
11671 + int err, sz, nelm;
11672 + aufs_bindex_t bindex, btail;
11673 + struct au_drinfo_store work;
11674 + struct au_drinfo_rev *rev, **p;
11675 + struct au_drinfo_rev_elm *elm;
11676 + struct super_block *sb;
11677 + struct au_branch *br;
11678 + struct au_hinode *hdir;
11680 + err = au_drinfo_store_work_init(&work, btgt);
11682 + if (unlikely(err))
11686 + btail = au_dbtaildir(dentry);
11687 + nelm = btail - btgt;
11688 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11689 + rev = kcalloc(1, sz, GFP_NOFS);
11690 + if (unlikely(!rev)) {
11694 + rev->nelm = nelm;
11700 + sb = dentry->d_sb;
11701 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11702 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11703 + hdir = au_hi(d_inode(dentry), btgt);
11704 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11705 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11706 + work.h_dentry = au_h_dptr(dentry, bindex);
11707 + if (!work.h_dentry)
11710 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11711 + &work.allocated);
11713 + if (unlikely(err))
11716 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11717 + br = au_sbr(sb, bindex);
11718 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11719 + work.whnamelen += au_drinfo_name(br, work.infoname,
11720 + work.infonamelen);
11721 + AuDbg("whname %.*s, i%llu, %.*s\n",
11722 + work.whnamelen, work.whname,
11723 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11724 + work.fdata->drinfo.oldnamelen,
11725 + work.fdata->drinfo.oldname);
11727 + err = au_drinfo_store_sio(&work, elm);
11729 + if (unlikely(err))
11732 + if (unlikely(err)) {
11733 + /* revert all drinfo */
11734 + au_drinfo_store_rev(rev, &work);
11735 + au_kfree_try_rcu(rev);
11738 + au_hn_inode_unlock(hdir);
11741 + au_drinfo_store_work_fin(&work);
11746 +/* ---------------------------------------------------------------------- */
11748 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11749 + struct qstr *dst_name, void *_rev)
11751 + int err, already;
11753 + struct super_block *sb;
11754 + struct au_branch *br;
11755 + struct au_dr_br *dr;
11756 + struct dentry *h_dentry;
11757 + struct inode *h_inode;
11758 + struct au_dr_hino *ent;
11759 + struct au_drinfo_rev *rev, **p;
11761 + AuDbg("bindex %d\n", bindex);
11764 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11765 + if (unlikely(!ent))
11769 + br = au_sbr(sb, bindex);
11770 + dr = &br->br_dirren;
11771 + h_dentry = au_h_dptr(src, bindex);
11772 + h_inode = d_inode(h_dentry);
11773 + ino = h_inode->i_ino;
11774 + ent->dr_h_ino = ino;
11775 + already = au_dr_hino_test_add(dr, ino, ent);
11776 + AuDbg("b%d, hi%llu, already %d\n",
11777 + bindex, (unsigned long long)ino, already);
11779 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11784 + rev->already = already;
11785 + goto out; /* success */
11790 + au_dr_hino_del(dr, ent);
11791 + au_kfree_rcu(ent);
11798 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11800 + struct au_drinfo_rev *rev;
11801 + struct au_drinfo_rev_elm *elm;
11806 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11807 + dput(elm->info_dentry);
11808 + au_kfree_rcu(elm->info_last);
11810 + au_kfree_try_rcu(rev);
11813 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11816 + struct au_drinfo_store work;
11817 + struct au_drinfo_rev *rev = _rev;
11818 + struct super_block *sb;
11819 + struct au_branch *br;
11820 + struct inode *h_inode;
11821 + struct au_dr_br *dr;
11822 + struct au_dr_hino *ent;
11824 + err = au_drinfo_store_work_init(&work, btgt);
11825 + if (unlikely(err))
11829 + br = au_sbr(sb, btgt);
11830 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11831 + work.h_ppath.mnt = au_br_mnt(br);
11832 + au_drinfo_store_rev(rev, &work);
11833 + au_drinfo_store_work_fin(&work);
11834 + if (rev->already)
11837 + dr = &br->br_dirren;
11838 + h_inode = d_inode(work.h_ppath.dentry);
11839 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11841 + au_dr_hino_del(dr, ent);
11842 + au_kfree_rcu(ent);
11845 + au_kfree_try_rcu(rev);
11846 + if (unlikely(err))
11847 + pr_err("failed to remove dirren info\n");
11850 +/* ---------------------------------------------------------------------- */
11852 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11853 + char *whname, int whnamelen,
11854 + struct dentry **info_dentry)
11856 + struct au_drinfo *drinfo;
11858 + struct inode *h_dir;
11859 + struct path infopath;
11862 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11864 + *info_dentry = NULL;
11867 + h_dir = d_inode(h_ppath->dentry);
11868 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11869 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11870 + if (IS_ERR(infopath.dentry)) {
11871 + drinfo = (void *)infopath.dentry;
11875 + if (d_is_negative(infopath.dentry))
11876 + goto out_dput; /* success */
11878 + infopath.mnt = h_ppath->mnt;
11879 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11880 + inode_unlock_shared(h_dir);
11883 + drinfo = (void *)f;
11887 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11888 + if (IS_ERR_OR_NULL(drinfo))
11891 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11892 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11897 + dput(infopath.dentry);
11900 + inode_unlock_shared(h_dir);
11901 + AuTraceErrPtr(drinfo);
11905 +struct au_drinfo_do_load_args {
11906 + struct au_drinfo **drinfop;
11907 + struct path *h_ppath;
11910 + struct dentry **info_dentry;
11913 +static void au_call_drinfo_do_load(void *args)
11915 + struct au_drinfo_do_load_args *a = args;
11917 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11921 +struct au_drinfo_load {
11922 + struct path h_ppath;
11923 + struct qstr *qname;
11924 + unsigned char no_sio;
11926 + aufs_bindex_t ninfo;
11927 + struct au_drinfo **drinfo;
11930 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11931 + struct au_branch *br)
11933 + int err, wkq_err, whnamelen, e;
11934 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11935 + = AUFS_WH_DR_INFO_PFX;
11936 + struct au_drinfo *drinfo;
11937 + struct qstr oldname;
11938 + struct inode *h_dir, *delegated;
11939 + struct dentry *info_dentry;
11940 + struct path infopath;
11942 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11943 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11944 + sizeof(whname) - whnamelen);
11946 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11949 + struct au_drinfo_do_load_args args = {
11950 + .drinfop = &drinfo,
11951 + .h_ppath = &w->h_ppath,
11952 + .whname = whname,
11953 + .whnamelen = whnamelen,
11954 + .info_dentry = &info_dentry
11956 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11957 + if (unlikely(wkq_err))
11958 + drinfo = ERR_PTR(wkq_err);
11960 + err = PTR_ERR(drinfo);
11961 + if (IS_ERR_OR_NULL(drinfo))
11965 + oldname.len = drinfo->oldnamelen;
11966 + oldname.name = drinfo->oldname;
11967 + if (au_qstreq(w->qname, &oldname)) {
11968 + /* the name is renamed back */
11969 + au_kfree_rcu(drinfo);
11972 + infopath.dentry = info_dentry;
11973 + infopath.mnt = w->h_ppath.mnt;
11974 + h_dir = d_inode(w->h_ppath.dentry);
11975 + delegated = NULL;
11976 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11977 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11978 + inode_unlock(h_dir);
11980 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11981 + if (unlikely(e == -EWOULDBLOCK))
11984 + au_kfree_rcu(w->drinfo[bindex]);
11985 + w->drinfo[bindex] = drinfo;
11986 + dput(info_dentry);
11993 +/* ---------------------------------------------------------------------- */
11995 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11997 + struct au_drinfo **p = drinfo;
12000 + au_kfree_rcu(*drinfo++);
12001 + au_kfree_try_rcu(p);
12004 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12005 + aufs_bindex_t btgt)
12008 + struct au_drinfo_load w;
12009 + aufs_bindex_t bindex, bbot;
12010 + struct au_branch *br;
12011 + struct inode *h_dir;
12012 + struct au_dr_hino *ent;
12013 + struct super_block *sb;
12015 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12016 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12017 + AuLNPair(&lkup->whname), btgt);
12019 + sb = dentry->d_sb;
12020 + bbot = au_sbbot(sb);
12021 + w.ninfo = bbot + 1;
12022 + if (!lkup->dirren.drinfo) {
12023 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12024 + sizeof(*lkup->dirren.drinfo),
12026 + if (unlikely(!lkup->dirren.drinfo)) {
12030 + lkup->dirren.ninfo = w.ninfo;
12032 + w.drinfo = lkup->dirren.drinfo;
12033 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12034 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12035 + AuDebugOn(!w.h_ppath.dentry);
12036 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12037 + w.qname = &dentry->d_name;
12040 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12041 + br = au_sbr(sb, bindex);
12042 + err = au_drinfo_load(&w, bindex, br);
12043 + if (unlikely(err))
12045 + if (w.drinfo[bindex])
12049 + br = au_sbr(sb, btgt);
12050 + h_dir = d_inode(w.h_ppath.dentry);
12051 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12053 + au_dr_hino_del(&br->br_dirren, ent);
12054 + au_kfree_rcu(ent);
12056 + goto out; /* success */
12059 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12060 + lkup->dirren.ninfo = 0;
12061 + lkup->dirren.drinfo = NULL;
12067 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12069 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12072 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12075 + struct au_drinfo *drinfo;
12078 + if (!lkup->dirren.drinfo)
12080 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12081 + drinfo = lkup->dirren.drinfo[btgt];
12085 + au_kfree_try_rcu(lkup->whname.name);
12086 + lkup->whname.name = NULL;
12087 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12088 + lkup->dirren.dr_name.name = drinfo->oldname;
12089 + lkup->name = &lkup->dirren.dr_name;
12090 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12092 + AuDbg("name %.*s, whname %.*s, b%d\n",
12093 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12101 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12105 + struct au_drinfo *drinfo;
12108 + if (!lkup->dirren.drinfo)
12110 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12111 + drinfo = lkup->dirren.drinfo[bindex];
12115 + match = (drinfo->ino == h_ino);
12116 + AuDbg("match %d\n", match);
12122 +/* ---------------------------------------------------------------------- */
12124 +int au_dr_opt_set(struct super_block *sb)
12127 + aufs_bindex_t bindex, bbot;
12128 + struct au_branch *br;
12131 + bbot = au_sbbot(sb);
12132 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12133 + br = au_sbr(sb, bindex);
12134 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12140 +int au_dr_opt_flush(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 + if (au_br_writable(br->br_perm))
12151 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12157 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12160 + aufs_bindex_t bindex, bbot;
12161 + struct au_branch *br;
12165 + err = au_dr_opt_flush(sb);
12166 + if (unlikely(err))
12170 + bbot = au_sbbot(sb);
12171 + for (bindex = 0; bindex <= bbot; bindex++) {
12172 + br = au_sbr(sb, bindex);
12173 + au_dr_hino_free(&br->br_dirren);
12179 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12180 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12181 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12183 +/* SPDX-License-Identifier: GPL-2.0 */
12185 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12187 + * This program is free software; you can redistribute it and/or modify
12188 + * it under the terms of the GNU General Public License as published by
12189 + * the Free Software Foundation; either version 2 of the License, or
12190 + * (at your option) any later version.
12192 + * This program is distributed in the hope that it will be useful,
12193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12195 + * GNU General Public License for more details.
12197 + * You should have received a copy of the GNU General Public License
12198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12202 + * renamed dir info
12205 +#ifndef __AUFS_DIRREN_H__
12206 +#define __AUFS_DIRREN_H__
12210 +#include <linux/dcache.h>
12211 +#include <linux/statfs.h>
12212 +#include <linux/uuid.h>
12215 +#define AuDirren_NHASH 100
12217 +#ifdef CONFIG_AUFS_DIRREN
12218 +enum au_brid_type {
12225 +struct au_dr_brid {
12226 + enum au_brid_type type;
12228 + uuid_t uuid; /* unimplemented yet */
12234 +/* 20 is the max digits length of ulong 64 */
12235 +/* brid-type "_" uuid "_" inum */
12236 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12237 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12239 +struct au_dr_hino {
12240 + struct hlist_bl_node dr_hnode;
12245 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12246 + struct au_dr_brid dr_brid;
12249 +struct au_dr_lookup {
12250 + /* dr_name is pointed by struct au_do_lookup_args.name */
12251 + struct qstr dr_name; /* subset of dr_info */
12252 + aufs_bindex_t ninfo;
12253 + struct au_drinfo **drinfo;
12256 +struct au_dr_hino;
12258 +struct au_dr_br { };
12259 +struct au_dr_lookup { };
12262 +/* ---------------------------------------------------------------------- */
12265 +struct au_do_lookup_args;
12267 +#ifdef CONFIG_AUFS_DIRREN
12268 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12269 + struct au_dr_hino *add_ent);
12270 +void au_dr_hino_free(struct au_dr_br *dr);
12271 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12272 + const struct path *path);
12273 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12274 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12275 + struct qstr *dst_name, void *_rev);
12276 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12277 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12278 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12279 + aufs_bindex_t bindex);
12280 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12281 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12283 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12284 +int au_dr_opt_set(struct super_block *sb);
12285 +int au_dr_opt_flush(struct super_block *sb);
12286 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12288 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12289 + struct au_dr_hino *add_ent);
12290 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12291 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12292 + const struct path *path);
12293 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12294 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12295 + struct qstr *dst_name, void *_rev);
12296 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12297 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12299 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12300 + aufs_bindex_t bindex);
12301 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12302 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12303 + aufs_bindex_t bindex, ino_t h_ino);
12304 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12305 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12306 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12307 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12310 +/* ---------------------------------------------------------------------- */
12312 +#ifdef CONFIG_AUFS_DIRREN
12313 +static inline int au_dr_ihash(ino_t h_ino)
12315 + return h_ino % AuDirren_NHASH;
12318 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12321 +#endif /* __KERNEL__ */
12322 +#endif /* __AUFS_DIRREN_H__ */
12323 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12324 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12325 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12327 +// SPDX-License-Identifier: GPL-2.0
12329 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12331 + * This program is free software; you can redistribute it and/or modify
12332 + * it under the terms of the GNU General Public License as published by
12333 + * the Free Software Foundation; either version 2 of the License, or
12334 + * (at your option) any later version.
12336 + * This program is distributed in the hope that it will be useful,
12337 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12338 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12339 + * GNU General Public License for more details.
12341 + * You should have received a copy of the GNU General Public License
12342 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12346 + * dynamically customizable operations for regular files
12351 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12354 + * How large will these lists be?
12355 + * Usually just a few elements, 20-30 at most for each, I guess.
12357 +static struct hlist_bl_head dynop[AuDyLast];
12359 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12360 + const void *h_op)
12362 + struct au_dykey *key, *tmp;
12363 + struct hlist_bl_node *pos;
12366 + hlist_bl_lock(hbl);
12367 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12368 + if (tmp->dk_op.dy_hop == h_op) {
12369 + if (kref_get_unless_zero(&tmp->dk_kref))
12373 + hlist_bl_unlock(hbl);
12378 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12380 + struct au_dykey **k, *found;
12381 + const void *h_op = key->dk_op.dy_hop;
12385 + k = br->br_dykey;
12386 + for (i = 0; i < AuBrDynOp; i++)
12388 + if (k[i]->dk_op.dy_hop == h_op) {
12395 + spin_lock(&br->br_dykey_lock);
12396 + for (; i < AuBrDynOp; i++)
12398 + if (k[i]->dk_op.dy_hop == h_op) {
12406 + spin_unlock(&br->br_dykey_lock);
12407 + BUG_ON(i == AuBrDynOp); /* expand the array */
12413 +/* kref_get() if @key is already added */
12414 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12416 + struct au_dykey *tmp, *found;
12417 + struct hlist_bl_node *pos;
12418 + const void *h_op = key->dk_op.dy_hop;
12421 + hlist_bl_lock(hbl);
12422 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12423 + if (tmp->dk_op.dy_hop == h_op) {
12424 + if (kref_get_unless_zero(&tmp->dk_kref))
12429 + hlist_bl_add_head(&key->dk_hnode, hbl);
12430 + hlist_bl_unlock(hbl);
12437 +static void dy_free_rcu(struct rcu_head *rcu)
12439 + struct au_dykey *key;
12441 + key = container_of(rcu, struct au_dykey, dk_rcu);
12446 +static void dy_free(struct kref *kref)
12448 + struct au_dykey *key;
12449 + struct hlist_bl_head *hbl;
12451 + key = container_of(kref, struct au_dykey, dk_kref);
12452 + hbl = dynop + key->dk_op.dy_type;
12453 + au_hbl_del(&key->dk_hnode, hbl);
12454 + call_rcu(&key->dk_rcu, dy_free_rcu);
12457 +void au_dy_put(struct au_dykey *key)
12459 + kref_put(&key->dk_kref, dy_free);
12462 +/* ---------------------------------------------------------------------- */
12464 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12466 +#ifdef CONFIG_AUFS_DEBUG
12467 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12468 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12470 +#define DyDbgDeclare(cnt) do {} while (0)
12471 +#define DyDbgInc(cnt) do {} while (0)
12474 +#define DySet(func, dst, src, h_op, h_sb) do { \
12476 + if (h_op->func) { \
12478 + dst.func = src.func; \
12480 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12484 +#define DySetForce(func, dst, src) do { \
12485 + AuDebugOn(!src.func); \
12487 + dst.func = src.func; \
12490 +#define DySetAop(func) \
12491 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12492 +#define DySetAopForce(func) \
12493 + DySetForce(func, dyaop->da_op, aufs_aop)
12495 +static void dy_aop(struct au_dykey *key, const void *h_op,
12496 + struct super_block *h_sb __maybe_unused)
12498 + struct au_dyaop *dyaop = (void *)key;
12499 + const struct address_space_operations *h_aop = h_op;
12500 + DyDbgDeclare(cnt);
12502 + AuDbg("%s\n", au_sbtype(h_sb));
12504 + DySetAop(writepage);
12505 + DySetAopForce(read_folio); /* force */
12506 + DySetAop(writepages);
12507 + DySetAop(dirty_folio);
12508 + DySetAop(invalidate_folio);
12509 + DySetAop(readahead);
12510 + DySetAop(write_begin);
12511 + DySetAop(write_end);
12513 + DySetAop(release_folio);
12514 + DySetAop(free_folio);
12515 + /* this one will be changed according to an aufs mount option */
12516 + DySetAop(direct_IO);
12517 + DySetAop(migrate_folio);
12518 + DySetAop(launder_folio);
12519 + DySetAop(is_partially_uptodate);
12520 + DySetAop(is_dirty_writeback);
12521 + DySetAop(error_remove_page);
12522 + DySetAop(swap_activate);
12523 + DySetAop(swap_deactivate);
12524 + DySetAop(swap_rw);
12526 + DyDbgSize(cnt, *h_aop);
12529 +/* ---------------------------------------------------------------------- */
12531 +static void dy_bug(struct kref *kref)
12536 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12538 + struct au_dykey *key, *old;
12539 + struct hlist_bl_head *hbl;
12542 + void (*set)(struct au_dykey *key, const void *h_op,
12543 + struct super_block *h_sb __maybe_unused);
12545 + static const struct op a[] = {
12547 + .sz = sizeof(struct au_dyaop),
12551 + const struct op *p;
12553 + hbl = dynop + op->dy_type;
12554 + key = dy_gfind_get(hbl, op->dy_hop);
12556 + goto out_add; /* success */
12558 + p = a + op->dy_type;
12559 + key = kzalloc(p->sz, GFP_NOFS);
12560 + if (unlikely(!key)) {
12561 + key = ERR_PTR(-ENOMEM);
12565 + key->dk_op.dy_hop = op->dy_hop;
12566 + kref_init(&key->dk_kref);
12567 + p->set(key, op->dy_hop, au_br_sb(br));
12568 + old = dy_gadd(hbl, key);
12570 + au_kfree_rcu(key);
12575 + old = dy_bradd(br, key);
12577 + /* its ref-count should never be zero here */
12578 + kref_put(&key->dk_kref, dy_bug);
12583 +/* ---------------------------------------------------------------------- */
12585 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12586 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12587 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12588 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12589 + * See the aufs manual in detail.
12591 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12594 + dyaop->da_op.direct_IO = NULL;
12596 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12599 +static struct au_dyaop *dy_aget(struct au_branch *br,
12600 + const struct address_space_operations *h_aop,
12603 + struct au_dyaop *dyaop;
12604 + struct au_dynop op;
12606 + op.dy_type = AuDy_AOP;
12607 + op.dy_haop = h_aop;
12608 + dyaop = (void *)dy_get(&op, br);
12609 + if (IS_ERR(dyaop))
12611 + dy_adx(dyaop, do_dx);
12617 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12618 + struct inode *h_inode)
12621 + struct super_block *sb;
12622 + struct au_branch *br;
12623 + struct au_dyaop *dyaop;
12625 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12626 + IiMustWriteLock(inode);
12628 + sb = inode->i_sb;
12629 + br = au_sbr(sb, bindex);
12630 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12631 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12632 + err = PTR_ERR(dyaop);
12633 + if (IS_ERR(dyaop))
12634 + /* unnecessary to call dy_fput() */
12638 + inode->i_mapping->a_ops = &dyaop->da_op;
12645 + * Is it safe to replace a_ops during the inode/file is in operation?
12646 + * Yes, I hope so.
12648 +int au_dy_irefresh(struct inode *inode)
12651 + aufs_bindex_t btop;
12652 + struct inode *h_inode;
12655 + if (S_ISREG(inode->i_mode)) {
12656 + btop = au_ibtop(inode);
12657 + h_inode = au_h_iptr(inode, btop);
12658 + err = au_dy_iaop(inode, btop, h_inode);
12663 +void au_dy_arefresh(int do_dx)
12665 + struct hlist_bl_head *hbl;
12666 + struct hlist_bl_node *pos;
12667 + struct au_dykey *key;
12669 + hbl = dynop + AuDy_AOP;
12670 + hlist_bl_lock(hbl);
12671 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12672 + dy_adx((void *)key, do_dx);
12673 + hlist_bl_unlock(hbl);
12676 +/* ---------------------------------------------------------------------- */
12678 +void __init au_dy_init(void)
12682 + for (i = 0; i < AuDyLast; i++)
12683 + INIT_HLIST_BL_HEAD(dynop + i);
12686 +void au_dy_fin(void)
12690 + for (i = 0; i < AuDyLast; i++)
12691 + WARN_ON(!hlist_bl_empty(dynop + i));
12693 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12694 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12695 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12697 +/* SPDX-License-Identifier: GPL-2.0 */
12699 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12701 + * This program is free software; you can redistribute it and/or modify
12702 + * it under the terms of the GNU General Public License as published by
12703 + * the Free Software Foundation; either version 2 of the License, or
12704 + * (at your option) any later version.
12706 + * This program is distributed in the hope that it will be useful,
12707 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12708 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12709 + * GNU General Public License for more details.
12711 + * You should have received a copy of the GNU General Public License
12712 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12716 + * dynamically customizable operations (for regular files only)
12719 +#ifndef __AUFS_DYNOP_H__
12720 +#define __AUFS_DYNOP_H__
12724 +#include <linux/fs.h>
12725 +#include <linux/kref.h>
12727 +enum {AuDy_AOP, AuDyLast};
12732 + const void *dy_hop;
12733 + const struct address_space_operations *dy_haop;
12739 + struct hlist_bl_node dk_hnode;
12740 + struct rcu_head dk_rcu;
12742 + struct au_dynop dk_op;
12745 + * during I am in the branch local array, kref is gotten. when the
12746 + * branch is removed, kref is put.
12748 + struct kref dk_kref;
12751 +/* stop unioning since their sizes are very different from each other */
12753 + struct au_dykey da_key;
12754 + struct address_space_operations da_op; /* not const */
12756 +/* make sure that 'struct au_dykey *' can be any type */
12757 +static_assert(!offsetof(struct au_dyaop, da_key));
12759 +/* ---------------------------------------------------------------------- */
12763 +void au_dy_put(struct au_dykey *key);
12764 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12765 + struct inode *h_inode);
12766 +int au_dy_irefresh(struct inode *inode);
12767 +void au_dy_arefresh(int do_dio);
12769 +void __init au_dy_init(void);
12770 +void au_dy_fin(void);
12772 +#endif /* __KERNEL__ */
12773 +#endif /* __AUFS_DYNOP_H__ */
12774 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12775 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12776 +++ linux/fs/aufs/export.c 2022-12-17 09:21:34.796521861 +0100
12778 +// SPDX-License-Identifier: GPL-2.0
12780 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12782 + * This program is free software; you can redistribute it and/or modify
12783 + * it under the terms of the GNU General Public License as published by
12784 + * the Free Software Foundation; either version 2 of the License, or
12785 + * (at your option) any later version.
12787 + * This program is distributed in the hope that it will be useful,
12788 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12789 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12790 + * GNU General Public License for more details.
12792 + * You should have received a copy of the GNU General Public License
12793 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12800 +#include <linux/exportfs.h>
12801 +#include <linux/fs_struct.h>
12802 +#include <linux/nsproxy.h>
12803 +#include <linux/random.h>
12804 +#include <linux/writeback.h>
12808 +#ifdef CONFIG_AUFS_INO_T_64
12816 +static ino_t decode_ino(__u32 *a)
12820 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12822 +#ifdef CONFIG_AUFS_INO_T_64
12828 +static void encode_ino(__u32 *a, ino_t ino)
12834 +#ifdef CONFIG_AUFS_INO_T_64
12839 +/* NFS file handle */
12843 +#ifdef CONFIG_AUFS_INO_T_64
12844 + /* support 64bit inode number */
12857 + Fh_ino = Fh_ino1,
12858 + Fh_dir_ino = Fh_dir_ino1
12861 +static int au_test_anon(struct dentry *dentry)
12863 + /* note: read d_flags without d_lock */
12864 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12867 +int au_test_nfsd(void)
12870 + struct task_struct *tsk = current;
12871 + char comm[sizeof(tsk->comm)];
12874 + if (tsk->flags & PF_KTHREAD) {
12875 + get_task_comm(comm, tsk);
12876 + ret = !strcmp(comm, "nfsd");
12882 +/* ---------------------------------------------------------------------- */
12883 +/* inode generation external table */
12885 +void au_xigen_inc(struct inode *inode)
12890 + struct super_block *sb;
12891 + struct au_sbinfo *sbinfo;
12893 + sb = inode->i_sb;
12894 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12896 + sbinfo = au_sbi(sb);
12897 + pos = inode->i_ino;
12898 + pos *= sizeof(igen);
12899 + igen = inode->i_generation + 1;
12900 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12901 + if (sz == sizeof(igen))
12902 + return; /* success */
12904 + if (unlikely(sz >= 0))
12905 + AuIOErr("xigen error (%zd)\n", sz);
12908 +int au_xigen_new(struct inode *inode)
12913 + struct super_block *sb;
12914 + struct au_sbinfo *sbinfo;
12915 + struct file *file;
12918 + /* todo: dirty, at mount time */
12919 + if (inode->i_ino == AUFS_ROOT_INO)
12921 + sb = inode->i_sb;
12922 + SiMustAnyLock(sb);
12923 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12927 + pos = inode->i_ino;
12928 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12929 + AuIOErr1("too large i%lld\n", pos);
12932 + pos *= sizeof(inode->i_generation);
12935 + sbinfo = au_sbi(sb);
12936 + file = sbinfo->si_xigen;
12939 + if (vfsub_f_size_read(file)
12940 + < pos + sizeof(inode->i_generation)) {
12941 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12942 + sz = xino_fwrite(file, &inode->i_generation,
12943 + sizeof(inode->i_generation), &pos);
12945 + sz = xino_fread(file, &inode->i_generation,
12946 + sizeof(inode->i_generation), &pos);
12947 + if (sz == sizeof(inode->i_generation))
12948 + goto out; /* success */
12951 + if (unlikely(sz >= 0)) {
12953 + AuIOErr("xigen error (%zd)\n", sz);
12960 +int au_xigen_set(struct super_block *sb, struct path *path)
12963 + struct au_sbinfo *sbinfo;
12964 + struct file *file;
12966 + SiMustWriteLock(sb);
12968 + sbinfo = au_sbi(sb);
12969 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12970 + err = PTR_ERR(file);
12971 + if (IS_ERR(file))
12974 + if (sbinfo->si_xigen)
12975 + fput(sbinfo->si_xigen);
12976 + sbinfo->si_xigen = file;
12983 +void au_xigen_clr(struct super_block *sb)
12985 + struct au_sbinfo *sbinfo;
12987 + SiMustWriteLock(sb);
12989 + sbinfo = au_sbi(sb);
12990 + if (sbinfo->si_xigen) {
12991 + fput(sbinfo->si_xigen);
12992 + sbinfo->si_xigen = NULL;
12996 +/* ---------------------------------------------------------------------- */
12998 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13001 + struct dentry *dentry, *d;
13002 + struct inode *inode;
13003 + unsigned int sigen;
13006 + inode = ilookup(sb, ino);
13010 + dentry = ERR_PTR(-ESTALE);
13011 + sigen = au_sigen(sb);
13012 + if (unlikely(au_is_bad_inode(inode)
13013 + || IS_DEADDIR(inode)
13014 + || sigen != au_iigen(inode, NULL)))
13018 + if (!dir_ino || S_ISDIR(inode->i_mode))
13019 + dentry = d_find_alias(inode);
13021 + spin_lock(&inode->i_lock);
13022 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13023 + spin_lock(&d->d_lock);
13024 + if (!au_test_anon(d)
13025 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13026 + dentry = dget_dlock(d);
13027 + spin_unlock(&d->d_lock);
13030 + spin_unlock(&d->d_lock);
13032 + spin_unlock(&inode->i_lock);
13034 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13035 + /* need to refresh */
13043 + AuTraceErrPtr(dentry);
13047 +/* ---------------------------------------------------------------------- */
13049 +/* todo: dirty? */
13050 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13052 +struct au_compare_mnt_args {
13054 + struct super_block *sb;
13057 + struct vfsmount *mnt;
13060 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13062 + struct au_compare_mnt_args *a = arg;
13064 + if (mnt->mnt_sb != a->sb)
13066 + a->mnt = mntget(mnt);
13070 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13073 + struct path root;
13074 + struct au_compare_mnt_args args = {
13078 + get_fs_root(current->fs, &root);
13080 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13081 + rcu_read_unlock();
13084 + AuDebugOn(!args.mnt);
13088 +struct au_nfsd_si_lock {
13089 + unsigned int sigen;
13090 + aufs_bindex_t bindex, br_id;
13091 + unsigned char force_lock;
13094 +static int si_nfsd_read_lock(struct super_block *sb,
13095 + struct au_nfsd_si_lock *nsi_lock)
13098 + aufs_bindex_t bindex;
13100 + si_read_lock(sb, AuLock_FLUSH);
13102 + /* branch id may be wrapped around */
13104 + bindex = au_br_index(sb, nsi_lock->br_id);
13105 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13106 + goto out; /* success */
13110 + if (!nsi_lock->force_lock)
13111 + si_read_unlock(sb);
13114 + nsi_lock->bindex = bindex;
13118 +struct find_name_by_ino {
13119 + struct dir_context ctx;
13120 + int called, found;
13127 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13128 + loff_t offset, u64 ino, unsigned int d_type)
13130 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13134 + if (a->ino != ino)
13137 + memcpy(a->name, name, namelen);
13138 + a->namelen = namelen;
13143 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13144 + struct au_nfsd_si_lock *nsi_lock)
13146 + struct dentry *dentry, *parent;
13147 + struct file *file;
13148 + struct inode *dir;
13149 + struct find_name_by_ino arg = {
13151 + .actor = find_name_by_ino
13156 + parent = path->dentry;
13158 + si_read_unlock(parent->d_sb);
13159 + file = vfsub_dentry_open(path, au_dir_roflags);
13160 + dentry = (void *)file;
13161 + if (IS_ERR(file))
13164 + dentry = ERR_PTR(-ENOMEM);
13165 + arg.name = (void *)__get_free_page(GFP_NOFS);
13166 + if (unlikely(!arg.name))
13173 + err = vfsub_iterate_dir(file, &arg.ctx);
13174 + } while (!err && !arg.found && arg.called);
13175 + dentry = ERR_PTR(err);
13176 + if (unlikely(err))
13178 + /* instead of ENOENT */
13179 + dentry = ERR_PTR(-ESTALE);
13183 + /* do not call vfsub_lkup_one() */
13184 + dir = d_inode(parent);
13185 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13186 + AuTraceErrPtr(dentry);
13187 + if (IS_ERR(dentry))
13189 + AuDebugOn(au_test_anon(dentry));
13190 + if (unlikely(d_really_is_negative(dentry))) {
13192 + dentry = ERR_PTR(-ENOENT);
13196 + free_page((unsigned long)arg.name);
13200 + if (unlikely(nsi_lock
13201 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13202 + if (!IS_ERR(dentry)) {
13204 + dentry = ERR_PTR(-ESTALE);
13206 + AuTraceErrPtr(dentry);
13210 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13212 + struct au_nfsd_si_lock *nsi_lock)
13214 + struct dentry *dentry;
13215 + struct path path;
13217 + if (dir_ino != AUFS_ROOT_INO) {
13218 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13219 + dentry = path.dentry;
13220 + if (!path.dentry || IS_ERR(path.dentry))
13222 + AuDebugOn(au_test_anon(path.dentry));
13224 + path.dentry = dget(sb->s_root);
13226 + path.mnt = au_mnt_get(sb);
13227 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13231 + AuTraceErrPtr(dentry);
13235 +/* ---------------------------------------------------------------------- */
13237 +static int h_acceptable(void *expv, struct dentry *dentry)
13242 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13243 + char *buf, int len, struct super_block *sb)
13247 + struct path path;
13249 + p = d_path(h_rootpath, buf, len);
13254 + path.mnt = h_rootpath->mnt;
13255 + path.dentry = h_parent;
13256 + p = d_path(&path, buf, len);
13262 + path.mnt = au_mnt_get(sb);
13263 + path.dentry = sb->s_root;
13264 + p = d_path(&path, buf, len - strlen(p));
13265 + mntput(path.mnt);
13269 + p[strlen(p)] = '/';
13272 + AuTraceErrPtr(p);
13277 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13278 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13280 + struct dentry *dentry, *h_parent, *root;
13281 + struct super_block *h_sb;
13282 + char *pathname, *p;
13283 + struct vfsmount *h_mnt;
13284 + struct au_branch *br;
13286 + struct path path;
13288 + br = au_sbr(sb, nsi_lock->bindex);
13289 + h_mnt = au_br_mnt(br);
13290 + h_sb = h_mnt->mnt_sb;
13291 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13293 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13294 + fh_len - Fh_tail, fh[Fh_h_type],
13295 + h_acceptable, /*context*/NULL);
13297 + dentry = h_parent;
13298 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13299 + AuWarn1("%s decode_fh failed, %ld\n",
13300 + au_sbtype(h_sb), PTR_ERR(h_parent));
13304 + if (unlikely(au_test_anon(h_parent))) {
13305 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13306 + au_sbtype(h_sb));
13307 + goto out_h_parent;
13310 + dentry = ERR_PTR(-ENOMEM);
13311 + pathname = (void *)__get_free_page(GFP_NOFS);
13312 + if (unlikely(!pathname))
13313 + goto out_h_parent;
13315 + root = sb->s_root;
13316 + path.mnt = h_mnt;
13317 + di_read_lock_parent(root, !AuLock_IR);
13318 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13319 + di_read_unlock(root, !AuLock_IR);
13320 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13321 + dentry = (void *)p;
13323 + goto out_pathname;
13325 + si_read_unlock(sb);
13326 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13327 + dentry = ERR_PTR(err);
13328 + if (unlikely(err))
13331 + dentry = ERR_PTR(-ENOENT);
13332 + AuDebugOn(au_test_anon(path.dentry));
13333 + if (unlikely(d_really_is_negative(path.dentry)))
13336 + if (ino != d_inode(path.dentry)->i_ino)
13337 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13339 + dentry = dget(path.dentry);
13344 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13345 + if (!IS_ERR(dentry)) {
13347 + dentry = ERR_PTR(-ESTALE);
13350 + free_page((unsigned long)pathname);
13354 + AuTraceErrPtr(dentry);
13358 +/* ---------------------------------------------------------------------- */
13360 +static struct dentry *
13361 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13364 + struct dentry *dentry;
13365 + __u32 *fh = fid->raw;
13366 + struct au_branch *br;
13367 + ino_t ino, dir_ino;
13368 + struct au_nfsd_si_lock nsi_lock = {
13372 + dentry = ERR_PTR(-ESTALE);
13373 + /* it should never happen, but the file handle is unreliable */
13374 + if (unlikely(fh_len < Fh_tail))
13376 + nsi_lock.sigen = fh[Fh_sigen];
13377 + nsi_lock.br_id = fh[Fh_br_id];
13379 + /* branch id may be wrapped around */
13381 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13383 + nsi_lock.force_lock = 1;
13385 + /* is this inode still cached? */
13386 + ino = decode_ino(fh + Fh_ino);
13387 + /* it should never happen */
13388 + if (unlikely(ino == AUFS_ROOT_INO))
13391 + dir_ino = decode_ino(fh + Fh_dir_ino);
13392 + dentry = decode_by_ino(sb, ino, dir_ino);
13393 + if (IS_ERR(dentry))
13398 + /* is the parent dir cached? */
13399 + br = au_sbr(sb, nsi_lock.bindex);
13400 + au_lcnt_inc(&br->br_nfiles);
13401 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13402 + if (IS_ERR(dentry))
13407 + /* lookup path */
13408 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13409 + if (IS_ERR(dentry))
13411 + if (unlikely(!dentry))
13412 + /* todo?: make it ESTALE */
13416 + if (!au_digen_test(dentry, au_sigen(sb))
13417 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13418 + goto out_unlock; /* success */
13421 + dentry = ERR_PTR(-ESTALE);
13424 + au_lcnt_dec(&br->br_nfiles);
13425 + si_read_unlock(sb);
13427 + AuTraceErrPtr(dentry);
13431 +#if 0 /* reserved for future use */
13432 +/* support subtreecheck option */
13433 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13434 + int fh_len, int fh_type)
13436 + struct dentry *parent;
13437 + __u32 *fh = fid->raw;
13440 + dir_ino = decode_ino(fh + Fh_dir_ino);
13441 + parent = decode_by_ino(sb, dir_ino, 0);
13442 + if (IS_ERR(parent))
13445 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13446 + dir_ino, fh, fh_len);
13449 + AuTraceErrPtr(parent);
13454 +/* ---------------------------------------------------------------------- */
13456 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13457 + struct inode *dir)
13460 + aufs_bindex_t bindex;
13461 + struct super_block *sb, *h_sb;
13462 + struct dentry *dentry, *parent, *h_parent;
13463 + struct inode *h_dir;
13464 + struct au_branch *br;
13467 + if (unlikely(*max_len <= Fh_tail)) {
13468 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13472 + err = FILEID_ROOT;
13473 + if (inode->i_ino == AUFS_ROOT_INO) {
13474 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13479 + sb = inode->i_sb;
13480 + err = si_read_lock(sb, AuLock_FLUSH);
13481 + if (unlikely(err))
13484 +#ifdef CONFIG_AUFS_DEBUG
13485 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13486 + AuWarn1("NFS-exporting requires xino\n");
13490 + ii_read_lock_child(inode);
13491 + bindex = au_ibtop(inode);
13493 + dentry = d_find_any_alias(inode);
13494 + if (unlikely(!dentry))
13496 + AuDebugOn(au_test_anon(dentry));
13497 + parent = dget_parent(dentry);
13499 + if (unlikely(!parent))
13501 + if (d_really_is_positive(parent))
13502 + dir = d_inode(parent);
13505 + ii_read_lock_parent(dir);
13506 + h_dir = au_h_iptr(dir, bindex);
13507 + ii_read_unlock(dir);
13508 + if (unlikely(!h_dir))
13510 + h_parent = d_find_any_alias(h_dir);
13511 + if (unlikely(!h_parent))
13512 + goto out_hparent;
13515 + br = au_sbr(sb, bindex);
13516 + h_sb = au_br_sb(br);
13517 + if (unlikely(!h_sb->s_export_op)) {
13518 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13519 + goto out_hparent;
13522 + fh[Fh_br_id] = br->br_id;
13523 + fh[Fh_sigen] = au_sigen(sb);
13524 + encode_ino(fh + Fh_ino, inode->i_ino);
13525 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13526 + fh[Fh_igen] = inode->i_generation;
13528 + *max_len -= Fh_tail;
13529 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13531 + /*connectable or subtreecheck*/0);
13532 + err = fh[Fh_h_type];
13533 + *max_len += Fh_tail;
13534 + /* todo: macros? */
13535 + if (err != FILEID_INVALID)
13538 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13545 + ii_read_unlock(inode);
13546 + si_read_unlock(sb);
13548 + if (unlikely(err < 0))
13549 + err = FILEID_INVALID;
13553 +/* ---------------------------------------------------------------------- */
13555 +static int aufs_commit_metadata(struct inode *inode)
13558 + aufs_bindex_t bindex;
13559 + struct super_block *sb;
13560 + struct inode *h_inode;
13561 + int (*f)(struct inode *inode);
13563 + sb = inode->i_sb;
13564 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13565 + ii_write_lock_child(inode);
13566 + bindex = au_ibtop(inode);
13567 + AuDebugOn(bindex < 0);
13568 + h_inode = au_h_iptr(inode, bindex);
13570 + f = h_inode->i_sb->s_export_op->commit_metadata;
13572 + err = f(h_inode);
13574 + err = sync_inode_metadata(h_inode, /*wait*/1);
13576 + au_cpup_attr_timesizes(inode);
13577 + ii_write_unlock(inode);
13578 + si_read_unlock(sb);
13582 +/* ---------------------------------------------------------------------- */
13584 +static struct export_operations aufs_export_op = {
13585 + .fh_to_dentry = aufs_fh_to_dentry,
13586 + /* .fh_to_parent = aufs_fh_to_parent, */
13587 + .encode_fh = aufs_encode_fh,
13588 + .commit_metadata = aufs_commit_metadata
13591 +void au_export_init(struct super_block *sb)
13593 + struct au_sbinfo *sbinfo;
13596 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13597 + && IS_MODULE(CONFIG_EXPORTFS),
13598 + AUFS_NAME ": unsupported configuration "
13599 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13601 + sb->s_export_op = &aufs_export_op;
13602 + sbinfo = au_sbi(sb);
13603 + sbinfo->si_xigen = NULL;
13604 + get_random_bytes(&u, sizeof(u));
13605 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13606 + atomic_set(&sbinfo->si_xigen_next, u);
13608 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13609 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13610 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13612 +// SPDX-License-Identifier: GPL-2.0
13614 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13616 + * This program is free software; you can redistribute it and/or modify
13617 + * it under the terms of the GNU General Public License as published by
13618 + * the Free Software Foundation; either version 2 of the License, or
13619 + * (at your option) any later version.
13621 + * This program is distributed in the hope that it will be useful,
13622 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13623 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13624 + * GNU General Public License for more details.
13626 + * You should have received a copy of the GNU General Public License
13627 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13631 + * File-based Hierarchy Storage Management
13634 +#include <linux/anon_inodes.h>
13635 +#include <linux/poll.h>
13636 +#include <linux/seq_file.h>
13637 +#include <linux/statfs.h>
13640 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13642 + struct au_sbinfo *sbinfo;
13643 + struct au_fhsm *fhsm;
13645 + SiMustAnyLock(sb);
13647 + sbinfo = au_sbi(sb);
13648 + fhsm = &sbinfo->si_fhsm;
13649 + AuDebugOn(!fhsm);
13650 + return fhsm->fhsm_bottom;
13653 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13655 + struct au_sbinfo *sbinfo;
13656 + struct au_fhsm *fhsm;
13658 + SiMustWriteLock(sb);
13660 + sbinfo = au_sbi(sb);
13661 + fhsm = &sbinfo->si_fhsm;
13662 + AuDebugOn(!fhsm);
13663 + fhsm->fhsm_bottom = bindex;
13666 +/* ---------------------------------------------------------------------- */
13668 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13670 + struct au_br_fhsm *bf;
13672 + bf = br->br_fhsm;
13673 + MtxMustLock(&bf->bf_lock);
13675 + return !bf->bf_readable
13676 + || time_after(jiffies,
13677 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13680 +/* ---------------------------------------------------------------------- */
13682 +static void au_fhsm_notify(struct super_block *sb, int val)
13684 + struct au_sbinfo *sbinfo;
13685 + struct au_fhsm *fhsm;
13687 + SiMustAnyLock(sb);
13689 + sbinfo = au_sbi(sb);
13690 + fhsm = &sbinfo->si_fhsm;
13691 + if (au_fhsm_pid(fhsm)
13692 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13693 + atomic_set(&fhsm->fhsm_readable, val);
13695 + wake_up(&fhsm->fhsm_wqh);
13699 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13700 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13703 + struct au_branch *br;
13704 + struct au_br_fhsm *bf;
13706 + br = au_sbr(sb, bindex);
13707 + AuDebugOn(au_br_rdonly(br));
13708 + bf = br->br_fhsm;
13712 + mutex_lock(&bf->bf_lock);
13714 + MtxMustLock(&bf->bf_lock);
13716 + /* sb->s_root for NFS is unreliable */
13717 + err = au_br_stfs(br, &bf->bf_stfs);
13718 + if (unlikely(err)) {
13719 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13723 + bf->bf_jiffy = jiffies;
13724 + bf->bf_readable = 1;
13726 + au_fhsm_notify(sb, /*val*/1);
13728 + *rstfs = bf->bf_stfs;
13732 + mutex_unlock(&bf->bf_lock);
13733 + au_fhsm_notify(sb, /*val*/1);
13738 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13741 + struct au_sbinfo *sbinfo;
13742 + struct au_fhsm *fhsm;
13743 + struct au_branch *br;
13744 + struct au_br_fhsm *bf;
13746 + AuDbg("b%d, force %d\n", bindex, force);
13747 + SiMustAnyLock(sb);
13749 + sbinfo = au_sbi(sb);
13750 + fhsm = &sbinfo->si_fhsm;
13751 + if (!au_ftest_si(sbinfo, FHSM)
13752 + || fhsm->fhsm_bottom == bindex)
13755 + br = au_sbr(sb, bindex);
13756 + bf = br->br_fhsm;
13758 + mutex_lock(&bf->bf_lock);
13760 + || au_fhsm_pid(fhsm)
13761 + || au_fhsm_test_jiffy(sbinfo, br))
13762 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13764 + mutex_unlock(&bf->bf_lock);
13767 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13769 + aufs_bindex_t bindex, bbot;
13770 + struct au_branch *br;
13772 + /* exclude the bottom */
13773 + bbot = au_fhsm_bottom(sb);
13774 + for (bindex = 0; bindex < bbot; bindex++) {
13775 + br = au_sbr(sb, bindex);
13776 + if (au_br_fhsm(br->br_perm))
13777 + au_fhsm_wrote(sb, bindex, force);
13781 +/* ---------------------------------------------------------------------- */
13783 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13786 + struct au_sbinfo *sbinfo;
13787 + struct au_fhsm *fhsm;
13790 + sbinfo = file->private_data;
13791 + fhsm = &sbinfo->si_fhsm;
13792 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13793 + if (atomic_read(&fhsm->fhsm_readable))
13794 + mask = EPOLLIN /* | EPOLLRDNORM */;
13797 + AuDbg("mask 0x%x\n", mask);
13801 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13802 + struct aufs_stfs *stfs, __s16 brid)
13806 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13808 + err = __put_user(brid, &stbr->brid);
13809 + if (unlikely(err))
13815 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13816 + struct aufs_stbr __user *stbr, size_t count)
13820 + aufs_bindex_t bindex, bbot;
13821 + struct au_branch *br;
13822 + struct au_br_fhsm *bf;
13824 + /* except the bottom branch */
13827 + bbot = au_fhsm_bottom(sb);
13828 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13829 + br = au_sbr(sb, bindex);
13830 + if (!au_br_fhsm(br->br_perm))
13833 + bf = br->br_fhsm;
13834 + mutex_lock(&bf->bf_lock);
13835 + if (bf->bf_readable) {
13837 + if (count >= sizeof(*stbr))
13838 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13841 + bf->bf_readable = 0;
13842 + count -= sizeof(*stbr);
13846 + mutex_unlock(&bf->bf_lock);
13849 + err = sizeof(*stbr) * nstbr;
13854 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13859 + aufs_bindex_t nfhsm, bindex, bbot;
13860 + struct au_sbinfo *sbinfo;
13861 + struct au_fhsm *fhsm;
13862 + struct au_branch *br;
13863 + struct super_block *sb;
13866 + sbinfo = file->private_data;
13867 + fhsm = &sbinfo->si_fhsm;
13869 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13870 + if (!atomic_read(&fhsm->fhsm_readable)) {
13871 + if (vfsub_file_flags(file) & O_NONBLOCK)
13874 + err = wait_event_interruptible_locked_irq
13876 + atomic_read(&fhsm->fhsm_readable));
13878 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13879 + if (unlikely(err))
13882 + /* sb may already be dead */
13883 + au_rw_read_lock(&sbinfo->si_rwsem);
13884 + readable = atomic_read(&fhsm->fhsm_readable);
13885 + if (readable > 0) {
13886 + sb = sbinfo->si_sb;
13888 + /* exclude the bottom branch */
13890 + bbot = au_fhsm_bottom(sb);
13891 + for (bindex = 0; bindex < bbot; bindex++) {
13892 + br = au_sbr(sb, bindex);
13893 + if (au_br_fhsm(br->br_perm))
13897 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13898 + atomic_set(&fhsm->fhsm_readable, 0);
13899 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13903 + au_rw_read_unlock(&sbinfo->si_rwsem);
13911 +static int au_fhsm_release(struct inode *inode, struct file *file)
13913 + struct au_sbinfo *sbinfo;
13914 + struct au_fhsm *fhsm;
13916 + /* sb may already be dead */
13917 + sbinfo = file->private_data;
13918 + fhsm = &sbinfo->si_fhsm;
13919 + spin_lock(&fhsm->fhsm_spin);
13920 + fhsm->fhsm_pid = 0;
13921 + spin_unlock(&fhsm->fhsm_spin);
13922 + kobject_put(&sbinfo->si_kobj);
13927 +static const struct file_operations au_fhsm_fops = {
13928 + .owner = THIS_MODULE,
13929 + .llseek = noop_llseek,
13930 + .read = au_fhsm_read,
13931 + .poll = au_fhsm_poll,
13932 + .release = au_fhsm_release
13935 +int au_fhsm_fd(struct super_block *sb, int oflags)
13938 + struct au_sbinfo *sbinfo;
13939 + struct au_fhsm *fhsm;
13942 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13946 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13950 + sbinfo = au_sbi(sb);
13951 + fhsm = &sbinfo->si_fhsm;
13952 + spin_lock(&fhsm->fhsm_spin);
13953 + if (!fhsm->fhsm_pid)
13954 + fhsm->fhsm_pid = current->pid;
13957 + spin_unlock(&fhsm->fhsm_spin);
13958 + if (unlikely(err))
13961 + oflags |= O_RDONLY;
13962 + /* oflags |= FMODE_NONOTIFY; */
13963 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13965 + if (unlikely(fd < 0))
13968 + /* succeed regardless 'fhsm' status */
13969 + kobject_get(&sbinfo->si_kobj);
13970 + si_noflush_read_lock(sb);
13971 + if (au_ftest_si(sbinfo, FHSM))
13972 + au_fhsm_wrote_all(sb, /*force*/0);
13973 + si_read_unlock(sb);
13974 + goto out; /* success */
13977 + spin_lock(&fhsm->fhsm_spin);
13978 + fhsm->fhsm_pid = 0;
13979 + spin_unlock(&fhsm->fhsm_spin);
13985 +/* ---------------------------------------------------------------------- */
13987 +int au_fhsm_br_alloc(struct au_branch *br)
13992 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13994 + au_br_fhsm_init(br->br_fhsm);
14001 +/* ---------------------------------------------------------------------- */
14003 +void au_fhsm_fin(struct super_block *sb)
14005 + au_fhsm_notify(sb, /*val*/-1);
14008 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14010 + struct au_fhsm *fhsm;
14012 + fhsm = &sbinfo->si_fhsm;
14013 + spin_lock_init(&fhsm->fhsm_spin);
14014 + init_waitqueue_head(&fhsm->fhsm_wqh);
14015 + atomic_set(&fhsm->fhsm_readable, 0);
14016 + fhsm->fhsm_expire
14017 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14018 + fhsm->fhsm_bottom = -1;
14021 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14023 + sbinfo->si_fhsm.fhsm_expire
14024 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14027 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14031 + if (!au_ftest_si(sbinfo, FHSM))
14034 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14035 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14036 + seq_printf(seq, ",fhsm_sec=%u", u);
14038 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14039 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14040 +++ linux/fs/aufs/file.c 2023-09-04 13:39:55.763295607 +0200
14042 +// SPDX-License-Identifier: GPL-2.0
14044 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14046 + * This program is free software; you can redistribute it and/or modify
14047 + * it under the terms of the GNU General Public License as published by
14048 + * the Free Software Foundation; either version 2 of the License, or
14049 + * (at your option) any later version.
14051 + * This program is distributed in the hope that it will be useful,
14052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14054 + * GNU General Public License for more details.
14056 + * You should have received a copy of the GNU General Public License
14057 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14061 + * handling file/dir, and address_space operation
14064 +#ifdef CONFIG_AUFS_DEBUG
14065 +#include <linux/migrate.h>
14067 +#include <linux/pagemap.h>
14070 +/* drop flags for writing */
14071 +unsigned int au_file_roflags(unsigned int flags)
14073 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14074 + flags |= O_RDONLY | O_NOATIME;
14078 +/* common functions to regular file and dir */
14079 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14080 + struct file *file, int force_wr)
14082 + struct file *h_file;
14083 + struct dentry *h_dentry;
14084 + struct inode *h_inode;
14085 + struct super_block *sb;
14086 + struct au_branch *br;
14087 + struct path h_path;
14090 + /* a race condition can happen between open and unlink/rmdir */
14091 + h_file = ERR_PTR(-ENOENT);
14092 + h_dentry = au_h_dptr(dentry, bindex);
14093 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14095 + h_inode = d_inode(h_dentry);
14096 + spin_lock(&h_dentry->d_lock);
14097 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14098 + /* || !d_inode(dentry)->i_nlink */
14100 + spin_unlock(&h_dentry->d_lock);
14101 + if (unlikely(err))
14104 + sb = dentry->d_sb;
14105 + br = au_sbr(sb, bindex);
14106 + err = au_br_test_oflag(flags, br);
14107 + h_file = ERR_PTR(err);
14108 + if (unlikely(err))
14111 + /* drop flags for writing */
14112 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14113 + if (force_wr && !(flags & O_WRONLY))
14115 + flags = au_file_roflags(flags);
14117 + h_file = ERR_PTR(-EROFS);
14118 + flags = au_file_roflags(flags);
14119 + if (unlikely(vfsub_native_ro(h_inode)
14120 + || IS_APPEND(h_inode)))
14122 + flags &= ~O_ACCMODE;
14123 + flags |= O_WRONLY;
14126 + flags &= ~O_CREAT;
14127 + au_lcnt_inc(&br->br_nfiles);
14128 + h_path.dentry = h_dentry;
14129 + h_path.mnt = au_br_mnt(br);
14131 + * vfs::backing_file_open() looks promising since it can get rid of
14132 + * mm::vm_prfile approach from my mind.
14133 + * but I keep current approach for a while.
14135 + h_file = vfsub_dentry_open(&h_path, flags);
14136 + if (IS_ERR(h_file))
14139 + if (flags & __FMODE_EXEC) {
14140 + err = deny_write_access(h_file);
14141 + if (unlikely(err)) {
14143 + h_file = ERR_PTR(err);
14147 + fsnotify_open(h_file);
14148 + goto out; /* success */
14151 + au_lcnt_dec(&br->br_nfiles);
14156 +static int au_cmoo(struct dentry *dentry)
14158 + int err, cmoo, matched;
14159 + unsigned int udba;
14160 + struct path h_path;
14161 + struct au_pin pin;
14162 + struct au_cp_generic cpg = {
14163 + .dentry = dentry,
14168 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14170 + struct inode *delegated;
14171 + struct super_block *sb;
14172 + struct au_sbinfo *sbinfo;
14173 + struct au_fhsm *fhsm;
14175 + struct au_branch *br;
14176 + struct dentry *parent;
14177 + struct au_hinode *hdir;
14179 + DiMustWriteLock(dentry);
14180 + IiMustWriteLock(d_inode(dentry));
14183 + if (IS_ROOT(dentry))
14185 + cpg.bsrc = au_dbtop(dentry);
14189 + sb = dentry->d_sb;
14190 + sbinfo = au_sbi(sb);
14191 + fhsm = &sbinfo->si_fhsm;
14192 + pid = au_fhsm_pid(fhsm);
14195 + && (current->pid == pid
14196 + || rcu_dereference(current->real_parent)->pid == pid));
14197 + rcu_read_unlock();
14201 + br = au_sbr(sb, cpg.bsrc);
14202 + cmoo = au_br_cmoo(br->br_perm);
14205 + if (!d_is_reg(dentry))
14206 + cmoo &= AuBrAttr_COO_ALL;
14210 + parent = dget_parent(dentry);
14211 + di_write_lock_parent(parent);
14212 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14214 + if (unlikely(err < 0)) {
14215 + err = 0; /* there is no upper writable branch */
14218 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14220 + /* do not respect the coo attrib for the target branch */
14221 + err = au_cpup_dirs(dentry, cpg.bdst);
14222 + if (unlikely(err))
14225 + di_downgrade_lock(parent, AuLock_IR);
14226 + udba = au_opt_udba(sb);
14227 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14228 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14229 + if (unlikely(err))
14232 + err = au_sio_cpup_simple(&cpg);
14234 + if (unlikely(err))
14236 + if (!(cmoo & AuBrWAttr_MOO))
14237 + goto out_parent; /* success */
14239 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14240 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14241 + if (unlikely(err))
14244 + h_path.mnt = au_br_mnt(br);
14245 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14246 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14247 + delegated = NULL;
14248 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14250 + /* todo: keep h_dentry or not? */
14251 + if (unlikely(err == -EWOULDBLOCK)) {
14252 + pr_warn("cannot retry for NFSv4 delegation"
14253 + " for an internal unlink\n");
14256 + if (unlikely(err)) {
14257 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14261 + goto out_parent; /* success */
14264 + di_downgrade_lock(parent, AuLock_IR);
14266 + di_read_unlock(parent, AuLock_IR);
14273 +int au_do_open(struct file *file, struct au_do_open_args *args)
14275 + int err, aopen = args->aopen;
14276 + struct dentry *dentry;
14277 + struct au_finfo *finfo;
14280 + err = au_finfo_init(file, args->fidir);
14283 + err = au_finfo_init(file, args->fidir);
14286 + if (unlikely(err))
14289 + dentry = file->f_path.dentry;
14290 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14291 + di_write_lock_child(dentry);
14292 + err = au_cmoo(dentry);
14295 + err = args->open(file, vfsub_file_flags(file),
14296 + au_di(dentry)->di_htmpfile);
14297 + di_write_unlock(dentry);
14299 + di_downgrade_lock(dentry, AuLock_IR);
14301 + err = args->open(file, vfsub_file_flags(file),
14304 + di_read_unlock(dentry, AuLock_IR);
14308 + finfo = au_fi(file);
14310 + finfo->fi_file = file;
14311 + au_hbl_add(&finfo->fi_hlist,
14312 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14315 + fi_write_unlock(file);
14318 + fi_write_unlock(file);
14321 + if (unlikely(err)) {
14322 + finfo->fi_hdir = NULL;
14323 + au_finfo_fin(file);
14331 +int au_reopen_nondir(struct file *file)
14334 + aufs_bindex_t btop;
14335 + struct dentry *dentry;
14336 + struct au_branch *br;
14337 + struct file *h_file, *h_file_tmp;
14339 + dentry = file->f_path.dentry;
14340 + btop = au_dbtop(dentry);
14341 + br = au_sbr(dentry->d_sb, btop);
14342 + h_file_tmp = NULL;
14343 + if (au_fbtop(file) == btop) {
14344 + h_file = au_hf_top(file);
14345 + if (file->f_mode == h_file->f_mode)
14346 + return 0; /* success */
14347 + h_file_tmp = h_file;
14348 + get_file(h_file_tmp);
14349 + au_lcnt_inc(&br->br_nfiles);
14350 + au_set_h_fptr(file, btop, NULL);
14352 + AuDebugOn(au_fi(file)->fi_hdir);
14355 + * file exists on both of rw and ro
14356 + * open --> dbtop and fbtop are both 0
14357 + * prepend a branch as rw, "rw" become ro
14359 + * delete the top branch, "rw" becomes rw again
14360 + * --> dbtop is 1, fbtop is still 0
14361 + * write --> fbtop is 0 but dbtop is 1
14363 + /* AuDebugOn(au_fbtop(file) < btop); */
14365 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14366 + file, /*force_wr*/0);
14367 + err = PTR_ERR(h_file);
14368 + if (IS_ERR(h_file)) {
14369 + if (h_file_tmp) {
14371 + au_set_h_fptr(file, btop, h_file_tmp);
14372 + h_file_tmp = NULL;
14374 + goto out; /* todo: close all? */
14378 + au_set_fbtop(file, btop);
14379 + au_set_h_fptr(file, btop, h_file);
14380 + au_update_figen(file);
14381 + /* todo: necessary? */
14382 + /* file->f_ra = h_file->f_ra; */
14385 + if (h_file_tmp) {
14386 + fput(h_file_tmp);
14387 + au_lcnt_dec(&br->br_nfiles);
14392 +/* ---------------------------------------------------------------------- */
14394 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14395 + struct dentry *hi_wh)
14398 + aufs_bindex_t btop;
14399 + struct au_dinfo *dinfo;
14400 + struct dentry *h_dentry;
14401 + struct au_hdentry *hdp;
14403 + dinfo = au_di(file->f_path.dentry);
14404 + AuRwMustWriteLock(&dinfo->di_rwsem);
14406 + btop = dinfo->di_btop;
14407 + dinfo->di_btop = btgt;
14408 + hdp = au_hdentry(dinfo, btgt);
14409 + h_dentry = hdp->hd_dentry;
14410 + hdp->hd_dentry = hi_wh;
14411 + err = au_reopen_nondir(file);
14412 + hdp->hd_dentry = h_dentry;
14413 + dinfo->di_btop = btop;
14418 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14419 + aufs_bindex_t bcpup, struct au_pin *pin)
14422 + struct inode *inode, *h_inode;
14423 + struct dentry *h_dentry, *hi_wh;
14424 + struct au_cp_generic cpg = {
14425 + .dentry = file->f_path.dentry,
14432 + au_update_dbtop(cpg.dentry);
14433 + inode = d_inode(cpg.dentry);
14435 + if (au_dbtop(cpg.dentry) <= bcpup
14436 + && au_dbbot(cpg.dentry) >= bcpup) {
14437 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14438 + if (h_dentry && d_is_positive(h_dentry))
14439 + h_inode = d_inode(h_dentry);
14441 + hi_wh = au_hi_wh(inode, bcpup);
14442 + if (!hi_wh && !h_inode)
14443 + err = au_sio_cpup_wh(&cpg, file);
14445 + /* already copied-up after unlink */
14446 + err = au_reopen_wh(file, bcpup, hi_wh);
14449 + && (inode->i_nlink > 1
14450 + || (inode->i_state & I_LINKABLE))
14451 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14452 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14458 + * prepare the @file for writing.
14460 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14463 + aufs_bindex_t dbtop;
14464 + struct dentry *parent;
14465 + struct inode *inode;
14466 + struct super_block *sb;
14467 + struct file *h_file;
14468 + struct au_cp_generic cpg = {
14469 + .dentry = file->f_path.dentry,
14474 + .flags = AuCpup_DTIME
14477 + sb = cpg.dentry->d_sb;
14478 + inode = d_inode(cpg.dentry);
14479 + cpg.bsrc = au_fbtop(file);
14480 + err = au_test_ro(sb, cpg.bsrc, inode);
14481 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14482 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14487 + /* need to cpup or reopen */
14488 + parent = dget_parent(cpg.dentry);
14489 + di_write_lock_parent(parent);
14490 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14492 + if (unlikely(err < 0))
14496 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14497 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14498 + if (unlikely(err))
14502 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14503 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14504 + if (unlikely(err))
14507 + dbtop = au_dbtop(cpg.dentry);
14508 + if (dbtop <= cpg.bdst)
14509 + cpg.bsrc = cpg.bdst;
14511 + if (dbtop <= cpg.bdst /* just reopen */
14512 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14514 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14515 + if (IS_ERR(h_file))
14516 + err = PTR_ERR(h_file);
14518 + di_downgrade_lock(parent, AuLock_IR);
14519 + if (dbtop > cpg.bdst)
14520 + err = au_sio_cpup_simple(&cpg);
14522 + err = au_reopen_nondir(file);
14523 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14525 + } else { /* copyup as wh and reopen */
14527 + * since writable hfsplus branch is not supported,
14528 + * h_open_pre/post() are unnecessary.
14530 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14531 + di_downgrade_lock(parent, AuLock_IR);
14535 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14536 + goto out_dput; /* success */
14542 + di_downgrade_lock(parent, AuLock_IR);
14544 + di_read_unlock(parent, AuLock_IR);
14551 +/* ---------------------------------------------------------------------- */
14553 +int au_do_flush(struct file *file, fl_owner_t id,
14554 + int (*flush)(struct file *file, fl_owner_t id))
14557 + struct super_block *sb;
14558 + struct inode *inode;
14560 + inode = file_inode(file);
14561 + sb = inode->i_sb;
14562 + si_noflush_read_lock(sb);
14563 + fi_read_lock(file);
14564 + ii_read_lock_child(inode);
14566 + err = flush(file, id);
14567 + au_cpup_attr_timesizes(inode);
14569 + ii_read_unlock(inode);
14570 + fi_read_unlock(file);
14571 + si_read_unlock(sb);
14575 +/* ---------------------------------------------------------------------- */
14577 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14580 + struct au_pin pin;
14581 + struct au_finfo *finfo;
14582 + struct dentry *parent, *hi_wh;
14583 + struct inode *inode;
14584 + struct super_block *sb;
14585 + struct au_cp_generic cpg = {
14586 + .dentry = file->f_path.dentry,
14591 + .flags = AuCpup_DTIME
14594 + FiMustWriteLock(file);
14597 + finfo = au_fi(file);
14598 + sb = cpg.dentry->d_sb;
14599 + inode = d_inode(cpg.dentry);
14600 + cpg.bdst = au_ibtop(inode);
14601 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14604 + parent = dget_parent(cpg.dentry);
14605 + if (au_test_ro(sb, cpg.bdst, inode)) {
14606 + di_read_lock_parent(parent, !AuLock_IR);
14607 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14609 + di_read_unlock(parent, !AuLock_IR);
14610 + if (unlikely(err < 0))
14615 + di_read_lock_parent(parent, AuLock_IR);
14616 + hi_wh = au_hi_wh(inode, cpg.bdst);
14617 + if (!S_ISDIR(inode->i_mode)
14618 + && au_opt_test(au_mntflags(sb), PLINK)
14619 + && au_plink_test(inode)
14620 + && !d_unhashed(cpg.dentry)
14621 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14622 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14623 + if (unlikely(err))
14626 + /* always superio. */
14627 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14628 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14630 + err = au_sio_cpup_simple(&cpg);
14633 + } else if (hi_wh) {
14634 + /* already copied-up after unlink */
14635 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14636 + *need_reopen = 0;
14640 + di_read_unlock(parent, AuLock_IR);
14647 +static void au_do_refresh_dir(struct file *file)
14649 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14650 + struct au_hfile *p, tmp, *q;
14651 + struct au_finfo *finfo;
14652 + struct super_block *sb;
14653 + struct au_fidir *fidir;
14655 + FiMustWriteLock(file);
14657 + sb = file->f_path.dentry->d_sb;
14658 + finfo = au_fi(file);
14659 + fidir = finfo->fi_hdir;
14660 + AuDebugOn(!fidir);
14661 + p = fidir->fd_hfile + finfo->fi_btop;
14662 + brid = p->hf_br->br_id;
14663 + bbot = fidir->fd_bbot;
14664 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14668 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14669 + if (new_bindex == bindex)
14671 + if (new_bindex < 0) {
14672 + au_set_h_fptr(file, bindex, NULL);
14676 + /* swap two lower inode, and loop again */
14677 + q = fidir->fd_hfile + new_bindex;
14681 + if (tmp.hf_file) {
14687 + p = fidir->fd_hfile;
14688 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14689 + bbot = au_sbbot(sb);
14690 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14691 + finfo->fi_btop++, p++)
14692 + if (p->hf_file) {
14693 + if (file_inode(p->hf_file))
14695 + au_hfput(p, /*execed*/0);
14698 + bbot = au_br_index(sb, brid);
14699 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14700 + finfo->fi_btop++, p++)
14702 + au_hfput(p, /*execed*/0);
14703 + bbot = au_sbbot(sb);
14706 + p = fidir->fd_hfile + bbot;
14707 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14708 + fidir->fd_bbot--, p--)
14709 + if (p->hf_file) {
14710 + if (file_inode(p->hf_file))
14712 + au_hfput(p, /*execed*/0);
14714 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14718 + * after branch manipulating, refresh the file.
14720 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14722 + int err, need_reopen, nbr;
14723 + aufs_bindex_t bbot, bindex;
14724 + struct dentry *dentry;
14725 + struct super_block *sb;
14726 + struct au_finfo *finfo;
14727 + struct au_hfile *hfile;
14729 + dentry = file->f_path.dentry;
14730 + sb = dentry->d_sb;
14731 + nbr = au_sbbot(sb) + 1;
14732 + finfo = au_fi(file);
14733 + if (!finfo->fi_hdir) {
14734 + hfile = &finfo->fi_htop;
14735 + AuDebugOn(!hfile->hf_file);
14736 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14737 + AuDebugOn(bindex < 0);
14738 + if (bindex != finfo->fi_btop)
14739 + au_set_fbtop(file, bindex);
14741 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14742 + if (unlikely(err))
14744 + au_do_refresh_dir(file);
14749 + if (!au_test_mmapped(file))
14750 + err = au_file_refresh_by_inode(file, &need_reopen);
14751 + if (finfo->fi_hdir)
14752 + /* harmless if err */
14753 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14754 + if (!err && need_reopen && !d_unlinked(dentry))
14755 + err = reopen(file);
14757 + au_update_figen(file);
14758 + goto out; /* success */
14761 + /* error, close all lower files */
14762 + if (finfo->fi_hdir) {
14763 + bbot = au_fbbot_dir(file);
14764 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14765 + au_set_h_fptr(file, bindex, NULL);
14772 +/* common function to regular file and dir */
14773 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14774 + int wlock, unsigned int fi_lsc)
14777 + unsigned int sigen, figen;
14778 + aufs_bindex_t btop;
14779 + unsigned char pseudo_link;
14780 + struct dentry *dentry;
14781 + struct inode *inode;
14784 + dentry = file->f_path.dentry;
14785 + inode = d_inode(dentry);
14786 + sigen = au_sigen(dentry->d_sb);
14787 + fi_write_lock_nested(file, fi_lsc);
14788 + figen = au_figen(file);
14790 + di_write_lock_child(dentry);
14792 + di_write_lock_child2(dentry);
14793 + btop = au_dbtop(dentry);
14794 + pseudo_link = (btop != au_ibtop(inode));
14795 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14797 + di_downgrade_lock(dentry, AuLock_IR);
14798 + fi_downgrade_lock(file);
14800 + goto out; /* success */
14803 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14804 + if (au_digen_test(dentry, sigen)) {
14805 + err = au_reval_dpath(dentry, sigen);
14806 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14810 + err = refresh_file(file, reopen);
14813 + di_downgrade_lock(dentry, AuLock_IR);
14814 + fi_downgrade_lock(file);
14817 + di_write_unlock(dentry);
14818 + fi_write_unlock(file);
14825 +/* ---------------------------------------------------------------------- */
14827 +/* cf. aufs_nopage() */
14828 +/* for madvise(2) */
14829 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14831 + folio_unlock(folio);
14835 +/* it will never be called, but necessary to support O_DIRECT */
14836 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14837 +{ BUG(); return 0; }
14839 +/* they will never be called. */
14840 +#ifdef CONFIG_AUFS_DEBUG
14841 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14842 + loff_t pos, unsigned len,
14843 + struct page **pagep, void **fsdata)
14844 +{ AuUnsupport(); return 0; }
14845 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14846 + loff_t pos, unsigned len, unsigned copied,
14847 + struct page *page, void *fsdata)
14848 +{ AuUnsupport(); return 0; }
14849 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14850 +{ AuUnsupport(); return 0; }
14852 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14853 +{ AuUnsupport(); return true; }
14854 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14855 +{ AuUnsupport(); }
14856 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14857 +{ AuUnsupport(); return true; }
14858 +#if 0 /* called by memory compaction regardless file */
14859 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14860 + struct folio *src, enum migrate_mode mode)
14861 +{ AuUnsupport(); return 0; }
14863 +static int aufs_launder_folio(struct folio *folio)
14864 +{ AuUnsupport(); return 0; }
14865 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14867 +{ AuUnsupport(); return true; }
14868 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14870 +{ AuUnsupport(); }
14871 +static int aufs_error_remove_page(struct address_space *mapping,
14872 + struct page *page)
14873 +{ AuUnsupport(); return 0; }
14874 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14876 +{ AuUnsupport(); return 0; }
14877 +static void aufs_swap_deactivate(struct file *file)
14878 +{ AuUnsupport(); }
14879 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14880 +{ AuUnsupport(); return 0; }
14881 +#endif /* CONFIG_AUFS_DEBUG */
14883 +const struct address_space_operations aufs_aop = {
14884 + .read_folio = aufs_read_folio,
14885 + .direct_IO = aufs_direct_IO,
14886 +#ifdef CONFIG_AUFS_DEBUG
14887 + .writepage = aufs_writepage,
14888 + /* no writepages, because of writepage */
14889 + .dirty_folio = aufs_dirty_folio,
14890 + /* no readpages, because of readpage */
14891 + .write_begin = aufs_write_begin,
14892 + .write_end = aufs_write_end,
14893 + /* no bmap, no block device */
14894 + .invalidate_folio = aufs_invalidate_folio,
14895 + .release_folio = aufs_release_folio,
14896 + /* is fallback_migrate_page ok? */
14897 + /* .migrate_folio = aufs_migrate_folio, */
14898 + .launder_folio = aufs_launder_folio,
14899 + .is_partially_uptodate = aufs_is_partially_uptodate,
14900 + .is_dirty_writeback = aufs_is_dirty_writeback,
14901 + .error_remove_page = aufs_error_remove_page,
14902 + .swap_activate = aufs_swap_activate,
14903 + .swap_deactivate = aufs_swap_deactivate,
14904 + .swap_rw = aufs_swap_rw
14905 +#endif /* CONFIG_AUFS_DEBUG */
14907 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14908 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14909 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14911 +/* SPDX-License-Identifier: GPL-2.0 */
14913 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14915 + * This program is free software; you can redistribute it and/or modify
14916 + * it under the terms of the GNU General Public License as published by
14917 + * the Free Software Foundation; either version 2 of the License, or
14918 + * (at your option) any later version.
14920 + * This program is distributed in the hope that it will be useful,
14921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14923 + * GNU General Public License for more details.
14925 + * You should have received a copy of the GNU General Public License
14926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14930 + * file operations
14933 +#ifndef __AUFS_FILE_H__
14934 +#define __AUFS_FILE_H__
14938 +#include <linux/file.h>
14939 +#include <linux/fs.h>
14940 +#include <linux/mm_types.h>
14941 +#include <linux/poll.h>
14942 +#include "rwsem.h"
14946 + struct file *hf_file;
14947 + struct au_branch *hf_br;
14952 + aufs_bindex_t fd_bbot;
14953 + aufs_bindex_t fd_nent;
14954 + struct au_vdir *fd_vdir_cache;
14955 + struct au_hfile fd_hfile[];
14958 +static inline int au_fidir_sz(int nent)
14960 + AuDebugOn(nent < 0);
14961 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14965 + atomic_t fi_generation;
14967 + struct au_rwsem fi_rwsem;
14968 + aufs_bindex_t fi_btop;
14970 + /* do not union them */
14971 + struct { /* for non-dir */
14972 + struct au_hfile fi_htop;
14973 + atomic_t fi_mmapped;
14975 + struct au_fidir *fi_hdir; /* for dir only */
14977 + struct hlist_bl_node fi_hlist;
14978 + struct file *fi_file; /* very ugly */
14979 + struct rcu_head rcu;
14980 +} ____cacheline_aligned_in_smp;
14982 +/* ---------------------------------------------------------------------- */
14985 +extern const struct address_space_operations aufs_aop;
14986 +unsigned int au_file_roflags(unsigned int flags);
14987 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14988 + struct file *file, int force_wr);
14989 +struct au_do_open_args {
14991 + int (*open)(struct file *file, int flags,
14992 + struct file *h_file);
14993 + struct au_fidir *fidir;
14994 + struct file *h_file;
14996 +int au_do_open(struct file *file, struct au_do_open_args *args);
14997 +int au_reopen_nondir(struct file *file);
14999 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15000 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15001 + int wlock, unsigned int fi_lsc);
15002 +int au_do_flush(struct file *file, fl_owner_t id,
15003 + int (*flush)(struct file *file, fl_owner_t id));
15006 +#ifdef CONFIG_AUFS_POLL
15007 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15010 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15012 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15014 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15015 + struct file *h_file);
15017 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15018 + aufs_bindex_t bindex, int force_wr)
15019 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15020 + struct file *h_file);
15024 +extern const struct file_operations aufs_file_fop;
15025 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15026 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15027 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15030 +void au_hfput(struct au_hfile *hf, int execed);
15031 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15032 + struct file *h_file);
15034 +void au_update_figen(struct file *file);
15035 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15036 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15038 +void au_fi_init_once(void *_fi);
15039 +void au_finfo_fin(struct file *file);
15040 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15043 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15044 +#ifdef CONFIG_COMPAT
15045 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15046 + unsigned long arg);
15047 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15048 + unsigned long arg);
15051 +/* ---------------------------------------------------------------------- */
15053 +static inline struct au_finfo *au_fi(struct file *file)
15055 + return file->private_data;
15058 +/* ---------------------------------------------------------------------- */
15060 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15061 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15062 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15063 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15065 +#define fi_read_trylock_nested(f) \
15066 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15067 +#define fi_write_trylock_nested(f) \
15068 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15071 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15072 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15073 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15075 +/* lock subclass for finfo */
15081 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15083 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15086 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15088 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15092 + * fi_read_lock_1, fi_write_lock_1,
15093 + * fi_read_lock_2, fi_write_lock_2
15095 +#define AuReadLockFunc(name) \
15096 +static inline void fi_read_lock_##name(struct file *f) \
15097 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15099 +#define AuWriteLockFunc(name) \
15100 +static inline void fi_write_lock_##name(struct file *f) \
15101 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15103 +#define AuRWLockFuncs(name) \
15104 + AuReadLockFunc(name) \
15105 + AuWriteLockFunc(name)
15110 +#undef AuReadLockFunc
15111 +#undef AuWriteLockFunc
15112 +#undef AuRWLockFuncs
15114 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15115 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15116 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15118 +/* ---------------------------------------------------------------------- */
15120 +/* todo: hard/soft set? */
15121 +static inline aufs_bindex_t au_fbtop(struct file *file)
15123 + FiMustAnyLock(file);
15124 + return au_fi(file)->fi_btop;
15127 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15129 + FiMustAnyLock(file);
15130 + AuDebugOn(!au_fi(file)->fi_hdir);
15131 + return au_fi(file)->fi_hdir->fd_bbot;
15134 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15136 + FiMustAnyLock(file);
15137 + AuDebugOn(!au_fi(file)->fi_hdir);
15138 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15141 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15143 + FiMustWriteLock(file);
15144 + au_fi(file)->fi_btop = bindex;
15147 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15149 + FiMustWriteLock(file);
15150 + AuDebugOn(!au_fi(file)->fi_hdir);
15151 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15154 +static inline void au_set_fvdir_cache(struct file *file,
15155 + struct au_vdir *vdir_cache)
15157 + FiMustWriteLock(file);
15158 + AuDebugOn(!au_fi(file)->fi_hdir);
15159 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15162 +static inline struct file *au_hf_top(struct file *file)
15164 + FiMustAnyLock(file);
15165 + AuDebugOn(au_fi(file)->fi_hdir);
15166 + return au_fi(file)->fi_htop.hf_file;
15169 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15171 + FiMustAnyLock(file);
15172 + AuDebugOn(!au_fi(file)->fi_hdir);
15173 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15176 +/* todo: memory barrier? */
15177 +static inline unsigned int au_figen(struct file *f)
15179 + return atomic_read(&au_fi(f)->fi_generation);
15182 +static inline void au_set_mmapped(struct file *f)
15184 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15186 + pr_warn("fi_mmapped wrapped around\n");
15187 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15191 +static inline void au_unset_mmapped(struct file *f)
15193 + atomic_dec(&au_fi(f)->fi_mmapped);
15196 +static inline int au_test_mmapped(struct file *f)
15198 + return atomic_read(&au_fi(f)->fi_mmapped);
15201 +/* customize vma->vm_file */
15203 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15204 + struct file *file)
15208 + f = vma->vm_file;
15210 + vma->vm_file = file;
15215 +#define AuDbgVmRegion(file, vma) do {} while (0)
15217 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15218 + struct file *file)
15220 + au_do_vm_file_reset(vma, file);
15223 +#define AuDbgVmRegion(file, vma) \
15224 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15226 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15227 + struct file *file)
15231 + au_do_vm_file_reset(vma, file);
15232 + f = vma->vm_region->vm_file;
15234 + vma->vm_region->vm_file = file;
15237 +#endif /* CONFIG_MMU */
15239 +/* handle vma->vm_prfile */
15240 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15241 + struct file *file)
15244 + vma->vm_prfile = file;
15245 +#ifndef CONFIG_MMU
15247 + vma->vm_region->vm_prfile = file;
15251 +#endif /* __KERNEL__ */
15252 +#endif /* __AUFS_FILE_H__ */
15253 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15254 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15255 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15257 +// SPDX-License-Identifier: GPL-2.0
15259 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15261 + * This program is free software; you can redistribute it and/or modify
15262 + * it under the terms of the GNU General Public License as published by
15263 + * the Free Software Foundation; either version 2 of the License, or
15264 + * (at your option) any later version.
15266 + * This program is distributed in the hope that it will be useful,
15267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15269 + * GNU General Public License for more details.
15271 + * You should have received a copy of the GNU General Public License
15272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15276 + * file private data
15281 +void au_hfput(struct au_hfile *hf, int execed)
15284 + allow_write_access(hf->hf_file);
15285 + fput(hf->hf_file);
15286 + hf->hf_file = NULL;
15287 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15288 + hf->hf_br = NULL;
15291 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15293 + struct au_finfo *finfo = au_fi(file);
15294 + struct au_hfile *hf;
15295 + struct au_fidir *fidir;
15297 + fidir = finfo->fi_hdir;
15299 + AuDebugOn(finfo->fi_btop != bindex);
15300 + hf = &finfo->fi_htop;
15302 + hf = fidir->fd_hfile + bindex;
15304 + if (hf && hf->hf_file)
15305 + au_hfput(hf, vfsub_file_execed(file));
15307 + FiMustWriteLock(file);
15308 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15309 + hf->hf_file = val;
15310 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15314 +void au_update_figen(struct file *file)
15316 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15317 + /* smp_mb(); */ /* atomic_set */
15320 +/* ---------------------------------------------------------------------- */
15322 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15324 + struct au_fidir *fidir;
15327 + nbr = au_sbbot(sb) + 1;
15329 + nbr = 2; /* initial allocate for 2 branches */
15330 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15332 + fidir->fd_bbot = -1;
15333 + fidir->fd_nent = nbr;
15339 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15342 + struct au_fidir *fidir, *p;
15344 + AuRwMustWriteLock(&finfo->fi_rwsem);
15345 + fidir = finfo->fi_hdir;
15346 + AuDebugOn(!fidir);
15349 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15350 + GFP_NOFS, may_shrink);
15352 + p->fd_nent = nbr;
15353 + finfo->fi_hdir = p;
15360 +/* ---------------------------------------------------------------------- */
15362 +void au_finfo_fin(struct file *file)
15364 + struct au_finfo *finfo;
15366 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15368 + finfo = au_fi(file);
15369 + AuDebugOn(finfo->fi_hdir);
15370 + AuRwDestroy(&finfo->fi_rwsem);
15371 + au_cache_free_finfo(finfo);
15374 +void au_fi_init_once(void *_finfo)
15376 + struct au_finfo *finfo = _finfo;
15378 + au_rw_init(&finfo->fi_rwsem);
15381 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15384 + struct au_finfo *finfo;
15385 + struct dentry *dentry;
15388 + dentry = file->f_path.dentry;
15389 + finfo = au_cache_alloc_finfo();
15390 + if (unlikely(!finfo))
15394 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15395 + au_rw_write_lock(&finfo->fi_rwsem);
15396 + finfo->fi_btop = -1;
15397 + finfo->fi_hdir = fidir;
15398 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15399 + /* smp_mb(); */ /* atomic_set */
15401 + file->private_data = finfo;
15406 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15407 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15408 +++ linux/fs/aufs/f_op.c 2023-09-04 13:39:55.763295607 +0200
15410 +// SPDX-License-Identifier: GPL-2.0
15412 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15414 + * This program is free software; you can redistribute it and/or modify
15415 + * it under the terms of the GNU General Public License as published by
15416 + * the Free Software Foundation; either version 2 of the License, or
15417 + * (at your option) any later version.
15419 + * This program is distributed in the hope that it will be useful,
15420 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15421 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15422 + * GNU General Public License for more details.
15424 + * You should have received a copy of the GNU General Public License
15425 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15429 + * file and vm operations
15432 +#include <linux/aio.h>
15433 +#include <linux/fs_stack.h>
15434 +#include <linux/mman.h>
15435 +#include <linux/security.h>
15438 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15441 + aufs_bindex_t bindex;
15442 + struct dentry *dentry, *h_dentry;
15443 + struct au_finfo *finfo;
15444 + struct inode *h_inode;
15446 + FiMustWriteLock(file);
15449 + dentry = file->f_path.dentry;
15450 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15451 + finfo = au_fi(file);
15452 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15453 + atomic_set(&finfo->fi_mmapped, 0);
15454 + bindex = au_dbtop(dentry);
15456 + h_dentry = au_h_dptr(dentry, bindex);
15457 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15458 + if (unlikely(err))
15460 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15461 + if (IS_ERR(h_file)) {
15462 + err = PTR_ERR(h_file);
15466 + h_dentry = h_file->f_path.dentry;
15467 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15468 + if (unlikely(err))
15470 + /* br ref is already inc-ed */
15473 + if (flags & __O_TMPFILE) {
15474 + AuDebugOn(!h_file);
15475 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15476 + au_di(dentry)->di_htmpfile = NULL;
15478 + if (!(flags & O_EXCL)) {
15479 + h_inode = file_inode(h_file);
15480 + spin_lock(&h_inode->i_lock);
15481 + h_inode->i_state |= I_LINKABLE;
15482 + spin_unlock(&h_inode->i_lock);
15485 + au_set_fbtop(file, bindex);
15486 + au_set_h_fptr(file, bindex, h_file);
15487 + au_update_figen(file);
15488 + /* todo: necessary? */
15489 + /* file->f_ra = h_file->f_ra; */
15495 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15496 + struct file *file)
15499 + struct super_block *sb;
15500 + struct au_do_open_args args = {
15501 + .open = au_do_open_nondir
15504 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15505 + file, vfsub_file_flags(file), file->f_mode);
15507 + sb = file->f_path.dentry->d_sb;
15508 + si_read_lock(sb, AuLock_FLUSH);
15509 + err = au_do_open(file, &args);
15510 + si_read_unlock(sb);
15514 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15516 + struct au_finfo *finfo;
15517 + aufs_bindex_t bindex;
15519 + finfo = au_fi(file);
15520 + au_hbl_del(&finfo->fi_hlist,
15521 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15522 + bindex = finfo->fi_btop;
15524 + au_set_h_fptr(file, bindex, NULL);
15526 + au_finfo_fin(file);
15530 +/* ---------------------------------------------------------------------- */
15532 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15535 + struct file *h_file;
15538 + h_file = au_hf_top(file);
15540 + err = vfsub_flush(h_file, id);
15544 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15546 + return au_do_flush(file, id, au_do_flush_nondir);
15549 +/* ---------------------------------------------------------------------- */
15551 + * read and write functions acquire [fdi]_rwsem once, but release before
15552 + * mmap_sem. This is because to stop a race condition between mmap(2).
15553 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15554 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15555 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15558 +/* Callers should call au_read_post() or fput() in the end */
15559 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15561 + struct file *h_file;
15564 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15566 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15567 + h_file = au_hf_top(file);
15568 + get_file(h_file);
15570 + fi_read_unlock(file);
15572 + h_file = ERR_PTR(err);
15577 +static void au_read_post(struct inode *inode, struct file *h_file)
15579 + /* update without lock, I don't think it a problem */
15580 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15584 +struct au_write_pre {
15586 + unsigned int lsc;
15590 + aufs_bindex_t btop;
15594 + * return with iinfo is write-locked
15595 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15598 +static struct file *au_write_pre(struct file *file, int do_ready,
15599 + struct au_write_pre *wpre)
15601 + struct file *h_file;
15602 + struct dentry *dentry;
15604 + unsigned int lsc;
15605 + struct au_pin pin;
15610 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15611 + h_file = ERR_PTR(err);
15612 + if (unlikely(err))
15615 + dentry = file->f_path.dentry;
15617 + err = au_ready_to_write(file, -1, &pin);
15618 + if (unlikely(err)) {
15619 + h_file = ERR_PTR(err);
15620 + di_write_unlock(dentry);
15625 + di_downgrade_lock(dentry, /*flags*/0);
15627 + wpre->btop = au_fbtop(file);
15628 + h_file = au_hf_top(file);
15629 + get_file(h_file);
15631 + wpre->blks = file_inode(h_file)->i_blocks;
15634 + di_read_unlock(dentry, /*flags*/0);
15637 + fi_write_unlock(file);
15642 +static void au_write_post(struct inode *inode, struct file *h_file,
15643 + struct au_write_pre *wpre, ssize_t written)
15645 + struct inode *h_inode;
15647 + au_cpup_attr_timesizes(inode);
15648 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15649 + h_inode = file_inode(h_file);
15650 + inode->i_mode = h_inode->i_mode;
15651 + ii_write_unlock(inode);
15652 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15654 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15655 + /*force*/h_inode->i_blocks > wpre->blks);
15660 + * todo: very ugly
15661 + * it locks both of i_mutex and si_rwsem for read in safe.
15662 + * if the plink maintenance mode continues forever (that is the problem),
15663 + * may loop forever.
15665 +static void au_mtx_and_read_lock(struct inode *inode)
15668 + struct super_block *sb = inode->i_sb;
15671 + inode_lock(inode);
15672 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15675 + inode_unlock(inode);
15676 + si_read_lock(sb, AuLock_NOPLMW);
15677 + si_read_unlock(sb);
15681 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15682 + struct iov_iter *iov_iter)
15685 + struct file *file;
15686 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15688 + err = security_file_permission(h_file, rw);
15689 + if (unlikely(err))
15692 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15694 + if (rw == MAY_READ)
15695 + iter = h_file->f_op->read_iter;
15696 + else if (rw == MAY_WRITE)
15697 + iter = h_file->f_op->write_iter;
15699 + file = kio->ki_filp;
15700 + kio->ki_filp = h_file;
15703 + err = iter(kio, iov_iter);
15706 + /* currently there is no such fs */
15708 + kio->ki_filp = file;
15714 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15717 + struct file *file, *h_file;
15718 + struct inode *inode;
15719 + struct super_block *sb;
15721 + file = kio->ki_filp;
15722 + inode = file_inode(file);
15723 + sb = inode->i_sb;
15724 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15726 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15727 + err = PTR_ERR(h_file);
15728 + if (IS_ERR(h_file))
15731 + if (au_test_loopback_kthread()) {
15732 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15733 + if (file->f_mapping != h_file->f_mapping) {
15734 + file->f_mapping = h_file->f_mapping;
15735 + smp_mb(); /* unnecessary? */
15738 + fi_read_unlock(file);
15740 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15741 + /* todo: necessary? */
15742 + /* file->f_ra = h_file->f_ra; */
15743 + au_read_post(inode, h_file);
15746 + si_read_unlock(sb);
15750 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15753 + struct au_write_pre wpre;
15754 + struct inode *inode;
15755 + struct file *file, *h_file;
15757 + file = kio->ki_filp;
15758 + inode = file_inode(file);
15759 + au_mtx_and_read_lock(inode);
15762 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15763 + err = PTR_ERR(h_file);
15764 + if (IS_ERR(h_file))
15767 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15768 + au_write_post(inode, h_file, &wpre, err);
15771 + si_read_unlock(inode->i_sb);
15772 + inode_unlock(inode);
15777 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15778 + * don't have their own .splice_{read,write} implimentations, and they use
15779 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15780 + * simple converters to f_op->iter_read() and ->iter_write().
15781 + * But we keep our own implementations because some non-mainlined FSes may have
15782 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15783 + * away an opportunity to co-work with aufs from them.
15785 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15786 + struct pipe_inode_info *pipe, size_t len,
15787 + unsigned int flags)
15790 + struct file *h_file;
15791 + struct inode *inode;
15792 + struct super_block *sb;
15794 + inode = file_inode(file);
15795 + sb = inode->i_sb;
15796 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15798 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15799 + err = PTR_ERR(h_file);
15800 + if (IS_ERR(h_file))
15803 + err = vfsub_splice_read(h_file, ppos, pipe, len, flags);
15804 + /* todo: necessary? */
15805 + /* file->f_ra = h_file->f_ra; */
15806 + au_read_post(inode, h_file);
15809 + si_read_unlock(sb);
15814 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15815 + size_t len, unsigned int flags)
15818 + struct au_write_pre wpre;
15819 + struct inode *inode;
15820 + struct file *h_file;
15822 + inode = file_inode(file);
15823 + au_mtx_and_read_lock(inode);
15826 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15827 + err = PTR_ERR(h_file);
15828 + if (IS_ERR(h_file))
15831 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15832 + au_write_post(inode, h_file, &wpre, err);
15835 + si_read_unlock(inode->i_sb);
15836 + inode_unlock(inode);
15840 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15844 + struct au_write_pre wpre;
15845 + struct inode *inode;
15846 + struct file *h_file;
15848 + inode = file_inode(file);
15849 + au_mtx_and_read_lock(inode);
15852 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15853 + err = PTR_ERR(h_file);
15854 + if (IS_ERR(h_file))
15858 + err = vfs_fallocate(h_file, mode, offset, len);
15861 + * we don't need to call file_modifed() here since au_write_post()
15862 + * is equivalent and copies-up all timestamps and permission bits.
15864 + au_write_post(inode, h_file, &wpre, /*written*/1);
15867 + si_read_unlock(inode->i_sb);
15868 + inode_unlock(inode);
15872 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15873 + struct file *dst, loff_t dst_pos,
15874 + size_t len, unsigned int flags)
15877 + struct au_write_pre wpre;
15878 + enum { SRC, DST };
15880 + struct inode *inode;
15881 + struct file *h_file;
15882 + struct super_block *h_sb;
15884 +#define a_src a[SRC]
15885 +#define a_dst a[DST]
15888 + a_src.inode = file_inode(src);
15889 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15891 + a_dst.inode = file_inode(dst);
15892 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15895 + au_mtx_and_read_lock(a_dst.inode);
15897 + * in order to match the order in di_write_lock2_{child,parent}(),
15898 + * use f_path.dentry for this comparison.
15900 + if (src->f_path.dentry < dst->f_path.dentry) {
15901 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15902 + err = PTR_ERR(a_src.h_file);
15903 + if (IS_ERR(a_src.h_file))
15906 + wpre.lsc = AuLsc_FI_2;
15907 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15908 + err = PTR_ERR(a_dst.h_file);
15909 + if (IS_ERR(a_dst.h_file)) {
15910 + au_read_post(a_src.inode, a_src.h_file);
15914 + wpre.lsc = AuLsc_FI_1;
15915 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15916 + err = PTR_ERR(a_dst.h_file);
15917 + if (IS_ERR(a_dst.h_file))
15920 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15921 + err = PTR_ERR(a_src.h_file);
15922 + if (IS_ERR(a_src.h_file)) {
15923 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15930 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15931 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15932 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15938 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15939 + dst_pos, len, flags);
15942 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15943 + fi_read_unlock(src);
15944 + au_read_post(a_src.inode, a_src.h_file);
15946 + si_read_unlock(a_dst.inode->i_sb);
15947 + inode_unlock(a_dst.inode);
15954 +/* ---------------------------------------------------------------------- */
15957 + * The locking order around current->mmap_sem.
15958 + * - in most and regular cases
15959 + * file I/O syscall -- aufs_read() or something
15960 + * -- si_rwsem for read -- mmap_sem
15961 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15963 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15964 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15965 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15966 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15967 + * It means that when aufs acquires si_rwsem for write, the process should never
15968 + * acquire mmap_sem.
15970 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15971 + * problem either since any directory is not able to be mmap-ed.
15972 + * The similar scenario is applied to aufs_readlink() too.
15975 +#if 0 /* stop calling security_file_mmap() */
15976 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15977 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15979 +static unsigned long au_arch_prot_conv(unsigned long flags)
15981 + /* currently ppc64 only */
15982 +#ifdef CONFIG_PPC64
15983 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15984 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15985 + return AuConv_VM_PROT(flags, SAO);
15987 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15992 +static unsigned long au_prot_conv(unsigned long flags)
15994 + return AuConv_VM_PROT(flags, READ)
15995 + | AuConv_VM_PROT(flags, WRITE)
15996 + | AuConv_VM_PROT(flags, EXEC)
15997 + | au_arch_prot_conv(flags);
16000 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16001 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16003 +static unsigned long au_flag_conv(unsigned long flags)
16005 + return AuConv_VM_MAP(flags, GROWSDOWN)
16006 + | AuConv_VM_MAP(flags, DENYWRITE)
16007 + | AuConv_VM_MAP(flags, LOCKED);
16011 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16014 + const unsigned char wlock
16015 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16016 + struct super_block *sb;
16017 + struct file *h_file;
16018 + struct inode *inode;
16020 + AuDbgVmRegion(file, vma);
16022 + inode = file_inode(file);
16023 + sb = inode->i_sb;
16025 + si_read_lock(sb, AuLock_NOPLMW);
16027 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16029 + err = PTR_ERR(h_file);
16030 + if (IS_ERR(h_file))
16034 + au_set_mmapped(file);
16035 + au_vm_file_reset(vma, h_file);
16037 + * we cannot call security_mmap_file() here since it may acquire
16038 + * mmap_sem or i_mutex.
16040 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16041 + * au_flag_conv(vma->vm_flags));
16044 + err = call_mmap(h_file, vma);
16046 + au_vm_prfile_set(vma, file);
16047 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16048 + goto out_fput; /* success */
16050 + au_unset_mmapped(file);
16051 + au_vm_file_reset(vma, file);
16055 + ii_write_unlock(inode);
16060 + si_read_unlock(sb);
16066 +/* ---------------------------------------------------------------------- */
16068 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16072 + struct au_write_pre wpre;
16073 + struct inode *inode;
16074 + struct file *h_file;
16076 + err = 0; /* -EBADF; */ /* posix? */
16077 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16080 + inode = file_inode(file);
16081 + au_mtx_and_read_lock(inode);
16084 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16085 + err = PTR_ERR(h_file);
16086 + if (IS_ERR(h_file))
16089 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16090 + au_write_post(inode, h_file, &wpre, /*written*/0);
16093 + si_read_unlock(inode->i_sb);
16094 + inode_unlock(inode);
16099 +static int aufs_fasync(int fd, struct file *file, int flag)
16102 + struct file *h_file;
16103 + struct super_block *sb;
16105 + sb = file->f_path.dentry->d_sb;
16106 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16108 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16109 + err = PTR_ERR(h_file);
16110 + if (IS_ERR(h_file))
16113 + if (h_file->f_op->fasync)
16114 + err = h_file->f_op->fasync(fd, h_file, flag);
16115 + fput(h_file); /* instead of au_read_post() */
16118 + si_read_unlock(sb);
16122 +static int aufs_setfl(struct file *file, unsigned long arg)
16125 + struct file *h_file;
16126 + struct super_block *sb;
16128 + sb = file->f_path.dentry->d_sb;
16129 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16131 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16132 + err = PTR_ERR(h_file);
16133 + if (IS_ERR(h_file))
16136 + /* stop calling h_file->fasync */
16137 + arg |= vfsub_file_flags(file) & FASYNC;
16138 + err = setfl(/*unused fd*/-1, h_file, arg);
16139 + fput(h_file); /* instead of au_read_post() */
16142 + si_read_unlock(sb);
16146 +/* ---------------------------------------------------------------------- */
16148 +const struct file_operations aufs_file_fop = {
16149 + .owner = THIS_MODULE,
16151 + .llseek = default_llseek,
16153 + .read_iter = aufs_read_iter,
16154 + .write_iter = aufs_write_iter,
16156 +#ifdef CONFIG_AUFS_POLL
16157 + .poll = aufs_poll,
16159 + .unlocked_ioctl = aufs_ioctl_nondir,
16160 +#ifdef CONFIG_COMPAT
16161 + .compat_ioctl = aufs_compat_ioctl_nondir,
16163 + .mmap = aufs_mmap,
16164 + .open = aufs_open_nondir,
16165 + .flush = aufs_flush_nondir,
16166 + .release = aufs_release_nondir,
16167 + .fsync = aufs_fsync_nondir,
16168 + .fasync = aufs_fasync,
16169 + .setfl = aufs_setfl,
16170 + .splice_write = aufs_splice_write,
16171 + .splice_read = aufs_splice_read,
16172 +#if 0 /* reserved for future use */
16173 + .aio_splice_write = aufs_aio_splice_write,
16174 + .aio_splice_read = aufs_aio_splice_read,
16176 + .fallocate = aufs_fallocate,
16177 + .copy_file_range = aufs_copy_file_range
16179 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16180 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16181 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16183 +// SPDX-License-Identifier: GPL-2.0
16185 + * Copyright (C) 2022 Junjiro R. Okajima
16187 + * This program is free software; you can redistribute it and/or modify
16188 + * it under the terms of the GNU General Public License as published by
16189 + * the Free Software Foundation; either version 2 of the License, or
16190 + * (at your option) any later version.
16192 + * This program is distributed in the hope that it will be useful,
16193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16195 + * GNU General Public License for more details.
16197 + * You should have received a copy of the GNU General Public License
16198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16202 + * fs context, aka new mount api
16205 +#include <linux/fs_context.h>
16208 +struct au_fsctx_opts {
16209 + aufs_bindex_t bindex;
16210 + unsigned char skipped;
16211 + struct au_opt *opt, *opt_tail;
16212 + struct super_block *sb;
16213 + struct au_sbinfo *sbinfo;
16214 + struct au_opts opts;
16217 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16218 +static int cvt_err(int err)
16232 +static int au_fsctx_reconfigure(struct fs_context *fc)
16235 + unsigned int mntflags;
16236 + struct dentry *root;
16237 + struct super_block *sb;
16238 + struct inode *inode;
16239 + struct au_fsctx_opts *a = fc->fs_private;
16241 + AuDbg("fc %p\n", fc);
16245 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16247 + di_write_lock_child(root);
16248 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16249 + aufs_write_unlock(root);
16252 + inode = d_inode(root);
16253 + inode_lock(inode);
16254 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16255 + if (unlikely(err))
16257 + di_write_lock_child(root);
16259 + /* au_opts_remount() may return an error */
16260 + err = au_opts_remount(sb, &a->opts);
16262 + if (au_ftest_opts(a->opts.flags, REFRESH))
16263 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16266 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16267 + mntflags = au_mntflags(sb);
16268 + do_dx = !!au_opt_test(mntflags, DIO);
16269 + au_dy_arefresh(do_dx);
16272 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16273 + aufs_write_unlock(root);
16276 + inode_unlock(inode);
16277 + err = cvt_err(err);
16283 +/* ---------------------------------------------------------------------- */
16285 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16288 + struct au_fsctx_opts *a = fc->fs_private;
16289 + struct au_sbinfo *sbinfo = a->sbinfo;
16290 + struct dentry *root;
16291 + struct inode *inode;
16293 + sbinfo->si_sb = sb;
16294 + sb->s_fs_info = sbinfo;
16295 + kobject_get(&sbinfo->si_kobj);
16297 + __si_write_lock(sb);
16299 + au_sbilist_add(sb);
16301 + /* all timestamps always follow the ones on the branch */
16302 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16303 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16304 + sb->s_op = &aufs_sop;
16305 + sb->s_d_op = &aufs_dop;
16306 + sb->s_magic = AUFS_SUPER_MAGIC;
16307 + sb->s_maxbytes = 0;
16308 + sb->s_stack_depth = 1;
16309 + au_export_init(sb);
16310 + au_xattr_init(sb);
16312 + err = au_alloc_root(sb);
16313 + if (unlikely(err)) {
16314 + si_write_unlock(sb);
16317 + root = sb->s_root;
16318 + inode = d_inode(root);
16319 + ii_write_lock_parent(inode);
16320 + aufs_write_unlock(root);
16322 + /* lock vfs_inode first, then aufs. */
16323 + inode_lock(inode);
16324 + aufs_write_lock(root);
16325 + err = au_opts_mount(sb, &a->opts);
16327 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16328 + sb->s_d_op = &aufs_dop_noreval;
16329 + /* infofc(fc, "%ps", sb->s_d_op); */
16330 + pr_info("%ps\n", sb->s_d_op);
16331 + au_refresh_dop(root, /*force_reval*/0);
16332 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16333 + au_refresh_iop(inode, /*force_getattr*/0);
16335 + aufs_write_unlock(root);
16336 + inode_unlock(inode);
16338 + goto out; /* success */
16341 + sb->s_root = NULL;
16344 + if (unlikely(err))
16345 + kobject_put(&sbinfo->si_kobj);
16347 + err = cvt_err(err);
16352 +static int au_fsctx_get_tree(struct fs_context *fc)
16356 + AuDbg("fc %p\n", fc);
16357 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16363 +/* ---------------------------------------------------------------------- */
16365 +static void au_fsctx_dump(struct au_opts *opts)
16367 +#ifdef CONFIG_AUFS_DEBUG
16368 + /* reduce stack space */
16370 + struct au_opt_add *add;
16371 + struct au_opt_del *del;
16372 + struct au_opt_mod *mod;
16373 + struct au_opt_xino *xino;
16374 + struct au_opt_xino_itrunc *xino_itrunc;
16375 + struct au_opt_wbr_create *create;
16377 + struct au_opt *opt;
16380 + while (opt->type != Opt_tail) {
16381 + switch (opt->type) {
16383 + u.add = &opt->add;
16384 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16385 + u.add->bindex, u.add->pathname, u.add->perm,
16386 + u.add->path.dentry);
16391 + u.del = &opt->del;
16392 + AuDbg("del {%s, %p}\n",
16393 + u.del->pathname, u.del->h_path.dentry);
16398 + u.mod = &opt->mod;
16399 + AuDbg("mod {%s, 0x%x, %p}\n",
16400 + u.mod->path, u.mod->perm, u.mod->h_root);
16403 + u.add = &opt->add;
16404 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16405 + u.add->bindex, u.add->pathname, u.add->perm,
16406 + u.add->path.dentry);
16408 + case Opt_prepend:
16409 + u.add = &opt->add;
16410 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16411 + u.add->bindex, u.add->pathname, u.add->perm,
16412 + u.add->path.dentry);
16416 + AuDbg("dirwh %d\n", opt->dirwh);
16418 + case Opt_rdcache:
16419 + AuDbg("rdcache %d\n", opt->rdcache);
16422 + AuDbg("rdblk %d\n", opt->rdblk);
16425 + AuDbg("rdhash %u\n", opt->rdhash);
16429 + u.xino = &opt->xino;
16430 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16433 +#define au_fsctx_TF(name) \
16434 + case Opt_##name: \
16438 + AuLabel(no##name); \
16441 + /* simple true/false flag */
16442 + au_fsctx_TF(trunc_xino);
16443 + au_fsctx_TF(trunc_xib);
16444 + au_fsctx_TF(dirperm1);
16445 + au_fsctx_TF(plink);
16446 + au_fsctx_TF(shwh);
16447 + au_fsctx_TF(dio);
16448 + au_fsctx_TF(warn_perm);
16449 + au_fsctx_TF(verbose);
16450 + au_fsctx_TF(sum);
16451 + au_fsctx_TF(dirren);
16452 + au_fsctx_TF(acl);
16453 +#undef au_fsctx_TF
16455 + case Opt_trunc_xino_path:
16457 + case Opt_itrunc_xino:
16458 + u.xino_itrunc = &opt->xino_itrunc;
16459 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16465 + case Opt_list_plink:
16466 + AuLabel(list_plink);
16469 + AuDbg("udba %d, %s\n",
16470 + opt->udba, au_optstr_udba(opt->udba));
16472 + case Opt_diropq_a:
16473 + AuLabel(diropq_a);
16475 + case Opt_diropq_w:
16476 + AuLabel(diropq_w);
16481 + case Opt_wbr_create:
16482 + u.create = &opt->wbr_create;
16483 + AuDbg("create %d, %s\n", u.create->wbr_create,
16484 + au_optstr_wbr_create(u.create->wbr_create));
16485 + switch (u.create->wbr_create) {
16486 + case AuWbrCreate_MFSV:
16488 + case AuWbrCreate_PMFSV:
16489 + AuDbg("%d sec\n", u.create->mfs_second);
16491 + case AuWbrCreate_MFSRR:
16493 + case AuWbrCreate_TDMFS:
16494 + AuDbg("%llu watermark\n",
16495 + u.create->mfsrr_watermark);
16497 + case AuWbrCreate_MFSRRV:
16499 + case AuWbrCreate_TDMFSV:
16501 + case AuWbrCreate_PMFSRRV:
16502 + AuDbg("%llu watermark, %d sec\n",
16503 + u.create->mfsrr_watermark,
16504 + u.create->mfs_second);
16508 + case Opt_wbr_copyup:
16509 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16510 + au_optstr_wbr_copyup(opt->wbr_copyup));
16512 + case Opt_fhsm_sec:
16513 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16517 + AuDbg("type %d\n", opt->type);
16525 +/* ---------------------------------------------------------------------- */
16528 + * For conditionally compiled mount options.
16529 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16531 +#define au_ignore_flag(name, action) \
16532 + fsparam_flag(name, action), \
16533 + fsparam_flag("no" name, Opt_ignore_silent)
16535 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16536 + fsparam_string("br", Opt_br),
16538 + /* "add=%d:%s" or "ins=%d:%s" */
16539 + fsparam_string("add", Opt_add),
16540 + fsparam_string("ins", Opt_add),
16541 + fsparam_path("append", Opt_append),
16542 + fsparam_path("prepend", Opt_prepend),
16544 + fsparam_path("del", Opt_del),
16545 + /* fsparam_s32("idel", Opt_idel), */
16546 + fsparam_path("mod", Opt_mod),
16547 + /* fsparam_string("imod", Opt_imod), */
16549 + fsparam_s32("dirwh", Opt_dirwh),
16551 + fsparam_path("xino", Opt_xino),
16552 + fsparam_flag("noxino", Opt_noxino),
16553 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16554 + /* "trunc_xino_v=%d:%d" */
16555 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16556 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16557 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16558 + /* fsparam_path("zxino", Opt_zxino), */
16559 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16561 +#ifdef CONFIG_PROC_FS
16562 + fsparam_flag_no("plink", Opt_plink),
16564 + au_ignore_flag("plink", Opt_ignore),
16567 +#ifdef CONFIG_AUFS_DEBUG
16568 + fsparam_flag("list_plink", Opt_list_plink),
16571 + fsparam_string("udba", Opt_udba),
16573 + fsparam_flag_no("dio", Opt_dio),
16575 +#ifdef CONFIG_AUFS_DIRREN
16576 + fsparam_flag_no("dirren", Opt_dirren),
16578 + au_ignore_flag("dirren", Opt_ignore),
16581 +#ifdef CONFIG_AUFS_FHSM
16582 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16584 + fsparam_s32("fhsm_sec", Opt_ignore),
16587 + /* always | a | whiteouted | w */
16588 + fsparam_string("diropq", Opt_diropq),
16590 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16592 +#ifdef CONFIG_AUFS_SHWH
16593 + fsparam_flag_no("shwh", Opt_shwh),
16595 + au_ignore_flag("shwh", Opt_err),
16598 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16600 + fsparam_flag_no("verbose", Opt_verbose),
16601 + fsparam_flag("v", Opt_verbose),
16602 + fsparam_flag("quiet", Opt_noverbose),
16603 + fsparam_flag("q", Opt_noverbose),
16604 + /* user-space may handle this */
16605 + fsparam_flag("silent", Opt_noverbose),
16607 + fsparam_flag_no("sum", Opt_sum),
16608 + fsparam_flag("wsum", Opt_wsum),
16610 + fsparam_s32("rdcache", Opt_rdcache),
16611 + /* "def" or s32 */
16612 + fsparam_string("rdblk", Opt_rdblk),
16613 + /* "def" or s32 */
16614 + fsparam_string("rdhash", Opt_rdhash),
16616 + fsparam_string("create", Opt_wbr_create),
16617 + fsparam_string("create_policy", Opt_wbr_create),
16618 + fsparam_string("cpup", Opt_wbr_copyup),
16619 + fsparam_string("copyup", Opt_wbr_copyup),
16620 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16622 + /* generic VFS flag */
16623 +#ifdef CONFIG_FS_POSIX_ACL
16624 + fsparam_flag_no("acl", Opt_acl),
16626 + au_ignore_flag("acl", Opt_ignore),
16629 + /* internal use for the scripts */
16630 + fsparam_string("si", Opt_ignore_silent),
16632 + /* obsoleted, keep them temporary */
16633 + fsparam_flag("nodlgt", Opt_ignore_silent),
16634 + fsparam_flag("clean_plink", Opt_ignore),
16635 + fsparam_string("dirs", Opt_br),
16636 + fsparam_u32("debug", Opt_ignore),
16637 + /* "whiteout" or "all" */
16638 + fsparam_string("delete", Opt_ignore),
16639 + fsparam_string("imap", Opt_ignore),
16641 + /* temporary workaround, due to old mount(8)? */
16642 + fsparam_flag("relatime", Opt_ignore_silent),
16647 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16648 + char *brspec, size_t speclen,
16649 + aufs_bindex_t bindex)
16654 + AuDbg("brspec %s\n", brspec);
16658 + speclen = strlen(brspec);
16659 + /* will be freed by au_fsctx_free() */
16660 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16661 + if (unlikely(!p)) {
16662 + errorfc(fc, "failed in %s", brspec);
16665 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16672 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16676 + struct au_fsctx_opts *a = fc->fs_private;
16677 + struct au_opt *opt = a->opt;
16678 + aufs_bindex_t bindex = a->bindex;
16680 + AuDbg("brspec %s\n", brspec);
16683 + while ((p = strsep(&brspec, ":")) && *p) {
16684 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16686 + if (unlikely(err))
16690 + if (unlikely(opt > a->opt_tail)) {
16696 + opt->type = Opt_tail;
16699 + a->bindex = bindex;
16706 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16710 + struct au_fsctx_opts *a = fc->fs_private;
16711 + struct au_opt *opt = a->opt;
16714 + p = strchr(addspec, ':');
16715 + if (unlikely(!p)) {
16716 + errorfc(fc, "bad arg in %s", addspec);
16720 + err = kstrtoint(addspec, 0, &n);
16721 + if (unlikely(err)) {
16722 + errorfc(fc, "bad integer in %s", addspec);
16725 + AuDbg("n %d\n", n);
16726 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16733 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16734 + struct fs_parameter *param)
16739 + /* will be freed by au_fsctx_free() */
16740 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16741 + if (unlikely(!del->pathname))
16743 + AuDbg("del %s\n", del->pathname);
16744 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16745 + if (unlikely(err))
16746 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16753 +#if 0 /* reserved for future use */
16754 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16755 + aufs_bindex_t bindex)
16758 + struct super_block *sb;
16759 + struct dentry *root;
16760 + struct au_fsctx_opts *a = fc->fs_private;
16766 + root = sb->s_root;
16767 + aufs_read_lock(root, AuLock_FLUSH);
16768 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16769 + errorfc(fc, "out of bounds, %d", bindex);
16774 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16775 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16778 + aufs_read_unlock(root, !AuLock_IR);
16784 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16785 + struct fs_parameter *param)
16788 + struct path path;
16792 + /* will be freed by au_fsctx_free() */
16793 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16794 + if (unlikely(!mod->path))
16798 + p = strchr(mod->path, '=');
16799 + if (unlikely(!p)) {
16800 + errorfc(fc, "no permission %s", mod->path);
16805 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16806 + if (unlikely(err)) {
16807 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16811 + mod->perm = au_br_perm_val(p);
16812 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16813 + mod->h_root = dget(path.dentry);
16821 +#if 0 /* reserved for future use */
16822 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16827 + struct super_block *sb;
16828 + struct dentry *root;
16829 + struct au_fsctx_opts *a = fc->fs_private;
16835 + p = strchr(ibrspec, ':');
16836 + if (unlikely(!p)) {
16837 + errorfc(fc, "no index, %s", ibrspec);
16841 + err = kstrtoint(ibrspec, 0, &n);
16842 + if (unlikely(err)) {
16843 + errorfc(fc, "bad integer in %s", ibrspec);
16846 + AuDbg("n %d\n", n);
16848 + root = sb->s_root;
16849 + aufs_read_lock(root, AuLock_FLUSH);
16850 + if (n < 0 || au_sbbot(sb) < n) {
16851 + errorfc(fc, "out of bounds, %d", bindex);
16856 + mod->perm = au_br_perm_val(p);
16857 + AuDbg("mod path %s, perm 0x%x, %s\n",
16858 + mod->path, mod->perm, p);
16859 + mod->h_root = dget(au_h_dptr(root, bindex));
16862 + aufs_read_unlock(root, !AuLock_IR);
16869 +static int au_fsctx_parse_xino(struct fs_context *fc,
16870 + struct au_opt_xino *xino,
16871 + struct fs_parameter *param)
16874 + struct au_fsctx_opts *a = fc->fs_private;
16877 + /* will be freed by au_opts_free() */
16878 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16879 + if (unlikely(!xino->path))
16881 + AuDbg("path %s\n", xino->path);
16883 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16885 + err = PTR_ERR(xino->file);
16886 + if (IS_ERR(xino->file)) {
16887 + xino->file = NULL;
16892 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16894 + errorfc(fc, "%s must be outside", xino->path);
16903 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16904 + struct au_opt_xino_itrunc *xino_itrunc,
16908 + aufs_bindex_t bbot, bindex;
16909 + struct path path;
16910 + struct dentry *root;
16911 + struct au_fsctx_opts *a = fc->fs_private;
16913 + AuDebugOn(!a->sb);
16915 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16916 + if (unlikely(err)) {
16917 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16921 + xino_itrunc->bindex = -1;
16922 + root = a->sb->s_root;
16923 + aufs_read_lock(root, AuLock_FLUSH);
16924 + bbot = au_sbbot(a->sb);
16925 + for (bindex = 0; bindex <= bbot; bindex++) {
16926 + if (au_h_dptr(root, bindex) == path.dentry) {
16927 + xino_itrunc->bindex = bindex;
16931 + aufs_read_unlock(root, !AuLock_IR);
16934 + if (unlikely(xino_itrunc->bindex < 0)) {
16936 + errorfc(fc, "no such branch %s", pathname);
16944 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16945 + struct au_opt_xino_itrunc *xino_itrunc,
16946 + unsigned int bindex)
16949 + aufs_bindex_t bbot;
16950 + struct super_block *sb;
16951 + struct au_fsctx_opts *a = fc->fs_private;
16957 + si_noflush_read_lock(sb);
16958 + bbot = au_sbbot(sb);
16959 + si_read_unlock(sb);
16960 + if (bindex <= bbot)
16961 + xino_itrunc->bindex = bindex;
16964 + errorfc(fc, "out of bounds, %u", bindex);
16971 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16974 + struct fs_parse_result result;
16975 + struct au_fsctx_opts *a = fc->fs_private;
16976 + struct au_opt *opt = a->opt;
16978 + AuDbg("fc %p, param {key %s, string %s}\n",
16979 + fc, param->key, param->string);
16980 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16981 + if (unlikely(err < 0))
16984 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16985 + token, result.negated, result.uint_64);
16991 + err = au_fsctx_parse_br(fc, param->string);
16994 + err = au_fsctx_parse_add(fc, param->string);
16997 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
16998 + /*dummy bindex*/1);
17000 + case Opt_prepend:
17001 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17006 + err = au_fsctx_parse_del(fc, &opt->del, param);
17008 +#if 0 /* reserved for future use */
17015 + del->pathname = "(indexed)";
17016 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17021 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17023 +#ifdef IMOD /* reserved for future use */
17030 + u.mod->path = "(indexed)";
17031 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17036 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17038 + case Opt_trunc_xino_path:
17040 + errorfc(fc, "no such branch %s", param->string);
17043 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17047 + case Opt_trunc_xino_v:
17053 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17057 + case Opt_itrunc_xino:
17059 + errorfc(fc, "out of bounds %s", param->string);
17062 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17068 + opt->dirwh = result.int_32;
17071 + case Opt_rdcache:
17072 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17073 + errorfc(fc, "rdcache must be smaller than %d",
17074 + AUFS_RDCACHE_MAX);
17078 + opt->rdcache = result.int_32;
17083 + opt->rdblk = AUFS_RDBLK_DEF;
17084 + if (!strcmp(param->string, "def"))
17087 + err = kstrtoint(param->string, 0, &result.int_32);
17088 + if (unlikely(err)) {
17089 + errorfc(fc, "bad value in %s", param->key);
17093 + if (unlikely(result.int_32 < 0
17094 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17095 + errorfc(fc, "bad value in %s", param->key);
17098 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17099 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17103 + opt->rdblk = result.int_32;
17108 + opt->rdhash = AUFS_RDHASH_DEF;
17109 + if (!strcmp(param->string, "def"))
17112 + err = kstrtoint(param->string, 0, &result.int_32);
17113 + if (unlikely(err)) {
17114 + errorfc(fc, "bad value in %s", param->key);
17117 + /* how about zero? */
17118 + if (result.int_32 < 0
17119 + || result.int_32 * sizeof(struct hlist_head)
17120 + > KMALLOC_MAX_SIZE) {
17122 + errorfc(fc, "bad integer in %s", param->key);
17125 + opt->rdhash = result.int_32;
17130 + * As other options, fs/aufs/opts.c can handle these strings by
17131 + * match_token(). But "diropq=" is deprecated now and will
17132 + * never have other value. So simple strcmp() is enough here.
17134 + if (!strcmp(param->string, "a") ||
17135 + !strcmp(param->string, "always")) {
17137 + opt->type = Opt_diropq_a;
17138 + } else if (!strcmp(param->string, "w") ||
17139 + !strcmp(param->string, "whiteouted")) {
17141 + opt->type = Opt_diropq_w;
17143 + errorfc(fc, "unknown value %s", param->string);
17147 + opt->udba = au_udba_val(param->string);
17148 + if (opt->udba >= 0)
17151 + errorf(fc, "wrong value, %s", param->string);
17154 + case Opt_wbr_create:
17155 + opt->wbr_create.wbr_create
17156 + = au_wbr_create_val(param->string, &opt->wbr_create);
17157 + if (opt->wbr_create.wbr_create >= 0)
17160 + errorf(fc, "wrong value, %s", param->key);
17163 + case Opt_wbr_copyup:
17164 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17165 + if (opt->wbr_copyup >= 0)
17168 + errorfc(fc, "wrong value, %s", param->key);
17171 + case Opt_fhsm_sec:
17172 + if (unlikely(result.int_32 < 0)) {
17173 + errorfc(fc, "bad integer in %s\n", param->key);
17178 + opt->fhsm_second = result.int_32;
17180 + warnfc(fc, "ignored %s %s", param->key, param->string);
17183 + /* simple true/false flag */
17184 +#define au_fsctx_TF(name) \
17185 + case Opt_##name: \
17187 + opt->tf = !result.negated; \
17189 + au_fsctx_TF(trunc_xino);
17190 + au_fsctx_TF(trunc_xib);
17191 + au_fsctx_TF(dirperm1);
17192 + au_fsctx_TF(plink);
17193 + au_fsctx_TF(shwh);
17194 + au_fsctx_TF(dio);
17195 + au_fsctx_TF(warn_perm);
17196 + au_fsctx_TF(verbose);
17197 + au_fsctx_TF(sum);
17198 + au_fsctx_TF(dirren);
17199 + au_fsctx_TF(acl);
17200 +#undef au_fsctx_TF
17202 + case Opt_noverbose:
17204 + opt->type = Opt_verbose;
17210 + case Opt_list_plink:
17217 + warnfc(fc, "ignored %s", param->key);
17219 + case Opt_ignore_silent:
17228 + if (unlikely(err))
17236 + case Opt_noverbose:
17241 + opt->type = token;
17245 + if (unlikely(opt > a->opt_tail)) {
17249 + opt->type = Opt_tail;
17257 + * these options accept both 'name=val' and 'name:val' form.
17258 + * some accept optional '=' in its value.
17259 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17261 +static inline unsigned int is_colonopt(char *str)
17263 +#define do_test(name) \
17264 + if (!strncmp(str, name ":", sizeof(name))) \
17265 + return sizeof(name) - 1
17269 + do_test("append");
17270 + do_test("prepend");
17272 + /* do_test("idel"); */
17274 + /* do_test("imod"); */
17280 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17285 + struct au_fsctx_opts *a = fc->fs_private;
17288 + AuDbg("str %s\n", str);
17290 + u = is_colonopt(str);
17293 + str = strchr(str, ',');
17299 + AuDbg("str %s\n", str);
17301 + err = generic_parse_monolithic(fc, str);
17303 + au_fsctx_dump(&a->opts);
17308 +/* ---------------------------------------------------------------------- */
17310 +static void au_fsctx_opts_free(struct au_opts *opts)
17312 + struct au_opt *opt;
17315 + while (opt->type != Opt_tail) {
17316 + switch (opt->type) {
17321 + case Opt_prepend:
17322 + kfree(opt->add.pathname);
17323 + path_put(&opt->add.path);
17326 + kfree(opt->del.pathname);
17329 + path_put(&opt->del.h_path);
17332 + kfree(opt->mod.path);
17335 + dput(opt->mod.h_root);
17338 + kfree(opt->xino.path);
17339 + fput(opt->xino.file);
17346 +static void au_fsctx_free(struct fs_context *fc)
17348 + struct au_fsctx_opts *a = fc->fs_private;
17350 + /* fs_type=%p, root=%pD */
17351 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17352 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17354 + kobject_put(&a->sbinfo->si_kobj);
17355 + au_fsctx_opts_free(&a->opts);
17356 + free_page((unsigned long)a->opts.opt);
17360 +static const struct fs_context_operations au_fsctx_ops = {
17361 + .free = au_fsctx_free,
17362 + .parse_param = au_fsctx_parse_param,
17363 + .parse_monolithic = au_fsctx_parse_monolithic,
17364 + .get_tree = au_fsctx_get_tree,
17365 + .reconfigure = au_fsctx_reconfigure
17367 + * nfs4 requires ->dup()? No.
17368 + * I don't know what is this ->dup() for.
17372 +int aufs_fsctx_init(struct fs_context *fc)
17375 + struct au_fsctx_opts *a;
17377 + /* fs_type=%p, root=%pD */
17378 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17379 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17381 + /* they will be freed by au_fsctx_free() */
17383 + a = kzalloc(sizeof(*a), GFP_NOFS);
17384 + if (unlikely(!a))
17387 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17388 + if (unlikely(!a->opts.opt))
17390 + a->opt = a->opts.opt;
17391 + a->opt->type = Opt_tail;
17392 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17393 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17394 + a->opts.sb_flags = fc->sb_flags;
17398 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17399 + a->opts.flags = AuOpts_REMOUNT;
17400 + a->sb = fc->root->d_sb;
17401 + a->sbinfo = au_sbi(a->sb);
17402 + kobject_get(&a->sbinfo->si_kobj);
17404 + a->sbinfo = au_si_alloc(a->sb);
17405 + AuDebugOn(!a->sbinfo);
17406 + err = PTR_ERR(a->sbinfo);
17407 + if (IS_ERR(a->sbinfo))
17409 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17413 + fc->fs_private = a;
17414 + fc->ops = &au_fsctx_ops;
17415 + goto out; /* success */
17418 + free_page((unsigned long)a->opts.opt);
17425 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17426 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17427 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17429 +/* SPDX-License-Identifier: GPL-2.0 */
17431 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17433 + * This program is free software; you can redistribute it and/or modify
17434 + * it under the terms of the GNU General Public License as published by
17435 + * the Free Software Foundation; either version 2 of the License, or
17436 + * (at your option) any later version.
17438 + * This program is distributed in the hope that it will be useful,
17439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17441 + * GNU General Public License for more details.
17443 + * You should have received a copy of the GNU General Public License
17444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17448 + * judging filesystem type
17451 +#ifndef __AUFS_FSTYPE_H__
17452 +#define __AUFS_FSTYPE_H__
17456 +#include <linux/fs.h>
17457 +#include <linux/magic.h>
17458 +#include <linux/nfs_fs.h>
17459 +#include <linux/romfs_fs.h>
17461 +static inline int au_test_aufs(struct super_block *sb)
17463 + return sb->s_magic == AUFS_SUPER_MAGIC;
17466 +static inline const char *au_sbtype(struct super_block *sb)
17468 + return sb->s_type->name;
17471 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17473 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17474 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17480 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17482 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17483 + return sb->s_magic == ROMFS_MAGIC;
17489 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17491 +#if IS_ENABLED(CONFIG_CRAMFS)
17492 + return sb->s_magic == CRAMFS_MAGIC;
17497 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17499 +#if IS_ENABLED(CONFIG_NFS_FS)
17500 + return sb->s_magic == NFS_SUPER_MAGIC;
17506 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17508 +#if IS_ENABLED(CONFIG_FUSE_FS)
17509 + return sb->s_magic == FUSE_SUPER_MAGIC;
17515 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17517 +#if IS_ENABLED(CONFIG_XFS_FS)
17518 + return sb->s_magic == XFS_SB_MAGIC;
17524 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17526 +#ifdef CONFIG_TMPFS
17527 + return sb->s_magic == TMPFS_MAGIC;
17533 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17535 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17536 + return !strcmp(au_sbtype(sb), "ecryptfs");
17542 +static inline int au_test_ramfs(struct super_block *sb)
17544 + return sb->s_magic == RAMFS_MAGIC;
17547 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17549 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17550 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17556 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17558 +#ifdef CONFIG_PROC_FS
17559 + return sb->s_magic == PROC_SUPER_MAGIC;
17565 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17567 +#ifdef CONFIG_SYSFS
17568 + return sb->s_magic == SYSFS_MAGIC;
17574 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17576 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17577 + return sb->s_magic == CONFIGFS_MAGIC;
17583 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17585 +#if IS_ENABLED(CONFIG_MINIX_FS)
17586 + return sb->s_magic == MINIX3_SUPER_MAGIC
17587 + || sb->s_magic == MINIX2_SUPER_MAGIC
17588 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17589 + || sb->s_magic == MINIX_SUPER_MAGIC
17590 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17596 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17598 +#if IS_ENABLED(CONFIG_FAT_FS)
17599 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17605 +static inline int au_test_msdos(struct super_block *sb)
17607 + return au_test_fat(sb);
17610 +static inline int au_test_vfat(struct super_block *sb)
17612 + return au_test_fat(sb);
17615 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17617 +#ifdef CONFIG_SECURITYFS
17618 + return sb->s_magic == SECURITYFS_MAGIC;
17624 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17626 +#if IS_ENABLED(CONFIG_SQUASHFS)
17627 + return sb->s_magic == SQUASHFS_MAGIC;
17633 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17635 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17636 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17642 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17644 +#if IS_ENABLED(CONFIG_XENFS)
17645 + return sb->s_magic == XENFS_SUPER_MAGIC;
17651 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17653 +#ifdef CONFIG_DEBUG_FS
17654 + return sb->s_magic == DEBUGFS_MAGIC;
17660 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17662 +#if IS_ENABLED(CONFIG_NILFS)
17663 + return sb->s_magic == NILFS_SUPER_MAGIC;
17669 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17671 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17672 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17678 +/* ---------------------------------------------------------------------- */
17680 + * they can't be an aufs branch.
17682 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17685 +#ifndef CONFIG_AUFS_BR_RAMFS
17686 + au_test_ramfs(sb) ||
17688 + au_test_procfs(sb)
17689 + || au_test_sysfs(sb)
17690 + || au_test_configfs(sb)
17691 + || au_test_debugfs(sb)
17692 + || au_test_securityfs(sb)
17693 + || au_test_xenfs(sb)
17694 + || au_test_ecryptfs(sb)
17695 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17696 + || au_test_aufs(sb); /* will be supported in next version */
17699 +static inline int au_test_fs_remote(struct super_block *sb)
17701 + return !au_test_tmpfs(sb)
17702 +#ifdef CONFIG_AUFS_BR_RAMFS
17703 + && !au_test_ramfs(sb)
17705 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17708 +/* ---------------------------------------------------------------------- */
17711 + * Note: these functions (below) are created after reading ->getattr() in all
17712 + * filesystems under linux/fs. it means we have to do so in every update...
17716 + * some filesystems require getattr to refresh the inode attributes before
17718 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17719 + * and leave the work for d_revalidate()
17721 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17723 + return au_test_nfs(sb)
17724 + || au_test_fuse(sb)
17725 + /* || au_test_btrfs(sb) */ /* untested */
17730 + * filesystems which don't maintain i_size or i_blocks.
17732 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17734 + return au_test_xfs(sb)
17735 + || au_test_btrfs(sb)
17736 + || au_test_ubifs(sb)
17737 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17738 + /* || au_test_minix(sb) */ /* untested */
17743 + * filesystems which don't store the correct value in some of their inode
17746 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17748 + return au_test_fs_bad_iattr_size(sb)
17749 + || au_test_fat(sb)
17750 + || au_test_msdos(sb)
17751 + || au_test_vfat(sb);
17754 +/* they don't check i_nlink in link(2) */
17755 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17757 + return au_test_tmpfs(sb)
17758 +#ifdef CONFIG_AUFS_BR_RAMFS
17759 + || au_test_ramfs(sb)
17761 + || au_test_ubifs(sb)
17762 + || au_test_hfsplus(sb);
17766 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17768 +static inline int au_test_fs_notime(struct super_block *sb)
17770 + return au_test_nfs(sb)
17771 + || au_test_fuse(sb)
17772 + || au_test_ubifs(sb)
17776 +/* temporary support for i#1 in cramfs */
17777 +static inline int au_test_fs_unique_ino(struct inode *inode)
17779 + if (au_test_cramfs(inode->i_sb))
17780 + return inode->i_ino != 1;
17784 +/* ---------------------------------------------------------------------- */
17787 + * the filesystem where the xino files placed must support i/o after unlink and
17788 + * maintain i_size and i_blocks.
17790 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17792 + return au_test_fs_remote(sb)
17793 + || au_test_fs_bad_iattr_size(sb)
17794 + /* don't want unnecessary work for xino */
17795 + || au_test_aufs(sb)
17796 + || au_test_ecryptfs(sb)
17797 + || au_test_nilfs(sb);
17800 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17802 + return au_test_tmpfs(sb)
17803 + || au_test_ramfs(sb);
17807 + * test if the @sb is real-readonly.
17809 +static inline int au_test_fs_rr(struct super_block *sb)
17811 + return au_test_squashfs(sb)
17812 + || au_test_iso9660(sb)
17813 + || au_test_cramfs(sb)
17814 + || au_test_romfs(sb);
17818 + * test if the @inode is nfs with 'noacl' option
17819 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17821 +static inline int au_test_nfs_noacl(struct inode *inode)
17823 + return au_test_nfs(inode->i_sb)
17824 + /* && IS_POSIXACL(inode) */
17825 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17828 +#endif /* __KERNEL__ */
17829 +#endif /* __AUFS_FSTYPE_H__ */
17830 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17831 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17832 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17834 +/* SPDX-License-Identifier: GPL-2.0 */
17836 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17838 + * This program is free software; you can redistribute it and/or modify
17839 + * it under the terms of the GNU General Public License as published by
17840 + * the Free Software Foundation; either version 2 of the License, or
17841 + * (at your option) any later version.
17843 + * This program is distributed in the hope that it will be useful,
17844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17846 + * GNU General Public License for more details.
17848 + * You should have received a copy of the GNU General Public License
17849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17853 + * helpers for hlist_bl.h
17856 +#ifndef __AUFS_HBL_H__
17857 +#define __AUFS_HBL_H__
17861 +#include <linux/list_bl.h>
17863 +static inline void au_hbl_add(struct hlist_bl_node *node,
17864 + struct hlist_bl_head *hbl)
17866 + hlist_bl_lock(hbl);
17867 + hlist_bl_add_head(node, hbl);
17868 + hlist_bl_unlock(hbl);
17871 +static inline void au_hbl_del(struct hlist_bl_node *node,
17872 + struct hlist_bl_head *hbl)
17874 + hlist_bl_lock(hbl);
17875 + hlist_bl_del(node);
17876 + hlist_bl_unlock(hbl);
17879 +#define au_hbl_for_each(pos, head) \
17880 + for (pos = hlist_bl_first(head); \
17884 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17886 + unsigned long cnt;
17887 + struct hlist_bl_node *pos;
17890 + hlist_bl_lock(hbl);
17891 + au_hbl_for_each(pos, hbl)
17893 + hlist_bl_unlock(hbl);
17897 +#endif /* __KERNEL__ */
17898 +#endif /* __AUFS_HBL_H__ */
17899 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17900 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17901 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17903 +// SPDX-License-Identifier: GPL-2.0
17905 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17907 + * This program is free software; you can redistribute it and/or modify
17908 + * it under the terms of the GNU General Public License as published by
17909 + * the Free Software Foundation; either version 2 of the License, or
17910 + * (at your option) any later version.
17912 + * This program is distributed in the hope that it will be useful,
17913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17915 + * GNU General Public License for more details.
17917 + * You should have received a copy of the GNU General Public License
17918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17922 + * fsnotify for the lower directories
17927 +/* FS_IN_IGNORED is unnecessary */
17928 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17929 + | FS_CREATE | FS_EVENT_ON_CHILD);
17930 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17931 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17933 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17935 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17937 + /* AuDbg("here\n"); */
17938 + au_cache_free_hnotify(hn);
17939 + smp_mb__before_atomic(); /* for atomic64_dec */
17940 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17941 + wake_up(&au_hfsn_wq);
17944 +static int au_hfsn_alloc(struct au_hinode *hinode)
17947 + struct au_hnotify *hn;
17948 + struct super_block *sb;
17949 + struct au_branch *br;
17950 + struct fsnotify_mark *mark;
17951 + aufs_bindex_t bindex;
17953 + hn = hinode->hi_notify;
17954 + sb = hn->hn_aufs_inode->i_sb;
17955 + bindex = au_br_index(sb, hinode->hi_id);
17956 + br = au_sbr(sb, bindex);
17957 + AuDebugOn(!br->br_hfsn);
17959 + mark = &hn->hn_mark;
17960 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17961 + mark->mask = AuHfsnMask;
17963 + * by udba rename or rmdir, aufs assign a new inode to the known
17964 + * h_inode, so specify 1 to allow dups.
17967 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17973 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17975 + struct fsnotify_mark *mark;
17976 + unsigned long long ull;
17977 + struct fsnotify_group *group;
17979 + ull = atomic64_inc_return(&au_hfsn_ifree);
17982 + mark = &hn->hn_mark;
17983 + spin_lock(&mark->lock);
17984 + group = mark->group;
17985 + fsnotify_get_group(group);
17986 + spin_unlock(&mark->lock);
17988 + fsnotify_destroy_mark(mark, group);
17989 + fsnotify_put_mark(mark);
17990 + fsnotify_put_group(group);
17993 + /* free hn by myself */
17997 +/* ---------------------------------------------------------------------- */
17999 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18001 + struct fsnotify_mark *mark;
18003 + mark = &hinode->hi_notify->hn_mark;
18004 + spin_lock(&mark->lock);
18006 + AuDebugOn(mark->mask & AuHfsnMask);
18007 + mark->mask |= AuHfsnMask;
18009 + AuDebugOn(!(mark->mask & AuHfsnMask));
18010 + mark->mask &= ~AuHfsnMask;
18012 + spin_unlock(&mark->lock);
18013 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18016 +/* ---------------------------------------------------------------------- */
18018 +/* #define AuDbgHnotify */
18019 +#ifdef AuDbgHnotify
18020 +static char *au_hfsn_name(u32 mask)
18022 +#ifdef CONFIG_AUFS_DEBUG
18023 +#define test_ret(flag) \
18025 + if (mask & flag) \
18028 + test_ret(FS_ACCESS);
18029 + test_ret(FS_MODIFY);
18030 + test_ret(FS_ATTRIB);
18031 + test_ret(FS_CLOSE_WRITE);
18032 + test_ret(FS_CLOSE_NOWRITE);
18033 + test_ret(FS_OPEN);
18034 + test_ret(FS_MOVED_FROM);
18035 + test_ret(FS_MOVED_TO);
18036 + test_ret(FS_CREATE);
18037 + test_ret(FS_DELETE);
18038 + test_ret(FS_DELETE_SELF);
18039 + test_ret(FS_MOVE_SELF);
18040 + test_ret(FS_UNMOUNT);
18041 + test_ret(FS_Q_OVERFLOW);
18042 + test_ret(FS_IN_IGNORED);
18043 + test_ret(FS_ISDIR);
18044 + test_ret(FS_IN_ONESHOT);
18045 + test_ret(FS_EVENT_ON_CHILD);
18054 +/* ---------------------------------------------------------------------- */
18056 +static void au_hfsn_free_group(struct fsnotify_group *group)
18058 + struct au_br_hfsnotify *hfsn = group->private;
18060 + /* AuDbg("here\n"); */
18061 + au_kfree_try_rcu(hfsn);
18064 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18065 + u32 mask, const void *data, int data_type,
18066 + struct inode *dir,
18067 + const struct qstr *file_name, u32 cookie,
18068 + struct fsnotify_iter_info *iter_info)
18071 + struct au_hnotify *hnotify;
18072 + struct inode *h_dir, *h_inode;
18073 + struct fsnotify_mark *inode_mark;
18075 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18076 + || data_type == FSNOTIFY_EVENT_DENTRY));
18079 + /* if FS_UNMOUNT happens, there must be another bug */
18080 + AuDebugOn(mask & FS_UNMOUNT);
18081 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18086 +#ifdef AuDbgHnotify
18088 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18089 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18090 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18091 + h_dir->i_ino, mask, au_hfsn_name(mask),
18092 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18093 + /* WARN_ON(1); */
18098 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18099 + AuDebugOn(!inode_mark);
18100 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18101 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18107 +static struct fsnotify_ops au_hfsn_ops = {
18108 + .handle_event = au_hfsn_handle_event,
18109 + .free_group_priv = au_hfsn_free_group,
18110 + .free_mark = au_hfsn_free_mark
18113 +/* ---------------------------------------------------------------------- */
18115 +static void au_hfsn_fin_br(struct au_branch *br)
18117 + struct au_br_hfsnotify *hfsn;
18119 + hfsn = br->br_hfsn;
18122 + fsnotify_put_group(hfsn->hfsn_group);
18127 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18130 + struct fsnotify_group *group;
18131 + struct au_br_hfsnotify *hfsn;
18134 + br->br_hfsn = NULL;
18135 + if (!au_br_hnotifyable(perm))
18139 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18140 + if (unlikely(!hfsn))
18144 + group = fsnotify_alloc_group(&au_hfsn_ops,
18145 + /*flags - not for userspace*/0);
18146 + if (IS_ERR(group)) {
18147 + err = PTR_ERR(group);
18148 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18152 + group->private = hfsn;
18153 + hfsn->hfsn_group = group;
18154 + br->br_hfsn = hfsn;
18155 + goto out; /* success */
18158 + au_kfree_try_rcu(hfsn);
18163 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18168 + if (!br->br_hfsn)
18169 + err = au_hfsn_init_br(br, perm);
18174 +/* ---------------------------------------------------------------------- */
18176 +static void au_hfsn_fin(void)
18178 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18179 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18182 +const struct au_hnotify_op au_hnotify_op = {
18183 + .ctl = au_hfsn_ctl,
18184 + .alloc = au_hfsn_alloc,
18185 + .free = au_hfsn_free,
18187 + .fin = au_hfsn_fin,
18189 + .reset_br = au_hfsn_reset_br,
18190 + .fin_br = au_hfsn_fin_br,
18191 + .init_br = au_hfsn_init_br
18193 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18194 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18195 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18197 +// SPDX-License-Identifier: GPL-2.0
18199 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18201 + * This program is free software; you can redistribute it and/or modify
18202 + * it under the terms of the GNU General Public License as published by
18203 + * the Free Software Foundation; either version 2 of the License, or
18204 + * (at your option) any later version.
18206 + * This program is distributed in the hope that it will be useful,
18207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18209 + * GNU General Public License for more details.
18211 + * You should have received a copy of the GNU General Public License
18212 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18216 + * special support for filesystems which acquires an inode mutex
18217 + * at final closing a file, eg, hfsplus.
18219 + * This trick is very simple and stupid, just to open the file before really
18220 + * necessary open to tell hfsplus that this is not the final closing.
18221 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18222 + * and au_h_open_post() after releasing it.
18227 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18230 + struct file *h_file;
18231 + struct dentry *h_dentry;
18233 + h_dentry = au_h_dptr(dentry, bindex);
18234 + AuDebugOn(!h_dentry);
18235 + AuDebugOn(d_is_negative(h_dentry));
18238 + if (au_test_hfsplus(h_dentry->d_sb)
18239 + && d_is_reg(h_dentry))
18240 + h_file = au_h_open(dentry, bindex,
18241 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18242 + /*file*/NULL, force_wr);
18246 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18247 + struct file *h_file)
18249 + struct au_branch *br;
18253 + br = au_sbr(dentry->d_sb, bindex);
18254 + au_lcnt_dec(&br->br_nfiles);
18257 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18258 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18259 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18261 +// SPDX-License-Identifier: GPL-2.0
18263 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18265 + * This program is free software; you can redistribute it and/or modify
18266 + * it under the terms of the GNU General Public License as published by
18267 + * the Free Software Foundation; either version 2 of the License, or
18268 + * (at your option) any later version.
18270 + * This program is distributed in the hope that it will be useful,
18271 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18272 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18273 + * GNU General Public License for more details.
18275 + * You should have received a copy of the GNU General Public License
18276 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18280 + * abstraction to notify the direct changes on lower directories
18283 +/* #include <linux/iversion.h> */
18286 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18289 + struct au_hnotify *hn;
18292 + hn = au_cache_alloc_hnotify();
18294 + hn->hn_aufs_inode = inode;
18295 + hinode->hi_notify = hn;
18296 + err = au_hnotify_op.alloc(hinode);
18298 + if (unlikely(err)) {
18299 + hinode->hi_notify = NULL;
18300 + au_cache_free_hnotify(hn);
18302 + * The upper dir was removed by udba, but the same named
18303 + * dir left. In this case, aufs assigns a new inode
18304 + * number and set the monitor again.
18305 + * For the lower dir, the old monitor is still left.
18307 + if (err == -EEXIST)
18316 +void au_hn_free(struct au_hinode *hinode)
18318 + struct au_hnotify *hn;
18320 + hn = hinode->hi_notify;
18322 + hinode->hi_notify = NULL;
18323 + if (au_hnotify_op.free(hinode, hn))
18324 + au_cache_free_hnotify(hn);
18328 +/* ---------------------------------------------------------------------- */
18330 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18332 + if (hinode->hi_notify)
18333 + au_hnotify_op.ctl(hinode, do_set);
18336 +void au_hn_reset(struct inode *inode, unsigned int flags)
18338 + aufs_bindex_t bindex, bbot;
18339 + struct inode *hi;
18340 + struct dentry *iwhdentry;
18342 + bbot = au_ibbot(inode);
18343 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18344 + hi = au_h_iptr(inode, bindex);
18348 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18349 + iwhdentry = au_hi_wh(inode, bindex);
18353 + au_set_h_iptr(inode, bindex, NULL, 0);
18354 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18355 + flags & ~AuHi_XINO);
18358 + /* inode_unlock(hi); */
18362 +/* ---------------------------------------------------------------------- */
18364 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18367 + aufs_bindex_t bindex, bbot, bfound, btop;
18368 + struct inode *h_i;
18371 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18372 + pr_warn("branch root dir was changed\n");
18377 + bbot = au_ibbot(inode);
18378 + btop = au_ibtop(inode);
18379 +#if 0 /* reserved for future use */
18380 + if (bindex == bbot) {
18381 + /* keep this ino in rename case */
18385 + for (bindex = btop; bindex <= bbot; bindex++)
18386 + if (au_h_iptr(inode, bindex) == h_inode) {
18393 + for (bindex = btop; bindex <= bbot; bindex++) {
18394 + h_i = au_h_iptr(inode, bindex);
18398 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18399 + /* ignore this error */
18400 + /* bad action? */
18403 + /* children inode number will be broken */
18410 +static int hn_gen_tree(struct dentry *dentry)
18412 + int err, i, j, ndentry;
18413 + struct au_dcsub_pages dpages;
18414 + struct au_dpage *dpage;
18415 + struct dentry **dentries;
18417 + err = au_dpages_init(&dpages, GFP_NOFS);
18418 + if (unlikely(err))
18420 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18421 + if (unlikely(err))
18424 + for (i = 0; i < dpages.ndpage; i++) {
18425 + dpage = dpages.dpages + i;
18426 + dentries = dpage->dentries;
18427 + ndentry = dpage->ndentry;
18428 + for (j = 0; j < ndentry; j++) {
18429 + struct dentry *d;
18436 + if (d_really_is_positive(d))
18437 + /* todo: reset children xino?
18438 + cached children only? */
18439 + au_iigen_dec(d_inode(d));
18444 + au_dpages_free(&dpages);
18450 + * return 0 if processed.
18452 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18453 + const unsigned int isdir)
18456 + struct dentry *d;
18457 + struct qstr *dname;
18460 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18461 + pr_warn("branch root dir was changed\n");
18467 + AuDebugOn(!name);
18468 + au_iigen_dec(inode);
18469 + spin_lock(&inode->i_lock);
18470 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18471 + spin_lock(&d->d_lock);
18472 + dname = &d->d_name;
18473 + if (dname->len != nlen
18474 + && memcmp(dname->name, name, nlen)) {
18475 + spin_unlock(&d->d_lock);
18480 + spin_unlock(&d->d_lock);
18483 + spin_unlock(&inode->i_lock);
18485 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18486 + d = d_find_any_alias(inode);
18488 + au_iigen_dec(inode);
18492 + spin_lock(&d->d_lock);
18493 + dname = &d->d_name;
18494 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18495 + spin_unlock(&d->d_lock);
18496 + err = hn_gen_tree(d);
18497 + spin_lock(&d->d_lock);
18499 + spin_unlock(&d->d_lock);
18508 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18512 + if (IS_ROOT(dentry)) {
18513 + pr_warn("branch root dir was changed\n");
18519 + au_digen_dec(dentry);
18520 + if (d_really_is_positive(dentry))
18521 + au_iigen_dec(d_inode(dentry));
18523 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18524 + if (d_really_is_positive(dentry))
18525 + err = hn_gen_tree(dentry);
18532 +/* ---------------------------------------------------------------------- */
18534 +/* hnotify job flags */
18535 +#define AuHnJob_XINO0 1
18536 +#define AuHnJob_GEN (1 << 1)
18537 +#define AuHnJob_DIRENT (1 << 2)
18538 +#define AuHnJob_ISDIR (1 << 3)
18539 +#define AuHnJob_TRYXINO0 (1 << 4)
18540 +#define AuHnJob_MNTPNT (1 << 5)
18541 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18542 +#define au_fset_hnjob(flags, name) \
18543 + do { (flags) |= AuHnJob_##name; } while (0)
18544 +#define au_fclr_hnjob(flags, name) \
18545 + do { (flags) &= ~AuHnJob_##name; } while (0)
18553 +struct au_hnotify_args {
18554 + struct inode *h_dir, *dir, *h_child_inode;
18556 + unsigned int flags[AuHnLast];
18557 + unsigned int h_child_nlen;
18558 + char h_child_name[];
18561 +struct hn_job_args {
18562 + unsigned int flags;
18563 + struct inode *inode, *h_inode, *dir, *h_dir;
18564 + struct dentry *dentry;
18569 +static int hn_job(struct hn_job_args *a)
18571 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18575 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18576 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18578 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18581 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18582 + if (!a->h_inode->i_nlink
18583 + && !(a->h_inode->i_state & I_LINKABLE))
18584 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18585 + inode_unlock_shared(a->h_inode);
18588 + /* make the generation obsolete */
18589 + if (au_ftest_hnjob(a->flags, GEN)) {
18592 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18594 + if (e && a->dentry)
18595 + hn_gen_by_name(a->dentry, isdir);
18596 + /* ignore this error */
18599 + /* make dir entries obsolete */
18600 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18601 + struct au_vdir *vdir;
18603 + vdir = au_ivdir(a->inode);
18605 + vdir->vd_jiffy = 0;
18606 + /* IMustLock(a->inode); */
18607 + /* inode_inc_iversion(a->inode); */
18610 + /* can do nothing but warn */
18611 + if (au_ftest_hnjob(a->flags, MNTPNT)
18613 + && d_mountpoint(a->dentry))
18614 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18619 +/* ---------------------------------------------------------------------- */
18621 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18622 + struct inode *dir)
18624 + struct dentry *dentry, *d, *parent;
18625 + struct qstr *dname;
18627 + parent = d_find_any_alias(dir);
18632 + spin_lock(&parent->d_lock);
18633 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18634 + /* AuDbg("%pd\n", d); */
18635 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18636 + dname = &d->d_name;
18637 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18638 + goto cont_unlock;
18642 + goto cont_unlock;
18643 + if (au_dcount(d) > 0) {
18644 + dentry = dget_dlock(d);
18645 + spin_unlock(&d->d_lock);
18650 + spin_unlock(&d->d_lock);
18652 + spin_unlock(&parent->d_lock);
18656 + di_write_lock_child(dentry);
18661 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18662 + aufs_bindex_t bindex, ino_t h_ino)
18664 + struct inode *inode;
18669 + err = au_xino_read(sb, bindex, h_ino, &ino);
18671 + inode = ilookup(sb, ino);
18675 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18676 + pr_warn("wrong root branch\n");
18682 + ii_write_lock_child(inode);
18688 +static void au_hn_bh(void *_args)
18690 + struct au_hnotify_args *a = _args;
18691 + struct super_block *sb;
18692 + aufs_bindex_t bindex, bbot, bfound;
18693 + unsigned char xino, try_iput;
18695 + struct inode *inode;
18697 + struct hn_job_args args;
18698 + struct dentry *dentry;
18699 + struct au_sbinfo *sbinfo;
18701 + AuDebugOn(!_args);
18702 + AuDebugOn(!a->h_dir);
18703 + AuDebugOn(!a->dir);
18704 + AuDebugOn(!a->mask);
18705 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18706 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18707 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18712 + * do not lock a->dir->i_mutex here
18713 + * because of d_revalidate() may cause a deadlock.
18715 + sb = a->dir->i_sb;
18717 + sbinfo = au_sbi(sb);
18718 + AuDebugOn(!sbinfo);
18719 + si_write_lock(sb, AuLock_NOPLMW);
18721 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18722 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18723 + case FS_MOVED_FROM:
18724 + case FS_MOVED_TO:
18725 + AuWarn1("DIRREN with UDBA may not work correctly "
18726 + "for the direct rename(2)\n");
18729 + ii_read_lock_parent(a->dir);
18731 + bbot = au_ibbot(a->dir);
18732 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18733 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18737 + ii_read_unlock(a->dir);
18738 + if (unlikely(bfound < 0))
18741 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18743 + if (a->h_child_inode)
18744 + h_ino = a->h_child_inode->i_ino;
18746 + if (a->h_child_nlen
18747 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18748 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18749 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18752 + if (dentry && d_really_is_positive(dentry))
18753 + inode = d_inode(dentry);
18754 + if (xino && !inode && h_ino
18755 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18756 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18757 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18758 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18762 + args.flags = a->flags[AuHn_CHILD];
18763 + args.dentry = dentry;
18764 + args.inode = inode;
18765 + args.h_inode = a->h_child_inode;
18766 + args.dir = a->dir;
18767 + args.h_dir = a->h_dir;
18768 + args.h_name = a->h_child_name;
18769 + args.h_nlen = a->h_child_nlen;
18770 + err = hn_job(&args);
18772 + if (au_di(dentry))
18773 + di_write_unlock(dentry);
18776 + if (inode && try_iput) {
18777 + ii_write_unlock(inode);
18781 + ii_write_lock_parent(a->dir);
18782 + args.flags = a->flags[AuHn_PARENT];
18783 + args.dentry = NULL;
18784 + args.inode = a->dir;
18785 + args.h_inode = a->h_dir;
18787 + args.h_dir = NULL;
18788 + args.h_name = NULL;
18790 + err = hn_job(&args);
18791 + ii_write_unlock(a->dir);
18794 + iput(a->h_child_inode);
18797 + si_write_unlock(sb);
18798 + au_nwt_done(&sbinfo->si_nowait);
18802 +/* ---------------------------------------------------------------------- */
18804 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18805 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18808 + unsigned int flags[AuHnLast], f;
18809 + unsigned char isdir, isroot, wh;
18810 + struct inode *dir;
18811 + struct au_hnotify_args *args;
18812 + char *p, *h_child_name;
18815 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18816 + dir = igrab(hnotify->hn_aufs_inode);
18820 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18822 + h_child_name = (void *)h_child_qstr->name;
18823 + len = h_child_qstr->len;
18824 + if (h_child_name) {
18825 + if (len > AUFS_WH_PFX_LEN
18826 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18827 + h_child_name += AUFS_WH_PFX_LEN;
18828 + len -= AUFS_WH_PFX_LEN;
18834 + if (h_child_inode)
18835 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18836 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18837 + flags[AuHn_CHILD] = 0;
18839 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18840 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18841 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18842 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18843 + case FS_MOVED_FROM:
18844 + case FS_MOVED_TO:
18845 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18846 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18849 + AuDebugOn(!h_child_name);
18854 + * aufs never be able to get this child inode.
18855 + * revalidation should be in d_revalidate()
18856 + * by checking i_nlink, i_generation or d_unhashed().
18858 + AuDebugOn(!h_child_name);
18859 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18860 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18868 + h_child_inode = NULL;
18871 + /* iput() and kfree() will be called in au_hnotify() */
18872 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18873 + if (unlikely(!args)) {
18874 + AuErr1("no memory\n");
18878 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18879 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18880 + args->mask = mask;
18882 + args->h_dir = igrab(h_dir);
18883 + if (h_child_inode)
18884 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18885 + args->h_child_inode = h_child_inode;
18886 + args->h_child_nlen = len;
18888 + p = (void *)args;
18889 + p += sizeof(*args);
18890 + memcpy(p, h_child_name, len);
18894 + /* NFS fires the event for silly-renamed one from kworker */
18896 + if (!dir->i_nlink
18897 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18899 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18900 + if (unlikely(err)) {
18901 + pr_err("wkq %d\n", err);
18902 + iput(args->h_child_inode);
18903 + iput(args->h_dir);
18905 + au_kfree_rcu(args);
18912 +/* ---------------------------------------------------------------------- */
18914 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18918 + AuDebugOn(!(udba & AuOptMask_UDBA));
18921 + if (au_hnotify_op.reset_br)
18922 + err = au_hnotify_op.reset_br(udba, br, perm);
18927 +int au_hnotify_init_br(struct au_branch *br, int perm)
18932 + if (au_hnotify_op.init_br)
18933 + err = au_hnotify_op.init_br(br, perm);
18938 +void au_hnotify_fin_br(struct au_branch *br)
18940 + if (au_hnotify_op.fin_br)
18941 + au_hnotify_op.fin_br(br);
18944 +static void au_hn_destroy_cache(void)
18946 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18947 + au_cache[AuCache_HNOTIFY] = NULL;
18950 +int __init au_hnotify_init(void)
18955 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18956 + if (au_cache[AuCache_HNOTIFY]) {
18958 + if (au_hnotify_op.init)
18959 + err = au_hnotify_op.init();
18960 + if (unlikely(err))
18961 + au_hn_destroy_cache();
18967 +void au_hnotify_fin(void)
18969 + if (au_hnotify_op.fin)
18970 + au_hnotify_op.fin();
18972 + /* cf. au_cache_fin() */
18973 + if (au_cache[AuCache_HNOTIFY])
18974 + au_hn_destroy_cache();
18976 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18977 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18978 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
18980 +// SPDX-License-Identifier: GPL-2.0
18982 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18984 + * This program is free software; you can redistribute it and/or modify
18985 + * it under the terms of the GNU General Public License as published by
18986 + * the Free Software Foundation; either version 2 of the License, or
18987 + * (at your option) any later version.
18989 + * This program is distributed in the hope that it will be useful,
18990 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18991 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18992 + * GNU General Public License for more details.
18994 + * You should have received a copy of the GNU General Public License
18995 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18999 + * inode private data
19004 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19006 + struct inode *h_inode;
19007 + struct au_hinode *hinode;
19009 + IiMustAnyLock(inode);
19011 + hinode = au_hinode(au_ii(inode), bindex);
19012 + h_inode = hinode->hi_inode;
19013 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19017 +/* todo: hard/soft set? */
19018 +void au_hiput(struct au_hinode *hinode)
19020 + au_hn_free(hinode);
19021 + dput(hinode->hi_whdentry);
19022 + iput(hinode->hi_inode);
19025 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19027 + unsigned int flags;
19028 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19031 + if (au_opt_test(mnt_flags, XINO))
19032 + au_fset_hi(flags, XINO);
19033 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19034 + au_fset_hi(flags, HNOTIFY);
19038 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19039 + struct inode *h_inode, unsigned int flags)
19041 + struct au_hinode *hinode;
19042 + struct inode *hi;
19043 + struct au_iinfo *iinfo = au_ii(inode);
19045 + IiMustWriteLock(inode);
19047 + hinode = au_hinode(iinfo, bindex);
19048 + hi = hinode->hi_inode;
19049 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19052 + au_hiput(hinode);
19053 + hinode->hi_inode = h_inode;
19056 + struct super_block *sb = inode->i_sb;
19057 + struct au_branch *br;
19059 + AuDebugOn(inode->i_mode
19060 + && (h_inode->i_mode & S_IFMT)
19061 + != (inode->i_mode & S_IFMT));
19062 + if (bindex == iinfo->ii_btop)
19063 + au_cpup_igen(inode, h_inode);
19064 + br = au_sbr(sb, bindex);
19065 + hinode->hi_id = br->br_id;
19066 + if (au_ftest_hi(flags, XINO)) {
19067 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19069 + if (unlikely(err))
19070 + AuIOErr1("failed au_xino_write() %d\n", err);
19073 + if (au_ftest_hi(flags, HNOTIFY)
19074 + && au_br_hnotifyable(br->br_perm)) {
19075 + err = au_hn_alloc(hinode, inode);
19076 + if (unlikely(err))
19077 + AuIOErr1("au_hn_alloc() %d\n", err);
19082 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19083 + struct dentry *h_wh)
19085 + struct au_hinode *hinode;
19087 + IiMustWriteLock(inode);
19089 + hinode = au_hinode(au_ii(inode), bindex);
19090 + AuDebugOn(hinode->hi_whdentry);
19091 + hinode->hi_whdentry = h_wh;
19094 +void au_update_iigen(struct inode *inode, int half)
19096 + struct au_iinfo *iinfo;
19097 + struct au_iigen *iigen;
19098 + unsigned int sigen;
19100 + sigen = au_sigen(inode->i_sb);
19101 + iinfo = au_ii(inode);
19102 + iigen = &iinfo->ii_generation;
19103 + spin_lock(&iigen->ig_spin);
19104 + iigen->ig_generation = sigen;
19106 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19108 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19109 + spin_unlock(&iigen->ig_spin);
19112 +/* it may be called at remount time, too */
19113 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19115 + struct au_iinfo *iinfo;
19116 + aufs_bindex_t bindex, bbot;
19118 + AuDebugOn(au_is_bad_inode(inode));
19119 + IiMustWriteLock(inode);
19121 + iinfo = au_ii(inode);
19122 + if (do_put_zero && iinfo->ii_btop >= 0) {
19123 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19125 + struct inode *h_i;
19127 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19130 + && !(h_i->i_state & I_LINKABLE))
19131 + au_set_h_iptr(inode, bindex, NULL, 0);
19135 + iinfo->ii_btop = -1;
19136 + iinfo->ii_bbot = -1;
19137 + bbot = au_sbbot(inode->i_sb);
19138 + for (bindex = 0; bindex <= bbot; bindex++)
19139 + if (au_hinode(iinfo, bindex)->hi_inode) {
19140 + iinfo->ii_btop = bindex;
19143 + if (iinfo->ii_btop >= 0)
19144 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19145 + if (au_hinode(iinfo, bindex)->hi_inode) {
19146 + iinfo->ii_bbot = bindex;
19149 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19152 +/* ---------------------------------------------------------------------- */
19154 +void au_icntnr_init_once(void *_c)
19156 + struct au_icntnr *c = _c;
19157 + struct au_iinfo *iinfo = &c->iinfo;
19159 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19160 + au_rw_init(&iinfo->ii_rwsem);
19161 + inode_init_once(&c->vfs_inode);
19164 +void au_hinode_init(struct au_hinode *hinode)
19166 + hinode->hi_inode = NULL;
19167 + hinode->hi_id = -1;
19168 + au_hn_init(hinode);
19169 + hinode->hi_whdentry = NULL;
19172 +int au_iinfo_init(struct inode *inode)
19174 + struct au_iinfo *iinfo;
19175 + struct super_block *sb;
19176 + struct au_hinode *hi;
19179 + sb = inode->i_sb;
19180 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19181 + nbr = au_sbbot(sb) + 1;
19182 + if (unlikely(nbr <= 0))
19184 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19186 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19188 + iinfo->ii_hinode = hi;
19189 + for (i = 0; i < nbr; i++, hi++)
19190 + au_hinode_init(hi);
19192 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19193 + iinfo->ii_btop = -1;
19194 + iinfo->ii_bbot = -1;
19195 + iinfo->ii_vdir = NULL;
19201 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19204 + struct au_hinode *hip;
19206 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19209 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19212 + iinfo->ii_hinode = hip;
19213 + i = iinfo->ii_bbot + 1;
19215 + for (; i < nbr; i++, hip++)
19216 + au_hinode_init(hip);
19223 +void au_iinfo_fin(struct inode *inode)
19225 + struct au_iinfo *iinfo;
19226 + struct au_hinode *hi;
19227 + struct super_block *sb;
19228 + aufs_bindex_t bindex, bbot;
19229 + const unsigned char unlinked = !inode->i_nlink;
19231 + AuDebugOn(au_is_bad_inode(inode));
19233 + sb = inode->i_sb;
19234 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19235 + if (si_pid_test(sb))
19236 + au_xino_delete_inode(inode, unlinked);
19239 + * it is safe to hide the dependency between sbinfo and
19243 + si_noflush_read_lock(sb);
19244 + au_xino_delete_inode(inode, unlinked);
19245 + si_read_unlock(sb);
19249 + iinfo = au_ii(inode);
19250 + if (iinfo->ii_vdir)
19251 + au_vdir_free(iinfo->ii_vdir);
19253 + bindex = iinfo->ii_btop;
19254 + if (bindex >= 0) {
19255 + hi = au_hinode(iinfo, bindex);
19256 + bbot = iinfo->ii_bbot;
19257 + while (bindex++ <= bbot) {
19258 + if (hi->hi_inode)
19263 + au_kfree_rcu(iinfo->ii_hinode);
19264 + AuRwDestroy(&iinfo->ii_rwsem);
19266 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19267 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19268 +++ linux/fs/aufs/inode.c 2023-09-03 02:21:58.863304341 +0200
19270 +// SPDX-License-Identifier: GPL-2.0
19272 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19274 + * This program is free software; you can redistribute it and/or modify
19275 + * it under the terms of the GNU General Public License as published by
19276 + * the Free Software Foundation; either version 2 of the License, or
19277 + * (at your option) any later version.
19279 + * This program is distributed in the hope that it will be useful,
19280 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19281 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19282 + * GNU General Public License for more details.
19284 + * You should have received a copy of the GNU General Public License
19285 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19289 + * inode functions
19292 +#include <linux/iversion.h>
19295 +struct inode *au_igrab(struct inode *inode)
19298 + AuDebugOn(!atomic_read(&inode->i_count));
19304 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19306 + au_cpup_attr_all(inode, /*force*/0);
19307 + au_update_iigen(inode, /*half*/1);
19309 + inode_inc_iversion(inode);
19312 +static int au_ii_refresh(struct inode *inode, int *update)
19316 + aufs_bindex_t bindex, new_bindex;
19317 + struct super_block *sb;
19318 + struct au_iinfo *iinfo;
19319 + struct au_hinode *p, *q, tmp;
19321 + AuDebugOn(au_is_bad_inode(inode));
19322 + IiMustWriteLock(inode);
19325 + sb = inode->i_sb;
19326 + nbr = au_sbbot(sb) + 1;
19327 + type = inode->i_mode & S_IFMT;
19328 + iinfo = au_ii(inode);
19329 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19330 + if (unlikely(err))
19333 + AuDebugOn(iinfo->ii_btop < 0);
19334 + p = au_hinode(iinfo, iinfo->ii_btop);
19335 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19337 + if (!p->hi_inode)
19340 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19341 + new_bindex = au_br_index(sb, p->hi_id);
19342 + if (new_bindex == bindex)
19345 + if (new_bindex < 0) {
19348 + p->hi_inode = NULL;
19352 + if (new_bindex < iinfo->ii_btop)
19353 + iinfo->ii_btop = new_bindex;
19354 + if (iinfo->ii_bbot < new_bindex)
19355 + iinfo->ii_bbot = new_bindex;
19356 + /* swap two lower inode, and loop again */
19357 + q = au_hinode(iinfo, new_bindex);
19361 + if (tmp.hi_inode) {
19366 + au_update_ibrange(inode, /*do_put_zero*/0);
19367 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19368 + e = au_dy_irefresh(inode);
19369 + if (unlikely(e && !err))
19377 +void au_refresh_iop(struct inode *inode, int force_getattr)
19380 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19381 + const struct inode_operations *iop
19382 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19384 + if (inode->i_op == iop)
19387 + switch (inode->i_mode & S_IFMT) {
19389 + type = AuIop_DIR;
19392 + type = AuIop_SYMLINK;
19395 + type = AuIop_OTHER;
19399 + inode->i_op = iop + type;
19400 + /* unnecessary smp_wmb() */
19403 +int au_refresh_hinode_self(struct inode *inode)
19407 + err = au_ii_refresh(inode, &update);
19409 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19415 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19417 + int err, e, update;
19418 + unsigned int flags;
19420 + aufs_bindex_t bindex, bbot;
19421 + unsigned char isdir;
19422 + struct au_hinode *p;
19423 + struct au_iinfo *iinfo;
19425 + err = au_ii_refresh(inode, &update);
19426 + if (unlikely(err))
19430 + iinfo = au_ii(inode);
19431 + p = au_hinode(iinfo, iinfo->ii_btop);
19432 + mode = (inode->i_mode & S_IFMT);
19433 + isdir = S_ISDIR(mode);
19434 + flags = au_hi_flags(inode, isdir);
19435 + bbot = au_dbbot(dentry);
19436 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19437 + struct inode *h_i, *h_inode;
19438 + struct dentry *h_d;
19440 + h_d = au_h_dptr(dentry, bindex);
19441 + if (!h_d || d_is_negative(h_d))
19444 + h_inode = d_inode(h_d);
19445 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19446 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19447 + h_i = au_h_iptr(inode, bindex);
19449 + if (h_i == h_inode)
19455 + if (bindex < iinfo->ii_btop)
19456 + iinfo->ii_btop = bindex;
19457 + if (iinfo->ii_bbot < bindex)
19458 + iinfo->ii_bbot = bindex;
19459 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19462 + au_update_ibrange(inode, /*do_put_zero*/0);
19463 + e = au_dy_irefresh(inode);
19464 + if (unlikely(e && !err))
19467 + au_refresh_hinode_attr(inode, update && isdir);
19474 +static int set_inode(struct inode *inode, struct dentry *dentry)
19477 + unsigned int flags;
19479 + aufs_bindex_t bindex, btop, btail;
19480 + unsigned char isdir;
19481 + struct dentry *h_dentry;
19482 + struct inode *h_inode;
19483 + struct au_iinfo *iinfo;
19484 + const struct inode_operations *iop;
19486 + IiMustWriteLock(inode);
19490 + iop = au_sbi(inode->i_sb)->si_iop_array;
19491 + btop = au_dbtop(dentry);
19492 + h_dentry = au_h_dptr(dentry, btop);
19493 + h_inode = d_inode(h_dentry);
19494 + mode = h_inode->i_mode;
19495 + switch (mode & S_IFMT) {
19497 + btail = au_dbtail(dentry);
19498 + inode->i_op = iop + AuIop_OTHER;
19499 + inode->i_fop = &aufs_file_fop;
19500 + err = au_dy_iaop(inode, btop, h_inode);
19501 + if (unlikely(err))
19506 + btail = au_dbtaildir(dentry);
19507 + inode->i_op = iop + AuIop_DIR;
19508 + inode->i_fop = &aufs_dir_fop;
19511 + btail = au_dbtail(dentry);
19512 + inode->i_op = iop + AuIop_SYMLINK;
19518 + btail = au_dbtail(dentry);
19519 + inode->i_op = iop + AuIop_OTHER;
19520 + init_special_inode(inode, mode, h_inode->i_rdev);
19523 + AuIOErr("Unknown file type 0%o\n", mode);
19528 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19529 + flags = au_hi_flags(inode, isdir);
19530 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19531 + && au_ftest_hi(flags, HNOTIFY)
19532 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19533 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19534 + au_fclr_hi(flags, HNOTIFY);
19535 + iinfo = au_ii(inode);
19536 + iinfo->ii_btop = btop;
19537 + iinfo->ii_bbot = btail;
19538 + for (bindex = btop; bindex <= btail; bindex++) {
19539 + h_dentry = au_h_dptr(dentry, bindex);
19541 + au_set_h_iptr(inode, bindex,
19542 + au_igrab(d_inode(h_dentry)), flags);
19544 + au_cpup_attr_all(inode, /*force*/1);
19546 + * to force calling aufs_get_inode_acl() every time,
19547 + * do not call cache_no_acl() for aufs inode.
19555 + * successful returns with iinfo write_locked
19557 + * zero: success, matched
19558 + * plus: no error, but unmatched
19560 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19563 + unsigned int gen, igflags;
19564 + aufs_bindex_t bindex, bbot;
19565 + struct inode *h_inode, *h_dinode;
19566 + struct dentry *h_dentry;
19569 + * before this function, if aufs got any iinfo lock, it must be only
19570 + * one, the parent dir.
19571 + * it can happen by UDBA and the obsoleted inode number.
19574 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19578 + ii_write_lock_new_child(inode);
19579 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19580 + h_dinode = d_inode(h_dentry);
19581 + bbot = au_ibbot(inode);
19582 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19583 + h_inode = au_h_iptr(inode, bindex);
19584 + if (!h_inode || h_inode != h_dinode)
19588 + gen = au_iigen(inode, &igflags);
19589 + if (gen == au_digen(dentry)
19590 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19593 + /* fully refresh inode using dentry */
19594 + err = au_refresh_hinode(inode, dentry);
19596 + au_update_iigen(inode, /*half*/0);
19600 + if (unlikely(err))
19601 + ii_write_unlock(inode);
19606 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19607 + unsigned int d_type, ino_t *ino)
19610 + const int isnondir = d_type != DT_DIR;
19612 + /* prevent hardlinked inode number from race condition */
19614 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19615 + if (unlikely(err))
19619 + err = au_xino_read(sb, bindex, h_ino, ino);
19620 + if (unlikely(err))
19621 + goto out_xinondir;
19625 + *ino = au_xino_new_ino(sb);
19626 + if (unlikely(!*ino))
19627 + goto out_xinondir;
19628 + err = au_xino_write(sb, bindex, h_ino, *ino);
19629 + if (unlikely(err))
19630 + goto out_xinondir;
19634 + if (isnondir && idx >= 0)
19635 + au_xinondir_leave(sb, bindex, h_ino, idx);
19640 +/* successful returns with iinfo write_locked */
19641 +/* todo: return with unlocked? */
19642 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19644 + struct inode *inode, *h_inode;
19645 + struct dentry *h_dentry;
19646 + struct super_block *sb;
19647 + ino_t h_ino, ino;
19648 + int err, idx, hlinked;
19649 + aufs_bindex_t btop;
19651 + sb = dentry->d_sb;
19652 + btop = au_dbtop(dentry);
19653 + h_dentry = au_h_dptr(dentry, btop);
19654 + h_inode = d_inode(h_dentry);
19655 + h_ino = h_inode->i_ino;
19656 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19660 + * stop 'race'-ing between hardlinks under different
19664 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19665 + inode = ERR_PTR(err);
19666 + if (unlikely(err))
19670 + err = au_xino_read(sb, btop, h_ino, &ino);
19671 + inode = ERR_PTR(err);
19672 + if (unlikely(err))
19673 + goto out_xinondir;
19676 + ino = au_xino_new_ino(sb);
19677 + if (unlikely(!ino)) {
19678 + inode = ERR_PTR(-EIO);
19679 + goto out_xinondir;
19683 + AuDbg("i%lu\n", (unsigned long)ino);
19684 + inode = au_iget_locked(sb, ino);
19685 + err = PTR_ERR(inode);
19686 + if (IS_ERR(inode))
19687 + goto out_xinondir;
19689 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19690 + if (inode->i_state & I_NEW) {
19691 + ii_write_lock_new_child(inode);
19692 + err = set_inode(inode, dentry);
19694 + unlock_new_inode(inode);
19695 + goto out_xinondir; /* success */
19699 + * iget_failed() calls iput(), but we need to call
19700 + * ii_write_unlock() after iget_failed(). so dirty hack for
19703 + atomic_inc(&inode->i_count);
19704 + iget_failed(inode);
19705 + ii_write_unlock(inode);
19706 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19707 + /* ignore this error */
19709 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19711 + * horrible race condition between lookup, readdir and copyup
19712 + * (or something).
19714 + if (hlinked && idx >= 0)
19715 + au_xinondir_leave(sb, btop, h_ino, idx);
19716 + err = reval_inode(inode, dentry);
19717 + if (unlikely(err < 0)) {
19722 + goto out; /* success */
19723 + else if (hlinked && idx >= 0) {
19724 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19725 + if (unlikely(err)) {
19727 + inode = ERR_PTR(err);
19733 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19734 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19735 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19736 + btop, au_sbtype(h_dentry->d_sb), dentry,
19737 + (unsigned long)h_ino, (unsigned long)ino);
19739 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19742 + if (hlinked && idx >= 0)
19743 + au_xinondir_leave(sb, btop, h_ino, idx);
19749 + inode = ERR_PTR(err);
19751 + if (hlinked && idx >= 0)
19752 + au_xinondir_leave(sb, btop, h_ino, idx);
19757 +/* ---------------------------------------------------------------------- */
19759 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19760 + struct inode *inode)
19763 + struct inode *hi;
19765 + err = au_br_rdonly(au_sbr(sb, bindex));
19767 + /* pseudo-link after flushed may happen out of bounds */
19770 + && au_ibtop(inode) <= bindex
19771 + && bindex <= au_ibbot(inode)) {
19773 + * permission check is unnecessary since vfsub routine
19774 + * will be called later
19776 + hi = au_h_iptr(inode, bindex);
19778 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19784 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19787 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19789 + return inode_permission(h_idmap, h_inode, mask);
19792 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19795 + if (au_test_nfs(h_inode->i_sb)
19796 + && (mask & MAY_WRITE)
19797 + && S_ISDIR(h_inode->i_mode))
19798 + mask |= MAY_READ; /* force permission check */
19799 + return au_test_h_perm(h_idmap, h_inode, mask);
19801 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19802 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19803 +++ linux/fs/aufs/inode.h 2023-09-03 02:21:58.863304341 +0200
19805 +/* SPDX-License-Identifier: GPL-2.0 */
19807 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19809 + * This program is free software; you can redistribute it and/or modify
19810 + * it under the terms of the GNU General Public License as published by
19811 + * the Free Software Foundation; either version 2 of the License, or
19812 + * (at your option) any later version.
19814 + * This program is distributed in the hope that it will be useful,
19815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19817 + * GNU General Public License for more details.
19819 + * You should have received a copy of the GNU General Public License
19820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19824 + * inode operations
19827 +#ifndef __AUFS_INODE_H__
19828 +#define __AUFS_INODE_H__
19832 +#include <linux/fsnotify.h>
19833 +#include "rwsem.h"
19837 +struct au_hnotify {
19838 +#ifdef CONFIG_AUFS_HNOTIFY
19839 +#ifdef CONFIG_AUFS_HFSNOTIFY
19840 + /* never use fsnotify_add_vfsmount_mark() */
19841 + struct fsnotify_mark hn_mark;
19843 + struct inode *hn_aufs_inode; /* no get/put */
19844 + struct rcu_head rcu;
19846 +} ____cacheline_aligned_in_smp;
19848 +struct au_hinode {
19849 + struct inode *hi_inode;
19850 + aufs_bindex_t hi_id;
19851 +#ifdef CONFIG_AUFS_HNOTIFY
19852 + struct au_hnotify *hi_notify;
19855 + /* reference to the copied-up whiteout with get/put */
19856 + struct dentry *hi_whdentry;
19860 +#define AuIG_HALF_REFRESHED 1
19861 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19862 +#define au_ig_fset(flags, name) \
19863 + do { (flags) |= AuIG_##name; } while (0)
19864 +#define au_ig_fclr(flags, name) \
19865 + do { (flags) &= ~AuIG_##name; } while (0)
19868 + spinlock_t ig_spin;
19869 + __u32 ig_generation, ig_flags;
19874 + struct au_iigen ii_generation;
19875 + struct super_block *ii_hsb1; /* no get/put */
19877 + struct au_rwsem ii_rwsem;
19878 + aufs_bindex_t ii_btop, ii_bbot;
19880 + struct au_hinode *ii_hinode;
19881 + struct au_vdir *ii_vdir;
19884 +struct au_icntnr {
19885 + struct au_iinfo iinfo;
19886 + struct inode vfs_inode;
19887 + struct hlist_bl_node plink;
19888 + struct rcu_head rcu;
19889 +} ____cacheline_aligned_in_smp;
19891 +/* au_pin flags */
19892 +#define AuPin_DI_LOCKED 1
19893 +#define AuPin_MNT_WRITE (1 << 1)
19894 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19895 +#define au_fset_pin(flags, name) \
19896 + do { (flags) |= AuPin_##name; } while (0)
19897 +#define au_fclr_pin(flags, name) \
19898 + do { (flags) &= ~AuPin_##name; } while (0)
19902 + struct dentry *dentry;
19903 + unsigned int udba;
19904 + unsigned char lsc_di, lsc_hi, flags;
19905 + aufs_bindex_t bindex;
19908 + struct dentry *parent;
19909 + struct au_hinode *hdir;
19910 + struct vfsmount *h_mnt;
19912 + /* temporary unlock/relock for copyup */
19913 + struct dentry *h_dentry, *h_parent;
19914 + struct au_branch *br;
19915 + struct task_struct *task;
19918 +void au_pin_hdir_unlock(struct au_pin *p);
19919 +int au_pin_hdir_lock(struct au_pin *p);
19920 +int au_pin_hdir_relock(struct au_pin *p);
19921 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19922 +void au_pin_hdir_release(struct au_pin *p);
19924 +/* ---------------------------------------------------------------------- */
19926 +static inline struct au_iinfo *au_ii(struct inode *inode)
19928 + BUG_ON(is_bad_inode(inode));
19929 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19932 +/* ---------------------------------------------------------------------- */
19935 +struct inode *au_igrab(struct inode *inode);
19936 +void au_refresh_iop(struct inode *inode, int force_getattr);
19937 +int au_refresh_hinode_self(struct inode *inode);
19938 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19939 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19940 + unsigned int d_type, ino_t *ino);
19941 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19942 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19943 + struct inode *inode);
19944 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19946 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19949 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19950 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19952 +#ifdef CONFIG_AUFS_SHWH
19953 + return au_ino(sb, bindex, h_ino, d_type, ino);
19966 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19967 + aufs_iop_nogetattr[AuIop_Last];
19969 +/* au_wr_dir flags */
19970 +#define AuWrDir_ADD_ENTRY 1
19971 +#define AuWrDir_ISDIR (1 << 1)
19972 +#define AuWrDir_TMPFILE (1 << 2)
19973 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19974 +#define au_fset_wrdir(flags, name) \
19975 + do { (flags) |= AuWrDir_##name; } while (0)
19976 +#define au_fclr_wrdir(flags, name) \
19977 + do { (flags) &= ~AuWrDir_##name; } while (0)
19979 +struct au_wr_dir_args {
19980 + aufs_bindex_t force_btgt;
19981 + unsigned char flags;
19983 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19984 + struct au_wr_dir_args *args);
19986 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19987 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19988 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19989 + unsigned int udba, unsigned char flags);
19990 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19991 + unsigned int udba, unsigned char flags) __must_check;
19992 +int au_do_pin(struct au_pin *pin) __must_check;
19993 +void au_unpin(struct au_pin *pin);
19994 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19996 +#define AuIcpup_DID_CPUP 1
19997 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
19998 +#define au_fset_icpup(flags, name) \
19999 + do { (flags) |= AuIcpup_##name; } while (0)
20000 +#define au_fclr_icpup(flags, name) \
20001 + do { (flags) &= ~AuIcpup_##name; } while (0)
20003 +struct au_icpup_args {
20004 + unsigned char flags;
20005 + unsigned char pin_flags;
20006 + aufs_bindex_t btgt;
20007 + unsigned int udba;
20008 + struct au_pin pin;
20009 + struct path h_path;
20010 + struct inode *h_inode;
20013 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20014 + struct au_icpup_args *a);
20016 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20017 + struct path *h_path, int locked);
20020 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20021 + struct dentry *h_parent, int isdir);
20022 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
20023 + struct dentry *dentry, umode_t mode, dev_t dev);
20024 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
20025 + struct dentry *dentry, const char *symname);
20026 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
20027 + struct dentry *dentry, umode_t mode, bool want_excl);
20028 +struct vfsub_aopen_args;
20029 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20030 + struct vfsub_aopen_args *args);
20031 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
20032 + struct file *file, umode_t mode);
20033 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20034 + struct dentry *dentry);
20035 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
20036 + struct dentry *dentry, umode_t mode);
20039 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20040 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20041 + struct dentry *h_parent, int isdir);
20042 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20043 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20046 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20047 +int aufs_rename(struct mnt_idmap *idmap,
20048 + struct inode *_src_dir, struct dentry *_src_dentry,
20049 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20050 + unsigned int _flags);
20053 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20054 +void au_hiput(struct au_hinode *hinode);
20055 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20056 + struct dentry *h_wh);
20057 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20059 +/* hinode flags */
20060 +#define AuHi_XINO 1
20061 +#define AuHi_HNOTIFY (1 << 1)
20062 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20063 +#define au_fset_hi(flags, name) \
20064 + do { (flags) |= AuHi_##name; } while (0)
20065 +#define au_fclr_hi(flags, name) \
20066 + do { (flags) &= ~AuHi_##name; } while (0)
20068 +#ifndef CONFIG_AUFS_HNOTIFY
20069 +#undef AuHi_HNOTIFY
20070 +#define AuHi_HNOTIFY 0
20073 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20074 + struct inode *h_inode, unsigned int flags);
20076 +void au_update_iigen(struct inode *inode, int half);
20077 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20079 +void au_icntnr_init_once(void *_c);
20080 +void au_hinode_init(struct au_hinode *hinode);
20081 +int au_iinfo_init(struct inode *inode);
20082 +void au_iinfo_fin(struct inode *inode);
20083 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20085 +#ifdef CONFIG_PROC_FS
20087 +int au_plink_maint(struct super_block *sb, int flags);
20089 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20090 +int au_plink_maint_enter(struct super_block *sb);
20091 +#ifdef CONFIG_AUFS_DEBUG
20092 +void au_plink_list(struct super_block *sb);
20094 +AuStubVoid(au_plink_list, struct super_block *sb)
20096 +int au_plink_test(struct inode *inode);
20097 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20098 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20099 + struct dentry *h_dentry);
20100 +void au_plink_put(struct super_block *sb, int verbose);
20101 +void au_plink_clean(struct super_block *sb, int verbose);
20102 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20104 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20105 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20106 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20107 +AuStubVoid(au_plink_list, struct super_block *sb);
20108 +AuStubInt0(au_plink_test, struct inode *inode);
20109 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20110 + struct inode *inode, aufs_bindex_t bindex);
20111 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20112 + struct dentry *h_dentry);
20113 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20114 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20115 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20116 +#endif /* CONFIG_PROC_FS */
20118 +#ifdef CONFIG_AUFS_XATTR
20120 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20121 + unsigned int verbose);
20122 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20123 +void au_xattr_init(struct super_block *sb);
20125 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20126 + int ignore_flags, unsigned int verbose);
20127 +AuStubVoid(au_xattr_init, struct super_block *sb);
20130 +#ifdef CONFIG_FS_POSIX_ACL
20131 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu);
20132 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
20133 + struct dentry *dentry, int type);
20134 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
20135 + struct posix_acl *acl, int type);
20138 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20144 +struct au_sxattr {
20148 + const char *name;
20149 + const void *value;
20154 + struct posix_acl *acl;
20159 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20160 + struct au_sxattr *arg);
20163 +/* ---------------------------------------------------------------------- */
20165 +/* lock subclass for iinfo */
20167 + AuLsc_II_CHILD, /* child first */
20168 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20169 + AuLsc_II_CHILD3, /* copyup dirs */
20170 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20171 + AuLsc_II_PARENT2,
20172 + AuLsc_II_PARENT3, /* copyup dirs */
20173 + AuLsc_II_NEW_CHILD
20177 + * ii_read_lock_child, ii_write_lock_child,
20178 + * ii_read_lock_child2, ii_write_lock_child2,
20179 + * ii_read_lock_child3, ii_write_lock_child3,
20180 + * ii_read_lock_parent, ii_write_lock_parent,
20181 + * ii_read_lock_parent2, ii_write_lock_parent2,
20182 + * ii_read_lock_parent3, ii_write_lock_parent3,
20183 + * ii_read_lock_new_child, ii_write_lock_new_child,
20185 +#define AuReadLockFunc(name, lsc) \
20186 +static inline void ii_read_lock_##name(struct inode *i) \
20188 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20191 +#define AuWriteLockFunc(name, lsc) \
20192 +static inline void ii_write_lock_##name(struct inode *i) \
20194 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20197 +#define AuRWLockFuncs(name, lsc) \
20198 + AuReadLockFunc(name, lsc) \
20199 + AuWriteLockFunc(name, lsc)
20201 +AuRWLockFuncs(child, CHILD);
20202 +AuRWLockFuncs(child2, CHILD2);
20203 +AuRWLockFuncs(child3, CHILD3);
20204 +AuRWLockFuncs(parent, PARENT);
20205 +AuRWLockFuncs(parent2, PARENT2);
20206 +AuRWLockFuncs(parent3, PARENT3);
20207 +AuRWLockFuncs(new_child, NEW_CHILD);
20209 +#undef AuReadLockFunc
20210 +#undef AuWriteLockFunc
20211 +#undef AuRWLockFuncs
20213 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20214 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20215 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20217 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20218 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20219 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20221 +/* ---------------------------------------------------------------------- */
20223 +static inline void au_icntnr_init(struct au_icntnr *c)
20225 +#ifdef CONFIG_AUFS_DEBUG
20226 + c->vfs_inode.i_mode = 0;
20230 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20232 + unsigned int gen;
20233 + struct au_iinfo *iinfo;
20234 + struct au_iigen *iigen;
20236 + iinfo = au_ii(inode);
20237 + iigen = &iinfo->ii_generation;
20238 + spin_lock(&iigen->ig_spin);
20240 + *igflags = iigen->ig_flags;
20241 + gen = iigen->ig_generation;
20242 + spin_unlock(&iigen->ig_spin);
20247 +/* tiny test for inode number */
20248 +/* tmpfs generation is too rough */
20249 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20251 + struct au_iinfo *iinfo;
20253 + iinfo = au_ii(inode);
20254 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20255 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20256 + && iinfo->ii_higen == h_inode->i_generation);
20259 +static inline void au_iigen_dec(struct inode *inode)
20261 + struct au_iinfo *iinfo;
20262 + struct au_iigen *iigen;
20264 + iinfo = au_ii(inode);
20265 + iigen = &iinfo->ii_generation;
20266 + spin_lock(&iigen->ig_spin);
20267 + iigen->ig_generation--;
20268 + spin_unlock(&iigen->ig_spin);
20271 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20276 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20282 +/* ---------------------------------------------------------------------- */
20284 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20285 + aufs_bindex_t bindex)
20287 + return iinfo->ii_hinode + bindex;
20290 +static inline int au_is_bad_inode(struct inode *inode)
20292 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20295 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20296 + aufs_bindex_t bindex)
20298 + IiMustAnyLock(inode);
20299 + return au_hinode(au_ii(inode), bindex)->hi_id;
20302 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20304 + IiMustAnyLock(inode);
20305 + return au_ii(inode)->ii_btop;
20308 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20310 + IiMustAnyLock(inode);
20311 + return au_ii(inode)->ii_bbot;
20314 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20316 + IiMustAnyLock(inode);
20317 + return au_ii(inode)->ii_vdir;
20320 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20322 + IiMustAnyLock(inode);
20323 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20326 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20328 + IiMustWriteLock(inode);
20329 + au_ii(inode)->ii_btop = bindex;
20332 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20334 + IiMustWriteLock(inode);
20335 + au_ii(inode)->ii_bbot = bindex;
20338 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20340 + IiMustWriteLock(inode);
20341 + au_ii(inode)->ii_vdir = vdir;
20344 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20346 + IiMustAnyLock(inode);
20347 + return au_hinode(au_ii(inode), bindex);
20350 +/* ---------------------------------------------------------------------- */
20352 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20355 + return pin->parent;
20359 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20361 + if (pin && pin->hdir)
20362 + return pin->hdir->hi_inode;
20366 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20369 + return pin->hdir;
20373 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20376 + pin->dentry = dentry;
20379 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20380 + unsigned char lflag)
20384 + au_fset_pin(pin->flags, DI_LOCKED);
20386 + au_fclr_pin(pin->flags, DI_LOCKED);
20390 +#if 0 /* reserved */
20391 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20394 + dput(pin->parent);
20395 + pin->parent = dget(parent);
20400 +/* ---------------------------------------------------------------------- */
20403 +#ifdef CONFIG_AUFS_HNOTIFY
20404 +struct au_hnotify_op {
20405 + void (*ctl)(struct au_hinode *hinode, int do_set);
20406 + int (*alloc)(struct au_hinode *hinode);
20409 + * if it returns true, the caller should free hinode->hi_notify,
20410 + * otherwise ->free() frees it.
20412 + int (*free)(struct au_hinode *hinode,
20413 + struct au_hnotify *hn) __must_check;
20415 + void (*fin)(void);
20416 + int (*init)(void);
20418 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20419 + void (*fin_br)(struct au_branch *br);
20420 + int (*init_br)(struct au_branch *br, int perm);
20424 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20425 +void au_hn_free(struct au_hinode *hinode);
20426 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20427 +void au_hn_reset(struct inode *inode, unsigned int flags);
20428 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20429 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20430 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20431 +int au_hnotify_init_br(struct au_branch *br, int perm);
20432 +void au_hnotify_fin_br(struct au_branch *br);
20433 +int __init au_hnotify_init(void);
20434 +void au_hnotify_fin(void);
20437 +extern const struct au_hnotify_op au_hnotify_op;
20440 +void au_hn_init(struct au_hinode *hinode)
20442 + hinode->hi_notify = NULL;
20445 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20447 + return hinode->hi_notify;
20451 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20452 + struct au_hinode *hinode __maybe_unused,
20453 + struct inode *inode __maybe_unused)
20454 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20455 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20456 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20457 + int do_set __maybe_unused)
20458 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20459 + unsigned int flags __maybe_unused)
20460 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20461 + struct au_branch *br __maybe_unused,
20462 + int perm __maybe_unused)
20463 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20464 + int perm __maybe_unused)
20465 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20466 +AuStubInt0(__init au_hnotify_init, void)
20467 +AuStubVoid(au_hnotify_fin, void)
20468 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20469 +#endif /* CONFIG_AUFS_HNOTIFY */
20471 +static inline void au_hn_suspend(struct au_hinode *hdir)
20473 + au_hn_ctl(hdir, /*do_set*/0);
20476 +static inline void au_hn_resume(struct au_hinode *hdir)
20478 + au_hn_ctl(hdir, /*do_set*/1);
20481 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20483 + inode_lock(hdir->hi_inode);
20484 + au_hn_suspend(hdir);
20487 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20488 + unsigned int sc __maybe_unused)
20490 + inode_lock_nested(hdir->hi_inode, sc);
20491 + au_hn_suspend(hdir);
20494 +#if 0 /* unused */
20495 +#include "vfsub.h"
20496 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20499 + inode_lock_shared_nested(hdir->hi_inode, sc);
20500 + au_hn_suspend(hdir);
20504 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20506 + au_hn_resume(hdir);
20507 + inode_unlock(hdir->hi_inode);
20510 +#endif /* __KERNEL__ */
20511 +#endif /* __AUFS_INODE_H__ */
20512 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20513 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20514 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20516 +// SPDX-License-Identifier: GPL-2.0
20518 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20520 + * This program is free software; you can redistribute it and/or modify
20521 + * it under the terms of the GNU General Public License as published by
20522 + * the Free Software Foundation; either version 2 of the License, or
20523 + * (at your option) any later version.
20525 + * This program is distributed in the hope that it will be useful,
20526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20528 + * GNU General Public License for more details.
20530 + * You should have received a copy of the GNU General Public License
20531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20536 + * plink-management and readdir in userspace.
20537 + * assist the pathconf(3) wrapper library.
20539 + * File-based Hierarchical Storage Management.
20542 +#include <linux/compat.h>
20543 +#include <linux/file.h>
20546 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20549 + aufs_bindex_t wbi, bindex, bbot;
20550 + struct file *h_file;
20551 + struct super_block *sb;
20552 + struct dentry *root;
20553 + struct au_branch *br;
20554 + struct aufs_wbr_fd wbrfd = {
20555 + .oflags = au_dir_roflags,
20558 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20559 + | O_NOATIME | O_CLOEXEC;
20561 + AuDebugOn(wbrfd.oflags & ~valid);
20564 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20565 + if (unlikely(err)) {
20571 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20572 + wbrfd.oflags |= au_dir_roflags;
20573 + AuDbg("0%o\n", wbrfd.oflags);
20574 + if (unlikely(wbrfd.oflags & ~valid))
20578 + fd = get_unused_fd_flags(0);
20580 + if (unlikely(fd < 0))
20583 + h_file = ERR_PTR(-EINVAL);
20586 + sb = path->dentry->d_sb;
20587 + root = sb->s_root;
20588 + aufs_read_lock(root, AuLock_IR);
20589 + bbot = au_sbbot(sb);
20590 + if (wbrfd.brid >= 0) {
20591 + wbi = au_br_index(sb, wbrfd.brid);
20592 + if (unlikely(wbi < 0 || wbi > bbot))
20596 + h_file = ERR_PTR(-ENOENT);
20597 + br = au_sbr(sb, wbi);
20598 + if (!au_br_writable(br->br_perm)) {
20602 + bindex = wbi + 1;
20604 + for (; bindex <= bbot; bindex++) {
20605 + br = au_sbr(sb, bindex);
20606 + if (au_br_writable(br->br_perm)) {
20608 + br = au_sbr(sb, wbi);
20613 + AuDbg("wbi %d\n", wbi);
20615 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20619 + aufs_read_unlock(root, AuLock_IR);
20620 + err = PTR_ERR(h_file);
20621 + if (IS_ERR(h_file))
20624 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20625 + fd_install(fd, h_file);
20627 + goto out; /* success */
20630 + put_unused_fd(fd);
20636 +/* ---------------------------------------------------------------------- */
20638 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20641 + struct dentry *dentry;
20644 + case AUFS_CTL_RDU:
20645 + case AUFS_CTL_RDU_INO:
20646 + err = au_rdu_ioctl(file, cmd, arg);
20649 + case AUFS_CTL_WBR_FD:
20650 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20653 + case AUFS_CTL_IBUSY:
20654 + err = au_ibusy_ioctl(file, arg);
20657 + case AUFS_CTL_BRINFO:
20658 + err = au_brinfo_ioctl(file, arg);
20661 + case AUFS_CTL_FHSM_FD:
20662 + dentry = file->f_path.dentry;
20663 + if (IS_ROOT(dentry))
20664 + err = au_fhsm_fd(dentry->d_sb, arg);
20670 + /* do not call the lower */
20671 + AuDbg("0x%x\n", cmd);
20679 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20684 + case AUFS_CTL_MVDOWN:
20685 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20688 + case AUFS_CTL_WBR_FD:
20689 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20693 + /* do not call the lower */
20694 + AuDbg("0x%x\n", cmd);
20702 +#ifdef CONFIG_COMPAT
20703 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20704 + unsigned long arg)
20709 + case AUFS_CTL_RDU:
20710 + case AUFS_CTL_RDU_INO:
20711 + err = au_rdu_compat_ioctl(file, cmd, arg);
20714 + case AUFS_CTL_IBUSY:
20715 + err = au_ibusy_compat_ioctl(file, arg);
20718 + case AUFS_CTL_BRINFO:
20719 + err = au_brinfo_compat_ioctl(file, arg);
20723 + err = aufs_ioctl_dir(file, cmd, arg);
20730 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20731 + unsigned long arg)
20733 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20736 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20737 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20738 +++ linux/fs/aufs/i_op_add.c 2023-09-04 13:39:55.763295607 +0200
20740 +// SPDX-License-Identifier: GPL-2.0
20742 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20744 + * This program is free software; you can redistribute it and/or modify
20745 + * it under the terms of the GNU General Public License as published by
20746 + * the Free Software Foundation; either version 2 of the License, or
20747 + * (at your option) any later version.
20749 + * This program is distributed in the hope that it will be useful,
20750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20752 + * GNU General Public License for more details.
20754 + * You should have received a copy of the GNU General Public License
20755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20759 + * inode operations (add entry)
20762 +#include <linux/iversion.h>
20766 + * final procedure of adding a new entry, except link(2).
20767 + * remove whiteout, instantiate, copyup the parent dir's times and size
20768 + * and update version.
20769 + * if it failed, re-create the removed whiteout.
20771 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20772 + struct dentry *wh_dentry, struct dentry *dentry)
20775 + aufs_bindex_t bwh;
20776 + struct path h_path;
20777 + struct super_block *sb;
20778 + struct inode *inode, *h_dir;
20779 + struct dentry *wh;
20784 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20785 + IMustLock(h_dir);
20786 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20787 + bwh = au_dbwh(dentry);
20788 + h_path.dentry = wh_dentry;
20789 + h_path.mnt = au_sbr_mnt(sb, bindex);
20790 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20792 + if (unlikely(err))
20796 + inode = au_new_inode(dentry, /*must_new*/1);
20797 + if (!IS_ERR(inode)) {
20798 + d_instantiate(dentry, inode);
20799 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20801 + au_dir_ts(dir, bindex);
20802 + inode_inc_iversion(dir);
20803 + au_fhsm_wrote(sb, bindex, /*force*/0);
20804 + return 0; /* success */
20807 + err = PTR_ERR(inode);
20812 + /* dir inode is locked */
20813 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20814 + rerr = PTR_ERR(wh);
20815 + if (IS_ERR(wh)) {
20816 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20817 + dentry, err, rerr);
20826 +static int au_d_may_add(struct dentry *dentry)
20831 + if (unlikely(d_unhashed(dentry)))
20833 + if (unlikely(d_really_is_positive(dentry)))
20839 + * simple tests for the adding inode operations.
20840 + * following the checks in vfs, plus the parent-child relationship.
20842 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20843 + struct dentry *h_parent, int isdir)
20847 + struct dentry *h_dentry;
20848 + struct inode *h_inode;
20850 + err = -ENAMETOOLONG;
20851 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20854 + h_dentry = au_h_dptr(dentry, bindex);
20855 + if (d_really_is_negative(dentry)) {
20857 + if (unlikely(d_is_positive(h_dentry)))
20860 + /* rename(2) case */
20862 + if (unlikely(d_is_negative(h_dentry)))
20864 + h_inode = d_inode(h_dentry);
20865 + if (unlikely(!h_inode->i_nlink))
20868 + h_mode = h_inode->i_mode;
20871 + if (unlikely(S_ISDIR(h_mode)))
20873 + } else if (unlikely(!S_ISDIR(h_mode))) {
20880 + /* expected parent dir is locked */
20881 + if (unlikely(h_parent != h_dentry->d_parent))
20890 + * initial procedure of adding a new entry.
20891 + * prepare writable branch and the parent dir, lock it,
20892 + * and lookup whiteout for the new entry.
20894 +static struct dentry*
20895 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20896 + struct dentry *src_dentry, struct au_pin *pin,
20897 + struct au_wr_dir_args *wr_dir_args)
20899 + struct dentry *wh_dentry, *h_parent;
20900 + struct super_block *sb;
20901 + struct au_branch *br;
20903 + unsigned int udba;
20904 + aufs_bindex_t bcpup;
20906 + AuDbg("%pd\n", dentry);
20908 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20910 + wh_dentry = ERR_PTR(err);
20911 + if (unlikely(err < 0))
20914 + sb = dentry->d_sb;
20915 + udba = au_opt_udba(sb);
20916 + err = au_pin(pin, dentry, bcpup, udba,
20917 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20918 + wh_dentry = ERR_PTR(err);
20919 + if (unlikely(err))
20922 + h_parent = au_pinned_h_parent(pin);
20923 + if (udba != AuOpt_UDBA_NONE
20924 + && au_dbtop(dentry) == bcpup)
20925 + err = au_may_add(dentry, bcpup, h_parent,
20926 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20927 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20928 + err = -ENAMETOOLONG;
20929 + wh_dentry = ERR_PTR(err);
20930 + if (unlikely(err))
20933 + br = au_sbr(sb, bcpup);
20935 + struct path tmp = {
20936 + .dentry = h_parent,
20937 + .mnt = au_br_mnt(br)
20939 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20942 + wh_dentry = NULL;
20943 + if (bcpup != au_dbwh(dentry))
20944 + goto out; /* success */
20947 + * ENAMETOOLONG here means that if we allowed create such name, then it
20948 + * would not be able to removed in the future. So we don't allow such
20949 + * name here and we don't handle ENAMETOOLONG differently here.
20951 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20954 + if (IS_ERR(wh_dentry))
20957 + return wh_dentry;
20960 +/* ---------------------------------------------------------------------- */
20962 +enum { Mknod, Symlink, Creat };
20963 +struct simple_arg {
20970 + struct vfsub_aopen_args *aopen;
20973 + const char *symname;
20982 +static int add_simple(struct inode *dir, struct dentry *dentry,
20983 + struct simple_arg *arg)
20986 + aufs_bindex_t btop;
20987 + unsigned char created;
20988 + const unsigned char try_aopen
20989 + = (arg->type == Creat && arg->u.c.try_aopen);
20990 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20991 + struct dentry *wh_dentry, *parent;
20992 + struct inode *h_dir;
20993 + struct super_block *sb;
20994 + struct au_branch *br;
20995 + /* to reduce stack size */
20997 + struct au_dtime dt;
20998 + struct au_pin pin;
20999 + struct path h_path;
21000 + struct au_wr_dir_args wr_dir_args;
21003 + AuDbg("%pd\n", dentry);
21007 + a = kmalloc(sizeof(*a), GFP_NOFS);
21008 + if (unlikely(!a))
21010 + a->wr_dir_args.force_btgt = -1;
21011 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21013 + parent = dentry->d_parent; /* dir inode is locked */
21014 + if (!try_aopen) {
21015 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21016 + if (unlikely(err))
21019 + err = au_d_may_add(dentry);
21020 + if (unlikely(err))
21023 + di_write_lock_parent(parent);
21024 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21025 + &a->pin, &a->wr_dir_args);
21026 + err = PTR_ERR(wh_dentry);
21027 + if (IS_ERR(wh_dentry))
21030 + btop = au_dbtop(dentry);
21031 + sb = dentry->d_sb;
21032 + br = au_sbr(sb, btop);
21033 + a->h_path.dentry = au_h_dptr(dentry, btop);
21034 + a->h_path.mnt = au_br_mnt(br);
21035 + h_dir = au_pinned_h_dir(&a->pin);
21036 + switch (arg->type) {
21038 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21039 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21040 + arg->u.c.want_excl);
21042 + if (!err && try_aopen)
21043 + aopen->file->f_mode |= FMODE_CREATED;
21046 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21047 + AuDbg("err %d\n", err);
21048 + AuDbgFile(aopen->file);
21049 + created = err >= 0
21050 + && !!(aopen->file->f_mode & FMODE_CREATED);
21054 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21058 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21065 + if (unlikely(err < 0))
21068 + err = epilog(dir, btop, wh_dentry, dentry);
21070 + goto out_unpin; /* success */
21073 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21074 + /* no delegation since it is just created */
21075 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21078 + AuIOErr("%pd revert failure(%d, %d)\n",
21079 + dentry, err, rerr);
21082 + au_dtime_revert(&a->dt);
21084 + if (try_aopen && h_dir->i_op->atomic_open
21085 + && (aopen->file->f_mode & FMODE_OPENED))
21086 + /* aopen->file is still opened */
21087 + au_lcnt_dec(&aopen->br->br_nfiles);
21090 + au_unpin(&a->pin);
21094 + di_write_unlock(parent);
21096 + if (unlikely(err)) {
21097 + au_update_dbtop(dentry);
21101 + aufs_read_unlock(dentry, AuLock_DW);
21108 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
21109 + struct dentry *dentry, umode_t mode, dev_t dev)
21111 + struct simple_arg arg = {
21118 + return add_simple(dir, dentry, &arg);
21121 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
21122 + struct dentry *dentry, const char *symname)
21124 + struct simple_arg arg = {
21126 + .u.s.symname = symname
21128 + return add_simple(dir, dentry, &arg);
21131 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
21132 + struct dentry *dentry, umode_t mode, bool want_excl)
21134 + struct simple_arg arg = {
21138 + .want_excl = want_excl
21141 + return add_simple(dir, dentry, &arg);
21144 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21145 + struct vfsub_aopen_args *aopen_args)
21147 + struct simple_arg arg = {
21150 + .mode = aopen_args->create_mode,
21151 + .want_excl = aopen_args->open_flag & O_EXCL,
21152 + .try_aopen = true,
21153 + .aopen = aopen_args
21156 + return add_simple(dir, dentry, &arg);
21159 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
21160 + struct file *file, umode_t mode)
21163 + aufs_bindex_t bindex;
21164 + struct path h_ppath;
21165 + struct super_block *sb;
21166 + struct au_branch *br;
21167 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21168 + struct inode *h_dir, *inode;
21169 + struct vfsmount *h_mnt;
21170 + struct mnt_idmap *h_idmap;
21171 + struct file *h_file;
21172 + struct au_wr_dir_args wr_dir_args = {
21173 + .force_btgt = -1,
21174 + .flags = AuWrDir_TMPFILE
21177 + /* copy-up may happen */
21182 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21183 + if (unlikely(err))
21186 + dentry = file->f_path.dentry;
21187 + err = au_di_init(dentry);
21188 + if (unlikely(err))
21192 + parent = d_find_any_alias(dir);
21193 + AuDebugOn(!parent);
21194 + di_write_lock_parent(parent);
21195 + if (unlikely(d_inode(parent) != dir))
21198 + err = au_digen_test(parent, au_sigen(sb));
21199 + if (unlikely(err))
21202 + bindex = au_dbtop(parent);
21203 + au_set_dbtop(dentry, bindex);
21204 + au_set_dbbot(dentry, bindex);
21205 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21207 + if (unlikely(err < 0))
21210 + err = -EOPNOTSUPP;
21211 + h_dir = au_h_iptr(dir, bindex);
21212 + if (unlikely(!h_dir->i_op->tmpfile))
21215 + br = au_sbr(sb, bindex);
21216 + h_mnt = au_br_mnt(br);
21217 + err = vfsub_mnt_want_write(h_mnt);
21218 + if (unlikely(err))
21221 + h_idmap = mnt_idmap(h_mnt);
21222 + h_parent = au_h_dptr(parent, bindex);
21223 + h_ppath.mnt = h_mnt;
21224 + h_ppath.dentry = h_parent;
21225 + h_file = kernel_tmpfile_open(h_idmap, &h_ppath, mode, /*open_flag*/0,
21227 + if (IS_ERR(h_file)) {
21228 + err = PTR_ERR(h_file);
21233 + h_dentry = h_file->f_path.dentry;
21234 + au_set_dbtop(dentry, bindex);
21235 + au_set_dbbot(dentry, bindex);
21236 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21237 + inode = au_new_inode(dentry, /*must_new*/1);
21238 + if (IS_ERR(inode)) {
21239 + err = PTR_ERR(inode);
21240 + au_set_h_dptr(dentry, bindex, NULL);
21241 + au_set_dbtop(dentry, -1);
21242 + au_set_dbbot(dentry, -1);
21246 + if (!inode->i_nlink)
21247 + set_nlink(inode, 1);
21248 + d_tmpfile(file, inode);
21249 + au_di(dentry)->di_tmpfile = 1;
21250 + get_file(h_file);
21251 + au_di(dentry)->di_htmpfile = h_file;
21253 + /* update without i_mutex */
21254 + if (au_ibtop(dir) == au_dbtop(dentry))
21255 + au_cpup_attr_timesizes(dir);
21260 + vfsub_mnt_drop_write(h_mnt);
21262 + di_write_unlock(parent);
21264 + di_write_unlock(dentry);
21269 + au_di(dentry)->di_htmpfile = NULL;
21270 + au_di_fin(dentry);
21271 + dentry->d_fsdata = NULL;
21273 + si_read_unlock(sb);
21274 + if (!err && h_file) {
21276 + err = finish_open_simple(file, err);
21278 + au_lcnt_inc(&br->br_nfiles);
21281 + au_di(dentry)->di_htmpfile = NULL;
21282 + au_di_fin(dentry);
21283 + dentry->d_fsdata = NULL;
21287 + inode_unlock(dir);
21292 +/* ---------------------------------------------------------------------- */
21294 +struct au_link_args {
21295 + aufs_bindex_t bdst, bsrc;
21296 + struct au_pin pin;
21297 + struct path h_path;
21298 + struct dentry *src_parent, *parent;
21301 +static int au_cpup_before_link(struct dentry *src_dentry,
21302 + struct au_link_args *a)
21305 + struct dentry *h_src_dentry;
21306 + struct au_cp_generic cpg = {
21307 + .dentry = src_dentry,
21312 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21315 + di_read_lock_parent(a->src_parent, AuLock_IR);
21316 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21317 + if (unlikely(err))
21320 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21321 + err = au_pin(&a->pin, src_dentry, a->bdst,
21322 + au_opt_udba(src_dentry->d_sb),
21323 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21324 + if (unlikely(err))
21327 + err = au_sio_cpup_simple(&cpg);
21328 + au_unpin(&a->pin);
21331 + di_read_unlock(a->src_parent, AuLock_IR);
21335 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21336 + struct au_link_args *a)
21339 + unsigned char plink;
21340 + aufs_bindex_t bbot;
21341 + struct dentry *h_src_dentry;
21342 + struct inode *h_inode, *inode, *delegated;
21343 + struct super_block *sb;
21344 + struct file *h_file;
21348 + sb = src_dentry->d_sb;
21349 + inode = d_inode(src_dentry);
21350 + if (au_ibtop(inode) <= a->bdst)
21351 + h_inode = au_h_iptr(inode, a->bdst);
21352 + if (!h_inode || !h_inode->i_nlink) {
21353 + /* copyup src_dentry as the name of dentry. */
21354 + bbot = au_dbbot(dentry);
21355 + if (bbot < a->bsrc)
21356 + au_set_dbbot(dentry, a->bsrc);
21357 + au_set_h_dptr(dentry, a->bsrc,
21358 + dget(au_h_dptr(src_dentry, a->bsrc)));
21359 + dget(a->h_path.dentry);
21360 + au_set_h_dptr(dentry, a->bdst, NULL);
21361 + AuDbg("temporary d_inode...\n");
21362 + spin_lock(&dentry->d_lock);
21363 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21364 + spin_unlock(&dentry->d_lock);
21365 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21366 + if (IS_ERR(h_file))
21367 + err = PTR_ERR(h_file);
21369 + struct au_cp_generic cpg = {
21370 + .dentry = dentry,
21375 + .flags = AuCpup_KEEPLINO
21377 + err = au_sio_cpup_simple(&cpg);
21378 + au_h_open_post(dentry, a->bsrc, h_file);
21380 + dput(a->h_path.dentry);
21381 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21383 + au_set_h_dptr(dentry, a->bdst,
21384 + a->h_path.dentry);
21386 + spin_lock(&dentry->d_lock);
21387 + dentry->d_inode = NULL; /* restore */
21388 + spin_unlock(&dentry->d_lock);
21389 + AuDbg("temporary d_inode...done\n");
21390 + au_set_h_dptr(dentry, a->bsrc, NULL);
21391 + au_set_dbbot(dentry, bbot);
21393 + /* the inode of src_dentry already exists on a.bdst branch */
21394 + h_src_dentry = d_find_alias(h_inode);
21395 + if (!h_src_dentry && au_plink_test(inode)) {
21397 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21398 + err = PTR_ERR(h_src_dentry);
21399 + if (IS_ERR(h_src_dentry))
21402 + if (unlikely(d_is_negative(h_src_dentry))) {
21403 + dput(h_src_dentry);
21404 + h_src_dentry = NULL;
21408 + if (h_src_dentry) {
21409 + delegated = NULL;
21410 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21411 + &a->h_path, &delegated);
21412 + if (unlikely(err == -EWOULDBLOCK)) {
21413 + pr_warn("cannot retry for NFSv4 delegation"
21414 + " for an internal link\n");
21417 + dput(h_src_dentry);
21419 + AuIOErr("no dentry found for hi%lu on b%d\n",
21420 + h_inode->i_ino, a->bdst);
21425 + if (!err && !plink)
21426 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21433 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21434 + struct dentry *dentry)
21437 + struct au_dtime dt;
21438 + struct au_link_args *a;
21439 + struct dentry *wh_dentry, *h_src_dentry;
21440 + struct inode *inode, *delegated;
21441 + struct super_block *sb;
21442 + struct au_wr_dir_args wr_dir_args = {
21443 + /* .force_btgt = -1, */
21444 + .flags = AuWrDir_ADD_ENTRY
21448 + inode = d_inode(src_dentry);
21449 + IMustLock(inode);
21452 + a = kzalloc(sizeof(*a), GFP_NOFS);
21453 + if (unlikely(!a))
21456 + a->parent = dentry->d_parent; /* dir inode is locked */
21457 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21458 + AuLock_NOPLM | AuLock_GEN);
21459 + if (unlikely(err))
21461 + err = au_d_linkable(src_dentry);
21462 + if (unlikely(err))
21464 + err = au_d_may_add(dentry);
21465 + if (unlikely(err))
21468 + a->src_parent = dget_parent(src_dentry);
21469 + wr_dir_args.force_btgt = au_ibtop(inode);
21471 + di_write_lock_parent(a->parent);
21472 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21473 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21475 + err = PTR_ERR(wh_dentry);
21476 + if (IS_ERR(wh_dentry))
21480 + sb = dentry->d_sb;
21481 + a->bdst = au_dbtop(dentry);
21482 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21483 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21484 + a->bsrc = au_ibtop(inode);
21485 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21486 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21487 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21488 + if (!h_src_dentry) {
21489 + a->bsrc = au_dbtop(src_dentry);
21490 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21491 + AuDebugOn(!h_src_dentry);
21492 + } else if (IS_ERR(h_src_dentry)) {
21493 + err = PTR_ERR(h_src_dentry);
21498 + * aufs doesn't touch the credential so
21499 + * security_dentry_create_files_as() is unnecessary.
21501 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21502 + if (a->bdst < a->bsrc
21503 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21504 + err = au_cpup_or_link(src_dentry, dentry, a);
21506 + delegated = NULL;
21507 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21508 + &a->h_path, &delegated);
21509 + if (unlikely(err == -EWOULDBLOCK)) {
21510 + pr_warn("cannot retry for NFSv4 delegation"
21511 + " for an internal link\n");
21515 + dput(h_src_dentry);
21518 + * copyup src_dentry to the branch we process,
21519 + * and then link(2) to it.
21521 + dput(h_src_dentry);
21522 + if (a->bdst < a->bsrc
21523 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21524 + au_unpin(&a->pin);
21525 + di_write_unlock(a->parent);
21526 + err = au_cpup_before_link(src_dentry, a);
21527 + di_write_lock_parent(a->parent);
21529 + err = au_pin(&a->pin, dentry, a->bdst,
21531 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21532 + if (unlikely(err))
21536 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21538 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21539 + delegated = NULL;
21540 + err = vfsub_link(h_src_dentry,
21541 + au_pinned_h_dir(&a->pin),
21542 + &a->h_path, &delegated);
21543 + if (unlikely(err == -EWOULDBLOCK)) {
21544 + pr_warn("cannot retry"
21545 + " for NFSv4 delegation"
21546 + " for an internal link\n");
21552 + if (unlikely(err))
21556 + a->h_path.dentry = wh_dentry;
21557 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21559 + if (unlikely(err))
21563 + au_dir_ts(dir, a->bdst);
21564 + inode_inc_iversion(dir);
21565 + inc_nlink(inode);
21566 + inode->i_ctime = dir->i_ctime;
21567 + d_instantiate(dentry, au_igrab(inode));
21568 + if (d_unhashed(a->h_path.dentry))
21569 + /* some filesystem calls d_drop() */
21571 + /* some filesystems consume an inode even hardlink */
21572 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21573 + goto out_unpin; /* success */
21576 + /* no delegation since it is just created */
21577 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21578 + /*delegated*/NULL, /*force*/0);
21579 + if (unlikely(rerr)) {
21580 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21583 + au_dtime_revert(&dt);
21585 + au_unpin(&a->pin);
21589 + di_write_unlock(a->parent);
21590 + dput(a->src_parent);
21592 + if (unlikely(err)) {
21593 + au_update_dbtop(dentry);
21596 + aufs_read_and_write_unlock2(dentry, src_dentry);
21604 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
21605 + struct dentry *dentry, umode_t mode)
21608 + aufs_bindex_t bindex;
21609 + unsigned char diropq;
21610 + struct path h_path;
21611 + struct dentry *wh_dentry, *parent, *opq_dentry;
21612 + struct inode *h_inode;
21613 + struct super_block *sb;
21615 + struct au_pin pin;
21616 + struct au_dtime dt;
21617 + } *a; /* reduce the stack usage */
21618 + struct au_wr_dir_args wr_dir_args = {
21619 + .force_btgt = -1,
21620 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21626 + a = kmalloc(sizeof(*a), GFP_NOFS);
21627 + if (unlikely(!a))
21630 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21631 + if (unlikely(err))
21633 + err = au_d_may_add(dentry);
21634 + if (unlikely(err))
21637 + parent = dentry->d_parent; /* dir inode is locked */
21638 + di_write_lock_parent(parent);
21639 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21640 + &a->pin, &wr_dir_args);
21641 + err = PTR_ERR(wh_dentry);
21642 + if (IS_ERR(wh_dentry))
21645 + sb = dentry->d_sb;
21646 + bindex = au_dbtop(dentry);
21647 + h_path.dentry = au_h_dptr(dentry, bindex);
21648 + h_path.mnt = au_sbr_mnt(sb, bindex);
21649 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21650 + if (unlikely(err))
21653 + /* make the dir opaque */
21655 + h_inode = d_inode(h_path.dentry);
21657 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21658 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21659 + opq_dentry = au_diropq_create(dentry, bindex);
21660 + inode_unlock(h_inode);
21661 + err = PTR_ERR(opq_dentry);
21662 + if (IS_ERR(opq_dentry))
21664 + dput(opq_dentry);
21668 + err = epilog(dir, bindex, wh_dentry, dentry);
21671 + goto out_unpin; /* success */
21676 + AuLabel(revert opq);
21677 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21678 + rerr = au_diropq_remove(dentry, bindex);
21679 + inode_unlock(h_inode);
21681 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21682 + dentry, err, rerr);
21688 + AuLabel(revert dir);
21689 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21691 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21692 + dentry, err, rerr);
21695 + au_dtime_revert(&a->dt);
21697 + au_unpin(&a->pin);
21700 + di_write_unlock(parent);
21702 + if (unlikely(err)) {
21703 + au_update_dbtop(dentry);
21706 + aufs_read_unlock(dentry, AuLock_DW);
21712 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21713 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21714 +++ linux/fs/aufs/i_op.c 2023-09-03 02:21:58.859971007 +0200
21716 +// SPDX-License-Identifier: GPL-2.0
21718 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21720 + * This program is free software; you can redistribute it and/or modify
21721 + * it under the terms of the GNU General Public License as published by
21722 + * the Free Software Foundation; either version 2 of the License, or
21723 + * (at your option) any later version.
21725 + * This program is distributed in the hope that it will be useful,
21726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21728 + * GNU General Public License for more details.
21730 + * You should have received a copy of the GNU General Public License
21731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21735 + * inode operations (except add/del/rename)
21738 +#include <linux/device_cgroup.h>
21739 +#include <linux/filelock.h>
21740 +#include <linux/fs_stack.h>
21741 +#include <linux/iversion.h>
21742 +#include <linux/security.h>
21745 +static int h_permission(struct inode *h_inode, int mask,
21746 + struct path *h_path, int brperm)
21749 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21750 + struct mnt_idmap *h_idmap;
21753 + if (write_mask && IS_IMMUTABLE(h_inode))
21757 + if (((mask & MAY_EXEC)
21758 + && S_ISREG(h_inode->i_mode)
21759 + && (path_noexec(h_path)
21760 + || !(h_inode->i_mode & 0111))))
21764 + * - skip the lower fs test in the case of write to ro branch.
21765 + * - nfs dir permission write check is optimized, but a policy for
21766 + * link/rename requires a real check.
21767 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21768 + * in this case, generic_permission() returns -EOPNOTSUPP.
21770 + h_idmap = mnt_idmap(h_path->mnt);
21771 + if ((write_mask && !au_br_writable(brperm))
21772 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21773 + && write_mask && !(mask & MAY_READ))
21774 + || !h_inode->i_op->permission) {
21775 + /* AuLabel(generic_permission); */
21776 + /* AuDbg("get_inode_acl %ps\n",
21777 + h_inode->i_op->get_inode_acl); */
21778 + err = generic_permission(h_idmap, h_inode, mask);
21779 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21780 + err = h_inode->i_op->permission(h_idmap, h_inode,
21784 + /* AuLabel(h_inode->permission); */
21785 + err = h_inode->i_op->permission(h_idmap, h_inode, mask);
21790 + err = devcgroup_inode_permission(h_inode, mask);
21792 + err = security_inode_permission(h_inode, mask);
21798 +static int aufs_permission(struct mnt_idmap *idmap, struct inode *inode,
21802 + aufs_bindex_t bindex, bbot;
21803 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21804 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21805 + struct inode *h_inode;
21806 + struct super_block *sb;
21807 + struct au_branch *br;
21809 + /* todo: support rcu-walk? */
21810 + if (mask & MAY_NOT_BLOCK)
21813 + sb = inode->i_sb;
21814 + si_read_lock(sb, AuLock_FLUSH);
21815 + ii_read_lock_child(inode);
21816 +#if 0 /* reserved for future use */
21818 + * This test may be rather 'too much' since the test is essentially done
21819 + * in the aufs_lookup(). Theoretically it is possible that the inode
21820 + * generation doesn't match to the superblock's here. But it isn't a
21821 + * big deal I suppose.
21823 + err = au_iigen_test(inode, au_sigen(sb));
21824 + if (unlikely(err))
21830 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21831 + err = au_busy_or_stale();
21832 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21833 + if (unlikely(!h_inode
21834 + || (h_inode->i_mode & S_IFMT)
21835 + != (inode->i_mode & S_IFMT)))
21839 + bindex = au_ibtop(inode);
21840 + br = au_sbr(sb, bindex);
21841 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21844 + && !special_file(h_inode->i_mode)) {
21845 + /* test whether the upper writable branch exists */
21847 + for (; bindex >= 0; bindex--)
21848 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21856 + /* non-write to dir */
21858 + bbot = au_ibbot(inode);
21859 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21860 + h_inode = au_h_iptr(inode, bindex);
21862 + err = au_busy_or_stale();
21863 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21866 + br = au_sbr(sb, bindex);
21867 + err = h_permission(h_inode, mask, &br->br_path,
21873 + ii_read_unlock(inode);
21874 + si_read_unlock(sb);
21878 +/* ---------------------------------------------------------------------- */
21880 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21881 + unsigned int flags)
21883 + struct dentry *ret, *parent;
21884 + struct inode *inode;
21885 + struct super_block *sb;
21886 + int err, npositive;
21890 + /* todo: support rcu-walk? */
21891 + ret = ERR_PTR(-ECHILD);
21892 + if (flags & LOOKUP_RCU)
21895 + ret = ERR_PTR(-ENAMETOOLONG);
21896 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21900 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21901 + ret = ERR_PTR(err);
21902 + if (unlikely(err))
21905 + err = au_di_init(dentry);
21906 + ret = ERR_PTR(err);
21907 + if (unlikely(err))
21911 + npositive = 0; /* suppress a warning */
21912 + parent = dentry->d_parent; /* dir inode is locked */
21913 + di_read_lock_parent(parent, AuLock_IR);
21914 + err = au_alive_dir(parent);
21916 + err = au_digen_test(parent, au_sigen(sb));
21918 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21919 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21920 + AuLkup_ALLOW_NEG);
21923 + di_read_unlock(parent, AuLock_IR);
21924 + ret = ERR_PTR(err);
21925 + if (unlikely(err < 0))
21929 + inode = au_new_inode(dentry, /*must_new*/0);
21930 + if (IS_ERR(inode)) {
21931 + ret = (void *)inode;
21938 + atomic_inc(&inode->i_count);
21939 + ret = d_splice_alias(inode, dentry);
21940 +#if 0 /* reserved for future use */
21941 + if (unlikely(d_need_lookup(dentry))) {
21942 + spin_lock(&dentry->d_lock);
21943 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21944 + spin_unlock(&dentry->d_lock);
21948 + if (!IS_ERR(ret)) {
21950 + if (ret && ret != dentry)
21951 + ii_write_unlock(inode);
21953 + ii_write_unlock(inode);
21960 + di_write_unlock(dentry);
21962 + si_read_unlock(sb);
21967 +/* ---------------------------------------------------------------------- */
21970 + * very dirty and complicated aufs ->atomic_open().
21971 + * aufs_atomic_open()
21972 + * + au_aopen_or_create()
21974 + * + vfsub_atomic_open()
21975 + * + branch fs ->atomic_open()
21976 + * may call the actual 'open' for h_file
21977 + * + inc br_nfiles only if opened
21978 + * + au_aopen_no_open() or au_aopen_do_open()
21980 + * au_aopen_do_open()
21981 + * + finish_open()
21982 + * + au_do_aopen()
21983 + * + au_do_open() the body of all 'open'
21984 + * + au_do_open_nondir()
21985 + * set the passed h_file
21987 + * au_aopen_no_open()
21988 + * + finish_no_open()
21991 +struct aopen_node {
21992 + struct hlist_bl_node hblist;
21993 + struct file *file, *h_file;
21996 +static int au_do_aopen(struct inode *inode, struct file *file)
21998 + struct hlist_bl_head *aopen;
21999 + struct hlist_bl_node *pos;
22000 + struct aopen_node *node;
22001 + struct au_do_open_args args = {
22003 + .open = au_do_open_nondir
22006 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22007 + hlist_bl_lock(aopen);
22008 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22009 + if (node->file == file) {
22010 + args.h_file = node->h_file;
22013 + hlist_bl_unlock(aopen);
22014 + /* AuDebugOn(!args.h_file); */
22016 + return au_do_open(file, &args);
22019 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22020 + struct aopen_node *aopen_node)
22023 + struct hlist_bl_head *aopen;
22026 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22027 + au_hbl_add(&aopen_node->hblist, aopen);
22028 + err = finish_open(file, dentry, au_do_aopen);
22029 + au_hbl_del(&aopen_node->hblist, aopen);
22030 + /* AuDbgFile(file); */
22031 + AuDbg("%pd%s%s\n", dentry,
22032 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22033 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22039 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22045 + err = finish_no_open(file, dentry);
22051 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22052 + struct file *file, unsigned int open_flag,
22053 + umode_t create_mode)
22055 + int err, did_open;
22056 + unsigned int lkup_flags;
22057 + aufs_bindex_t bindex;
22058 + struct super_block *sb;
22059 + struct dentry *parent, *d;
22060 + struct vfsub_aopen_args args = {
22061 + .open_flag = open_flag,
22062 + .create_mode = create_mode
22064 + struct aopen_node aopen_node = {
22069 + AuDbg("open_flag 0%o\n", open_flag);
22070 + AuDbgDentry(dentry);
22073 + if (!au_di(dentry)) {
22074 + lkup_flags = LOOKUP_OPEN;
22075 + if (open_flag & O_CREAT)
22076 + lkup_flags |= LOOKUP_CREATE;
22077 + d = aufs_lookup(dir, dentry, lkup_flags);
22079 + err = PTR_ERR(d);
22084 + * obsoleted dentry found.
22085 + * another error will be returned later.
22091 + AuDbgDentry(dentry);
22094 + if (d_is_positive(dentry)
22095 + || d_unhashed(dentry)
22096 + || d_unlinked(dentry)
22097 + || !(open_flag & O_CREAT)) {
22098 + err = au_aopen_no_open(file, dentry);
22099 + goto out; /* success */
22102 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22103 + if (unlikely(err))
22106 + sb = dentry->d_sb;
22107 + parent = dentry->d_parent; /* dir is locked */
22108 + di_write_lock_parent(parent);
22109 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22110 + if (unlikely(err < 0))
22113 + AuDbgDentry(dentry);
22114 + if (d_is_positive(dentry)) {
22115 + err = au_aopen_no_open(file, dentry);
22116 + goto out_parent; /* success */
22119 + args.file = alloc_empty_file(file->f_flags, current_cred());
22120 + err = PTR_ERR(args.file);
22121 + if (IS_ERR(args.file))
22124 + bindex = au_dbtop(dentry);
22125 + err = au_aopen_or_create(dir, dentry, &args);
22127 + AuDbgFile(args.file);
22128 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22129 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22132 + args.file = NULL;
22134 + di_write_unlock(parent);
22135 + di_write_unlock(dentry);
22136 + if (unlikely(err < 0)) {
22143 + err = au_aopen_no_open(file, dentry);
22145 + aopen_node.h_file = args.file;
22146 + err = au_aopen_do_open(file, dentry, &aopen_node);
22148 + if (unlikely(err < 0)) {
22152 + au_lcnt_dec(&args.br->br_nfiles);
22154 + goto out_sb; /* success */
22157 + di_write_unlock(parent);
22158 + di_write_unlock(dentry);
22160 + si_read_unlock(sb);
22168 +/* ---------------------------------------------------------------------- */
22170 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22171 + const unsigned char add_entry, aufs_bindex_t bcpup,
22172 + aufs_bindex_t btop)
22175 + struct dentry *h_parent;
22176 + struct inode *h_dir;
22179 + IMustLock(d_inode(parent));
22181 + di_write_lock_parent(parent);
22184 + if (!au_h_dptr(parent, bcpup)) {
22185 + if (btop > bcpup)
22186 + err = au_cpup_dirs(dentry, bcpup);
22187 + else if (btop < bcpup)
22188 + err = au_cpdown_dirs(dentry, bcpup);
22192 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22193 + h_parent = au_h_dptr(parent, bcpup);
22194 + h_dir = d_inode(h_parent);
22195 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22196 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22197 + /* todo: no unlock here */
22198 + inode_unlock_shared(h_dir);
22200 + AuDbg("bcpup %d\n", bcpup);
22202 + if (d_really_is_negative(dentry))
22203 + au_set_h_dptr(dentry, btop, NULL);
22204 + au_update_dbrange(dentry, /*do_put_zero*/0);
22209 + di_write_unlock(parent);
22211 + err = bcpup; /* success */
22218 + * decide the branch and the parent dir where we will create a new entry.
22219 + * returns new bindex or an error.
22220 + * copyup the parent dir if needed.
22222 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22223 + struct au_wr_dir_args *args)
22226 + unsigned int flags;
22227 + aufs_bindex_t bcpup, btop, src_btop;
22228 + const unsigned char add_entry
22229 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22230 + | au_ftest_wrdir(args->flags, TMPFILE);
22231 + struct super_block *sb;
22232 + struct dentry *parent;
22233 + struct au_sbinfo *sbinfo;
22235 + sb = dentry->d_sb;
22236 + sbinfo = au_sbi(sb);
22237 + parent = dget_parent(dentry);
22238 + btop = au_dbtop(dentry);
22240 + if (args->force_btgt < 0) {
22241 + if (src_dentry) {
22242 + src_btop = au_dbtop(src_dentry);
22243 + if (src_btop < btop)
22244 + bcpup = src_btop;
22245 + } else if (add_entry) {
22247 + if (au_ftest_wrdir(args->flags, ISDIR))
22248 + au_fset_wbr(flags, DIR);
22249 + err = AuWbrCreate(sbinfo, dentry, flags);
22253 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22255 + err = AuWbrCopyup(sbinfo, dentry);
22257 + if (!IS_ROOT(dentry)) {
22258 + di_read_lock_parent(parent, !AuLock_IR);
22259 + err = AuWbrCopyup(sbinfo, dentry);
22260 + di_read_unlock(parent, !AuLock_IR);
22262 + err = AuWbrCopyup(sbinfo, dentry);
22265 + if (unlikely(err < 0))
22269 + bcpup = args->force_btgt;
22270 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22273 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22275 + if (bcpup == btop)
22276 + goto out; /* success */
22278 + /* copyup the new parent into the branch we process */
22279 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22281 + if (d_really_is_negative(dentry)) {
22282 + au_set_h_dptr(dentry, btop, NULL);
22283 + au_set_dbtop(dentry, bcpup);
22284 + au_set_dbbot(dentry, bcpup);
22286 + AuDebugOn(add_entry
22287 + && !au_ftest_wrdir(args->flags, TMPFILE)
22288 + && !au_h_dptr(dentry, bcpup));
22296 +/* ---------------------------------------------------------------------- */
22298 +void au_pin_hdir_unlock(struct au_pin *p)
22301 + au_hn_inode_unlock(p->hdir);
22304 +int au_pin_hdir_lock(struct au_pin *p)
22312 + /* even if an error happens later, keep this lock */
22313 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22316 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22321 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22322 + p->h_parent, p->br);
22328 +int au_pin_hdir_relock(struct au_pin *p)
22331 + struct inode *h_i;
22332 + struct dentry *h_d[] = {
22337 + err = au_pin_hdir_lock(p);
22338 + if (unlikely(err))
22341 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22344 + if (d_is_positive(h_d[i])) {
22345 + h_i = d_inode(h_d[i]);
22346 + err = !h_i->i_nlink;
22354 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22356 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22359 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22362 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22363 + p->lsc_hi, 0, NULL, _RET_IP_);
22364 + au_pin_hdir_set_owner(p, current);
22368 +void au_pin_hdir_release(struct au_pin *p)
22371 + au_pin_hdir_set_owner(p, p->task);
22372 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22376 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22378 + if (pin && pin->parent)
22379 + return au_h_dptr(pin->parent, pin->bindex);
22383 +void au_unpin(struct au_pin *p)
22386 + au_pin_hdir_unlock(p);
22387 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22388 + vfsub_mnt_drop_write(p->h_mnt);
22392 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22393 + di_read_unlock(p->parent, AuLock_IR);
22394 + iput(p->hdir->hi_inode);
22396 + p->parent = NULL;
22399 + /* do not clear p->task */
22402 +int au_do_pin(struct au_pin *p)
22405 + struct super_block *sb;
22406 + struct inode *h_dir;
22409 + sb = p->dentry->d_sb;
22410 + p->br = au_sbr(sb, p->bindex);
22411 + if (IS_ROOT(p->dentry)) {
22412 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22413 + p->h_mnt = au_br_mnt(p->br);
22414 + err = vfsub_mnt_want_write(p->h_mnt);
22415 + if (unlikely(err)) {
22416 + au_fclr_pin(p->flags, MNT_WRITE);
22423 + p->h_dentry = NULL;
22424 + if (p->bindex <= au_dbbot(p->dentry))
22425 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22427 + p->parent = dget_parent(p->dentry);
22428 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22429 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22432 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22433 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22435 + h_dir = p->hdir->hi_inode;
22439 + * if DI_LOCKED is not set, then p->parent may be different
22440 + * and h_parent can be NULL.
22442 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22444 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22445 + di_read_unlock(p->parent, AuLock_IR);
22447 + p->parent = NULL;
22451 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22452 + p->h_mnt = au_br_mnt(p->br);
22453 + err = vfsub_mnt_want_write(p->h_mnt);
22454 + if (unlikely(err)) {
22455 + au_fclr_pin(p->flags, MNT_WRITE);
22456 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22457 + di_read_unlock(p->parent, AuLock_IR);
22459 + p->parent = NULL;
22465 + err = au_pin_hdir_lock(p);
22467 + goto out; /* success */
22472 + pr_err("err %d\n", err);
22473 + err = au_busy_or_stale();
22478 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22479 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22480 + unsigned int udba, unsigned char flags)
22482 + p->dentry = dentry;
22484 + p->lsc_di = lsc_di;
22485 + p->lsc_hi = lsc_hi;
22486 + p->flags = flags;
22487 + p->bindex = bindex;
22489 + p->parent = NULL;
22493 + p->h_dentry = NULL;
22494 + p->h_parent = NULL;
22496 + p->task = current;
22499 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22500 + unsigned int udba, unsigned char flags)
22502 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22504 + return au_do_pin(pin);
22507 +/* ---------------------------------------------------------------------- */
22510 + * ->setattr() and ->getattr() are called in various cases.
22511 + * chmod, stat: dentry is revalidated.
22512 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22514 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22516 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22517 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22520 + struct dentry *parent;
22523 + if (au_digen_test(dentry, sigen)) {
22524 + parent = dget_parent(dentry);
22525 + di_read_lock_parent(parent, AuLock_IR);
22526 + err = au_refresh_dentry(dentry, parent);
22527 + di_read_unlock(parent, AuLock_IR);
22535 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22536 + struct au_icpup_args *a)
22540 + aufs_bindex_t btop, ibtop;
22541 + struct dentry *hi_wh, *parent;
22542 + struct inode *inode;
22543 + struct au_wr_dir_args wr_dir_args = {
22544 + .force_btgt = -1,
22548 + if (d_is_dir(dentry))
22549 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22550 + /* plink or hi_wh() case */
22551 + btop = au_dbtop(dentry);
22552 + inode = d_inode(dentry);
22553 + ibtop = au_ibtop(inode);
22554 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22555 + wr_dir_args.force_btgt = ibtop;
22556 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22557 + if (unlikely(err < 0))
22561 + au_fset_icpup(a->flags, DID_CPUP);
22564 + a->pin_flags = AuPin_MNT_WRITE;
22566 + if (!IS_ROOT(dentry)) {
22567 + au_fset_pin(a->pin_flags, DI_LOCKED);
22568 + parent = dget_parent(dentry);
22569 + di_write_lock_parent(parent);
22572 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22573 + if (unlikely(err))
22577 + a->h_path.dentry = au_h_dptr(dentry, btop);
22578 + a->h_inode = d_inode(a->h_path.dentry);
22579 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22580 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22581 + if (ia->ia_size < i_size_read(a->h_inode))
22582 + sz = ia->ia_size;
22583 + inode_unlock_shared(a->h_inode);
22587 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22588 + hi_wh = au_hi_wh(inode, a->btgt);
22590 + struct au_cp_generic cpg = {
22591 + .dentry = dentry,
22597 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22598 + if (unlikely(err))
22600 + hi_wh = au_hi_wh(inode, a->btgt);
22601 + /* todo: revalidate hi_wh? */
22606 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22607 + di_downgrade_lock(parent, AuLock_IR);
22611 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22612 + goto out; /* success */
22614 + if (!d_unhashed(dentry)) {
22615 + struct au_cp_generic cpg = {
22616 + .dentry = dentry,
22621 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22623 + err = au_sio_cpup_simple(&cpg);
22625 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22626 + } else if (!hi_wh)
22627 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22629 + a->h_path.dentry = hi_wh; /* do not dget here */
22632 + a->h_inode = d_inode(a->h_path.dentry);
22634 + goto out; /* success */
22635 + au_unpin(&a->pin);
22638 + di_write_unlock(parent);
22643 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22647 +static int aufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
22648 + struct iattr *ia)
22651 + struct inode *inode, *delegated;
22652 + struct super_block *sb;
22653 + struct file *file;
22654 + struct au_icpup_args *a;
22655 + struct mnt_idmap *h_idmap;
22657 + inode = d_inode(dentry);
22658 + IMustLock(inode);
22660 + err = setattr_prepare(idmap, dentry, ia);
22661 + if (unlikely(err))
22665 + a = kzalloc(sizeof(*a), GFP_NOFS);
22666 + if (unlikely(!a))
22669 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22670 + ia->ia_valid &= ~ATTR_MODE;
22673 + sb = dentry->d_sb;
22674 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22675 + if (unlikely(err))
22678 + if (ia->ia_valid & ATTR_FILE) {
22679 + /* currently ftruncate(2) only */
22680 + AuDebugOn(!d_is_reg(dentry));
22681 + file = ia->ia_file;
22682 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22684 + if (unlikely(err))
22686 + ia->ia_file = au_hf_top(file);
22687 + a->udba = AuOpt_UDBA_NONE;
22689 + /* fchmod() doesn't pass ia_file */
22690 + a->udba = au_opt_udba(sb);
22691 + di_write_lock_child(dentry);
22692 + /* no d_unlinked(), to set UDBA_NONE for root */
22693 + if (d_unhashed(dentry))
22694 + a->udba = AuOpt_UDBA_NONE;
22695 + if (a->udba != AuOpt_UDBA_NONE) {
22696 + AuDebugOn(IS_ROOT(dentry));
22697 + err = au_reval_for_attr(dentry, au_sigen(sb));
22698 + if (unlikely(err))
22703 + err = au_pin_and_icpup(dentry, ia, a);
22704 + if (unlikely(err < 0))
22706 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22707 + ia->ia_file = NULL;
22708 + ia->ia_valid &= ~ATTR_FILE;
22711 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22712 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22713 + == (ATTR_MODE | ATTR_CTIME)) {
22714 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22715 + if (unlikely(err))
22717 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22718 + && (ia->ia_valid & ATTR_CTIME)) {
22719 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22720 + if (unlikely(err))
22724 + if (ia->ia_valid & ATTR_SIZE) {
22727 + if (ia->ia_size < i_size_read(inode))
22729 + truncate_setsize(inode, ia->ia_size);
22732 + if (ia->ia_valid & ATTR_FILE)
22734 + inode_unlock(a->h_inode);
22735 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22736 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22738 + delegated = NULL;
22740 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22742 + err = break_deleg_wait(&delegated);
22750 + * regardless aufs 'acl' option setting.
22751 + * why don't all acl-aware fs call this func from their ->setattr()?
22753 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22754 + h_idmap = mnt_idmap(a->h_path.mnt);
22755 + err = vfsub_acl_chmod(h_idmap, a->h_path.dentry, ia->ia_mode);
22758 + au_cpup_attr_changeable(inode);
22761 + inode_unlock(a->h_inode);
22762 + au_unpin(&a->pin);
22763 + if (unlikely(err))
22764 + au_update_dbtop(dentry);
22766 + di_write_unlock(dentry);
22768 + fi_write_unlock(file);
22769 + ia->ia_file = file;
22770 + ia->ia_valid |= ATTR_FILE;
22773 + si_read_unlock(sb);
22781 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22782 +static int au_h_path_to_set_attr(struct dentry *dentry,
22783 + struct au_icpup_args *a, struct path *h_path)
22786 + struct super_block *sb;
22788 + sb = dentry->d_sb;
22789 + a->udba = au_opt_udba(sb);
22790 + /* no d_unlinked(), to set UDBA_NONE for root */
22791 + if (d_unhashed(dentry))
22792 + a->udba = AuOpt_UDBA_NONE;
22793 + if (a->udba != AuOpt_UDBA_NONE) {
22794 + AuDebugOn(IS_ROOT(dentry));
22795 + err = au_reval_for_attr(dentry, au_sigen(sb));
22796 + if (unlikely(err))
22799 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22800 + if (unlikely(err < 0))
22803 + h_path->dentry = a->h_path.dentry;
22804 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22810 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22811 + struct au_sxattr *arg)
22814 + struct path h_path;
22815 + struct super_block *sb;
22816 + struct au_icpup_args *a;
22817 + struct inode *h_inode;
22818 + struct mnt_idmap *h_idmap;
22820 + IMustLock(inode);
22823 + a = kzalloc(sizeof(*a), GFP_NOFS);
22824 + if (unlikely(!a))
22827 + sb = dentry->d_sb;
22828 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22829 + if (unlikely(err))
22832 + h_path.dentry = NULL; /* silence gcc */
22833 + di_write_lock_child(dentry);
22834 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22835 + if (unlikely(err))
22837 + h_idmap = mnt_idmap(h_path.mnt);
22839 + inode_unlock(a->h_inode);
22840 + switch (arg->type) {
22841 + case AU_XATTR_SET:
22842 + AuDebugOn(d_is_negative(h_path.dentry));
22843 + err = vfsub_setxattr(h_idmap, h_path.dentry,
22844 + arg->u.set.name, arg->u.set.value,
22845 + arg->u.set.size, arg->u.set.flags);
22848 + err = -EOPNOTSUPP;
22849 + h_inode = d_inode(h_path.dentry);
22850 + if (h_inode->i_op->set_acl) {
22851 + /* this will call posix_acl_update_mode */
22852 + err = h_inode->i_op->set_acl(h_idmap, h_path.dentry,
22853 + arg->u.acl_set.acl,
22854 + arg->u.acl_set.type);
22859 + au_cpup_attr_timesizes(inode);
22861 + au_unpin(&a->pin);
22862 + if (unlikely(err))
22863 + au_update_dbtop(dentry);
22866 + di_write_unlock(dentry);
22867 + si_read_unlock(sb);
22876 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22877 + unsigned int nlink)
22881 + inode->i_mode = st->mode;
22882 + /* don't i_[ug]id_write() here */
22883 + inode->i_uid = st->uid;
22884 + inode->i_gid = st->gid;
22885 + inode->i_atime = st->atime;
22886 + inode->i_mtime = st->mtime;
22887 + inode->i_ctime = st->ctime;
22889 + au_cpup_attr_nlink(inode, /*force*/0);
22890 + if (S_ISDIR(inode->i_mode)) {
22891 + n = inode->i_nlink;
22894 + smp_mb(); /* for i_nlink */
22895 + /* 0 can happen */
22896 + set_nlink(inode, n);
22899 + spin_lock(&inode->i_lock);
22900 + inode->i_blocks = st->blocks;
22901 + i_size_write(inode, st->size);
22902 + spin_unlock(&inode->i_lock);
22906 + * common routine for aufs_getattr() and au_getxattr().
22907 + * returns zero or negative (an error).
22908 + * @dentry will be read-locked in success.
22910 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22911 + struct path *h_path, int locked)
22914 + unsigned int mnt_flags, sigen;
22915 + unsigned char udba_none;
22916 + aufs_bindex_t bindex;
22917 + struct super_block *sb, *h_sb;
22919 + h_path->mnt = NULL;
22920 + h_path->dentry = NULL;
22923 + sb = dentry->d_sb;
22924 + mnt_flags = au_mntflags(sb);
22925 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22927 + if (unlikely(locked))
22928 + goto body; /* skip locking dinfo */
22930 + /* support fstat(2) */
22931 + if (!d_unlinked(dentry) && !udba_none) {
22932 + sigen = au_sigen(sb);
22933 + err = au_digen_test(dentry, sigen);
22935 + di_read_lock_child(dentry, AuLock_IR);
22936 + err = au_dbrange_test(dentry);
22937 + if (unlikely(err)) {
22938 + di_read_unlock(dentry, AuLock_IR);
22942 + AuDebugOn(IS_ROOT(dentry));
22943 + di_write_lock_child(dentry);
22944 + err = au_dbrange_test(dentry);
22946 + err = au_reval_for_attr(dentry, sigen);
22948 + di_downgrade_lock(dentry, AuLock_IR);
22950 + di_write_unlock(dentry);
22955 + di_read_lock_child(dentry, AuLock_IR);
22959 + inode = d_inode(dentry);
22960 + if (unlikely(!inode))
22963 + bindex = au_ibtop(inode);
22964 + h_path->mnt = au_sbr_mnt(sb, bindex);
22965 + h_sb = h_path->mnt->mnt_sb;
22967 + && !au_test_fs_bad_iattr(h_sb)
22969 + goto out; /* success */
22971 + if (au_dbtop(dentry) == bindex)
22972 + h_path->dentry = au_h_dptr(dentry, bindex);
22973 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22974 + h_path->dentry = au_plink_lkup(inode, bindex);
22975 + if (IS_ERR(h_path->dentry))
22976 + /* pretending success */
22977 + h_path->dentry = NULL;
22979 + dput(h_path->dentry);
22986 +static int aufs_getattr(struct mnt_idmap *idmap, const struct path *path,
22987 + struct kstat *st, u32 request, unsigned int query)
22990 + unsigned char positive;
22991 + struct path h_path;
22992 + struct dentry *dentry;
22993 + struct inode *inode;
22994 + struct super_block *sb;
22996 + dentry = path->dentry;
22997 + inode = d_inode(dentry);
22998 + sb = dentry->d_sb;
22999 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23000 + if (unlikely(err))
23002 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23004 + if (unlikely(err))
23006 + if (unlikely(!h_path.dentry))
23007 + /* illegally overlapped or something */
23008 + goto out_fill; /* pretending success */
23010 + positive = d_is_positive(h_path.dentry);
23012 + /* no vfsub version */
23013 + err = vfs_getattr(&h_path, st, request, query);
23016 + au_refresh_iattr(inode, st,
23017 + d_inode(h_path.dentry)->i_nlink);
23018 + goto out_fill; /* success */
23024 + generic_fillattr(idmap, inode, st);
23026 + di_read_unlock(dentry, AuLock_IR);
23028 + si_read_unlock(sb);
23034 +/* ---------------------------------------------------------------------- */
23036 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23037 + struct delayed_call *done)
23040 + struct dentry *h_dentry;
23041 + struct inode *h_inode;
23043 + aufs_bindex_t bindex;
23045 + ret = NULL; /* suppress a warning */
23050 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23051 + if (unlikely(err))
23054 + err = au_d_hashed_positive(dentry);
23055 + if (unlikely(err))
23059 + inode = d_inode(dentry);
23060 + bindex = au_ibtop(inode);
23061 + h_inode = au_h_iptr(inode, bindex);
23062 + if (unlikely(!h_inode->i_op->get_link))
23067 + if (au_dbtop(dentry) <= bindex) {
23068 + h_dentry = au_h_dptr(dentry, bindex);
23073 + h_dentry = d_find_any_alias(h_inode);
23074 + if (IS_ERR(h_dentry)) {
23075 + err = PTR_ERR(h_dentry);
23079 + if (unlikely(!h_dentry))
23083 + AuDbg("%ps\n", h_inode->i_op->get_link);
23084 + AuDbgDentry(h_dentry);
23085 + ret = vfs_get_link(h_dentry, done);
23088 + err = PTR_ERR(ret);
23091 + aufs_read_unlock(dentry, AuLock_IR);
23093 + if (unlikely(err))
23094 + ret = ERR_PTR(err);
23095 + AuTraceErrPtr(ret);
23099 +/* ---------------------------------------------------------------------- */
23101 +static int au_is_special(struct inode *inode)
23103 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23106 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23110 + aufs_bindex_t bindex;
23111 + struct super_block *sb;
23112 + struct inode *h_inode;
23113 + struct vfsmount *h_mnt;
23115 + sb = inode->i_sb;
23116 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23117 + "unexpected s_flags 0x%lx", sb->s_flags);
23119 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23121 + si_read_lock(sb, AuLock_FLUSH);
23122 + ii_write_lock_child(inode);
23125 + bindex = au_ibtop(inode);
23126 + h_inode = au_h_iptr(inode, bindex);
23127 + if (!au_test_ro(sb, bindex, inode)) {
23128 + h_mnt = au_sbr_mnt(sb, bindex);
23129 + err = vfsub_mnt_want_write(h_mnt);
23131 + err = vfsub_update_time(h_inode, ts, flags);
23132 + vfsub_mnt_drop_write(h_mnt);
23134 + } else if (au_is_special(h_inode)) {
23136 + * Never copy-up here.
23137 + * These special files may already be opened and used for
23138 + * communicating. If we copied it up, then the communication
23139 + * would be corrupted.
23141 + AuWarn1("timestamps for i%lu are ignored "
23142 + "since it is on readonly branch (hi%lu).\n",
23143 + inode->i_ino, h_inode->i_ino);
23144 + } else if (flags & ~S_ATIME) {
23146 + AuIOErr1("unexpected flags 0x%x\n", flags);
23151 + au_cpup_attr_timesizes(inode);
23152 + ii_write_unlock(inode);
23153 + si_read_unlock(sb);
23156 + if (!err && (flags & S_VERSION))
23157 + inode_inc_iversion(inode);
23162 +/* ---------------------------------------------------------------------- */
23164 +/* no getattr version will be set by module.c:aufs_init() */
23165 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23167 + [AuIop_SYMLINK] = {
23168 + .permission = aufs_permission,
23169 +#ifdef CONFIG_FS_POSIX_ACL
23170 + .get_inode_acl = aufs_get_inode_acl,
23171 + .get_acl = aufs_get_acl,
23172 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23175 + .setattr = aufs_setattr,
23176 + .getattr = aufs_getattr,
23178 +#ifdef CONFIG_AUFS_XATTR
23179 + .listxattr = aufs_listxattr,
23182 + .get_link = aufs_get_link
23184 + /* .update_time = aufs_update_time */
23187 + .create = aufs_create,
23188 + .lookup = aufs_lookup,
23189 + .link = aufs_link,
23190 + .unlink = aufs_unlink,
23191 + .symlink = aufs_symlink,
23192 + .mkdir = aufs_mkdir,
23193 + .rmdir = aufs_rmdir,
23194 + .mknod = aufs_mknod,
23195 + .rename = aufs_rename,
23197 + .permission = aufs_permission,
23198 +#ifdef CONFIG_FS_POSIX_ACL
23199 + .get_inode_acl = aufs_get_inode_acl,
23200 + .get_acl = aufs_get_acl,
23201 + .set_acl = aufs_set_acl,
23204 + .setattr = aufs_setattr,
23205 + .getattr = aufs_getattr,
23207 +#ifdef CONFIG_AUFS_XATTR
23208 + .listxattr = aufs_listxattr,
23211 + .update_time = aufs_update_time,
23212 + .atomic_open = aufs_atomic_open,
23213 + .tmpfile = aufs_tmpfile
23215 + [AuIop_OTHER] = {
23216 + .permission = aufs_permission,
23217 +#ifdef CONFIG_FS_POSIX_ACL
23218 + .get_inode_acl = aufs_get_inode_acl,
23219 + .get_acl = aufs_get_acl,
23220 + .set_acl = aufs_set_acl,
23223 + .setattr = aufs_setattr,
23224 + .getattr = aufs_getattr,
23226 +#ifdef CONFIG_AUFS_XATTR
23227 + .listxattr = aufs_listxattr,
23230 + .update_time = aufs_update_time
23233 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23234 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23235 +++ linux/fs/aufs/i_op_del.c 2023-09-03 02:21:58.859971007 +0200
23237 +// SPDX-License-Identifier: GPL-2.0
23239 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23241 + * This program is free software; you can redistribute it and/or modify
23242 + * it under the terms of the GNU General Public License as published by
23243 + * the Free Software Foundation; either version 2 of the License, or
23244 + * (at your option) any later version.
23246 + * This program is distributed in the hope that it will be useful,
23247 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23248 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23249 + * GNU General Public License for more details.
23251 + * You should have received a copy of the GNU General Public License
23252 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23256 + * inode operations (del entry)
23259 +#include <linux/iversion.h>
23263 + * decide if a new whiteout for @dentry is necessary or not.
23264 + * when it is necessary, prepare the parent dir for the upper branch whose
23265 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23266 + * be done by caller.
23268 + * 0: wh is unnecessary
23269 + * plus: wh is necessary
23272 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23274 + int need_wh, err;
23275 + aufs_bindex_t btop;
23276 + struct super_block *sb;
23278 + sb = dentry->d_sb;
23279 + btop = au_dbtop(dentry);
23280 + if (*bcpup < 0) {
23282 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23283 + err = AuWbrCopyup(au_sbi(sb), dentry);
23285 + if (unlikely(err < 0))
23289 + AuDebugOn(btop < *bcpup
23290 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23291 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23293 + if (*bcpup != btop) {
23294 + err = au_cpup_dirs(dentry, *bcpup);
23295 + if (unlikely(err))
23299 + struct au_dinfo *dinfo, *tmp;
23301 + need_wh = -ENOMEM;
23302 + dinfo = au_di(dentry);
23303 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23305 + au_di_cp(tmp, dinfo);
23306 + au_di_swap(tmp, dinfo);
23307 + /* returns the number of positive dentries */
23308 + need_wh = au_lkup_dentry(dentry, btop + 1,
23309 + /* AuLkup_IGNORE_PERM */ 0);
23310 + au_di_swap(tmp, dinfo);
23311 + au_rw_write_unlock(&tmp->di_rwsem);
23315 + AuDbg("need_wh %d\n", need_wh);
23323 + * simple tests for the del-entry operations.
23324 + * following the checks in vfs, plus the parent-child relationship.
23326 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23327 + struct dentry *h_parent, int isdir)
23331 + struct dentry *h_dentry, *h_latest;
23332 + struct inode *h_inode;
23333 + struct path h_ppath;
23334 + struct super_block *sb;
23335 + struct au_branch *br;
23336 + struct mnt_idmap *h_idmap;
23338 + h_dentry = au_h_dptr(dentry, bindex);
23339 + if (d_really_is_positive(dentry)) {
23341 + if (unlikely(d_is_negative(h_dentry)))
23343 + h_inode = d_inode(h_dentry);
23344 + if (unlikely(!h_inode->i_nlink))
23347 + h_mode = h_inode->i_mode;
23350 + if (unlikely(S_ISDIR(h_mode)))
23352 + } else if (unlikely(!S_ISDIR(h_mode))) {
23357 + /* rename(2) case */
23359 + if (unlikely(d_is_positive(h_dentry)))
23364 + /* expected parent dir is locked */
23365 + if (unlikely(h_parent != h_dentry->d_parent))
23370 + * rmdir a dir may break the consistency on some filesystem.
23371 + * let's try heavy test.
23374 + sb = dentry->d_sb;
23375 + br = au_sbr(sb, bindex);
23376 + h_idmap = au_br_idmap(br);
23377 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23378 + && au_test_h_perm(h_idmap, d_inode(h_parent),
23379 + MAY_EXEC | MAY_WRITE)))
23382 + h_ppath.dentry = h_parent;
23383 + h_ppath.mnt = au_br_mnt(br);
23384 + h_latest = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
23386 + if (IS_ERR(h_latest))
23388 + if (h_latest == h_dentry)
23397 + * decide the branch where we operate for @dentry. the branch index will be set
23398 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23399 + * dir for reverting.
23400 + * when a new whiteout is necessary, create it.
23402 +static struct dentry*
23403 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23404 + struct au_dtime *dt, struct au_pin *pin)
23406 + struct dentry *wh_dentry;
23407 + struct super_block *sb;
23408 + struct path h_path;
23409 + int err, need_wh;
23410 + unsigned int udba;
23411 + aufs_bindex_t bcpup;
23413 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23414 + wh_dentry = ERR_PTR(need_wh);
23415 + if (unlikely(need_wh < 0))
23418 + sb = dentry->d_sb;
23419 + udba = au_opt_udba(sb);
23421 + err = au_pin(pin, dentry, bcpup, udba,
23422 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23423 + wh_dentry = ERR_PTR(err);
23424 + if (unlikely(err))
23427 + h_path.dentry = au_pinned_h_parent(pin);
23428 + if (udba != AuOpt_UDBA_NONE
23429 + && au_dbtop(dentry) == bcpup) {
23430 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23431 + wh_dentry = ERR_PTR(err);
23432 + if (unlikely(err))
23436 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23437 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23438 + wh_dentry = NULL;
23440 + goto out; /* success, no need to create whiteout */
23442 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23443 + if (IS_ERR(wh_dentry))
23446 + /* returns with the parent is locked and wh_dentry is dget-ed */
23447 + goto out; /* success */
23452 + return wh_dentry;
23456 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23457 + * in order to be revertible and save time for removing many child whiteouts
23459 + * returns 1 when there are too many child whiteout and caller should remove
23460 + * them asynchronously. returns 0 when the number of children is enough small to
23461 + * remove now or the branch fs is a remote fs.
23462 + * otherwise return an error.
23464 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23465 + struct au_nhash *whlist, struct inode *dir)
23467 + int rmdir_later, err, dirwh;
23468 + struct dentry *h_dentry;
23469 + struct super_block *sb;
23470 + struct inode *inode;
23472 + sb = dentry->d_sb;
23473 + SiMustAnyLock(sb);
23474 + h_dentry = au_h_dptr(dentry, bindex);
23475 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23476 + if (unlikely(err))
23479 + /* stop monitoring */
23480 + inode = d_inode(dentry);
23481 + au_hn_free(au_hi(inode, bindex));
23483 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23484 + dirwh = au_sbi(sb)->si_dirwh;
23485 + rmdir_later = (dirwh <= 1);
23486 + if (!rmdir_later)
23487 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23490 + return rmdir_later;
23493 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23494 + if (unlikely(err)) {
23495 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23496 + h_dentry, bindex, err);
23506 + * final procedure for deleting a entry.
23507 + * maintain dentry and iattr.
23509 +static void epilog(struct inode *dir, struct dentry *dentry,
23510 + aufs_bindex_t bindex)
23512 + struct inode *inode;
23514 + inode = d_inode(dentry);
23516 + inode->i_ctime = dir->i_ctime;
23518 + au_dir_ts(dir, bindex);
23519 + inode_inc_iversion(dir);
23523 + * when an error happened, remove the created whiteout and revert everything.
23525 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23526 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23527 + struct dentry *dentry, struct au_dtime *dt)
23530 + struct path h_path = {
23531 + .dentry = wh_dentry,
23532 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23535 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23537 + au_set_dbwh(dentry, bwh);
23538 + au_dtime_revert(dt);
23542 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23546 +/* ---------------------------------------------------------------------- */
23548 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23551 + aufs_bindex_t bwh, bindex, btop;
23552 + struct inode *inode, *h_dir, *delegated;
23553 + struct dentry *parent, *wh_dentry;
23554 + /* to reduce stack size */
23556 + struct au_dtime dt;
23557 + struct au_pin pin;
23558 + struct path h_path;
23564 + a = kmalloc(sizeof(*a), GFP_NOFS);
23565 + if (unlikely(!a))
23568 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23569 + if (unlikely(err))
23571 + err = au_d_hashed_positive(dentry);
23572 + if (unlikely(err))
23574 + inode = d_inode(dentry);
23575 + IMustLock(inode);
23577 + if (unlikely(d_is_dir(dentry)))
23578 + goto out_unlock; /* possible? */
23580 + btop = au_dbtop(dentry);
23581 + bwh = au_dbwh(dentry);
23583 + parent = dentry->d_parent; /* dir inode is locked */
23584 + di_write_lock_parent(parent);
23585 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23587 + err = PTR_ERR(wh_dentry);
23588 + if (IS_ERR(wh_dentry))
23591 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23592 + a->h_path.dentry = au_h_dptr(dentry, btop);
23593 + dget(a->h_path.dentry);
23594 + if (bindex == btop) {
23595 + h_dir = au_pinned_h_dir(&a->pin);
23596 + delegated = NULL;
23597 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23598 + if (unlikely(err == -EWOULDBLOCK)) {
23599 + pr_warn("cannot retry for NFSv4 delegation"
23600 + " for an internal unlink\n");
23604 + /* dir inode is locked */
23605 + h_dir = d_inode(wh_dentry->d_parent);
23606 + IMustLock(h_dir);
23611 + vfsub_drop_nlink(inode);
23612 + epilog(dir, dentry, bindex);
23614 + /* update target timestamps */
23615 + if (bindex == btop) {
23616 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23618 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23620 + /* todo: this timestamp may be reverted later */
23621 + inode->i_ctime = h_dir->i_ctime;
23622 + goto out_unpin; /* success */
23629 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23636 + au_unpin(&a->pin);
23638 + dput(a->h_path.dentry);
23640 + di_write_unlock(parent);
23642 + aufs_read_unlock(dentry, AuLock_DW);
23649 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23651 + int err, rmdir_later;
23652 + aufs_bindex_t bwh, bindex, btop;
23653 + struct inode *inode;
23654 + struct dentry *parent, *wh_dentry, *h_dentry;
23655 + struct au_whtmp_rmdir *args;
23656 + /* to reduce stack size */
23658 + struct au_dtime dt;
23659 + struct au_pin pin;
23665 + a = kmalloc(sizeof(*a), GFP_NOFS);
23666 + if (unlikely(!a))
23669 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23670 + if (unlikely(err))
23672 + err = au_alive_dir(dentry);
23673 + if (unlikely(err))
23675 + inode = d_inode(dentry);
23676 + IMustLock(inode);
23678 + if (unlikely(!d_is_dir(dentry)))
23679 + goto out_unlock; /* possible? */
23682 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23683 + if (unlikely(!args))
23686 + parent = dentry->d_parent; /* dir inode is locked */
23687 + di_write_lock_parent(parent);
23688 + err = au_test_empty(dentry, &args->whlist);
23689 + if (unlikely(err))
23692 + btop = au_dbtop(dentry);
23693 + bwh = au_dbwh(dentry);
23695 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23697 + err = PTR_ERR(wh_dentry);
23698 + if (IS_ERR(wh_dentry))
23701 + h_dentry = au_h_dptr(dentry, btop);
23704 + if (bindex == btop) {
23705 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23707 + rmdir_later = err;
23711 + /* stop monitoring */
23712 + au_hn_free(au_hi(inode, btop));
23714 + /* dir inode is locked */
23715 + IMustLock(d_inode(wh_dentry->d_parent));
23720 + vfsub_dead_dir(inode);
23721 + au_set_dbdiropq(dentry, -1);
23722 + epilog(dir, dentry, bindex);
23724 + if (rmdir_later) {
23725 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23729 + goto out_unpin; /* success */
23737 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23744 + au_unpin(&a->pin);
23748 + di_write_unlock(parent);
23750 + au_whtmp_rmdir_free(args);
23752 + aufs_read_unlock(dentry, AuLock_DW);
23759 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23760 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23761 +++ linux/fs/aufs/i_op_ren.c 2023-09-03 02:21:58.863304341 +0200
23763 +// SPDX-License-Identifier: GPL-2.0
23765 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23767 + * This program is free software; you can redistribute it and/or modify
23768 + * it under the terms of the GNU General Public License as published by
23769 + * the Free Software Foundation; either version 2 of the License, or
23770 + * (at your option) any later version.
23772 + * This program is distributed in the hope that it will be useful,
23773 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23774 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23775 + * GNU General Public License for more details.
23777 + * You should have received a copy of the GNU General Public License
23778 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23782 + * inode operation (rename entry)
23783 + * todo: this is crazy monster
23786 +#include <linux/iversion.h>
23789 +enum { AuSRC, AuDST, AuSrcDst };
23790 +enum { AuPARENT, AuCHILD, AuParentChild };
23792 +#define AuRen_ISDIR_SRC 1
23793 +#define AuRen_ISDIR_DST (1 << 1)
23794 +#define AuRen_ISSAMEDIR (1 << 2)
23795 +#define AuRen_WHSRC (1 << 3)
23796 +#define AuRen_WHDST (1 << 4)
23797 +#define AuRen_MNT_WRITE (1 << 5)
23798 +#define AuRen_DT_DSTDIR (1 << 6)
23799 +#define AuRen_DIROPQ_SRC (1 << 7)
23800 +#define AuRen_DIROPQ_DST (1 << 8)
23801 +#define AuRen_DIRREN (1 << 9)
23802 +#define AuRen_DROPPED_SRC (1 << 10)
23803 +#define AuRen_DROPPED_DST (1 << 11)
23804 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23805 +#define au_fset_ren(flags, name) \
23806 + do { (flags) |= AuRen_##name; } while (0)
23807 +#define au_fclr_ren(flags, name) \
23808 + do { (flags) &= ~AuRen_##name; } while (0)
23810 +#ifndef CONFIG_AUFS_DIRREN
23811 +#undef AuRen_DIRREN
23812 +#define AuRen_DIRREN 0
23815 +struct au_ren_args {
23817 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23819 + struct inode *dir, *inode;
23820 + struct au_hinode *hdir, *hinode;
23821 + struct au_dtime dt[AuParentChild];
23822 + aufs_bindex_t btop, bdiropq;
23825 +#define src_dentry sd[AuSRC].dentry
23826 +#define src_dir sd[AuSRC].dir
23827 +#define src_inode sd[AuSRC].inode
23828 +#define src_h_dentry sd[AuSRC].h_dentry
23829 +#define src_parent sd[AuSRC].parent
23830 +#define src_h_parent sd[AuSRC].h_parent
23831 +#define src_wh_dentry sd[AuSRC].wh_dentry
23832 +#define src_hdir sd[AuSRC].hdir
23833 +#define src_hinode sd[AuSRC].hinode
23834 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23835 +#define src_dt sd[AuSRC].dt
23836 +#define src_btop sd[AuSRC].btop
23837 +#define src_bdiropq sd[AuSRC].bdiropq
23839 +#define dst_dentry sd[AuDST].dentry
23840 +#define dst_dir sd[AuDST].dir
23841 +#define dst_inode sd[AuDST].inode
23842 +#define dst_h_dentry sd[AuDST].h_dentry
23843 +#define dst_parent sd[AuDST].parent
23844 +#define dst_h_parent sd[AuDST].h_parent
23845 +#define dst_wh_dentry sd[AuDST].wh_dentry
23846 +#define dst_hdir sd[AuDST].hdir
23847 +#define dst_hinode sd[AuDST].hinode
23848 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23849 +#define dst_dt sd[AuDST].dt
23850 +#define dst_btop sd[AuDST].btop
23851 +#define dst_bdiropq sd[AuDST].bdiropq
23853 + struct dentry *h_trap;
23854 + struct au_branch *br;
23855 + struct path h_path;
23856 + struct au_nhash whlist;
23857 + aufs_bindex_t btgt, src_bwh;
23860 + unsigned short auren_flags;
23861 + unsigned char flags; /* syscall parameter */
23862 + unsigned char exchange;
23865 + struct au_whtmp_rmdir *thargs;
23866 + struct dentry *h_dst;
23867 + struct au_hinode *h_root;
23870 +/* ---------------------------------------------------------------------- */
23873 + * functions for reverting.
23874 + * when an error happened in a single rename systemcall, we should revert
23875 + * everything as if nothing happened.
23876 + * we don't need to revert the copied-up/down the parent dir since they are
23880 +#define RevertFailure(fmt, ...) do { \
23881 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23882 + ##__VA_ARGS__, err, rerr); \
23886 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23889 + struct dentry *d;
23890 +#define src_or_dst(member) a->sd[idx].member
23892 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23893 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23894 + rerr = au_diropq_remove(d, a->btgt);
23895 + au_hn_inode_unlock(src_or_dst(hinode));
23896 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23898 + RevertFailure("remove diropq %pd", d);
23900 +#undef src_or_dst_
23903 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23905 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23906 + au_ren_do_rev_diropq(err, a, AuSRC);
23907 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23908 + au_ren_do_rev_diropq(err, a, AuDST);
23911 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23914 + struct inode *delegated;
23915 + struct path h_ppath = {
23916 + .dentry = a->src_h_parent,
23917 + .mnt = a->h_path.mnt
23920 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23921 + rerr = PTR_ERR(a->h_path.dentry);
23922 + if (IS_ERR(a->h_path.dentry)) {
23923 + RevertFailure("lkup one %pd", a->src_dentry);
23927 + delegated = NULL;
23928 + rerr = vfsub_rename(a->dst_h_dir,
23929 + au_h_dptr(a->src_dentry, a->btgt),
23930 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23931 + if (unlikely(rerr == -EWOULDBLOCK)) {
23932 + pr_warn("cannot retry for NFSv4 delegation"
23933 + " for an internal rename\n");
23936 + d_drop(a->h_path.dentry);
23937 + dput(a->h_path.dentry);
23938 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23940 + RevertFailure("rename %pd", a->src_dentry);
23943 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23946 + struct inode *delegated;
23947 + struct path h_ppath = {
23948 + .dentry = a->dst_h_parent,
23949 + .mnt = a->h_path.mnt
23952 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23953 + rerr = PTR_ERR(a->h_path.dentry);
23954 + if (IS_ERR(a->h_path.dentry)) {
23955 + RevertFailure("lkup one %pd", a->dst_dentry);
23958 + if (d_is_positive(a->h_path.dentry)) {
23959 + d_drop(a->h_path.dentry);
23960 + dput(a->h_path.dentry);
23964 + delegated = NULL;
23965 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23966 + &delegated, a->flags);
23967 + if (unlikely(rerr == -EWOULDBLOCK)) {
23968 + pr_warn("cannot retry for NFSv4 delegation"
23969 + " for an internal rename\n");
23972 + d_drop(a->h_path.dentry);
23973 + dput(a->h_path.dentry);
23975 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23977 + RevertFailure("rename %pd", a->h_dst);
23980 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23984 + a->h_path.dentry = a->src_wh_dentry;
23985 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23986 + au_set_dbwh(a->src_dentry, a->src_bwh);
23988 + RevertFailure("unlink %pd", a->src_wh_dentry);
23990 +#undef RevertFailure
23992 +/* ---------------------------------------------------------------------- */
23995 + * when we have to copyup the renaming entry, do it with the rename-target name
23996 + * in order to minimize the cost (the later actual rename is unnecessary).
23997 + * otherwise rename it on the target branch.
23999 +static int au_ren_or_cpup(struct au_ren_args *a)
24002 + struct dentry *d;
24003 + struct inode *delegated;
24005 + d = a->src_dentry;
24006 + if (au_dbtop(d) == a->btgt) {
24007 + a->h_path.dentry = a->dst_h_dentry;
24008 + AuDebugOn(au_dbtop(d) != a->btgt);
24009 + delegated = NULL;
24010 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24011 + a->dst_h_dir, &a->h_path, &delegated,
24013 + if (unlikely(err == -EWOULDBLOCK)) {
24014 + pr_warn("cannot retry for NFSv4 delegation"
24015 + " for an internal rename\n");
24021 + if (!err && a->h_dst)
24022 + /* it will be set to dinfo later */
24028 +/* cf. aufs_rmdir() */
24029 +static int au_ren_del_whtmp(struct au_ren_args *a)
24032 + struct inode *dir;
24034 + dir = a->dst_dir;
24035 + SiMustAnyLock(dir->i_sb);
24036 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24037 + au_sbi(dir->i_sb)->si_dirwh)
24038 + || au_test_fs_remote(a->h_dst->d_sb)) {
24039 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24040 + if (unlikely(err))
24041 + pr_warn("failed removing whtmp dir %pd (%d), "
24042 + "ignored.\n", a->h_dst, err);
24044 + au_nhash_wh_free(&a->thargs->whlist);
24045 + a->thargs->whlist = a->whlist;
24046 + a->whlist.nh_num = 0;
24047 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24049 + a->thargs = NULL;
24055 +/* make it 'opaque' dir. */
24056 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24059 + struct dentry *d, *diropq;
24060 +#define src_or_dst(member) a->sd[idx].member
24063 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24064 + src_or_dst(bdiropq) = au_dbdiropq(d);
24065 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24066 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24067 + diropq = au_diropq_create(d, a->btgt);
24068 + au_hn_inode_unlock(src_or_dst(hinode));
24069 + if (IS_ERR(diropq))
24070 + err = PTR_ERR(diropq);
24074 +#undef src_or_dst_
24078 +static int au_ren_diropq(struct au_ren_args *a)
24081 + unsigned char always;
24082 + struct dentry *d;
24085 + d = a->dst_dentry; /* already renamed on the branch */
24086 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24087 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24088 + && !au_ftest_ren(a->auren_flags, DIRREN)
24089 + && a->btgt != au_dbdiropq(a->src_dentry)
24090 + && (a->dst_wh_dentry
24091 + || a->btgt <= au_dbdiropq(d)
24092 + /* hide the lower to keep xino */
24093 + /* the lowers may not be a dir, but we hide them anyway */
24094 + || a->btgt < au_dbbot(d)
24097 + err = au_ren_do_diropq(a, AuSRC);
24098 + if (unlikely(err))
24100 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24102 + if (!a->exchange)
24103 + goto out; /* success */
24105 + d = a->src_dentry; /* already renamed on the branch */
24106 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24107 + && a->btgt != au_dbdiropq(a->dst_dentry)
24108 + && (a->btgt < au_dbdiropq(d)
24109 + || a->btgt < au_dbbot(d)
24111 + AuDbgDentry(a->src_dentry);
24112 + AuDbgDentry(a->dst_dentry);
24113 + err = au_ren_do_diropq(a, AuDST);
24114 + if (unlikely(err))
24115 + goto out_rev_src;
24116 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24118 + goto out; /* success */
24121 + AuDbg("err %d, reverting src\n", err);
24122 + au_ren_rev_diropq(err, a);
24127 +static int do_rename(struct au_ren_args *a)
24130 + struct dentry *d, *h_d;
24132 + if (!a->exchange) {
24133 + /* prepare workqueue args for asynchronous rmdir */
24134 + h_d = a->dst_h_dentry;
24135 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24136 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24137 + && d_is_positive(h_d)) {
24139 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24141 + if (unlikely(!a->thargs))
24143 + a->h_dst = dget(h_d);
24146 + /* create whiteout for src_dentry */
24147 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24148 + a->src_bwh = au_dbwh(a->src_dentry);
24149 + AuDebugOn(a->src_bwh >= 0);
24150 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24151 + a->src_h_parent);
24152 + err = PTR_ERR(a->src_wh_dentry);
24153 + if (IS_ERR(a->src_wh_dentry))
24157 + /* lookup whiteout for dentry */
24158 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24159 + h_d = au_wh_lkup(a->dst_h_parent,
24160 + &a->dst_dentry->d_name, a->br);
24161 + err = PTR_ERR(h_d);
24164 + if (d_is_negative(h_d))
24167 + a->dst_wh_dentry = h_d;
24170 + /* rename dentry to tmpwh */
24172 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24173 + if (unlikely(err))
24176 + d = a->dst_dentry;
24177 + au_set_h_dptr(d, a->btgt, NULL);
24178 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24179 + if (unlikely(err))
24181 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24185 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24186 +#if 0 /* debugging */
24187 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24188 + && d_is_positive(a->dst_h_dentry)
24189 + && a->src_btop != a->btgt);
24192 + /* rename by vfs_rename or cpup */
24193 + err = au_ren_or_cpup(a);
24194 + if (unlikely(err))
24195 + /* leave the copied-up one */
24198 + /* make dir opaque */
24199 + err = au_ren_diropq(a);
24200 + if (unlikely(err))
24203 + /* update target timestamps */
24204 + if (a->exchange) {
24205 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24206 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24207 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24208 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24210 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24211 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24212 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24213 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24215 + if (!a->exchange) {
24216 + /* remove whiteout for dentry */
24217 + if (a->dst_wh_dentry) {
24218 + a->h_path.dentry = a->dst_wh_dentry;
24219 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24221 + if (unlikely(err))
24225 + /* remove whtmp */
24227 + au_ren_del_whtmp(a); /* ignore this error */
24229 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24232 + goto out_success;
24235 + au_ren_rev_diropq(err, a);
24237 + au_ren_rev_rename(err, a);
24241 + au_ren_rev_whtmp(err, a);
24243 + dput(a->dst_wh_dentry);
24244 + a->dst_wh_dentry = NULL;
24246 + if (a->src_wh_dentry)
24247 + au_ren_rev_whsrc(err, a);
24249 + dput(a->src_wh_dentry);
24250 + dput(a->dst_wh_dentry);
24254 + au_whtmp_rmdir_free(a->thargs);
24255 + a->thargs = NULL;
24261 +/* ---------------------------------------------------------------------- */
24264 + * test if @dentry dir can be rename destination or not.
24265 + * success means, it is a logically empty dir.
24267 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24269 + return au_test_empty(dentry, whlist);
24273 + * test if @a->src_dentry dir can be rename source or not.
24274 + * if it can, return 0.
24276 + * - it is a logically empty dir.
24277 + * - or, it exists on writable branch and has no children including whiteouts
24278 + * on the lower branch unless DIRREN is on.
24280 +static int may_rename_srcdir(struct au_ren_args *a)
24283 + unsigned int rdhash;
24284 + aufs_bindex_t btop, btgt;
24285 + struct dentry *dentry;
24286 + struct super_block *sb;
24287 + struct au_sbinfo *sbinfo;
24289 + dentry = a->src_dentry;
24290 + sb = dentry->d_sb;
24291 + sbinfo = au_sbi(sb);
24292 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24293 + au_fset_ren(a->auren_flags, DIRREN);
24296 + btop = au_dbtop(dentry);
24297 + if (btop != btgt) {
24298 + struct au_nhash whlist;
24300 + SiMustAnyLock(sb);
24301 + rdhash = sbinfo->si_rdhash;
24303 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24305 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24306 + if (unlikely(err))
24308 + err = au_test_empty(dentry, &whlist);
24309 + au_nhash_wh_free(&whlist);
24313 + if (btop == au_dbtaildir(dentry))
24314 + return 0; /* success */
24316 + err = au_test_empty_lower(dentry);
24319 + if (err == -ENOTEMPTY) {
24320 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24323 + AuWarn1("renaming dir who has child(ren) on multiple "
24324 + "branches, is not supported\n");
24331 +/* side effect: sets whlist and h_dentry */
24332 +static int au_ren_may_dir(struct au_ren_args *a)
24335 + unsigned int rdhash;
24336 + struct dentry *d;
24338 + d = a->dst_dentry;
24339 + SiMustAnyLock(d->d_sb);
24342 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24343 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24345 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24346 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24347 + if (unlikely(err))
24350 + if (!a->exchange) {
24351 + au_set_dbtop(d, a->dst_btop);
24352 + err = may_rename_dstdir(d, &a->whlist);
24353 + au_set_dbtop(d, a->btgt);
24355 + err = may_rename_srcdir(a);
24357 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24358 + if (unlikely(err))
24361 + d = a->src_dentry;
24362 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24363 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24364 + err = may_rename_srcdir(a);
24365 + if (unlikely(err)) {
24366 + au_nhash_wh_free(&a->whlist);
24367 + a->whlist.nh_num = 0;
24374 +/* ---------------------------------------------------------------------- */
24377 + * simple tests for rename.
24378 + * following the checks in vfs, plus the parent-child relationship.
24380 +static int au_may_ren(struct au_ren_args *a)
24383 + struct inode *h_inode;
24385 + if (a->src_btop == a->btgt) {
24386 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24387 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24388 + if (unlikely(err))
24391 + if (unlikely(a->src_h_dentry == a->h_trap))
24396 + if (a->dst_btop != a->btgt)
24399 + err = -ENOTEMPTY;
24400 + if (unlikely(a->dst_h_dentry == a->h_trap))
24404 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24405 + if (d_really_is_negative(a->dst_dentry)) {
24406 + if (d_is_negative(a->dst_h_dentry))
24407 + err = au_may_add(a->dst_dentry, a->btgt,
24408 + a->dst_h_parent, isdir);
24410 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24412 + h_inode = d_inode(a->dst_h_dentry);
24413 + if (h_inode->i_nlink)
24414 + err = au_may_del(a->dst_dentry, a->btgt,
24415 + a->dst_h_parent, isdir);
24419 + if (unlikely(err == -ENOENT || err == -EEXIST))
24425 +/* ---------------------------------------------------------------------- */
24430 + * - src_dir and dir by lock_rename()
24431 + * - inode if exists
24434 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24436 + * + di_write_lock2_child()
24437 + * + di_write_lock_child()
24438 + * + ii_write_lock_child()
24439 + * + di_write_lock_child2()
24440 + * + ii_write_lock_child2()
24441 + * + src_parent and parent
24442 + * + di_write_lock_parent()
24443 + * + ii_write_lock_parent()
24444 + * + di_write_lock_parent2()
24445 + * + ii_write_lock_parent2()
24446 + * + lower src_dir and dir by vfsub_lock_rename()
24447 + * + verify the every relationships between child and parent. if any
24448 + * of them failed, unlock all and return -EBUSY.
24450 +static void au_ren_unlock(struct au_ren_args *a)
24452 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24453 + a->dst_h_parent, a->dst_hdir);
24454 + if (au_ftest_ren(a->auren_flags, DIRREN)
24456 + au_hn_inode_unlock(a->h_root);
24457 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24458 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24461 +static int au_ren_lock(struct au_ren_args *a)
24464 + unsigned int udba;
24467 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24468 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24469 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24470 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24472 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24473 + if (unlikely(err))
24475 + au_fset_ren(a->auren_flags, MNT_WRITE);
24476 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24477 + struct dentry *root;
24478 + struct inode *dir;
24481 + * sbinfo is already locked, so this ii_read_lock is
24482 + * unnecessary. but our debugging feature checks it.
24484 + root = a->src_inode->i_sb->s_root;
24485 + if (root != a->src_parent && root != a->dst_parent) {
24486 + dir = d_inode(root);
24487 + ii_read_lock_parent3(dir);
24488 + a->h_root = au_hi(dir, a->btgt);
24489 + ii_read_unlock(dir);
24490 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24493 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24494 + a->dst_h_parent, a->dst_hdir);
24495 + udba = au_opt_udba(a->src_dentry->d_sb);
24496 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24497 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24498 + err = au_busy_or_stale();
24499 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24500 + err = au_h_verify(a->src_h_dentry, udba,
24501 + d_inode(a->src_h_parent), a->src_h_parent,
24503 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24504 + err = au_h_verify(a->dst_h_dentry, udba,
24505 + d_inode(a->dst_h_parent), a->dst_h_parent,
24508 + goto out; /* success */
24510 + err = au_busy_or_stale();
24511 + au_ren_unlock(a);
24517 +/* ---------------------------------------------------------------------- */
24519 +static void au_ren_refresh_dir(struct au_ren_args *a)
24521 + struct inode *dir;
24523 + dir = a->dst_dir;
24524 + inode_inc_iversion(dir);
24525 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24526 + /* is this updating defined in POSIX? */
24527 + au_cpup_attr_timesizes(a->src_inode);
24528 + au_cpup_attr_nlink(dir, /*force*/1);
24530 + au_dir_ts(dir, a->btgt);
24532 + if (a->exchange) {
24533 + dir = a->src_dir;
24534 + inode_inc_iversion(dir);
24535 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24536 + /* is this updating defined in POSIX? */
24537 + au_cpup_attr_timesizes(a->dst_inode);
24538 + au_cpup_attr_nlink(dir, /*force*/1);
24540 + au_dir_ts(dir, a->btgt);
24543 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24546 + dir = a->src_dir;
24547 + inode_inc_iversion(dir);
24548 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24549 + au_cpup_attr_nlink(dir, /*force*/1);
24550 + au_dir_ts(dir, a->btgt);
24553 +static void au_ren_refresh(struct au_ren_args *a)
24555 + aufs_bindex_t bbot, bindex;
24556 + struct dentry *d, *h_d;
24557 + struct inode *i, *h_i;
24558 + struct super_block *sb;
24560 + d = a->dst_dentry;
24563 + /* already dget-ed by au_ren_or_cpup() */
24564 + au_set_h_dptr(d, a->btgt, a->h_dst);
24566 + i = a->dst_inode;
24568 + if (!a->exchange) {
24569 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24570 + vfsub_drop_nlink(i);
24572 + vfsub_dead_dir(i);
24573 + au_cpup_attr_timesizes(i);
24575 + au_update_dbrange(d, /*do_put_zero*/1);
24577 + au_cpup_attr_nlink(i, /*force*/1);
24580 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24581 + au_set_h_dptr(d, bindex, NULL);
24582 + bbot = au_dbbot(d);
24583 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24584 + au_set_h_dptr(d, bindex, NULL);
24585 + au_update_dbrange(d, /*do_put_zero*/0);
24589 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24590 + d_drop(a->src_dentry);
24591 + if (au_ftest_ren(a->auren_flags, DIRREN))
24592 + au_set_dbwh(a->src_dentry, -1);
24596 + d = a->src_dentry;
24597 + au_set_dbwh(d, -1);
24598 + bbot = au_dbbot(d);
24599 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24600 + h_d = au_h_dptr(d, bindex);
24602 + au_set_h_dptr(d, bindex, NULL);
24604 + au_set_dbbot(d, a->btgt);
24607 + i = a->src_inode;
24608 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24609 + return; /* success */
24611 + bbot = au_ibbot(i);
24612 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24613 + h_i = au_h_iptr(i, bindex);
24615 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24616 + /* ignore this error */
24617 + au_set_h_iptr(i, bindex, NULL, 0);
24620 + au_set_ibbot(i, a->btgt);
24623 +/* ---------------------------------------------------------------------- */
24625 +/* mainly for link(2) and rename(2) */
24626 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24628 + aufs_bindex_t bdiropq, bwh;
24629 + struct dentry *parent;
24630 + struct au_branch *br;
24632 + parent = dentry->d_parent;
24633 + IMustLock(d_inode(parent)); /* dir is locked */
24635 + bdiropq = au_dbdiropq(parent);
24636 + bwh = au_dbwh(dentry);
24637 + br = au_sbr(dentry->d_sb, btgt);
24638 + if (au_br_rdonly(br)
24639 + || (0 <= bdiropq && bdiropq < btgt)
24640 + || (0 <= bwh && bwh < btgt))
24643 + AuDbg("btgt %d\n", btgt);
24647 +/* sets src_btop, dst_btop and btgt */
24648 +static int au_ren_wbr(struct au_ren_args *a)
24651 + struct au_wr_dir_args wr_dir_args = {
24652 + /* .force_btgt = -1, */
24653 + .flags = AuWrDir_ADD_ENTRY
24656 + a->src_btop = au_dbtop(a->src_dentry);
24657 + a->dst_btop = au_dbtop(a->dst_dentry);
24658 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24659 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24660 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24661 + wr_dir_args.force_btgt = a->src_btop;
24662 + if (a->dst_inode && a->dst_btop < a->src_btop)
24663 + wr_dir_args.force_btgt = a->dst_btop;
24664 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24665 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24668 + au_update_dbtop(a->dst_dentry);
24673 +static void au_ren_dt(struct au_ren_args *a)
24675 + a->h_path.dentry = a->src_h_parent;
24676 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24677 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24678 + a->h_path.dentry = a->dst_h_parent;
24679 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24682 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24683 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24687 + a->h_path.dentry = a->src_h_dentry;
24688 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24689 + if (d_is_positive(a->dst_h_dentry)) {
24690 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24691 + a->h_path.dentry = a->dst_h_dentry;
24692 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24696 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24698 + struct dentry *h_d;
24699 + struct inode *h_inode;
24701 + au_dtime_revert(a->src_dt + AuPARENT);
24702 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24703 + au_dtime_revert(a->dst_dt + AuPARENT);
24705 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24706 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24707 + h_inode = d_inode(h_d);
24708 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24709 + au_dtime_revert(a->src_dt + AuCHILD);
24710 + inode_unlock(h_inode);
24712 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24713 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24714 + h_inode = d_inode(h_d);
24715 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24716 + au_dtime_revert(a->dst_dt + AuCHILD);
24717 + inode_unlock(h_inode);
24722 +/* ---------------------------------------------------------------------- */
24724 +int aufs_rename(struct mnt_idmap *idmap,
24725 + struct inode *_src_dir, struct dentry *_src_dentry,
24726 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24727 + unsigned int _flags)
24729 + int err, lock_flags;
24731 + /* reduce stack space */
24732 + struct au_ren_args *a;
24733 + struct au_pin pin;
24735 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24736 + IMustLock(_src_dir);
24737 + IMustLock(_dst_dir);
24740 + if (unlikely(_flags & RENAME_WHITEOUT))
24744 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24745 + a = kzalloc(sizeof(*a), GFP_NOFS);
24746 + if (unlikely(!a))
24749 + a->flags = _flags;
24750 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24751 + && RENAME_EXCHANGE > U8_MAX);
24752 + a->exchange = _flags & RENAME_EXCHANGE;
24753 + a->src_dir = _src_dir;
24754 + a->src_dentry = _src_dentry;
24755 + a->src_inode = NULL;
24756 + if (d_really_is_positive(a->src_dentry))
24757 + a->src_inode = d_inode(a->src_dentry);
24758 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24759 + a->dst_dir = _dst_dir;
24760 + a->dst_dentry = _dst_dentry;
24761 + a->dst_inode = NULL;
24762 + if (d_really_is_positive(a->dst_dentry))
24763 + a->dst_inode = d_inode(a->dst_dentry);
24764 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24765 + if (a->dst_inode) {
24767 + * if EXCHANGE && src is non-dir && dst is dir,
24768 + * dst is not locked.
24770 + /* IMustLock(a->dst_inode); */
24771 + au_igrab(a->dst_inode);
24775 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24776 + if (d_is_dir(a->src_dentry)) {
24777 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24778 + if (unlikely(!a->exchange
24779 + && d_really_is_positive(a->dst_dentry)
24780 + && !d_is_dir(a->dst_dentry)))
24782 + lock_flags |= AuLock_DIRS;
24784 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24785 + au_fset_ren(a->auren_flags, ISDIR_DST);
24786 + if (unlikely(!a->exchange
24787 + && d_really_is_positive(a->src_dentry)
24788 + && !d_is_dir(a->src_dentry)))
24790 + lock_flags |= AuLock_DIRS;
24792 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24794 + if (unlikely(err))
24797 + err = au_d_hashed_positive(a->src_dentry);
24798 + if (unlikely(err))
24801 + if (a->dst_inode) {
24803 + * If it is a dir, VFS unhash it before this
24804 + * function. It means we cannot rely upon d_unhashed().
24806 + if (unlikely(!a->dst_inode->i_nlink))
24808 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24809 + err = au_d_hashed_positive(a->dst_dentry);
24810 + if (unlikely(err && !a->exchange))
24812 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24814 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24818 + * is it possible?
24819 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24820 + * there may exist a problem somewhere else.
24823 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24826 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24827 + di_write_lock_parent(a->dst_parent);
24829 + /* which branch we process */
24830 + err = au_ren_wbr(a);
24831 + if (unlikely(err < 0))
24833 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24834 + a->h_path.mnt = au_br_mnt(a->br);
24836 + /* are they available to be renamed */
24837 + err = au_ren_may_dir(a);
24838 + if (unlikely(err))
24839 + goto out_children;
24841 + /* prepare the writable parent dir on the same branch */
24842 + if (a->dst_btop == a->btgt) {
24843 + au_fset_ren(a->auren_flags, WHDST);
24845 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24846 + if (unlikely(err))
24847 + goto out_children;
24851 + if (!a->exchange) {
24852 + if (a->src_dir != a->dst_dir) {
24854 + * this temporary unlock is safe,
24855 + * because both dir->i_mutex are locked.
24857 + di_write_unlock(a->dst_parent);
24858 + di_write_lock_parent(a->src_parent);
24859 + err = au_wr_dir_need_wh(a->src_dentry,
24860 + au_ftest_ren(a->auren_flags,
24863 + di_write_unlock(a->src_parent);
24864 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24866 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24868 + err = au_wr_dir_need_wh(a->src_dentry,
24869 + au_ftest_ren(a->auren_flags,
24873 + if (unlikely(err < 0))
24874 + goto out_children;
24876 + au_fset_ren(a->auren_flags, WHSRC);
24879 + if (a->src_btop != a->btgt) {
24880 + err = au_pin(&pin, a->src_dentry, a->btgt,
24881 + au_opt_udba(a->src_dentry->d_sb),
24882 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24884 + struct au_cp_generic cpg = {
24885 + .dentry = a->src_dentry,
24887 + .bsrc = a->src_btop,
24890 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24892 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24893 + err = au_sio_cpup_simple(&cpg);
24896 + if (unlikely(err))
24897 + goto out_children;
24898 + a->src_btop = a->btgt;
24899 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24900 + if (!a->exchange)
24901 + au_fset_ren(a->auren_flags, WHSRC);
24905 + if (a->exchange && a->dst_inode
24906 + && a->dst_btop != a->btgt) {
24907 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24908 + au_opt_udba(a->dst_dentry->d_sb),
24909 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24911 + struct au_cp_generic cpg = {
24912 + .dentry = a->dst_dentry,
24914 + .bsrc = a->dst_btop,
24917 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24919 + err = au_sio_cpup_simple(&cpg);
24922 + if (unlikely(err))
24923 + goto out_children;
24924 + a->dst_btop = a->btgt;
24925 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24928 + /* lock them all */
24929 + err = au_ren_lock(a);
24930 + if (unlikely(err))
24931 + /* leave the copied-up one */
24932 + goto out_children;
24934 + if (!a->exchange) {
24935 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24936 + err = au_may_ren(a);
24937 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24938 + err = -ENAMETOOLONG;
24939 + if (unlikely(err))
24943 + /* store timestamps to be revertible */
24946 + /* store dirren info */
24947 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24948 + err = au_dr_rename(a->src_dentry, a->btgt,
24949 + &a->dst_dentry->d_name, &rev);
24951 + if (unlikely(err))
24956 + err = do_rename(a);
24957 + if (unlikely(err))
24960 + if (au_ftest_ren(a->auren_flags, DIRREN))
24961 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24963 + /* update dir attributes */
24964 + au_ren_refresh_dir(a);
24966 + /* dput/iput all lower dentries */
24967 + au_ren_refresh(a);
24969 + goto out_hdir; /* success */
24972 + if (au_ftest_ren(a->auren_flags, DIRREN))
24973 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24975 + au_ren_rev_dt(err, a);
24977 + au_ren_unlock(a);
24979 + au_nhash_wh_free(&a->whlist);
24980 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24981 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24982 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24983 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24987 + if (d_unhashed(a->src_dentry))
24988 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24989 + if (d_unhashed(a->dst_dentry))
24990 + au_fset_ren(a->auren_flags, DROPPED_DST);
24991 + if (!a->exchange)
24992 + d_move(a->src_dentry, a->dst_dentry);
24994 + d_exchange(a->src_dentry, a->dst_dentry);
24995 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24996 + d_drop(a->dst_dentry);
24998 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
24999 + d_drop(a->src_dentry);
25001 + au_update_dbtop(a->dst_dentry);
25002 + if (!a->dst_inode)
25003 + d_drop(a->dst_dentry);
25005 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25006 + di_write_unlock(a->dst_parent);
25008 + di_write_unlock2(a->src_parent, a->dst_parent);
25010 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25012 + iput(a->dst_inode);
25014 + au_whtmp_rmdir_free(a->thargs);
25020 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25021 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25022 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
25024 +# SPDX-License-Identifier: GPL-2.0
25026 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25028 + Aufs is a stackable unification filesystem such as Unionfs,
25029 + which unifies several directories and provides a merged single
25031 + In the early days, aufs was entirely re-designed and
25032 + re-implemented Unionfs Version 1.x series. Introducing many
25033 + original ideas, approaches and improvements, it becomes totally
25034 + different from Unionfs while keeping the basic features.
25038 + prompt "Maximum number of branches"
25039 + default AUFS_BRANCH_MAX_127
25041 + Specifies the maximum number of branches (or member directories)
25042 + in a single aufs. The larger value consumes more system
25043 + resources and has a minor impact to performance.
25044 +config AUFS_BRANCH_MAX_127
25047 + Specifies the maximum number of branches (or member directories)
25048 + in a single aufs. The larger value consumes more system
25049 + resources and has a minor impact to performance.
25050 +config AUFS_BRANCH_MAX_511
25053 + Specifies the maximum number of branches (or member directories)
25054 + in a single aufs. The larger value consumes more system
25055 + resources and has a minor impact to performance.
25056 +config AUFS_BRANCH_MAX_1023
25059 + Specifies the maximum number of branches (or member directories)
25060 + in a single aufs. The larger value consumes more system
25061 + resources and has a minor impact to performance.
25062 +config AUFS_BRANCH_MAX_32767
25065 + Specifies the maximum number of branches (or member directories)
25066 + in a single aufs. The larger value consumes more system
25067 + resources and has a minor impact to performance.
25070 +config AUFS_SBILIST
25072 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25075 + Automatic configuration for internal use.
25076 + When aufs supports Magic SysRq or /proc, enabled automatically.
25078 +config AUFS_HNOTIFY
25079 + bool "Detect direct branch access (bypassing aufs)"
25081 + If you want to modify files on branches directly, eg. bypassing aufs,
25082 + and want aufs to detect the changes of them fully, then enable this
25083 + option and use 'udba=notify' mount option.
25084 + Currently there is only one available configuration, "fsnotify".
25085 + It will have a negative impact to the performance.
25086 + See detail in aufs.5.
25089 + prompt "method" if AUFS_HNOTIFY
25090 + default AUFS_HFSNOTIFY
25091 +config AUFS_HFSNOTIFY
25096 +config AUFS_EXPORT
25097 + bool "NFS-exportable aufs"
25098 + depends on EXPORTFS
25100 + If you want to export your mounted aufs via NFS, then enable this
25101 + option. There are several requirements for this configuration.
25102 + See detail in aufs.5.
25104 +config AUFS_INO_T_64
25106 + depends on AUFS_EXPORT
25107 + depends on 64BIT && !(ALPHA || S390)
25110 + Automatic configuration for internal use.
25111 + /* typedef unsigned long/int __kernel_ino_t */
25112 + /* alpha and s390x are int */
25115 + bool "support for XATTR/EA (including Security Labels)"
25117 + If your branch fs supports XATTR/EA and you want to make them
25118 + available in aufs too, then enable this opsion and specify the
25119 + branch attributes for EA.
25120 + See detail in aufs.5.
25123 + bool "File-based Hierarchical Storage Management"
25125 + Hierarchical Storage Management (or HSM) is a well-known feature
25126 + in the storage world. Aufs provides this feature as file-based.
25127 + with multiple branches.
25128 + These multiple branches are prioritized, ie. the topmost one
25129 + should be the fastest drive and be used heavily.
25132 + bool "Readdir in userspace"
25134 + Aufs has two methods to provide a merged view for a directory,
25135 + by a user-space library and by kernel-space natively. The latter
25136 + is always enabled but sometimes large and slow.
25137 + If you enable this option, install the library in aufs2-util
25138 + package, and set some environment variables for your readdir(3),
25139 + then the work will be handled in user-space which generally
25140 + shows better performance in most cases.
25141 + See detail in aufs.5.
25143 +config AUFS_DIRREN
25144 + bool "Workaround for rename(2)-ing a directory"
25146 + By default, aufs returns EXDEV error in renameing a dir who has
25147 + his child on the lower branch, since it is a bad idea to issue
25148 + rename(2) internally for every lower branch. But user may not
25149 + accept this behaviour. So here is a workaround to allow such
25150 + rename(2) and store some extra information on the writable
25151 + branch. Obviously this costs high (and I don't like it).
25152 + To use this feature, you need to enable this configuration AND
25153 + to specify the mount option `dirren.'
25154 + See details in aufs.5 and the design documents.
25157 + bool "Show whiteouts"
25159 + If you want to make the whiteouts in aufs visible, then enable
25160 + this option and specify 'shwh' mount option. Although it may
25161 + sounds like philosophy or something, but in technically it
25162 + simply shows the name of whiteout with keeping its behaviour.
25164 +config AUFS_BR_RAMFS
25165 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25167 + If you want to use ramfs as an aufs branch fs, then enable this
25168 + option. Generally tmpfs is recommended.
25169 + Aufs prohibited them to be a branch fs by default, because
25170 + initramfs becomes unusable after switch_root or something
25171 + generally. If you sets initramfs as an aufs branch and boot your
25172 + system by switch_root, you will meet a problem easily since the
25173 + files in initramfs may be inaccessible.
25174 + Unless you are going to use ramfs as an aufs branch fs without
25175 + switch_root or something, leave it N.
25177 +config AUFS_BR_FUSE
25178 + bool "Fuse fs as an aufs branch"
25179 + depends on FUSE_FS
25182 + If you want to use fuse-based userspace filesystem as an aufs
25183 + branch fs, then enable this option.
25184 + It implements the internal poll(2) operation which is
25185 + implemented by fuse only (curretnly).
25190 + Automatic configuration for internal use.
25192 +config AUFS_BR_HFSPLUS
25193 + bool "Hfsplus as an aufs branch"
25194 + depends on HFSPLUS_FS
25197 + If you want to use hfsplus fs as an aufs branch fs, then enable
25198 + this option. This option introduces a small overhead at
25199 + copying-up a file on hfsplus.
25201 +config AUFS_BDEV_LOOP
25203 + depends on BLK_DEV_LOOP
25206 + Automatic configuration for internal use.
25207 + Convert =[ym] into =y.
25210 + bool "Debug aufs"
25212 + Enable this to compile aufs internal debug code.
25213 + It will have a negative impact to the performance.
25215 +config AUFS_MAGIC_SYSRQ
25217 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25220 + Automatic configuration for internal use.
25221 + When aufs supports Magic SysRq, enabled automatically.
25223 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25224 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25225 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25227 +/* SPDX-License-Identifier: GPL-2.0 */
25229 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25231 + * This program is free software; you can redistribute it and/or modify
25232 + * it under the terms of the GNU General Public License as published by
25233 + * the Free Software Foundation; either version 2 of the License, or
25234 + * (at your option) any later version.
25236 + * This program is distributed in the hope that it will be useful,
25237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25239 + * GNU General Public License for more details.
25241 + * You should have received a copy of the GNU General Public License
25242 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25246 + * simple long counter wrapper
25249 +#ifndef __AUFS_LCNT_H__
25250 +#define __AUFS_LCNT_H__
25254 +#include "debug.h"
25256 +#define AuLCntATOMIC 1
25257 +#define AuLCntPCPUCNT 2
25259 + * why does percpu_refcount require extra synchronize_rcu()s in
25260 + * au_br_do_free()
25262 +#define AuLCntPCPUREF 3
25264 +/* #define AuLCntChosen AuLCntATOMIC */
25265 +#define AuLCntChosen AuLCntPCPUCNT
25266 +/* #define AuLCntChosen AuLCntPCPUREF */
25268 +#if AuLCntChosen == AuLCntATOMIC
25269 +#include <linux/atomic.h>
25271 +typedef atomic_long_t au_lcnt_t;
25273 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25275 + atomic_long_set(cnt, 0);
25279 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25284 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25285 + int do_sync __maybe_unused)
25290 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25292 + atomic_long_inc(cnt);
25295 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25297 + atomic_long_dec(cnt);
25300 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25302 + return atomic_long_read(cnt);
25306 +#if AuLCntChosen == AuLCntPCPUCNT
25307 +#include <linux/percpu_counter.h>
25309 +typedef struct percpu_counter au_lcnt_t;
25311 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25313 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25316 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25321 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25323 + percpu_counter_destroy(cnt);
25326 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25328 + percpu_counter_inc(cnt);
25331 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25333 + percpu_counter_dec(cnt);
25336 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25340 + n = percpu_counter_sum(cnt);
25342 + if (LONG_MAX != LLONG_MAX
25344 + AuWarn1("%s\n", "wrap-around");
25350 +#if AuLCntChosen == AuLCntPCPUREF
25351 +#include <linux/percpu-refcount.h>
25353 +typedef struct percpu_ref au_lcnt_t;
25355 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25358 + release = percpu_ref_exit;
25359 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25362 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25364 + synchronize_rcu();
25367 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25369 + percpu_ref_kill(cnt);
25371 + au_lcnt_wait_for_fin(cnt);
25374 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25376 + percpu_ref_get(cnt);
25379 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25381 + percpu_ref_put(cnt);
25385 + * avoid calling this func as possible.
25387 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25391 + percpu_ref_switch_to_atomic_sync(cnt);
25392 + l = atomic_long_read(&cnt->count);
25394 + percpu_ref_switch_to_percpu(cnt);
25396 + /* percpu_ref is initialized by 1 instead of 0 */
25401 +#ifdef CONFIG_AUFS_DEBUG
25402 +#define AuLCntZero(val) do { \
25405 + AuDbg("%s = %ld\n", #val, l); \
25408 +#define AuLCntZero(val) do {} while (0)
25411 +#endif /* __KERNEL__ */
25412 +#endif /* __AUFS_LCNT_H__ */
25413 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25414 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25415 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25417 +// SPDX-License-Identifier: GPL-2.0
25419 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25421 + * This program is free software; you can redistribute it and/or modify
25422 + * it under the terms of the GNU General Public License as published by
25423 + * the Free Software Foundation; either version 2 of the License, or
25424 + * (at your option) any later version.
25426 + * This program is distributed in the hope that it will be useful,
25427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25429 + * GNU General Public License for more details.
25431 + * You should have received a copy of the GNU General Public License
25432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25436 + * support for loopback block device as a branch
25441 +/* added into drivers/block/loop.c */
25442 +static struct file *(*backing_file_func)(struct super_block *sb);
25445 + * test if two lower dentries have overlapping branches.
25447 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25449 + struct super_block *h_sb;
25450 + struct file *backing_file;
25452 + if (unlikely(!backing_file_func)) {
25453 + /* don't load "loop" module here */
25454 + backing_file_func = symbol_get(loop_backing_file);
25455 + if (unlikely(!backing_file_func))
25456 + /* "loop" module is not loaded */
25460 + h_sb = h_adding->d_sb;
25461 + backing_file = backing_file_func(h_sb);
25462 + if (!backing_file)
25465 + h_adding = backing_file->f_path.dentry;
25467 + * h_adding can be local NFS.
25468 + * in this case aufs cannot detect the loop.
25470 + if (unlikely(h_adding->d_sb == sb))
25472 + return !!au_test_subdir(h_adding, sb->s_root);
25475 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25476 +int au_test_loopback_kthread(void)
25479 + struct task_struct *tsk = current;
25480 + char c, comm[sizeof(tsk->comm)];
25483 + if (tsk->flags & PF_KTHREAD) {
25484 + get_task_comm(comm, tsk);
25486 + ret = ('0' <= c && c <= '9'
25487 + && !strncmp(comm, "loop", 4));
25493 +/* ---------------------------------------------------------------------- */
25495 +#define au_warn_loopback_step 16
25496 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25497 +static unsigned long *au_warn_loopback_array;
25499 +void au_warn_loopback(struct super_block *h_sb)
25501 + int i, new_nelem;
25502 + unsigned long *a, magic;
25503 + static DEFINE_SPINLOCK(spin);
25505 + magic = h_sb->s_magic;
25506 + spin_lock(&spin);
25507 + a = au_warn_loopback_array;
25508 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25509 + if (a[i] == magic) {
25510 + spin_unlock(&spin);
25514 + /* h_sb is new to us, print it */
25515 + if (i < au_warn_loopback_nelem) {
25520 + /* expand the array */
25521 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25522 + a = au_kzrealloc(au_warn_loopback_array,
25523 + au_warn_loopback_nelem * sizeof(unsigned long),
25524 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25525 + /*may_shrink*/0);
25527 + au_warn_loopback_nelem = new_nelem;
25528 + au_warn_loopback_array = a;
25533 + spin_unlock(&spin);
25534 + AuWarn1("realloc failed, ignored\n");
25538 + spin_unlock(&spin);
25539 + pr_warn("you may want to try another patch for loopback file "
25540 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25543 +int au_loopback_init(void)
25546 + struct super_block *sb __maybe_unused;
25548 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25551 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25552 + sizeof(unsigned long), GFP_NOFS);
25553 + if (unlikely(!au_warn_loopback_array))
25559 +void au_loopback_fin(void)
25561 + if (backing_file_func)
25562 + symbol_put(loop_backing_file);
25563 + au_kfree_try_rcu(au_warn_loopback_array);
25565 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25566 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25567 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25569 +/* SPDX-License-Identifier: GPL-2.0 */
25571 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25573 + * This program is free software; you can redistribute it and/or modify
25574 + * it under the terms of the GNU General Public License as published by
25575 + * the Free Software Foundation; either version 2 of the License, or
25576 + * (at your option) any later version.
25578 + * This program is distributed in the hope that it will be useful,
25579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25581 + * GNU General Public License for more details.
25583 + * You should have received a copy of the GNU General Public License
25584 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25588 + * support for loopback mount as a branch
25591 +#ifndef __AUFS_LOOP_H__
25592 +#define __AUFS_LOOP_H__
25597 +struct super_block;
25599 +#ifdef CONFIG_AUFS_BDEV_LOOP
25600 +/* drivers/block/loop.c */
25601 +struct file *loop_backing_file(struct super_block *sb);
25604 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25605 +int au_test_loopback_kthread(void);
25606 +void au_warn_loopback(struct super_block *h_sb);
25608 +int au_loopback_init(void);
25609 +void au_loopback_fin(void);
25611 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25613 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25614 + struct dentry *h_adding)
25615 +AuStubInt0(au_test_loopback_kthread, void)
25616 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25618 +AuStubInt0(au_loopback_init, void)
25619 +AuStubVoid(au_loopback_fin, void)
25620 +#endif /* BLK_DEV_LOOP */
25622 +#endif /* __KERNEL__ */
25623 +#endif /* __AUFS_LOOP_H__ */
25624 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25625 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25626 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25628 +# SPDX-License-Identifier: GPL-2.0
25630 +# defined in ${srctree}/fs/fuse/inode.c
25632 +ifdef CONFIG_FUSE_FS
25633 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25636 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25638 +ifdef CONFIG_XFS_FS
25639 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25642 +# defined in ${srctree}/fs/configfs/mount.c
25644 +ifdef CONFIG_CONFIGFS_FS
25645 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25648 +# defined in ${srctree}/fs/ubifs/ubifs.h
25650 +ifdef CONFIG_UBIFS_FS
25651 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25654 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25656 +ifdef CONFIG_HFSPLUS_FS
25657 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25659 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25660 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25661 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25663 +# SPDX-License-Identifier: GPL-2.0
25665 +include ${src}/magic.mk
25666 +ifeq (${CONFIG_AUFS_FS},m)
25667 +include ${src}/conf.mk
25669 +-include ${src}/priv_def.mk
25671 +# cf. include/linux/kernel.h
25673 +ccflags-y += -DDEBUG
25674 +# sparse requires the full pathname
25676 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25678 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25681 +obj-$(CONFIG_AUFS_FS) += aufs.o
25682 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25683 + wkq.o vfsub.o dcsub.o \
25684 + cpup.o whout.o wbr_policy.o \
25685 + dinfo.o dentry.o \
25687 + finfo.o file.o f_op.o \
25689 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25693 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25694 +aufs-$(CONFIG_SYSFS) += sysfs.o
25695 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25696 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25697 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25698 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25699 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25700 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25701 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25702 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25703 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25704 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25705 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25706 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25707 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25708 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25709 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25710 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25711 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25713 +// SPDX-License-Identifier: GPL-2.0
25715 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25717 + * This program is free software; you can redistribute it and/or modify
25718 + * it under the terms of the GNU General Public License as published by
25719 + * the Free Software Foundation; either version 2 of the License, or
25720 + * (at your option) any later version.
25722 + * This program is distributed in the hope that it will be useful,
25723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25725 + * GNU General Public License for more details.
25727 + * You should have received a copy of the GNU General Public License
25728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25732 + * module global variables and operations
25735 +#include <linux/module.h>
25736 +#include <linux/seq_file.h>
25739 +/* shrinkable realloc */
25740 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25748 +#if 0 /* unused */
25755 + AuDebugOn(!new_sz);
25758 + diff = au_kmidx_sub(sz, new_sz);
25764 + /* expand or SLOB */
25765 + p = krealloc(p, new_sz, gfp);
25766 + else if (new_sz < sz && may_shrink) {
25770 + q = kmalloc(new_sz, gfp);
25773 + memcpy(q, p, new_sz);
25774 + au_kfree_try_rcu(p);
25785 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25788 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25789 + if (p && new_sz > nused)
25790 + memset(p + nused, 0, new_sz - nused);
25794 +/* ---------------------------------------------------------------------- */
25798 +struct kmem_cache *au_cache[AuCache_Last];
25800 +static void au_cache_fin(void)
25805 + * Make sure all delayed rcu free inodes are flushed before we
25810 + /* excluding AuCache_HNOTIFY */
25811 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25812 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25813 + kmem_cache_destroy(au_cache[i]);
25814 + au_cache[i] = NULL;
25818 +static int __init au_cache_init(void)
25820 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25821 + if (au_cache[AuCache_DINFO])
25822 + /* SLAB_DESTROY_BY_RCU */
25823 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25824 + au_icntnr_init_once);
25825 + if (au_cache[AuCache_ICNTNR])
25826 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25827 + au_fi_init_once);
25828 + if (au_cache[AuCache_FINFO])
25829 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25830 + if (au_cache[AuCache_VDIR])
25831 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25832 + if (au_cache[AuCache_DEHSTR])
25839 +/* ---------------------------------------------------------------------- */
25841 +int au_dir_roflags;
25843 +#ifdef CONFIG_AUFS_SBILIST
25845 + * iterate_supers_type() doesn't protect us from
25846 + * remounting (branch management)
25848 +struct hlist_bl_head au_sbilist;
25852 + * functions for module interface.
25854 +MODULE_LICENSE("GPL");
25855 +/* MODULE_LICENSE("GPL v2"); */
25856 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25857 +MODULE_DESCRIPTION(AUFS_NAME
25858 + " -- Advanced multi layered unification filesystem");
25859 +MODULE_VERSION(AUFS_VERSION);
25860 +MODULE_ALIAS_FS(AUFS_NAME);
25862 +/* this module parameter has no meaning when SYSFS is disabled */
25863 +int sysaufs_brs = 1;
25864 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25865 +module_param_named(brs, sysaufs_brs, int, 0444);
25867 +/* this module parameter has no meaning when USER_NS is disabled */
25869 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25870 +module_param_named(allow_userns, au_userns, bool, 0444);
25872 +/* ---------------------------------------------------------------------- */
25874 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25876 +int au_seq_path(struct seq_file *seq, struct path *path)
25880 + err = seq_path(seq, path, au_esc_chars);
25889 +/* ---------------------------------------------------------------------- */
25891 +static int __init aufs_init(void)
25896 + p = au_esc_chars;
25897 + for (i = 1; i <= ' '; i++)
25903 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25905 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25906 + for (i = 0; i < AuIop_Last; i++)
25907 + aufs_iop_nogetattr[i].getattr = NULL;
25909 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25911 + au_sbilist_init();
25912 + sysaufs_brs_init();
25915 + err = sysaufs_init();
25916 + if (unlikely(err))
25918 + err = dbgaufs_init();
25919 + if (unlikely(err))
25920 + goto out_sysaufs;
25921 + err = au_procfs_init();
25922 + if (unlikely(err))
25923 + goto out_dbgaufs;
25924 + err = au_wkq_init();
25925 + if (unlikely(err))
25927 + err = au_loopback_init();
25928 + if (unlikely(err))
25930 + err = au_hnotify_init();
25931 + if (unlikely(err))
25932 + goto out_loopback;
25933 + err = au_sysrq_init();
25934 + if (unlikely(err))
25936 + err = au_cache_init();
25937 + if (unlikely(err))
25940 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25941 + err = register_filesystem(&aufs_fs_type);
25942 + if (unlikely(err))
25945 + /* since we define pr_fmt, call printk directly */
25946 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25947 + goto out; /* success */
25954 + au_hnotify_fin();
25956 + au_loopback_fin();
25970 +static void __exit aufs_exit(void)
25972 + unregister_filesystem(&aufs_fs_type);
25975 + au_hnotify_fin();
25976 + au_loopback_fin();
25984 +module_init(aufs_init);
25985 +module_exit(aufs_exit);
25986 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25987 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25988 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
25990 +/* SPDX-License-Identifier: GPL-2.0 */
25992 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25994 + * This program is free software; you can redistribute it and/or modify
25995 + * it under the terms of the GNU General Public License as published by
25996 + * the Free Software Foundation; either version 2 of the License, or
25997 + * (at your option) any later version.
25999 + * This program is distributed in the hope that it will be useful,
26000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26002 + * GNU General Public License for more details.
26004 + * You should have received a copy of the GNU General Public License
26005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26009 + * module initialization and module-global
26012 +#ifndef __AUFS_MODULE_H__
26013 +#define __AUFS_MODULE_H__
26017 +#include <linux/slab.h>
26018 +#include "debug.h"
26019 +#include "dentry.h"
26022 +#include "inode.h"
26027 +/* module parameters */
26028 +extern int sysaufs_brs;
26029 +extern bool au_userns;
26031 +/* ---------------------------------------------------------------------- */
26033 +extern int au_dir_roflags;
26035 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26036 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26040 + * Comparing the size of the object with sizeof(struct rcu_head)
26041 + * case 1: object is always larger
26042 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26043 + * case 2: object is always smaller
26044 + * --> au_kfree_small()
26045 + * case 3: object can be any size
26046 + * --> au_kfree_try_rcu()
26049 +static inline void au_kfree_do_rcu(const void *p)
26052 + struct rcu_head rcu;
26053 + } *a = (void *)p;
26055 + kfree_rcu(a, rcu);
26058 +#define au_kfree_rcu(_p) do { \
26059 + typeof(_p) p = (_p); \
26060 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26062 + au_kfree_do_rcu(p); \
26065 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26066 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26068 +static inline void au_kfree_try_rcu(const void *p)
26072 + if (au_kfree_sz_test(p))
26073 + au_kfree_do_rcu(p);
26078 +static inline void au_kfree_small(const void *p)
26082 + AuDebugOn(au_kfree_sz_test(p));
26086 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26088 +#ifndef CONFIG_SLOB
26089 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26091 + return -1; /* SLOB is untested */
26095 +int au_seq_path(struct seq_file *seq, struct path *path);
26097 +#ifdef CONFIG_PROC_FS
26099 +int __init au_procfs_init(void);
26100 +void au_procfs_fin(void);
26102 +AuStubInt0(au_procfs_init, void);
26103 +AuStubVoid(au_procfs_fin, void);
26106 +/* ---------------------------------------------------------------------- */
26115 + AuCache_HNOTIFY, /* must be last */
26119 +extern struct kmem_cache *au_cache[AuCache_Last];
26121 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26122 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26123 +#define AuCacheCtor(type, ctor) \
26124 + kmem_cache_create(#type, sizeof(struct type), \
26125 + __alignof__(struct type), AuCacheFlags, ctor)
26127 +#define AuCacheFuncAlloc(name, index) \
26128 + static inline struct au_##name *au_cache_alloc_##name(void) \
26129 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26131 +#define AuCacheFuncs(name, index) \
26132 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26133 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26135 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26136 + { void *p = rcu; \
26137 + p -= offsetof(struct au_##name, rcu); \
26138 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26139 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26140 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26141 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26143 + static inline void au_cache_free_##name(struct au_##name *p) \
26144 + { /* au_cache_free_##name##_norcu(p); */ \
26145 + au_cache_free_##name##_rcu(p); }
26147 +AuCacheFuncs(dinfo, DINFO);
26148 +AuCacheFuncAlloc(dinfo, DINFO);
26150 +AuCacheFuncs(icntnr, ICNTNR);
26151 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26152 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26154 +AuCacheFuncs(finfo, FINFO);
26155 +AuCacheFuncAlloc(finfo, FINFO);
26157 +AuCacheFuncs(vdir, VDIR);
26158 +AuCacheFuncAlloc(vdir, VDIR);
26160 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26161 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26163 +#ifdef CONFIG_AUFS_HNOTIFY
26164 +AuCacheFuncs(hnotify, HNOTIFY);
26165 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26168 +#endif /* __KERNEL__ */
26169 +#endif /* __AUFS_MODULE_H__ */
26170 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26171 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26172 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26174 +// SPDX-License-Identifier: GPL-2.0
26176 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26178 + * This program is free software; you can redistribute it and/or modify
26179 + * it under the terms of the GNU General Public License as published by
26180 + * the Free Software Foundation; either version 2 of the License, or
26181 + * (at your option) any later version.
26183 + * This program is distributed in the hope that it will be useful,
26184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26186 + * GNU General Public License for more details.
26188 + * You should have received a copy of the GNU General Public License
26189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26193 + * move-down, opposite of copy-up
26198 +struct au_mvd_args {
26200 + struct super_block *h_sb;
26201 + struct dentry *h_parent;
26202 + struct au_hinode *hdir;
26203 + struct inode *h_dir, *h_inode;
26204 + struct au_pin pin;
26205 + } info[AUFS_MVDOWN_NARRAY];
26207 + struct aufs_mvdown mvdown;
26208 + struct dentry *dentry, *parent;
26209 + struct inode *inode, *dir;
26210 + struct super_block *sb;
26211 + aufs_bindex_t bopq, bwh, bfound;
26212 + unsigned char rename_lock;
26215 +#define mvd_errno mvdown.au_errno
26216 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26217 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26218 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26219 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26221 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26222 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26223 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26224 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26225 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26226 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26228 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26229 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26230 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26231 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26232 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26233 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26235 +#define AU_MVD_PR(flag, ...) do { \
26237 + pr_err(__VA_ARGS__); \
26240 +static int find_lower_writable(struct au_mvd_args *a)
26242 + struct super_block *sb;
26243 + aufs_bindex_t bindex, bbot;
26244 + struct au_branch *br;
26247 + bindex = a->mvd_bsrc;
26248 + bbot = au_sbbot(sb);
26249 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26250 + for (bindex++; bindex <= bbot; bindex++) {
26251 + br = au_sbr(sb, bindex);
26252 + if (au_br_fhsm(br->br_perm)
26253 + && !sb_rdonly(au_br_sb(br)))
26256 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26257 + for (bindex++; bindex <= bbot; bindex++) {
26258 + br = au_sbr(sb, bindex);
26259 + if (!au_br_rdonly(br))
26263 + for (bindex++; bindex <= bbot; bindex++) {
26264 + br = au_sbr(sb, bindex);
26265 + if (!sb_rdonly(au_br_sb(br))) {
26266 + if (au_br_rdonly(br))
26268 + |= AUFS_MVDOWN_ROLOWER_R;
26276 +/* make the parent dir on bdst */
26277 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26282 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26283 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26284 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26285 + a->mvd_h_dst_parent = NULL;
26286 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26287 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26288 + if (!a->mvd_h_dst_parent) {
26289 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26290 + if (unlikely(err)) {
26291 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26294 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26302 +/* lock them all */
26303 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26306 + struct dentry *h_trap;
26308 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26309 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26310 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26311 + au_opt_udba(a->sb),
26312 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26314 + if (unlikely(err)) {
26315 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26319 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26320 + a->rename_lock = 0;
26321 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26322 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26323 + au_opt_udba(a->sb),
26324 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26325 + err = au_do_pin(&a->mvd_pin_src);
26327 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26328 + if (unlikely(err)) {
26329 + AU_MVD_PR(dmsg, "pin_src failed\n");
26332 + goto out; /* success */
26335 + a->rename_lock = 1;
26336 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26337 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26338 + au_opt_udba(a->sb),
26339 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26341 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26342 + if (unlikely(err)) {
26343 + AU_MVD_PR(dmsg, "pin_src failed\n");
26344 + au_pin_hdir_lock(&a->mvd_pin_dst);
26347 + au_pin_hdir_unlock(&a->mvd_pin_src);
26348 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26349 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26351 + err = (h_trap != a->mvd_h_src_parent);
26353 + err = (h_trap != a->mvd_h_dst_parent);
26355 + BUG_ON(err); /* it should never happen */
26356 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26359 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26360 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26361 + au_pin_hdir_lock(&a->mvd_pin_src);
26362 + au_unpin(&a->mvd_pin_src);
26363 + au_pin_hdir_lock(&a->mvd_pin_dst);
26366 + goto out; /* success */
26369 + au_unpin(&a->mvd_pin_dst);
26375 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26377 + if (!a->rename_lock)
26378 + au_unpin(&a->mvd_pin_src);
26380 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26381 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26382 + au_pin_hdir_lock(&a->mvd_pin_src);
26383 + au_unpin(&a->mvd_pin_src);
26384 + au_pin_hdir_lock(&a->mvd_pin_dst);
26386 + au_unpin(&a->mvd_pin_dst);
26389 +/* copy-down the file */
26390 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26393 + struct au_cp_generic cpg = {
26394 + .dentry = a->dentry,
26395 + .bdst = a->mvd_bdst,
26396 + .bsrc = a->mvd_bsrc,
26398 + .pin = &a->mvd_pin_dst,
26399 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26402 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26403 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26404 + au_fset_cpup(cpg.flags, OVERWRITE);
26405 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26406 + au_fset_cpup(cpg.flags, RWDST);
26407 + err = au_sio_cpdown_simple(&cpg);
26408 + if (unlikely(err))
26409 + AU_MVD_PR(dmsg, "cpdown failed\n");
26416 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26419 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26422 + struct path h_path;
26423 + struct au_branch *br;
26424 + struct inode *delegated;
26426 + br = au_sbr(a->sb, a->mvd_bdst);
26427 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26428 + err = PTR_ERR(h_path.dentry);
26429 + if (IS_ERR(h_path.dentry)) {
26430 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26435 + if (d_is_positive(h_path.dentry)) {
26436 + h_path.mnt = au_br_mnt(br);
26437 + delegated = NULL;
26438 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26439 + &delegated, /*force*/0);
26440 + if (unlikely(err == -EWOULDBLOCK)) {
26441 + pr_warn("cannot retry for NFSv4 delegation"
26442 + " for an internal unlink\n");
26445 + if (unlikely(err))
26446 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26448 + dput(h_path.dentry);
26456 + * unlink the topmost h_dentry
26458 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26461 + struct path h_path;
26462 + struct inode *delegated;
26464 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26465 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26466 + delegated = NULL;
26467 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26468 + if (unlikely(err == -EWOULDBLOCK)) {
26469 + pr_warn("cannot retry for NFSv4 delegation"
26470 + " for an internal unlink\n");
26473 + if (unlikely(err))
26474 + AU_MVD_PR(dmsg, "unlink failed\n");
26480 +/* Since mvdown succeeded, we ignore an error of this function */
26481 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26484 + struct au_branch *br;
26486 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26487 + br = au_sbr(a->sb, a->mvd_bsrc);
26488 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26490 + br = au_sbr(a->sb, a->mvd_bdst);
26491 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26492 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26495 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26497 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26501 + * copy-down the file and unlink the bsrc file.
26502 + * - unlink the bdst whout if exist
26503 + * - copy-down the file (with whtmp name and rename)
26504 + * - unlink the bsrc file
26506 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26510 + err = au_do_mkdir(dmsg, a);
26512 + err = au_do_lock(dmsg, a);
26513 + if (unlikely(err))
26517 + * do not revert the activities we made on bdst since they should be
26518 + * harmless in aufs.
26521 + err = au_do_cpdown(dmsg, a);
26523 + err = au_do_unlink_wh(dmsg, a);
26524 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26525 + err = au_do_unlink(dmsg, a);
26526 + if (unlikely(err))
26529 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26530 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26531 + if (find_lower_writable(a) < 0)
26532 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26534 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26535 + au_do_stfs(dmsg, a);
26537 + /* maintain internal array */
26538 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26539 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26540 + au_set_dbtop(a->dentry, a->mvd_bdst);
26541 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26542 + au_set_ibtop(a->inode, a->mvd_bdst);
26544 + /* hide the lower */
26545 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26546 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26547 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26548 + au_set_ibbot(a->inode, a->mvd_bsrc);
26550 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26551 + au_set_dbbot(a->dentry, a->mvd_bdst);
26552 + if (au_ibbot(a->inode) < a->mvd_bdst)
26553 + au_set_ibbot(a->inode, a->mvd_bdst);
26556 + au_do_unlock(dmsg, a);
26562 +/* ---------------------------------------------------------------------- */
26564 +/* make sure the file is idle */
26565 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26567 + int err, plinked;
26570 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26571 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26572 + && au_dcount(a->dentry) == 1
26573 + && atomic_read(&a->inode->i_count) == 1
26574 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26575 + && (!plinked || !au_plink_test(a->inode))
26576 + && a->inode->i_nlink == 1)
26581 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26582 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26583 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26584 + a->mvd_h_src_inode->i_nlink,
26585 + plinked, plinked ? au_plink_test(a->inode) : 0);
26592 +/* make sure the parent dir is fine */
26593 +static int au_mvd_args_parent(const unsigned char dmsg,
26594 + struct au_mvd_args *a)
26597 + aufs_bindex_t bindex;
26600 + if (unlikely(au_alive_dir(a->parent))) {
26602 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26606 + a->bopq = au_dbdiropq(a->parent);
26607 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26608 + AuDbg("b%d\n", bindex);
26609 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26610 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26612 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26613 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26614 + a->bopq, a->mvd_bdst);
26622 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26623 + struct au_mvd_args *a)
26626 + struct au_dinfo *dinfo, *tmp;
26628 + /* lookup the next lower positive entry */
26630 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26631 + if (unlikely(!tmp))
26636 + dinfo = au_di(a->dentry);
26637 + au_di_cp(tmp, dinfo);
26638 + au_di_swap(tmp, dinfo);
26640 + /* returns the number of positive dentries */
26641 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26642 + /* AuLkup_IGNORE_PERM */ 0);
26644 + a->bwh = au_dbwh(a->dentry);
26645 + else if (err > 0)
26646 + a->bfound = au_dbtop(a->dentry);
26648 + au_di_swap(tmp, dinfo);
26649 + au_rw_write_unlock(&tmp->di_rwsem);
26651 + if (unlikely(err < 0))
26652 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26655 + * here, we have these cases.
26657 + * no positive dentry under bsrc. there are more sub-cases.
26659 + * there no whiteout, we can safely move-down.
26662 + * bsrc < bwh && bwh < bdst
26663 + * there is a whiteout on RO branch. cannot proceed.
26665 + * there is a whiteout on the RW target branch. it should
26668 + * there is a whiteout somewhere unrelated branch.
26669 + * -1 < bfound && bfound <= bsrc
26672 + * found, but it is on RO branch between bsrc and bdst. cannot
26675 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26678 + * found, after we create the file on bdst, it will be hidden.
26681 + AuDebugOn(a->bfound == -1
26683 + && a->bwh <= a->mvd_bsrc);
26684 + AuDebugOn(-1 < a->bfound
26685 + && a->bfound <= a->mvd_bsrc);
26688 + if (a->bfound == -1
26689 + && a->mvd_bsrc < a->bwh
26691 + && a->bwh < a->mvd_bdst) {
26692 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26693 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26694 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26696 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26697 + a->mvd_errno = EAU_MVDOWN_UPPER;
26698 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26699 + a->mvd_bdst, a->bfound);
26703 + err = 0; /* success */
26710 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26715 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26716 + && a->bfound == a->mvd_bdst)
26722 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26725 + struct au_branch *br;
26728 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26732 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26733 + a->mvd_bsrc = au_ibtop(a->inode);
26735 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26736 + if (unlikely(a->mvd_bsrc < 0
26737 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26738 + || au_dbbot(a->dentry) < a->mvd_bsrc
26739 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26740 + || (a->mvd_bsrc < au_ibtop(a->inode)
26741 + || au_ibbot(a->inode) < a->mvd_bsrc
26742 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26743 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26744 + AU_MVD_PR(dmsg, "no upper\n");
26748 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26749 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26750 + AU_MVD_PR(dmsg, "on the bottom\n");
26753 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26754 + br = au_sbr(a->sb, a->mvd_bsrc);
26755 + err = au_br_rdonly(br);
26756 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26757 + if (unlikely(err))
26759 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26760 + || IS_APPEND(a->mvd_h_src_inode))) {
26762 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26768 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26769 + a->mvd_bdst = find_lower_writable(a);
26770 + if (unlikely(a->mvd_bdst < 0)) {
26771 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26772 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26776 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26777 + if (unlikely(a->mvd_bdst < 0
26778 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26779 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26780 + AU_MVD_PR(dmsg, "no lower brid\n");
26785 + err = au_mvd_args_busy(dmsg, a);
26787 + err = au_mvd_args_parent(dmsg, a);
26789 + err = au_mvd_args_intermediate(dmsg, a);
26791 + err = au_mvd_args_exist(dmsg, a);
26793 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26800 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26803 + unsigned char dmsg;
26804 + struct au_mvd_args *args;
26805 + struct inode *inode;
26807 + inode = d_inode(dentry);
26809 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26813 + args = kmalloc(sizeof(*args), GFP_NOFS);
26814 + if (unlikely(!args))
26817 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26819 + /* VERIFY_WRITE */
26820 + err = !access_ok(uarg, sizeof(*uarg));
26821 + if (unlikely(err)) {
26826 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26827 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26828 + args->mvdown.au_errno = 0;
26829 + args->dentry = dentry;
26830 + args->inode = inode;
26831 + args->sb = dentry->d_sb;
26834 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26835 + args->parent = dget_parent(dentry);
26836 + args->dir = d_inode(args->parent);
26837 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26838 + dput(args->parent);
26839 + if (unlikely(args->parent != dentry->d_parent)) {
26840 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26844 + inode_lock_nested(inode, I_MUTEX_CHILD);
26845 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26846 + if (unlikely(err))
26849 + di_write_lock_parent(args->parent);
26850 + err = au_mvd_args(dmsg, args);
26851 + if (unlikely(err))
26854 + err = au_do_mvdown(dmsg, args);
26855 + if (unlikely(err))
26858 + au_cpup_attr_timesizes(args->dir);
26859 + au_cpup_attr_timesizes(inode);
26860 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26861 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26862 + /* au_digen_dec(dentry); */
26865 + di_write_unlock(args->parent);
26866 + aufs_read_unlock(dentry, AuLock_DW);
26868 + inode_unlock(inode);
26870 + inode_unlock(args->dir);
26872 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26875 + au_kfree_rcu(args);
26880 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26881 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26882 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26884 +// SPDX-License-Identifier: GPL-2.0
26886 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26888 + * This program is free software; you can redistribute it and/or modify
26889 + * it under the terms of the GNU General Public License as published by
26890 + * the Free Software Foundation; either version 2 of the License, or
26891 + * (at your option) any later version.
26893 + * This program is distributed in the hope that it will be useful,
26894 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26895 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26896 + * GNU General Public License for more details.
26898 + * You should have received a copy of the GNU General Public License
26899 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26903 + * mount options/flags
26906 +#include <linux/types.h> /* a distribution requires */
26907 +#include <linux/parser.h>
26910 +/* ---------------------------------------------------------------------- */
26912 +static const char *au_parser_pattern(int val, match_table_t tbl)
26914 + struct match_token *p;
26917 + while (p->pattern) {
26918 + if (p->token == val)
26919 + return p->pattern;
26926 +static const char *au_optstr(int *val, match_table_t tbl)
26928 + struct match_token *p;
26935 + while (p->pattern) {
26937 + && (v & p->token) == p->token) {
26938 + *val &= ~p->token;
26939 + return p->pattern;
26948 +/* ---------------------------------------------------------------------- */
26950 +static match_table_t brperm = {
26951 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26952 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26953 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26957 +static match_table_t brattr = {
26959 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26960 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26961 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26962 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26963 +#ifdef CONFIG_AUFS_FHSM
26964 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26966 +#ifdef CONFIG_AUFS_XATTR
26967 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26968 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26969 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26970 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26971 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26972 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26975 + /* ro/rr branch */
26976 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26979 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26980 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26985 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26992 + p = strchr(str, '+');
26995 + v = match_token(str, table, args);
26997 + if (v & AuBrAttr_CMOO_Mask)
26998 + attr &= ~AuBrAttr_CMOO_Mask;
27003 + pr_warn("ignored branch attribute %s\n", str);
27013 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27021 + p = au_optstr(&perm, brattr);
27024 + memcpy(q, p, sz + 1);
27030 + p = au_optstr(&perm, brattr);
27034 + memcpy(q, p, sz + 1);
27040 + return q - str->a;
27043 +int au_br_perm_val(char *perm)
27045 + int val, bad, sz;
27047 + substring_t args[MAX_OPT_ARGS];
27048 + au_br_perm_str_t attr;
27050 + p = strchr(perm, '+');
27053 + val = match_token(perm, brperm, args);
27057 + pr_warn("ignored branch permission %s\n", perm);
27058 + val = AuBrPerm_RO;
27064 + val |= br_attr_val(p + 1, brattr, args);
27067 + switch (val & AuBrPerm_Mask) {
27068 + case AuBrPerm_RO:
27069 + case AuBrPerm_RR:
27070 + bad = val & AuBrWAttr_Mask;
27071 + val &= ~AuBrWAttr_Mask;
27073 + case AuBrPerm_RW:
27074 + bad = val & AuBrRAttr_Mask;
27075 + val &= ~AuBrRAttr_Mask;
27080 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27081 + * does not treat it as an error, just warning.
27082 + * this is a tiny guard for the user operation.
27084 + if (val & AuBrAttr_UNPIN) {
27085 + bad |= AuBrAttr_UNPIN;
27086 + val &= ~AuBrAttr_UNPIN;
27089 + if (unlikely(bad)) {
27090 + sz = au_do_optstr_br_attr(&attr, bad);
27092 + pr_warn("ignored branch attribute %s\n", attr.a);
27099 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27101 + au_br_perm_str_t attr;
27107 + p = au_optstr(&perm, brperm);
27108 + AuDebugOn(!p || !*p);
27110 + memcpy(q, p, sz + 1);
27113 + sz = au_do_optstr_br_attr(&attr, perm);
27116 + memcpy(q, attr.a, sz + 1);
27119 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27122 +/* ---------------------------------------------------------------------- */
27124 +static match_table_t udbalevel = {
27125 + {AuOpt_UDBA_REVAL, "reval"},
27126 + {AuOpt_UDBA_NONE, "none"},
27127 +#ifdef CONFIG_AUFS_HNOTIFY
27128 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27129 +#ifdef CONFIG_AUFS_HFSNOTIFY
27130 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27136 +int au_udba_val(char *str)
27138 + substring_t args[MAX_OPT_ARGS];
27140 + return match_token(str, udbalevel, args);
27143 +const char *au_optstr_udba(int udba)
27145 + return au_parser_pattern(udba, udbalevel);
27148 +/* ---------------------------------------------------------------------- */
27150 +static match_table_t au_wbr_create_policy = {
27151 + {AuWbrCreate_TDP, "tdp"},
27152 + {AuWbrCreate_TDP, "top-down-parent"},
27153 + {AuWbrCreate_RR, "rr"},
27154 + {AuWbrCreate_RR, "round-robin"},
27155 + {AuWbrCreate_MFS, "mfs"},
27156 + {AuWbrCreate_MFS, "most-free-space"},
27157 + {AuWbrCreate_MFSV, "mfs:%d"},
27158 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27160 + /* top-down regardless the parent, and then mfs */
27161 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27162 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27164 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27165 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27166 + {AuWbrCreate_PMFS, "pmfs"},
27167 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27168 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27169 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27174 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27175 + struct au_opt_wbr_create *create)
27178 + unsigned long long ull;
27181 + if (!match_u64(arg, &ull))
27182 + create->mfsrr_watermark = ull;
27184 + pr_err("bad integer in %s\n", str);
27191 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27192 + struct au_opt_wbr_create *create)
27197 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27198 + create->mfs_second = n;
27200 + pr_err("bad integer in %s\n", str);
27207 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27210 + substring_t args[MAX_OPT_ARGS];
27212 + err = match_token(str, au_wbr_create_policy, args);
27213 + create->wbr_create = err;
27215 + case AuWbrCreate_MFSRRV:
27216 + case AuWbrCreate_TDMFSV:
27217 + case AuWbrCreate_PMFSRRV:
27218 + e = au_wbr_mfs_wmark(&args[0], str, create);
27220 + e = au_wbr_mfs_sec(&args[1], str, create);
27224 + case AuWbrCreate_MFSRR:
27225 + case AuWbrCreate_TDMFS:
27226 + case AuWbrCreate_PMFSRR:
27227 + e = au_wbr_mfs_wmark(&args[0], str, create);
27228 + if (unlikely(e)) {
27233 + case AuWbrCreate_MFS:
27234 + case AuWbrCreate_PMFS:
27235 + create->mfs_second = AUFS_MFS_DEF_SEC;
27237 + case AuWbrCreate_MFSV:
27238 + case AuWbrCreate_PMFSV:
27239 + e = au_wbr_mfs_sec(&args[0], str, create);
27248 +const char *au_optstr_wbr_create(int wbr_create)
27250 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27253 +static match_table_t au_wbr_copyup_policy = {
27254 + {AuWbrCopyup_TDP, "tdp"},
27255 + {AuWbrCopyup_TDP, "top-down-parent"},
27256 + {AuWbrCopyup_BUP, "bup"},
27257 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27258 + {AuWbrCopyup_BU, "bu"},
27259 + {AuWbrCopyup_BU, "bottom-up"},
27263 +int au_wbr_copyup_val(char *str)
27265 + substring_t args[MAX_OPT_ARGS];
27267 + return match_token(str, au_wbr_copyup_policy, args);
27270 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27272 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27275 +/* ---------------------------------------------------------------------- */
27277 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27278 + aufs_bindex_t bindex)
27281 + struct au_opt_add *add = &opt->add;
27284 + add->bindex = bindex;
27285 + add->perm = AuBrPerm_RO;
27286 + add->pathname = opt_str;
27287 + p = strchr(opt_str, '=');
27291 + add->perm = au_br_perm_val(p);
27294 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27297 + add->perm = AuBrPerm_RO;
27298 + if (au_test_fs_rr(add->path.dentry->d_sb))
27299 + add->perm = AuBrPerm_RR;
27300 + else if (!bindex && !(sb_flags & SB_RDONLY))
27301 + add->perm = AuBrPerm_RW;
27303 + opt->type = Opt_add;
27306 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27313 +static int au_opt_wbr_create(struct super_block *sb,
27314 + struct au_opt_wbr_create *create)
27317 + struct au_sbinfo *sbinfo;
27319 + SiMustWriteLock(sb);
27321 + err = 1; /* handled */
27322 + sbinfo = au_sbi(sb);
27323 + if (sbinfo->si_wbr_create_ops->fin) {
27324 + err = sbinfo->si_wbr_create_ops->fin(sb);
27329 + sbinfo->si_wbr_create = create->wbr_create;
27330 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27331 + switch (create->wbr_create) {
27332 + case AuWbrCreate_MFSRRV:
27333 + case AuWbrCreate_MFSRR:
27334 + case AuWbrCreate_TDMFS:
27335 + case AuWbrCreate_TDMFSV:
27336 + case AuWbrCreate_PMFSRR:
27337 + case AuWbrCreate_PMFSRRV:
27338 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27340 + case AuWbrCreate_MFS:
27341 + case AuWbrCreate_MFSV:
27342 + case AuWbrCreate_PMFS:
27343 + case AuWbrCreate_PMFSV:
27344 + sbinfo->si_wbr_mfs.mfs_expire
27345 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27349 + if (sbinfo->si_wbr_create_ops->init)
27350 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27357 + * plus: processed without an error
27358 + * zero: unprocessed
27360 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27361 + struct au_opts *opts)
27364 + struct au_sbinfo *sbinfo;
27366 + SiMustWriteLock(sb);
27368 + err = 1; /* handled */
27369 + sbinfo = au_sbi(sb);
27370 + switch (opt->type) {
27372 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27373 + sbinfo->si_mntflags |= opt->udba;
27374 + opts->given_udba |= opt->udba;
27379 + au_opt_set(sbinfo->si_mntflags, PLINK);
27381 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27382 + au_plink_put(sb, /*verbose*/1);
27383 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27386 + case Opt_list_plink:
27387 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27388 + au_plink_list(sb);
27393 + au_opt_set(sbinfo->si_mntflags, DIO);
27394 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27396 + au_opt_clr(sbinfo->si_mntflags, DIO);
27397 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27401 + case Opt_fhsm_sec:
27402 + au_fhsm_set(sbinfo, opt->fhsm_second);
27405 + case Opt_diropq_a:
27406 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27408 + case Opt_diropq_w:
27409 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27412 + case Opt_warn_perm:
27414 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27416 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27419 + case Opt_verbose:
27421 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27423 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27428 + au_opt_set(sbinfo->si_mntflags, SUM);
27430 + au_opt_clr(sbinfo->si_mntflags, SUM);
27431 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27435 + au_opt_clr(sbinfo->si_mntflags, SUM);
27436 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27439 + case Opt_wbr_create:
27440 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27442 + case Opt_wbr_copyup:
27443 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27444 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27448 + sbinfo->si_dirwh = opt->dirwh;
27451 + case Opt_rdcache:
27452 + sbinfo->si_rdcache
27453 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27456 + sbinfo->si_rdblk = opt->rdblk;
27459 + sbinfo->si_rdhash = opt->rdhash;
27464 + au_opt_set(sbinfo->si_mntflags, SHWH);
27466 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27469 + case Opt_dirperm1:
27471 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27473 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27476 + case Opt_trunc_xino:
27478 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27480 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27483 + case Opt_trunc_xino_path:
27484 + case Opt_itrunc_xino:
27485 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27491 + case Opt_trunc_xib:
27493 + au_fset_opts(opts->flags, TRUNC_XIB);
27495 + au_fclr_opts(opts->flags, TRUNC_XIB);
27501 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27502 + err = au_dr_opt_set(sb);
27507 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27509 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27510 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27516 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27522 + sb->s_flags |= SB_POSIXACL;
27524 + sb->s_flags &= ~SB_POSIXACL;
27536 + * returns tri-state.
27537 + * plus: processed without an error
27538 + * zero: unprocessed
27541 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27542 + struct au_opts *opts)
27544 + int err, do_refresh;
27547 + switch (opt->type) {
27549 + opt->add.bindex = au_sbbot(sb) + 1;
27550 + if (opt->add.bindex < 0)
27551 + opt->add.bindex = 0;
27553 + /* Always goto add, not fallthrough */
27554 + case Opt_prepend:
27555 + opt->add.bindex = 0;
27557 + add: /* indented label */
27559 + err = au_br_add(sb, &opt->add,
27560 + au_ftest_opts(opts->flags, REMOUNT));
27563 + au_fset_opts(opts->flags, REFRESH);
27569 + err = au_br_del(sb, &opt->del,
27570 + au_ftest_opts(opts->flags, REMOUNT));
27573 + au_fset_opts(opts->flags, TRUNC_XIB);
27574 + au_fset_opts(opts->flags, REFRESH);
27580 + err = au_br_mod(sb, &opt->mod,
27581 + au_ftest_opts(opts->flags, REMOUNT),
27586 + au_fset_opts(opts->flags, REFRESH);
27593 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27594 + struct au_opt_xino **opt_xino,
27595 + struct au_opts *opts)
27600 + switch (opt->type) {
27602 + err = au_xino_set(sb, &opt->xino,
27603 + !!au_ftest_opts(opts->flags, REMOUNT));
27605 + *opt_xino = &opt->xino;
27609 + *opt_xino = (void *)-1;
27616 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27617 + unsigned int pending)
27620 + aufs_bindex_t bindex, bbot;
27621 + unsigned char do_plink, skip, do_free, can_no_dreval;
27622 + struct au_branch *br;
27623 + struct au_wbr *wbr;
27624 + struct dentry *root, *dentry;
27625 + struct inode *dir, *h_dir;
27626 + struct au_sbinfo *sbinfo;
27627 + struct au_hinode *hdir;
27629 + SiMustAnyLock(sb);
27631 + sbinfo = au_sbi(sb);
27632 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27634 + if (!(sb_flags & SB_RDONLY)) {
27635 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27636 + pr_warn("first branch should be rw\n");
27637 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27638 + pr_warn_once("shwh should be used with ro\n");
27641 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27642 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27643 + pr_warn_once("udba=*notify requires xino\n");
27645 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27646 + pr_warn_once("dirperm1 breaks the protection"
27647 + " by the permission bits on the lower branch\n");
27651 + root = sb->s_root;
27652 + dir = d_inode(root);
27653 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27654 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27656 + bbot = au_sbbot(sb);
27657 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27659 + h_dir = au_h_iptr(dir, bindex);
27660 + br = au_sbr(sb, bindex);
27662 + if ((br->br_perm & AuBrAttr_ICEX)
27663 + && !h_dir->i_op->listxattr)
27664 + br->br_perm &= ~AuBrAttr_ICEX;
27665 +#if 0 /* untested */
27666 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27667 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27668 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27672 + wbr = br->br_wbr;
27674 + wbr_wh_read_lock(wbr);
27676 + if (!au_br_writable(br->br_perm)) {
27679 + || (!wbr->wbr_whbase
27680 + && !wbr->wbr_plink
27681 + && !wbr->wbr_orph));
27682 + } else if (!au_br_wh_linkable(br->br_perm)) {
27683 + /* skip = (!br->br_whbase && !br->br_orph); */
27684 + skip = (!wbr || !wbr->wbr_whbase);
27685 + if (skip && wbr) {
27687 + skip = !!wbr->wbr_plink;
27689 + skip = !wbr->wbr_plink;
27692 + /* skip = (br->br_whbase && br->br_ohph); */
27693 + skip = (wbr && wbr->wbr_whbase);
27696 + skip = !!wbr->wbr_plink;
27698 + skip = !wbr->wbr_plink;
27702 + wbr_wh_read_unlock(wbr);
27704 + if (can_no_dreval) {
27705 + dentry = br->br_path.dentry;
27706 + spin_lock(&dentry->d_lock);
27707 + if (dentry->d_flags &
27708 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27709 + can_no_dreval = 0;
27710 + spin_unlock(&dentry->d_lock);
27713 + if (au_br_fhsm(br->br_perm)) {
27715 + AuDebugOn(!br->br_fhsm);
27721 + hdir = au_hi(dir, bindex);
27722 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27724 + wbr_wh_write_lock(wbr);
27725 + err = au_wh_init(br, sb);
27727 + wbr_wh_write_unlock(wbr);
27728 + au_hn_inode_unlock(hdir);
27730 + if (!err && do_free) {
27731 + au_kfree_rcu(wbr);
27732 + br->br_wbr = NULL;
27736 + if (can_no_dreval)
27737 + au_fset_si(sbinfo, NO_DREVAL);
27739 + au_fclr_si(sbinfo, NO_DREVAL);
27742 + au_fset_si(sbinfo, FHSM);
27743 + for (bindex = bbot; bindex >= 0; bindex--) {
27744 + br = au_sbr(sb, bindex);
27745 + if (au_br_fhsm(br->br_perm)) {
27746 + au_fhsm_set_bottom(sb, bindex);
27751 + au_fclr_si(sbinfo, FHSM);
27752 + au_fhsm_set_bottom(sb, -1);
27758 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27761 + unsigned int tmp;
27762 + aufs_bindex_t bindex, bbot;
27763 + struct au_opt *opt;
27764 + struct au_opt_xino *opt_xino, xino;
27765 + struct au_sbinfo *sbinfo;
27766 + struct au_branch *br;
27767 + struct inode *dir;
27769 + SiMustWriteLock(sb);
27774 + while (err >= 0 && opt->type != Opt_tail)
27775 + err = au_opt_simple(sb, opt++, opts);
27778 + else if (unlikely(err < 0))
27781 + /* disable xino and udba temporary */
27782 + sbinfo = au_sbi(sb);
27783 + tmp = sbinfo->si_mntflags;
27784 + au_opt_clr(sbinfo->si_mntflags, XINO);
27785 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27788 + while (err >= 0 && opt->type != Opt_tail)
27789 + err = au_opt_br(sb, opt++, opts);
27792 + else if (unlikely(err < 0))
27795 + bbot = au_sbbot(sb);
27796 + if (unlikely(bbot < 0)) {
27798 + pr_err("no branches\n");
27802 + if (au_opt_test(tmp, XINO))
27803 + au_opt_set(sbinfo->si_mntflags, XINO);
27805 + while (!err && opt->type != Opt_tail)
27806 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27807 + if (unlikely(err))
27810 + err = au_opts_verify(sb, sb->s_flags, tmp);
27811 + if (unlikely(err))
27814 + /* restore xino */
27815 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27816 + xino.file = au_xino_def(sb);
27817 + err = PTR_ERR(xino.file);
27818 + if (IS_ERR(xino.file))
27821 + err = au_xino_set(sb, &xino, /*remount*/0);
27823 + if (unlikely(err))
27827 + /* restore udba */
27828 + tmp &= AuOptMask_UDBA;
27829 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27830 + sbinfo->si_mntflags |= tmp;
27831 + bbot = au_sbbot(sb);
27832 + for (bindex = 0; bindex <= bbot; bindex++) {
27833 + br = au_sbr(sb, bindex);
27834 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27835 + if (unlikely(err))
27836 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27838 + /* go on even if err */
27840 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27841 + dir = d_inode(sb->s_root);
27842 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27849 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27852 + unsigned char no_dreval;
27853 + struct inode *dir;
27854 + struct au_opt_xino *opt_xino;
27855 + struct au_opt *opt;
27856 + struct au_sbinfo *sbinfo;
27858 + SiMustWriteLock(sb);
27860 + err = au_dr_opt_flush(sb);
27861 + if (unlikely(err))
27863 + au_fset_opts(opts->flags, DR_FLUSHED);
27865 + dir = d_inode(sb->s_root);
27866 + sbinfo = au_sbi(sb);
27869 + while (err >= 0 && opt->type != Opt_tail) {
27870 + err = au_opt_simple(sb, opt, opts);
27872 + err = au_opt_br(sb, opt, opts);
27874 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27880 + /* go on even err */
27882 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27883 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27884 + if (unlikely(rerr && !err))
27887 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27888 + au_fset_opts(opts->flags, REFRESH_IDOP);
27890 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27891 + rerr = au_xib_trunc(sb);
27892 + if (unlikely(rerr && !err))
27896 + /* will be handled by the caller */
27897 + if (!au_ftest_opts(opts->flags, REFRESH)
27898 + && (opts->given_udba
27899 + || au_opt_test(sbinfo->si_mntflags, XINO)
27900 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27902 + au_fset_opts(opts->flags, REFRESH);
27904 + AuDbg("status 0x%x\n", opts->flags);
27910 +/* ---------------------------------------------------------------------- */
27912 +unsigned int au_opt_udba(struct super_block *sb)
27914 + return au_mntflags(sb) & AuOptMask_UDBA;
27916 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27917 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27918 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27920 +/* SPDX-License-Identifier: GPL-2.0 */
27922 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27924 + * This program is free software; you can redistribute it and/or modify
27925 + * it under the terms of the GNU General Public License as published by
27926 + * the Free Software Foundation; either version 2 of the License, or
27927 + * (at your option) any later version.
27929 + * This program is distributed in the hope that it will be useful,
27930 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27931 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27932 + * GNU General Public License for more details.
27934 + * You should have received a copy of the GNU General Public License
27935 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27939 + * mount options/flags
27942 +#ifndef __AUFS_OPTS_H__
27943 +#define __AUFS_OPTS_H__
27947 +#include <linux/fs_parser.h>
27948 +#include <linux/namei.h>
27949 +#include <linux/path.h>
27953 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27954 + Opt_idel, Opt_imod,
27955 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27956 + Opt_xino, Opt_noxino,
27957 + Opt_trunc_xino, Opt_trunc_xino_v,
27958 + Opt_trunc_xino_path, Opt_itrunc_xino,
27961 + Opt_plink, Opt_list_plink,
27964 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27966 + Opt_wbr_copyup, Opt_wbr_create,
27968 + Opt_verbose, Opt_noverbose,
27969 + Opt_sum, Opt_wsum,
27973 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27976 +/* ---------------------------------------------------------------------- */
27979 +#define AuOpt_XINO 1 /* external inode number bitmap
27980 + and translation table */
27981 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27982 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27983 +#define AuOpt_UDBA_REVAL (1 << 3)
27984 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27985 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27986 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27987 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27989 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27990 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27991 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27992 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27993 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27994 +#define AuOpt_DIO (1 << 14) /* direct io */
27995 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
27997 +#ifndef CONFIG_AUFS_HNOTIFY
27998 +#undef AuOpt_UDBA_HNOTIFY
27999 +#define AuOpt_UDBA_HNOTIFY 0
28001 +#ifndef CONFIG_AUFS_DIRREN
28002 +#undef AuOpt_DIRREN
28003 +#define AuOpt_DIRREN 0
28005 +#ifndef CONFIG_AUFS_SHWH
28007 +#define AuOpt_SHWH 0
28010 +#define AuOpt_Def (AuOpt_XINO \
28011 + | AuOpt_UDBA_REVAL \
28013 + /* | AuOpt_DIRPERM1 */ \
28014 + | AuOpt_WARN_PERM)
28015 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28016 + | AuOpt_UDBA_REVAL \
28017 + | AuOpt_UDBA_HNOTIFY)
28019 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28021 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28022 +#define au_opt_set(flags, name) do { \
28023 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28024 + ((flags) |= AuOpt_##name); \
28026 +#define au_opt_set_udba(flags, name) do { \
28027 + (flags) &= ~AuOptMask_UDBA; \
28028 + ((flags) |= AuOpt_##name); \
28030 +#define au_opt_clr(flags, name) do { \
28031 + ((flags) &= ~AuOpt_##name); \
28034 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28036 +#ifdef CONFIG_PROC_FS
28039 + return mntflags & ~AuOpt_PLINK;
28043 +/* ---------------------------------------------------------------------- */
28045 +/* policies to select one among multiple writable branches */
28047 + AuWbrCreate_TDP, /* top down parent */
28048 + AuWbrCreate_RR, /* round robin */
28049 + AuWbrCreate_MFS, /* most free space */
28050 + AuWbrCreate_MFSV, /* mfs with seconds */
28051 + AuWbrCreate_MFSRR, /* mfs then rr */
28052 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28053 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28054 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28055 + AuWbrCreate_PMFS, /* parent and mfs */
28056 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28057 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28058 + AuWbrCreate_PMFSRRV, /* plus seconds */
28060 + AuWbrCreate_Def = AuWbrCreate_TDP
28064 + AuWbrCopyup_TDP, /* top down parent */
28065 + AuWbrCopyup_BUP, /* bottom up parent */
28066 + AuWbrCopyup_BU, /* bottom up */
28068 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28071 +/* ---------------------------------------------------------------------- */
28075 +struct au_opt_add {
28076 + aufs_bindex_t bindex;
28079 + struct path path;
28082 +struct au_opt_del {
28084 + struct path h_path;
28087 +struct au_opt_mod {
28090 + struct dentry *h_root;
28093 +struct au_opt_xino {
28095 + struct file *file;
28098 +struct au_opt_xino_itrunc {
28099 + aufs_bindex_t bindex;
28102 +struct au_opt_wbr_create {
28105 + unsigned long long mfsrr_watermark;
28111 + struct au_opt_xino xino;
28112 + struct au_opt_xino_itrunc xino_itrunc;
28113 + struct au_opt_add add;
28114 + struct au_opt_del del;
28115 + struct au_opt_mod mod;
28118 + unsigned int rdblk;
28119 + unsigned int rdhash;
28121 + struct au_opt_wbr_create wbr_create;
28123 + unsigned int fhsm_second;
28124 + bool tf; /* generic flag, true or false */
28129 +#define AuOpts_REMOUNT 1
28130 +#define AuOpts_REFRESH (1 << 1)
28131 +#define AuOpts_TRUNC_XIB (1 << 2)
28132 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28133 +#define AuOpts_REFRESH_IDOP (1 << 4)
28134 +#define AuOpts_DR_FLUSHED (1 << 5)
28135 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28136 +#define au_fset_opts(flags, name) \
28137 + do { (flags) |= AuOpts_##name; } while (0)
28138 +#define au_fclr_opts(flags, name) \
28139 + do { (flags) &= ~AuOpts_##name; } while (0)
28141 +#ifndef CONFIG_AUFS_DIRREN
28142 +#undef AuOpts_DR_FLUSHED
28143 +#define AuOpts_DR_FLUSHED 0
28147 + struct au_opt *opt;
28150 + unsigned int given_udba;
28151 + unsigned int flags;
28152 + unsigned long sb_flags;
28155 +/* ---------------------------------------------------------------------- */
28158 +int au_br_perm_val(char *perm);
28159 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28160 +int au_udba_val(char *str);
28161 +const char *au_optstr_udba(int udba);
28162 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28163 +const char *au_optstr_wbr_create(int wbr_create);
28164 +int au_wbr_copyup_val(char *str);
28165 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28167 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28168 + aufs_bindex_t bindex);
28169 +struct super_block;
28170 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28171 + unsigned int pending);
28172 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28173 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28175 +unsigned int au_opt_udba(struct super_block *sb);
28178 +int aufs_fsctx_init(struct fs_context *fc);
28179 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28181 +#endif /* __KERNEL__ */
28182 +#endif /* __AUFS_OPTS_H__ */
28183 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28184 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28185 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28187 +// SPDX-License-Identifier: GPL-2.0
28189 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28191 + * This program is free software; you can redistribute it and/or modify
28192 + * it under the terms of the GNU General Public License as published by
28193 + * the Free Software Foundation; either version 2 of the License, or
28194 + * (at your option) any later version.
28196 + * This program is distributed in the hope that it will be useful,
28197 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28198 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28199 + * GNU General Public License for more details.
28201 + * You should have received a copy of the GNU General Public License
28202 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28212 + * the pseudo-link maintenance mode.
28213 + * during a user process maintains the pseudo-links,
28214 + * prohibit adding a new plink and branch manipulation.
28218 + * For entry functions which will handle plink, and i_mutex is already held
28220 + * They cannot wait and should return an error at once.
28221 + * Callers has to check the error.
28223 + * For entry functions which will handle plink, but i_mutex is not held
28225 + * They can wait the plink maintenance mode to finish.
28227 + * They behave like F_SETLK and F_SETLKW.
28228 + * If the caller never handle plink, then both flags are unnecessary.
28231 +int au_plink_maint(struct super_block *sb, int flags)
28235 + struct task_struct *parent, *prev;
28236 + struct au_sbinfo *sbi;
28238 + SiMustAnyLock(sb);
28241 + if (!au_opt_test(au_mntflags(sb), PLINK))
28244 + sbi = au_sbi(sb);
28245 + pid = sbi->si_plink_maint_pid;
28246 + if (!pid || pid == current->pid)
28249 + /* todo: it highly depends upon /sbin/mount.aufs */
28251 + parent = current;
28255 + parent = rcu_dereference(parent->real_parent);
28256 + if (parent == prev)
28258 + ppid = task_pid_vnr(parent);
28259 + if (pid == ppid) {
28260 + rcu_read_unlock();
28265 + rcu_read_unlock();
28267 + if (au_ftest_lock(flags, NOPLMW)) {
28268 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28269 + /* AuDebugOn(!lockdep_depth(current)); */
28270 + while (sbi->si_plink_maint_pid) {
28271 + si_read_unlock(sb);
28272 + /* gave up wake_up_bit() */
28273 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28275 + if (au_ftest_lock(flags, FLUSH))
28276 + au_nwt_flush(&sbi->si_nowait);
28277 + si_noflush_read_lock(sb);
28279 + } else if (au_ftest_lock(flags, NOPLM)) {
28280 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28288 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28290 + spin_lock(&sbinfo->si_plink_maint_lock);
28291 + sbinfo->si_plink_maint_pid = 0;
28292 + spin_unlock(&sbinfo->si_plink_maint_lock);
28293 + wake_up_all(&sbinfo->si_plink_wq);
28296 +int au_plink_maint_enter(struct super_block *sb)
28299 + struct au_sbinfo *sbinfo;
28302 + sbinfo = au_sbi(sb);
28303 + /* make sure i am the only one in this fs */
28304 + si_write_lock(sb, AuLock_FLUSH);
28305 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28306 + spin_lock(&sbinfo->si_plink_maint_lock);
28307 + if (!sbinfo->si_plink_maint_pid)
28308 + sbinfo->si_plink_maint_pid = current->pid;
28311 + spin_unlock(&sbinfo->si_plink_maint_lock);
28313 + si_write_unlock(sb);
28318 +/* ---------------------------------------------------------------------- */
28320 +#ifdef CONFIG_AUFS_DEBUG
28321 +void au_plink_list(struct super_block *sb)
28324 + struct au_sbinfo *sbinfo;
28325 + struct hlist_bl_head *hbl;
28326 + struct hlist_bl_node *pos;
28327 + struct au_icntnr *icntnr;
28329 + SiMustAnyLock(sb);
28331 + sbinfo = au_sbi(sb);
28332 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28333 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28335 + for (i = 0; i < AuPlink_NHASH; i++) {
28336 + hbl = sbinfo->si_plink + i;
28337 + hlist_bl_lock(hbl);
28338 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28339 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28340 + hlist_bl_unlock(hbl);
28345 +/* is the inode pseudo-linked? */
28346 +int au_plink_test(struct inode *inode)
28349 + struct au_sbinfo *sbinfo;
28350 + struct hlist_bl_head *hbl;
28351 + struct hlist_bl_node *pos;
28352 + struct au_icntnr *icntnr;
28354 + sbinfo = au_sbi(inode->i_sb);
28355 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28356 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28357 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28360 + i = au_plink_hash(inode->i_ino);
28361 + hbl = sbinfo->si_plink + i;
28362 + hlist_bl_lock(hbl);
28363 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28364 + if (&icntnr->vfs_inode == inode) {
28368 + hlist_bl_unlock(hbl);
28372 +/* ---------------------------------------------------------------------- */
28375 + * generate a name for plink.
28376 + * the file will be stored under AUFS_WH_PLINKDIR.
28378 +/* 20 is max digits length of ulong 64 */
28379 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28381 +static int plink_name(char *name, int len, struct inode *inode,
28382 + aufs_bindex_t bindex)
28385 + struct inode *h_inode;
28387 + h_inode = au_h_iptr(inode, bindex);
28388 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28392 +struct au_do_plink_lkup_args {
28393 + struct dentry **errp;
28394 + struct qstr *tgtname;
28395 + struct path *h_ppath;
28398 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28399 + struct path *h_ppath)
28401 + struct dentry *h_dentry;
28402 + struct inode *h_inode;
28404 + h_inode = d_inode(h_ppath->dentry);
28405 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28406 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28407 + inode_unlock_shared(h_inode);
28412 +static void au_call_do_plink_lkup(void *args)
28414 + struct au_do_plink_lkup_args *a = args;
28415 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28418 +/* lookup the plink-ed @inode under the branch at @bindex */
28419 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28421 + struct dentry *h_dentry;
28422 + struct au_branch *br;
28423 + struct path h_ppath;
28425 + char a[PLINK_NAME_LEN];
28426 + struct qstr tgtname = QSTR_INIT(a, 0);
28428 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28430 + br = au_sbr(inode->i_sb, bindex);
28431 + h_ppath.dentry = br->br_wbr->wbr_plink;
28432 + h_ppath.mnt = au_br_mnt(br);
28433 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28435 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28436 + struct au_do_plink_lkup_args args = {
28437 + .errp = &h_dentry,
28438 + .tgtname = &tgtname,
28439 + .h_ppath = &h_ppath
28442 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28443 + if (unlikely(wkq_err))
28444 + h_dentry = ERR_PTR(wkq_err);
28446 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28451 +/* create a pseudo-link */
28452 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28453 + struct dentry *h_dentry)
28456 + struct path h_path;
28457 + struct inode *h_dir, *delegated;
28459 + h_dir = d_inode(h_ppath->dentry);
28460 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28461 + h_path.mnt = h_ppath->mnt;
28463 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28464 + err = PTR_ERR(h_path.dentry);
28465 + if (IS_ERR(h_path.dentry))
28469 + /* wh.plink dir is not monitored */
28470 + /* todo: is it really safe? */
28471 + if (d_is_positive(h_path.dentry)
28472 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28473 + delegated = NULL;
28474 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28475 + if (unlikely(err == -EWOULDBLOCK)) {
28476 + pr_warn("cannot retry for NFSv4 delegation"
28477 + " for an internal unlink\n");
28480 + dput(h_path.dentry);
28481 + h_path.dentry = NULL;
28485 + if (!err && d_is_negative(h_path.dentry)) {
28486 + delegated = NULL;
28487 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28488 + if (unlikely(err == -EWOULDBLOCK)) {
28489 + pr_warn("cannot retry for NFSv4 delegation"
28490 + " for an internal link\n");
28494 + dput(h_path.dentry);
28497 + inode_unlock(h_dir);
28501 +struct do_whplink_args {
28503 + struct qstr *tgt;
28504 + struct path *h_ppath;
28505 + struct dentry *h_dentry;
28508 +static void call_do_whplink(void *args)
28510 + struct do_whplink_args *a = args;
28511 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28514 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28515 + aufs_bindex_t bindex)
28517 + int err, wkq_err;
28518 + struct au_branch *br;
28519 + struct au_wbr *wbr;
28520 + struct path h_ppath;
28521 + char a[PLINK_NAME_LEN];
28522 + struct qstr tgtname = QSTR_INIT(a, 0);
28524 + br = au_sbr(inode->i_sb, bindex);
28525 + wbr = br->br_wbr;
28526 + h_ppath.dentry = wbr->wbr_plink;
28527 + h_ppath.mnt = au_br_mnt(br);
28528 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28530 + /* always superio. */
28531 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28532 + struct do_whplink_args args = {
28535 + .h_ppath = &h_ppath,
28536 + .h_dentry = h_dentry
28538 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28539 + if (unlikely(wkq_err))
28542 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28548 + * create a new pseudo-link for @h_dentry on @bindex.
28549 + * the linked inode is held in aufs @inode.
28551 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28552 + struct dentry *h_dentry)
28554 + struct super_block *sb;
28555 + struct au_sbinfo *sbinfo;
28556 + struct hlist_bl_head *hbl;
28557 + struct hlist_bl_node *pos;
28558 + struct au_icntnr *icntnr;
28559 + int found, err, cnt, i;
28561 + sb = inode->i_sb;
28562 + sbinfo = au_sbi(sb);
28563 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28564 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28566 + found = au_plink_test(inode);
28570 + i = au_plink_hash(inode->i_ino);
28571 + hbl = sbinfo->si_plink + i;
28574 + hlist_bl_lock(hbl);
28575 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28576 + if (&icntnr->vfs_inode == inode) {
28582 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28583 + hlist_bl_add_head(&icntnr->plink, hbl);
28585 + hlist_bl_unlock(hbl);
28587 + cnt = au_hbl_count(hbl);
28588 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28589 + if (cnt > AUFS_PLINK_WARN)
28590 + AuWarn1(msg ", %d\n", cnt);
28592 + err = whplink(h_dentry, inode, bindex);
28593 + if (unlikely(err)) {
28594 + pr_warn("err %d, damaged pseudo link.\n", err);
28595 + au_hbl_del(&icntnr->plink, hbl);
28596 + iput(&icntnr->vfs_inode);
28599 + iput(&icntnr->vfs_inode);
28602 +/* free all plinks */
28603 +void au_plink_put(struct super_block *sb, int verbose)
28606 + struct au_sbinfo *sbinfo;
28607 + struct hlist_bl_head *hbl;
28608 + struct hlist_bl_node *pos, *tmp;
28609 + struct au_icntnr *icntnr;
28611 + SiMustWriteLock(sb);
28613 + sbinfo = au_sbi(sb);
28614 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28615 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28617 + /* no spin_lock since sbinfo is write-locked */
28619 + for (i = 0; i < AuPlink_NHASH; i++) {
28620 + hbl = sbinfo->si_plink + i;
28621 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28622 + pr_warn("pseudo-link is not flushed");
28625 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28626 + iput(&icntnr->vfs_inode);
28627 + INIT_HLIST_BL_HEAD(hbl);
28631 +void au_plink_clean(struct super_block *sb, int verbose)
28633 + struct dentry *root;
28635 + root = sb->s_root;
28636 + aufs_write_lock(root);
28637 + if (au_opt_test(au_mntflags(sb), PLINK))
28638 + au_plink_put(sb, verbose);
28639 + aufs_write_unlock(root);
28642 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28645 + aufs_bindex_t btop, bbot, bindex;
28648 + btop = au_ibtop(inode);
28649 + bbot = au_ibbot(inode);
28651 + for (bindex = btop; bindex <= bbot; bindex++) {
28652 + if (!au_h_iptr(inode, bindex)
28653 + || au_ii_br_id(inode, bindex) != br_id)
28655 + au_set_h_iptr(inode, bindex, NULL, 0);
28660 + for (bindex = btop; bindex <= bbot; bindex++)
28661 + if (au_h_iptr(inode, bindex)) {
28671 +/* free the plinks on a branch specified by @br_id */
28672 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28674 + struct au_sbinfo *sbinfo;
28675 + struct hlist_bl_head *hbl;
28676 + struct hlist_bl_node *pos, *tmp;
28677 + struct au_icntnr *icntnr;
28678 + struct inode *inode;
28681 + SiMustWriteLock(sb);
28683 + sbinfo = au_sbi(sb);
28684 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28685 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28687 + /* no bit_lock since sbinfo is write-locked */
28688 + for (i = 0; i < AuPlink_NHASH; i++) {
28689 + hbl = sbinfo->si_plink + i;
28690 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28691 + inode = au_igrab(&icntnr->vfs_inode);
28692 + ii_write_lock_child(inode);
28693 + do_put = au_plink_do_half_refresh(inode, br_id);
28695 + hlist_bl_del(&icntnr->plink);
28698 + ii_write_unlock(inode);
28703 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28704 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28705 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28707 +// SPDX-License-Identifier: GPL-2.0
28709 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28711 + * This program is free software; you can redistribute it and/or modify
28712 + * it under the terms of the GNU General Public License as published by
28713 + * the Free Software Foundation; either version 2 of the License, or
28714 + * (at your option) any later version.
28716 + * This program is distributed in the hope that it will be useful,
28717 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28718 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28719 + * GNU General Public License for more details.
28721 + * You should have received a copy of the GNU General Public License
28722 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28727 + * There is only one filesystem which implements ->poll operation, currently.
28732 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28735 + struct file *h_file;
28736 + struct super_block *sb;
28738 + /* We should pretend an error happened. */
28739 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28740 + sb = file->f_path.dentry->d_sb;
28741 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28743 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28744 + if (IS_ERR(h_file)) {
28745 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28749 + mask = vfs_poll(h_file, pt);
28750 + fput(h_file); /* instead of au_read_post() */
28753 + si_read_unlock(sb);
28754 + if (mask & EPOLLERR)
28755 + AuDbg("mask 0x%x\n", mask);
28758 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28759 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28760 +++ linux/fs/aufs/posix_acl.c 2023-09-03 02:21:58.863304341 +0200
28762 +// SPDX-License-Identifier: GPL-2.0
28764 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28766 + * This program is free software; you can redistribute it and/or modify
28767 + * it under the terms of the GNU General Public License as published by
28768 + * the Free Software Foundation; either version 2 of the License, or
28769 + * (at your option) any later version.
28771 + * This program is distributed in the hope that it will be useful,
28772 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28773 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28774 + * GNU General Public License for more details.
28776 + * You should have received a copy of the GNU General Public License
28777 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28781 + * posix acl operations
28784 +#include <linux/fs.h>
28787 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu)
28789 + struct posix_acl *acl;
28791 + aufs_bindex_t bindex;
28792 + struct inode *h_inode;
28793 + struct super_block *sb;
28795 + acl = ERR_PTR(-ECHILD);
28800 + sb = inode->i_sb;
28801 + si_read_lock(sb, AuLock_FLUSH);
28802 + ii_read_lock_child(inode);
28803 + if (!(sb->s_flags & SB_POSIXACL))
28806 + bindex = au_ibtop(inode);
28807 + h_inode = au_h_iptr(inode, bindex);
28808 + if (unlikely(!h_inode
28809 + || ((h_inode->i_mode & S_IFMT)
28810 + != (inode->i_mode & S_IFMT)))) {
28811 + err = au_busy_or_stale();
28812 + acl = ERR_PTR(err);
28816 + /* always topmost only */
28817 + acl = get_inode_acl(h_inode, type);
28819 + forget_cached_acl(inode, type);
28821 + set_cached_acl(inode, type, acl);
28824 + ii_read_unlock(inode);
28825 + si_read_unlock(sb);
28828 + AuTraceErrPtr(acl);
28832 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
28833 + struct dentry *dentry, int type)
28835 + struct posix_acl *acl;
28836 + struct inode *inode;
28838 + inode = d_inode(dentry);
28839 + acl = aufs_get_inode_acl(inode, type, /*rcu*/false);
28844 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
28845 + struct posix_acl *acl, int type)
28849 + struct inode *inode;
28850 + struct au_sxattr arg = {
28851 + .type = AU_ACL_SET,
28858 + inode = d_inode(dentry);
28859 + IMustLock(inode);
28861 + ssz = au_sxattr(dentry, inode, &arg);
28862 + /* forget even it if succeeds since the branch might set differently */
28863 + forget_cached_acl(inode, type);
28870 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28871 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28872 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28874 +// SPDX-License-Identifier: GPL-2.0
28876 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28878 + * This program is free software; you can redistribute it and/or modify
28879 + * it under the terms of the GNU General Public License as published by
28880 + * the Free Software Foundation; either version 2 of the License, or
28881 + * (at your option) any later version.
28883 + * This program is distributed in the hope that it will be useful,
28884 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28885 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28886 + * GNU General Public License for more details.
28888 + * You should have received a copy of the GNU General Public License
28889 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28893 + * procfs interfaces
28896 +#include <linux/proc_fs.h>
28899 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28901 + struct au_sbinfo *sbinfo;
28903 + sbinfo = file->private_data;
28905 + au_plink_maint_leave(sbinfo);
28906 + kobject_put(&sbinfo->si_kobj);
28912 +static void au_procfs_plm_write_clean(struct file *file)
28914 + struct au_sbinfo *sbinfo;
28916 + sbinfo = file->private_data;
28918 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28921 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28924 + struct super_block *sb;
28925 + struct au_sbinfo *sbinfo;
28926 + struct hlist_bl_node *pos;
28929 + if (unlikely(file->private_data))
28933 + /* don't use au_sbilist_lock() here */
28934 + hlist_bl_lock(&au_sbilist);
28935 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28936 + if (id == sysaufs_si_id(sbinfo)) {
28937 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28938 + sb = sbinfo->si_sb;
28941 + hlist_bl_unlock(&au_sbilist);
28944 + if (unlikely(!sb))
28947 + err = au_plink_maint_enter(sb);
28949 + /* keep kobject_get() */
28950 + file->private_data = sbinfo;
28952 + kobject_put(&sbinfo->si_kobj);
28958 + * Accept a valid "si=xxxx" only.
28959 + * Once it is accepted successfully, accept "clean" too.
28961 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28962 + size_t count, loff_t *ppos)
28965 + unsigned long id;
28966 + /* last newline is allowed */
28967 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28970 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28974 + if (unlikely(count > sizeof(buf)))
28977 + err = copy_from_user(buf, ubuf, count);
28978 + if (unlikely(err)) {
28985 + if (!strcmp("clean", buf)) {
28986 + au_procfs_plm_write_clean(file);
28987 + goto out_success;
28988 + } else if (unlikely(strncmp("si=", buf, 3)))
28991 + err = kstrtoul(buf + 3, 16, &id);
28992 + if (unlikely(err))
28995 + err = au_procfs_plm_write_si(file, id);
28996 + if (unlikely(err))
29000 + err = count; /* success */
29005 +static const struct proc_ops au_procfs_plm_op = {
29006 + .proc_write = au_procfs_plm_write,
29007 + .proc_release = au_procfs_plm_release
29010 +/* ---------------------------------------------------------------------- */
29012 +static struct proc_dir_entry *au_procfs_dir;
29014 +void au_procfs_fin(void)
29016 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29017 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29020 +int __init au_procfs_init(void)
29023 + struct proc_dir_entry *entry;
29026 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29027 + if (unlikely(!au_procfs_dir))
29030 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29031 + au_procfs_dir, &au_procfs_plm_op);
29032 + if (unlikely(!entry))
29036 + goto out; /* success */
29040 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29044 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29045 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29046 +++ linux/fs/aufs/rdu.c 2023-09-04 13:39:55.763295607 +0200
29048 +// SPDX-License-Identifier: GPL-2.0
29050 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29052 + * This program is free software; you can redistribute it and/or modify
29053 + * it under the terms of the GNU General Public License as published by
29054 + * the Free Software Foundation; either version 2 of the License, or
29055 + * (at your option) any later version.
29057 + * This program is distributed in the hope that it will be useful,
29058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29060 + * GNU General Public License for more details.
29062 + * You should have received a copy of the GNU General Public License
29063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29067 + * readdir in userspace.
29070 +#include <linux/compat.h>
29071 +#include <linux/fs_stack.h>
29072 +#include <linux/security.h>
29075 +/* bits for struct aufs_rdu.flags */
29076 +#define AuRdu_CALLED 1
29077 +#define AuRdu_CONT (1 << 1)
29078 +#define AuRdu_FULL (1 << 2)
29079 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29080 +#define au_fset_rdu(flags, name) \
29081 + do { (flags) |= AuRdu_##name; } while (0)
29082 +#define au_fclr_rdu(flags, name) \
29083 + do { (flags) &= ~AuRdu_##name; } while (0)
29085 +struct au_rdu_arg {
29086 + struct dir_context ctx;
29087 + struct aufs_rdu *rdu;
29088 + union au_rdu_ent_ul ent;
29089 + unsigned long end;
29091 + struct super_block *sb;
29095 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29096 + loff_t offset, u64 h_ino, unsigned int d_type)
29099 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29100 + struct aufs_rdu *rdu = arg->rdu;
29101 + struct au_rdu_ent ent;
29105 + au_fset_rdu(rdu->cookie.flags, CALLED);
29106 + len = au_rdu_len(nlen);
29107 + if (arg->ent.ul + len < arg->end) {
29109 + ent.bindex = rdu->cookie.bindex;
29110 + ent.type = d_type;
29112 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29113 + ent.type = DT_UNKNOWN;
29115 + /* unnecessary to support mmap_sem since this is a dir */
29117 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29119 + if (copy_to_user(arg->ent.e->name, name, nlen))
29121 + /* the terminating NULL */
29122 + if (__put_user(0, arg->ent.e->name + nlen))
29125 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29126 + arg->ent.ul += len;
29130 + au_fset_rdu(rdu->cookie.flags, FULL);
29132 + rdu->tail = arg->ent;
29136 + /* AuTraceErr(err); */
29140 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29144 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29146 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29147 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29149 + if (unlikely(offset != cookie->h_pos))
29155 + au_fclr_rdu(cookie->flags, CALLED);
29157 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29161 + && au_ftest_rdu(cookie->flags, CALLED)
29162 + && !au_ftest_rdu(cookie->flags, FULL));
29163 + cookie->h_pos = h_file->f_pos;
29170 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29173 + aufs_bindex_t bbot;
29174 + struct au_rdu_arg arg = {
29176 + .actor = au_rdu_fill
29179 + struct dentry *dentry;
29180 + struct inode *inode;
29181 + struct file *h_file;
29182 + struct au_rdu_cookie *cookie = &rdu->cookie;
29184 + /* VERIFY_WRITE */
29185 + err = !access_ok(rdu->ent.e, rdu->sz);
29186 + if (unlikely(err)) {
29192 + rdu->tail = rdu->ent;
29195 + arg.ent = rdu->ent;
29196 + arg.end = arg.ent.ul;
29197 + arg.end += rdu->sz;
29200 + if (unlikely(!file->f_op->iterate_shared))
29203 + err = security_file_permission(file, MAY_READ);
29205 + if (unlikely(err))
29208 + dentry = file->f_path.dentry;
29209 + inode = d_inode(dentry);
29210 + inode_lock_shared(inode);
29212 + arg.sb = inode->i_sb;
29213 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29214 + if (unlikely(err))
29216 + err = au_alive_dir(dentry);
29217 + if (unlikely(err))
29219 + /* todo: reval? */
29220 + fi_read_lock(file);
29223 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29224 + && cookie->generation != au_figen(file)))
29229 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29231 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29233 + bbot = au_fbtop(file);
29234 + if (cookie->bindex < bbot)
29235 + cookie->bindex = bbot;
29236 + bbot = au_fbbot_dir(file);
29237 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29238 + for (; !err && cookie->bindex <= bbot;
29239 + cookie->bindex++, cookie->h_pos = 0) {
29240 + h_file = au_hf_dir(file, cookie->bindex);
29244 + au_fclr_rdu(cookie->flags, FULL);
29245 + err = au_rdu_do(h_file, &arg);
29247 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29250 + AuDbg("rent %llu\n", rdu->rent);
29252 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29253 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29254 + au_fset_rdu(cookie->flags, CONT);
29255 + cookie->generation = au_figen(file);
29258 + ii_read_lock_child(inode);
29259 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29260 + ii_read_unlock(inode);
29263 + fi_read_unlock(file);
29265 + si_read_unlock(arg.sb);
29267 + inode_unlock_shared(inode);
29273 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29277 + unsigned long long nent;
29278 + union au_rdu_ent_ul *u;
29279 + struct au_rdu_ent ent;
29280 + struct super_block *sb;
29283 + nent = rdu->nent;
29285 + sb = file->f_path.dentry->d_sb;
29286 + si_read_lock(sb, AuLock_FLUSH);
29287 + while (nent-- > 0) {
29288 + /* unnecessary to support mmap_sem since this is a dir */
29289 + err = copy_from_user(&ent, u->e, sizeof(ent));
29291 + /* VERIFY_WRITE */
29292 + err = !access_ok(&u->e->ino, sizeof(ino));
29293 + if (unlikely(err)) {
29299 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29301 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29303 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29305 + if (unlikely(err)) {
29310 + err = __put_user(ino, &u->e->ino);
29311 + if (unlikely(err)) {
29316 + u->ul += au_rdu_len(ent.nlen);
29318 + si_read_unlock(sb);
29323 +/* ---------------------------------------------------------------------- */
29325 +static int au_rdu_verify(struct aufs_rdu *rdu)
29327 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29328 + "%llu, b%d, 0x%x, g%u}\n",
29329 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29331 + rdu->rent, rdu->shwh, rdu->full,
29332 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29333 + rdu->cookie.generation);
29335 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29339 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29343 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29346 + struct aufs_rdu rdu;
29347 + void __user *p = (void __user *)arg;
29349 + err = copy_from_user(&rdu, p, sizeof(rdu));
29350 + if (unlikely(err)) {
29355 + err = au_rdu_verify(&rdu);
29356 + if (unlikely(err))
29360 + case AUFS_CTL_RDU:
29361 + err = au_rdu(file, &rdu);
29362 + if (unlikely(err))
29365 + e = copy_to_user(p, &rdu, sizeof(rdu));
29366 + if (unlikely(e)) {
29371 + case AUFS_CTL_RDU_INO:
29372 + err = au_rdu_ino(file, &rdu);
29376 + /* err = -ENOTTY; */
29385 +#ifdef CONFIG_COMPAT
29386 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29389 + struct aufs_rdu rdu;
29390 + void __user *p = compat_ptr(arg);
29392 + /* todo: get_user()? */
29393 + err = copy_from_user(&rdu, p, sizeof(rdu));
29394 + if (unlikely(err)) {
29399 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29400 + err = au_rdu_verify(&rdu);
29401 + if (unlikely(err))
29405 + case AUFS_CTL_RDU:
29406 + err = au_rdu(file, &rdu);
29407 + if (unlikely(err))
29410 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29411 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29412 + e = copy_to_user(p, &rdu, sizeof(rdu));
29413 + if (unlikely(e)) {
29418 + case AUFS_CTL_RDU_INO:
29419 + err = au_rdu_ino(file, &rdu);
29423 + /* err = -ENOTTY; */
29432 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29433 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29434 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29436 +/* SPDX-License-Identifier: GPL-2.0 */
29438 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29440 + * This program is free software; you can redistribute it and/or modify
29441 + * it under the terms of the GNU General Public License as published by
29442 + * the Free Software Foundation; either version 2 of the License, or
29443 + * (at your option) any later version.
29445 + * This program is distributed in the hope that it will be useful,
29446 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29447 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29448 + * GNU General Public License for more details.
29450 + * You should have received a copy of the GNU General Public License
29451 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29455 + * simple read-write semaphore wrappers
29458 +#ifndef __AUFS_RWSEM_H__
29459 +#define __AUFS_RWSEM_H__
29463 +#include "debug.h"
29465 +/* in the future, the name 'au_rwsem' will be totally gone */
29466 +#define au_rwsem rw_semaphore
29468 +/* to debug easier, do not make them inlined functions */
29469 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29471 +#ifdef CONFIG_LOCKDEP
29472 +/* rwsem_is_locked() is unusable */
29473 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29474 + && !lockdep_recursing(current) \
29476 + && !lockdep_is_held_type(rw, 1))
29477 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29478 + && !lockdep_recursing(current) \
29480 + && !lockdep_is_held_type(rw, 0))
29481 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29482 + && !lockdep_recursing(current) \
29484 + && !lockdep_is_held(rw))
29485 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29486 + && !lockdep_recursing(current) \
29488 + && lockdep_is_held(rw))
29490 +#define AuRwMustReadLock(rw) do {} while (0)
29491 +#define AuRwMustWriteLock(rw) do {} while (0)
29492 +#define AuRwMustAnyLock(rw) do {} while (0)
29493 +#define AuRwDestroy(rw) do {} while (0)
29496 +#define au_rw_init(rw) init_rwsem(rw)
29498 +#define au_rw_init_wlock(rw) do { \
29499 + au_rw_init(rw); \
29500 + down_write(rw); \
29503 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29504 + au_rw_init(rw); \
29505 + down_write_nested(rw, lsc); \
29508 +#define au_rw_read_lock(rw) down_read(rw)
29509 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29510 +#define au_rw_read_unlock(rw) up_read(rw)
29511 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29512 +#define au_rw_write_lock(rw) down_write(rw)
29513 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29514 +#define au_rw_write_unlock(rw) up_write(rw)
29515 +/* why is not _nested version defined? */
29516 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29517 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29519 +#endif /* __KERNEL__ */
29520 +#endif /* __AUFS_RWSEM_H__ */
29521 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29522 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29523 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29525 +// SPDX-License-Identifier: GPL-2.0
29527 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29529 + * This program is free software; you can redistribute it and/or modify
29530 + * it under the terms of the GNU General Public License as published by
29531 + * the Free Software Foundation; either version 2 of the License, or
29532 + * (at your option) any later version.
29534 + * This program is distributed in the hope that it will be useful,
29535 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29536 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29537 + * GNU General Public License for more details.
29539 + * You should have received a copy of the GNU General Public License
29540 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29544 + * superblock private data
29547 +#include <linux/iversion.h>
29551 + * they are necessary regardless sysfs is disabled.
29553 +void au_si_free(struct kobject *kobj)
29556 + struct au_sbinfo *sbinfo;
29557 + char *locked __maybe_unused; /* debug only */
29559 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29560 + for (i = 0; i < AuPlink_NHASH; i++)
29561 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29562 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29564 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29565 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29566 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29567 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29569 + dbgaufs_si_fin(sbinfo);
29570 + au_rw_write_lock(&sbinfo->si_rwsem);
29571 + au_br_free(sbinfo);
29572 + au_rw_write_unlock(&sbinfo->si_rwsem);
29574 + au_kfree_try_rcu(sbinfo->si_branch);
29575 + mutex_destroy(&sbinfo->si_xib_mtx);
29576 + AuRwDestroy(&sbinfo->si_rwsem);
29578 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29579 + /* si_nfiles is waited too */
29580 + au_kfree_rcu(sbinfo);
29583 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29585 + struct au_sbinfo *sbinfo;
29589 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29590 + if (unlikely(!sbinfo))
29593 + /* will be reallocated separately */
29594 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29595 + if (unlikely(!sbinfo->si_branch))
29598 + err = sysaufs_si_init(sbinfo);
29600 + dbgaufs_si_null(sbinfo);
29601 + err = dbgaufs_si_init(sbinfo);
29602 + if (unlikely(err))
29603 + kobject_put(&sbinfo->si_kobj);
29605 + if (unlikely(err))
29608 + au_nwt_init(&sbinfo->si_nowait);
29609 + au_rw_init_wlock(&sbinfo->si_rwsem);
29611 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29612 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29614 + sbinfo->si_bbot = -1;
29615 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29617 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29618 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29619 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29620 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29622 + au_fhsm_init(sbinfo);
29624 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29626 + sbinfo->si_xino_jiffy = jiffies;
29627 + sbinfo->si_xino_expire
29628 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29629 + mutex_init(&sbinfo->si_xib_mtx);
29630 + /* leave si_xib_last_pindex and si_xib_next_bit */
29632 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29634 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29635 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29636 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29637 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29639 + for (i = 0; i < AuPlink_NHASH; i++)
29640 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29641 + init_waitqueue_head(&sbinfo->si_plink_wq);
29642 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29644 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29646 + /* with getattr by default */
29647 + sbinfo->si_iop_array = aufs_iop;
29649 + /* leave other members for sysaufs and si_mnt. */
29650 + sbinfo->si_sb = sb;
29652 + sb->s_fs_info = sbinfo;
29655 + return sbinfo; /* success */
29658 + au_kfree_try_rcu(sbinfo->si_branch);
29660 + au_kfree_rcu(sbinfo);
29662 + return ERR_PTR(err);
29665 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29668 + struct au_branch **brp;
29670 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29673 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29674 + if (unlikely(!sz))
29675 + sz = sizeof(*brp);
29676 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29679 + sbinfo->si_branch = brp;
29686 +/* ---------------------------------------------------------------------- */
29688 +unsigned int au_sigen_inc(struct super_block *sb)
29690 + unsigned int gen;
29691 + struct inode *inode;
29693 + SiMustWriteLock(sb);
29695 + gen = ++au_sbi(sb)->si_generation;
29696 + au_update_digen(sb->s_root);
29697 + inode = d_inode(sb->s_root);
29698 + au_update_iigen(inode, /*half*/0);
29699 + inode_inc_iversion(inode);
29703 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29705 + aufs_bindex_t br_id;
29707 + struct au_sbinfo *sbinfo;
29709 + SiMustWriteLock(sb);
29711 + sbinfo = au_sbi(sb);
29712 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29713 + br_id = ++sbinfo->si_last_br_id;
29714 + AuDebugOn(br_id < 0);
29715 + if (br_id && au_br_index(sb, br_id) < 0)
29722 +/* ---------------------------------------------------------------------- */
29724 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29725 +int si_read_lock(struct super_block *sb, int flags)
29730 + if (au_ftest_lock(flags, FLUSH))
29731 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29733 + si_noflush_read_lock(sb);
29734 + err = au_plink_maint(sb, flags);
29735 + if (unlikely(err))
29736 + si_read_unlock(sb);
29741 +int si_write_lock(struct super_block *sb, int flags)
29745 + if (au_ftest_lock(flags, FLUSH))
29746 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29748 + si_noflush_write_lock(sb);
29749 + err = au_plink_maint(sb, flags);
29750 + if (unlikely(err))
29751 + si_write_unlock(sb);
29756 +/* dentry and super_block lock. call at entry point */
29757 +int aufs_read_lock(struct dentry *dentry, int flags)
29760 + struct super_block *sb;
29762 + sb = dentry->d_sb;
29763 + err = si_read_lock(sb, flags);
29764 + if (unlikely(err))
29767 + if (au_ftest_lock(flags, DW))
29768 + di_write_lock_child(dentry);
29770 + di_read_lock_child(dentry, flags);
29772 + if (au_ftest_lock(flags, GEN)) {
29773 + err = au_digen_test(dentry, au_sigen(sb));
29774 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29775 + AuDebugOn(!err && au_dbrange_test(dentry));
29777 + err = au_dbrange_test(dentry);
29778 + if (unlikely(err))
29779 + aufs_read_unlock(dentry, flags);
29786 +void aufs_read_unlock(struct dentry *dentry, int flags)
29788 + if (au_ftest_lock(flags, DW))
29789 + di_write_unlock(dentry);
29791 + di_read_unlock(dentry, flags);
29792 + si_read_unlock(dentry->d_sb);
29795 +void aufs_write_lock(struct dentry *dentry)
29797 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29798 + di_write_lock_child(dentry);
29801 +void aufs_write_unlock(struct dentry *dentry)
29803 + di_write_unlock(dentry);
29804 + si_write_unlock(dentry->d_sb);
29807 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29810 + unsigned int sigen;
29811 + struct super_block *sb;
29814 + err = si_read_lock(sb, flags);
29815 + if (unlikely(err))
29818 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29820 + if (au_ftest_lock(flags, GEN)) {
29821 + sigen = au_sigen(sb);
29822 + err = au_digen_test(d1, sigen);
29823 + AuDebugOn(!err && au_dbrange_test(d1));
29825 + err = au_digen_test(d2, sigen);
29826 + AuDebugOn(!err && au_dbrange_test(d2));
29828 + if (unlikely(err))
29829 + aufs_read_and_write_unlock2(d1, d2);
29836 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29838 + di_write_unlock2(d1, d2);
29839 + si_read_unlock(d1->d_sb);
29841 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29842 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29843 +++ linux/fs/aufs/super.c 2022-11-05 23:02:18.969222617 +0100
29845 +// SPDX-License-Identifier: GPL-2.0
29847 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29849 + * This program is free software; you can redistribute it and/or modify
29850 + * it under the terms of the GNU General Public License as published by
29851 + * the Free Software Foundation; either version 2 of the License, or
29852 + * (at your option) any later version.
29854 + * This program is distributed in the hope that it will be useful,
29855 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29856 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29857 + * GNU General Public License for more details.
29859 + * You should have received a copy of the GNU General Public License
29860 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29864 + * mount and super_block operations
29867 +#include <linux/iversion.h>
29868 +#include <linux/mm.h>
29869 +#include <linux/seq_file.h>
29870 +#include <linux/statfs.h>
29871 +#include <linux/vmalloc.h>
29875 + * super_operations
29877 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29879 + struct au_icntnr *c;
29881 + c = au_cache_alloc_icntnr(sb);
29883 + au_icntnr_init(c);
29884 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29885 + c->iinfo.ii_hinode = NULL;
29886 + return &c->vfs_inode;
29891 +static void aufs_destroy_inode(struct inode *inode)
29893 + if (!au_is_bad_inode(inode))
29894 + au_iinfo_fin(inode);
29897 +static void aufs_free_inode(struct inode *inode)
29899 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29902 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29904 + struct inode *inode;
29907 + inode = iget_locked(sb, ino);
29908 + if (unlikely(!inode)) {
29909 + inode = ERR_PTR(-ENOMEM);
29912 + if (!(inode->i_state & I_NEW))
29915 + err = au_xigen_new(inode);
29917 + err = au_iinfo_init(inode);
29919 + inode_inc_iversion(inode);
29921 + iget_failed(inode);
29922 + inode = ERR_PTR(err);
29926 + /* never return NULL */
29927 + AuDebugOn(!inode);
29928 + AuTraceErrPtr(inode);
29932 +/* lock free root dinfo */
29933 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29936 + aufs_bindex_t bindex, bbot;
29937 + struct path path;
29938 + struct au_hdentry *hdp;
29939 + struct au_branch *br;
29940 + au_br_perm_str_t perm;
29943 + bbot = au_sbbot(sb);
29945 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29946 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29947 + br = au_sbr(sb, bindex);
29948 + path.mnt = au_br_mnt(br);
29949 + path.dentry = hdp->hd_dentry;
29950 + err = au_seq_path(seq, &path);
29952 + au_optstr_br_perm(&perm, br->br_perm);
29953 + seq_printf(seq, "=%s", perm.a);
29954 + if (bindex != bbot)
29955 + seq_putc(seq, ':');
29958 + if (unlikely(err || seq_has_overflowed(seq)))
29964 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29965 + const char *append)
29970 + while (*pat != ':')
29973 + strcpy(p, append);
29974 + AuDebugOn(strlen(fmt) >= len);
29977 +static void au_show_wbr_create(struct seq_file *m, int v,
29978 + struct au_sbinfo *sbinfo)
29982 + struct au_wbr_mfs *mfs;
29984 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29986 + seq_puts(m, ",create=");
29987 + pat = au_optstr_wbr_create(v);
29988 + mfs = &sbinfo->si_wbr_mfs;
29990 + case AuWbrCreate_TDP:
29991 + case AuWbrCreate_RR:
29992 + case AuWbrCreate_MFS:
29993 + case AuWbrCreate_PMFS:
29994 + seq_puts(m, pat);
29996 + case AuWbrCreate_MFSRR:
29997 + case AuWbrCreate_TDMFS:
29998 + case AuWbrCreate_PMFSRR:
29999 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30000 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30002 + case AuWbrCreate_MFSV:
30003 + case AuWbrCreate_PMFSV:
30004 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30005 + seq_printf(m, fmt,
30006 + jiffies_to_msecs(mfs->mfs_expire)
30009 + case AuWbrCreate_MFSRRV:
30010 + case AuWbrCreate_TDMFSV:
30011 + case AuWbrCreate_PMFSRRV:
30012 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30013 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30014 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30021 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30023 +#ifdef CONFIG_SYSFS
30027 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30028 + aufs_bindex_t bindex, brid;
30029 + struct qstr *name;
30031 + struct dentry *d, *h_root;
30032 + struct au_branch *br;
30034 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30037 + f = au_sbi(sb)->si_xib;
30041 + /* stop printing the default xino path on the first writable branch */
30043 + bindex = au_xi_root(sb, f->f_path.dentry);
30044 + if (bindex >= 0) {
30045 + br = au_sbr_sb(sb, bindex);
30046 + h_root = au_br_dentry(br);
30049 + d = f->f_path.dentry;
30050 + name = &d->d_name;
30051 + /* safe ->d_parent because the file is unlinked */
30052 + if (d->d_parent == h_root
30053 + && name->len == len
30054 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30057 + seq_puts(seq, ",xino=");
30058 + err = au_xino_path(seq, f);
30065 +/* seq_file will re-call me in case of too long string */
30066 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30069 + unsigned int mnt_flags, v;
30070 + struct super_block *sb;
30071 + struct au_sbinfo *sbinfo;
30073 +#define AuBool(name, str) do { \
30074 + v = au_opt_test(mnt_flags, name); \
30075 + if (v != au_opt_test(AuOpt_Def, name)) \
30076 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30079 +#define AuStr(name, str) do { \
30080 + v = mnt_flags & AuOptMask_##name; \
30081 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30082 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30085 +#define AuUInt(name, str, val) do { \
30086 + if (val != AUFS_##name##_DEF) \
30087 + seq_printf(m, "," #str "=%u", val); \
30090 + sb = dentry->d_sb;
30091 + if (sb->s_flags & SB_POSIXACL)
30092 + seq_puts(m, ",acl");
30093 +#if 0 /* reserved for future use */
30094 + if (sb->s_flags & SB_I_VERSION)
30095 + seq_puts(m, ",i_version");
30098 + /* lock free root dinfo */
30099 + si_noflush_read_lock(sb);
30100 + sbinfo = au_sbi(sb);
30101 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30103 + mnt_flags = au_mntflags(sb);
30104 + if (au_opt_test(mnt_flags, XINO)) {
30105 + err = au_show_xino(m, sb);
30106 + if (unlikely(err))
30109 + seq_puts(m, ",noxino");
30111 + AuBool(TRUNC_XINO, trunc_xino);
30112 + AuStr(UDBA, udba);
30113 + AuBool(SHWH, shwh);
30114 + AuBool(PLINK, plink);
30115 + AuBool(DIO, dio);
30116 + AuBool(DIRPERM1, dirperm1);
30118 + v = sbinfo->si_wbr_create;
30119 + if (v != AuWbrCreate_Def)
30120 + au_show_wbr_create(m, v, sbinfo);
30122 + v = sbinfo->si_wbr_copyup;
30123 + if (v != AuWbrCopyup_Def)
30124 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30126 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30127 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30128 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30130 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30132 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30133 + AuUInt(RDCACHE, rdcache, v);
30135 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30136 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30138 + au_fhsm_show(m, sbinfo);
30140 + AuBool(DIRREN, dirren);
30141 + AuBool(SUM, sum);
30142 + /* AuBool(SUM_W, wsum); */
30143 + AuBool(WARN_PERM, warn_perm);
30144 + AuBool(VERBOSE, verbose);
30147 + /* be sure to print "br:" last */
30148 + if (!sysaufs_brs) {
30149 + seq_puts(m, ",br:");
30150 + au_show_brs(m, sb);
30152 + si_read_unlock(sb);
30160 +/* ---------------------------------------------------------------------- */
30162 +/* sum mode which returns the summation for statfs(2) */
30164 +static u64 au_add_till_max(u64 a, u64 b)
30172 + return ULLONG_MAX;
30175 +static u64 au_mul_till_max(u64 a, long mul)
30183 + return ULLONG_MAX;
30186 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30189 + long bsize, factor;
30190 + u64 blocks, bfree, bavail, files, ffree;
30191 + aufs_bindex_t bbot, bindex, i;
30192 + unsigned char shared;
30193 + struct path h_path;
30194 + struct super_block *h_sb;
30197 + bsize = LONG_MAX;
30203 + bbot = au_sbbot(sb);
30204 + for (bindex = 0; bindex <= bbot; bindex++) {
30205 + h_path.mnt = au_sbr_mnt(sb, bindex);
30206 + h_sb = h_path.mnt->mnt_sb;
30208 + for (i = 0; !shared && i < bindex; i++)
30209 + shared = (au_sbr_sb(sb, i) == h_sb);
30213 + /* sb->s_root for NFS is unreliable */
30214 + h_path.dentry = h_path.mnt->mnt_root;
30215 + err = vfs_statfs(&h_path, buf);
30216 + if (unlikely(err))
30219 + if (bsize > buf->f_bsize) {
30221 + * we will reduce bsize, so we have to expand blocks
30222 + * etc. to match them again
30224 + factor = (bsize / buf->f_bsize);
30225 + blocks = au_mul_till_max(blocks, factor);
30226 + bfree = au_mul_till_max(bfree, factor);
30227 + bavail = au_mul_till_max(bavail, factor);
30228 + bsize = buf->f_bsize;
30231 + factor = (buf->f_bsize / bsize);
30232 + blocks = au_add_till_max(blocks,
30233 + au_mul_till_max(buf->f_blocks, factor));
30234 + bfree = au_add_till_max(bfree,
30235 + au_mul_till_max(buf->f_bfree, factor));
30236 + bavail = au_add_till_max(bavail,
30237 + au_mul_till_max(buf->f_bavail, factor));
30238 + files = au_add_till_max(files, buf->f_files);
30239 + ffree = au_add_till_max(ffree, buf->f_ffree);
30242 + buf->f_bsize = bsize;
30243 + buf->f_blocks = blocks;
30244 + buf->f_bfree = bfree;
30245 + buf->f_bavail = bavail;
30246 + buf->f_files = files;
30247 + buf->f_ffree = ffree;
30248 + buf->f_frsize = 0;
30254 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30257 + struct path h_path;
30258 + struct super_block *sb;
30260 + /* lock free root dinfo */
30261 + sb = dentry->d_sb;
30262 + si_noflush_read_lock(sb);
30263 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30264 + /* sb->s_root for NFS is unreliable */
30265 + h_path.mnt = au_sbr_mnt(sb, 0);
30266 + h_path.dentry = h_path.mnt->mnt_root;
30267 + err = vfs_statfs(&h_path, buf);
30269 + err = au_statfs_sum(sb, buf);
30270 + si_read_unlock(sb);
30273 + buf->f_type = AUFS_SUPER_MAGIC;
30274 + buf->f_namelen = AUFS_MAX_NAMELEN;
30275 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30277 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30282 +/* ---------------------------------------------------------------------- */
30284 +static int aufs_sync_fs(struct super_block *sb, int wait)
30287 + aufs_bindex_t bbot, bindex;
30288 + struct au_branch *br;
30289 + struct super_block *h_sb;
30292 + si_noflush_read_lock(sb);
30293 + bbot = au_sbbot(sb);
30294 + for (bindex = 0; bindex <= bbot; bindex++) {
30295 + br = au_sbr(sb, bindex);
30296 + if (!au_br_writable(br->br_perm))
30299 + h_sb = au_sbr_sb(sb, bindex);
30300 + e = vfsub_sync_filesystem(h_sb);
30301 + if (unlikely(e && !err))
30303 + /* go on even if an error happens */
30305 + si_read_unlock(sb);
30310 +/* ---------------------------------------------------------------------- */
30312 +/* final actions when unmounting a file system */
30313 +static void aufs_put_super(struct super_block *sb)
30315 + struct au_sbinfo *sbinfo;
30317 + sbinfo = au_sbi(sb);
30319 + kobject_put(&sbinfo->si_kobj);
30322 +/* ---------------------------------------------------------------------- */
30324 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30325 + struct super_block *sb, void *arg)
30328 + unsigned long long n, sz;
30335 + if (*hint > ULLONG_MAX / sizeof(array)) {
30336 + array = ERR_PTR(-EMFILE);
30337 + pr_err("hint %llu\n", *hint);
30341 + sz = sizeof(array) * *hint;
30342 + array = kzalloc(sz, GFP_NOFS);
30343 + if (unlikely(!array))
30344 + array = vzalloc(sz);
30345 + if (unlikely(!array)) {
30346 + array = ERR_PTR(-ENOMEM);
30350 + n = cb(sb, array, *hint, arg);
30351 + AuDebugOn(n > *hint);
30358 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30359 + unsigned long long max __maybe_unused,
30362 + unsigned long long n;
30363 + struct inode **p, *inode;
30364 + struct list_head *head;
30369 + spin_lock(&sb->s_inode_list_lock);
30370 + list_for_each_entry(inode, head, i_sb_list) {
30371 + if (!au_is_bad_inode(inode)
30372 + && au_ii(inode)->ii_btop >= 0) {
30373 + spin_lock(&inode->i_lock);
30374 + if (atomic_read(&inode->i_count)) {
30378 + AuDebugOn(n > max);
30380 + spin_unlock(&inode->i_lock);
30383 + spin_unlock(&sb->s_inode_list_lock);
30388 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30390 + struct au_sbinfo *sbi;
30392 + sbi = au_sbi(sb);
30393 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30394 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30397 +void au_iarray_free(struct inode **a, unsigned long long max)
30399 + unsigned long long ull;
30401 + for (ull = 0; ull < max; ull++)
30406 +/* ---------------------------------------------------------------------- */
30409 + * refresh dentry and inode at remount time.
30411 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30412 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30413 + struct dentry *parent)
30417 + di_write_lock_child(dentry);
30418 + di_read_lock_parent(parent, AuLock_IR);
30419 + err = au_refresh_dentry(dentry, parent);
30420 + if (!err && dir_flags)
30421 + au_hn_reset(d_inode(dentry), dir_flags);
30422 + di_read_unlock(parent, AuLock_IR);
30423 + di_write_unlock(dentry);
30428 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30429 + struct au_sbinfo *sbinfo,
30430 + const unsigned int dir_flags, unsigned int do_idop)
30433 + struct dentry *parent;
30436 + parent = dget_parent(dentry);
30437 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30438 + if (d_really_is_positive(dentry)) {
30439 + if (!d_is_dir(dentry))
30440 + err = au_do_refresh(dentry, /*dir_flags*/0,
30443 + err = au_do_refresh(dentry, dir_flags, parent);
30444 + if (unlikely(err))
30445 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30448 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30449 + AuDbgDentry(dentry);
30455 + au_refresh_dop(dentry, /*force_reval*/0);
30457 + au_refresh_dop(dentry, /*force_reval*/1);
30463 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30465 + int err, i, j, ndentry, e;
30466 + unsigned int sigen;
30467 + struct au_dcsub_pages dpages;
30468 + struct au_dpage *dpage;
30469 + struct dentry **dentries, *d;
30470 + struct au_sbinfo *sbinfo;
30471 + struct dentry *root = sb->s_root;
30472 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30475 + au_refresh_dop(root, /*force_reval*/0);
30477 + err = au_dpages_init(&dpages, GFP_NOFS);
30478 + if (unlikely(err))
30480 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30481 + if (unlikely(err))
30484 + sigen = au_sigen(sb);
30485 + sbinfo = au_sbi(sb);
30486 + for (i = 0; i < dpages.ndpage; i++) {
30487 + dpage = dpages.dpages + i;
30488 + dentries = dpage->dentries;
30489 + ndentry = dpage->ndentry;
30490 + for (j = 0; j < ndentry; j++) {
30492 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30494 + if (unlikely(e && !err))
30496 + /* go on even err */
30501 + au_dpages_free(&dpages);
30506 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30509 + unsigned int sigen;
30510 + unsigned long long max, ull;
30511 + struct inode *inode, **array;
30513 + array = au_iarray_alloc(sb, &max);
30514 + err = PTR_ERR(array);
30515 + if (IS_ERR(array))
30519 + sigen = au_sigen(sb);
30520 + for (ull = 0; ull < max; ull++) {
30521 + inode = array[ull];
30522 + if (unlikely(!inode))
30526 + ii_write_lock_child(inode);
30527 + if (au_iigen(inode, NULL) != sigen) {
30528 + e = au_refresh_hinode_self(inode);
30529 + if (unlikely(e)) {
30530 + au_refresh_iop(inode, /*force_getattr*/1);
30531 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30534 + /* go on even if err */
30537 + if (!e && do_idop)
30538 + au_refresh_iop(inode, /*force_getattr*/0);
30539 + ii_write_unlock(inode);
30542 + au_iarray_free(array, max);
30548 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30551 + unsigned int udba;
30552 + aufs_bindex_t bindex, bbot;
30553 + struct dentry *root;
30554 + struct inode *inode;
30555 + struct au_branch *br;
30556 + struct au_sbinfo *sbi;
30558 + au_sigen_inc(sb);
30559 + sbi = au_sbi(sb);
30560 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30562 + root = sb->s_root;
30563 + DiMustNoWaiters(root);
30564 + inode = d_inode(root);
30565 + IiMustNoWaiters(inode);
30567 + udba = au_opt_udba(sb);
30568 + bbot = au_sbbot(sb);
30569 + for (bindex = 0; bindex <= bbot; bindex++) {
30570 + br = au_sbr(sb, bindex);
30571 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30572 + if (unlikely(err))
30573 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30575 + /* go on even if err */
30577 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30580 + if (au_ftest_si(sbi, NO_DREVAL)) {
30581 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30582 + sb->s_d_op = &aufs_dop_noreval;
30583 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30584 + sbi->si_iop_array = aufs_iop_nogetattr;
30586 + AuDebugOn(sb->s_d_op == &aufs_dop);
30587 + sb->s_d_op = &aufs_dop;
30588 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30589 + sbi->si_iop_array = aufs_iop;
30591 + pr_info("reset to %ps and %ps\n",
30592 + sb->s_d_op, sbi->si_iop_array);
30595 + di_write_unlock(root);
30596 + err = au_refresh_d(sb, do_idop);
30597 + e = au_refresh_i(sb, do_idop);
30598 + if (unlikely(e && !err))
30600 + /* aufs_write_lock() calls ..._child() */
30601 + di_write_lock_child(root);
30603 + au_cpup_attr_all(inode, /*force*/1);
30605 + if (unlikely(err))
30606 + AuIOErr("refresh failed, ignored, %d\n", err);
30609 +const struct super_operations aufs_sop = {
30610 + .alloc_inode = aufs_alloc_inode,
30611 + .destroy_inode = aufs_destroy_inode,
30612 + .free_inode = aufs_free_inode,
30613 + /* always deleting, no clearing */
30614 + .drop_inode = generic_delete_inode,
30615 + .show_options = aufs_show_options,
30616 + .statfs = aufs_statfs,
30617 + .put_super = aufs_put_super,
30618 + .sync_fs = aufs_sync_fs
30621 +/* ---------------------------------------------------------------------- */
30623 +int au_alloc_root(struct super_block *sb)
30626 + struct inode *inode;
30627 + struct dentry *root;
30630 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30631 + err = PTR_ERR(inode);
30632 + if (IS_ERR(inode))
30635 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30636 + inode->i_fop = &aufs_dir_fop;
30637 + inode->i_mode = S_IFDIR;
30638 + set_nlink(inode, 2);
30639 + unlock_new_inode(inode);
30641 + root = d_make_root(inode);
30642 + if (unlikely(!root))
30644 + err = PTR_ERR(root);
30645 + if (IS_ERR(root))
30648 + err = au_di_init(root);
30650 + sb->s_root = root;
30651 + return 0; /* success */
30659 +/* ---------------------------------------------------------------------- */
30661 +static void aufs_kill_sb(struct super_block *sb)
30663 + struct au_sbinfo *sbinfo;
30664 + struct dentry *root;
30666 + sbinfo = au_sbi(sb);
30670 + au_sbilist_del(sb);
30672 + root = sb->s_root;
30674 + aufs_write_lock(root);
30676 + __si_write_lock(sb);
30679 + if (sbinfo->si_wbr_create_ops->fin)
30680 + sbinfo->si_wbr_create_ops->fin(sb);
30681 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30682 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30683 + au_remount_refresh(sb, /*do_idop*/0);
30685 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30686 + au_plink_put(sb, /*verbose*/1);
30689 + au_dr_opt_flush(sb);
30692 + aufs_write_unlock(root);
30694 + __si_write_unlock(sb);
30696 + sbinfo->si_sb = NULL;
30697 + au_nwt_flush(&sbinfo->si_nowait);
30700 + kill_anon_super(sb);
30703 +struct file_system_type aufs_fs_type = {
30704 + .name = AUFS_FSTYPE,
30705 + /* a race between rename and others */
30706 + .fs_flags = FS_RENAME_DOES_D_MOVE
30708 + /*| FS_ALLOW_IDMAP*/
30710 + .init_fs_context = aufs_fsctx_init,
30711 + .parameters = aufs_fsctx_paramspec,
30712 + .kill_sb = aufs_kill_sb,
30713 + /* no need to __module_get() and module_put(). */
30714 + .owner = THIS_MODULE,
30716 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30717 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30718 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30720 +/* SPDX-License-Identifier: GPL-2.0 */
30722 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30724 + * This program is free software; you can redistribute it and/or modify
30725 + * it under the terms of the GNU General Public License as published by
30726 + * the Free Software Foundation; either version 2 of the License, or
30727 + * (at your option) any later version.
30729 + * This program is distributed in the hope that it will be useful,
30730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30732 + * GNU General Public License for more details.
30734 + * You should have received a copy of the GNU General Public License
30735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30739 + * super_block operations
30742 +#ifndef __AUFS_SUPER_H__
30743 +#define __AUFS_SUPER_H__
30747 +#include <linux/fs.h>
30748 +#include <linux/kobject.h>
30751 +#include "rwsem.h"
30754 +/* policies to select one among multiple writable branches */
30755 +struct au_wbr_copyup_operations {
30756 + int (*copyup)(struct dentry *dentry);
30759 +#define AuWbr_DIR 1 /* target is a dir */
30760 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30762 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30763 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30764 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30766 +struct au_wbr_create_operations {
30767 + int (*create)(struct dentry *dentry, unsigned int flags);
30768 + int (*init)(struct super_block *sb);
30769 + int (*fin)(struct super_block *sb);
30772 +struct au_wbr_mfs {
30773 + struct mutex mfs_lock; /* protect this structure */
30774 + unsigned long mfs_jiffy;
30775 + unsigned long mfs_expire;
30776 + aufs_bindex_t mfs_bindex;
30778 + unsigned long long mfsrr_bytes;
30779 + unsigned long long mfsrr_watermark;
30782 +#define AuPlink_NHASH 100
30783 +static inline int au_plink_hash(ino_t ino)
30785 + return ino % AuPlink_NHASH;
30788 +/* File-based Hierarchical Storage Management */
30790 +#ifdef CONFIG_AUFS_FHSM
30791 + /* allow only one process who can receive the notification */
30792 + spinlock_t fhsm_spin;
30794 + wait_queue_head_t fhsm_wqh;
30795 + atomic_t fhsm_readable;
30797 + /* these are protected by si_rwsem */
30798 + unsigned long fhsm_expire;
30799 + aufs_bindex_t fhsm_bottom;
30804 +struct au_sbinfo {
30805 + /* nowait tasks in the system-wide workqueue */
30806 + struct au_nowait_tasks si_nowait;
30809 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30810 + * rwsem for au_sbinfo is necessary.
30812 + struct au_rwsem si_rwsem;
30815 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30818 + au_lcnt_t si_ninodes, si_nfiles;
30820 + /* branch management */
30821 + unsigned int si_generation;
30823 + /* see AuSi_ flags */
30824 + unsigned char au_si_status;
30826 + aufs_bindex_t si_bbot;
30828 + /* dirty trick to keep br_id plus */
30829 + unsigned int si_last_br_id :
30830 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30831 + struct au_branch **si_branch;
30833 + /* policy to select a writable branch */
30834 + unsigned char si_wbr_copyup;
30835 + unsigned char si_wbr_create;
30836 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30837 + struct au_wbr_create_operations *si_wbr_create_ops;
30839 + /* round robin */
30840 + atomic_t si_wbr_rr_next;
30842 + /* most free space */
30843 + struct au_wbr_mfs si_wbr_mfs;
30845 + /* File-based Hierarchical Storage Management */
30846 + struct au_fhsm si_fhsm;
30848 + /* mount flags */
30849 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30850 + unsigned int si_mntflags;
30852 + /* external inode number (bitmap and translation table) */
30853 + loff_t si_ximaxent; /* max entries in a xino */
30855 + struct file *si_xib;
30856 + struct mutex si_xib_mtx; /* protect xib members */
30857 + unsigned long *si_xib_buf;
30858 + unsigned long si_xib_last_pindex;
30859 + int si_xib_next_bit;
30861 + unsigned long si_xino_jiffy;
30862 + unsigned long si_xino_expire;
30863 + /* reserved for future use */
30864 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30866 +#ifdef CONFIG_AUFS_EXPORT
30867 + /* i_generation */
30868 + /* todo: make xigen file an array to support many inode numbers */
30869 + struct file *si_xigen;
30870 + atomic_t si_xigen_next;
30873 + /* dirty trick to support atomic_open */
30874 + struct hlist_bl_head si_aopen;
30876 + /* vdir parameters */
30877 + unsigned long si_rdcache; /* max cache time in jiffies */
30878 + unsigned int si_rdblk; /* deblk size */
30879 + unsigned int si_rdhash; /* hash size */
30882 + * If the number of whiteouts are larger than si_dirwh, leave all of
30883 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30884 + * future fsck.aufs or kernel thread will remove them later.
30885 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30887 + unsigned int si_dirwh;
30889 + /* pseudo_link list */
30890 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30891 + wait_queue_head_t si_plink_wq;
30892 + spinlock_t si_plink_maint_lock;
30893 + pid_t si_plink_maint_pid;
30896 + struct hlist_bl_head si_files;
30898 + /* with/without getattr, brother of sb->s_d_op */
30899 + const struct inode_operations *si_iop_array;
30902 + * sysfs and lifetime management.
30903 + * this is not a small structure and it may be a waste of memory in case
30904 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30905 + * but using sysfs is majority.
30907 + struct kobject si_kobj;
30908 +#ifdef CONFIG_DEBUG_FS
30909 + struct dentry *si_dbgaufs;
30910 + struct dentry *si_dbgaufs_plink;
30911 + struct dentry *si_dbgaufs_xib;
30912 +#ifdef CONFIG_AUFS_EXPORT
30913 + struct dentry *si_dbgaufs_xigen;
30917 +#ifdef CONFIG_AUFS_SBILIST
30918 + struct hlist_bl_node si_list;
30921 + /* dirty, necessary for unmounting, sysfs and sysrq */
30922 + struct super_block *si_sb;
30925 +/* sbinfo status flags */
30927 + * set true when refresh_dirs() failed at remount time.
30928 + * then try refreshing dirs at access time again.
30929 + * if it is false, refreshing dirs at access time is unnecessary
30931 +#define AuSi_FAILED_REFRESH_DIR 1
30932 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30933 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30935 +#ifndef CONFIG_AUFS_FHSM
30937 +#define AuSi_FHSM 0
30940 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30941 + unsigned int flag)
30943 + AuRwMustAnyLock(&sbi->si_rwsem);
30944 + return sbi->au_si_status & flag;
30946 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30947 +#define au_fset_si(sbinfo, name) do { \
30948 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30949 + (sbinfo)->au_si_status |= AuSi_##name; \
30951 +#define au_fclr_si(sbinfo, name) do { \
30952 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30953 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30956 +/* ---------------------------------------------------------------------- */
30958 +/* policy to select one among writable branches */
30959 +#define AuWbrCopyup(sbinfo, ...) \
30960 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30961 +#define AuWbrCreate(sbinfo, ...) \
30962 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30964 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30965 +#define AuLock_DW 1 /* write-lock dentry */
30966 +#define AuLock_IR (1 << 1) /* read-lock inode */
30967 +#define AuLock_IW (1 << 2) /* write-lock inode */
30968 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30969 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30970 + /* except RENAME_EXCHANGE */
30971 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30972 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30973 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30974 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30975 +#define au_fset_lock(flags, name) \
30976 + do { (flags) |= AuLock_##name; } while (0)
30977 +#define au_fclr_lock(flags, name) \
30978 + do { (flags) &= ~AuLock_##name; } while (0)
30980 +/* ---------------------------------------------------------------------- */
30983 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30985 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30986 + unsigned long long max, void *arg);
30987 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30988 + struct super_block *sb, void *arg);
30989 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30990 +void au_iarray_free(struct inode **a, unsigned long long max);
30992 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30993 +extern const struct super_operations aufs_sop;
30994 +int au_alloc_root(struct super_block *sb);
30995 +extern struct file_system_type aufs_fs_type;
30998 +void au_si_free(struct kobject *kobj);
30999 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31000 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31002 +unsigned int au_sigen_inc(struct super_block *sb);
31003 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31005 +int si_read_lock(struct super_block *sb, int flags);
31006 +int si_write_lock(struct super_block *sb, int flags);
31007 +int aufs_read_lock(struct dentry *dentry, int flags);
31008 +void aufs_read_unlock(struct dentry *dentry, int flags);
31009 +void aufs_write_lock(struct dentry *dentry);
31010 +void aufs_write_unlock(struct dentry *dentry);
31011 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31012 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31014 +/* wbr_policy.c */
31015 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31016 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31017 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31018 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31019 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31022 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31024 +#ifdef CONFIG_AUFS_FHSM
31027 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31031 + spin_lock(&fhsm->fhsm_spin);
31032 + pid = fhsm->fhsm_pid;
31033 + spin_unlock(&fhsm->fhsm_spin);
31038 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31039 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31040 +int au_fhsm_fd(struct super_block *sb, int oflags);
31041 +int au_fhsm_br_alloc(struct au_branch *br);
31042 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31043 +void au_fhsm_fin(struct super_block *sb);
31044 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31045 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31046 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31048 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31050 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31051 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31052 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31053 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31054 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31055 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31056 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31057 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31058 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31061 +/* ---------------------------------------------------------------------- */
31063 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31065 + return sb->s_fs_info;
31068 +/* ---------------------------------------------------------------------- */
31070 +#ifdef CONFIG_AUFS_EXPORT
31071 +int au_test_nfsd(void);
31072 +void au_export_init(struct super_block *sb);
31073 +void au_xigen_inc(struct inode *inode);
31074 +int au_xigen_new(struct inode *inode);
31075 +int au_xigen_set(struct super_block *sb, struct path *path);
31076 +void au_xigen_clr(struct super_block *sb);
31078 +static inline int au_busy_or_stale(void)
31080 + if (!au_test_nfsd())
31085 +AuStubInt0(au_test_nfsd, void)
31086 +AuStubVoid(au_export_init, struct super_block *sb)
31087 +AuStubVoid(au_xigen_inc, struct inode *inode)
31088 +AuStubInt0(au_xigen_new, struct inode *inode)
31089 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31090 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31091 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31092 +#endif /* CONFIG_AUFS_EXPORT */
31094 +/* ---------------------------------------------------------------------- */
31096 +#ifdef CONFIG_AUFS_SBILIST
31098 +extern struct hlist_bl_head au_sbilist;
31100 +static inline void au_sbilist_init(void)
31102 + INIT_HLIST_BL_HEAD(&au_sbilist);
31105 +static inline void au_sbilist_add(struct super_block *sb)
31107 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31110 +static inline void au_sbilist_del(struct super_block *sb)
31112 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31115 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31116 +static inline void au_sbilist_lock(void)
31118 + hlist_bl_lock(&au_sbilist);
31121 +static inline void au_sbilist_unlock(void)
31123 + hlist_bl_unlock(&au_sbilist);
31125 +#define AuGFP_SBILIST GFP_ATOMIC
31127 +AuStubVoid(au_sbilist_lock, void)
31128 +AuStubVoid(au_sbilist_unlock, void)
31129 +#define AuGFP_SBILIST GFP_NOFS
31130 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31132 +AuStubVoid(au_sbilist_init, void)
31133 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31134 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31135 +AuStubVoid(au_sbilist_lock, void)
31136 +AuStubVoid(au_sbilist_unlock, void)
31137 +#define AuGFP_SBILIST GFP_NOFS
31140 +/* ---------------------------------------------------------------------- */
31142 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31145 + * This function is a dynamic '__init' function actually,
31146 + * so the tiny check for si_rwsem is unnecessary.
31148 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31149 +#ifdef CONFIG_DEBUG_FS
31150 + sbinfo->si_dbgaufs = NULL;
31151 + sbinfo->si_dbgaufs_plink = NULL;
31152 + sbinfo->si_dbgaufs_xib = NULL;
31153 +#ifdef CONFIG_AUFS_EXPORT
31154 + sbinfo->si_dbgaufs_xigen = NULL;
31159 +/* ---------------------------------------------------------------------- */
31161 +/* current->atomic_flags */
31162 +/* this value should never corrupt the ones defined in linux/sched.h */
31163 +#define PFA_AUFS 0x10
31165 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31166 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31167 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31169 +static inline int si_pid_test(struct super_block *sb)
31171 + return !!task_test_aufs(current);
31174 +static inline void si_pid_clr(struct super_block *sb)
31176 + AuDebugOn(!task_test_aufs(current));
31177 + task_clear_aufs(current);
31180 +static inline void si_pid_set(struct super_block *sb)
31182 + AuDebugOn(task_test_aufs(current));
31183 + task_set_aufs(current);
31186 +/* ---------------------------------------------------------------------- */
31188 +/* lock superblock. mainly for entry point functions */
31189 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31190 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31191 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31192 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31194 +#define __si_read_trylock_nested(sb) \
31195 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31196 +#define __si_write_trylock_nested(sb) \
31197 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31200 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31201 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31202 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31204 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31205 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31206 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31208 +static inline void si_noflush_read_lock(struct super_block *sb)
31210 + __si_read_lock(sb);
31214 +static inline int si_noflush_read_trylock(struct super_block *sb)
31218 + locked = __si_read_trylock(sb);
31224 +static inline void si_noflush_write_lock(struct super_block *sb)
31226 + __si_write_lock(sb);
31230 +static inline int si_noflush_write_trylock(struct super_block *sb)
31234 + locked = __si_write_trylock(sb);
31240 +#if 0 /* reserved */
31241 +static inline int si_read_trylock(struct super_block *sb, int flags)
31243 + if (au_ftest_lock(flags, FLUSH))
31244 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31245 + return si_noflush_read_trylock(sb);
31249 +static inline void si_read_unlock(struct super_block *sb)
31252 + __si_read_unlock(sb);
31255 +#if 0 /* reserved */
31256 +static inline int si_write_trylock(struct super_block *sb, int flags)
31258 + if (au_ftest_lock(flags, FLUSH))
31259 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31260 + return si_noflush_write_trylock(sb);
31264 +static inline void si_write_unlock(struct super_block *sb)
31267 + __si_write_unlock(sb);
31270 +#if 0 /* reserved */
31271 +static inline void si_downgrade_lock(struct super_block *sb)
31273 + __si_downgrade_lock(sb);
31277 +/* ---------------------------------------------------------------------- */
31279 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31281 + SiMustAnyLock(sb);
31282 + return au_sbi(sb)->si_bbot;
31285 +static inline unsigned int au_mntflags(struct super_block *sb)
31287 + SiMustAnyLock(sb);
31288 + return au_sbi(sb)->si_mntflags;
31291 +static inline unsigned int au_sigen(struct super_block *sb)
31293 + SiMustAnyLock(sb);
31294 + return au_sbi(sb)->si_generation;
31297 +static inline struct au_branch *au_sbr(struct super_block *sb,
31298 + aufs_bindex_t bindex)
31300 + SiMustAnyLock(sb);
31301 + return au_sbi(sb)->si_branch[0 + bindex];
31304 +static inline loff_t au_xi_maxent(struct super_block *sb)
31306 + SiMustAnyLock(sb);
31307 + return au_sbi(sb)->si_ximaxent;
31310 +#endif /* __KERNEL__ */
31311 +#endif /* __AUFS_SUPER_H__ */
31312 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31313 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31314 +++ linux/fs/aufs/sysaufs.c 2022-11-05 23:02:18.969222617 +0100
31316 +// SPDX-License-Identifier: GPL-2.0
31318 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31320 + * This program is free software; you can redistribute it and/or modify
31321 + * it under the terms of the GNU General Public License as published by
31322 + * the Free Software Foundation; either version 2 of the License, or
31323 + * (at your option) any later version.
31325 + * This program is distributed in the hope that it will be useful,
31326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31328 + * GNU General Public License for more details.
31330 + * You should have received a copy of the GNU General Public License
31331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31335 + * sysfs interface and lifetime management
31336 + * they are necessary regardless sysfs is disabled.
31339 +#include <linux/random.h>
31342 +unsigned long sysaufs_si_mask;
31343 +struct kset *sysaufs_kset;
31345 +#define AuSiAttr(_name) { \
31346 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31347 + .show = sysaufs_si_##_name, \
31350 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31351 +struct attribute *sysaufs_si_attrs[] = {
31352 + &sysaufs_si_attr_xi_path.attr,
31355 +ATTRIBUTE_GROUPS(sysaufs_si);
31357 +static const struct sysfs_ops au_sbi_ops = {
31358 + .show = sysaufs_si_show
31361 +static struct kobj_type au_sbi_ktype = {
31362 + .release = au_si_free,
31363 + .sysfs_ops = &au_sbi_ops,
31364 + .default_groups = sysaufs_si_groups
31367 +/* ---------------------------------------------------------------------- */
31369 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31373 + sbinfo->si_kobj.kset = sysaufs_kset;
31374 + /* cf. sysaufs_name() */
31375 + err = kobject_init_and_add
31376 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31377 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31382 +void sysaufs_fin(void)
31384 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31385 + kset_unregister(sysaufs_kset);
31388 +int __init sysaufs_init(void)
31393 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31394 + } while (!sysaufs_si_mask);
31397 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31398 + if (unlikely(!sysaufs_kset))
31400 + err = PTR_ERR(sysaufs_kset);
31401 + if (IS_ERR(sysaufs_kset))
31403 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31404 + if (unlikely(err))
31405 + kset_unregister(sysaufs_kset);
31410 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31411 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31412 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31414 +/* SPDX-License-Identifier: GPL-2.0 */
31416 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31418 + * This program is free software; you can redistribute it and/or modify
31419 + * it under the terms of the GNU General Public License as published by
31420 + * the Free Software Foundation; either version 2 of the License, or
31421 + * (at your option) any later version.
31423 + * This program is distributed in the hope that it will be useful,
31424 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31425 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31426 + * GNU General Public License for more details.
31428 + * You should have received a copy of the GNU General Public License
31429 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31433 + * sysfs interface and mount lifetime management
31436 +#ifndef __SYSAUFS_H__
31437 +#define __SYSAUFS_H__
31441 +#include <linux/sysfs.h>
31442 +#include "module.h"
31444 +struct super_block;
31447 +struct sysaufs_si_attr {
31448 + struct attribute attr;
31449 + int (*show)(struct seq_file *seq, struct super_block *sb);
31452 +/* ---------------------------------------------------------------------- */
31455 +extern unsigned long sysaufs_si_mask;
31456 +extern struct kset *sysaufs_kset;
31457 +extern struct attribute *sysaufs_si_attrs[];
31458 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31459 +int __init sysaufs_init(void);
31460 +void sysaufs_fin(void);
31462 +/* ---------------------------------------------------------------------- */
31464 +/* some people doesn't like to show a pointer in kernel */
31465 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31467 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31470 +#define SysaufsSiNamePrefix "si_"
31471 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31472 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31474 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31475 + sysaufs_si_id(sbinfo));
31479 +#ifdef CONFIG_SYSFS
31481 +extern struct attribute_group *sysaufs_attr_group;
31483 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31484 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31486 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31487 +#ifdef CONFIG_COMPAT
31488 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31491 +void sysaufs_br_init(struct au_branch *br);
31492 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31493 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31495 +#define sysaufs_brs_init() do {} while (0)
31498 +#define sysaufs_attr_group NULL
31500 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31501 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31502 + struct attribute *attr, char *buf)
31503 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31504 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31505 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31507 +static inline void sysaufs_brs_init(void)
31512 +#endif /* CONFIG_SYSFS */
31514 +#endif /* __KERNEL__ */
31515 +#endif /* __SYSAUFS_H__ */
31516 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31517 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31518 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31520 +// SPDX-License-Identifier: GPL-2.0
31522 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31524 + * This program is free software; you can redistribute it and/or modify
31525 + * it under the terms of the GNU General Public License as published by
31526 + * the Free Software Foundation; either version 2 of the License, or
31527 + * (at your option) any later version.
31529 + * This program is distributed in the hope that it will be useful,
31530 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31531 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31532 + * GNU General Public License for more details.
31534 + * You should have received a copy of the GNU General Public License
31535 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31539 + * sysfs interface
31542 +#include <linux/compat.h>
31543 +#include <linux/seq_file.h>
31546 +#ifdef CONFIG_AUFS_FS_MODULE
31547 +/* this entry violates the "one line per file" policy of sysfs */
31548 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31552 + static char *conf =
31553 +/* this file is generated at compiling */
31554 +#include "conf.str"
31557 + err = snprintf(buf, PAGE_SIZE, conf);
31558 + if (unlikely(err >= PAGE_SIZE))
31563 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31566 +static struct attribute *au_attr[] = {
31567 +#ifdef CONFIG_AUFS_FS_MODULE
31568 + &au_config_attr.attr,
31570 + NULL, /* need to NULL terminate the list of attributes */
31573 +static struct attribute_group sysaufs_attr_group_body = {
31577 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31579 +/* ---------------------------------------------------------------------- */
31581 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31585 + SiMustAnyLock(sb);
31588 + if (au_opt_test(au_mntflags(sb), XINO)) {
31589 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31590 + seq_putc(seq, '\n');
31596 + * the lifetime of branch is independent from the entry under sysfs.
31597 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31600 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31601 + aufs_bindex_t bindex, int idx)
31604 + struct path path;
31605 + struct dentry *root;
31606 + struct au_branch *br;
31607 + au_br_perm_str_t perm;
31609 + AuDbg("b%d\n", bindex);
31612 + root = sb->s_root;
31613 + di_read_lock_parent(root, !AuLock_IR);
31614 + br = au_sbr(sb, bindex);
31617 + case AuBrSysfs_BR:
31618 + path.mnt = au_br_mnt(br);
31619 + path.dentry = au_h_dptr(root, bindex);
31620 + err = au_seq_path(seq, &path);
31622 + au_optstr_br_perm(&perm, br->br_perm);
31623 + seq_printf(seq, "=%s\n", perm.a);
31626 + case AuBrSysfs_BRID:
31627 + seq_printf(seq, "%d\n", br->br_id);
31630 + di_read_unlock(root, !AuLock_IR);
31631 + if (unlikely(err || seq_has_overflowed(seq)))
31637 +/* ---------------------------------------------------------------------- */
31639 +static struct seq_file *au_seq(char *p, ssize_t len)
31641 + struct seq_file *seq;
31643 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31645 + /* mutex_init(&seq.lock); */
31648 + return seq; /* success */
31651 + seq = ERR_PTR(-ENOMEM);
31655 +#define SysaufsBr_PREFIX "br"
31656 +#define SysaufsBrid_PREFIX "brid"
31658 +/* todo: file size may exceed PAGE_SIZE */
31659 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31665 + aufs_bindex_t bbot;
31666 + struct au_sbinfo *sbinfo;
31667 + struct super_block *sb;
31668 + struct seq_file *seq;
31670 + struct attribute **cattr;
31672 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31673 + sb = sbinfo->si_sb;
31676 + * prevent a race condition between sysfs and aufs.
31677 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31678 + * prohibits maintaining the sysfs entries.
31679 + * hew we acquire read lock after sysfs_get_active_two().
31680 + * on the other hand, the remount process may maintain the sysfs/aufs
31681 + * entries after acquiring write lock.
31682 + * it can cause a deadlock.
31683 + * simply we gave up processing read here.
31686 + if (unlikely(!si_noflush_read_trylock(sb)))
31689 + seq = au_seq(buf, PAGE_SIZE);
31690 + err = PTR_ERR(seq);
31694 + name = (void *)attr->name;
31695 + cattr = sysaufs_si_attrs;
31697 + if (!strcmp(name, (*cattr)->name)) {
31698 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31705 + if (!strncmp(name, SysaufsBrid_PREFIX,
31706 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31707 + idx = AuBrSysfs_BRID;
31708 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31709 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31710 + sizeof(SysaufsBr_PREFIX) - 1)) {
31711 + idx = AuBrSysfs_BR;
31712 + name += sizeof(SysaufsBr_PREFIX) - 1;
31716 + err = kstrtol(name, 10, &l);
31718 + bbot = au_sbbot(sb);
31720 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31727 + err = seq->count;
31728 + /* sysfs limit */
31729 + if (unlikely(err == PAGE_SIZE))
31732 + au_kfree_rcu(seq);
31734 + si_read_unlock(sb);
31739 +/* ---------------------------------------------------------------------- */
31741 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31745 + aufs_bindex_t bindex, bbot;
31748 + struct seq_file *seq;
31749 + struct au_branch *br;
31751 + si_read_lock(sb, AuLock_FLUSH);
31752 + bbot = au_sbbot(sb);
31758 + buf = (void *)__get_free_page(GFP_NOFS);
31759 + if (unlikely(!buf))
31762 + seq = au_seq(buf, PAGE_SIZE);
31763 + err = PTR_ERR(seq);
31767 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31768 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31769 + /* VERIFY_WRITE */
31770 + err = !access_ok(arg, sizeof(*arg));
31771 + if (unlikely(err))
31774 + br = au_sbr(sb, bindex);
31775 + brid = br->br_id;
31776 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31777 + err = __put_user(brid, &arg->id);
31778 + if (unlikely(err))
31781 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31782 + err = __put_user(br->br_perm, &arg->perm);
31783 + if (unlikely(err))
31786 + err = au_seq_path(seq, &br->br_path);
31787 + if (unlikely(err))
31789 + seq_putc(seq, '\0');
31790 + if (!seq_has_overflowed(seq)) {
31791 + err = copy_to_user(arg->path, seq->buf, seq->count);
31793 + if (unlikely(err))
31800 + if (unlikely(err))
31804 + au_kfree_rcu(seq);
31806 + free_page((unsigned long)buf);
31808 + si_read_unlock(sb);
31812 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31814 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31817 +#ifdef CONFIG_COMPAT
31818 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31820 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31824 +/* ---------------------------------------------------------------------- */
31826 +void sysaufs_br_init(struct au_branch *br)
31829 + struct au_brsysfs *br_sysfs;
31830 + struct attribute *attr;
31832 + br_sysfs = br->br_sysfs;
31833 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31834 + attr = &br_sysfs->attr;
31835 + sysfs_attr_init(attr);
31836 + attr->name = br_sysfs->name;
31837 + attr->mode = 0444;
31842 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31844 + struct au_branch *br;
31845 + struct kobject *kobj;
31846 + struct au_brsysfs *br_sysfs;
31848 + aufs_bindex_t bbot;
31850 + if (!sysaufs_brs)
31853 + kobj = &au_sbi(sb)->si_kobj;
31854 + bbot = au_sbbot(sb);
31855 + for (; bindex <= bbot; bindex++) {
31856 + br = au_sbr(sb, bindex);
31857 + br_sysfs = br->br_sysfs;
31858 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31859 + sysfs_remove_file(kobj, &br_sysfs->attr);
31865 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31868 + aufs_bindex_t bbot;
31869 + struct kobject *kobj;
31870 + struct au_branch *br;
31871 + struct au_brsysfs *br_sysfs;
31873 + if (!sysaufs_brs)
31876 + kobj = &au_sbi(sb)->si_kobj;
31877 + bbot = au_sbbot(sb);
31878 + for (; bindex <= bbot; bindex++) {
31879 + br = au_sbr(sb, bindex);
31880 + br_sysfs = br->br_sysfs;
31881 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31882 + SysaufsBr_PREFIX "%d", bindex);
31883 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31884 + SysaufsBrid_PREFIX "%d", bindex);
31885 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31886 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31887 + if (unlikely(err))
31888 + pr_warn("failed %s under sysfs(%d)\n",
31889 + br_sysfs->name, err);
31894 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31895 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31896 +++ linux/fs/aufs/sysrq.c 2022-11-05 23:02:18.969222617 +0100
31898 +// SPDX-License-Identifier: GPL-2.0
31900 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31902 + * This program is free software; you can redistribute it and/or modify
31903 + * it under the terms of the GNU General Public License as published by
31904 + * the Free Software Foundation; either version 2 of the License, or
31905 + * (at your option) any later version.
31907 + * This program is distributed in the hope that it will be useful,
31908 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31909 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31910 + * GNU General Public License for more details.
31912 + * You should have received a copy of the GNU General Public License
31913 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31917 + * magic sysrq handler
31920 +/* #include <linux/sysrq.h> */
31921 +#include <linux/writeback.h>
31924 +/* ---------------------------------------------------------------------- */
31926 +static void sysrq_sb(struct super_block *sb)
31929 + struct au_sbinfo *sbinfo;
31930 + struct file *file;
31931 + struct hlist_bl_head *files;
31932 + struct hlist_bl_node *pos;
31933 + struct au_finfo *finfo;
31936 + plevel = au_plevel;
31937 + au_plevel = KERN_WARNING;
31939 + /* since we define pr_fmt, call printk directly */
31940 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31942 + sbinfo = au_sbi(sb);
31943 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31944 + pr("superblock\n");
31947 +#if 0 /* reserved */
31949 + int err, i, j, ndentry;
31950 + struct au_dcsub_pages dpages;
31951 + struct au_dpage *dpage;
31953 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31954 + if (unlikely(err))
31956 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31958 + for (i = 0; i < dpages.ndpage; i++) {
31959 + dpage = dpages.dpages + i;
31960 + ndentry = dpage->ndentry;
31961 + for (j = 0; j < ndentry; j++)
31962 + au_dpri_dentry(dpage->dentries[j]);
31964 + au_dpages_free(&dpages);
31968 + pr("isolated inode\n");
31969 + spin_lock(&sb->s_inode_list_lock);
31970 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31971 + spin_lock(&i->i_lock);
31972 + if (hlist_empty(&i->i_dentry))
31973 + au_dpri_inode(i);
31974 + spin_unlock(&i->i_lock);
31976 + spin_unlock(&sb->s_inode_list_lock);
31979 + files = &au_sbi(sb)->si_files;
31980 + hlist_bl_lock(files);
31981 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31984 + file = finfo->fi_file;
31985 + mode = file_inode(file)->i_mode;
31986 + if (!special_file(mode))
31987 + au_dpri_file(file);
31989 + hlist_bl_unlock(files);
31993 + au_plevel = plevel;
31996 +/* ---------------------------------------------------------------------- */
31998 +/* module parameter */
31999 +static char *aufs_sysrq_key = "a";
32000 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32001 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32003 +static void au_sysrq(int key __maybe_unused)
32005 + struct au_sbinfo *sbinfo;
32006 + struct hlist_bl_node *pos;
32009 + au_sbilist_lock();
32010 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32011 + sysrq_sb(sbinfo->si_sb);
32012 + au_sbilist_unlock();
32016 +static struct sysrq_key_op au_sysrq_op = {
32017 + .handler = au_sysrq,
32018 + .help_msg = "Aufs",
32019 + .action_msg = "Aufs",
32020 + .enable_mask = SYSRQ_ENABLE_DUMP
32023 +/* ---------------------------------------------------------------------- */
32025 +int __init au_sysrq_init(void)
32031 + key = *aufs_sysrq_key;
32032 + if ('a' <= key && key <= 'z')
32033 + err = register_sysrq_key(key, &au_sysrq_op);
32034 + if (unlikely(err))
32035 + pr_err("err %d, sysrq=%c\n", err, key);
32039 +void au_sysrq_fin(void)
32043 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32044 + if (unlikely(err))
32045 + pr_err("err %d (ignored)\n", err);
32047 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32048 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32049 +++ linux/fs/aufs/vdir.c 2022-12-17 09:21:34.799855195 +0100
32051 +// SPDX-License-Identifier: GPL-2.0
32053 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32055 + * This program is free software; you can redistribute it and/or modify
32056 + * it under the terms of the GNU General Public License as published by
32057 + * the Free Software Foundation; either version 2 of the License, or
32058 + * (at your option) any later version.
32060 + * This program is distributed in the hope that it will be useful,
32061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32063 + * GNU General Public License for more details.
32065 + * You should have received a copy of the GNU General Public License
32066 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32070 + * virtual or vertical directory
32073 +#include <linux/iversion.h>
32076 +static unsigned int calc_size(int nlen)
32078 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32081 +static int set_deblk_end(union au_vdir_deblk_p *p,
32082 + union au_vdir_deblk_p *deblk_end)
32084 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32085 + p->de->de_str.len = 0;
32089 + return -1; /* error */
32092 +/* returns true or false */
32093 +static int is_deblk_end(union au_vdir_deblk_p *p,
32094 + union au_vdir_deblk_p *deblk_end)
32096 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32097 + return !p->de->de_str.len;
32101 +static unsigned char *last_deblk(struct au_vdir *vdir)
32103 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32106 +/* ---------------------------------------------------------------------- */
32108 +/* estimate the appropriate size for name hash table */
32109 +unsigned int au_rdhash_est(loff_t sz)
32117 + if (sz < AUFS_RDHASH_DEF)
32118 + n = AUFS_RDHASH_DEF;
32119 + /* pr_info("n %u\n", n); */
32124 + * the allocated memory has to be freed by
32125 + * au_nhash_wh_free() or au_nhash_de_free().
32127 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32129 + struct hlist_head *head;
32133 + sz = sizeof(*nhash->nh_head) * num_hash;
32134 + head = kmalloc(sz, gfp);
32136 + nhash->nh_num = num_hash;
32137 + nhash->nh_head = head;
32138 + for (u = 0; u < num_hash; u++)
32139 + INIT_HLIST_HEAD(head++);
32140 + return 0; /* success */
32146 +static void nhash_count(struct hlist_head *head)
32148 +#if 0 /* debugging */
32150 + struct hlist_node *pos;
32153 + hlist_for_each(pos, head)
32155 + pr_info("%lu\n", n);
32159 +static void au_nhash_wh_do_free(struct hlist_head *head)
32161 + struct au_vdir_wh *pos;
32162 + struct hlist_node *node;
32164 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32165 + au_kfree_rcu(pos);
32168 +static void au_nhash_de_do_free(struct hlist_head *head)
32170 + struct au_vdir_dehstr *pos;
32171 + struct hlist_node *node;
32173 + hlist_for_each_entry_safe(pos, node, head, hash)
32174 + au_cache_free_vdir_dehstr(pos);
32177 +static void au_nhash_do_free(struct au_nhash *nhash,
32178 + void (*free)(struct hlist_head *head))
32181 + struct hlist_head *head;
32183 + n = nhash->nh_num;
32187 + head = nhash->nh_head;
32188 + while (n-- > 0) {
32189 + nhash_count(head);
32192 + au_kfree_try_rcu(nhash->nh_head);
32195 +void au_nhash_wh_free(struct au_nhash *whlist)
32197 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32200 +static void au_nhash_de_free(struct au_nhash *delist)
32202 + au_nhash_do_free(delist, au_nhash_de_do_free);
32205 +/* ---------------------------------------------------------------------- */
32207 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32211 + unsigned int u, n;
32212 + struct hlist_head *head;
32213 + struct au_vdir_wh *pos;
32216 + n = whlist->nh_num;
32217 + head = whlist->nh_head;
32218 + for (u = 0; u < n; u++, head++)
32219 + hlist_for_each_entry(pos, head, wh_hash)
32220 + if (pos->wh_bindex == btgt && ++num > limit)
32225 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32226 + unsigned char *name,
32227 + unsigned int len)
32230 + /* const unsigned int magic_bit = 12; */
32232 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32239 + /* v = hash_long(v, magic_bit); */
32240 + v %= nhash->nh_num;
32241 + return nhash->nh_head + v;
32244 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32247 + return str->len == nlen && !memcmp(str->name, name, nlen);
32250 +/* returns found or not */
32251 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32253 + struct hlist_head *head;
32254 + struct au_vdir_wh *pos;
32255 + struct au_vdir_destr *str;
32257 + head = au_name_hash(whlist, name, nlen);
32258 + hlist_for_each_entry(pos, head, wh_hash) {
32259 + str = &pos->wh_str;
32260 + AuDbg("%.*s\n", str->len, str->name);
32261 + if (au_nhash_test_name(str, name, nlen))
32267 +/* returns found(true) or not */
32268 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32270 + struct hlist_head *head;
32271 + struct au_vdir_dehstr *pos;
32272 + struct au_vdir_destr *str;
32274 + head = au_name_hash(delist, name, nlen);
32275 + hlist_for_each_entry(pos, head, hash) {
32277 + AuDbg("%.*s\n", str->len, str->name);
32278 + if (au_nhash_test_name(str, name, nlen))
32284 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32285 + unsigned char d_type)
32287 +#ifdef CONFIG_AUFS_SHWH
32288 + wh->wh_ino = ino;
32289 + wh->wh_type = d_type;
32293 +/* ---------------------------------------------------------------------- */
32295 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32296 + unsigned int d_type, aufs_bindex_t bindex,
32297 + unsigned char shwh)
32300 + struct au_vdir_destr *str;
32301 + struct au_vdir_wh *wh;
32303 + AuDbg("%.*s\n", nlen, name);
32304 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32307 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32308 + if (unlikely(!wh))
32312 + wh->wh_bindex = bindex;
32314 + au_shwh_init_wh(wh, ino, d_type);
32315 + str = &wh->wh_str;
32317 + memcpy(str->name, name, nlen);
32318 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32325 +static int append_deblk(struct au_vdir *vdir)
32328 + unsigned long ul;
32329 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32330 + union au_vdir_deblk_p p, deblk_end;
32331 + unsigned char **o;
32334 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32335 + GFP_NOFS, /*may_shrink*/0);
32336 + if (unlikely(!o))
32339 + vdir->vd_deblk = o;
32340 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32342 + ul = vdir->vd_nblk++;
32343 + vdir->vd_deblk[ul] = p.deblk;
32344 + vdir->vd_last.ul = ul;
32345 + vdir->vd_last.p.deblk = p.deblk;
32346 + deblk_end.deblk = p.deblk + deblk_sz;
32347 + err = set_deblk_end(&p, &deblk_end);
32354 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32355 + unsigned int d_type, struct au_nhash *delist)
32359 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32360 + union au_vdir_deblk_p p, *room, deblk_end;
32361 + struct au_vdir_dehstr *dehstr;
32363 + p.deblk = last_deblk(vdir);
32364 + deblk_end.deblk = p.deblk + deblk_sz;
32365 + room = &vdir->vd_last.p;
32366 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32367 + || !is_deblk_end(room, &deblk_end));
32369 + sz = calc_size(nlen);
32370 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32371 + err = append_deblk(vdir);
32372 + if (unlikely(err))
32375 + p.deblk = last_deblk(vdir);
32376 + deblk_end.deblk = p.deblk + deblk_sz;
32378 + AuDebugOn(room->deblk != p.deblk);
32382 + dehstr = au_cache_alloc_vdir_dehstr();
32383 + if (unlikely(!dehstr))
32386 + dehstr->str = &room->de->de_str;
32387 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32388 + room->de->de_ino = ino;
32389 + room->de->de_type = d_type;
32390 + room->de->de_str.len = nlen;
32391 + memcpy(room->de->de_str.name, name, nlen);
32394 + room->deblk += sz;
32395 + if (unlikely(set_deblk_end(room, &deblk_end)))
32396 + err = append_deblk(vdir);
32403 +/* ---------------------------------------------------------------------- */
32405 +void au_vdir_free(struct au_vdir *vdir)
32407 + unsigned char **deblk;
32409 + deblk = vdir->vd_deblk;
32410 + while (vdir->vd_nblk--)
32411 + au_kfree_try_rcu(*deblk++);
32412 + au_kfree_try_rcu(vdir->vd_deblk);
32413 + au_cache_free_vdir(vdir);
32416 +static struct au_vdir *alloc_vdir(struct file *file)
32418 + struct au_vdir *vdir;
32419 + struct super_block *sb;
32422 + sb = file->f_path.dentry->d_sb;
32423 + SiMustAnyLock(sb);
32426 + vdir = au_cache_alloc_vdir();
32427 + if (unlikely(!vdir))
32430 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32431 + if (unlikely(!vdir->vd_deblk))
32434 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32435 + if (!vdir->vd_deblk_sz) {
32436 + /* estimate the appropriate size for deblk */
32437 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32438 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32440 + vdir->vd_nblk = 0;
32441 + vdir->vd_version = 0;
32442 + vdir->vd_jiffy = 0;
32443 + err = append_deblk(vdir);
32445 + return vdir; /* success */
32447 + au_kfree_try_rcu(vdir->vd_deblk);
32450 + au_cache_free_vdir(vdir);
32452 + vdir = ERR_PTR(err);
32456 +static int reinit_vdir(struct au_vdir *vdir)
32459 + union au_vdir_deblk_p p, deblk_end;
32461 + while (vdir->vd_nblk > 1) {
32462 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32463 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32466 + p.deblk = vdir->vd_deblk[0];
32467 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32468 + err = set_deblk_end(&p, &deblk_end);
32469 + /* keep vd_dblk_sz */
32470 + vdir->vd_last.ul = 0;
32471 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32472 + vdir->vd_version = 0;
32473 + vdir->vd_jiffy = 0;
32478 +/* ---------------------------------------------------------------------- */
32480 +#define AuFillVdir_CALLED 1
32481 +#define AuFillVdir_WHABLE (1 << 1)
32482 +#define AuFillVdir_SHWH (1 << 2)
32483 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32484 +#define au_fset_fillvdir(flags, name) \
32485 + do { (flags) |= AuFillVdir_##name; } while (0)
32486 +#define au_fclr_fillvdir(flags, name) \
32487 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32489 +#ifndef CONFIG_AUFS_SHWH
32490 +#undef AuFillVdir_SHWH
32491 +#define AuFillVdir_SHWH 0
32494 +struct fillvdir_arg {
32495 + struct dir_context ctx;
32496 + struct file *file;
32497 + struct au_vdir *vdir;
32498 + struct au_nhash delist;
32499 + struct au_nhash whlist;
32500 + aufs_bindex_t bindex;
32501 + unsigned int flags;
32505 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32506 + loff_t offset __maybe_unused, u64 h_ino,
32507 + unsigned int d_type)
32509 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32510 + char *name = (void *)__name;
32511 + struct super_block *sb;
32513 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32516 + sb = arg->file->f_path.dentry->d_sb;
32517 + au_fset_fillvdir(arg->flags, CALLED);
32519 + if (nlen <= AUFS_WH_PFX_LEN
32520 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32521 + if (test_known(&arg->delist, name, nlen)
32522 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32523 + goto out; /* already exists or whiteouted */
32525 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32527 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32528 + d_type = DT_UNKNOWN;
32529 + arg->err = append_de(arg->vdir, name, nlen, ino,
32530 + d_type, &arg->delist);
32532 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32533 + name += AUFS_WH_PFX_LEN;
32534 + nlen -= AUFS_WH_PFX_LEN;
32535 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32536 + goto out; /* already whiteouted */
32538 + ino = 0; /* just to suppress a warning */
32540 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32543 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32544 + d_type = DT_UNKNOWN;
32545 + arg->err = au_nhash_append_wh
32546 + (&arg->whlist, name, nlen, ino, d_type,
32547 + arg->bindex, shwh);
32553 + arg->vdir->vd_jiffy = jiffies;
32555 + AuTraceErr(arg->err);
32556 + return !arg->err;
32559 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32560 + struct au_nhash *whlist, struct au_nhash *delist)
32562 +#ifdef CONFIG_AUFS_SHWH
32564 + unsigned int nh, u;
32565 + struct hlist_head *head;
32566 + struct au_vdir_wh *pos;
32567 + struct hlist_node *n;
32569 + struct au_vdir_destr *destr;
32571 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32574 + o = p = (void *)__get_free_page(GFP_NOFS);
32575 + if (unlikely(!p))
32579 + nh = whlist->nh_num;
32580 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32581 + p += AUFS_WH_PFX_LEN;
32582 + for (u = 0; u < nh; u++) {
32583 + head = whlist->nh_head + u;
32584 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32585 + destr = &pos->wh_str;
32586 + memcpy(p, destr->name, destr->len);
32587 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32588 + pos->wh_ino, pos->wh_type, delist);
32589 + if (unlikely(err))
32594 + free_page((unsigned long)o);
32604 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32607 + unsigned int rdhash;
32609 + aufs_bindex_t bbot, bindex, btop;
32610 + unsigned char shwh;
32611 + struct file *hf, *file;
32612 + struct super_block *sb;
32614 + file = arg->file;
32615 + sb = file->f_path.dentry->d_sb;
32616 + SiMustAnyLock(sb);
32618 + rdhash = au_sbi(sb)->si_rdhash;
32620 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32621 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32622 + if (unlikely(err))
32624 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32625 + if (unlikely(err))
32631 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32633 + au_fset_fillvdir(arg->flags, SHWH);
32635 + btop = au_fbtop(file);
32636 + bbot = au_fbbot_dir(file);
32637 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32638 + hf = au_hf_dir(file, bindex);
32642 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32644 + if (unlikely(offset))
32647 + arg->bindex = bindex;
32648 + au_fclr_fillvdir(arg->flags, WHABLE);
32650 + || (bindex != bbot
32651 + && au_br_whable(au_sbr_perm(sb, bindex))))
32652 + au_fset_fillvdir(arg->flags, WHABLE);
32655 + au_fclr_fillvdir(arg->flags, CALLED);
32657 + err = vfsub_iterate_dir(hf, &arg->ctx);
32660 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32663 + * dir_relax() may be good for concurrency, but aufs should not
32664 + * use it since it will cause a lockdep problem.
32668 + if (!err && shwh)
32669 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32671 + au_nhash_wh_free(&arg->whlist);
32674 + au_nhash_de_free(&arg->delist);
32679 +static int read_vdir(struct file *file, int may_read)
32682 + unsigned long expire;
32683 + unsigned char do_read;
32684 + struct fillvdir_arg arg = {
32686 + .actor = fillvdir
32689 + struct inode *inode;
32690 + struct au_vdir *vdir, *allocated;
32693 + inode = file_inode(file);
32694 + IMustLock(inode);
32695 + IiMustWriteLock(inode);
32696 + SiMustAnyLock(inode->i_sb);
32698 + allocated = NULL;
32700 + expire = au_sbi(inode->i_sb)->si_rdcache;
32701 + vdir = au_ivdir(inode);
32704 + vdir = alloc_vdir(file);
32705 + err = PTR_ERR(vdir);
32706 + if (IS_ERR(vdir))
32709 + allocated = vdir;
32710 + } else if (may_read
32711 + && (!inode_eq_iversion(inode, vdir->vd_version)
32712 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32714 + err = reinit_vdir(vdir);
32715 + if (unlikely(err))
32720 + return 0; /* success */
32724 + err = au_do_read_vdir(&arg);
32726 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32727 + vdir->vd_version = inode_query_iversion(inode);
32728 + vdir->vd_last.ul = 0;
32729 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32731 + au_set_ivdir(inode, allocated);
32732 + } else if (allocated)
32733 + au_vdir_free(allocated);
32739 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32742 + unsigned long ul, n;
32743 + const unsigned int deblk_sz = src->vd_deblk_sz;
32745 + AuDebugOn(tgt->vd_nblk != 1);
32748 + if (tgt->vd_nblk < src->vd_nblk) {
32749 + unsigned char **p;
32751 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32752 + GFP_NOFS, /*may_shrink*/0);
32753 + if (unlikely(!p))
32755 + tgt->vd_deblk = p;
32758 + if (tgt->vd_deblk_sz != deblk_sz) {
32759 + unsigned char *p;
32761 + tgt->vd_deblk_sz = deblk_sz;
32762 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32763 + /*may_shrink*/1);
32764 + if (unlikely(!p))
32766 + tgt->vd_deblk[0] = p;
32768 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32769 + tgt->vd_version = src->vd_version;
32770 + tgt->vd_jiffy = src->vd_jiffy;
32772 + n = src->vd_nblk;
32773 + for (ul = 1; ul < n; ul++) {
32774 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32776 + if (unlikely(!tgt->vd_deblk[ul]))
32780 + tgt->vd_nblk = n;
32781 + tgt->vd_last.ul = tgt->vd_last.ul;
32782 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32783 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32784 + - src->vd_deblk[src->vd_last.ul];
32786 + return 0; /* success */
32789 + rerr = reinit_vdir(tgt);
32794 +int au_vdir_init(struct file *file)
32797 + struct inode *inode;
32798 + struct au_vdir *vdir_cache, *allocated;
32800 + /* test file->f_pos here instead of ctx->pos */
32801 + err = read_vdir(file, !file->f_pos);
32802 + if (unlikely(err))
32805 + allocated = NULL;
32806 + vdir_cache = au_fvdir_cache(file);
32807 + if (!vdir_cache) {
32808 + vdir_cache = alloc_vdir(file);
32809 + err = PTR_ERR(vdir_cache);
32810 + if (IS_ERR(vdir_cache))
32812 + allocated = vdir_cache;
32813 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32814 + /* test file->f_pos here instead of ctx->pos */
32815 + err = reinit_vdir(vdir_cache);
32816 + if (unlikely(err))
32819 + return 0; /* success */
32821 + inode = file_inode(file);
32822 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32824 + file->f_version = inode_query_iversion(inode);
32826 + au_set_fvdir_cache(file, allocated);
32827 + } else if (allocated)
32828 + au_vdir_free(allocated);
32834 +static loff_t calc_offset(struct au_vdir *vdir)
32837 + union au_vdir_deblk_p p;
32839 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32840 + offset = vdir->vd_last.p.deblk - p.deblk;
32841 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32845 +/* returns true or false */
32846 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32849 + unsigned int deblk_sz;
32850 + unsigned long ul, n;
32852 + union au_vdir_deblk_p p, deblk_end;
32853 + struct au_vdir *vdir_cache;
32856 + vdir_cache = au_fvdir_cache(file);
32857 + offset = calc_offset(vdir_cache);
32858 + AuDbg("offset %lld\n", offset);
32859 + if (ctx->pos == offset)
32862 + vdir_cache->vd_last.ul = 0;
32863 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32868 + deblk_sz = vdir_cache->vd_deblk_sz;
32869 + ul = div64_u64(ctx->pos, deblk_sz);
32870 + AuDbg("ul %lu\n", ul);
32871 + if (ul >= vdir_cache->vd_nblk)
32874 + n = vdir_cache->vd_nblk;
32875 + for (; ul < n; ul++) {
32876 + p.deblk = vdir_cache->vd_deblk[ul];
32877 + deblk_end.deblk = p.deblk + deblk_sz;
32879 + offset *= deblk_sz;
32880 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32883 + l = calc_size(p.de->de_str.len);
32887 + if (!is_deblk_end(&p, &deblk_end)) {
32889 + vdir_cache->vd_last.ul = ul;
32890 + vdir_cache->vd_last.p = p;
32898 + AuDbg("valid %d\n", !valid);
32902 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32904 + unsigned int l, deblk_sz;
32905 + union au_vdir_deblk_p deblk_end;
32906 + struct au_vdir *vdir_cache;
32907 + struct au_vdir_de *de;
32909 + if (!seek_vdir(file, ctx))
32912 + vdir_cache = au_fvdir_cache(file);
32913 + deblk_sz = vdir_cache->vd_deblk_sz;
32915 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32916 + deblk_end.deblk += deblk_sz;
32917 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32918 + de = vdir_cache->vd_last.p.de;
32919 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32920 + de->de_str.len, de->de_str.name, ctx->pos,
32921 + (unsigned long)de->de_ino, de->de_type);
32922 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32923 + de->de_str.len, de->de_ino,
32925 + /* todo: ignore the error caused by udba? */
32926 + /* return err; */
32930 + l = calc_size(de->de_str.len);
32931 + vdir_cache->vd_last.p.deblk += l;
32934 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32935 + vdir_cache->vd_last.ul++;
32936 + vdir_cache->vd_last.p.deblk
32937 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32938 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32947 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32948 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32949 +++ linux/fs/aufs/vfsub.c 2023-09-04 13:39:55.763295607 +0200
32951 +// SPDX-License-Identifier: GPL-2.0
32953 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32955 + * This program is free software; you can redistribute it and/or modify
32956 + * it under the terms of the GNU General Public License as published by
32957 + * the Free Software Foundation; either version 2 of the License, or
32958 + * (at your option) any later version.
32960 + * This program is distributed in the hope that it will be useful,
32961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32963 + * GNU General Public License for more details.
32965 + * You should have received a copy of the GNU General Public License
32966 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32970 + * sub-routines for VFS
32973 +#include <linux/mnt_namespace.h>
32974 +#include <linux/nsproxy.h>
32975 +#include <linux/security.h>
32976 +#include <linux/splice.h>
32979 +#ifdef CONFIG_AUFS_BR_FUSE
32980 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32982 + if (!au_test_fuse(h_sb) || !au_userns)
32985 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32989 +int vfsub_sync_filesystem(struct super_block *h_sb)
32994 + down_read(&h_sb->s_umount);
32995 + err = sync_filesystem(h_sb);
32996 + up_read(&h_sb->s_umount);
33002 +/* ---------------------------------------------------------------------- */
33004 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33008 + struct super_block *h_sb;
33011 + * Always needs h_path->mnt for LSM or FUSE branch.
33013 + AuDebugOn(!h_path->mnt);
33015 + /* for remote fs, leave work for its getattr or d_revalidate */
33016 + /* for bad i_attr fs, handle them in aufs_getattr() */
33017 + /* still some fs may acquire i_mutex. we need to skip them */
33021 + h_sb = h_path->dentry->d_sb;
33022 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33024 + err = vfsub_getattr(h_path, &st);
33029 +/* ---------------------------------------------------------------------- */
33031 +struct file *vfsub_dentry_open(struct path *path, int flags)
33033 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33037 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33039 + struct file *file;
33042 + file = filp_open(path,
33043 + oflags /* | __FMODE_NONOTIFY */,
33046 + if (IS_ERR(file))
33048 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33055 + * Ideally this function should call VFS:do_last() in order to keep all its
33056 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33057 + * structure such as nameidata. This is a second (or third) best approach.
33058 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33060 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33061 + struct vfsub_aopen_args *args)
33064 + struct au_branch *br = args->br;
33065 + struct file *file = args->file;
33066 + /* copied from linux/fs/namei.c:atomic_open() */
33067 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33070 + AuDebugOn(!dir->i_op->atomic_open);
33072 + err = au_br_test_oflag(args->open_flag, br);
33073 + if (unlikely(err))
33076 + au_lcnt_inc(&br->br_nfiles);
33077 + file->f_path.dentry = DENTRY_NOT_SET;
33078 + file->f_path.mnt = au_br_mnt(br);
33079 + AuDbg("%ps\n", dir->i_op->atomic_open);
33080 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33081 + args->create_mode);
33082 + if (unlikely(err < 0)) {
33083 + au_lcnt_dec(&br->br_nfiles);
33087 + /* temporary workaround for nfsv4 branch */
33088 + if (au_test_nfs(dir->i_sb))
33089 + nfs_mark_for_revalidate(dir);
33091 + if (file->f_mode & FMODE_CREATED)
33092 + fsnotify_create(dir, dentry);
33093 + if (!(file->f_mode & FMODE_OPENED)) {
33094 + au_lcnt_dec(&br->br_nfiles);
33098 + /* todo: call VFS:may_open() here */
33099 + /* todo: ima_file_check() too? */
33100 + if (!err && (args->open_flag & __FMODE_EXEC))
33101 + err = deny_write_access(file);
33103 + fsnotify_open(file);
33105 + au_lcnt_dec(&br->br_nfiles);
33106 + /* note that the file is created and still opened */
33112 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33116 + err = kern_path(name, flags, path);
33117 + if (!err && d_is_positive(path->dentry))
33118 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33122 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33123 + struct path *ppath, int len)
33125 + struct path path;
33127 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33128 + if (IS_ERR(path.dentry))
33130 + if (d_is_positive(path.dentry)) {
33131 + path.mnt = ppath->mnt;
33132 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33136 + AuTraceErrPtr(path.dentry);
33137 + return path.dentry;
33140 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33143 + struct path path;
33145 + /* VFS checks it too, but by WARN_ON_ONCE() */
33146 + IMustLock(d_inode(ppath->dentry));
33148 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33149 + if (IS_ERR(path.dentry))
33151 + if (d_is_positive(path.dentry)) {
33152 + path.mnt = ppath->mnt;
33153 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33157 + AuTraceErrPtr(path.dentry);
33158 + return path.dentry;
33161 +void vfsub_call_lkup_one(void *args)
33163 + struct vfsub_lkup_one_args *a = args;
33164 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33167 +/* ---------------------------------------------------------------------- */
33169 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33170 + struct dentry *d2, struct au_hinode *hdir2)
33172 + struct dentry *d;
33175 + d = lock_rename(d1, d2);
33177 + au_hn_suspend(hdir1);
33178 + if (hdir1 != hdir2)
33179 + au_hn_suspend(hdir2);
33184 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33185 + struct dentry *d2, struct au_hinode *hdir2)
33187 + au_hn_resume(hdir1);
33188 + if (hdir1 != hdir2)
33189 + au_hn_resume(hdir2);
33191 + unlock_rename(d1, d2);
33195 +/* ---------------------------------------------------------------------- */
33197 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33200 + struct dentry *d;
33201 + struct mnt_idmap *idmap;
33205 + d = path->dentry;
33206 + path->dentry = d->d_parent;
33207 + err = security_path_mknod(path, d, mode, 0);
33208 + path->dentry = d;
33209 + if (unlikely(err))
33211 + idmap = mnt_idmap(path->mnt);
33214 + err = vfs_create(idmap, dir, path->dentry, mode, want_excl);
33217 + struct path tmp = *path;
33220 + vfsub_update_h_iattr(&tmp, &did);
33222 + tmp.dentry = path->dentry->d_parent;
33223 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33232 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33235 + struct dentry *d;
33236 + struct mnt_idmap *idmap;
33240 + d = path->dentry;
33241 + path->dentry = d->d_parent;
33242 + err = security_path_symlink(path, d, symname);
33243 + path->dentry = d;
33244 + if (unlikely(err))
33246 + idmap = mnt_idmap(path->mnt);
33249 + err = vfs_symlink(idmap, dir, path->dentry, symname);
33252 + struct path tmp = *path;
33255 + vfsub_update_h_iattr(&tmp, &did);
33257 + tmp.dentry = path->dentry->d_parent;
33258 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33267 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33270 + struct dentry *d;
33271 + struct mnt_idmap *idmap;
33275 + d = path->dentry;
33276 + path->dentry = d->d_parent;
33277 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33278 + path->dentry = d;
33279 + if (unlikely(err))
33281 + idmap = mnt_idmap(path->mnt);
33284 + err = vfs_mknod(idmap, dir, path->dentry, mode, dev);
33287 + struct path tmp = *path;
33290 + vfsub_update_h_iattr(&tmp, &did);
33292 + tmp.dentry = path->dentry->d_parent;
33293 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33302 +static int au_test_nlink(struct inode *inode)
33304 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33306 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33307 + || inode->i_nlink < link_max)
33312 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33313 + struct inode **delegated_inode)
33316 + struct dentry *d;
33317 + struct mnt_idmap *idmap;
33321 + err = au_test_nlink(d_inode(src_dentry));
33322 + if (unlikely(err))
33325 + /* we don't call may_linkat() */
33326 + d = path->dentry;
33327 + path->dentry = d->d_parent;
33328 + err = security_path_link(src_dentry, path, d);
33329 + path->dentry = d;
33330 + if (unlikely(err))
33332 + idmap = mnt_idmap(path->mnt);
33335 + err = vfs_link(src_dentry, idmap, dir, path->dentry, delegated_inode);
33338 + struct path tmp = *path;
33341 + /* fuse has different memory inode for the same inumber */
33342 + vfsub_update_h_iattr(&tmp, &did);
33344 + tmp.dentry = path->dentry->d_parent;
33345 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33346 + tmp.dentry = src_dentry;
33347 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33356 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33357 + struct inode *dir, struct path *path,
33358 + struct inode **delegated_inode, unsigned int flags)
33361 + struct renamedata rd;
33362 + struct path tmp = {
33365 + struct dentry *d;
33368 + IMustLock(src_dir);
33370 + d = path->dentry;
33371 + path->dentry = d->d_parent;
33372 + tmp.dentry = src_dentry->d_parent;
33373 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33374 + path->dentry = d;
33375 + if (unlikely(err))
33378 + rd.old_mnt_idmap = mnt_idmap(path->mnt);
33379 + rd.old_dir = src_dir;
33380 + rd.old_dentry = src_dentry;
33381 + rd.new_mnt_idmap = rd.old_mnt_idmap;
33382 + rd.new_dir = dir;
33383 + rd.new_dentry = path->dentry;
33384 + rd.delegated_inode = delegated_inode;
33385 + rd.flags = flags;
33387 + err = vfs_rename(&rd);
33392 + tmp.dentry = d->d_parent;
33393 + vfsub_update_h_iattr(&tmp, &did);
33395 + tmp.dentry = src_dentry;
33396 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33397 + tmp.dentry = src_dentry->d_parent;
33398 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33407 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33410 + struct dentry *d;
33411 + struct mnt_idmap *idmap;
33415 + d = path->dentry;
33416 + path->dentry = d->d_parent;
33417 + err = security_path_mkdir(path, d, mode);
33418 + path->dentry = d;
33419 + if (unlikely(err))
33421 + idmap = mnt_idmap(path->mnt);
33424 + err = vfs_mkdir(idmap, dir, path->dentry, mode);
33427 + struct path tmp = *path;
33430 + vfsub_update_h_iattr(&tmp, &did);
33432 + tmp.dentry = path->dentry->d_parent;
33433 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33442 +int vfsub_rmdir(struct inode *dir, struct path *path)
33445 + struct dentry *d;
33446 + struct mnt_idmap *idmap;
33450 + d = path->dentry;
33451 + path->dentry = d->d_parent;
33452 + err = security_path_rmdir(path, d);
33453 + path->dentry = d;
33454 + if (unlikely(err))
33456 + idmap = mnt_idmap(path->mnt);
33459 + err = vfs_rmdir(idmap, dir, path->dentry);
33462 + struct path tmp = {
33463 + .dentry = path->dentry->d_parent,
33467 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33474 +/* ---------------------------------------------------------------------- */
33476 +/* todo: support mmap_sem? */
33477 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33483 + err = vfs_read(file, ubuf, count, ppos);
33486 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33490 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33496 + err = kernel_read(file, kbuf, count, ppos);
33500 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33504 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33510 + err = vfs_write(file, ubuf, count, ppos);
33513 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33517 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33522 + err = kernel_write(file, kbuf, count, ppos);
33525 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33529 +int vfsub_flush(struct file *file, fl_owner_t id)
33534 + if (file->f_op->flush) {
33535 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33536 + err = file->f_op->flush(file, id);
33539 + err = file->f_op->flush(file, id);
33543 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33549 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33553 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33556 + err = iterate_dir(file, ctx);
33559 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33564 +long vfsub_splice_read(struct file *in, loff_t *ppos,
33565 + struct pipe_inode_info *pipe, size_t len,
33566 + unsigned int flags)
33571 + err = vfs_splice_read(in, ppos, pipe, len, flags);
33573 + file_accessed(in);
33575 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33579 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33580 + loff_t *ppos, size_t len, unsigned int flags)
33585 + err = do_splice_from(pipe, out, ppos, len, flags);
33588 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33592 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33596 + /* file can be NULL */
33598 + err = vfs_fsync(file, datasync);
33602 + AuDebugOn(!file);
33603 + path = &file->f_path;
33605 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33610 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33611 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33612 + struct file *h_file)
33615 + struct inode *h_inode;
33616 + struct super_block *h_sb;
33617 + struct mnt_idmap *h_idmap;
33620 + err = vfsub_truncate(h_path, length);
33624 + h_inode = d_inode(h_path->dentry);
33625 + h_sb = h_inode->i_sb;
33627 + sb_start_write(h_sb);
33629 + err = security_file_truncate(h_file);
33631 + h_idmap = mnt_idmap(h_path->mnt);
33633 + err = do_truncate(h_idmap, h_path->dentry, length, attr,
33638 + sb_end_write(h_sb);
33645 +/* ---------------------------------------------------------------------- */
33647 +struct au_vfsub_mkdir_args {
33649 + struct inode *dir;
33650 + struct path *path;
33654 +static void au_call_vfsub_mkdir(void *args)
33656 + struct au_vfsub_mkdir_args *a = args;
33657 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33660 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33662 + int err, do_sio, wkq_err;
33663 + struct mnt_idmap *idmap;
33665 + idmap = mnt_idmap(path->mnt);
33666 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33669 + err = vfsub_mkdir(dir, path, mode);
33672 + struct au_vfsub_mkdir_args args = {
33678 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33679 + if (unlikely(wkq_err))
33686 +struct au_vfsub_rmdir_args {
33688 + struct inode *dir;
33689 + struct path *path;
33692 +static void au_call_vfsub_rmdir(void *args)
33694 + struct au_vfsub_rmdir_args *a = args;
33695 + *a->errp = vfsub_rmdir(a->dir, a->path);
33698 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33700 + int err, do_sio, wkq_err;
33701 + struct mnt_idmap *idmap;
33703 + idmap = mnt_idmap(path->mnt);
33704 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33707 + err = vfsub_rmdir(dir, path);
33710 + struct au_vfsub_rmdir_args args = {
33715 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33716 + if (unlikely(wkq_err))
33723 +/* ---------------------------------------------------------------------- */
33725 +struct notify_change_args {
33727 + struct path *path;
33728 + struct iattr *ia;
33729 + struct inode **delegated_inode;
33732 +static void call_notify_change(void *args)
33734 + struct notify_change_args *a = args;
33735 + struct inode *h_inode;
33736 + struct mnt_idmap *idmap;
33738 + h_inode = d_inode(a->path->dentry);
33739 + IMustLock(h_inode);
33741 + *a->errp = -EPERM;
33742 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33743 + idmap = mnt_idmap(a->path->mnt);
33745 + *a->errp = notify_change(idmap, a->path->dentry, a->ia,
33746 + a->delegated_inode);
33749 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33751 + AuTraceErr(*a->errp);
33754 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33755 + struct inode **delegated_inode)
33758 + struct notify_change_args args = {
33762 + .delegated_inode = delegated_inode
33765 + call_notify_change(&args);
33770 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33771 + struct inode **delegated_inode)
33773 + int err, wkq_err;
33774 + struct notify_change_args args = {
33778 + .delegated_inode = delegated_inode
33781 + wkq_err = au_wkq_wait(call_notify_change, &args);
33782 + if (unlikely(wkq_err))
33788 +/* ---------------------------------------------------------------------- */
33790 +struct unlink_args {
33792 + struct inode *dir;
33793 + struct path *path;
33794 + struct inode **delegated_inode;
33797 +static void call_unlink(void *args)
33799 + struct unlink_args *a = args;
33800 + struct dentry *d = a->path->dentry;
33801 + struct inode *h_inode;
33802 + struct mnt_idmap *idmap;
33803 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33804 + && au_dcount(d) == 1);
33806 + IMustLock(a->dir);
33808 + a->path->dentry = d->d_parent;
33809 + *a->errp = security_path_unlink(a->path, d);
33810 + a->path->dentry = d;
33811 + if (unlikely(*a->errp))
33814 + if (!stop_sillyrename)
33817 + if (d_is_positive(d)) {
33818 + h_inode = d_inode(d);
33822 + idmap = mnt_idmap(a->path->mnt);
33824 + *a->errp = vfs_unlink(idmap, a->dir, d, a->delegated_inode);
33827 + struct path tmp = {
33828 + .dentry = d->d_parent,
33829 + .mnt = a->path->mnt
33831 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33834 + if (!stop_sillyrename)
33839 + AuTraceErr(*a->errp);
33843 + * @dir: must be locked.
33844 + * @dentry: target dentry.
33846 +int vfsub_unlink(struct inode *dir, struct path *path,
33847 + struct inode **delegated_inode, int force)
33850 + struct unlink_args args = {
33854 + .delegated_inode = delegated_inode
33858 + call_unlink(&args);
33862 + wkq_err = au_wkq_wait(call_unlink, &args);
33863 + if (unlikely(wkq_err))
33869 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33870 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33871 +++ linux/fs/aufs/vfsub.h 2023-09-04 13:39:55.763295607 +0200
33873 +/* SPDX-License-Identifier: GPL-2.0 */
33875 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33877 + * This program is free software; you can redistribute it and/or modify
33878 + * it under the terms of the GNU General Public License as published by
33879 + * the Free Software Foundation; either version 2 of the License, or
33880 + * (at your option) any later version.
33882 + * This program is distributed in the hope that it will be useful,
33883 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33884 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33885 + * GNU General Public License for more details.
33887 + * You should have received a copy of the GNU General Public License
33888 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33892 + * sub-routines for VFS
33895 +#ifndef __AUFS_VFSUB_H__
33896 +#define __AUFS_VFSUB_H__
33900 +#include <linux/fs.h>
33901 +#include <linux/mount.h>
33902 +#include <linux/posix_acl.h>
33903 +#include <linux/xattr.h>
33904 +#include "debug.h"
33906 +/* copied from linux/fs/internal.h */
33907 +/* todo: BAD approach!! */
33908 +extern void __mnt_drop_write(struct vfsmount *);
33909 +extern struct file *alloc_empty_file(int, const struct cred *);
33911 +/* ---------------------------------------------------------------------- */
33913 +/* lock subclass for lower inode */
33914 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33915 +/* reduce? gave up. */
33917 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33918 + AuLsc_I_PARENT, /* lower inode, parent first */
33919 + AuLsc_I_PARENT2, /* copyup dirs */
33920 + AuLsc_I_PARENT3, /* copyup wh */
33926 +/* to debug easier, do not make them inlined functions */
33927 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33928 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33930 +/* ---------------------------------------------------------------------- */
33932 +static inline void vfsub_drop_nlink(struct inode *inode)
33934 + AuDebugOn(!inode->i_nlink);
33935 + drop_nlink(inode);
33938 +static inline void vfsub_dead_dir(struct inode *inode)
33940 + AuDebugOn(!S_ISDIR(inode->i_mode));
33941 + inode->i_flags |= S_DEAD;
33942 + clear_nlink(inode);
33945 +static inline int vfsub_native_ro(struct inode *inode)
33947 + return sb_rdonly(inode->i_sb)
33948 + || IS_RDONLY(inode)
33949 + /* || IS_APPEND(inode) */
33950 + || IS_IMMUTABLE(inode);
33953 +#ifdef CONFIG_AUFS_BR_FUSE
33954 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33956 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33959 +int vfsub_sync_filesystem(struct super_block *h_sb);
33961 +/* ---------------------------------------------------------------------- */
33963 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33964 +struct file *vfsub_dentry_open(struct path *path, int flags);
33965 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33967 +struct vfsub_aopen_args {
33968 + struct file *file;
33969 + unsigned int open_flag;
33970 + umode_t create_mode;
33971 + struct au_branch *br;
33973 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33974 + struct vfsub_aopen_args *args);
33975 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33977 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33978 + struct path *ppath, int len);
33979 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33982 +struct vfsub_lkup_one_args {
33983 + struct dentry **errp;
33984 + struct qstr *name;
33985 + struct path *ppath;
33988 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33989 + struct path *ppath)
33991 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33994 +void vfsub_call_lkup_one(void *args);
33996 +/* ---------------------------------------------------------------------- */
33998 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34003 + err = mnt_want_write(mnt);
34008 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34011 + mnt_drop_write(mnt);
34015 +#if 0 /* reserved */
34016 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34019 + mnt_drop_write_file(file);
34024 +/* ---------------------------------------------------------------------- */
34027 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34028 + struct dentry *d2, struct au_hinode *hdir2);
34029 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34030 + struct dentry *d2, struct au_hinode *hdir2);
34032 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34034 +int vfsub_symlink(struct inode *dir, struct path *path,
34035 + const char *symname);
34036 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34037 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34038 + struct path *path, struct inode **delegated_inode);
34039 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34040 + struct inode *hdir, struct path *path,
34041 + struct inode **delegated_inode, unsigned int flags);
34042 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34043 +int vfsub_rmdir(struct inode *dir, struct path *path);
34045 +/* ---------------------------------------------------------------------- */
34047 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34049 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34051 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34053 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34055 +int vfsub_flush(struct file *file, fl_owner_t id);
34056 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34058 +static inline loff_t vfsub_f_size_read(struct file *file)
34060 + return i_size_read(file_inode(file));
34063 +static inline unsigned int vfsub_file_flags(struct file *file)
34065 + unsigned int flags;
34067 + spin_lock(&file->f_lock);
34068 + flags = file->f_flags;
34069 + spin_unlock(&file->f_lock);
34074 +static inline int vfsub_file_execed(struct file *file)
34076 + /* todo: direct access f_flags */
34077 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34080 +#if 0 /* reserved */
34081 +static inline void vfsub_file_accessed(struct file *h_file)
34083 + file_accessed(h_file);
34084 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34088 +#if 0 /* reserved */
34089 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34090 + struct dentry *h_dentry)
34092 + struct path h_path = {
34093 + .dentry = h_dentry,
34096 + touch_atime(&h_path);
34097 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34101 +static inline int vfsub_update_time(struct inode *h_inode,
34102 + struct timespec64 *ts, int flags)
34104 + return inode_update_time(h_inode, ts, flags);
34105 + /* no vfsub_update_h_iattr() since we don't have struct path */
34108 +#ifdef CONFIG_FS_POSIX_ACL
34109 +static inline int vfsub_acl_chmod(struct mnt_idmap *h_idmap,
34110 + struct dentry *h_dentry, umode_t h_mode)
34114 + err = posix_acl_chmod(h_idmap, h_dentry, h_mode);
34115 + if (err == -EOPNOTSUPP)
34120 +AuStubInt0(vfsub_acl_chmod, struct mnt_idmap *h_idmap,
34121 + struct dentry *h_dentry, umode_t h_mode);
34124 +long vfsub_splice_read(struct file *in, loff_t *ppos,
34125 + struct pipe_inode_info *pipe, size_t len,
34126 + unsigned int flags);
34127 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34128 + loff_t *ppos, size_t len, unsigned int flags);
34130 +static inline long vfsub_truncate(struct path *path, loff_t length)
34135 + err = vfs_truncate(path, length);
34140 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34141 + struct file *h_file);
34142 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34145 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34148 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34154 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34160 +/* copy_file_range(2) is a systemcall */
34161 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34162 + struct file *dst, loff_t dst_pos,
34163 + size_t len, unsigned int flags)
34168 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34174 +/* ---------------------------------------------------------------------- */
34176 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34181 + err = vfs_llseek(file, offset, origin);
34186 +/* ---------------------------------------------------------------------- */
34188 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34189 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34190 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34191 + struct inode **delegated_inode);
34192 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34193 + struct inode **delegated_inode);
34194 +int vfsub_unlink(struct inode *dir, struct path *path,
34195 + struct inode **delegated_inode, int force);
34197 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34199 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34202 +/* ---------------------------------------------------------------------- */
34204 +static inline int vfsub_setxattr(struct mnt_idmap *idmap,
34205 + struct dentry *dentry, const char *name,
34206 + const void *value, size_t size, int flags)
34211 + err = vfs_setxattr(idmap, dentry, name, value, size, flags);
34217 +static inline int vfsub_removexattr(struct mnt_idmap *idmap,
34218 + struct dentry *dentry, const char *name)
34223 + err = vfs_removexattr(idmap, dentry, name);
34229 +#ifdef CONFIG_FS_POSIX_ACL
34230 +static inline int vfsub_set_acl(struct mnt_idmap *idmap,
34231 + struct dentry *dentry, const char *name,
34232 + struct posix_acl *acl)
34237 + err = vfs_set_acl(idmap, dentry, name, acl);
34243 +static inline int vfsub_remove_acl(struct mnt_idmap *idmap,
34244 + struct dentry *dentry, const char *name)
34249 + err = vfs_remove_acl(idmap, dentry, name);
34255 +AuStubInt0(vfsub_set_acl, struct mnt_idmap *idmap, struct dentry *dentry,
34256 + const char *name, struct posix_acl *acl);
34257 +AuStubInt0(vfsub_remove_acl, struct mnt_idmap *idmap,
34258 + struct dentry *dentry, const char *name);
34261 +#endif /* __KERNEL__ */
34262 +#endif /* __AUFS_VFSUB_H__ */
34263 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34264 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34265 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34267 +// SPDX-License-Identifier: GPL-2.0
34269 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34271 + * This program is free software; you can redistribute it and/or modify
34272 + * it under the terms of the GNU General Public License as published by
34273 + * the Free Software Foundation; either version 2 of the License, or
34274 + * (at your option) any later version.
34276 + * This program is distributed in the hope that it will be useful,
34277 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34278 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34279 + * GNU General Public License for more details.
34281 + * You should have received a copy of the GNU General Public License
34282 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34286 + * policies for selecting one among multiple writable branches
34289 +#include <linux/statfs.h>
34292 +/* subset of cpup_attr() */
34293 +static noinline_for_stack
34294 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34298 + struct inode *h_isrc;
34300 + h_isrc = d_inode(h_src);
34301 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34302 + ia.ia_mode = h_isrc->i_mode;
34303 + ia.ia_uid = h_isrc->i_uid;
34304 + ia.ia_gid = h_isrc->i_gid;
34305 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34306 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34307 + /* no delegation since it is just created */
34308 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34310 + /* is this nfs only? */
34311 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34312 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34313 + ia.ia_mode = h_isrc->i_mode;
34314 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34320 +#define AuCpdown_PARENT_OPQ 1
34321 +#define AuCpdown_WHED (1 << 1)
34322 +#define AuCpdown_MADE_DIR (1 << 2)
34323 +#define AuCpdown_DIROPQ (1 << 3)
34324 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34325 +#define au_fset_cpdown(flags, name) \
34326 + do { (flags) |= AuCpdown_##name; } while (0)
34327 +#define au_fclr_cpdown(flags, name) \
34328 + do { (flags) &= ~AuCpdown_##name; } while (0)
34330 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34331 + unsigned int *flags)
34334 + struct dentry *opq_dentry;
34336 + opq_dentry = au_diropq_create(dentry, bdst);
34337 + err = PTR_ERR(opq_dentry);
34338 + if (IS_ERR(opq_dentry))
34340 + dput(opq_dentry);
34341 + au_fset_cpdown(*flags, DIROPQ);
34347 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34348 + struct inode *dir, aufs_bindex_t bdst)
34351 + struct path h_path;
34352 + struct au_branch *br;
34354 + br = au_sbr(dentry->d_sb, bdst);
34355 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34356 + err = PTR_ERR(h_path.dentry);
34357 + if (IS_ERR(h_path.dentry))
34361 + if (d_is_positive(h_path.dentry)) {
34362 + h_path.mnt = au_br_mnt(br);
34363 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34366 + dput(h_path.dentry);
34372 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34373 + struct au_pin *pin,
34374 + struct dentry *h_parent, void *arg)
34377 + aufs_bindex_t bopq, btop;
34378 + struct path h_path;
34379 + struct dentry *parent;
34380 + struct inode *h_dir, *h_inode, *inode, *dir;
34381 + unsigned int *flags = arg;
34383 + btop = au_dbtop(dentry);
34384 + /* dentry is di-locked */
34385 + parent = dget_parent(dentry);
34386 + dir = d_inode(parent);
34387 + h_dir = d_inode(h_parent);
34388 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34389 + IMustLock(h_dir);
34391 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34392 + if (unlikely(err < 0))
34394 + h_path.dentry = au_h_dptr(dentry, bdst);
34395 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34396 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34397 + if (unlikely(err))
34399 + au_fset_cpdown(*flags, MADE_DIR);
34401 + bopq = au_dbdiropq(dentry);
34402 + au_fclr_cpdown(*flags, WHED);
34403 + au_fclr_cpdown(*flags, DIROPQ);
34404 + if (au_dbwh(dentry) == bdst)
34405 + au_fset_cpdown(*flags, WHED);
34406 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34407 + au_fset_cpdown(*flags, PARENT_OPQ);
34408 + h_inode = d_inode(h_path.dentry);
34409 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34410 + if (au_ftest_cpdown(*flags, WHED)) {
34411 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34412 + if (unlikely(err)) {
34413 + inode_unlock(h_inode);
34418 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34419 + inode_unlock(h_inode);
34420 + if (unlikely(err))
34423 + if (au_ftest_cpdown(*flags, WHED)) {
34424 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34425 + if (unlikely(err))
34429 + inode = d_inode(dentry);
34430 + if (au_ibbot(inode) < bdst)
34431 + au_set_ibbot(inode, bdst);
34432 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34433 + au_hi_flags(inode, /*isdir*/1));
34434 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34435 + goto out; /* success */
34439 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34440 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34441 + rerr = au_diropq_remove(dentry, bdst);
34442 + inode_unlock(h_inode);
34443 + if (unlikely(rerr)) {
34444 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34445 + dentry, bdst, rerr);
34451 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34452 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34453 + if (unlikely(rerr)) {
34454 + AuIOErr("failed removing %pd b%d (%d)\n",
34455 + dentry, bdst, rerr);
34460 + au_set_h_dptr(dentry, bdst, NULL);
34461 + if (au_dbbot(dentry) == bdst)
34462 + au_update_dbbot(dentry);
34468 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34471 + unsigned int flags;
34474 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34479 +/* ---------------------------------------------------------------------- */
34481 +/* policies for create */
34483 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34485 + int err, i, j, ndentry;
34486 + aufs_bindex_t bopq;
34487 + struct au_dcsub_pages dpages;
34488 + struct au_dpage *dpage;
34489 + struct dentry **dentries, *parent, *d;
34491 + err = au_dpages_init(&dpages, GFP_NOFS);
34492 + if (unlikely(err))
34494 + parent = dget_parent(dentry);
34495 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34496 + if (unlikely(err))
34500 + for (i = 0; i < dpages.ndpage; i++) {
34501 + dpage = dpages.dpages + i;
34502 + dentries = dpage->dentries;
34503 + ndentry = dpage->ndentry;
34504 + for (j = 0; j < ndentry; j++) {
34506 + di_read_lock_parent2(d, !AuLock_IR);
34507 + bopq = au_dbdiropq(d);
34508 + di_read_unlock(d, !AuLock_IR);
34509 + if (bopq >= 0 && bopq < err)
34516 + au_dpages_free(&dpages);
34521 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34523 + for (; bindex >= 0; bindex--)
34524 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34529 +/* top down parent */
34530 +static int au_wbr_create_tdp(struct dentry *dentry,
34531 + unsigned int flags __maybe_unused)
34534 + aufs_bindex_t btop, bindex;
34535 + struct super_block *sb;
34536 + struct dentry *parent, *h_parent;
34538 + sb = dentry->d_sb;
34539 + btop = au_dbtop(dentry);
34541 + if (!au_br_rdonly(au_sbr(sb, btop)))
34545 + parent = dget_parent(dentry);
34546 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34547 + h_parent = au_h_dptr(parent, bindex);
34548 + if (!h_parent || d_is_negative(h_parent))
34551 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34558 + /* bottom up here */
34559 + if (unlikely(err < 0)) {
34560 + err = au_wbr_bu(sb, btop - 1);
34562 + err = au_wbr_nonopq(dentry, err);
34566 + AuDbg("b%d\n", err);
34570 +/* ---------------------------------------------------------------------- */
34572 +/* an exception for the policy other than tdp */
34573 +static int au_wbr_create_exp(struct dentry *dentry)
34576 + aufs_bindex_t bwh, bdiropq;
34577 + struct dentry *parent;
34580 + bwh = au_dbwh(dentry);
34581 + parent = dget_parent(dentry);
34582 + bdiropq = au_dbdiropq(parent);
34584 + if (bdiropq >= 0)
34585 + err = min(bdiropq, bwh);
34588 + AuDbg("%d\n", err);
34589 + } else if (bdiropq >= 0) {
34591 + AuDbg("%d\n", err);
34596 + err = au_wbr_nonopq(dentry, err);
34598 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34601 + AuDbg("%d\n", err);
34605 +/* ---------------------------------------------------------------------- */
34608 +static int au_wbr_create_init_rr(struct super_block *sb)
34612 + err = au_wbr_bu(sb, au_sbbot(sb));
34613 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34616 + AuDbg("b%d\n", err);
34620 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34624 + aufs_bindex_t bindex, bbot;
34625 + struct super_block *sb;
34628 + err = au_wbr_create_exp(dentry);
34632 + sb = dentry->d_sb;
34633 + next = &au_sbi(sb)->si_wbr_rr_next;
34634 + bbot = au_sbbot(sb);
34636 + for (bindex = 0; bindex <= bbot; bindex++) {
34637 + if (!au_ftest_wbr(flags, DIR)) {
34638 + err = atomic_dec_return(next) + 1;
34639 + /* modulo for 0 is meaningless */
34640 + if (unlikely(!err))
34641 + err = atomic_dec_return(next) + 1;
34643 + err = atomic_read(next);
34644 + AuDbg("%d\n", err);
34647 + AuDbg("%d\n", err);
34648 + if (!au_br_rdonly(au_sbr(sb, err)))
34654 + err = au_wbr_nonopq(dentry, err);
34657 + AuDbg("%d\n", err);
34661 +/* ---------------------------------------------------------------------- */
34663 +/* most free space */
34664 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34666 + struct super_block *sb;
34667 + struct au_branch *br;
34668 + struct au_wbr_mfs *mfs;
34669 + struct dentry *h_parent;
34670 + aufs_bindex_t bindex, bbot;
34672 + unsigned long long b, bavail;
34673 + struct path h_path;
34674 + /* reduce the stack usage */
34675 + struct kstatfs *st;
34677 + st = kmalloc(sizeof(*st), GFP_NOFS);
34678 + if (unlikely(!st)) {
34679 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34684 + sb = dentry->d_sb;
34685 + mfs = &au_sbi(sb)->si_wbr_mfs;
34686 + MtxMustLock(&mfs->mfs_lock);
34687 + mfs->mfs_bindex = -EROFS;
34688 + mfs->mfsrr_bytes = 0;
34691 + bbot = au_sbbot(sb);
34693 + bindex = au_dbtop(parent);
34694 + bbot = au_dbtaildir(parent);
34697 + for (; bindex <= bbot; bindex++) {
34699 + h_parent = au_h_dptr(parent, bindex);
34700 + if (!h_parent || d_is_negative(h_parent))
34703 + br = au_sbr(sb, bindex);
34704 + if (au_br_rdonly(br))
34707 + /* sb->s_root for NFS is unreliable */
34708 + h_path.mnt = au_br_mnt(br);
34709 + h_path.dentry = h_path.mnt->mnt_root;
34710 + err = vfs_statfs(&h_path, st);
34711 + if (unlikely(err)) {
34712 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34716 + /* when the available size is equal, select the lower one */
34717 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34718 + || sizeof(b) < sizeof(st->f_bsize));
34719 + b = st->f_bavail * st->f_bsize;
34720 + br->br_wbr->wbr_bytes = b;
34721 + if (b >= bavail) {
34723 + mfs->mfs_bindex = bindex;
34724 + mfs->mfs_jiffy = jiffies;
34728 + mfs->mfsrr_bytes = bavail;
34729 + AuDbg("b%d\n", mfs->mfs_bindex);
34730 + au_kfree_rcu(st);
34733 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34736 + struct dentry *parent;
34737 + struct super_block *sb;
34738 + struct au_wbr_mfs *mfs;
34740 + err = au_wbr_create_exp(dentry);
34744 + sb = dentry->d_sb;
34746 + if (au_ftest_wbr(flags, PARENT))
34747 + parent = dget_parent(dentry);
34748 + mfs = &au_sbi(sb)->si_wbr_mfs;
34749 + mutex_lock(&mfs->mfs_lock);
34750 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34751 + || mfs->mfs_bindex < 0
34752 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34753 + au_mfs(dentry, parent);
34754 + mutex_unlock(&mfs->mfs_lock);
34755 + err = mfs->mfs_bindex;
34759 + err = au_wbr_nonopq(dentry, err);
34762 + AuDbg("b%d\n", err);
34766 +static int au_wbr_create_init_mfs(struct super_block *sb)
34768 + struct au_wbr_mfs *mfs;
34770 + mfs = &au_sbi(sb)->si_wbr_mfs;
34771 + mutex_init(&mfs->mfs_lock);
34772 + mfs->mfs_jiffy = 0;
34773 + mfs->mfs_bindex = -EROFS;
34778 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34780 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34784 +/* ---------------------------------------------------------------------- */
34786 +/* top down regardless parent, and then mfs */
34787 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34788 + unsigned int flags __maybe_unused)
34791 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34792 + unsigned long long watermark;
34793 + struct super_block *sb;
34794 + struct au_wbr_mfs *mfs;
34795 + struct au_branch *br;
34796 + struct dentry *parent;
34798 + sb = dentry->d_sb;
34799 + mfs = &au_sbi(sb)->si_wbr_mfs;
34800 + mutex_lock(&mfs->mfs_lock);
34801 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34802 + || mfs->mfs_bindex < 0)
34803 + au_mfs(dentry, /*parent*/NULL);
34804 + watermark = mfs->mfsrr_watermark;
34805 + bmfs = mfs->mfs_bindex;
34806 + mutex_unlock(&mfs->mfs_lock);
34808 + /* another style of au_wbr_create_exp() */
34809 + bwh = au_dbwh(dentry);
34810 + parent = dget_parent(dentry);
34811 + btail = au_dbtaildir(parent);
34812 + if (bwh >= 0 && bwh < btail)
34815 + err = au_wbr_nonopq(dentry, btail);
34816 + if (unlikely(err < 0))
34820 + for (bindex = 0; bindex <= btail; bindex++) {
34821 + br = au_sbr(sb, bindex);
34822 + if (au_br_rdonly(br))
34824 + if (br->br_wbr->wbr_bytes > watermark) {
34835 + AuDbg("b%d\n", err);
34839 +/* ---------------------------------------------------------------------- */
34841 +/* most free space and then round robin */
34842 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34845 + struct au_wbr_mfs *mfs;
34847 + err = au_wbr_create_mfs(dentry, flags);
34849 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34850 + mutex_lock(&mfs->mfs_lock);
34851 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34852 + err = au_wbr_create_rr(dentry, flags);
34853 + mutex_unlock(&mfs->mfs_lock);
34856 + AuDbg("b%d\n", err);
34860 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34864 + au_wbr_create_init_mfs(sb); /* ignore */
34865 + err = au_wbr_create_init_rr(sb);
34870 +/* ---------------------------------------------------------------------- */
34872 +/* top down parent and most free space */
34873 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34876 + unsigned long long b;
34877 + aufs_bindex_t bindex, btop, bbot;
34878 + struct super_block *sb;
34879 + struct dentry *parent, *h_parent;
34880 + struct au_branch *br;
34882 + err = au_wbr_create_tdp(dentry, flags);
34883 + if (unlikely(err < 0))
34885 + parent = dget_parent(dentry);
34886 + btop = au_dbtop(parent);
34887 + bbot = au_dbtaildir(parent);
34888 + if (btop == bbot)
34889 + goto out_parent; /* success */
34891 + e2 = au_wbr_create_mfs(dentry, flags);
34893 + goto out_parent; /* success */
34895 + /* when the available size is equal, select upper one */
34896 + sb = dentry->d_sb;
34897 + br = au_sbr(sb, err);
34898 + b = br->br_wbr->wbr_bytes;
34899 + AuDbg("b%d, %llu\n", err, b);
34901 + for (bindex = btop; bindex <= bbot; bindex++) {
34902 + h_parent = au_h_dptr(parent, bindex);
34903 + if (!h_parent || d_is_negative(h_parent))
34906 + br = au_sbr(sb, bindex);
34907 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34908 + b = br->br_wbr->wbr_bytes;
34910 + AuDbg("b%d, %llu\n", err, b);
34915 + err = au_wbr_nonopq(dentry, err);
34920 + AuDbg("b%d\n", err);
34924 +/* ---------------------------------------------------------------------- */
34927 + * - top down parent
34928 + * - most free space with parent
34929 + * - most free space round-robin regardless parent
34931 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34934 + unsigned long long watermark;
34935 + struct super_block *sb;
34936 + struct au_branch *br;
34937 + struct au_wbr_mfs *mfs;
34939 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34940 + if (unlikely(err < 0))
34943 + sb = dentry->d_sb;
34944 + br = au_sbr(sb, err);
34945 + mfs = &au_sbi(sb)->si_wbr_mfs;
34946 + mutex_lock(&mfs->mfs_lock);
34947 + watermark = mfs->mfsrr_watermark;
34948 + mutex_unlock(&mfs->mfs_lock);
34949 + if (br->br_wbr->wbr_bytes < watermark)
34950 + /* regardless the parent dir */
34951 + err = au_wbr_create_mfsrr(dentry, flags);
34954 + AuDbg("b%d\n", err);
34958 +/* ---------------------------------------------------------------------- */
34960 +/* policies for copyup */
34962 +/* top down parent */
34963 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34965 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34968 +/* bottom up parent */
34969 +static int au_wbr_copyup_bup(struct dentry *dentry)
34972 + aufs_bindex_t bindex, btop;
34973 + struct dentry *parent, *h_parent;
34974 + struct super_block *sb;
34977 + sb = dentry->d_sb;
34978 + parent = dget_parent(dentry);
34979 + btop = au_dbtop(parent);
34980 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34981 + h_parent = au_h_dptr(parent, bindex);
34982 + if (!h_parent || d_is_negative(h_parent))
34985 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34992 + /* bottom up here */
34993 + if (unlikely(err < 0))
34994 + err = au_wbr_bu(sb, btop - 1);
34996 + AuDbg("b%d\n", err);
35001 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
35005 + err = au_wbr_bu(dentry->d_sb, btop);
35006 + AuDbg("b%d\n", err);
35008 + err = au_wbr_nonopq(dentry, err);
35010 + AuDbg("b%d\n", err);
35014 +static int au_wbr_copyup_bu(struct dentry *dentry)
35017 + aufs_bindex_t btop;
35019 + btop = au_dbtop(dentry);
35020 + err = au_wbr_do_copyup_bu(dentry, btop);
35024 +/* ---------------------------------------------------------------------- */
35026 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35027 + [AuWbrCopyup_TDP] = {
35028 + .copyup = au_wbr_copyup_tdp
35030 + [AuWbrCopyup_BUP] = {
35031 + .copyup = au_wbr_copyup_bup
35033 + [AuWbrCopyup_BU] = {
35034 + .copyup = au_wbr_copyup_bu
35038 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35039 + [AuWbrCreate_TDP] = {
35040 + .create = au_wbr_create_tdp
35042 + [AuWbrCreate_RR] = {
35043 + .create = au_wbr_create_rr,
35044 + .init = au_wbr_create_init_rr
35046 + [AuWbrCreate_MFS] = {
35047 + .create = au_wbr_create_mfs,
35048 + .init = au_wbr_create_init_mfs,
35049 + .fin = au_wbr_create_fin_mfs
35051 + [AuWbrCreate_MFSV] = {
35052 + .create = au_wbr_create_mfs,
35053 + .init = au_wbr_create_init_mfs,
35054 + .fin = au_wbr_create_fin_mfs
35056 + [AuWbrCreate_MFSRR] = {
35057 + .create = au_wbr_create_mfsrr,
35058 + .init = au_wbr_create_init_mfsrr,
35059 + .fin = au_wbr_create_fin_mfs
35061 + [AuWbrCreate_MFSRRV] = {
35062 + .create = au_wbr_create_mfsrr,
35063 + .init = au_wbr_create_init_mfsrr,
35064 + .fin = au_wbr_create_fin_mfs
35066 + [AuWbrCreate_TDMFS] = {
35067 + .create = au_wbr_create_tdmfs,
35068 + .init = au_wbr_create_init_mfs,
35069 + .fin = au_wbr_create_fin_mfs
35071 + [AuWbrCreate_TDMFSV] = {
35072 + .create = au_wbr_create_tdmfs,
35073 + .init = au_wbr_create_init_mfs,
35074 + .fin = au_wbr_create_fin_mfs
35076 + [AuWbrCreate_PMFS] = {
35077 + .create = au_wbr_create_pmfs,
35078 + .init = au_wbr_create_init_mfs,
35079 + .fin = au_wbr_create_fin_mfs
35081 + [AuWbrCreate_PMFSV] = {
35082 + .create = au_wbr_create_pmfs,
35083 + .init = au_wbr_create_init_mfs,
35084 + .fin = au_wbr_create_fin_mfs
35086 + [AuWbrCreate_PMFSRR] = {
35087 + .create = au_wbr_create_pmfsrr,
35088 + .init = au_wbr_create_init_mfsrr,
35089 + .fin = au_wbr_create_fin_mfs
35091 + [AuWbrCreate_PMFSRRV] = {
35092 + .create = au_wbr_create_pmfsrr,
35093 + .init = au_wbr_create_init_mfsrr,
35094 + .fin = au_wbr_create_fin_mfs
35097 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35098 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35099 +++ linux/fs/aufs/whout.c 2023-09-03 02:21:58.863304341 +0200
35101 +// SPDX-License-Identifier: GPL-2.0
35103 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35105 + * This program is free software; you can redistribute it and/or modify
35106 + * it under the terms of the GNU General Public License as published by
35107 + * the Free Software Foundation; either version 2 of the License, or
35108 + * (at your option) any later version.
35110 + * This program is distributed in the hope that it will be useful,
35111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35113 + * GNU General Public License for more details.
35115 + * You should have received a copy of the GNU General Public License
35116 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35120 + * whiteout for logical deletion and opaque directory
35125 +#define WH_MASK 0444
35128 + * If a directory contains this file, then it is opaque. We start with the
35129 + * .wh. flag so that it is blocked by lookup.
35131 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35132 + sizeof(AUFS_WH_DIROPQ) - 1);
35135 + * generate whiteout name, which is NOT terminated by NULL.
35136 + * @name: original d_name.name
35137 + * @len: original d_name.len
35138 + * @wh: whiteout qstr
35139 + * returns zero when succeeds, otherwise error.
35140 + * succeeded value as wh->name should be freed by kfree().
35142 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35146 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35147 + return -ENAMETOOLONG;
35149 + wh->len = name->len + AUFS_WH_PFX_LEN;
35150 + p = kmalloc(wh->len, GFP_NOFS);
35153 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35154 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35161 +/* ---------------------------------------------------------------------- */
35164 + * test if the @wh_name exists under @h_ppath.
35165 + * @try_sio specifies the necessary of super-io.
35167 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
35168 + struct qstr *wh_name, int try_sio)
35171 + struct dentry *wh_dentry;
35174 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35176 + wh_dentry = au_sio_lkup_one(h_idmap, wh_name, h_ppath);
35177 + err = PTR_ERR(wh_dentry);
35178 + if (IS_ERR(wh_dentry)) {
35179 + if (err == -ENAMETOOLONG)
35185 + if (d_is_negative(wh_dentry))
35186 + goto out_wh; /* success */
35189 + if (d_is_reg(wh_dentry))
35190 + goto out_wh; /* success */
35193 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35194 + wh_dentry, d_inode(wh_dentry)->i_mode);
35203 + * test if the @h_path->dentry sets opaque or not.
35205 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path)
35208 + struct inode *h_dir;
35210 + h_dir = d_inode(h_path->dentry);
35211 + err = au_wh_test(h_idmap, h_path, &diropq_name,
35212 + au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC));
35217 + * returns a negative dentry whose name is unique and temporary.
35219 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35220 + struct qstr *prefix)
35222 + struct dentry *dentry;
35224 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35226 + /* strict atomic_t is unnecessary here */
35227 + static unsigned short cnt;
35229 + struct path h_ppath;
35230 + struct mnt_idmap *h_idmap;
35232 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35235 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35236 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35237 + dentry = ERR_PTR(-ENAMETOOLONG);
35238 + if (unlikely(qs.len > NAME_MAX))
35240 + dentry = ERR_PTR(-ENOMEM);
35241 + name = kmalloc(qs.len + 1, GFP_NOFS);
35242 + if (unlikely(!name))
35246 + /* doubly whiteout-ed */
35247 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35248 + p = name + AUFS_WH_PFX_LEN * 2;
35249 + memcpy(p, prefix->name, prefix->len);
35250 + p += prefix->len;
35252 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35254 + h_ppath.dentry = h_parent;
35255 + h_ppath.mnt = au_br_mnt(br);
35256 + h_idmap = au_br_idmap(br);
35258 + for (i = 0; i < 3; i++) {
35259 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35260 + dentry = au_sio_lkup_one(h_idmap, &qs, &h_ppath);
35261 + if (IS_ERR(dentry) || d_is_negative(dentry))
35265 + /* pr_warn("could not get random name\n"); */
35266 + dentry = ERR_PTR(-EEXIST);
35267 + AuDbg("%.*s\n", AuLNPair(&qs));
35271 + if (name != defname)
35272 + au_kfree_try_rcu(name);
35274 + AuTraceErrPtr(dentry);
35279 + * rename the @h_dentry on @br to the whiteouted temporary name.
35281 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35284 + struct path h_path = {
35285 + .mnt = au_br_mnt(br)
35287 + struct inode *h_dir, *delegated;
35288 + struct dentry *h_parent;
35290 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35291 + h_dir = d_inode(h_parent);
35292 + IMustLock(h_dir);
35294 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35295 + err = PTR_ERR(h_path.dentry);
35296 + if (IS_ERR(h_path.dentry))
35299 + /* under the same dir, no need to lock_rename() */
35300 + delegated = NULL;
35301 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35304 + if (unlikely(err == -EWOULDBLOCK)) {
35305 + pr_warn("cannot retry for NFSv4 delegation"
35306 + " for an internal rename\n");
35309 + dput(h_path.dentry);
35316 +/* ---------------------------------------------------------------------- */
35318 + * functions for removing a whiteout
35321 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35324 + struct inode *delegated;
35327 + * forces superio when the dir has a sticky bit.
35328 + * this may be a violation of unix fs semantics.
35330 + force = (h_dir->i_mode & S_ISVTX)
35331 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35332 + delegated = NULL;
35333 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35334 + if (unlikely(err == -EWOULDBLOCK)) {
35335 + pr_warn("cannot retry for NFSv4 delegation"
35336 + " for an internal unlink\n");
35342 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35343 + struct dentry *dentry)
35347 + err = do_unlink_wh(h_dir, h_path);
35348 + if (!err && dentry)
35349 + au_set_dbwh(dentry, -1);
35354 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35357 + struct path h_path;
35360 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35361 + if (IS_ERR(h_path.dentry))
35362 + err = PTR_ERR(h_path.dentry);
35364 + if (d_is_reg(h_path.dentry)) {
35365 + h_path.mnt = h_ppath->mnt;
35366 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35368 + dput(h_path.dentry);
35374 +/* ---------------------------------------------------------------------- */
35376 + * initialize/clean whiteout for a branch
35379 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35383 + struct inode *delegated;
35385 + if (d_is_negative(whpath->dentry))
35389 + err = vfsub_rmdir(h_dir, whpath);
35391 + delegated = NULL;
35392 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35393 + if (unlikely(err == -EWOULDBLOCK)) {
35394 + pr_warn("cannot retry for NFSv4 delegation"
35395 + " for an internal unlink\n");
35399 + if (unlikely(err))
35400 + pr_warn("failed removing %pd (%d), ignored.\n",
35401 + whpath->dentry, err);
35404 +static int test_linkable(struct dentry *h_root)
35406 + struct inode *h_dir = d_inode(h_root);
35408 + if (h_dir->i_op->link)
35411 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35412 + h_root, au_sbtype(h_root->d_sb));
35413 + return -ENOSYS; /* the branch doesn't have its ->link() */
35416 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35417 +static int au_whdir(struct inode *h_dir, struct path *path)
35422 + if (d_is_negative(path->dentry)) {
35425 + if (au_test_nfs(path->dentry->d_sb))
35427 + err = vfsub_mkdir(h_dir, path, mode);
35428 + } else if (d_is_dir(path->dentry))
35431 + pr_err("unknown %pd exists\n", path->dentry);
35436 +struct au_wh_base {
35437 + const struct qstr *name;
35438 + struct dentry *dentry;
35441 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35442 + struct path *h_path)
35444 + h_path->dentry = base[AuBrWh_BASE].dentry;
35445 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35446 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35447 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35448 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35449 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35453 + * returns tri-state,
35454 + * minus: error, caller should print the message
35456 + * plus: error, caller should NOT print the message
35458 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35459 + int do_plink, struct au_wh_base base[],
35460 + struct path *h_path)
35463 + struct inode *h_dir;
35465 + h_dir = d_inode(h_root);
35466 + h_path->dentry = base[AuBrWh_BASE].dentry;
35467 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35468 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35470 + err = test_linkable(h_root);
35471 + if (unlikely(err)) {
35476 + err = au_whdir(h_dir, h_path);
35477 + if (unlikely(err))
35479 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35481 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35482 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35483 + err = au_whdir(h_dir, h_path);
35484 + if (unlikely(err))
35486 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35493 + * for the moment, aufs supports the branch filesystem which does not support
35494 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35495 + * copyup failed. finally, such filesystem will not be used as the writable
35498 + * returns tri-state, see above.
35500 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35501 + int do_plink, struct au_wh_base base[],
35502 + struct path *h_path)
35505 + struct inode *h_dir;
35507 + WbrWhMustWriteLock(wbr);
35509 + err = test_linkable(h_root);
35510 + if (unlikely(err)) {
35516 + * todo: should this create be done in /sbin/mount.aufs helper?
35519 + h_dir = d_inode(h_root);
35520 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35521 + h_path->dentry = base[AuBrWh_BASE].dentry;
35522 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35523 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35526 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35527 + if (unlikely(err))
35530 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35532 + err = au_whdir(h_dir, h_path);
35533 + if (unlikely(err))
35535 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35537 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35538 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35540 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35541 + err = au_whdir(h_dir, h_path);
35542 + if (unlikely(err))
35544 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35551 + * initialize the whiteout base file/dir for @br.
35553 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35556 + const unsigned char do_plink
35557 + = !!au_opt_test(au_mntflags(sb), PLINK);
35558 + struct inode *h_dir;
35559 + struct path path = br->br_path;
35560 + struct dentry *h_root = path.dentry;
35561 + struct au_wbr *wbr = br->br_wbr;
35562 + static const struct qstr base_name[] = {
35563 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35564 + sizeof(AUFS_BASE_NAME) - 1),
35565 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35566 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35567 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35568 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35570 + struct au_wh_base base[] = {
35571 + [AuBrWh_BASE] = {
35572 + .name = base_name + AuBrWh_BASE,
35575 + [AuBrWh_PLINK] = {
35576 + .name = base_name + AuBrWh_PLINK,
35579 + [AuBrWh_ORPH] = {
35580 + .name = base_name + AuBrWh_ORPH,
35586 + WbrWhMustWriteLock(wbr);
35588 + for (i = 0; i < AuBrWh_Last; i++) {
35589 + /* doubly whiteouted */
35590 + struct dentry *d;
35592 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35593 + err = PTR_ERR(d);
35597 + base[i].dentry = d;
35599 + && wbr->wbr_wh[i]
35600 + && wbr->wbr_wh[i] != base[i].dentry);
35604 + for (i = 0; i < AuBrWh_Last; i++) {
35605 + dput(wbr->wbr_wh[i]);
35606 + wbr->wbr_wh[i] = NULL;
35610 + if (!au_br_writable(br->br_perm)) {
35611 + h_dir = d_inode(h_root);
35612 + au_wh_init_ro(h_dir, base, &path);
35613 + } else if (!au_br_wh_linkable(br->br_perm)) {
35614 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35620 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35626 + goto out; /* success */
35629 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35630 + err, h_root, au_sbtype(h_root->d_sb));
35632 + for (i = 0; i < AuBrWh_Last; i++)
35633 + dput(base[i].dentry);
35637 +/* ---------------------------------------------------------------------- */
35639 + * whiteouts are all hard-linked usually.
35640 + * when its link count reaches a ceiling, we create a new whiteout base
35641 + * asynchronously.
35644 +struct reinit_br_wh {
35645 + struct super_block *sb;
35646 + struct au_branch *br;
35649 +static void reinit_br_wh(void *arg)
35652 + aufs_bindex_t bindex;
35653 + struct path h_path;
35654 + struct reinit_br_wh *a = arg;
35655 + struct au_wbr *wbr;
35656 + struct inode *dir, *delegated;
35657 + struct dentry *h_root;
35658 + struct au_hinode *hdir;
35661 + wbr = a->br->br_wbr;
35662 + /* big aufs lock */
35663 + si_noflush_write_lock(a->sb);
35664 + if (!au_br_writable(a->br->br_perm))
35666 + bindex = au_br_index(a->sb, a->br->br_id);
35667 + if (unlikely(bindex < 0))
35670 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35671 + dir = d_inode(a->sb->s_root);
35672 + hdir = au_hi(dir, bindex);
35673 + h_root = au_h_dptr(a->sb->s_root, bindex);
35674 + AuDebugOn(h_root != au_br_dentry(a->br));
35676 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35677 + wbr_wh_write_lock(wbr);
35678 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35681 + h_path.dentry = wbr->wbr_whbase;
35682 + h_path.mnt = au_br_mnt(a->br);
35683 + delegated = NULL;
35684 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35686 + if (unlikely(err == -EWOULDBLOCK)) {
35687 + pr_warn("cannot retry for NFSv4 delegation"
35688 + " for an internal unlink\n");
35692 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35695 + dput(wbr->wbr_whbase);
35696 + wbr->wbr_whbase = NULL;
35698 + err = au_wh_init(a->br, a->sb);
35699 + wbr_wh_write_unlock(wbr);
35700 + au_hn_inode_unlock(hdir);
35701 + di_read_unlock(a->sb->s_root, AuLock_IR);
35703 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35707 + atomic_dec(&wbr->wbr_wh_running);
35708 + au_lcnt_dec(&a->br->br_count);
35709 + si_write_unlock(a->sb);
35710 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35712 + if (unlikely(err))
35713 + AuIOErr("err %d\n", err);
35716 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35718 + int do_dec, wkq_err;
35719 + struct reinit_br_wh *arg;
35722 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35725 + /* ignore ENOMEM */
35726 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35729 + * dec(wh_running), kfree(arg) and dec(br_count)
35730 + * in reinit function
35734 + au_lcnt_inc(&br->br_count);
35735 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35736 + if (unlikely(wkq_err)) {
35737 + atomic_dec(&br->br_wbr->wbr_wh_running);
35738 + au_lcnt_dec(&br->br_count);
35739 + au_kfree_rcu(arg);
35746 + atomic_dec(&br->br_wbr->wbr_wh_running);
35749 +/* ---------------------------------------------------------------------- */
35752 + * create the whiteout @wh.
35754 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35755 + struct dentry *wh)
35758 + struct path h_path = {
35761 + struct au_branch *br;
35762 + struct au_wbr *wbr;
35763 + struct dentry *h_parent;
35764 + struct inode *h_dir, *delegated;
35766 + h_parent = wh->d_parent; /* dir inode is locked */
35767 + h_dir = d_inode(h_parent);
35768 + IMustLock(h_dir);
35770 + br = au_sbr(sb, bindex);
35771 + h_path.mnt = au_br_mnt(br);
35772 + wbr = br->br_wbr;
35773 + wbr_wh_read_lock(wbr);
35774 + if (wbr->wbr_whbase) {
35775 + delegated = NULL;
35776 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35777 + if (unlikely(err == -EWOULDBLOCK)) {
35778 + pr_warn("cannot retry for NFSv4 delegation"
35779 + " for an internal link\n");
35782 + if (!err || err != -EMLINK)
35785 + /* link count full. re-initialize br_whbase. */
35786 + kick_reinit_br_wh(sb, br);
35789 + /* return this error in this context */
35790 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35792 + au_fhsm_wrote(sb, bindex, /*force*/0);
35795 + wbr_wh_read_unlock(wbr);
35799 +/* ---------------------------------------------------------------------- */
35802 + * create or remove the diropq.
35804 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35805 + unsigned int flags)
35807 + struct dentry *opq_dentry;
35808 + struct super_block *sb;
35809 + struct au_branch *br;
35810 + struct path h_path;
35813 + sb = dentry->d_sb;
35814 + br = au_sbr(sb, bindex);
35815 + h_path.dentry = au_h_dptr(dentry, bindex);
35816 + h_path.mnt = au_br_mnt(br);
35817 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35818 + if (IS_ERR(opq_dentry))
35821 + if (au_ftest_diropq(flags, CREATE)) {
35822 + err = link_or_create_wh(sb, bindex, opq_dentry);
35824 + au_set_dbdiropq(dentry, bindex);
35825 + goto out; /* success */
35828 + h_path.dentry = opq_dentry;
35829 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35831 + au_set_dbdiropq(dentry, -1);
35833 + dput(opq_dentry);
35834 + opq_dentry = ERR_PTR(err);
35837 + return opq_dentry;
35840 +struct do_diropq_args {
35841 + struct dentry **errp;
35842 + struct dentry *dentry;
35843 + aufs_bindex_t bindex;
35844 + unsigned int flags;
35847 +static void call_do_diropq(void *args)
35849 + struct do_diropq_args *a = args;
35850 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35853 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35854 + unsigned int flags)
35856 + struct dentry *diropq, *h_dentry;
35857 + struct mnt_idmap *h_idmap;
35859 + h_idmap = au_sbr_idmap(dentry->d_sb, bindex);
35860 + h_dentry = au_h_dptr(dentry, bindex);
35861 + if (!au_test_h_perm_sio(h_idmap, d_inode(h_dentry),
35862 + MAY_EXEC | MAY_WRITE))
35863 + diropq = do_diropq(dentry, bindex, flags);
35866 + struct do_diropq_args args = {
35868 + .dentry = dentry,
35869 + .bindex = bindex,
35873 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35874 + if (unlikely(wkq_err))
35875 + diropq = ERR_PTR(wkq_err);
35881 +/* ---------------------------------------------------------------------- */
35884 + * lookup whiteout dentry.
35885 + * @h_parent: lower parent dentry which must exist and be locked
35886 + * @base_name: name of dentry which will be whiteouted
35887 + * returns dentry for whiteout.
35889 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35890 + struct au_branch *br)
35893 + struct qstr wh_name;
35894 + struct dentry *wh_dentry;
35895 + struct path h_path;
35897 + err = au_wh_name_alloc(&wh_name, base_name);
35898 + wh_dentry = ERR_PTR(err);
35900 + h_path.dentry = h_parent;
35901 + h_path.mnt = au_br_mnt(br);
35902 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35903 + au_kfree_try_rcu(wh_name.name);
35905 + return wh_dentry;
35909 + * link/create a whiteout for @dentry on @bindex.
35911 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35912 + struct dentry *h_parent)
35914 + struct dentry *wh_dentry;
35915 + struct super_block *sb;
35918 + sb = dentry->d_sb;
35919 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35920 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35921 + err = link_or_create_wh(sb, bindex, wh_dentry);
35923 + au_set_dbwh(dentry, bindex);
35924 + au_fhsm_wrote(sb, bindex, /*force*/0);
35927 + wh_dentry = ERR_PTR(err);
35931 + return wh_dentry;
35934 +/* ---------------------------------------------------------------------- */
35936 +/* Delete all whiteouts in this directory on branch bindex. */
35937 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35938 + aufs_bindex_t bindex)
35941 + unsigned long ul, n;
35942 + struct qstr wh_name;
35944 + struct hlist_head *head;
35945 + struct au_vdir_wh *pos;
35946 + struct au_vdir_destr *str;
35949 + p = (void *)__get_free_page(GFP_NOFS);
35950 + wh_name.name = p;
35951 + if (unlikely(!wh_name.name))
35955 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35956 + p += AUFS_WH_PFX_LEN;
35957 + n = whlist->nh_num;
35958 + head = whlist->nh_head;
35959 + for (ul = 0; !err && ul < n; ul++, head++) {
35960 + hlist_for_each_entry(pos, head, wh_hash) {
35961 + if (pos->wh_bindex != bindex)
35964 + str = &pos->wh_str;
35965 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35966 + memcpy(p, str->name, str->len);
35967 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35968 + err = unlink_wh_name(h_path, &wh_name);
35973 + AuIOErr("whiteout name too long %.*s\n",
35974 + str->len, str->name);
35979 + free_page((unsigned long)wh_name.name);
35985 +struct del_wh_children_args {
35987 + struct path *h_path;
35988 + struct au_nhash *whlist;
35989 + aufs_bindex_t bindex;
35992 +static void call_del_wh_children(void *args)
35994 + struct del_wh_children_args *a = args;
35995 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
35998 +/* ---------------------------------------------------------------------- */
36000 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
36002 + struct au_whtmp_rmdir *whtmp;
36004 + unsigned int rdhash;
36006 + SiMustAnyLock(sb);
36008 + whtmp = kzalloc(sizeof(*whtmp), gfp);
36009 + if (unlikely(!whtmp)) {
36010 + whtmp = ERR_PTR(-ENOMEM);
36014 + /* no estimation for dir size */
36015 + rdhash = au_sbi(sb)->si_rdhash;
36017 + rdhash = AUFS_RDHASH_DEF;
36018 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
36019 + if (unlikely(err)) {
36020 + au_kfree_rcu(whtmp);
36021 + whtmp = ERR_PTR(err);
36028 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36031 + au_lcnt_dec(&whtmp->br->br_count);
36032 + dput(whtmp->wh_dentry);
36033 + iput(whtmp->dir);
36034 + au_nhash_wh_free(&whtmp->whlist);
36035 + au_kfree_rcu(whtmp);
36039 + * rmdir the whiteouted temporary named dir @h_dentry.
36040 + * @whlist: whiteouted children.
36042 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36043 + struct dentry *wh_dentry, struct au_nhash *whlist)
36046 + unsigned int h_nlink;
36047 + struct path wh_path;
36048 + struct inode *wh_inode, *h_dir;
36049 + struct au_branch *br;
36050 + struct mnt_idmap *h_idmap;
36052 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36053 + IMustLock(h_dir);
36055 + br = au_sbr(dir->i_sb, bindex);
36056 + wh_path.dentry = wh_dentry;
36057 + wh_path.mnt = au_br_mnt(br);
36058 + h_idmap = au_br_idmap(br);
36059 + wh_inode = d_inode(wh_dentry);
36060 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36063 + * someone else might change some whiteouts while we were sleeping.
36064 + * it means this whlist may have an obsoleted entry.
36066 + if (!au_test_h_perm_sio(h_idmap, wh_inode, MAY_EXEC | MAY_WRITE))
36067 + err = del_wh_children(&wh_path, whlist, bindex);
36070 + struct del_wh_children_args args = {
36072 + .h_path = &wh_path,
36073 + .whlist = whlist,
36077 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36078 + if (unlikely(wkq_err))
36081 + inode_unlock(wh_inode);
36084 + h_nlink = h_dir->i_nlink;
36085 + err = vfsub_rmdir(h_dir, &wh_path);
36086 + /* some fs doesn't change the parent nlink in some cases */
36087 + h_nlink -= h_dir->i_nlink;
36091 + if (au_ibtop(dir) == bindex) {
36092 + /* todo: dir->i_mutex is necessary */
36093 + au_cpup_attr_timesizes(dir);
36095 + vfsub_drop_nlink(dir);
36097 + return 0; /* success */
36100 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36104 +static void call_rmdir_whtmp(void *args)
36107 + aufs_bindex_t bindex;
36108 + struct au_whtmp_rmdir *a = args;
36109 + struct super_block *sb;
36110 + struct dentry *h_parent;
36111 + struct inode *h_dir;
36112 + struct au_hinode *hdir;
36114 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36115 + /* inode_lock(a->dir); */
36117 + sb = a->dir->i_sb;
36118 + si_read_lock(sb, !AuLock_FLUSH);
36119 + if (!au_br_writable(a->br->br_perm))
36121 + bindex = au_br_index(sb, a->br->br_id);
36122 + if (unlikely(bindex < 0))
36126 + ii_write_lock_parent(a->dir);
36127 + h_parent = dget_parent(a->wh_dentry);
36128 + h_dir = d_inode(h_parent);
36129 + hdir = au_hi(a->dir, bindex);
36130 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36131 + if (unlikely(err))
36133 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36134 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36137 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36138 + au_hn_inode_unlock(hdir);
36139 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36143 + ii_write_unlock(a->dir);
36145 + /* inode_unlock(a->dir); */
36146 + au_whtmp_rmdir_free(a);
36147 + si_read_unlock(sb);
36148 + au_nwt_done(&au_sbi(sb)->si_nowait);
36149 + if (unlikely(err))
36150 + AuIOErr("err %d\n", err);
36153 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36154 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36157 + struct super_block *sb;
36161 + /* all post-process will be done in do_rmdir_whtmp(). */
36163 + args->dir = au_igrab(dir);
36164 + args->br = au_sbr(sb, bindex);
36165 + au_lcnt_inc(&args->br->br_count);
36166 + args->wh_dentry = dget(wh_dentry);
36167 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36168 + if (unlikely(wkq_err)) {
36169 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36170 + au_whtmp_rmdir_free(args);
36173 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36174 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36175 +++ linux/fs/aufs/whout.h 2023-09-03 02:21:58.863304341 +0200
36177 +/* SPDX-License-Identifier: GPL-2.0 */
36179 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36181 + * This program is free software; you can redistribute it and/or modify
36182 + * it under the terms of the GNU General Public License as published by
36183 + * the Free Software Foundation; either version 2 of the License, or
36184 + * (at your option) any later version.
36186 + * This program is distributed in the hope that it will be useful,
36187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36189 + * GNU General Public License for more details.
36191 + * You should have received a copy of the GNU General Public License
36192 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36196 + * whiteout for logical deletion and opaque directory
36199 +#ifndef __AUFS_WHOUT_H__
36200 +#define __AUFS_WHOUT_H__
36207 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36208 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
36209 + struct qstr *wh_name, int try_sio);
36210 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path);
36212 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36213 + struct qstr *prefix);
36214 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36215 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36216 + struct dentry *dentry);
36217 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36219 +/* diropq flags */
36220 +#define AuDiropq_CREATE 1
36221 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36222 +#define au_fset_diropq(flags, name) \
36223 + do { (flags) |= AuDiropq_##name; } while (0)
36224 +#define au_fclr_diropq(flags, name) \
36225 + do { (flags) &= ~AuDiropq_##name; } while (0)
36227 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36228 + unsigned int flags);
36229 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36230 + struct au_branch *br);
36231 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36232 + struct dentry *h_parent);
36234 +/* real rmdir for the whiteout-ed dir */
36235 +struct au_whtmp_rmdir {
36236 + struct inode *dir;
36237 + struct au_branch *br;
36238 + struct dentry *wh_dentry;
36239 + struct au_nhash whlist;
36242 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36243 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36244 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36245 + struct dentry *wh_dentry, struct au_nhash *whlist);
36246 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36247 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36249 +/* ---------------------------------------------------------------------- */
36251 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36252 + aufs_bindex_t bindex)
36254 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36257 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36259 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36262 +#endif /* __KERNEL__ */
36263 +#endif /* __AUFS_WHOUT_H__ */
36264 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36265 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36266 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36268 +// SPDX-License-Identifier: GPL-2.0
36270 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36272 + * This program is free software; you can redistribute it and/or modify
36273 + * it under the terms of the GNU General Public License as published by
36274 + * the Free Software Foundation; either version 2 of the License, or
36275 + * (at your option) any later version.
36277 + * This program is distributed in the hope that it will be useful,
36278 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36279 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36280 + * GNU General Public License for more details.
36282 + * You should have received a copy of the GNU General Public License
36283 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36287 + * workqueue for asynchronous/super-io operations
36288 + * todo: try new credential scheme
36291 +#include <linux/module.h>
36294 +/* internal workqueue named AUFS_WKQ_NAME */
36296 +static struct workqueue_struct *au_wkq;
36298 +struct au_wkinfo {
36299 + struct work_struct wk;
36300 + struct kobject *kobj;
36302 + unsigned int flags; /* see wkq.h */
36304 + au_wkq_func_t func;
36307 +#ifdef CONFIG_LOCKDEP
36309 + struct held_lock **hlock;
36312 + struct completion *comp;
36315 +/* ---------------------------------------------------------------------- */
36317 + * Aufs passes some operations to the workqueue such as the internal copyup.
36318 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36319 + * job run by workqueue depends upon the locks acquired in the other task.
36320 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36321 + * information too. And the job in the workqueue restores the info in order to
36322 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36323 + * correctly and expectedly.
36326 +#ifndef CONFIG_LOCKDEP
36327 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36328 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36329 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36330 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36331 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36333 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36335 + wkinfo->hlock = NULL;
36336 + wkinfo->dont_check = 0;
36343 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36345 + static DEFINE_SPINLOCK(spin);
36348 + struct lock_class_key *key;
36350 + { .name = "&sbinfo->si_rwsem" },
36351 + { .name = "&finfo->fi_rwsem" },
36352 + { .name = "&dinfo->di_rwsem" },
36353 + { .name = "&iinfo->ii_rwsem" }
36358 + /* lockless read from 'set.' see below */
36359 + if (set == ARRAY_SIZE(a)) {
36360 + for (i = 0; i < ARRAY_SIZE(a); i++)
36361 + if (a[i].key == key)
36366 + spin_lock(&spin);
36368 + for (i = 0; i < ARRAY_SIZE(a); i++)
36369 + if (a[i].key == key) {
36370 + spin_unlock(&spin);
36373 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36375 + if (unlikely(a[i].key == key)) { /* rare but possible */
36376 + spin_unlock(&spin);
36381 + if (strstr(a[i].name, name)) {
36383 + * the order of these three lines is important for the
36384 + * lockless read above.
36387 + spin_unlock(&spin);
36389 + /* AuDbg("%d, %s\n", set, name); */
36393 + spin_unlock(&spin);
36402 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36405 + struct task_struct *curr;
36406 + struct held_lock **hl, *held_locks, *p;
36410 + wkinfo->dont_check = lockdep_recursing(curr);
36411 + if (wkinfo->dont_check)
36413 + n = curr->lockdep_depth;
36418 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36419 + if (unlikely(!wkinfo->hlock))
36423 +#if 0 /* left for debugging */
36424 + if (0 && au_debug_test())
36425 + lockdep_print_held_locks(curr);
36427 + held_locks = curr->held_locks;
36428 + hl = wkinfo->hlock;
36430 + p = held_locks++;
36431 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36440 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36442 + au_kfree_try_rcu(wkinfo->hlock);
36445 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36447 + struct held_lock *p, **hl = wkinfo->hlock;
36450 + if (wkinfo->dont_check)
36454 + while ((p = *hl++)) { /* assignment */
36455 + subclass = lockdep_hlock_class(p)->subclass;
36456 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36458 + rwsem_acquire_read(p->instance, subclass, 0,
36459 + /*p->acquire_ip*/_RET_IP_);
36461 + rwsem_acquire(p->instance, subclass, 0,
36462 + /*p->acquire_ip*/_RET_IP_);
36466 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36468 + struct held_lock *p, **hl = wkinfo->hlock;
36470 + if (wkinfo->dont_check)
36474 + while ((p = *hl++)) /* assignment */
36475 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36479 +static void wkq_func(struct work_struct *wk)
36481 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36483 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36484 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36486 + au_wkq_lockdep_pre(wkinfo);
36487 + wkinfo->func(wkinfo->args);
36488 + au_wkq_lockdep_post(wkinfo);
36489 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36490 + complete(wkinfo->comp);
36492 + kobject_put(wkinfo->kobj);
36493 + module_put(THIS_MODULE); /* todo: ?? */
36494 + au_kfree_rcu(wkinfo);
36499 + * Since struct completion is large, try allocating it dynamically.
36501 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36503 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36505 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36507 + init_completion(*comp);
36508 + wkinfo->comp = *comp;
36514 +static void au_wkq_comp_free(struct completion *comp)
36516 + au_kfree_rcu(comp);
36519 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36521 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36522 + if (au_wkq_test()) {
36523 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36524 + " due to a dead dir by UDBA,"
36525 + " or async xino write?\n");
36526 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36529 + au_dbg_verify_kthread();
36531 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36532 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36533 + queue_work(au_wkq, &wkinfo->wk);
36535 + INIT_WORK(&wkinfo->wk, wkq_func);
36536 + schedule_work(&wkinfo->wk);
36541 + * Be careful. It is easy to make deadlock happen.
36542 + * processA: lock, wkq and wait
36543 + * processB: wkq and wait, lock in wkq
36546 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36549 + AuWkqCompDeclare(comp);
36550 + struct au_wkinfo wkinfo = {
36556 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36557 + if (unlikely(err))
36559 + err = au_wkq_lockdep_alloc(&wkinfo);
36560 + if (unlikely(err))
36563 + au_wkq_run(&wkinfo);
36564 + /* no timeout, no interrupt */
36565 + wait_for_completion(wkinfo.comp);
36567 + au_wkq_lockdep_free(&wkinfo);
36570 + au_wkq_comp_free(comp);
36572 + destroy_work_on_stack(&wkinfo.wk);
36577 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36578 + * problem in a concurrent umounting.
36580 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36581 + unsigned int flags)
36584 + struct au_wkinfo *wkinfo;
36586 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36589 + * wkq_func() must free this wkinfo.
36590 + * it highly depends upon the implementation of workqueue.
36593 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36595 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36596 + wkinfo->flags = flags & ~AuWkq_WAIT;
36597 + wkinfo->func = func;
36598 + wkinfo->args = args;
36599 + wkinfo->comp = NULL;
36600 + au_wkq_lockdep_init(wkinfo);
36601 + kobject_get(wkinfo->kobj);
36602 + __module_get(THIS_MODULE); /* todo: ?? */
36604 + au_wkq_run(wkinfo);
36607 + au_nwt_done(&au_sbi(sb)->si_nowait);
36613 +/* ---------------------------------------------------------------------- */
36615 +void au_nwt_init(struct au_nowait_tasks *nwt)
36617 + atomic_set(&nwt->nw_len, 0);
36618 + /* smp_mb(); */ /* atomic_set */
36619 + init_waitqueue_head(&nwt->nw_wq);
36622 +void au_wkq_fin(void)
36624 + destroy_workqueue(au_wkq);
36627 +int __init au_wkq_init(void)
36632 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36633 + if (IS_ERR(au_wkq))
36634 + err = PTR_ERR(au_wkq);
36635 + else if (!au_wkq)
36640 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36641 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36642 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36644 +/* SPDX-License-Identifier: GPL-2.0 */
36646 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36648 + * This program is free software; you can redistribute it and/or modify
36649 + * it under the terms of the GNU General Public License as published by
36650 + * the Free Software Foundation; either version 2 of the License, or
36651 + * (at your option) any later version.
36653 + * This program is distributed in the hope that it will be useful,
36654 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36655 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36656 + * GNU General Public License for more details.
36658 + * You should have received a copy of the GNU General Public License
36659 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36663 + * workqueue for asynchronous/super-io operations
36664 + * todo: try new credentials management scheme
36667 +#ifndef __AUFS_WKQ_H__
36668 +#define __AUFS_WKQ_H__
36672 +#include <linux/wait.h>
36674 +struct super_block;
36676 +/* ---------------------------------------------------------------------- */
36679 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36681 +struct au_nowait_tasks {
36683 + wait_queue_head_t nw_wq;
36686 +/* ---------------------------------------------------------------------- */
36688 +typedef void (*au_wkq_func_t)(void *args);
36691 +#define AuWkq_WAIT 1
36692 +#define AuWkq_NEST (1 << 1)
36693 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36694 +#define au_fset_wkq(flags, name) \
36695 + do { (flags) |= AuWkq_##name; } while (0)
36696 +#define au_fclr_wkq(flags, name) \
36697 + do { (flags) &= ~AuWkq_##name; } while (0)
36700 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36701 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36702 + unsigned int flags);
36703 +void au_nwt_init(struct au_nowait_tasks *nwt);
36704 +int __init au_wkq_init(void);
36705 +void au_wkq_fin(void);
36707 +/* ---------------------------------------------------------------------- */
36709 +static inline int au_wkq_test(void)
36711 + return current->flags & PF_WQ_WORKER;
36714 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36716 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36719 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36721 + if (atomic_dec_and_test(&nwt->nw_len))
36722 + wake_up_all(&nwt->nw_wq);
36725 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36727 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36731 +#endif /* __KERNEL__ */
36732 +#endif /* __AUFS_WKQ_H__ */
36733 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36734 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36735 +++ linux/fs/aufs/xattr.c 2023-09-03 02:21:58.863304341 +0200
36737 +// SPDX-License-Identifier: GPL-2.0
36739 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36741 + * This program is free software; you can redistribute it and/or modify
36742 + * it under the terms of the GNU General Public License as published by
36743 + * the Free Software Foundation; either version 2 of the License, or
36744 + * (at your option) any later version.
36746 + * This program is distributed in the hope that it will be useful,
36747 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36748 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36749 + * GNU General Public License for more details.
36751 + * You should have received a copy of the GNU General Public License
36752 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36756 + * handling xattr functions
36759 +#include <linux/fs.h>
36760 +#include <linux/xattr.h>
36763 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36765 + if (!ignore_flags)
36773 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36778 +#define cmp(brattr, prefix) do { \
36779 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36780 + XATTR_##prefix##_PREFIX_LEN)) { \
36781 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36787 + cmp(SEC, SECURITY);
36788 + cmp(SYS, SYSTEM);
36789 + cmp(TR, TRUSTED);
36793 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36800 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36802 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36803 + char *name, char **buf, unsigned int ignore_flags,
36804 + unsigned int verbose)
36808 + struct inode *h_idst;
36809 + struct dentry *h_dst_dentry, *h_src_dentry;
36810 + struct mnt_idmap *h_dst_idmap, *h_src_idmap;
36811 + struct posix_acl *acl;
36813 + is_acl = !!is_posix_acl_xattr(name);
36814 + h_src_idmap = mnt_idmap(h_src->mnt);
36815 + h_src_dentry = h_src->dentry;
36817 + acl = vfs_get_acl(h_src_idmap, h_src_dentry, name);
36819 + if (unlikely(IS_ERR(acl))) {
36820 + err = PTR_ERR(acl);
36821 + if (err == -ENODATA)
36823 + else if (err == -EOPNOTSUPP
36824 + && au_test_nfs_noacl(d_inode(h_src_dentry)))
36826 + else if (verbose || au_debug_test())
36827 + pr_err("%s, err %d\n", name, err);
36831 + ssz = vfs_getxattr_alloc(h_src_idmap, h_src_dentry, name, buf,
36833 + if (unlikely(ssz <= 0)) {
36835 + if (err == -ENODATA)
36837 + else if (err == -EOPNOTSUPP
36838 + && (ignore_flags & au_xattr_out_of_list))
36840 + else if (err && (verbose || au_debug_test()))
36841 + pr_err("%s, err %d\n", name, err);
36846 + /* unlock it temporary */
36847 + h_dst_idmap = mnt_idmap(h_dst->mnt);
36848 + h_dst_dentry = h_dst->dentry;
36849 + h_idst = d_inode(h_dst_dentry);
36850 + inode_unlock(h_idst);
36852 + err = vfsub_set_acl(h_dst_idmap, h_dst_dentry, name, acl);
36853 + posix_acl_release(acl);
36855 + err = vfsub_setxattr(h_dst_idmap, h_dst_dentry, name, *buf,
36856 + ssz, /*flags*/0);
36857 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36858 + if (unlikely(err)) {
36859 + if (verbose || au_debug_test())
36860 + pr_err("%s, err %d\n", name, err);
36861 + err = au_xattr_ignore(err, name, ignore_flags);
36868 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36869 + unsigned int verbose)
36871 + int err, unlocked;
36873 + struct dentry *h_dst_dentry, *h_src_dentry;
36874 + struct inode *h_isrc, *h_idst;
36875 + char *value, *p, *o, *e;
36877 + /* try stopping to update the source inode while we are referencing */
36878 + /* there should not be the parent-child relationship between them */
36879 + h_dst_dentry = h_dst->dentry;
36880 + h_idst = d_inode(h_dst_dentry);
36881 + h_src_dentry = h_src->dentry;
36882 + h_isrc = d_inode(h_src_dentry);
36883 + inode_unlock(h_idst);
36884 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36885 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36888 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36889 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36891 + if (unlikely(err < 0)) {
36893 + if (err == -ENODATA
36894 + || err == -EOPNOTSUPP)
36895 + err = 0; /* ignore */
36904 + p = kmalloc(ssz, GFP_NOFS);
36906 + if (unlikely(!p))
36908 + err = vfs_listxattr(h_src_dentry, p, ssz);
36910 + inode_unlock_shared(h_isrc);
36912 + AuDbg("err %d, ssz %zd\n", err, ssz);
36913 + if (unlikely(err < 0))
36919 + ignore_flags |= au_xattr_out_of_list;
36920 + while (!err && p < e) {
36921 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36923 + p += strlen(p) + 1;
36925 + au_kfree_try_rcu(value);
36928 + au_kfree_try_rcu(o);
36931 + inode_unlock_shared(h_isrc);
36936 +/* ---------------------------------------------------------------------- */
36938 +static int au_smack_reentering(struct super_block *sb)
36940 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36942 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36943 + * i_op->getxattr(). ouch.
36945 + return si_pid_test(sb);
36956 +struct au_lgxattr {
36964 + const char *name;
36971 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36972 + struct au_lgxattr *arg)
36976 + struct path h_path;
36977 + struct super_block *sb;
36979 + sb = dentry->d_sb;
36980 + reenter = au_smack_reentering(sb);
36982 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36983 + if (unlikely(err))
36986 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36987 + if (unlikely(err))
36989 + if (unlikely(!h_path.dentry))
36990 + /* illegally overlapped or something */
36991 + goto out_di; /* pretending success */
36993 + /* always topmost entry only */
36994 + switch (arg->type) {
36995 + case AU_XATTR_LIST:
36996 + err = vfs_listxattr(h_path.dentry,
36997 + arg->u.list.list, arg->u.list.size);
36999 + case AU_XATTR_GET:
37000 + AuDebugOn(d_is_negative(h_path.dentry));
37001 + err = vfs_getxattr(mnt_idmap(h_path.mnt), h_path.dentry,
37002 + arg->u.get.name, arg->u.get.value,
37003 + arg->u.get.size);
37009 + di_read_unlock(dentry, AuLock_IR);
37012 + si_read_unlock(sb);
37018 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37020 + struct au_lgxattr arg = {
37021 + .type = AU_XATTR_LIST,
37028 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37031 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37032 + const char *name, void *value, size_t size)
37034 + struct au_lgxattr arg = {
37035 + .type = AU_XATTR_GET,
37043 + return au_lgxattr(dentry, inode, &arg);
37046 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37047 + const char *name, const void *value, size_t size,
37050 + struct au_sxattr arg = {
37051 + .type = AU_XATTR_SET,
37060 + return au_sxattr(dentry, inode, &arg);
37063 +/* ---------------------------------------------------------------------- */
37065 +static int au_xattr_get(const struct xattr_handler *handler,
37066 + struct dentry *dentry, struct inode *inode,
37067 + const char *name, void *buffer, size_t size)
37069 + return au_getxattr(dentry, inode, name, buffer, size);
37072 +static int au_xattr_set(const struct xattr_handler *handler,
37073 + struct mnt_idmap *idmap,
37074 + struct dentry *dentry, struct inode *inode,
37075 + const char *name, const void *value, size_t size,
37078 + return au_setxattr(dentry, inode, name, value, size, flags);
37081 +static const struct xattr_handler au_xattr_handler = {
37084 + .get = au_xattr_get,
37085 + .set = au_xattr_set
37088 +static const struct xattr_handler *au_xattr_handlers[] = {
37089 + &au_xattr_handler, /* must be last */
37093 +void au_xattr_init(struct super_block *sb)
37095 + sb->s_xattr = au_xattr_handlers;
37097 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37098 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37099 +++ linux/fs/aufs/xino.c 2023-09-03 02:21:58.863304341 +0200
37101 +// SPDX-License-Identifier: GPL-2.0
37103 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37105 + * This program is free software; you can redistribute it and/or modify
37106 + * it under the terms of the GNU General Public License as published by
37107 + * the Free Software Foundation; either version 2 of the License, or
37108 + * (at your option) any later version.
37110 + * This program is distributed in the hope that it will be useful,
37111 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37112 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37113 + * GNU General Public License for more details.
37115 + * You should have received a copy of the GNU General Public License
37116 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37120 + * external inode number translation table and bitmap
37122 + * things to consider
37124 + * + au_xino object
37125 + * + XINO files (xino, xib, xigen)
37126 + * + dynamic debugfs entries (xiN)
37127 + * + static debugfs entries (xib, xigen)
37128 + * + static sysfs entry (xi_path)
37129 + * - several entry points to handle them.
37130 + * + mount(2) without xino option (default)
37131 + * + mount(2) with xino option
37132 + * + mount(2) with noxino option
37134 + * + remount with add/del branches
37135 + * + remount with xino/noxino options
37138 +#include <linux/seq_file.h>
37139 +#include <linux/statfs.h>
37142 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37143 + aufs_bindex_t bbot,
37144 + struct super_block *h_sb)
37146 + /* todo: try binary-search if the branches are many */
37147 + for (; btop <= bbot; btop++)
37148 + if (h_sb == au_sbr_sb(sb, btop))
37154 + * find another branch who is on the same filesystem of the specified
37155 + * branch{@btgt}. search until @bbot.
37157 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37158 + aufs_bindex_t bbot)
37160 + aufs_bindex_t bindex;
37161 + struct super_block *tgt_sb;
37163 + tgt_sb = au_sbr_sb(sb, btgt);
37164 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37166 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37171 +/* ---------------------------------------------------------------------- */
37174 + * stop unnecessary notify events at creating xino files
37177 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37179 + aufs_bindex_t bfound, bindex, bbot;
37180 + struct dentry *parent;
37181 + struct au_branch *br;
37184 + parent = dentry->d_parent; /* safe d_parent access */
37185 + bbot = au_sbbot(sb);
37186 + for (bindex = 0; bindex <= bbot; bindex++) {
37187 + br = au_sbr(sb, bindex);
37188 + if (au_br_dentry(br) == parent) {
37194 + AuDbg("bfound b%d\n", bfound);
37198 +struct au_xino_lock_dir {
37199 + struct au_hinode *hdir;
37200 + struct dentry *parent;
37201 + struct inode *dir;
37204 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37205 + unsigned int lsc)
37207 + struct dentry *parent;
37208 + struct inode *dir;
37210 + parent = dget_parent(dentry);
37211 + dir = d_inode(parent);
37212 + inode_lock_nested(dir, lsc);
37213 +#if 0 /* it should not happen */
37214 + spin_lock(&dentry->d_lock);
37215 + if (unlikely(dentry->d_parent != parent)) {
37216 + spin_unlock(&dentry->d_lock);
37217 + inode_unlock(dir);
37222 + spin_unlock(&dentry->d_lock);
37229 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37230 + struct au_xino_lock_dir *ldir)
37232 + aufs_bindex_t bindex;
37234 + ldir->hdir = NULL;
37235 + bindex = au_xi_root(sb, xipath->dentry);
37236 + if (bindex >= 0) {
37237 + /* rw branch root */
37238 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37239 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37242 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37244 + ldir->dir = d_inode(ldir->parent);
37248 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37251 + au_hn_inode_unlock(ldir->hdir);
37253 + inode_unlock(ldir->dir);
37254 + dput(ldir->parent);
37258 +/* ---------------------------------------------------------------------- */
37261 + * create and set a new xino file
37263 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37266 + struct file *file;
37267 + struct dentry *h_parent, *d;
37268 + struct inode *h_dir, *inode;
37270 + static DEFINE_MUTEX(mtx);
37273 + * at mount-time, and the xino file is the default path,
37274 + * hnotify is disabled so we have no notify events to ignore.
37275 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37278 + mutex_lock(&mtx);
37279 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37280 + /* | __FMODE_NONOTIFY */,
37282 + if (IS_ERR(file)) {
37284 + mutex_unlock(&mtx);
37286 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37290 + /* keep file count */
37292 + d = file->f_path.dentry;
37293 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37295 + mutex_unlock(&mtx);
37296 + /* mnt_want_write() is unnecessary here */
37297 + h_dir = d_inode(h_parent);
37298 + inode = file_inode(file);
37299 + /* no delegation since it is just created */
37300 + if (inode->i_nlink)
37301 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37303 + inode_unlock(h_dir);
37305 + if (unlikely(err)) {
37307 + pr_err("unlink %s(%d)\n", fpath, err);
37312 + if (unlikely(sb && sb == d->d_sb)) {
37314 + pr_err("%s must be outside\n", fpath);
37317 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37319 + pr_err("xino doesn't support %s(%s)\n",
37320 + fpath, au_sbtype(d->d_sb));
37323 + return file; /* success */
37327 + file = ERR_PTR(err);
37332 + * create a new xinofile at the same place/path as @base.
37334 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37335 + struct file *copy_src)
37337 + struct file *file;
37338 + struct dentry *dentry;
37339 + struct inode *dir, *delegated;
37340 + struct qstr *name;
37341 + struct path ppath, path;
37342 + int err, do_unlock;
37343 + struct au_xino_lock_dir ldir;
37346 + au_xino_lock_dir(sb, base, &ldir);
37347 + dentry = base->dentry;
37348 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37349 + ppath.mnt = base->mnt;
37350 + dir = d_inode(ppath.dentry);
37353 + name = &dentry->d_name;
37354 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37355 + if (IS_ERR(path.dentry)) {
37356 + file = (void *)path.dentry;
37357 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37361 + /* no need to mnt_want_write() since we call dentry_open() later */
37362 + err = vfs_create(mnt_idmap(base->mnt), dir, path.dentry, 0666, NULL);
37363 + if (unlikely(err)) {
37364 + file = ERR_PTR(err);
37365 + pr_err("%pd create err %d\n", dentry, err);
37369 + path.mnt = base->mnt;
37370 + file = vfsub_dentry_open(&path,
37371 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37372 + /* | __FMODE_NONOTIFY */);
37373 + if (IS_ERR(file)) {
37374 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37378 + delegated = NULL;
37379 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37380 + au_xino_unlock_dir(&ldir);
37382 + if (unlikely(err == -EWOULDBLOCK)) {
37383 + pr_warn("cannot retry for NFSv4 delegation"
37384 + " for an internal unlink\n");
37387 + if (unlikely(err)) {
37388 + pr_err("%pd unlink err %d\n", dentry, err);
37393 + /* no one can touch copy_src xino */
37394 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37395 + if (unlikely(err)) {
37396 + pr_err("%pd copy err %d\n", dentry, err);
37400 + goto out_dput; /* success */
37404 + file = ERR_PTR(err);
37406 + dput(path.dentry);
37409 + au_xino_unlock_dir(&ldir);
37413 +struct file *au_xino_file1(struct au_xino *xi)
37415 + struct file *file;
37416 + unsigned int u, nfile;
37419 + nfile = xi->xi_nfile;
37420 + for (u = 0; u < nfile; u++) {
37421 + file = xi->xi_file[u];
37429 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37440 + if (idx < xi->xi_nfile) {
37441 + f = xi->xi_file[idx];
37445 + p = au_kzrealloc(xi->xi_file,
37446 + sizeof(*xi->xi_file) * xi->xi_nfile,
37447 + sizeof(*xi->xi_file) * (idx + 1),
37448 + GFP_NOFS, /*may_shrink*/0);
37450 + MtxMustLock(&xi->xi_mtx);
37452 + xi->xi_nfile = idx + 1;
37460 + xi->xi_file[idx] = file;
37467 + * if @xinew->xi is not set, then create new xigen file.
37469 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37471 + struct file *file;
37474 + SiMustAnyLock(sb);
37476 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37477 + if (IS_ERR(file)) {
37478 + err = PTR_ERR(file);
37479 + pr_err("%s[%d], err %d\n",
37480 + xinew->xi ? "xino" : "xigen",
37481 + xinew->idx, err);
37486 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37489 + /* todo: make xigen file an array */
37490 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37493 + if (unlikely(err))
37494 + file = ERR_PTR(err);
37500 +/* ---------------------------------------------------------------------- */
37503 + * truncate xino files
37505 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37506 + int idx, struct kstatfs *st)
37510 + struct file *file, *new_xino;
37511 + struct au_xi_new xinew = {
37516 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37517 + file = au_xino_file(xinew.xi, idx);
37521 + xinew.base = &file->f_path;
37522 + err = vfs_statfs(xinew.base, st);
37523 + if (unlikely(err)) {
37524 + AuErr1("statfs err %d, ignored\n", err);
37529 + blocks = file_inode(file)->i_blocks;
37530 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37531 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37533 + xinew.copy_src = file;
37534 + new_xino = au_xi_new(sb, &xinew);
37535 + if (IS_ERR(new_xino)) {
37536 + err = PTR_ERR(new_xino);
37537 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37541 + err = vfs_statfs(&new_xino->f_path, st);
37543 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37544 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37545 + st->f_bfree, st->f_blocks);
37547 + AuErr1("statfs err %d, ignored\n", err);
37555 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37558 + unsigned long jiffy;
37559 + aufs_bindex_t bbot;
37560 + struct kstatfs *st;
37561 + struct au_branch *br;
37562 + struct au_xino *xi;
37565 + st = kmalloc(sizeof(*st), GFP_NOFS);
37566 + if (unlikely(!st))
37570 + bbot = au_sbbot(sb);
37571 + if (unlikely(bindex < 0 || bbot < bindex))
37576 + br = au_sbr(sb, bindex);
37577 + xi = br->br_xino;
37578 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37579 + err = au_xino_do_trunc(sb, bindex, i, st);
37581 + au_sbi(sb)->si_xino_jiffy = jiffy;
37584 + au_kfree_rcu(st);
37589 +struct xino_do_trunc_args {
37590 + struct super_block *sb;
37591 + struct au_branch *br;
37595 +static void xino_do_trunc(void *_args)
37597 + struct xino_do_trunc_args *args = _args;
37598 + struct super_block *sb;
37599 + struct au_branch *br;
37600 + struct inode *dir;
37602 + aufs_bindex_t bindex;
37606 + dir = d_inode(sb->s_root);
37610 + si_noflush_write_lock(sb);
37611 + ii_read_lock_parent(dir);
37612 + bindex = au_br_index(sb, br->br_id);
37613 + err = au_xino_trunc(sb, bindex, idx);
37614 + ii_read_unlock(dir);
37615 + if (unlikely(err))
37616 + pr_warn("err b%d, (%d)\n", bindex, err);
37617 + atomic_dec(&br->br_xino->xi_truncating);
37618 + au_lcnt_dec(&br->br_count);
37619 + si_write_unlock(sb);
37620 + au_nwt_done(&au_sbi(sb)->si_nowait);
37621 + au_kfree_rcu(args);
37625 + * returns the index in the xi_file array whose corresponding file is necessary
37626 + * to truncate, or -1 which means no need to truncate.
37628 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37632 + struct kstatfs st;
37633 + struct au_sbinfo *sbinfo;
37634 + struct au_xino *xi;
37635 + struct file *file;
37637 + /* todo: si_xino_expire and the ratio should be customizable */
37638 + sbinfo = au_sbi(sb);
37639 + if (time_before(jiffies,
37640 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37643 + /* truncation border */
37644 + xi = br->br_xino;
37645 + for (u = 0; u < xi->xi_nfile; u++) {
37646 + file = au_xino_file(xi, u);
37650 + err = vfs_statfs(&file->f_path, &st);
37651 + if (unlikely(err)) {
37652 + AuErr1("statfs err %d, ignored\n", err);
37655 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37656 + >= AUFS_XINO_DEF_TRUNC)
37663 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37666 + struct xino_do_trunc_args *args;
37669 + idx = xino_trunc_test(sb, br);
37673 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37676 + /* lock and kfree() will be called in trunc_xino() */
37677 + args = kmalloc(sizeof(*args), GFP_NOFS);
37678 + if (unlikely(!args)) {
37679 + AuErr1("no memory\n");
37683 + au_lcnt_inc(&br->br_count);
37687 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37689 + return; /* success */
37691 + pr_err("wkq %d\n", wkq_err);
37692 + au_lcnt_dec(&br->br_count);
37693 + au_kfree_rcu(args);
37696 + atomic_dec(&br->br_xino->xi_truncating);
37699 +/* ---------------------------------------------------------------------- */
37701 +struct au_xi_calc {
37706 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37707 + struct au_xi_calc *calc)
37711 + maxent = au_xi_maxent(sb);
37712 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37713 + calc->pos *= sizeof(ino_t);
37716 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37717 + struct au_xi_calc *calc)
37720 + struct file *file;
37721 + struct au_xino *xi = br->br_xino;
37722 + struct au_xi_new xinew = {
37726 + SiMustAnyLock(sb);
37732 + mutex_lock(&xi->xi_mtx);
37733 + file = au_xino_file(xi, calc->idx);
37737 + file = au_xino_file(xi, /*idx*/-1);
37738 + AuDebugOn(!file);
37739 + xinew.idx = calc->idx;
37740 + xinew.base = &file->f_path;
37741 + /* xinew.copy_src = NULL; */
37742 + file = au_xi_new(sb, &xinew);
37743 + if (IS_ERR(file))
37744 + err = PTR_ERR(file);
37747 + mutex_unlock(&xi->xi_mtx);
37752 +struct au_xino_do_new_async_args {
37753 + struct super_block *sb;
37754 + struct au_branch *br;
37755 + struct au_xi_calc calc;
37759 +struct au_xi_writing {
37760 + struct hlist_bl_node node;
37761 + ino_t h_ino, ino;
37764 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37767 +static void au_xino_call_do_new_async(void *args)
37769 + struct au_xino_do_new_async_args *a = args;
37770 + struct au_branch *br;
37771 + struct super_block *sb;
37772 + struct au_sbinfo *sbi;
37773 + struct inode *root;
37774 + struct file *file;
37775 + struct au_xi_writing *del, *p;
37776 + struct hlist_bl_head *hbl;
37777 + struct hlist_bl_node *pos;
37782 + sbi = au_sbi(sb);
37783 + si_noflush_read_lock(sb);
37784 + root = d_inode(sb->s_root);
37785 + ii_read_lock_child(root);
37786 + err = au_xino_do_new_async(sb, br, &a->calc);
37787 + if (unlikely(err)) {
37788 + AuIOErr("err %d\n", err);
37792 + file = au_xino_file(br->br_xino, a->calc.idx);
37793 + AuDebugOn(!file);
37794 + err = au_xino_do_write(file, &a->calc, a->ino);
37795 + if (unlikely(err)) {
37796 + AuIOErr("err %d\n", err);
37801 + hbl = &br->br_xino->xi_writing;
37802 + hlist_bl_lock(hbl);
37803 + au_hbl_for_each(pos, hbl) {
37804 + p = container_of(pos, struct au_xi_writing, node);
37805 + if (p->ino == a->ino) {
37807 + hlist_bl_del(&p->node);
37811 + hlist_bl_unlock(hbl);
37812 + au_kfree_rcu(del);
37815 + au_lcnt_dec(&br->br_count);
37816 + ii_read_unlock(root);
37817 + si_read_unlock(sb);
37818 + au_nwt_done(&sbi->si_nowait);
37823 + * create a new xino file asynchronously
37825 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37826 + struct au_xi_calc *calc, ino_t ino)
37829 + struct au_xino_do_new_async_args *arg;
37832 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37833 + if (unlikely(!arg))
37838 + arg->calc = *calc;
37840 + au_lcnt_inc(&br->br_count);
37841 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37842 + if (unlikely(err)) {
37843 + pr_err("wkq %d\n", err);
37844 + au_lcnt_dec(&br->br_count);
37845 + au_kfree_rcu(arg);
37853 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37854 + * at the position of @h_ino.
37856 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37861 + struct au_xi_calc calc;
37862 + struct au_sbinfo *sbinfo;
37863 + struct file *file;
37864 + struct au_xino *xi;
37865 + struct hlist_bl_head *hbl;
37866 + struct hlist_bl_node *pos;
37867 + struct au_xi_writing *p;
37870 + if (!au_opt_test(au_mntflags(sb), XINO))
37871 + return 0; /* no xino */
37874 + au_xi_calc(sb, h_ino, &calc);
37875 + xi = au_sbr(sb, bindex)->br_xino;
37876 + file = au_xino_file(xi, calc.idx);
37878 + hbl = &xi->xi_writing;
37879 + hlist_bl_lock(hbl);
37880 + au_hbl_for_each(pos, hbl) {
37881 + p = container_of(pos, struct au_xi_writing, node);
37882 + if (p->h_ino == h_ino) {
37883 + AuDbg("hi%llu, i%llu, found\n",
37884 + (u64)p->h_ino, (u64)p->ino);
37889 + hlist_bl_unlock(hbl);
37891 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37892 + return 0; /* no xino */
37894 + sbinfo = au_sbi(sb);
37895 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37896 + if (sz == sizeof(*ino))
37897 + return 0; /* success */
37900 + if (unlikely(sz >= 0)) {
37902 + AuIOErr("xino read error (%zd)\n", sz);
37907 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37912 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37913 + if (sz == sizeof(ino))
37914 + return 0; /* success */
37916 + AuIOErr("write failed (%zd)\n", sz);
37921 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37922 + * at the position of @h_ino.
37923 + * even if @ino is zero, it is written to the xinofile and means no entry.
37924 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37925 + * try truncating it.
37927 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37931 + unsigned int mnt_flags;
37932 + struct au_xi_calc calc;
37933 + struct file *file;
37934 + struct au_branch *br;
37935 + struct au_xino *xi;
37936 + struct au_xi_writing *p;
37938 + SiMustAnyLock(sb);
37940 + mnt_flags = au_mntflags(sb);
37941 + if (!au_opt_test(mnt_flags, XINO))
37944 + au_xi_calc(sb, h_ino, &calc);
37945 + br = au_sbr(sb, bindex);
37946 + xi = br->br_xino;
37947 + file = au_xino_file(xi, calc.idx);
37949 + /* store the inum pair into the list */
37950 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37951 + p->h_ino = h_ino;
37953 + au_hbl_add(&p->node, &xi->xi_writing);
37955 + /* create and write a new xino file asynchronously */
37956 + err = au_xino_new_async(sb, br, &calc, ino);
37958 + return 0; /* success */
37962 + err = au_xino_do_write(file, &calc, ino);
37964 + br = au_sbr(sb, bindex);
37965 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37966 + && au_test_fs_trunc_xino(au_br_sb(br)))
37967 + xino_try_trunc(sb, br);
37968 + return 0; /* success */
37972 + AuIOErr("write failed (%d)\n", err);
37976 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37979 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37980 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37984 + const int prevent_endless = 10;
37988 + err = vfsub_read_k(file, kbuf, size, pos);
37989 + if (err == -EINTR
37990 + && !au_wkq_test()
37991 + && fatal_signal_pending(current)) {
37992 + err = xino_fread_wkq(file, kbuf, size, pos);
37993 + BUG_ON(err == -EINTR);
37995 + } while (i++ < prevent_endless
37996 + && (err == -EAGAIN || err == -EINTR));
37998 +#if 0 /* reserved for future use */
38000 + fsnotify_access(file->f_path.dentry);
38006 +struct xino_fread_args {
38008 + struct file *file;
38014 +static void call_xino_fread(void *args)
38016 + struct xino_fread_args *a = args;
38017 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38020 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38025 + struct xino_fread_args args = {
38033 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38034 + if (unlikely(wkq_err))
38040 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38043 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38048 + const int prevent_endless = 10;
38052 + err = vfsub_write_k(file, kbuf, size, pos);
38053 + if (err == -EINTR
38054 + && !au_wkq_test()
38055 + && fatal_signal_pending(current)) {
38056 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38057 + BUG_ON(err == -EINTR);
38059 + } while (i++ < prevent_endless
38060 + && (err == -EAGAIN || err == -EINTR));
38062 +#if 0 /* reserved for future use */
38064 + fsnotify_modify(file->f_path.dentry);
38070 +struct do_xino_fwrite_args {
38072 + struct file *file;
38078 +static void call_do_xino_fwrite(void *args)
38080 + struct do_xino_fwrite_args *a = args;
38081 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38084 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38089 + struct do_xino_fwrite_args args = {
38098 + * it breaks RLIMIT_FSIZE and normal user's limit,
38099 + * users should care about quota and real 'filesystem full.'
38101 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38102 + if (unlikely(wkq_err))
38108 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38112 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38114 + err = do_xino_fwrite(file, buf, size, pos);
38118 + err = xino_fwrite_wkq(file, buf, size, pos);
38125 +/* ---------------------------------------------------------------------- */
38128 + * inode number bitmap
38130 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38131 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38135 + AuDebugOn(bit < 0 || page_bits <= bit);
38136 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38140 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38142 + AuDebugOn(ino < AUFS_FIRST_INO);
38143 + ino -= AUFS_FIRST_INO;
38144 + *pindex = ino / page_bits;
38145 + *bit = ino % page_bits;
38148 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38153 + struct au_sbinfo *sbinfo;
38154 + struct file *xib;
38155 + unsigned long *p;
38157 + sbinfo = au_sbi(sb);
38158 + MtxMustLock(&sbinfo->si_xib_mtx);
38159 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38160 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38162 + if (pindex == sbinfo->si_xib_last_pindex)
38165 + xib = sbinfo->si_xib;
38166 + p = sbinfo->si_xib_buf;
38167 + pos = sbinfo->si_xib_last_pindex;
38168 + pos *= PAGE_SIZE;
38169 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38170 + if (unlikely(sz != PAGE_SIZE))
38174 + pos *= PAGE_SIZE;
38175 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38176 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38178 + memset(p, 0, PAGE_SIZE);
38179 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38181 + if (sz == PAGE_SIZE) {
38182 + sbinfo->si_xib_last_pindex = pindex;
38183 + return 0; /* success */
38187 + AuIOErr1("write failed (%zd)\n", sz);
38194 +static void au_xib_clear_bit(struct inode *inode)
38197 + unsigned long pindex;
38198 + struct super_block *sb;
38199 + struct au_sbinfo *sbinfo;
38201 + AuDebugOn(inode->i_nlink);
38203 + sb = inode->i_sb;
38204 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38205 + AuDebugOn(page_bits <= bit);
38206 + sbinfo = au_sbi(sb);
38207 + mutex_lock(&sbinfo->si_xib_mtx);
38208 + err = xib_pindex(sb, pindex);
38210 + clear_bit(bit, sbinfo->si_xib_buf);
38211 + sbinfo->si_xib_next_bit = bit;
38213 + mutex_unlock(&sbinfo->si_xib_mtx);
38216 +/* ---------------------------------------------------------------------- */
38219 + * truncate a xino bitmap file
38223 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38227 + unsigned long pindex;
38228 + loff_t pos, pend;
38229 + struct au_sbinfo *sbinfo;
38231 + unsigned long *p;
38234 + sbinfo = au_sbi(sb);
38235 + MtxMustLock(&sbinfo->si_xib_mtx);
38236 + p = sbinfo->si_xib_buf;
38237 + pend = vfsub_f_size_read(file);
38239 + while (pos < pend) {
38240 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38242 + if (unlikely(sz <= 0))
38246 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38247 + if (unlikely(*ino < AUFS_FIRST_INO))
38250 + xib_calc_bit(*ino, &pindex, &bit);
38251 + AuDebugOn(page_bits <= bit);
38252 + err = xib_pindex(sb, pindex);
38264 +static int xib_restore(struct super_block *sb)
38267 + unsigned int nfile;
38268 + aufs_bindex_t bindex, bbot;
38270 + struct au_branch *br;
38271 + struct au_xino *xi;
38272 + struct file *file;
38275 + page = (void *)__get_free_page(GFP_NOFS);
38276 + if (unlikely(!page))
38280 + bbot = au_sbbot(sb);
38281 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38282 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38283 + br = au_sbr(sb, bindex);
38284 + xi = br->br_xino;
38285 + nfile = xi->xi_nfile;
38286 + for (i = 0; i < nfile; i++) {
38287 + file = au_xino_file(xi, i);
38289 + err = do_xib_restore(sb, file, page);
38292 + AuDbg("skip shared b%d\n", bindex);
38293 + free_page((unsigned long)page);
38299 +int au_xib_trunc(struct super_block *sb)
38304 + struct au_sbinfo *sbinfo;
38305 + unsigned long *p;
38306 + struct file *file;
38308 + SiMustWriteLock(sb);
38311 + sbinfo = au_sbi(sb);
38312 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38315 + file = sbinfo->si_xib;
38316 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38319 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38320 + err = PTR_ERR(file);
38321 + if (IS_ERR(file))
38323 + fput(sbinfo->si_xib);
38324 + sbinfo->si_xib = file;
38326 + p = sbinfo->si_xib_buf;
38327 + memset(p, 0, PAGE_SIZE);
38329 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38330 + if (unlikely(sz != PAGE_SIZE)) {
38332 + AuIOErr("err %d\n", err);
38338 + mutex_lock(&sbinfo->si_xib_mtx);
38339 + /* mnt_want_write() is unnecessary here */
38340 + err = xib_restore(sb);
38341 + mutex_unlock(&sbinfo->si_xib_mtx);
38347 +/* ---------------------------------------------------------------------- */
38349 +struct au_xino *au_xino_alloc(unsigned int nfile)
38351 + struct au_xino *xi;
38353 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38354 + if (unlikely(!xi))
38356 + xi->xi_nfile = nfile;
38357 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38358 + if (unlikely(!xi->xi_file))
38361 + xi->xi_nondir.total = 8; /* initial size */
38362 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38364 + if (unlikely(!xi->xi_nondir.array))
38367 + spin_lock_init(&xi->xi_nondir.spin);
38368 + init_waitqueue_head(&xi->xi_nondir.wqh);
38369 + mutex_init(&xi->xi_mtx);
38370 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38371 + atomic_set(&xi->xi_truncating, 0);
38372 + kref_init(&xi->xi_kref);
38373 + goto out; /* success */
38376 + au_kfree_try_rcu(xi->xi_file);
38378 + au_kfree_rcu(xi);
38384 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38387 + struct au_xino *xi;
38390 + xi = au_xino_alloc(idx + 1);
38391 + if (unlikely(!xi)) {
38398 + xi->xi_file[idx] = file;
38399 + AuDebugOn(br->br_xino);
38400 + br->br_xino = xi;
38406 +static void au_xino_release(struct kref *kref)
38408 + struct au_xino *xi;
38410 + unsigned long ul;
38411 + struct hlist_bl_head *hbl;
38412 + struct hlist_bl_node *pos, *n;
38413 + struct au_xi_writing *p;
38415 + xi = container_of(kref, struct au_xino, xi_kref);
38416 + for (i = 0; i < xi->xi_nfile; i++)
38417 + if (xi->xi_file[i])
38418 + fput(xi->xi_file[i]);
38419 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38420 + AuDebugOn(xi->xi_nondir.array[i]);
38421 + mutex_destroy(&xi->xi_mtx);
38422 + hbl = &xi->xi_writing;
38423 + ul = au_hbl_count(hbl);
38424 + if (unlikely(ul)) {
38425 + pr_warn("xi_writing %lu\n", ul);
38426 + hlist_bl_lock(hbl);
38427 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38428 + hlist_bl_del(&p->node);
38429 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38432 + hlist_bl_unlock(hbl);
38434 + au_kfree_try_rcu(xi->xi_file);
38435 + au_kfree_try_rcu(xi->xi_nondir.array);
38436 + au_kfree_rcu(xi);
38439 +int au_xino_put(struct au_branch *br)
38442 + struct au_xino *xi;
38445 + xi = br->br_xino;
38447 + br->br_xino = NULL;
38448 + ret = kref_put(&xi->xi_kref, au_xino_release);
38454 +/* ---------------------------------------------------------------------- */
38457 + * xino mount option handlers
38461 +static void xino_clear_xib(struct super_block *sb)
38463 + struct au_sbinfo *sbinfo;
38465 + SiMustWriteLock(sb);
38467 + sbinfo = au_sbi(sb);
38468 + if (sbinfo->si_xib)
38469 + fput(sbinfo->si_xib);
38470 + sbinfo->si_xib = NULL;
38471 + if (sbinfo->si_xib_buf)
38472 + free_page((unsigned long)sbinfo->si_xib_buf);
38473 + sbinfo->si_xib_buf = NULL;
38476 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38480 + struct au_sbinfo *sbinfo;
38481 + struct file *file;
38482 + struct super_block *xi_sb;
38484 + SiMustWriteLock(sb);
38486 + sbinfo = au_sbi(sb);
38487 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38488 + err = PTR_ERR(file);
38489 + if (IS_ERR(file))
38491 + if (sbinfo->si_xib)
38492 + fput(sbinfo->si_xib);
38493 + sbinfo->si_xib = file;
38494 + xi_sb = file_inode(file)->i_sb;
38495 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38496 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38498 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38499 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38502 + sbinfo->si_ximaxent /= sizeof(ino_t);
38505 + if (!sbinfo->si_xib_buf)
38506 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38507 + if (unlikely(!sbinfo->si_xib_buf))
38510 + sbinfo->si_xib_last_pindex = 0;
38511 + sbinfo->si_xib_next_bit = 0;
38512 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38514 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38515 + if (unlikely(err != PAGE_SIZE))
38519 + goto out; /* success */
38522 + if (sbinfo->si_xib_buf)
38523 + free_page((unsigned long)sbinfo->si_xib_buf);
38524 + sbinfo->si_xib_buf = NULL;
38528 + fput(sbinfo->si_xib);
38529 + sbinfo->si_xib = NULL;
38535 +/* xino for each branch */
38536 +static void xino_clear_br(struct super_block *sb)
38538 + aufs_bindex_t bindex, bbot;
38539 + struct au_branch *br;
38541 + bbot = au_sbbot(sb);
38542 + for (bindex = 0; bindex <= bbot; bindex++) {
38543 + br = au_sbr(sb, bindex);
38549 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38550 + aufs_bindex_t bshared)
38552 + struct au_branch *brshared;
38554 + brshared = au_sbr(sb, bshared);
38555 + AuDebugOn(!brshared->br_xino);
38556 + AuDebugOn(!brshared->br_xino->xi_file);
38557 + if (br->br_xino != brshared->br_xino) {
38558 + au_xino_get(brshared);
38560 + br->br_xino = brshared->br_xino;
38564 +struct au_xino_do_set_br {
38565 + struct au_branch *br;
38567 + aufs_bindex_t bshared;
38570 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38571 + struct au_xino_do_set_br *args)
38574 + struct au_xi_calc calc;
38575 + struct file *file;
38576 + struct au_branch *br;
38577 + struct au_xi_new xinew = {
38582 + xinew.xi = br->br_xino;
38583 + au_xi_calc(sb, args->h_ino, &calc);
38584 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38585 + if (args->bshared >= 0)
38586 + /* shared xino */
38587 + au_xino_set_br_shared(sb, br, args->bshared);
38588 + else if (!xinew.xi) {
38590 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38591 + if (unlikely(err))
38595 + /* force re-creating */
38596 + xinew.xi = br->br_xino;
38597 + xinew.idx = calc.idx;
38598 + mutex_lock(&xinew.xi->xi_mtx);
38599 + file = au_xi_new(sb, &xinew);
38600 + mutex_unlock(&xinew.xi->xi_mtx);
38601 + err = PTR_ERR(file);
38602 + if (IS_ERR(file))
38604 + AuDebugOn(!file);
38606 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38607 + if (unlikely(err))
38615 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38618 + aufs_bindex_t bindex, bbot;
38619 + struct au_xino_do_set_br args;
38620 + struct inode *inode;
38622 + SiMustWriteLock(sb);
38624 + bbot = au_sbbot(sb);
38625 + inode = d_inode(sb->s_root);
38626 + for (bindex = 0; bindex <= bbot; bindex++) {
38627 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38628 + args.br = au_sbr(sb, bindex);
38629 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38630 + err = au_xino_do_set_br(sb, path, &args);
38631 + if (unlikely(err))
38639 +void au_xino_clr(struct super_block *sb)
38641 + struct au_sbinfo *sbinfo;
38643 + au_xigen_clr(sb);
38644 + xino_clear_xib(sb);
38645 + xino_clear_br(sb);
38646 + dbgaufs_brs_del(sb, 0);
38647 + sbinfo = au_sbi(sb);
38648 + /* lvalue, do not call au_mntflags() */
38649 + au_opt_clr(sbinfo->si_mntflags, XINO);
38652 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38655 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38656 + struct qstr *dname, *cur_name;
38657 + struct file *cur_xino;
38658 + struct au_sbinfo *sbinfo;
38659 + struct path *path, *cur_path;
38661 + SiMustWriteLock(sb);
38664 + sbinfo = au_sbi(sb);
38665 + path = &xiopt->file->f_path;
38666 + dentry = path->dentry;
38667 + parent = dget_parent(dentry);
38670 + cur_xino = sbinfo->si_xib;
38672 + cur_path = &cur_xino->f_path;
38673 + cur_dentry = cur_path->dentry;
38674 + cur_parent = dget_parent(cur_dentry);
38675 + cur_name = &cur_dentry->d_name;
38676 + dname = &dentry->d_name;
38677 + skip = (cur_parent == parent
38678 + && au_qstreq(dname, cur_name));
38679 + dput(cur_parent);
38685 + au_opt_set(sbinfo->si_mntflags, XINO);
38686 + err = au_xino_set_xib(sb, path);
38687 + /* si_x{read,write} are set */
38689 + err = au_xigen_set(sb, path);
38691 + err = au_xino_set_br(sb, path);
38693 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38694 + goto out; /* success */
38698 + AuIOErr("failed setting xino(%d).\n", err);
38707 + * create a xinofile at the default place/path.
38709 +struct file *au_xino_def(struct super_block *sb)
38711 + struct file *file;
38713 + struct au_branch *br;
38714 + struct super_block *h_sb;
38715 + struct path path;
38716 + aufs_bindex_t bbot, bindex, bwr;
38719 + bbot = au_sbbot(sb);
38721 + for (bindex = 0; bindex <= bbot; bindex++) {
38722 + br = au_sbr(sb, bindex);
38723 + if (au_br_writable(br->br_perm)
38724 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38731 + file = ERR_PTR(-ENOMEM);
38732 + page = (void *)__get_free_page(GFP_NOFS);
38733 + if (unlikely(!page))
38735 + path.mnt = au_br_mnt(br);
38736 + path.dentry = au_h_dptr(sb->s_root, bwr);
38737 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38738 + file = (void *)p;
38739 + if (!IS_ERR(p)) {
38740 + strcat(p, "/" AUFS_XINO_FNAME);
38741 + AuDbg("%s\n", p);
38742 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38744 + free_page((unsigned long)page);
38746 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38748 + if (IS_ERR(file))
38750 + h_sb = file->f_path.dentry->d_sb;
38751 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38752 + pr_err("xino doesn't support %s(%s)\n",
38753 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38755 + file = ERR_PTR(-EINVAL);
38763 +/* ---------------------------------------------------------------------- */
38766 + * initialize the xinofile for the specified branch @br
38767 + * at the place/path where @base_file indicates.
38768 + * test whether another branch is on the same filesystem or not,
38769 + * if found then share the xinofile with another branch.
38771 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38772 + struct path *base)
38775 + struct au_xino_do_set_br args = {
38780 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38782 + err = au_xino_do_set_br(sb, base, &args);
38783 + if (unlikely(err))
38789 +/* ---------------------------------------------------------------------- */
38792 + * get an unused inode number from bitmap
38794 +ino_t au_xino_new_ino(struct super_block *sb)
38797 + unsigned long *p, pindex, ul, pend;
38798 + struct au_sbinfo *sbinfo;
38799 + struct file *file;
38800 + int free_bit, err;
38802 + if (!au_opt_test(au_mntflags(sb), XINO))
38803 + return iunique(sb, AUFS_FIRST_INO);
38805 + sbinfo = au_sbi(sb);
38806 + mutex_lock(&sbinfo->si_xib_mtx);
38807 + p = sbinfo->si_xib_buf;
38808 + free_bit = sbinfo->si_xib_next_bit;
38809 + if (free_bit < page_bits && !test_bit(free_bit, p))
38810 + goto out; /* success */
38811 + free_bit = find_first_zero_bit(p, page_bits);
38812 + if (free_bit < page_bits)
38813 + goto out; /* success */
38815 + pindex = sbinfo->si_xib_last_pindex;
38816 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38817 + err = xib_pindex(sb, ul);
38818 + if (unlikely(err))
38820 + free_bit = find_first_zero_bit(p, page_bits);
38821 + if (free_bit < page_bits)
38822 + goto out; /* success */
38825 + file = sbinfo->si_xib;
38826 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38827 + for (ul = pindex + 1; ul <= pend; ul++) {
38828 + err = xib_pindex(sb, ul);
38829 + if (unlikely(err))
38831 + free_bit = find_first_zero_bit(p, page_bits);
38832 + if (free_bit < page_bits)
38833 + goto out; /* success */
38838 + set_bit(free_bit, p);
38839 + sbinfo->si_xib_next_bit = free_bit + 1;
38840 + pindex = sbinfo->si_xib_last_pindex;
38841 + mutex_unlock(&sbinfo->si_xib_mtx);
38842 + ino = xib_calc_ino(pindex, free_bit);
38843 + AuDbg("i%lu\n", (unsigned long)ino);
38846 + mutex_unlock(&sbinfo->si_xib_mtx);
38851 +/* for s_op->delete_inode() */
38852 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38855 + unsigned int mnt_flags;
38856 + aufs_bindex_t bindex, bbot, bi;
38857 + unsigned char try_trunc;
38858 + struct au_iinfo *iinfo;
38859 + struct super_block *sb;
38860 + struct au_hinode *hi;
38861 + struct inode *h_inode;
38862 + struct au_branch *br;
38863 + struct au_xi_calc calc;
38864 + struct file *file;
38866 + AuDebugOn(au_is_bad_inode(inode));
38868 + sb = inode->i_sb;
38869 + mnt_flags = au_mntflags(sb);
38870 + if (!au_opt_test(mnt_flags, XINO)
38871 + || inode->i_ino == AUFS_ROOT_INO)
38875 + au_xigen_inc(inode);
38876 + au_xib_clear_bit(inode);
38879 + iinfo = au_ii(inode);
38880 + bindex = iinfo->ii_btop;
38884 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38885 + hi = au_hinode(iinfo, bindex);
38886 + bbot = iinfo->ii_bbot;
38887 + for (; bindex <= bbot; bindex++, hi++) {
38888 + h_inode = hi->hi_inode;
38890 + || (!unlinked && h_inode->i_nlink))
38893 + /* inode may not be revalidated */
38894 + bi = au_br_index(sb, hi->hi_id);
38898 + br = au_sbr(sb, bi);
38899 + au_xi_calc(sb, h_inode->i_ino, &calc);
38900 + file = au_xino_file(br->br_xino, calc.idx);
38901 + if (IS_ERR_OR_NULL(file))
38904 + err = au_xino_do_write(file, &calc, /*ino*/0);
38905 + if (!err && try_trunc
38906 + && au_test_fs_trunc_xino(au_br_sb(br)))
38907 + xino_try_trunc(sb, br);
38911 +/* ---------------------------------------------------------------------- */
38913 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38915 + int found, total, i;
38918 + total = xi->xi_nondir.total;
38919 + for (i = 0; i < total; i++) {
38920 + if (xi->xi_nondir.array[i] != h_ino)
38929 +static int au_xinondir_expand(struct au_xino *xi)
38934 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38937 + sz = xi->xi_nondir.total * sizeof(ino_t);
38938 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38940 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38941 + /*may_shrink*/0);
38943 + xi->xi_nondir.array = p;
38944 + xi->xi_nondir.total <<= 1;
38945 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38953 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38954 + ino_t h_ino, int idx)
38956 + struct au_xino *xi;
38958 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38959 + xi = au_sbr(sb, bindex)->br_xino;
38960 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38962 + spin_lock(&xi->xi_nondir.spin);
38963 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38964 + xi->xi_nondir.array[idx] = 0;
38965 + spin_unlock(&xi->xi_nondir.spin);
38966 + wake_up_all(&xi->xi_nondir.wqh);
38969 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38972 + int err, found, empty;
38973 + struct au_xino *xi;
38977 + if (!au_opt_test(au_mntflags(sb), XINO))
38978 + goto out; /* no xino */
38980 + xi = au_sbr(sb, bindex)->br_xino;
38983 + spin_lock(&xi->xi_nondir.spin);
38984 + found = au_xinondir_find(xi, h_ino);
38985 + if (found == -1) {
38986 + empty = au_xinondir_find(xi, /*h_ino*/0);
38987 + if (empty == -1) {
38988 + empty = xi->xi_nondir.total;
38989 + err = au_xinondir_expand(xi);
38990 + if (unlikely(err))
38993 + xi->xi_nondir.array[empty] = h_ino;
38996 + spin_unlock(&xi->xi_nondir.spin);
38997 + wait_event(xi->xi_nondir.wqh,
38998 + xi->xi_nondir.array[found] != h_ino);
39003 + spin_unlock(&xi->xi_nondir.spin);
39008 +/* ---------------------------------------------------------------------- */
39010 +int au_xino_path(struct seq_file *seq, struct file *file)
39014 + err = au_seq_path(seq, &file->f_path);
39015 + if (unlikely(err))
39018 +#define Deleted "\\040(deleted)"
39019 + seq->count -= sizeof(Deleted) - 1;
39020 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39021 + sizeof(Deleted) - 1));
39027 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39028 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39029 +++ linux/include/uapi/linux/aufs_type.h 2023-09-04 13:40:14.109962274 +0200
39031 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39033 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39035 + * This program is free software; you can redistribute it and/or modify
39036 + * it under the terms of the GNU General Public License as published by
39037 + * the Free Software Foundation; either version 2 of the License, or
39038 + * (at your option) any later version.
39040 + * This program is distributed in the hope that it will be useful,
39041 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39042 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39043 + * GNU General Public License for more details.
39045 + * You should have received a copy of the GNU General Public License
39046 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39049 +#ifndef __AUFS_TYPE_H__
39050 +#define __AUFS_TYPE_H__
39052 +#define AUFS_NAME "aufs"
39056 + * define it before including all other headers.
39057 + * sched.h may use pr_* macros before defining "current", so define the
39058 + * no-current version first, and re-define later.
39060 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39061 +#include <linux/sched.h>
39063 +#define pr_fmt(fmt) \
39064 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39065 + (int)sizeof(current->comm), current->comm, current->pid
39066 +#include <linux/limits.h>
39068 +#include <stdint.h>
39069 +#include <sys/types.h>
39070 +#include <limits.h>
39071 +#endif /* __KERNEL__ */
39073 +#define AUFS_VERSION "6.5-20230904"
39075 +/* todo? move this to linux-2.6.19/include/magic.h */
39076 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39078 +/* ---------------------------------------------------------------------- */
39081 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39082 +typedef int8_t aufs_bindex_t;
39083 +#define AUFS_BRANCH_MAX 127
39085 +typedef int16_t aufs_bindex_t;
39086 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39087 +#define AUFS_BRANCH_MAX 511
39088 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39089 +#define AUFS_BRANCH_MAX 1023
39090 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39091 +#define AUFS_BRANCH_MAX 32767
39095 +#ifndef AUFS_BRANCH_MAX
39096 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39098 +#endif /* __KERNEL__ */
39100 +/* ---------------------------------------------------------------------- */
39102 +#define AUFS_FSTYPE AUFS_NAME
39104 +#define AUFS_ROOT_INO 2
39105 +#define AUFS_FIRST_INO 11
39107 +#define AUFS_WH_PFX ".wh."
39108 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39109 +#define AUFS_WH_TMP_LEN 4
39110 +/* a limit for rmdir/rename a dir and copyup */
39111 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39112 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39114 + - AUFS_WH_TMP_LEN) /* hex */
39115 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39116 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39117 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39118 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39119 +#define AUFS_DIRWH_DEF 3
39120 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39121 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39122 +#define AUFS_RDBLK_DEF 512 /* bytes */
39123 +#define AUFS_RDHASH_DEF 32
39124 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39125 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39126 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39127 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39128 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39130 +/* pseudo-link maintenace under /proc */
39131 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39132 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39133 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39135 +/* dirren, renamed dir */
39136 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39137 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39138 +/* whiteouted doubly */
39139 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39140 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39142 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39143 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39145 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39146 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39147 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39149 +/* doubly whiteouted */
39150 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39151 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39152 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39154 +/* branch permissions and attributes */
39155 +#define AUFS_BRPERM_RW "rw"
39156 +#define AUFS_BRPERM_RO "ro"
39157 +#define AUFS_BRPERM_RR "rr"
39158 +#define AUFS_BRATTR_COO_REG "coo_reg"
39159 +#define AUFS_BRATTR_COO_ALL "coo_all"
39160 +#define AUFS_BRATTR_FHSM "fhsm"
39161 +#define AUFS_BRATTR_UNPIN "unpin"
39162 +#define AUFS_BRATTR_ICEX "icex"
39163 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39164 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39165 +#define AUFS_BRATTR_ICEX_TR "icextr"
39166 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39167 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39168 +#define AUFS_BRRATTR_WH "wh"
39169 +#define AUFS_BRWATTR_NLWH "nolwh"
39170 +#define AUFS_BRWATTR_MOO "moo"
39172 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39173 +#define AuBrPerm_RO (1 << 1) /* readonly */
39174 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39175 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39177 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39178 +#define AuBrAttr_COO_ALL (1 << 4)
39179 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39181 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39182 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39183 + branch. meaningless since
39184 + linux-3.18-rc1 */
39186 +/* ignore error in copying XATTR */
39187 +#define AuBrAttr_ICEX_SEC (1 << 7)
39188 +#define AuBrAttr_ICEX_SYS (1 << 8)
39189 +#define AuBrAttr_ICEX_TR (1 << 9)
39190 +#define AuBrAttr_ICEX_USR (1 << 10)
39191 +#define AuBrAttr_ICEX_OTH (1 << 11)
39192 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39193 + | AuBrAttr_ICEX_SYS \
39194 + | AuBrAttr_ICEX_TR \
39195 + | AuBrAttr_ICEX_USR \
39196 + | AuBrAttr_ICEX_OTH)
39198 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39199 +#define AuBrRAttr_Mask AuBrRAttr_WH
39201 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39202 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39203 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39205 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39207 +/* #warning test userspace */
39209 +#ifndef CONFIG_AUFS_FHSM
39210 +#undef AuBrAttr_FHSM
39211 +#define AuBrAttr_FHSM 0
39213 +#ifndef CONFIG_AUFS_XATTR
39214 +#undef AuBrAttr_ICEX
39215 +#define AuBrAttr_ICEX 0
39216 +#undef AuBrAttr_ICEX_SEC
39217 +#define AuBrAttr_ICEX_SEC 0
39218 +#undef AuBrAttr_ICEX_SYS
39219 +#define AuBrAttr_ICEX_SYS 0
39220 +#undef AuBrAttr_ICEX_TR
39221 +#define AuBrAttr_ICEX_TR 0
39222 +#undef AuBrAttr_ICEX_USR
39223 +#define AuBrAttr_ICEX_USR 0
39224 +#undef AuBrAttr_ICEX_OTH
39225 +#define AuBrAttr_ICEX_OTH 0
39229 +/* the longest combination */
39230 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39231 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39232 + "+" AUFS_BRATTR_COO_REG \
39233 + "+" AUFS_BRATTR_FHSM \
39234 + "+" AUFS_BRATTR_UNPIN \
39235 + "+" AUFS_BRATTR_ICEX_SEC \
39236 + "+" AUFS_BRATTR_ICEX_SYS \
39237 + "+" AUFS_BRATTR_ICEX_USR \
39238 + "+" AUFS_BRATTR_ICEX_OTH \
39239 + "+" AUFS_BRWATTR_NLWH)
39242 + char a[AuBrPermStrSz];
39243 +} au_br_perm_str_t;
39245 +static inline int au_br_writable(int brperm)
39247 + return brperm & AuBrPerm_RW;
39250 +static inline int au_br_whable(int brperm)
39252 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39255 +static inline int au_br_wh_linkable(int brperm)
39257 + return !(brperm & AuBrWAttr_NoLinkWH);
39260 +static inline int au_br_cmoo(int brperm)
39262 + return brperm & AuBrAttr_CMOO_Mask;
39265 +static inline int au_br_fhsm(int brperm)
39267 + return brperm & AuBrAttr_FHSM;
39270 +/* ---------------------------------------------------------------------- */
39274 + /* readdir in userspace */
39278 + AuCtl_WBR_FD, /* pathconf wrapper */
39279 + AuCtl_IBUSY, /* busy inode */
39280 + AuCtl_MVDOWN, /* move-down */
39281 + AuCtl_BR, /* info about branches */
39282 + AuCtl_FHSM_FD /* connection for fhsm */
39285 +/* borrowed from linux/include/linux/kernel.h */
39287 +#ifdef _GNU_SOURCE
39288 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39290 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39292 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39295 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39297 +#define __aligned(x) __attribute__((aligned(x)))
39302 +#define __packed __attribute__((packed))
39306 +struct au_rdu_cookie {
39311 + uint32_t generation;
39314 +struct au_rdu_ent {
39323 +static inline int au_rdu_len(int nlen)
39325 + /* include the terminating NULL */
39326 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39327 + sizeof(uint64_t));
39330 +union au_rdu_ent_ul {
39331 + struct au_rdu_ent __user *e;
39343 + uint64_t sz; /* AuCtl_RDU */
39344 + uint64_t nent; /* AuCtl_RDU_INO */
39346 + union au_rdu_ent_ul ent;
39347 + uint16_t verify[AufsCtlRduV_End];
39349 + /* input/output */
39353 + union au_rdu_ent_ul tail;
39354 + /* number of entries which were added in a single call */
39359 + struct au_rdu_cookie cookie;
39362 +/* ---------------------------------------------------------------------- */
39364 +/* dirren. the branch is identified by the filename who contains this */
39365 +struct au_drinfo {
39368 + uint8_t oldnamelen;
39369 + uint64_t _padding;
39371 + uint8_t oldname[];
39374 +struct au_drinfo_fdata {
39376 + struct au_drinfo drinfo;
39379 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39381 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39383 +/* ---------------------------------------------------------------------- */
39385 +struct aufs_wbr_fd {
39390 +/* ---------------------------------------------------------------------- */
39392 +struct aufs_ibusy {
39393 + uint64_t ino, h_ino;
39397 +/* ---------------------------------------------------------------------- */
39399 +/* error code for move-down */
39400 +/* the actual message strings are implemented in aufs-util.git */
39402 + EAU_MVDOWN_OPAQUE = 1,
39403 + EAU_MVDOWN_WHITEOUT,
39404 + EAU_MVDOWN_UPPER,
39405 + EAU_MVDOWN_BOTTOM,
39406 + EAU_MVDOWN_NOUPPER,
39407 + EAU_MVDOWN_NOLOWERBR,
39411 +/* flags for move-down */
39412 +#define AUFS_MVDOWN_DMSG 1
39413 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39414 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39415 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39416 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39417 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39418 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39419 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39420 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39421 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39422 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39423 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39424 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39426 +/* index for move-down */
39428 + AUFS_MVDOWN_UPPER,
39429 + AUFS_MVDOWN_LOWER,
39430 + AUFS_MVDOWN_NARRAY
39434 + * additional info of move-down
39435 + * number of free blocks and inodes.
39436 + * subset of struct kstatfs, but smaller and always 64bit.
39438 +struct aufs_stfs {
39439 + uint64_t f_blocks;
39440 + uint64_t f_bavail;
39441 + uint64_t f_files;
39442 + uint64_t f_ffree;
39445 +struct aufs_stbr {
39446 + int16_t brid; /* optional input */
39447 + int16_t bindex; /* output */
39448 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39451 +struct aufs_mvdown {
39452 + uint32_t flags; /* input/output */
39453 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39454 + int8_t au_errno; /* output */
39457 +/* ---------------------------------------------------------------------- */
39459 +union aufs_brinfo {
39460 + /* PATH_MAX may differ between kernel-space and user-space */
39461 + char _spacer[4096];
39469 +/* ---------------------------------------------------------------------- */
39471 +#define AuCtlType 'A'
39472 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39473 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39474 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39475 + struct aufs_wbr_fd)
39476 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39477 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39478 + struct aufs_mvdown)
39479 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39480 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39482 +#endif /* __AUFS_TYPE_H__ */
39483 SPDX-License-Identifier: GPL-2.0
39484 aufs6.5 loopback patch
39486 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39487 index cbefd23beb44..53b9f81161d4 100644
39488 --- a/drivers/block/loop.c
39489 +++ b/drivers/block/loop.c
39490 @@ -54,7 +54,7 @@ struct loop_device {
39492 char lo_file_name[LO_NAME_SIZE];
39494 - struct file * lo_backing_file;
39495 + struct file *lo_backing_file, *lo_backing_virt_file;
39496 struct block_device *lo_device;
39498 gfp_t old_gfp_mask;
39499 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39503 +static struct file *loop_real_file(struct file *file)
39505 + struct file *f = NULL;
39507 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39508 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39512 static void loop_reread_partitions(struct loop_device *lo)
39515 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39517 struct file *file = fget(arg);
39518 struct file *old_file;
39519 + struct file *f, *virt_file = NULL, *old_virt_file;
39523 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39524 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39527 + f = loop_real_file(file);
39529 + virt_file = file;
39534 error = loop_validate_file(file, bdev);
39538 old_file = lo->lo_backing_file;
39539 + old_virt_file = lo->lo_backing_virt_file;
39543 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39544 blk_mq_freeze_queue(lo->lo_queue);
39545 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39546 lo->lo_backing_file = file;
39547 + lo->lo_backing_virt_file = virt_file;
39548 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39549 mapping_set_gfp_mask(file->f_mapping,
39550 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39551 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39555 + if (old_virt_file)
39556 + fput(old_virt_file);
39558 loop_reread_partitions(lo);
39560 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39561 loop_global_unlock(lo, is_loop);
39569 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39570 const struct loop_config *config)
39572 struct file *file = fget(config->fd);
39573 + struct file *f, *virt_file = NULL;
39574 struct inode *inode;
39575 struct address_space *mapping;
39577 @@ -1028,6 +1052,13 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39578 /* This is safe, since we have a reference from open(). */
39579 __module_get(THIS_MODULE);
39581 + f = loop_real_file(file);
39583 + virt_file = file;
39589 * If we don't hold exclusive handle for the device, upgrade to it
39590 * here to avoid changing device under exclusive owner.
39591 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39592 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39593 lo->lo_device = bdev;
39594 lo->lo_backing_file = file;
39595 + lo->lo_backing_virt_file = virt_file;
39596 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39597 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39599 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39600 bd_abort_claiming(bdev, loop_configure);
39605 /* This is safe: open() is still holding a reference. */
39606 module_put(THIS_MODULE);
39608 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39609 static void __loop_clr_fd(struct loop_device *lo, bool release)
39612 + struct file *virt_filp = lo->lo_backing_virt_file;
39613 gfp_t gfp = lo->old_gfp_mask;
39615 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39616 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39617 spin_lock_irq(&lo->lo_lock);
39618 filp = lo->lo_backing_file;
39619 lo->lo_backing_file = NULL;
39620 + lo->lo_backing_virt_file = NULL;
39621 spin_unlock_irq(&lo->lo_lock);
39623 lo->lo_device = NULL;
39624 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39625 * fput can take open_mutex which is usually taken before lo_mutex.
39632 static int loop_clr_fd(struct loop_device *lo)
39633 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39634 index 6b9cfc26b56b..e8878a13a0c8 100644
39635 --- a/fs/aufs/f_op.c
39636 +++ b/fs/aufs/f_op.c
39637 @@ -309,7 +309,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39638 if (IS_ERR(h_file))
39641 - if (au_test_loopback_kthread()) {
39642 + if (0 && au_test_loopback_kthread()) {
39643 au_warn_loopback(h_file->f_path.dentry->d_sb);
39644 if (file->f_mapping != h_file->f_mapping) {
39645 file->f_mapping = h_file->f_mapping;
39646 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39647 index 58043e31e5f3..e2bfae6f9d59 100644
39648 --- a/fs/aufs/loop.c
39649 +++ b/fs/aufs/loop.c
39650 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39651 symbol_put(loop_backing_file);
39652 au_kfree_try_rcu(au_warn_loopback_array);
39655 +/* ---------------------------------------------------------------------- */
39657 +/* support the loopback block device insude aufs */
39659 +struct file *aufs_real_loop(struct file *file)
39663 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39664 + fi_read_lock(file);
39665 + f = au_hf_top(file);
39666 + fi_read_unlock(file);
39670 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39671 index 03d4908a6c03..34d356e181d5 100644
39672 --- a/fs/aufs/loop.h
39673 +++ b/fs/aufs/loop.h
39674 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39676 int au_loopback_init(void);
39677 void au_loopback_fin(void);
39679 +struct file *aufs_real_loop(struct file *file);
39681 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39683 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39685 AuStubInt0(au_loopback_init, void)
39686 AuStubVoid(au_loopback_fin, void)
39688 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39689 #endif /* BLK_DEV_LOOP */
39691 #endif /* __KERNEL__ */
39692 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39693 index 81922d4faf54..c8a62c267d72 100644
39694 --- a/fs/aufs/super.c
39695 +++ b/fs/aufs/super.c
39696 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39697 .show_options = aufs_show_options,
39698 .statfs = aufs_statfs,
39699 .put_super = aufs_put_super,
39700 - .sync_fs = aufs_sync_fs
39701 + .sync_fs = aufs_sync_fs,
39702 +#ifdef CONFIG_AUFS_BDEV_LOOP
39703 + .real_loop = aufs_real_loop
39707 /* ---------------------------------------------------------------------- */
39708 diff --git a/include/linux/fs.h b/include/linux/fs.h
39709 index 5a2db7b8eca5..fc74b8e852c3 100644
39710 --- a/include/linux/fs.h
39711 +++ b/include/linux/fs.h
39712 @@ -1944,6 +1944,11 @@ struct super_operations {
39713 long (*free_cached_objects)(struct super_block *,
39714 struct shrink_control *);
39715 void (*shutdown)(struct super_block *sb);
39717 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39719 + struct file *(*real_loop)(struct file *);