1 SPDX-License-Identifier: GPL-2.0
2 aufs6.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index aa7e03cc1941..bf780967b6c4 100644
8 @@ -331,6 +331,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 f9541f40be4e..3a0e13ee39e7 100644
20 @@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
21 obj-$(CONFIG_EROFS_FS) += erofs/
22 obj-$(CONFIG_VBOXSF_FS) += vboxsf/
23 obj-$(CONFIG_ZONEFS_FS) += zonefs/
24 +obj-$(CONFIG_AUFS_FS) += aufs/
25 SPDX-License-Identifier: GPL-2.0
26 aufs6.x-rcN base patch
28 diff --git a/MAINTAINERS b/MAINTAINERS
29 index bf0f54c24f81..39b1844bce57 100644
32 @@ -3316,6 +3316,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 9f2d412fc560..1fefc6a8d049 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 25ac74d30bff..6c930ceed526 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 e871009f6c88..d62e114c1b1a 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 int arg)
103 +int setfl(int fd, struct file * filp, unsigned int arg)
105 struct inode * inode = file_inode(filp);
107 @@ -64,6 +64,8 @@ static int setfl(int fd, struct file * filp, unsigned int 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 d983d375ff11..7216ef993b5f 100644
137 @@ -925,8 +925,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 4aeb3fa11927..dd5871d0c429 100644
150 --- a/include/linux/fs.h
151 +++ b/include/linux/fs.h
152 @@ -1099,6 +1099,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 int arg);
157 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
158 extern int f_setown(struct file *filp, int who, int force);
159 extern void f_delown(struct file *filp);
160 @@ -1901,6 +1902,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 dc2844b071c2..069ffb776c2c 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 e85b5ad3e206..db4297f60bd3 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
238 aufs6.x-rcN mmap patch
240 diff --git a/fs/proc/base.c b/fs/proc/base.c
241 index ffd54617c354..29ec720c8038 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 3dd5be96691b..40d9d970b308 100644
271 --- a/fs/proc/task_mmu.c
272 +++ b/fs/proc/task_mmu.c
273 @@ -271,7 +271,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 @@ -1943,7 +1946,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 a8ac0dd8041e..9fca456e2259 100644
296 --- a/fs/proc/task_nommu.c
297 +++ b/fs/proc/task_nommu.c
298 @@ -137,7 +137,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 bf5d0b1b16f4..94b956eff452 100644
312 --- a/include/linux/mm.h
313 +++ b/include/linux/mm.h
314 @@ -2409,6 +2409,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 36c5b43999e6..ce93e97f76a6 100644
360 --- a/include/linux/mm_types.h
361 +++ b/include/linux/mm_types.h
362 @@ -524,6 +524,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 @@ -637,6 +640,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 3b6d20dfb9a8..ccad0325cfa9 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 ec65984e2ade..d59461647ccd 100644
399 @@ -138,3 +138,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 582f5317ff71..c024ebb30073 100644
408 @@ -3599,7 +3599,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 b56a7f0c9f85..5eb114409e07 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 @@ -554,7 +554,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 @@ -2364,7 +2364,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 @@ -2781,7 +2781,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 @@ -2876,7 +2876,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
459 if (file || vma->vm_file) {
461 - fput(vma->vm_file);
465 vma_iter_set(&vmi, vma->vm_end);
466 @@ -2938,6 +2938,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 @@ -2996,10 +2999,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, /*vm_flags*/0, 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, 0, pgoff, &populate, NULL);
507 +#endif /* CONFIG_AUFS_FS */
509 mmap_write_unlock(mm);
511 @@ -3350,7 +3377,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 if (vma_link(mm, new_vma))
520 @@ -3364,7 +3391,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 7f9e9e5a0e12..69663f2bd4c4 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 @@ -603,7 +603,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 @@ -1135,7 +1135,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 @@ -1221,10 +1221,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.x-rcN standalone patch
668 diff --git a/fs/dcache.c b/fs/dcache.c
669 index 6c930ceed526..576ad162cdec 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 @@ -3051,6 +3052,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 6518e33ea813..b67efac6a1ad 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 d62e114c1b1a..ceef001775bd 100644
704 @@ -87,6 +87,7 @@ int setfl(int fd, struct file * filp, unsigned int 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 ee21b3da9d08..c45ac36795dd 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 98f6601fbac6..8624e4ffa15b 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 4771701c896b..c79270aba792 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 7216ef993b5f..7ce1f1bc4268 100644
800 @@ -932,6 +932,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 efd4736bc94b..ce1a2c39ab23 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 db4297f60bd3..9aca18312afb 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 23b129d482a7..fca4c5707a1c 100644
843 --- a/security/security.c
844 +++ b/security/security.c
845 @@ -1750,6 +1750,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 @@ -1785,6 +1786,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 @@ -1803,6 +1805,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 @@ -1864,6 +1867,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 @@ -1881,6 +1885,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 @@ -2110,6 +2115,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 @@ -2588,6 +2594,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 @@ -2854,6 +2861,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-10-31 09:31:04.196547417 +0100
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-10-31 09:31:04.196547417 +0100
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 2023-10-10 22:51:18.033248030 +0200
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 + strscpy(p->a, str, sizeof(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-10-31 09:31:04.196547417 +0100
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)
7386 + struct timespec64 ctime;
7388 + if (!inode || IS_ERR(inode)) {
7389 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7393 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7394 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7395 + && sizeof(inode->i_blocks) != sizeof(u64));
7397 + n = (void *)wh->d_name.name;
7398 + l = wh->d_name.len;
7401 + ctime = inode_get_ctime(inode);
7402 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7403 + " acl %p, def_acl %p,"
7404 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7406 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7407 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7408 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7409 + inode->i_acl, inode->i_default_acl,
7410 + hn, (long long)timespec64_to_ns(&ctime) & 0x0ffff,
7411 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7412 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7413 + inode->i_generation,
7414 + l ? ", wh " : "", l, n);
7418 +void au_dpri_inode(struct inode *inode)
7420 + struct au_iinfo *iinfo;
7421 + struct au_hinode *hi;
7422 + aufs_bindex_t bindex;
7425 + err = do_pri_inode(-1, inode, -1, NULL);
7426 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7429 + iinfo = au_ii(inode);
7430 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7431 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7432 + if (iinfo->ii_btop < 0)
7435 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7436 + hi = au_hinode(iinfo, bindex);
7438 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7442 +void au_dpri_dalias(struct inode *inode)
7446 + spin_lock(&inode->i_lock);
7447 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7448 + au_dpri_dentry(d);
7449 + spin_unlock(&inode->i_lock);
7452 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7454 + struct dentry *wh = NULL;
7456 + struct inode *inode;
7457 + struct au_iinfo *iinfo;
7458 + struct au_hinode *hi;
7460 + if (!dentry || IS_ERR(dentry)) {
7461 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7464 + /* do not call dget_parent() here */
7465 + /* note: access d_xxx without d_lock */
7466 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7467 + bindex, dentry, dentry,
7468 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7469 + au_dcount(dentry), dentry->d_flags,
7470 + d_unhashed(dentry) ? "un" : "");
7473 + if (d_is_positive(dentry))
7474 + inode = d_inode(dentry);
7476 + && au_test_aufs(dentry->d_sb)
7478 + && !au_is_bad_inode(inode)) {
7479 + iinfo = au_ii(inode);
7480 + hi = au_hinode(iinfo, bindex);
7482 + wh = hi->hi_whdentry;
7484 + do_pri_inode(bindex, inode, hn, wh);
7488 +void au_dpri_dentry(struct dentry *dentry)
7490 + struct au_dinfo *dinfo;
7491 + aufs_bindex_t bindex;
7494 + err = do_pri_dentry(-1, dentry);
7495 + if (err || !au_test_aufs(dentry->d_sb))
7498 + dinfo = au_di(dentry);
7501 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7502 + dinfo->di_btop, dinfo->di_bbot,
7503 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7504 + dinfo->di_tmpfile);
7505 + if (dinfo->di_btop < 0)
7507 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7508 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7511 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7515 + if (!file || IS_ERR(file)) {
7516 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7521 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7522 + && au_test_aufs(file->f_path.dentry->d_sb)
7524 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7525 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7526 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7527 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7528 + file->f_version, file->f_pos, a);
7529 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7530 + do_pri_dentry(bindex, file->f_path.dentry);
7534 +void au_dpri_file(struct file *file)
7536 + struct au_finfo *finfo;
7537 + struct au_fidir *fidir;
7538 + struct au_hfile *hfile;
7539 + aufs_bindex_t bindex;
7542 + err = do_pri_file(-1, file);
7544 + || IS_ERR_OR_NULL(file->f_path.dentry)
7545 + || !au_test_aufs(file->f_path.dentry->d_sb))
7548 + finfo = au_fi(file);
7551 + if (finfo->fi_btop < 0)
7553 + fidir = finfo->fi_hdir;
7555 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7557 + for (bindex = finfo->fi_btop;
7558 + bindex >= 0 && bindex <= fidir->fd_bbot;
7560 + hfile = fidir->fd_hfile + bindex;
7561 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7565 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7567 + struct vfsmount *mnt;
7568 + struct super_block *sb;
7570 + if (!br || IS_ERR(br))
7572 + mnt = au_br_mnt(br);
7573 + if (!mnt || IS_ERR(mnt))
7576 + if (!sb || IS_ERR(sb))
7579 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7580 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7582 + bindex, br->br_perm, br->br_id, br->br_wbr,
7583 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7584 + sb->s_flags, sb->s_count,
7585 + atomic_read(&sb->s_active),
7586 + !!au_xino_file(br->br_xino, /*idx*/-1));
7590 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7594 +void au_dpri_sb(struct super_block *sb)
7596 + struct au_sbinfo *sbinfo;
7597 + aufs_bindex_t bindex;
7599 + /* to reduce stack size */
7601 + struct vfsmount mnt;
7602 + struct au_branch fake;
7605 + /* this function can be called from magic sysrq */
7606 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7607 + if (unlikely(!a)) {
7608 + dpri("no memory\n");
7612 + a->mnt.mnt_sb = sb;
7613 + a->fake.br_path.mnt = &a->mnt;
7614 + err = do_pri_br(-1, &a->fake);
7616 + dpri("dev 0x%x\n", sb->s_dev);
7617 + if (err || !au_test_aufs(sb))
7620 + sbinfo = au_sbi(sb);
7623 + dpri("nw %d, gen %u, kobj %d\n",
7624 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7625 + kref_read(&sbinfo->si_kobj.kref));
7626 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7627 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7630 +/* ---------------------------------------------------------------------- */
7632 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7634 + struct inode *h_inode, *inode = d_inode(dentry);
7635 + struct dentry *h_dentry;
7636 + aufs_bindex_t bindex, bbot, bi;
7638 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7641 + bbot = au_dbbot(dentry);
7642 + bi = au_ibbot(inode);
7645 + bindex = au_dbtop(dentry);
7646 + bi = au_ibtop(inode);
7650 + for (; bindex <= bbot; bindex++) {
7651 + h_dentry = au_h_dptr(dentry, bindex);
7654 + h_inode = au_h_iptr(inode, bindex);
7655 + if (unlikely(h_inode != d_inode(h_dentry))) {
7657 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7658 + AuDbgDentry(dentry);
7659 + AuDbgInode(inode);
7661 + if (au_test_fuse(h_inode->i_sb))
7669 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7672 + struct au_dcsub_pages dpages;
7673 + struct au_dpage *dpage;
7674 + struct dentry **dentries;
7676 + err = au_dpages_init(&dpages, GFP_NOFS);
7678 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7680 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7681 + dpage = dpages.dpages + i;
7682 + dentries = dpage->dentries;
7683 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7684 + AuDebugOn(au_digen_test(dentries[j], sigen));
7686 + au_dpages_free(&dpages);
7689 +void au_dbg_verify_kthread(void)
7691 + if (au_wkq_test()) {
7694 + * It may be recursive, but udba=notify between two aufs mounts,
7695 + * where a single ro branch is shared, is not a problem.
7701 +/* ---------------------------------------------------------------------- */
7703 +int __init au_debug_init(void)
7705 + aufs_bindex_t bindex;
7706 + struct au_vdir_destr destr;
7709 + AuDebugOn(bindex >= 0);
7712 + AuDebugOn(destr.len < NAME_MAX);
7714 +#ifdef CONFIG_4KSTACKS
7715 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7720 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7721 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7722 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7724 +/* SPDX-License-Identifier: GPL-2.0 */
7726 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7728 + * This program is free software; you can redistribute it and/or modify
7729 + * it under the terms of the GNU General Public License as published by
7730 + * the Free Software Foundation; either version 2 of the License, or
7731 + * (at your option) any later version.
7733 + * This program is distributed in the hope that it will be useful,
7734 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7735 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7736 + * GNU General Public License for more details.
7738 + * You should have received a copy of the GNU General Public License
7739 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7743 + * debug print functions
7746 +#ifndef __AUFS_DEBUG_H__
7747 +#define __AUFS_DEBUG_H__
7751 +#include <linux/atomic.h>
7752 +#include <linux/module.h>
7753 +#include <linux/kallsyms.h>
7754 +#include <linux/sysrq.h>
7756 +#ifdef CONFIG_AUFS_DEBUG
7757 +#define AuDebugOn(a) BUG_ON(a)
7759 +/* module parameter */
7760 +extern atomic_t aufs_debug;
7761 +static inline void au_debug_on(void)
7763 + atomic_inc(&aufs_debug);
7765 +static inline void au_debug_off(void)
7767 + atomic_dec_if_positive(&aufs_debug);
7770 +static inline int au_debug_test(void)
7772 + return atomic_read(&aufs_debug) > 0;
7775 +#define AuDebugOn(a) do {} while (0)
7776 +AuStubVoid(au_debug_on, void)
7777 +AuStubVoid(au_debug_off, void)
7778 +AuStubInt0(au_debug_test, void)
7779 +#endif /* CONFIG_AUFS_DEBUG */
7781 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7783 +/* ---------------------------------------------------------------------- */
7787 +#define AuDbg(fmt, ...) do { \
7788 + if (au_debug_test()) \
7789 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7791 +#define AuLabel(l) AuDbg(#l "\n")
7792 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7793 +#define AuWarn1(fmt, ...) do { \
7794 + static unsigned char _c; \
7796 + pr_warn(fmt, ##__VA_ARGS__); \
7799 +#define AuErr1(fmt, ...) do { \
7800 + static unsigned char _c; \
7802 + pr_err(fmt, ##__VA_ARGS__); \
7805 +#define AuIOErr1(fmt, ...) do { \
7806 + static unsigned char _c; \
7808 + AuIOErr(fmt, ##__VA_ARGS__); \
7811 +#define AuUnsupportMsg "This operation is not supported." \
7812 + " Please report this application to aufs-users ML."
7813 +#define AuUnsupport(fmt, ...) do { \
7814 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7818 +#define AuTraceErr(e) do { \
7819 + if (unlikely((e) < 0)) \
7820 + AuDbg("err %d\n", (int)(e)); \
7823 +#define AuTraceErrPtr(p) do { \
7825 + AuDbg("err %ld\n", PTR_ERR(p)); \
7828 +/* dirty macros for debug print, use with "%.*s" and caution */
7829 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7831 +/* ---------------------------------------------------------------------- */
7834 +#ifdef CONFIG_AUFS_DEBUG
7835 +extern struct mutex au_dbg_mtx;
7836 +extern char *au_plevel;
7838 +void au_dpri_whlist(struct au_nhash *whlist);
7840 +void au_dpri_vdir(struct au_vdir *vdir);
7842 +void au_dpri_inode(struct inode *inode);
7843 +void au_dpri_dalias(struct inode *inode);
7844 +void au_dpri_dentry(struct dentry *dentry);
7846 +void au_dpri_file(struct file *filp);
7847 +struct super_block;
7848 +void au_dpri_sb(struct super_block *sb);
7850 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7851 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7852 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7853 +void au_dbg_verify_kthread(void);
7855 +int __init au_debug_init(void);
7857 +#define AuDbgWhlist(w) do { \
7858 + mutex_lock(&au_dbg_mtx); \
7860 + au_dpri_whlist(w); \
7861 + mutex_unlock(&au_dbg_mtx); \
7864 +#define AuDbgVdir(v) do { \
7865 + mutex_lock(&au_dbg_mtx); \
7867 + au_dpri_vdir(v); \
7868 + mutex_unlock(&au_dbg_mtx); \
7871 +#define AuDbgInode(i) do { \
7872 + mutex_lock(&au_dbg_mtx); \
7874 + au_dpri_inode(i); \
7875 + mutex_unlock(&au_dbg_mtx); \
7878 +#define AuDbgDAlias(i) do { \
7879 + mutex_lock(&au_dbg_mtx); \
7881 + au_dpri_dalias(i); \
7882 + mutex_unlock(&au_dbg_mtx); \
7885 +#define AuDbgDentry(d) do { \
7886 + mutex_lock(&au_dbg_mtx); \
7888 + au_dpri_dentry(d); \
7889 + mutex_unlock(&au_dbg_mtx); \
7892 +#define AuDbgFile(f) do { \
7893 + mutex_lock(&au_dbg_mtx); \
7895 + au_dpri_file(f); \
7896 + mutex_unlock(&au_dbg_mtx); \
7899 +#define AuDbgSb(sb) do { \
7900 + mutex_lock(&au_dbg_mtx); \
7901 + AuDbg(#sb "\n"); \
7903 + mutex_unlock(&au_dbg_mtx); \
7906 +#define AuDbgSym(addr) do { \
7907 + char sym[KSYM_SYMBOL_LEN]; \
7908 + sprint_symbol(sym, (unsigned long)addr); \
7909 + AuDbg("%s\n", sym); \
7912 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7913 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7914 +AuStubVoid(au_dbg_verify_kthread, void)
7915 +AuStubInt0(__init au_debug_init, void)
7917 +#define AuDbgWhlist(w) do {} while (0)
7918 +#define AuDbgVdir(v) do {} while (0)
7919 +#define AuDbgInode(i) do {} while (0)
7920 +#define AuDbgDAlias(i) do {} while (0)
7921 +#define AuDbgDentry(d) do {} while (0)
7922 +#define AuDbgFile(f) do {} while (0)
7923 +#define AuDbgSb(sb) do {} while (0)
7924 +#define AuDbgSym(addr) do {} while (0)
7925 +#endif /* CONFIG_AUFS_DEBUG */
7927 +/* ---------------------------------------------------------------------- */
7929 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7930 +int __init au_sysrq_init(void);
7931 +void au_sysrq_fin(void);
7933 +#ifdef CONFIG_HW_CONSOLE
7934 +#define au_dbg_blocked() do { \
7936 + handle_sysrq('w'); \
7939 +AuStubVoid(au_dbg_blocked, void)
7943 +AuStubInt0(__init au_sysrq_init, void)
7944 +AuStubVoid(au_sysrq_fin, void)
7945 +AuStubVoid(au_dbg_blocked, void)
7946 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7948 +#endif /* __KERNEL__ */
7949 +#endif /* __AUFS_DEBUG_H__ */
7950 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7951 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7952 +++ linux/fs/aufs/dentry.c 2023-10-31 09:31:04.196547417 +0100
7954 +// SPDX-License-Identifier: GPL-2.0
7956 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7958 + * This program is free software; you can redistribute it and/or modify
7959 + * it under the terms of the GNU General Public License as published by
7960 + * the Free Software Foundation; either version 2 of the License, or
7961 + * (at your option) any later version.
7963 + * This program is distributed in the hope that it will be useful,
7964 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7966 + * GNU General Public License for more details.
7968 + * You should have received a copy of the GNU General Public License
7969 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7973 + * lookup and dentry operations
7976 +#include <linux/iversion.h>
7980 + * returns positive/negative dentry, NULL or an error.
7981 + * NULL means whiteout-ed or not-found.
7983 +static struct dentry*
7984 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7985 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7987 + struct dentry *h_dentry;
7988 + struct inode *h_inode;
7989 + struct au_branch *br;
7990 + struct mnt_idmap *h_idmap;
7991 + struct path h_path;
7992 + int wh_found, opq;
7993 + unsigned char wh_able;
7994 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7995 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7999 + br = au_sbr(dentry->d_sb, bindex);
8000 + h_path.dentry = h_parent;
8001 + h_path.mnt = au_br_mnt(br);
8002 + h_idmap = au_br_idmap(br);
8003 + wh_able = !!au_br_whable(br->br_perm);
8005 + wh_found = au_wh_test(h_idmap, &h_path, &args->whname,
8007 + h_dentry = ERR_PTR(wh_found);
8010 + if (unlikely(wh_found < 0))
8013 + /* We found a whiteout */
8014 + /* au_set_dbbot(dentry, bindex); */
8015 + au_set_dbwh(dentry, bindex);
8017 + return NULL; /* success */
8021 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8023 + h_dentry = au_sio_lkup_one(h_idmap, args->name, &h_path);
8024 + if (IS_ERR(h_dentry)) {
8025 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8031 + h_inode = d_inode(h_dentry);
8032 + if (d_is_negative(h_dentry)) {
8035 + } else if (wh_found
8036 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8038 + else if (au_ftest_lkup(args->flags, DIRREN)
8040 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8041 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8042 + (unsigned long long)h_inode->i_ino);
8046 + if (au_dbbot(dentry) <= bindex)
8047 + au_set_dbbot(dentry, bindex);
8048 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8049 + au_set_dbtop(dentry, bindex);
8050 + au_set_h_dptr(dentry, bindex, h_dentry);
8052 + if (!d_is_dir(h_dentry)
8054 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8055 + goto out; /* success */
8057 + h_path.dentry = h_dentry;
8058 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8059 + opq = au_diropq_test(h_idmap, &h_path);
8060 + inode_unlock_shared(h_inode);
8062 + au_set_dbdiropq(dentry, bindex);
8063 + else if (unlikely(opq < 0)) {
8064 + au_set_h_dptr(dentry, bindex, NULL);
8065 + h_dentry = ERR_PTR(opq);
8076 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8078 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8079 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8085 + * returns the number of lower positive dentries,
8086 + * otherwise an error.
8087 + * can be called at unlinking with @type is zero.
8089 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8090 + unsigned int flags)
8092 + int npositive, err;
8093 + aufs_bindex_t bindex, btail, bdiropq;
8094 + unsigned char isdir, dirperm1, dirren;
8095 + struct au_do_lookup_args args = {
8097 + .name = &dentry->d_name
8099 + struct dentry *parent;
8100 + struct super_block *sb;
8102 + sb = dentry->d_sb;
8103 + err = au_test_shwh(sb, args.name);
8104 + if (unlikely(err))
8107 + err = au_wh_name_alloc(&args.whname, args.name);
8108 + if (unlikely(err))
8111 + isdir = !!d_is_dir(dentry);
8112 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8113 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8115 + au_fset_lkup(args.flags, DIRREN);
8118 + parent = dget_parent(dentry);
8119 + btail = au_dbtaildir(parent);
8120 + for (bindex = btop; bindex <= btail; bindex++) {
8121 + struct dentry *h_parent, *h_dentry;
8122 + struct inode *h_inode, *h_dir;
8123 + struct au_branch *br;
8125 + h_dentry = au_h_dptr(dentry, bindex);
8127 + if (d_is_positive(h_dentry))
8131 + h_parent = au_h_dptr(parent, bindex);
8132 + if (!h_parent || !d_is_dir(h_parent))
8136 + /* if the inum matches, then use the prepared name */
8137 + err = au_dr_lkup_name(&args, bindex);
8138 + if (unlikely(err))
8142 + h_dir = d_inode(h_parent);
8143 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8144 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8145 + inode_unlock_shared(h_dir);
8146 + err = PTR_ERR(h_dentry);
8147 + if (IS_ERR(h_dentry))
8150 + au_fclr_lkup(args.flags, ALLOW_NEG);
8152 + au_fset_lkup(args.flags, IGNORE_PERM);
8154 + if (au_dbwh(dentry) == bindex)
8158 + if (d_is_negative(h_dentry))
8160 + h_inode = d_inode(h_dentry);
8163 + args.type = h_inode->i_mode & S_IFMT;
8164 + if (args.type != S_IFDIR)
8167 + /* the type of lower may be different */
8168 + bdiropq = au_dbdiropq(dentry);
8169 + if (bdiropq >= 0 && bdiropq <= bindex)
8172 + br = au_sbr(sb, bindex);
8174 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8175 + /*add_ent*/NULL)) {
8176 + /* prepare next name to lookup */
8177 + err = au_dr_lkup(&args, dentry, bindex);
8178 + if (unlikely(err))
8184 + AuLabel(positive);
8185 + au_update_dbtop(dentry);
8188 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8189 + && au_dbtop(dentry) < 0)) {
8191 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8197 + au_kfree_try_rcu(args.whname.name);
8199 + au_dr_lkup_fin(&args);
8204 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
8205 + struct path *ppath)
8207 + struct dentry *dentry;
8210 + if (!au_test_h_perm_sio(idmap, d_inode(ppath->dentry), MAY_EXEC))
8211 + dentry = vfsub_lkup_one(name, ppath);
8213 + struct vfsub_lkup_one_args args = {
8219 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8220 + if (unlikely(wkq_err))
8221 + dentry = ERR_PTR(wkq_err);
8228 + * lookup @dentry on @bindex which should be negative.
8230 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8233 + struct dentry *parent, *h_dentry;
8234 + struct au_branch *br;
8235 + struct mnt_idmap *h_idmap;
8236 + struct path h_ppath;
8238 + parent = dget_parent(dentry);
8239 + br = au_sbr(dentry->d_sb, bindex);
8240 + h_ppath.dentry = au_h_dptr(parent, bindex);
8241 + h_ppath.mnt = au_br_mnt(br);
8242 + h_idmap = au_br_idmap(br);
8244 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8246 + h_dentry = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
8247 + err = PTR_ERR(h_dentry);
8248 + if (IS_ERR(h_dentry))
8250 + if (unlikely(d_is_positive(h_dentry))) {
8252 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8258 + if (bindex < au_dbtop(dentry))
8259 + au_set_dbtop(dentry, bindex);
8260 + if (au_dbbot(dentry) < bindex)
8261 + au_set_dbbot(dentry, bindex);
8262 + au_set_h_dptr(dentry, bindex, h_dentry);
8269 +/* ---------------------------------------------------------------------- */
8271 +/* subset of struct inode */
8273 + unsigned long i_ino;
8274 + /* unsigned int i_nlink; */
8280 + blkcnt_t i_blocks;
8285 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8287 + ia->i_ino = h_inode->i_ino;
8288 + /* ia->i_nlink = h_inode->i_nlink; */
8289 + ia->i_uid = h_inode->i_uid;
8290 + ia->i_gid = h_inode->i_gid;
8291 + ia->i_version = inode_query_iversion(h_inode);
8293 + ia->i_size = h_inode->i_size;
8294 + ia->i_blocks = h_inode->i_blocks;
8296 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8299 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8301 + return ia->i_ino != h_inode->i_ino
8302 + /* || ia->i_nlink != h_inode->i_nlink */
8303 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8304 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8305 + || !inode_eq_iversion(h_inode, ia->i_version)
8307 + || ia->i_size != h_inode->i_size
8308 + || ia->i_blocks != h_inode->i_blocks
8310 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8313 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8314 + struct au_branch *br)
8317 + struct au_iattr ia;
8318 + struct inode *h_inode;
8319 + struct dentry *h_d;
8320 + struct super_block *h_sb;
8321 + struct path h_ppath;
8324 + memset(&ia, -1, sizeof(ia));
8325 + h_sb = h_dentry->d_sb;
8327 + if (d_is_positive(h_dentry)) {
8328 + h_inode = d_inode(h_dentry);
8329 + au_iattr_save(&ia, h_inode);
8330 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8331 + /* nfs d_revalidate may return 0 for negative dentry */
8332 + /* fuse d_revalidate always return 0 for negative dentry */
8335 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8336 + h_ppath.dentry = h_parent;
8337 + h_ppath.mnt = au_br_mnt(br);
8338 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8339 + err = PTR_ERR(h_d);
8344 + if (unlikely(h_d != h_dentry
8345 + || d_inode(h_d) != h_inode
8346 + || (h_inode && au_iattr_test(&ia, h_inode))))
8347 + err = au_busy_or_stale();
8355 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8356 + struct dentry *h_parent, struct au_branch *br)
8361 + if (udba == AuOpt_UDBA_REVAL
8362 + && !au_test_fs_remote(h_dentry->d_sb)) {
8364 + err = (d_inode(h_dentry->d_parent) != h_dir);
8365 + } else if (udba != AuOpt_UDBA_NONE)
8366 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8371 +/* ---------------------------------------------------------------------- */
8373 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8376 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8377 + struct au_hdentry tmp, *p, *q;
8378 + struct au_dinfo *dinfo;
8379 + struct super_block *sb;
8381 + DiMustWriteLock(dentry);
8383 + sb = dentry->d_sb;
8384 + dinfo = au_di(dentry);
8385 + bbot = dinfo->di_bbot;
8386 + bwh = dinfo->di_bwh;
8387 + bdiropq = dinfo->di_bdiropq;
8388 + bindex = dinfo->di_btop;
8389 + p = au_hdentry(dinfo, bindex);
8390 + for (; bindex <= bbot; bindex++, p++) {
8391 + if (!p->hd_dentry)
8394 + new_bindex = au_br_index(sb, p->hd_id);
8395 + if (new_bindex == bindex)
8398 + if (dinfo->di_bwh == bindex)
8400 + if (dinfo->di_bdiropq == bindex)
8401 + bdiropq = new_bindex;
8402 + if (new_bindex < 0) {
8404 + p->hd_dentry = NULL;
8408 + /* swap two lower dentries, and loop again */
8409 + q = au_hdentry(dinfo, new_bindex);
8413 + if (tmp.hd_dentry) {
8419 + dinfo->di_bwh = -1;
8420 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8421 + dinfo->di_bwh = bwh;
8423 + dinfo->di_bdiropq = -1;
8425 + && bdiropq <= au_sbbot(sb)
8426 + && au_sbr_whable(sb, bdiropq))
8427 + dinfo->di_bdiropq = bdiropq;
8430 + dinfo->di_btop = -1;
8431 + dinfo->di_bbot = -1;
8432 + bbot = au_dbbot(parent);
8434 + p = au_hdentry(dinfo, bindex);
8435 + for (; bindex <= bbot; bindex++, p++)
8436 + if (p->hd_dentry) {
8437 + dinfo->di_btop = bindex;
8441 + if (dinfo->di_btop >= 0) {
8443 + p = au_hdentry(dinfo, bindex);
8444 + for (; bindex >= 0; bindex--, p--)
8445 + if (p->hd_dentry) {
8446 + dinfo->di_bbot = bindex;
8455 +static void au_do_hide(struct dentry *dentry)
8457 + struct inode *inode;
8459 + if (d_really_is_positive(dentry)) {
8460 + inode = d_inode(dentry);
8461 + if (!d_is_dir(dentry)) {
8462 + if (inode->i_nlink && !d_unhashed(dentry))
8463 + drop_nlink(inode);
8465 + clear_nlink(inode);
8466 + /* stop next lookup */
8467 + inode->i_flags |= S_DEAD;
8469 + smp_mb(); /* necessary? */
8474 +static int au_hide_children(struct dentry *parent)
8476 + int err, i, j, ndentry;
8477 + struct au_dcsub_pages dpages;
8478 + struct au_dpage *dpage;
8479 + struct dentry *dentry;
8481 + err = au_dpages_init(&dpages, GFP_NOFS);
8482 + if (unlikely(err))
8484 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8485 + if (unlikely(err))
8488 + /* in reverse order */
8489 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8490 + dpage = dpages.dpages + i;
8491 + ndentry = dpage->ndentry;
8492 + for (j = ndentry - 1; j >= 0; j--) {
8493 + dentry = dpage->dentries[j];
8494 + if (dentry != parent)
8495 + au_do_hide(dentry);
8500 + au_dpages_free(&dpages);
8505 +static void au_hide(struct dentry *dentry)
8509 + AuDbgDentry(dentry);
8510 + if (d_is_dir(dentry)) {
8511 + /* shrink_dcache_parent(dentry); */
8512 + err = au_hide_children(dentry);
8513 + if (unlikely(err))
8514 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8517 + au_do_hide(dentry);
8521 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8523 + * a dirty branch is added
8524 + * - on the top of layers
8525 + * - in the middle of layers
8526 + * - to the bottom of layers
8528 + * on the added branch there exists
8531 + * - a same named entry
8533 + * * negative --> positive
8534 + * * positive --> positive
8535 + * - type is unchanged
8536 + * - type is changed
8538 + * * negative --> negative
8539 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8542 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8543 + struct au_dinfo *tmp)
8546 + aufs_bindex_t bindex, bbot;
8548 + struct dentry *dentry;
8549 + struct inode *inode;
8551 + } orig_h, tmp_h = {
8554 + struct au_hdentry *hd;
8555 + struct inode *inode, *h_inode;
8556 + struct dentry *h_dentry;
8559 + AuDebugOn(dinfo->di_btop < 0);
8561 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8562 + orig_h.inode = NULL;
8563 + if (d_is_positive(orig_h.dentry)) {
8564 + orig_h.inode = d_inode(orig_h.dentry);
8565 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8567 + if (tmp->di_btop >= 0) {
8568 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8569 + if (d_is_positive(tmp_h.dentry)) {
8570 + tmp_h.inode = d_inode(tmp_h.dentry);
8571 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8576 + if (d_really_is_positive(dentry))
8577 + inode = d_inode(dentry);
8578 + if (!orig_h.inode) {
8579 + AuDbg("negative originally\n");
8585 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8586 + AuDebugOn(dinfo->di_bdiropq != -1);
8588 + if (!tmp_h.inode) {
8589 + AuDbg("negative --> negative\n");
8590 + /* should have only one negative lower */
8591 + if (tmp->di_btop >= 0
8592 + && tmp->di_btop < dinfo->di_btop) {
8593 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8594 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8595 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8596 + au_di_cp(dinfo, tmp);
8597 + hd = au_hdentry(tmp, tmp->di_btop);
8598 + au_set_h_dptr(dentry, tmp->di_btop,
8599 + dget(hd->hd_dentry));
8601 + au_dbg_verify_dinode(dentry);
8603 + AuDbg("negative --> positive\n");
8605 + * similar to the behaviour of creating with bypassing
8607 + * unhash it in order to force an error in the
8608 + * succeeding create operation.
8609 + * we should not set S_DEAD here.
8612 + /* au_di_swap(tmp, dinfo); */
8613 + au_dbg_verify_dinode(dentry);
8616 + AuDbg("positive originally\n");
8617 + /* inode may be NULL */
8618 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8619 + if (!tmp_h.inode) {
8620 + AuDbg("positive --> negative\n");
8621 + /* or bypassing aufs */
8623 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8624 + dinfo->di_bwh = tmp->di_bwh;
8626 + err = au_refresh_hinode_self(inode);
8627 + au_dbg_verify_dinode(dentry);
8628 + } else if (orig_h.mode == tmp_h.mode) {
8629 + AuDbg("positive --> positive, same type\n");
8630 + if (!S_ISDIR(orig_h.mode)
8631 + && dinfo->di_btop > tmp->di_btop) {
8633 + * similar to the behaviour of removing and
8638 + err = au_refresh_hinode_self(inode);
8639 + au_dbg_verify_dinode(dentry);
8641 + /* fill empty slots */
8642 + if (dinfo->di_btop > tmp->di_btop)
8643 + dinfo->di_btop = tmp->di_btop;
8644 + if (dinfo->di_bbot < tmp->di_bbot)
8645 + dinfo->di_bbot = tmp->di_bbot;
8646 + dinfo->di_bwh = tmp->di_bwh;
8647 + dinfo->di_bdiropq = tmp->di_bdiropq;
8648 + bbot = dinfo->di_bbot;
8649 + bindex = tmp->di_btop;
8650 + hd = au_hdentry(tmp, bindex);
8651 + for (; bindex <= bbot; bindex++, hd++) {
8652 + if (au_h_dptr(dentry, bindex))
8654 + h_dentry = hd->hd_dentry;
8657 + AuDebugOn(d_is_negative(h_dentry));
8658 + h_inode = d_inode(h_dentry);
8659 + AuDebugOn(orig_h.mode
8660 + != (h_inode->i_mode
8662 + au_set_h_dptr(dentry, bindex,
8666 + err = au_refresh_hinode(inode, dentry);
8667 + au_dbg_verify_dinode(dentry);
8670 + AuDbg("positive --> positive, different type\n");
8671 + /* similar to the behaviour of removing and creating */
8674 + err = au_refresh_hinode_self(inode);
8675 + au_dbg_verify_dinode(dentry);
8683 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8685 + const struct dentry_operations *dop
8686 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8687 + static const unsigned int mask
8688 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8690 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8692 + if (dentry->d_op == dop)
8695 + AuDbg("%pd\n", dentry);
8696 + spin_lock(&dentry->d_lock);
8697 + if (dop == &aufs_dop)
8698 + dentry->d_flags |= mask;
8700 + dentry->d_flags &= ~mask;
8701 + dentry->d_op = dop;
8702 + spin_unlock(&dentry->d_lock);
8705 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8707 + int err, ebrange, nbr;
8708 + unsigned int sigen;
8709 + struct au_dinfo *dinfo, *tmp;
8710 + struct super_block *sb;
8711 + struct inode *inode;
8713 + DiMustWriteLock(dentry);
8714 + AuDebugOn(IS_ROOT(dentry));
8715 + AuDebugOn(d_really_is_negative(parent));
8717 + sb = dentry->d_sb;
8718 + sigen = au_sigen(sb);
8719 + err = au_digen_test(parent, sigen);
8720 + if (unlikely(err))
8723 + nbr = au_sbbot(sb) + 1;
8724 + dinfo = au_di(dentry);
8725 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8726 + if (unlikely(err))
8728 + ebrange = au_dbrange_test(dentry);
8730 + ebrange = au_do_refresh_hdentry(dentry, parent);
8732 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8733 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8734 + if (d_really_is_positive(dentry)) {
8735 + inode = d_inode(dentry);
8736 + err = au_refresh_hinode_self(inode);
8738 + au_dbg_verify_dinode(dentry);
8740 + goto out_dgen; /* success */
8744 + /* temporary dinfo */
8745 + AuDbgDentry(dentry);
8747 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8748 + if (unlikely(!tmp))
8750 + au_di_swap(tmp, dinfo);
8751 + /* returns the number of positive dentries */
8753 + * if current working dir is removed, it returns an error.
8754 + * but the dentry is legal.
8756 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8757 + AuDbgDentry(dentry);
8758 + au_di_swap(tmp, dinfo);
8759 + if (err == -ENOENT)
8762 + /* compare/refresh by dinfo */
8763 + AuDbgDentry(dentry);
8764 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8765 + au_dbg_verify_dinode(dentry);
8768 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8769 + au_rw_write_unlock(&tmp->di_rwsem);
8771 + if (unlikely(err))
8775 + au_update_digen(dentry);
8777 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8778 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8779 + AuDbgDentry(dentry);
8785 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8786 + struct dentry *dentry, aufs_bindex_t bindex)
8791 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8794 + AuDbg("b%d\n", bindex);
8796 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8797 + * due to whiteout and branch permission.
8799 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8800 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8801 + /* it may return tri-state */
8802 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8804 + if (unlikely(valid < 0))
8814 +/* todo: remove this */
8815 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8816 + unsigned int flags, int do_udba, int dirren)
8819 + umode_t mode, h_mode;
8820 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8821 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8822 + struct inode *h_inode, *h_cached_inode;
8823 + struct dentry *h_dentry;
8824 + struct qstr *name, *h_name;
8831 + unhashed = !!d_unhashed(dentry);
8832 + is_root = !!IS_ROOT(dentry);
8833 + name = &dentry->d_name;
8834 + tmpfile = au_di(dentry)->di_tmpfile;
8837 + * Theoretically, REVAL test should be unnecessary in case of
8839 + * But {fs,i}notify doesn't fire some necessary events,
8840 + * IN_ATTRIB for atime/nlink/pageio
8841 + * Let's do REVAL test too.
8843 + if (do_udba && inode) {
8844 + mode = (inode->i_mode & S_IFMT);
8845 + plus = (inode->i_nlink > 0);
8846 + ibs = au_ibtop(inode);
8847 + ibe = au_ibbot(inode);
8850 + btop = au_dbtop(dentry);
8852 + if (inode && S_ISDIR(inode->i_mode))
8853 + btail = au_dbtaildir(dentry);
8854 + for (bindex = btop; bindex <= btail; bindex++) {
8855 + h_dentry = au_h_dptr(dentry, bindex);
8859 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8860 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8861 + spin_lock(&h_dentry->d_lock);
8862 + h_name = &h_dentry->d_name;
8863 + if (unlikely(do_udba
8866 + && (unhashed != !!d_unhashed(h_dentry)
8867 + || (!tmpfile && !dirren
8868 + && !au_qstreq(name, h_name))
8871 + && !(flags & LOOKUP_OPEN)
8872 + && (h_dentry->d_flags
8873 + & DCACHE_NFSFS_RENAMED)))
8877 + h_unhashed = d_unhashed(h_dentry);
8878 + spin_unlock(&h_dentry->d_lock);
8879 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8880 + unhashed, h_unhashed, dentry, h_dentry);
8883 + spin_unlock(&h_dentry->d_lock);
8885 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8886 + if (unlikely(err))
8887 + /* do not goto err, to keep the errno */
8890 + /* todo: plink too? */
8895 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8899 + if (d_is_positive(h_dentry))
8900 + h_inode = d_inode(h_dentry);
8903 + h_cached_inode = h_inode;
8905 + h_mode = (h_inode->i_mode & S_IFMT);
8906 + h_plus = (h_inode->i_nlink > 0);
8908 + if (inode && ibs <= bindex && bindex <= ibe)
8909 + h_cached_inode = au_h_iptr(inode, bindex);
8912 + if (unlikely(plus != h_plus && !tmpfile))
8915 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8917 + && !IS_ROOT(h_dentry)
8918 + && unhashed != d_unhashed(h_dentry)))
8921 + if (unlikely(mode != h_mode
8922 + || h_cached_inode != h_inode))
8935 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8936 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8939 + struct dentry *parent;
8941 + if (!au_digen_test(dentry, sigen))
8944 + parent = dget_parent(dentry);
8945 + di_read_lock_parent(parent, AuLock_IR);
8946 + AuDebugOn(au_digen_test(parent, sigen));
8947 + au_dbg_verify_gen(parent, sigen);
8948 + err = au_refresh_dentry(dentry, parent);
8949 + di_read_unlock(parent, AuLock_IR);
8955 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8958 + struct dentry *d, *parent;
8960 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8961 + return simple_reval_dpath(dentry, sigen);
8963 + /* slow loop, keep it simple and stupid */
8964 + /* cf: au_cpup_dirs() */
8967 + while (au_digen_test(dentry, sigen)) {
8971 + parent = dget_parent(d);
8972 + if (!au_digen_test(parent, sigen))
8978 + di_write_lock_child2(d);
8980 + /* someone might update our dentry while we were sleeping */
8981 + if (au_digen_test(d, sigen)) {
8983 + * todo: consolidate with simple_reval_dpath(),
8984 + * do_refresh() and au_reval_for_attr().
8986 + di_read_lock_parent(parent, AuLock_IR);
8987 + err = au_refresh_dentry(d, parent);
8988 + di_read_unlock(parent, AuLock_IR);
8992 + di_write_unlock(d);
8994 + if (unlikely(err))
9002 + * if valid returns 1, otherwise 0.
9004 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9007 + unsigned int sigen;
9008 + unsigned char do_udba, dirren;
9009 + struct super_block *sb;
9010 + struct inode *inode;
9012 + /* todo: support rcu-walk? */
9013 + if (flags & LOOKUP_RCU)
9017 + if (unlikely(!au_di(dentry)))
9021 + sb = dentry->d_sb;
9024 + * i_mutex of parent dir may be held,
9025 + * but we should not return 'invalid' due to busy.
9027 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9028 + if (unlikely(err)) {
9034 + if (d_really_is_positive(dentry))
9035 + inode = d_inode(dentry);
9036 + if (unlikely(inode && au_is_bad_inode(inode))) {
9041 + if (unlikely(au_dbrange_test(dentry))) {
9047 + sigen = au_sigen(sb);
9048 + if (au_digen_test(dentry, sigen)) {
9049 + AuDebugOn(IS_ROOT(dentry));
9050 + err = au_reval_dpath(dentry, sigen);
9051 + if (unlikely(err)) {
9056 + di_downgrade_lock(dentry, AuLock_IR);
9059 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9061 + && !(inode->i_state && I_LINKABLE)
9062 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9067 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9068 + if (do_udba && inode) {
9069 + aufs_bindex_t btop = au_ibtop(inode);
9070 + struct inode *h_inode;
9073 + h_inode = au_h_iptr(inode, btop);
9074 + if (h_inode && au_test_higen(inode, h_inode)) {
9081 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9082 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9083 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9085 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9091 + di_downgrade_lock(dentry, AuLock_IR);
9093 + aufs_read_unlock(dentry, AuLock_IR);
9098 + AuDbg("%pd invalid, %d\n", dentry, valid);
9104 +static void aufs_d_release(struct dentry *dentry)
9106 + if (au_di(dentry)) {
9107 + au_di_fin(dentry);
9108 + au_hn_di_reinit(dentry);
9112 +const struct dentry_operations aufs_dop = {
9113 + .d_revalidate = aufs_d_revalidate,
9114 + .d_weak_revalidate = aufs_d_revalidate,
9115 + .d_release = aufs_d_release
9118 +/* aufs_dop without d_revalidate */
9119 +const struct dentry_operations aufs_dop_noreval = {
9120 + .d_release = aufs_d_release
9122 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9123 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9124 +++ linux/fs/aufs/dentry.h 2023-10-31 09:31:04.196547417 +0100
9126 +/* SPDX-License-Identifier: GPL-2.0 */
9128 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9130 + * This program is free software; you can redistribute it and/or modify
9131 + * it under the terms of the GNU General Public License as published by
9132 + * the Free Software Foundation; either version 2 of the License, or
9133 + * (at your option) any later version.
9135 + * This program is distributed in the hope that it will be useful,
9136 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9137 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9138 + * GNU General Public License for more details.
9140 + * You should have received a copy of the GNU General Public License
9141 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9145 + * lookup and dentry operations
9148 +#ifndef __AUFS_DENTRY_H__
9149 +#define __AUFS_DENTRY_H__
9153 +#include <linux/dcache.h>
9154 +#include "dirren.h"
9157 +struct au_hdentry {
9158 + struct dentry *hd_dentry;
9159 + aufs_bindex_t hd_id;
9163 + atomic_t di_generation;
9165 + struct au_rwsem di_rwsem;
9166 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9167 + unsigned char di_tmpfile; /* to allow the different name */
9168 + struct au_hdentry *di_hdentry;
9169 + struct file *di_htmpfile;
9170 + struct rcu_head rcu;
9171 +} ____cacheline_aligned_in_smp;
9173 +/* ---------------------------------------------------------------------- */
9175 +/* flags for au_lkup_dentry() */
9176 +#define AuLkup_ALLOW_NEG 1
9177 +#define AuLkup_IGNORE_PERM (1 << 1)
9178 +#define AuLkup_DIRREN (1 << 2)
9179 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9180 +#define au_fset_lkup(flags, name) \
9181 + do { (flags) |= AuLkup_##name; } while (0)
9182 +#define au_fclr_lkup(flags, name) \
9183 + do { (flags) &= ~AuLkup_##name; } while (0)
9185 +#ifndef CONFIG_AUFS_DIRREN
9186 +#undef AuLkup_DIRREN
9187 +#define AuLkup_DIRREN 0
9190 +struct au_do_lookup_args {
9191 + unsigned int flags;
9193 + struct qstr whname, *name;
9194 + struct au_dr_lookup dirren;
9197 +/* ---------------------------------------------------------------------- */
9200 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9202 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
9203 + struct path *ppath);
9204 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9205 + struct dentry *h_parent, struct au_branch *br);
9207 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9208 + unsigned int flags);
9209 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9210 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9211 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9212 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9215 +void au_di_init_once(void *_di);
9216 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9217 +void au_di_free(struct au_dinfo *dinfo);
9218 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9219 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9220 +int au_di_init(struct dentry *dentry);
9221 +void au_di_fin(struct dentry *dentry);
9222 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9224 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9225 +void di_read_unlock(struct dentry *d, int flags);
9226 +void di_downgrade_lock(struct dentry *d, int flags);
9227 +void di_write_lock(struct dentry *d, unsigned int lsc);
9228 +void di_write_unlock(struct dentry *d);
9229 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9230 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9231 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9233 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9234 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9235 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9236 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9238 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9239 + struct dentry *h_dentry);
9240 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9241 +int au_dbrange_test(struct dentry *dentry);
9242 +void au_update_digen(struct dentry *dentry);
9243 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9244 +void au_update_dbtop(struct dentry *dentry);
9245 +void au_update_dbbot(struct dentry *dentry);
9246 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9248 +/* ---------------------------------------------------------------------- */
9250 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9252 + return dentry->d_fsdata;
9255 +/* ---------------------------------------------------------------------- */
9257 +/* lock subclass for dinfo */
9259 + AuLsc_DI_CHILD, /* child first */
9260 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9261 + AuLsc_DI_CHILD3, /* copyup dirs */
9265 + AuLsc_DI_TMP /* temp for replacing dinfo */
9269 + * di_read_lock_child, di_write_lock_child,
9270 + * di_read_lock_child2, di_write_lock_child2,
9271 + * di_read_lock_child3, di_write_lock_child3,
9272 + * di_read_lock_parent, di_write_lock_parent,
9273 + * di_read_lock_parent2, di_write_lock_parent2,
9274 + * di_read_lock_parent3, di_write_lock_parent3,
9276 +#define AuReadLockFunc(name, lsc) \
9277 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9278 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9280 +#define AuWriteLockFunc(name, lsc) \
9281 +static inline void di_write_lock_##name(struct dentry *d) \
9282 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9284 +#define AuRWLockFuncs(name, lsc) \
9285 + AuReadLockFunc(name, lsc) \
9286 + AuWriteLockFunc(name, lsc)
9288 +AuRWLockFuncs(child, CHILD);
9289 +AuRWLockFuncs(child2, CHILD2);
9290 +AuRWLockFuncs(child3, CHILD3);
9291 +AuRWLockFuncs(parent, PARENT);
9292 +AuRWLockFuncs(parent2, PARENT2);
9293 +AuRWLockFuncs(parent3, PARENT3);
9295 +#undef AuReadLockFunc
9296 +#undef AuWriteLockFunc
9297 +#undef AuRWLockFuncs
9299 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9300 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9301 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9303 +/* ---------------------------------------------------------------------- */
9305 +/* todo: memory barrier? */
9306 +static inline unsigned int au_digen(struct dentry *d)
9308 + return atomic_read(&au_di(d)->di_generation);
9311 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9313 + hdentry->hd_dentry = NULL;
9316 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9317 + aufs_bindex_t bindex)
9319 + return di->di_hdentry + bindex;
9322 +static inline void au_hdput(struct au_hdentry *hd)
9325 + dput(hd->hd_dentry);
9328 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9330 + DiMustAnyLock(dentry);
9331 + return au_di(dentry)->di_btop;
9334 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9336 + DiMustAnyLock(dentry);
9337 + return au_di(dentry)->di_bbot;
9340 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9342 + DiMustAnyLock(dentry);
9343 + return au_di(dentry)->di_bwh;
9346 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9348 + DiMustAnyLock(dentry);
9349 + return au_di(dentry)->di_bdiropq;
9352 +/* todo: hard/soft set? */
9353 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9355 + DiMustWriteLock(dentry);
9356 + au_di(dentry)->di_btop = bindex;
9359 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9361 + DiMustWriteLock(dentry);
9362 + au_di(dentry)->di_bbot = bindex;
9365 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9367 + DiMustWriteLock(dentry);
9368 + /* dbwh can be outside of btop - bbot range */
9369 + au_di(dentry)->di_bwh = bindex;
9372 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9374 + DiMustWriteLock(dentry);
9375 + au_di(dentry)->di_bdiropq = bindex;
9378 +/* ---------------------------------------------------------------------- */
9380 +#ifdef CONFIG_AUFS_HNOTIFY
9381 +static inline void au_digen_dec(struct dentry *d)
9383 + atomic_dec(&au_di(d)->di_generation);
9386 +static inline void au_hn_di_reinit(struct dentry *dentry)
9388 + dentry->d_fsdata = NULL;
9391 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9392 +#endif /* CONFIG_AUFS_HNOTIFY */
9394 +#endif /* __KERNEL__ */
9395 +#endif /* __AUFS_DENTRY_H__ */
9396 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9397 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9398 +++ linux/fs/aufs/dinfo.c 2022-12-17 09:21:34.796521861 +0100
9400 +// SPDX-License-Identifier: GPL-2.0
9402 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9404 + * This program is free software; you can redistribute it and/or modify
9405 + * it under the terms of the GNU General Public License as published by
9406 + * the Free Software Foundation; either version 2 of the License, or
9407 + * (at your option) any later version.
9409 + * This program is distributed in the hope that it will be useful,
9410 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9411 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9412 + * GNU General Public License for more details.
9414 + * You should have received a copy of the GNU General Public License
9415 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9419 + * dentry private data
9424 +void au_di_init_once(void *_dinfo)
9426 + struct au_dinfo *dinfo = _dinfo;
9428 + au_rw_init(&dinfo->di_rwsem);
9431 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9433 + struct au_dinfo *dinfo;
9436 + dinfo = au_cache_alloc_dinfo();
9437 + if (unlikely(!dinfo))
9440 + nbr = au_sbbot(sb) + 1;
9443 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9444 + if (dinfo->di_hdentry) {
9445 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9446 + dinfo->di_btop = -1;
9447 + dinfo->di_bbot = -1;
9448 + dinfo->di_bwh = -1;
9449 + dinfo->di_bdiropq = -1;
9450 + dinfo->di_tmpfile = 0;
9451 + for (i = 0; i < nbr; i++)
9452 + dinfo->di_hdentry[i].hd_id = -1;
9453 + dinfo->di_htmpfile = NULL;
9457 + au_cache_free_dinfo(dinfo);
9464 +void au_di_free(struct au_dinfo *dinfo)
9466 + struct au_hdentry *p;
9467 + aufs_bindex_t bbot, bindex;
9469 + /* dentry may not be revalidated */
9470 + bindex = dinfo->di_btop;
9471 + if (bindex >= 0) {
9472 + bbot = dinfo->di_bbot;
9473 + p = au_hdentry(dinfo, bindex);
9474 + while (bindex++ <= bbot)
9477 + au_kfree_try_rcu(dinfo->di_hdentry);
9478 + au_cache_free_dinfo(dinfo);
9481 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9483 + struct au_hdentry *p;
9486 + AuRwMustWriteLock(&a->di_rwsem);
9487 + AuRwMustWriteLock(&b->di_rwsem);
9489 +#define DiSwap(v, name) \
9491 + v = a->di_##name; \
9492 + a->di_##name = b->di_##name; \
9493 + b->di_##name = v; \
9496 + DiSwap(p, hdentry);
9500 + DiSwap(bi, bdiropq);
9506 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9508 + AuRwMustWriteLock(&dst->di_rwsem);
9509 + AuRwMustWriteLock(&src->di_rwsem);
9511 + dst->di_btop = src->di_btop;
9512 + dst->di_bbot = src->di_bbot;
9513 + dst->di_bwh = src->di_bwh;
9514 + dst->di_bdiropq = src->di_bdiropq;
9518 +int au_di_init(struct dentry *dentry)
9521 + struct super_block *sb;
9522 + struct au_dinfo *dinfo;
9525 + sb = dentry->d_sb;
9526 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9528 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9529 + /* smp_mb(); */ /* atomic_set */
9530 + dentry->d_fsdata = dinfo;
9537 +void au_di_fin(struct dentry *dentry)
9539 + struct au_dinfo *dinfo;
9541 + dinfo = au_di(dentry);
9542 + AuRwDestroy(&dinfo->di_rwsem);
9543 + au_di_free(dinfo);
9546 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9549 + struct au_hdentry *hdp;
9551 + AuRwMustWriteLock(&dinfo->di_rwsem);
9554 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9556 + sz = sizeof(*hdp);
9557 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9560 + dinfo->di_hdentry = hdp;
9567 +/* ---------------------------------------------------------------------- */
9569 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9572 + case AuLsc_DI_CHILD:
9573 + ii_write_lock_child(inode);
9575 + case AuLsc_DI_CHILD2:
9576 + ii_write_lock_child2(inode);
9578 + case AuLsc_DI_CHILD3:
9579 + ii_write_lock_child3(inode);
9581 + case AuLsc_DI_PARENT:
9582 + ii_write_lock_parent(inode);
9584 + case AuLsc_DI_PARENT2:
9585 + ii_write_lock_parent2(inode);
9587 + case AuLsc_DI_PARENT3:
9588 + ii_write_lock_parent3(inode);
9595 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9598 + case AuLsc_DI_CHILD:
9599 + ii_read_lock_child(inode);
9601 + case AuLsc_DI_CHILD2:
9602 + ii_read_lock_child2(inode);
9604 + case AuLsc_DI_CHILD3:
9605 + ii_read_lock_child3(inode);
9607 + case AuLsc_DI_PARENT:
9608 + ii_read_lock_parent(inode);
9610 + case AuLsc_DI_PARENT2:
9611 + ii_read_lock_parent2(inode);
9613 + case AuLsc_DI_PARENT3:
9614 + ii_read_lock_parent3(inode);
9621 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9623 + struct inode *inode;
9625 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9626 + if (d_really_is_positive(d)) {
9627 + inode = d_inode(d);
9628 + if (au_ftest_lock(flags, IW))
9629 + do_ii_write_lock(inode, lsc);
9630 + else if (au_ftest_lock(flags, IR))
9631 + do_ii_read_lock(inode, lsc);
9635 +void di_read_unlock(struct dentry *d, int flags)
9637 + struct inode *inode;
9639 + if (d_really_is_positive(d)) {
9640 + inode = d_inode(d);
9641 + if (au_ftest_lock(flags, IW)) {
9642 + au_dbg_verify_dinode(d);
9643 + ii_write_unlock(inode);
9644 + } else if (au_ftest_lock(flags, IR)) {
9645 + au_dbg_verify_dinode(d);
9646 + ii_read_unlock(inode);
9649 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9652 +void di_downgrade_lock(struct dentry *d, int flags)
9654 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9655 + ii_downgrade_lock(d_inode(d));
9656 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9659 +void di_write_lock(struct dentry *d, unsigned int lsc)
9661 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9662 + if (d_really_is_positive(d))
9663 + do_ii_write_lock(d_inode(d), lsc);
9666 +void di_write_unlock(struct dentry *d)
9668 + au_dbg_verify_dinode(d);
9669 + if (d_really_is_positive(d))
9670 + ii_write_unlock(d_inode(d));
9671 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9674 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9676 + AuDebugOn(d1 == d2
9677 + || d_inode(d1) == d_inode(d2)
9678 + || d1->d_sb != d2->d_sb);
9680 + if ((isdir && au_test_subdir(d1, d2))
9682 + di_write_lock_child(d1);
9683 + di_write_lock_child2(d2);
9685 + di_write_lock_child(d2);
9686 + di_write_lock_child2(d1);
9690 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9692 + AuDebugOn(d1 == d2
9693 + || d_inode(d1) == d_inode(d2)
9694 + || d1->d_sb != d2->d_sb);
9696 + if ((isdir && au_test_subdir(d1, d2))
9698 + di_write_lock_parent(d1);
9699 + di_write_lock_parent2(d2);
9701 + di_write_lock_parent(d2);
9702 + di_write_lock_parent2(d1);
9706 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9708 + di_write_unlock(d1);
9709 + if (d_inode(d1) == d_inode(d2))
9710 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9712 + di_write_unlock(d2);
9715 +/* ---------------------------------------------------------------------- */
9717 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9721 + DiMustAnyLock(dentry);
9723 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9725 + AuDebugOn(bindex < 0);
9726 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9727 + AuDebugOn(d && au_dcount(d) <= 0);
9732 + * extended version of au_h_dptr().
9733 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9736 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9738 + struct dentry *h_dentry;
9739 + struct inode *inode, *h_inode;
9741 + AuDebugOn(d_really_is_negative(dentry));
9744 + if (au_dbtop(dentry) <= bindex
9745 + && bindex <= au_dbbot(dentry))
9746 + h_dentry = au_h_dptr(dentry, bindex);
9747 + if (h_dentry && !au_d_linkable(h_dentry)) {
9749 + goto out; /* success */
9752 + inode = d_inode(dentry);
9753 + AuDebugOn(bindex < au_ibtop(inode));
9754 + AuDebugOn(au_ibbot(inode) < bindex);
9755 + h_inode = au_h_iptr(inode, bindex);
9756 + h_dentry = d_find_alias(h_inode);
9758 + if (!IS_ERR(h_dentry)) {
9759 + if (!au_d_linkable(h_dentry))
9760 + goto out; /* success */
9766 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9767 + h_dentry = au_plink_lkup(inode, bindex);
9768 + AuDebugOn(!h_dentry);
9769 + if (!IS_ERR(h_dentry)) {
9770 + if (!au_d_hashed_positive(h_dentry))
9771 + goto out; /* success */
9778 + AuDbgDentry(h_dentry);
9782 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9784 + aufs_bindex_t bbot, bwh;
9786 + bbot = au_dbbot(dentry);
9788 + bwh = au_dbwh(dentry);
9791 + if (0 < bwh && bwh < bbot)
9797 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9799 + aufs_bindex_t bbot, bopq;
9801 + bbot = au_dbtail(dentry);
9803 + bopq = au_dbdiropq(dentry);
9804 + if (0 <= bopq && bopq < bbot)
9810 +/* ---------------------------------------------------------------------- */
9812 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9813 + struct dentry *h_dentry)
9815 + struct au_dinfo *dinfo;
9816 + struct au_hdentry *hd;
9817 + struct au_branch *br;
9819 + DiMustWriteLock(dentry);
9821 + dinfo = au_di(dentry);
9822 + hd = au_hdentry(dinfo, bindex);
9824 + hd->hd_dentry = h_dentry;
9826 + br = au_sbr(dentry->d_sb, bindex);
9827 + hd->hd_id = br->br_id;
9831 +int au_dbrange_test(struct dentry *dentry)
9834 + aufs_bindex_t btop, bbot;
9837 + btop = au_dbtop(dentry);
9838 + bbot = au_dbbot(dentry);
9840 + AuDebugOn(bbot < 0 && btop > bbot);
9843 + AuDebugOn(bbot >= 0);
9849 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9854 + if (unlikely(au_digen(dentry) != sigen
9855 + || au_iigen_test(d_inode(dentry), sigen)))
9861 +void au_update_digen(struct dentry *dentry)
9863 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9864 + /* smp_mb(); */ /* atomic_set */
9867 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9869 + struct au_dinfo *dinfo;
9870 + struct dentry *h_d;
9871 + struct au_hdentry *hdp;
9872 + aufs_bindex_t bindex, bbot;
9874 + DiMustWriteLock(dentry);
9876 + dinfo = au_di(dentry);
9877 + if (!dinfo || dinfo->di_btop < 0)
9880 + if (do_put_zero) {
9881 + bbot = dinfo->di_bbot;
9882 + bindex = dinfo->di_btop;
9883 + hdp = au_hdentry(dinfo, bindex);
9884 + for (; bindex <= bbot; bindex++, hdp++) {
9885 + h_d = hdp->hd_dentry;
9886 + if (h_d && d_is_negative(h_d))
9887 + au_set_h_dptr(dentry, bindex, NULL);
9891 + dinfo->di_btop = 0;
9892 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9893 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9894 + if (hdp->hd_dentry)
9896 + if (dinfo->di_btop > dinfo->di_bbot) {
9897 + dinfo->di_btop = -1;
9898 + dinfo->di_bbot = -1;
9902 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9903 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9904 + if (hdp->hd_dentry)
9906 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9909 +void au_update_dbtop(struct dentry *dentry)
9911 + aufs_bindex_t bindex, bbot;
9912 + struct dentry *h_dentry;
9914 + bbot = au_dbbot(dentry);
9915 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9916 + h_dentry = au_h_dptr(dentry, bindex);
9919 + if (d_is_positive(h_dentry)) {
9920 + au_set_dbtop(dentry, bindex);
9923 + au_set_h_dptr(dentry, bindex, NULL);
9927 +void au_update_dbbot(struct dentry *dentry)
9929 + aufs_bindex_t bindex, btop;
9930 + struct dentry *h_dentry;
9932 + btop = au_dbtop(dentry);
9933 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9934 + h_dentry = au_h_dptr(dentry, bindex);
9937 + if (d_is_positive(h_dentry)) {
9938 + au_set_dbbot(dentry, bindex);
9941 + au_set_h_dptr(dentry, bindex, NULL);
9945 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9947 + aufs_bindex_t bindex, bbot;
9949 + bbot = au_dbbot(dentry);
9950 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9951 + if (au_h_dptr(dentry, bindex) == h_dentry)
9955 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9956 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9957 +++ linux/fs/aufs/dir.c 2023-10-31 09:31:04.196547417 +0100
9959 +// SPDX-License-Identifier: GPL-2.0
9961 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9963 + * This program is free software; you can redistribute it and/or modify
9964 + * it under the terms of the GNU General Public License as published by
9965 + * the Free Software Foundation; either version 2 of the License, or
9966 + * (at your option) any later version.
9968 + * This program is distributed in the hope that it will be useful,
9969 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9970 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9971 + * GNU General Public License for more details.
9973 + * You should have received a copy of the GNU General Public License
9974 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9978 + * directory operations
9981 +#include <linux/fs_stack.h>
9982 +#include <linux/iversion.h>
9985 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9987 + unsigned int nlink;
9989 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9991 + nlink = dir->i_nlink;
9992 + nlink += h_dir->i_nlink - 2;
9993 + if (h_dir->i_nlink < 2)
9995 + smp_mb(); /* for i_nlink */
9996 + /* 0 can happen in revaliding */
9997 + set_nlink(dir, nlink);
10000 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10002 + unsigned int nlink;
10004 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10006 + nlink = dir->i_nlink;
10007 + nlink -= h_dir->i_nlink - 2;
10008 + if (h_dir->i_nlink < 2)
10010 + smp_mb(); /* for i_nlink */
10011 + /* nlink == 0 means the branch-fs is broken */
10012 + set_nlink(dir, nlink);
10015 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10018 + aufs_bindex_t bindex, bbot;
10019 + struct file *h_file;
10020 + struct dentry *h_dentry;
10024 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10026 + bbot = au_fbbot_dir(file);
10027 + for (bindex = au_fbtop(file);
10028 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10030 + h_file = au_hf_dir(file, bindex);
10031 + if (h_file && file_inode(h_file))
10032 + sz += vfsub_f_size_read(h_file);
10035 + AuDebugOn(!dentry);
10036 + AuDebugOn(!d_is_dir(dentry));
10038 + bbot = au_dbtaildir(dentry);
10039 + for (bindex = au_dbtop(dentry);
10040 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10042 + h_dentry = au_h_dptr(dentry, bindex);
10043 + if (h_dentry && d_is_positive(h_dentry))
10044 + sz += i_size_read(d_inode(h_dentry));
10047 + if (sz < KMALLOC_MAX_SIZE)
10048 + sz = roundup_pow_of_two(sz);
10049 + if (sz > KMALLOC_MAX_SIZE)
10050 + sz = KMALLOC_MAX_SIZE;
10051 + else if (sz < NAME_MAX) {
10052 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10053 + sz = AUFS_RDBLK_DEF;
10058 +struct au_dir_ts_arg {
10059 + struct dentry *dentry;
10060 + aufs_bindex_t brid;
10063 +static void au_do_dir_ts(void *arg)
10065 + struct au_dir_ts_arg *a = arg;
10066 + struct au_dtime dt;
10067 + struct path h_path;
10068 + struct inode *dir, *h_dir;
10069 + struct super_block *sb;
10070 + struct au_branch *br;
10071 + struct au_hinode *hdir;
10073 + aufs_bindex_t btop, bindex;
10075 + sb = a->dentry->d_sb;
10076 + if (d_really_is_negative(a->dentry))
10078 + /* no dir->i_mutex lock */
10079 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10081 + dir = d_inode(a->dentry);
10082 + btop = au_ibtop(dir);
10083 + bindex = au_br_index(sb, a->brid);
10084 + if (bindex < btop)
10087 + br = au_sbr(sb, bindex);
10088 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10089 + if (!h_path.dentry)
10091 + h_path.mnt = au_br_mnt(br);
10092 + au_dtime_store(&dt, a->dentry, &h_path);
10094 + br = au_sbr(sb, btop);
10095 + if (!au_br_writable(br->br_perm))
10097 + h_path.dentry = au_h_dptr(a->dentry, btop);
10098 + h_path.mnt = au_br_mnt(br);
10099 + err = vfsub_mnt_want_write(h_path.mnt);
10102 + hdir = au_hi(dir, btop);
10103 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10104 + h_dir = au_h_iptr(dir, btop);
10105 + if (h_dir->i_nlink
10106 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10107 + dt.dt_h_path = h_path;
10108 + au_dtime_revert(&dt);
10110 + au_hn_inode_unlock(hdir);
10111 + vfsub_mnt_drop_write(h_path.mnt);
10112 + au_cpup_attr_timesizes(dir);
10115 + aufs_read_unlock(a->dentry, AuLock_DW);
10118 + au_nwt_done(&au_sbi(sb)->si_nowait);
10119 + au_kfree_try_rcu(arg);
10122 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10124 + int perm, wkq_err;
10125 + aufs_bindex_t btop;
10126 + struct au_dir_ts_arg *arg;
10127 + struct dentry *dentry;
10128 + struct super_block *sb;
10132 + dentry = d_find_any_alias(dir);
10133 + AuDebugOn(!dentry);
10134 + sb = dentry->d_sb;
10135 + btop = au_ibtop(dir);
10136 + if (btop == bindex) {
10137 + au_cpup_attr_timesizes(dir);
10141 + perm = au_sbr_perm(sb, btop);
10142 + if (!au_br_writable(perm))
10145 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10149 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10150 + arg->brid = au_sbr_id(sb, bindex);
10151 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10152 + if (unlikely(wkq_err)) {
10153 + pr_err("wkq %d\n", wkq_err);
10155 + au_kfree_try_rcu(arg);
10162 +/* ---------------------------------------------------------------------- */
10164 +static int reopen_dir(struct file *file)
10167 + unsigned int flags;
10168 + aufs_bindex_t bindex, btail, btop;
10169 + struct dentry *dentry, *h_dentry;
10170 + struct file *h_file;
10172 + /* open all lower dirs */
10173 + dentry = file->f_path.dentry;
10174 + btop = au_dbtop(dentry);
10175 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10176 + au_set_h_fptr(file, bindex, NULL);
10177 + au_set_fbtop(file, btop);
10179 + btail = au_dbtaildir(dentry);
10180 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10181 + au_set_h_fptr(file, bindex, NULL);
10182 + au_set_fbbot_dir(file, btail);
10184 + flags = vfsub_file_flags(file);
10185 + for (bindex = btop; bindex <= btail; bindex++) {
10186 + h_dentry = au_h_dptr(dentry, bindex);
10189 + h_file = au_hf_dir(file, bindex);
10193 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10194 + err = PTR_ERR(h_file);
10195 + if (IS_ERR(h_file))
10196 + goto out; /* close all? */
10197 + au_set_h_fptr(file, bindex, h_file);
10199 + au_update_figen(file);
10200 + /* todo: necessary? */
10201 + /* file->f_ra = h_file->f_ra; */
10208 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10211 + aufs_bindex_t bindex, btail;
10212 + struct dentry *dentry, *h_dentry;
10213 + struct vfsmount *mnt;
10215 + FiMustWriteLock(file);
10216 + AuDebugOn(h_file);
10219 + mnt = file->f_path.mnt;
10220 + dentry = file->f_path.dentry;
10221 + file->f_version = inode_query_iversion(d_inode(dentry));
10222 + bindex = au_dbtop(dentry);
10223 + au_set_fbtop(file, bindex);
10224 + btail = au_dbtaildir(dentry);
10225 + au_set_fbbot_dir(file, btail);
10226 + for (; !err && bindex <= btail; bindex++) {
10227 + h_dentry = au_h_dptr(dentry, bindex);
10231 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10232 + if (unlikely(err))
10234 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10235 + if (IS_ERR(h_file)) {
10236 + err = PTR_ERR(h_file);
10239 + au_set_h_fptr(file, bindex, h_file);
10241 + au_update_figen(file);
10242 + /* todo: necessary? */
10243 + /* file->f_ra = h_file->f_ra; */
10245 + return 0; /* success */
10248 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10249 + au_set_h_fptr(file, bindex, NULL);
10250 + au_set_fbtop(file, -1);
10251 + au_set_fbbot_dir(file, -1);
10256 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10257 + struct file *file)
10260 + struct super_block *sb;
10261 + struct au_fidir *fidir;
10264 + sb = file->f_path.dentry->d_sb;
10265 + si_read_lock(sb, AuLock_FLUSH);
10266 + fidir = au_fidir_alloc(sb);
10268 + struct au_do_open_args args = {
10269 + .open = do_open_dir,
10272 + err = au_do_open(file, &args);
10273 + if (unlikely(err))
10274 + au_kfree_rcu(fidir);
10276 + si_read_unlock(sb);
10280 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10281 + struct file *file)
10283 + struct au_vdir *vdir_cache;
10284 + struct au_finfo *finfo;
10285 + struct au_fidir *fidir;
10286 + struct au_hfile *hf;
10287 + aufs_bindex_t bindex, bbot;
10289 + finfo = au_fi(file);
10290 + fidir = finfo->fi_hdir;
10292 + au_hbl_del(&finfo->fi_hlist,
10293 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10294 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10296 + au_vdir_free(vdir_cache);
10298 + bindex = finfo->fi_btop;
10299 + if (bindex >= 0) {
10300 + hf = fidir->fd_hfile + bindex;
10302 + * calls fput() instead of filp_close(),
10303 + * since no dnotify or lock for the lower file.
10305 + bbot = fidir->fd_bbot;
10306 + for (; bindex <= bbot; bindex++, hf++)
10308 + au_hfput(hf, /*execed*/0);
10310 + au_kfree_rcu(fidir);
10311 + finfo->fi_hdir = NULL;
10313 + au_finfo_fin(file);
10317 +/* ---------------------------------------------------------------------- */
10319 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10322 + aufs_bindex_t bindex, bbot;
10323 + struct file *h_file;
10326 + bbot = au_fbbot_dir(file);
10327 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10328 + h_file = au_hf_dir(file, bindex);
10330 + err = vfsub_flush(h_file, id);
10335 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10337 + return au_do_flush(file, id, au_do_flush_dir);
10340 +/* ---------------------------------------------------------------------- */
10342 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10345 + aufs_bindex_t bbot, bindex;
10346 + struct inode *inode;
10347 + struct super_block *sb;
10350 + sb = dentry->d_sb;
10351 + inode = d_inode(dentry);
10352 + IMustLock(inode);
10353 + bbot = au_dbbot(dentry);
10354 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10355 + struct path h_path;
10357 + if (au_test_ro(sb, bindex, inode))
10359 + h_path.dentry = au_h_dptr(dentry, bindex);
10360 + if (!h_path.dentry)
10363 + h_path.mnt = au_sbr_mnt(sb, bindex);
10364 + err = vfsub_fsync(NULL, &h_path, datasync);
10370 +static int au_do_fsync_dir(struct file *file, int datasync)
10373 + aufs_bindex_t bbot, bindex;
10374 + struct file *h_file;
10375 + struct super_block *sb;
10376 + struct inode *inode;
10378 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10379 + if (unlikely(err))
10382 + inode = file_inode(file);
10383 + sb = inode->i_sb;
10384 + bbot = au_fbbot_dir(file);
10385 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10386 + h_file = au_hf_dir(file, bindex);
10387 + if (!h_file || au_test_ro(sb, bindex, inode))
10390 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10398 + * @file may be NULL
10400 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10404 + struct dentry *dentry;
10405 + struct inode *inode;
10406 + struct super_block *sb;
10409 + dentry = file->f_path.dentry;
10410 + inode = d_inode(dentry);
10411 + inode_lock(inode);
10412 + sb = dentry->d_sb;
10413 + si_noflush_read_lock(sb);
10415 + err = au_do_fsync_dir(file, datasync);
10417 + di_write_lock_child(dentry);
10418 + err = au_do_fsync_dir_no_file(dentry, datasync);
10420 + au_cpup_attr_timesizes(inode);
10421 + di_write_unlock(dentry);
10423 + fi_write_unlock(file);
10425 + si_read_unlock(sb);
10426 + inode_unlock(inode);
10430 +/* ---------------------------------------------------------------------- */
10432 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10435 + struct dentry *dentry;
10436 + struct inode *inode, *h_inode;
10437 + struct super_block *sb;
10439 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10441 + dentry = file->f_path.dentry;
10442 + inode = d_inode(dentry);
10443 + IMustLock(inode);
10445 + sb = dentry->d_sb;
10446 + si_read_lock(sb, AuLock_FLUSH);
10447 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10448 + if (unlikely(err))
10450 + err = au_alive_dir(dentry);
10452 + err = au_vdir_init(file);
10453 + di_downgrade_lock(dentry, AuLock_IR);
10454 + if (unlikely(err))
10457 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10458 + if (!au_test_nfsd()) {
10459 + err = au_vdir_fill_de(file, ctx);
10460 + fsstack_copy_attr_atime(inode, h_inode);
10463 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10464 + * encode_fh() and others.
10466 + atomic_inc(&h_inode->i_count);
10467 + di_read_unlock(dentry, AuLock_IR);
10468 + si_read_unlock(sb);
10469 + err = au_vdir_fill_de(file, ctx);
10470 + fsstack_copy_attr_atime(inode, h_inode);
10471 + fi_write_unlock(file);
10479 + di_read_unlock(dentry, AuLock_IR);
10480 + fi_write_unlock(file);
10482 + si_read_unlock(sb);
10486 +/* ---------------------------------------------------------------------- */
10488 +#define AuTestEmpty_WHONLY 1
10489 +#define AuTestEmpty_CALLED (1 << 1)
10490 +#define AuTestEmpty_SHWH (1 << 2)
10491 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10492 +#define au_fset_testempty(flags, name) \
10493 + do { (flags) |= AuTestEmpty_##name; } while (0)
10494 +#define au_fclr_testempty(flags, name) \
10495 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10497 +#ifndef CONFIG_AUFS_SHWH
10498 +#undef AuTestEmpty_SHWH
10499 +#define AuTestEmpty_SHWH 0
10502 +struct test_empty_arg {
10503 + struct dir_context ctx;
10504 + struct au_nhash *whlist;
10505 + unsigned int flags;
10507 + aufs_bindex_t bindex;
10510 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10511 + int namelen, loff_t offset __maybe_unused, u64 ino,
10512 + unsigned int d_type)
10514 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10516 + char *name = (void *)__name;
10519 + au_fset_testempty(arg->flags, CALLED);
10521 + if (name[0] == '.'
10522 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10523 + goto out; /* success */
10525 + if (namelen <= AUFS_WH_PFX_LEN
10526 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10527 + if (au_ftest_testempty(arg->flags, WHONLY)
10528 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10529 + arg->err = -ENOTEMPTY;
10533 + name += AUFS_WH_PFX_LEN;
10534 + namelen -= AUFS_WH_PFX_LEN;
10535 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10536 + arg->err = au_nhash_append_wh
10537 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10538 + au_ftest_testempty(arg->flags, SHWH));
10542 + AuTraceErr(arg->err);
10543 + return !arg->err;
10546 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10549 + struct file *h_file;
10550 + struct au_branch *br;
10552 + h_file = au_h_open(dentry, arg->bindex,
10553 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10554 + /*file*/NULL, /*force_wr*/0);
10555 + err = PTR_ERR(h_file);
10556 + if (IS_ERR(h_file))
10560 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10561 + && !file_inode(h_file)->i_nlink)
10566 + au_fclr_testempty(arg->flags, CALLED);
10568 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10571 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10575 + br = au_sbr(dentry->d_sb, arg->bindex);
10576 + au_lcnt_dec(&br->br_nfiles);
10581 +struct do_test_empty_args {
10583 + struct dentry *dentry;
10584 + struct test_empty_arg *arg;
10587 +static void call_do_test_empty(void *args)
10589 + struct do_test_empty_args *a = args;
10590 + *a->errp = do_test_empty(a->dentry, a->arg);
10593 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10595 + int err, wkq_err;
10596 + struct dentry *h_dentry;
10597 + struct inode *h_inode;
10598 + struct mnt_idmap *h_idmap;
10600 + h_idmap = au_sbr_idmap(dentry->d_sb, arg->bindex);
10601 + h_dentry = au_h_dptr(dentry, arg->bindex);
10602 + h_inode = d_inode(h_dentry);
10603 + /* todo: i_mode changes anytime? */
10604 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10605 + err = au_test_h_perm_sio(h_idmap, h_inode, MAY_EXEC | MAY_READ);
10606 + inode_unlock_shared(h_inode);
10608 + err = do_test_empty(dentry, arg);
10610 + struct do_test_empty_args args = {
10612 + .dentry = dentry,
10615 + unsigned int flags = arg->flags;
10617 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10618 + if (unlikely(wkq_err))
10620 + arg->flags = flags;
10626 +int au_test_empty_lower(struct dentry *dentry)
10629 + unsigned int rdhash;
10630 + aufs_bindex_t bindex, btop, btail;
10631 + struct au_nhash whlist;
10632 + struct test_empty_arg arg = {
10634 + .actor = test_empty_cb
10637 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10639 + SiMustAnyLock(dentry->d_sb);
10641 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10643 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10644 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10645 + if (unlikely(err))
10649 + arg.whlist = &whlist;
10650 + btop = au_dbtop(dentry);
10651 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10652 + au_fset_testempty(arg.flags, SHWH);
10653 + test_empty = do_test_empty;
10654 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10655 + test_empty = sio_test_empty;
10656 + arg.bindex = btop;
10657 + err = test_empty(dentry, &arg);
10658 + if (unlikely(err))
10661 + au_fset_testempty(arg.flags, WHONLY);
10662 + btail = au_dbtaildir(dentry);
10663 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10664 + struct dentry *h_dentry;
10666 + h_dentry = au_h_dptr(dentry, bindex);
10667 + if (h_dentry && d_is_positive(h_dentry)) {
10668 + arg.bindex = bindex;
10669 + err = test_empty(dentry, &arg);
10674 + au_nhash_wh_free(&whlist);
10679 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10682 + struct test_empty_arg arg = {
10684 + .actor = test_empty_cb
10687 + aufs_bindex_t bindex, btail;
10690 + arg.whlist = whlist;
10691 + arg.flags = AuTestEmpty_WHONLY;
10692 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10693 + au_fset_testempty(arg.flags, SHWH);
10694 + btail = au_dbtaildir(dentry);
10695 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10696 + struct dentry *h_dentry;
10698 + h_dentry = au_h_dptr(dentry, bindex);
10699 + if (h_dentry && d_is_positive(h_dentry)) {
10700 + arg.bindex = bindex;
10701 + err = sio_test_empty(dentry, &arg);
10708 +/* ---------------------------------------------------------------------- */
10710 +const struct file_operations aufs_dir_fop = {
10711 + .owner = THIS_MODULE,
10712 + .llseek = default_llseek,
10713 + .read = generic_read_dir,
10714 + .iterate_shared = aufs_iterate_shared,
10715 + .unlocked_ioctl = aufs_ioctl_dir,
10716 +#ifdef CONFIG_COMPAT
10717 + .compat_ioctl = aufs_compat_ioctl_dir,
10719 + .open = aufs_open_dir,
10720 + .release = aufs_release_dir,
10721 + .flush = aufs_flush_dir,
10722 + .fsync = aufs_fsync_dir
10724 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10725 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10726 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10728 +/* SPDX-License-Identifier: GPL-2.0 */
10730 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10732 + * This program is free software; you can redistribute it and/or modify
10733 + * it under the terms of the GNU General Public License as published by
10734 + * the Free Software Foundation; either version 2 of the License, or
10735 + * (at your option) any later version.
10737 + * This program is distributed in the hope that it will be useful,
10738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10740 + * GNU General Public License for more details.
10742 + * You should have received a copy of the GNU General Public License
10743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10747 + * directory operations
10750 +#ifndef __AUFS_DIR_H__
10751 +#define __AUFS_DIR_H__
10755 +#include <linux/fs.h>
10757 +/* ---------------------------------------------------------------------- */
10759 +/* need to be faster and smaller */
10762 + unsigned int nh_num;
10763 + struct hlist_head *nh_head;
10766 +struct au_vdir_destr {
10767 + unsigned char len;
10768 + unsigned char name[];
10771 +struct au_vdir_dehstr {
10772 + struct hlist_node hash;
10773 + struct au_vdir_destr *str;
10774 + struct rcu_head rcu;
10775 +} ____cacheline_aligned_in_smp;
10777 +struct au_vdir_de {
10779 + unsigned char de_type;
10780 + /* caution: packed */
10781 + struct au_vdir_destr de_str;
10784 +struct au_vdir_wh {
10785 + struct hlist_node wh_hash;
10786 +#ifdef CONFIG_AUFS_SHWH
10788 + aufs_bindex_t wh_bindex;
10789 + unsigned char wh_type;
10791 + aufs_bindex_t wh_bindex;
10793 + /* caution: packed */
10794 + struct au_vdir_destr wh_str;
10797 +union au_vdir_deblk_p {
10798 + unsigned char *deblk;
10799 + struct au_vdir_de *de;
10803 + unsigned char **vd_deblk;
10804 + unsigned long vd_nblk;
10806 + unsigned long ul;
10807 + union au_vdir_deblk_p p;
10811 + unsigned int vd_deblk_sz;
10812 + unsigned long vd_jiffy;
10813 + struct rcu_head rcu;
10814 +} ____cacheline_aligned_in_smp;
10816 +/* ---------------------------------------------------------------------- */
10819 +extern const struct file_operations aufs_dir_fop;
10820 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10821 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10822 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10823 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10824 +int au_test_empty_lower(struct dentry *dentry);
10825 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10828 +unsigned int au_rdhash_est(loff_t sz);
10829 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10830 +void au_nhash_wh_free(struct au_nhash *whlist);
10831 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10833 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10834 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10835 + unsigned int d_type, aufs_bindex_t bindex,
10836 + unsigned char shwh);
10837 +void au_vdir_free(struct au_vdir *vdir);
10838 +int au_vdir_init(struct file *file);
10839 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10842 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10844 +#ifdef CONFIG_AUFS_RDU
10846 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10847 +#ifdef CONFIG_COMPAT
10848 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10849 + unsigned long arg);
10852 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10853 + unsigned int cmd, unsigned long arg)
10854 +#ifdef CONFIG_COMPAT
10855 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10856 + unsigned int cmd, unsigned long arg)
10860 +#endif /* __KERNEL__ */
10861 +#endif /* __AUFS_DIR_H__ */
10862 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10863 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10864 +++ linux/fs/aufs/dirren.c 2023-10-10 22:51:18.033248030 +0200
10866 +// SPDX-License-Identifier: GPL-2.0
10868 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10870 + * This program is free software; you can redistribute it and/or modify
10871 + * it under the terms of the GNU General Public License as published by
10872 + * the Free Software Foundation; either version 2 of the License, or
10873 + * (at your option) any later version.
10875 + * This program is distributed in the hope that it will be useful,
10876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10878 + * GNU General Public License for more details.
10880 + * You should have received a copy of the GNU General Public License
10881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10885 + * special handling in renaming a directory
10886 + * in order to support looking-up the before-renamed name on the lower readonly
10890 +#include <linux/byteorder/generic.h>
10893 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10897 + idx = au_dr_ihash(ent->dr_h_ino);
10898 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10901 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10904 + struct hlist_bl_head *hbl;
10907 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10908 + hbl = dr->dr_h_ino + i;
10909 + hlist_bl_lock(hbl);
10910 + ret &= hlist_bl_empty(hbl);
10911 + hlist_bl_unlock(hbl);
10917 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10919 + struct au_dr_hino *found, *ent;
10920 + struct hlist_bl_head *hbl;
10921 + struct hlist_bl_node *pos;
10925 + idx = au_dr_ihash(ino);
10926 + hbl = dr->dr_h_ino + idx;
10927 + hlist_bl_lock(hbl);
10928 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10929 + if (ent->dr_h_ino == ino) {
10933 + hlist_bl_unlock(hbl);
10938 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10939 + struct au_dr_hino *add_ent)
10942 + struct hlist_bl_head *hbl;
10943 + struct hlist_bl_node *pos;
10944 + struct au_dr_hino *ent;
10947 + idx = au_dr_ihash(ino);
10948 + hbl = dr->dr_h_ino + idx;
10949 +#if 0 /* debug print */
10951 + struct hlist_bl_node *tmp;
10953 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10954 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10957 + hlist_bl_lock(hbl);
10958 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10959 + if (ent->dr_h_ino == ino) {
10963 + if (!found && add_ent)
10964 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10965 + hlist_bl_unlock(hbl);
10967 + if (!found && add_ent)
10968 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10973 +void au_dr_hino_free(struct au_dr_br *dr)
10976 + struct hlist_bl_head *hbl;
10977 + struct hlist_bl_node *pos, *tmp;
10978 + struct au_dr_hino *ent;
10980 + /* SiMustWriteLock(sb); */
10982 + for (i = 0; i < AuDirren_NHASH; i++) {
10983 + hbl = dr->dr_h_ino + i;
10984 + /* no spinlock since sbinfo must be write-locked */
10985 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10986 + au_kfree_rcu(ent);
10987 + INIT_HLIST_BL_HEAD(hbl);
10991 +/* returns the number of inodes or an error */
10992 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10993 + struct file *hinofile)
10997 + loff_t pos, oldsize;
10999 + struct inode *hinoinode;
11000 + struct hlist_bl_head *hbl;
11001 + struct hlist_bl_node *n1, *n2;
11002 + struct au_dr_hino *ent;
11004 + SiMustWriteLock(sb);
11005 + AuDebugOn(!au_br_writable(br->br_perm));
11007 + hinoinode = file_inode(hinofile);
11008 + oldsize = i_size_read(hinoinode);
11012 + hbl = br->br_dirren.dr_h_ino;
11013 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11014 + /* no bit-lock since sbinfo must be write-locked */
11015 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11016 + AuDbg("hi%llu, %pD2\n",
11017 + (unsigned long long)ent->dr_h_ino, hinofile);
11018 + u64 = cpu_to_be64(ent->dr_h_ino);
11019 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11020 + if (ssz == sizeof(u64))
11023 + /* write error */
11024 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11031 + /* regardless the error */
11032 + if (pos < oldsize) {
11033 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11041 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11048 + struct au_dr_hino *ent;
11049 + struct inode *hinoinode;
11050 + struct hlist_bl_head *hbl;
11054 + hbl = dr->dr_h_ino;
11055 + hinoinode = file_inode(hinofile);
11056 + sz = i_size_read(hinoinode);
11057 + AuDebugOn(sz % sizeof(u64));
11058 + n = sz / sizeof(u64);
11060 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11061 + if (unlikely(ssz != sizeof(u64))) {
11062 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11069 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11075 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11076 + AuDbg("hi%llu, %pD2\n",
11077 + (unsigned long long)ent->dr_h_ino, hinofile);
11078 + hidx = au_dr_ihash(ent->dr_h_ino);
11079 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11081 + goto out; /* success */
11084 + au_dr_hino_free(dr);
11091 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11092 + * @path is a switch to distinguish load and store.
11094 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11095 + struct au_branch *br, const struct path *path)
11098 + unsigned char load, suspend;
11099 + struct file *hinofile;
11100 + struct au_hinode *hdir;
11101 + struct inode *dir, *delegated;
11102 + struct path hinopath;
11103 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11104 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11106 + AuDebugOn(bindex < 0 && !br);
11107 + AuDebugOn(bindex >= 0 && br);
11112 + br = au_sbr(sb, bindex);
11115 + path = &br->br_path;
11116 + AuDebugOn(!au_br_writable(br->br_perm));
11117 + if (unlikely(!au_br_writable(br->br_perm)))
11123 + dir = d_inode(sb->s_root);
11124 + hdir = au_hinode(au_ii(dir), bindex);
11125 + dir = hdir->hi_inode;
11126 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11128 + dir = d_inode(path->dentry);
11129 + inode_lock_nested(dir, AuLsc_I_CHILD);
11131 + hinopath.mnt = path->mnt;
11132 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11133 + err = PTR_ERR(hinopath.dentry);
11134 + if (IS_ERR(hinopath.dentry))
11138 + flags = O_RDONLY;
11140 + if (d_is_negative(hinopath.dentry))
11141 + goto out_dput; /* success */
11143 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11144 + if (d_is_positive(hinopath.dentry)) {
11145 + delegated = NULL;
11146 + err = vfsub_unlink(dir, &hinopath, &delegated,
11149 + if (unlikely(err))
11150 + pr_err("ignored err %d, %pd2\n",
11151 + err, hinopath.dentry);
11152 + if (unlikely(err == -EWOULDBLOCK))
11157 + } else if (!d_is_positive(hinopath.dentry)) {
11158 + err = vfsub_create(dir, &hinopath, 0600,
11159 + /*want_excl*/false);
11161 + if (unlikely(err))
11164 + flags = O_WRONLY;
11166 + hinofile = vfsub_dentry_open(&hinopath, flags);
11168 + au_hn_inode_unlock(hdir);
11170 + inode_unlock(dir);
11171 + dput(hinopath.dentry);
11172 + AuTraceErrPtr(hinofile);
11173 + if (IS_ERR(hinofile)) {
11174 + err = PTR_ERR(hinofile);
11179 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11181 + err = au_dr_hino_store(sb, br, hinofile);
11186 + dput(hinopath.dentry);
11189 + au_hn_inode_unlock(hdir);
11191 + inode_unlock(dir);
11197 +/* ---------------------------------------------------------------------- */
11199 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11202 + struct kstatfs kstfs;
11204 + struct dentry *dentry;
11205 + struct super_block *sb;
11207 + err = vfs_statfs((void *)path, &kstfs);
11209 + if (unlikely(err))
11212 + /* todo: support for UUID */
11214 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11215 + brid->type = AuBrid_FSID;
11216 + brid->fsid = kstfs.f_fsid;
11218 + dentry = path->dentry;
11219 + sb = dentry->d_sb;
11222 + brid->type = AuBrid_DEV;
11231 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11232 + const struct path *path)
11235 + struct au_dr_br *dr;
11236 + struct hlist_bl_head *hbl;
11238 + dr = &br->br_dirren;
11239 + hbl = dr->dr_h_ino;
11240 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11241 + INIT_HLIST_BL_HEAD(hbl);
11243 + err = au_dr_brid_init(&dr->dr_brid, path);
11244 + if (unlikely(err))
11247 + if (au_opt_test(au_mntflags(sb), DIRREN))
11248 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11255 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11260 + if (au_br_writable(br->br_perm))
11261 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11263 + au_dr_hino_free(&br->br_dirren);
11268 +/* ---------------------------------------------------------------------- */
11270 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11271 + char *buf, size_t sz)
11274 + unsigned int major, minor;
11278 + err = snprintf(p, sz, "%d_", brid->type);
11279 + AuDebugOn(err > sz);
11282 + switch (brid->type) {
11283 + case AuBrid_Unset:
11285 + case AuBrid_UUID:
11286 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11288 + case AuBrid_FSID:
11289 + err = snprintf(p, sz, "%08x-%08x",
11290 + brid->fsid.val[0], brid->fsid.val[1]);
11293 + major = MAJOR(brid->dev);
11294 + minor = MINOR(brid->dev);
11295 + if (major <= 0xff && minor <= 0xff)
11296 + err = snprintf(p, sz, "%02x%02x", major, minor);
11298 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11301 + AuDebugOn(err > sz);
11304 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11305 + AuDebugOn(err > sz);
11312 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11315 + struct dentry *br_dentry;
11316 + struct inode *br_inode;
11318 + br_dentry = au_br_dentry(br);
11319 + br_inode = d_inode(br_dentry);
11320 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11321 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11322 + AuDebugOn(rlen > len);
11327 +/* ---------------------------------------------------------------------- */
11330 + * from the given @h_dentry, construct drinfo at @*fdata.
11331 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11334 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11335 + struct dentry *h_dentry,
11336 + unsigned char *allocated)
11339 + struct au_drinfo_fdata *f, *p;
11340 + struct au_drinfo *drinfo;
11341 + struct inode *h_inode;
11342 + struct qstr *qname;
11346 + h_inode = d_inode(h_dentry);
11347 + qname = &h_dentry->d_name;
11348 + drinfo = &f->drinfo;
11349 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11350 + drinfo->oldnamelen = qname->len;
11351 + if (*allocated < sizeof(*f) + qname->len) {
11352 + v = roundup_pow_of_two(*allocated + qname->len);
11353 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11354 + if (unlikely(!p)) {
11362 + drinfo = &f->drinfo;
11364 + memcpy(drinfo->oldname, qname->name, qname->len);
11365 + AuDbg("i%llu, %.*s\n",
11366 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11367 + drinfo->oldname);
11374 +/* callers have to free the return value */
11375 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11377 + struct au_drinfo *ret, *drinfo;
11378 + struct au_drinfo_fdata fdata;
11383 + ret = ERR_PTR(-EIO);
11385 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11386 + if (unlikely(ssz != sizeof(fdata))) {
11387 + AuIOErr("ssz %zd, %u, %pD2\n",
11388 + ssz, (unsigned int)sizeof(fdata), file);
11392 + fdata.magic = ntohl((__force __be32)fdata.magic);
11393 + switch (fdata.magic) {
11394 + case AUFS_DRINFO_MAGIC_V1:
11397 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11398 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11402 + drinfo = &fdata.drinfo;
11403 + len = drinfo->oldnamelen;
11405 + AuIOErr("broken drinfo %pD2\n", file);
11410 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11411 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11412 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11413 + (unsigned long long)drinfo->ino,
11414 + (unsigned long long)h_ino, file);
11415 + goto out; /* success */
11418 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11419 + if (unlikely(!ret)) {
11420 + ret = ERR_PTR(-ENOMEM);
11421 + AuTraceErrPtr(ret);
11426 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11427 + if (unlikely(ssz != len)) {
11428 + au_kfree_rcu(ret);
11429 + ret = ERR_PTR(-EIO);
11430 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11434 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11440 +/* ---------------------------------------------------------------------- */
11442 +/* in order to be revertible */
11443 +struct au_drinfo_rev_elm {
11445 + struct dentry *info_dentry;
11446 + struct au_drinfo *info_last;
11449 +struct au_drinfo_rev {
11450 + unsigned char already;
11451 + aufs_bindex_t nelm;
11452 + struct au_drinfo_rev_elm elm[];
11455 +/* todo: isn't it too large? */
11456 +struct au_drinfo_store {
11457 + struct path h_ppath;
11458 + struct dentry *h_dentry;
11459 + struct au_drinfo_fdata *fdata;
11460 + char *infoname; /* inside of whname, just after PFX */
11461 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11462 + aufs_bindex_t btgt, btail;
11463 + unsigned char no_sio,
11464 + allocated, /* current size of *fdata */
11465 + infonamelen, /* room size for p */
11466 + whnamelen, /* length of the generated name */
11467 + renameback; /* renamed back */
11470 +/* on rename(2) error, the caller should revert it using @elm */
11471 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11472 + struct au_drinfo_rev_elm *elm)
11477 + struct path infopath = {
11478 + .mnt = w->h_ppath.mnt
11480 + struct inode *h_dir, *h_inode, *delegated;
11481 + struct file *infofile;
11482 + struct qstr *qname;
11485 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11487 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11489 + AuTraceErrPtr(infopath.dentry);
11490 + if (IS_ERR(infopath.dentry)) {
11491 + err = PTR_ERR(infopath.dentry);
11496 + h_dir = d_inode(w->h_ppath.dentry);
11497 + if (elm && d_is_negative(infopath.dentry)) {
11498 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11500 + if (unlikely(err))
11502 + elm->created = 1;
11503 + elm->info_dentry = dget(infopath.dentry);
11506 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11507 + AuTraceErrPtr(infofile);
11508 + if (IS_ERR(infofile)) {
11509 + err = PTR_ERR(infofile);
11513 + h_inode = d_inode(infopath.dentry);
11514 + if (elm && i_size_read(h_inode)) {
11515 + h_inode = d_inode(w->h_dentry);
11516 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11517 + AuTraceErrPtr(elm->info_last);
11518 + if (IS_ERR(elm->info_last)) {
11519 + err = PTR_ERR(elm->info_last);
11520 + elm->info_last = NULL;
11521 + AuDebugOn(elm->info_dentry);
11526 + if (elm && w->renameback) {
11527 + delegated = NULL;
11528 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11530 + if (unlikely(err == -EWOULDBLOCK))
11536 + qname = &w->h_dentry->d_name;
11537 + len = sizeof(*w->fdata) + qname->len;
11539 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11540 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11541 + if (ssz == len) {
11542 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11543 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11544 + goto out_fput; /* success */
11549 + /* the caller should revert it using @elm */
11555 + dput(infopath.dentry);
11561 +struct au_call_drinfo_do_store_args {
11563 + struct au_drinfo_store *w;
11564 + struct au_drinfo_rev_elm *elm;
11567 +static void au_call_drinfo_do_store(void *args)
11569 + struct au_call_drinfo_do_store_args *a = args;
11571 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11574 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11575 + struct au_drinfo_rev_elm *elm)
11577 + int err, wkq_err;
11580 + err = au_drinfo_do_store(w, elm);
11582 + struct au_call_drinfo_do_store_args a = {
11587 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11588 + if (unlikely(wkq_err))
11596 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11597 + aufs_bindex_t btgt)
11601 + memset(w, 0, sizeof(*w));
11602 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11603 + strscpy(w->whname, AUFS_WH_DR_INFO_PFX, sizeof(AUFS_WH_DR_INFO_PFX));
11604 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11605 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11607 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11610 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11611 + if (unlikely(!w->fdata)) {
11615 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11622 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11624 + au_kfree_rcu(w->fdata);
11627 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11628 + struct au_drinfo_store *w)
11630 + struct au_drinfo_rev_elm *elm;
11631 + struct inode *h_dir, *delegated;
11633 + struct path infopath = {
11634 + .mnt = w->h_ppath.mnt
11637 + h_dir = d_inode(w->h_ppath.dentry);
11638 + IMustLock(h_dir);
11642 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11643 + AuDebugOn(elm->created && elm->info_last);
11644 + if (elm->created) {
11646 + delegated = NULL;
11647 + infopath.dentry = elm->info_dentry;
11648 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11651 + if (unlikely(err == -EWOULDBLOCK))
11653 + dput(elm->info_dentry);
11654 + } else if (elm->info_last) {
11656 + w->fdata->drinfo = *elm->info_last;
11657 + memcpy(w->fdata->drinfo.oldname,
11658 + elm->info_last->oldname,
11659 + elm->info_last->oldnamelen);
11660 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11661 + au_kfree_rcu(elm->info_last);
11663 + if (unlikely(err))
11664 + AuIOErr("%d, %s\n", err, w->whname);
11665 + /* go on even if err */
11669 +/* caller has to call au_dr_rename_fin() later */
11670 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11671 + struct qstr *dst_name, void *_rev)
11673 + int err, sz, nelm;
11674 + aufs_bindex_t bindex, btail;
11675 + struct au_drinfo_store work;
11676 + struct au_drinfo_rev *rev, **p;
11677 + struct au_drinfo_rev_elm *elm;
11678 + struct super_block *sb;
11679 + struct au_branch *br;
11680 + struct au_hinode *hdir;
11682 + err = au_drinfo_store_work_init(&work, btgt);
11684 + if (unlikely(err))
11688 + btail = au_dbtaildir(dentry);
11689 + nelm = btail - btgt;
11690 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11691 + rev = kcalloc(1, sz, GFP_NOFS);
11692 + if (unlikely(!rev)) {
11696 + rev->nelm = nelm;
11702 + sb = dentry->d_sb;
11703 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11704 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11705 + hdir = au_hi(d_inode(dentry), btgt);
11706 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11707 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11708 + work.h_dentry = au_h_dptr(dentry, bindex);
11709 + if (!work.h_dentry)
11712 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11713 + &work.allocated);
11715 + if (unlikely(err))
11718 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11719 + br = au_sbr(sb, bindex);
11720 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11721 + work.whnamelen += au_drinfo_name(br, work.infoname,
11722 + work.infonamelen);
11723 + AuDbg("whname %.*s, i%llu, %.*s\n",
11724 + work.whnamelen, work.whname,
11725 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11726 + work.fdata->drinfo.oldnamelen,
11727 + work.fdata->drinfo.oldname);
11729 + err = au_drinfo_store_sio(&work, elm);
11731 + if (unlikely(err))
11734 + if (unlikely(err)) {
11735 + /* revert all drinfo */
11736 + au_drinfo_store_rev(rev, &work);
11737 + au_kfree_try_rcu(rev);
11740 + au_hn_inode_unlock(hdir);
11743 + au_drinfo_store_work_fin(&work);
11748 +/* ---------------------------------------------------------------------- */
11750 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11751 + struct qstr *dst_name, void *_rev)
11753 + int err, already;
11755 + struct super_block *sb;
11756 + struct au_branch *br;
11757 + struct au_dr_br *dr;
11758 + struct dentry *h_dentry;
11759 + struct inode *h_inode;
11760 + struct au_dr_hino *ent;
11761 + struct au_drinfo_rev *rev, **p;
11763 + AuDbg("bindex %d\n", bindex);
11766 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11767 + if (unlikely(!ent))
11771 + br = au_sbr(sb, bindex);
11772 + dr = &br->br_dirren;
11773 + h_dentry = au_h_dptr(src, bindex);
11774 + h_inode = d_inode(h_dentry);
11775 + ino = h_inode->i_ino;
11776 + ent->dr_h_ino = ino;
11777 + already = au_dr_hino_test_add(dr, ino, ent);
11778 + AuDbg("b%d, hi%llu, already %d\n",
11779 + bindex, (unsigned long long)ino, already);
11781 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11786 + rev->already = already;
11787 + goto out; /* success */
11792 + au_dr_hino_del(dr, ent);
11793 + au_kfree_rcu(ent);
11800 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11802 + struct au_drinfo_rev *rev;
11803 + struct au_drinfo_rev_elm *elm;
11808 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11809 + dput(elm->info_dentry);
11810 + au_kfree_rcu(elm->info_last);
11812 + au_kfree_try_rcu(rev);
11815 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11818 + struct au_drinfo_store work;
11819 + struct au_drinfo_rev *rev = _rev;
11820 + struct super_block *sb;
11821 + struct au_branch *br;
11822 + struct inode *h_inode;
11823 + struct au_dr_br *dr;
11824 + struct au_dr_hino *ent;
11826 + err = au_drinfo_store_work_init(&work, btgt);
11827 + if (unlikely(err))
11831 + br = au_sbr(sb, btgt);
11832 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11833 + work.h_ppath.mnt = au_br_mnt(br);
11834 + au_drinfo_store_rev(rev, &work);
11835 + au_drinfo_store_work_fin(&work);
11836 + if (rev->already)
11839 + dr = &br->br_dirren;
11840 + h_inode = d_inode(work.h_ppath.dentry);
11841 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11843 + au_dr_hino_del(dr, ent);
11844 + au_kfree_rcu(ent);
11847 + au_kfree_try_rcu(rev);
11848 + if (unlikely(err))
11849 + pr_err("failed to remove dirren info\n");
11852 +/* ---------------------------------------------------------------------- */
11854 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11855 + char *whname, int whnamelen,
11856 + struct dentry **info_dentry)
11858 + struct au_drinfo *drinfo;
11860 + struct inode *h_dir;
11861 + struct path infopath;
11864 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11866 + *info_dentry = NULL;
11869 + h_dir = d_inode(h_ppath->dentry);
11870 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11871 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11872 + if (IS_ERR(infopath.dentry)) {
11873 + drinfo = (void *)infopath.dentry;
11877 + if (d_is_negative(infopath.dentry))
11878 + goto out_dput; /* success */
11880 + infopath.mnt = h_ppath->mnt;
11881 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11882 + inode_unlock_shared(h_dir);
11885 + drinfo = (void *)f;
11889 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11890 + if (IS_ERR_OR_NULL(drinfo))
11893 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11894 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11899 + dput(infopath.dentry);
11902 + inode_unlock_shared(h_dir);
11903 + AuTraceErrPtr(drinfo);
11907 +struct au_drinfo_do_load_args {
11908 + struct au_drinfo **drinfop;
11909 + struct path *h_ppath;
11912 + struct dentry **info_dentry;
11915 +static void au_call_drinfo_do_load(void *args)
11917 + struct au_drinfo_do_load_args *a = args;
11919 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11923 +struct au_drinfo_load {
11924 + struct path h_ppath;
11925 + struct qstr *qname;
11926 + unsigned char no_sio;
11928 + aufs_bindex_t ninfo;
11929 + struct au_drinfo **drinfo;
11932 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11933 + struct au_branch *br)
11935 + int err, wkq_err, whnamelen, e;
11936 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11937 + = AUFS_WH_DR_INFO_PFX;
11938 + struct au_drinfo *drinfo;
11939 + struct qstr oldname;
11940 + struct inode *h_dir, *delegated;
11941 + struct dentry *info_dentry;
11942 + struct path infopath;
11944 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11945 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11946 + sizeof(whname) - whnamelen);
11948 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11951 + struct au_drinfo_do_load_args args = {
11952 + .drinfop = &drinfo,
11953 + .h_ppath = &w->h_ppath,
11954 + .whname = whname,
11955 + .whnamelen = whnamelen,
11956 + .info_dentry = &info_dentry
11958 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11959 + if (unlikely(wkq_err))
11960 + drinfo = ERR_PTR(wkq_err);
11962 + err = PTR_ERR(drinfo);
11963 + if (IS_ERR_OR_NULL(drinfo))
11967 + oldname.len = drinfo->oldnamelen;
11968 + oldname.name = drinfo->oldname;
11969 + if (au_qstreq(w->qname, &oldname)) {
11970 + /* the name is renamed back */
11971 + au_kfree_rcu(drinfo);
11974 + infopath.dentry = info_dentry;
11975 + infopath.mnt = w->h_ppath.mnt;
11976 + h_dir = d_inode(w->h_ppath.dentry);
11977 + delegated = NULL;
11978 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11979 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11980 + inode_unlock(h_dir);
11982 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11983 + if (unlikely(e == -EWOULDBLOCK))
11986 + au_kfree_rcu(w->drinfo[bindex]);
11987 + w->drinfo[bindex] = drinfo;
11988 + dput(info_dentry);
11995 +/* ---------------------------------------------------------------------- */
11997 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11999 + struct au_drinfo **p = drinfo;
12002 + au_kfree_rcu(*drinfo++);
12003 + au_kfree_try_rcu(p);
12006 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12007 + aufs_bindex_t btgt)
12010 + struct au_drinfo_load w;
12011 + aufs_bindex_t bindex, bbot;
12012 + struct au_branch *br;
12013 + struct inode *h_dir;
12014 + struct au_dr_hino *ent;
12015 + struct super_block *sb;
12017 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12018 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12019 + AuLNPair(&lkup->whname), btgt);
12021 + sb = dentry->d_sb;
12022 + bbot = au_sbbot(sb);
12023 + w.ninfo = bbot + 1;
12024 + if (!lkup->dirren.drinfo) {
12025 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12026 + sizeof(*lkup->dirren.drinfo),
12028 + if (unlikely(!lkup->dirren.drinfo)) {
12032 + lkup->dirren.ninfo = w.ninfo;
12034 + w.drinfo = lkup->dirren.drinfo;
12035 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12036 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12037 + AuDebugOn(!w.h_ppath.dentry);
12038 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12039 + w.qname = &dentry->d_name;
12042 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12043 + br = au_sbr(sb, bindex);
12044 + err = au_drinfo_load(&w, bindex, br);
12045 + if (unlikely(err))
12047 + if (w.drinfo[bindex])
12051 + br = au_sbr(sb, btgt);
12052 + h_dir = d_inode(w.h_ppath.dentry);
12053 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12055 + au_dr_hino_del(&br->br_dirren, ent);
12056 + au_kfree_rcu(ent);
12058 + goto out; /* success */
12061 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12062 + lkup->dirren.ninfo = 0;
12063 + lkup->dirren.drinfo = NULL;
12069 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12071 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12074 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12077 + struct au_drinfo *drinfo;
12080 + if (!lkup->dirren.drinfo)
12082 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12083 + drinfo = lkup->dirren.drinfo[btgt];
12087 + au_kfree_try_rcu(lkup->whname.name);
12088 + lkup->whname.name = NULL;
12089 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12090 + lkup->dirren.dr_name.name = drinfo->oldname;
12091 + lkup->name = &lkup->dirren.dr_name;
12092 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12094 + AuDbg("name %.*s, whname %.*s, b%d\n",
12095 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12103 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12107 + struct au_drinfo *drinfo;
12110 + if (!lkup->dirren.drinfo)
12112 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12113 + drinfo = lkup->dirren.drinfo[bindex];
12117 + match = (drinfo->ino == h_ino);
12118 + AuDbg("match %d\n", match);
12124 +/* ---------------------------------------------------------------------- */
12126 +int au_dr_opt_set(struct super_block *sb)
12129 + aufs_bindex_t bindex, bbot;
12130 + struct au_branch *br;
12133 + bbot = au_sbbot(sb);
12134 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12135 + br = au_sbr(sb, bindex);
12136 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12142 +int au_dr_opt_flush(struct super_block *sb)
12145 + aufs_bindex_t bindex, bbot;
12146 + struct au_branch *br;
12149 + bbot = au_sbbot(sb);
12150 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12151 + br = au_sbr(sb, bindex);
12152 + if (au_br_writable(br->br_perm))
12153 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12159 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12162 + aufs_bindex_t bindex, bbot;
12163 + struct au_branch *br;
12167 + err = au_dr_opt_flush(sb);
12168 + if (unlikely(err))
12172 + bbot = au_sbbot(sb);
12173 + for (bindex = 0; bindex <= bbot; bindex++) {
12174 + br = au_sbr(sb, bindex);
12175 + au_dr_hino_free(&br->br_dirren);
12181 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12182 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12183 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12185 +/* SPDX-License-Identifier: GPL-2.0 */
12187 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12189 + * This program is free software; you can redistribute it and/or modify
12190 + * it under the terms of the GNU General Public License as published by
12191 + * the Free Software Foundation; either version 2 of the License, or
12192 + * (at your option) any later version.
12194 + * This program is distributed in the hope that it will be useful,
12195 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12196 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12197 + * GNU General Public License for more details.
12199 + * You should have received a copy of the GNU General Public License
12200 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12204 + * renamed dir info
12207 +#ifndef __AUFS_DIRREN_H__
12208 +#define __AUFS_DIRREN_H__
12212 +#include <linux/dcache.h>
12213 +#include <linux/statfs.h>
12214 +#include <linux/uuid.h>
12217 +#define AuDirren_NHASH 100
12219 +#ifdef CONFIG_AUFS_DIRREN
12220 +enum au_brid_type {
12227 +struct au_dr_brid {
12228 + enum au_brid_type type;
12230 + uuid_t uuid; /* unimplemented yet */
12236 +/* 20 is the max digits length of ulong 64 */
12237 +/* brid-type "_" uuid "_" inum */
12238 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12239 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12241 +struct au_dr_hino {
12242 + struct hlist_bl_node dr_hnode;
12247 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12248 + struct au_dr_brid dr_brid;
12251 +struct au_dr_lookup {
12252 + /* dr_name is pointed by struct au_do_lookup_args.name */
12253 + struct qstr dr_name; /* subset of dr_info */
12254 + aufs_bindex_t ninfo;
12255 + struct au_drinfo **drinfo;
12258 +struct au_dr_hino;
12260 +struct au_dr_br { };
12261 +struct au_dr_lookup { };
12264 +/* ---------------------------------------------------------------------- */
12267 +struct au_do_lookup_args;
12269 +#ifdef CONFIG_AUFS_DIRREN
12270 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12271 + struct au_dr_hino *add_ent);
12272 +void au_dr_hino_free(struct au_dr_br *dr);
12273 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12274 + const struct path *path);
12275 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12276 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12277 + struct qstr *dst_name, void *_rev);
12278 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12279 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12280 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12281 + aufs_bindex_t bindex);
12282 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12283 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12285 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12286 +int au_dr_opt_set(struct super_block *sb);
12287 +int au_dr_opt_flush(struct super_block *sb);
12288 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12290 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12291 + struct au_dr_hino *add_ent);
12292 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12293 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12294 + const struct path *path);
12295 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12296 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12297 + struct qstr *dst_name, void *_rev);
12298 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12299 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12301 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12302 + aufs_bindex_t bindex);
12303 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12304 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12305 + aufs_bindex_t bindex, ino_t h_ino);
12306 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12307 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12308 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12309 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12312 +/* ---------------------------------------------------------------------- */
12314 +#ifdef CONFIG_AUFS_DIRREN
12315 +static inline int au_dr_ihash(ino_t h_ino)
12317 + return h_ino % AuDirren_NHASH;
12320 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12323 +#endif /* __KERNEL__ */
12324 +#endif /* __AUFS_DIRREN_H__ */
12325 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12326 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12327 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12329 +// SPDX-License-Identifier: GPL-2.0
12331 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12333 + * This program is free software; you can redistribute it and/or modify
12334 + * it under the terms of the GNU General Public License as published by
12335 + * the Free Software Foundation; either version 2 of the License, or
12336 + * (at your option) any later version.
12338 + * This program is distributed in the hope that it will be useful,
12339 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12340 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12341 + * GNU General Public License for more details.
12343 + * You should have received a copy of the GNU General Public License
12344 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12348 + * dynamically customizable operations for regular files
12353 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12356 + * How large will these lists be?
12357 + * Usually just a few elements, 20-30 at most for each, I guess.
12359 +static struct hlist_bl_head dynop[AuDyLast];
12361 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12362 + const void *h_op)
12364 + struct au_dykey *key, *tmp;
12365 + struct hlist_bl_node *pos;
12368 + hlist_bl_lock(hbl);
12369 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12370 + if (tmp->dk_op.dy_hop == h_op) {
12371 + if (kref_get_unless_zero(&tmp->dk_kref))
12375 + hlist_bl_unlock(hbl);
12380 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12382 + struct au_dykey **k, *found;
12383 + const void *h_op = key->dk_op.dy_hop;
12387 + k = br->br_dykey;
12388 + for (i = 0; i < AuBrDynOp; i++)
12390 + if (k[i]->dk_op.dy_hop == h_op) {
12397 + spin_lock(&br->br_dykey_lock);
12398 + for (; i < AuBrDynOp; i++)
12400 + if (k[i]->dk_op.dy_hop == h_op) {
12408 + spin_unlock(&br->br_dykey_lock);
12409 + BUG_ON(i == AuBrDynOp); /* expand the array */
12415 +/* kref_get() if @key is already added */
12416 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12418 + struct au_dykey *tmp, *found;
12419 + struct hlist_bl_node *pos;
12420 + const void *h_op = key->dk_op.dy_hop;
12423 + hlist_bl_lock(hbl);
12424 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12425 + if (tmp->dk_op.dy_hop == h_op) {
12426 + if (kref_get_unless_zero(&tmp->dk_kref))
12431 + hlist_bl_add_head(&key->dk_hnode, hbl);
12432 + hlist_bl_unlock(hbl);
12439 +static void dy_free_rcu(struct rcu_head *rcu)
12441 + struct au_dykey *key;
12443 + key = container_of(rcu, struct au_dykey, dk_rcu);
12448 +static void dy_free(struct kref *kref)
12450 + struct au_dykey *key;
12451 + struct hlist_bl_head *hbl;
12453 + key = container_of(kref, struct au_dykey, dk_kref);
12454 + hbl = dynop + key->dk_op.dy_type;
12455 + au_hbl_del(&key->dk_hnode, hbl);
12456 + call_rcu(&key->dk_rcu, dy_free_rcu);
12459 +void au_dy_put(struct au_dykey *key)
12461 + kref_put(&key->dk_kref, dy_free);
12464 +/* ---------------------------------------------------------------------- */
12466 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12468 +#ifdef CONFIG_AUFS_DEBUG
12469 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12470 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12472 +#define DyDbgDeclare(cnt) do {} while (0)
12473 +#define DyDbgInc(cnt) do {} while (0)
12476 +#define DySet(func, dst, src, h_op, h_sb) do { \
12478 + if (h_op->func) { \
12480 + dst.func = src.func; \
12482 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12486 +#define DySetForce(func, dst, src) do { \
12487 + AuDebugOn(!src.func); \
12489 + dst.func = src.func; \
12492 +#define DySetAop(func) \
12493 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12494 +#define DySetAopForce(func) \
12495 + DySetForce(func, dyaop->da_op, aufs_aop)
12497 +static void dy_aop(struct au_dykey *key, const void *h_op,
12498 + struct super_block *h_sb __maybe_unused)
12500 + struct au_dyaop *dyaop = (void *)key;
12501 + const struct address_space_operations *h_aop = h_op;
12502 + DyDbgDeclare(cnt);
12504 + AuDbg("%s\n", au_sbtype(h_sb));
12506 + DySetAop(writepage);
12507 + DySetAopForce(read_folio); /* force */
12508 + DySetAop(writepages);
12509 + DySetAop(dirty_folio);
12510 + DySetAop(invalidate_folio);
12511 + DySetAop(readahead);
12512 + DySetAop(write_begin);
12513 + DySetAop(write_end);
12515 + DySetAop(release_folio);
12516 + DySetAop(free_folio);
12517 + /* this one will be changed according to an aufs mount option */
12518 + DySetAop(direct_IO);
12519 + DySetAop(migrate_folio);
12520 + DySetAop(launder_folio);
12521 + DySetAop(is_partially_uptodate);
12522 + DySetAop(is_dirty_writeback);
12523 + DySetAop(error_remove_page);
12524 + DySetAop(swap_activate);
12525 + DySetAop(swap_deactivate);
12526 + DySetAop(swap_rw);
12528 + DyDbgSize(cnt, *h_aop);
12531 +/* ---------------------------------------------------------------------- */
12533 +static void dy_bug(struct kref *kref)
12538 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12540 + struct au_dykey *key, *old;
12541 + struct hlist_bl_head *hbl;
12544 + void (*set)(struct au_dykey *key, const void *h_op,
12545 + struct super_block *h_sb __maybe_unused);
12547 + static const struct op a[] = {
12549 + .sz = sizeof(struct au_dyaop),
12553 + const struct op *p;
12555 + hbl = dynop + op->dy_type;
12556 + key = dy_gfind_get(hbl, op->dy_hop);
12558 + goto out_add; /* success */
12560 + p = a + op->dy_type;
12561 + key = kzalloc(p->sz, GFP_NOFS);
12562 + if (unlikely(!key)) {
12563 + key = ERR_PTR(-ENOMEM);
12567 + key->dk_op.dy_hop = op->dy_hop;
12568 + kref_init(&key->dk_kref);
12569 + p->set(key, op->dy_hop, au_br_sb(br));
12570 + old = dy_gadd(hbl, key);
12572 + au_kfree_rcu(key);
12577 + old = dy_bradd(br, key);
12579 + /* its ref-count should never be zero here */
12580 + kref_put(&key->dk_kref, dy_bug);
12585 +/* ---------------------------------------------------------------------- */
12587 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12588 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12589 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12590 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12591 + * See the aufs manual in detail.
12593 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12596 + dyaop->da_op.direct_IO = NULL;
12598 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12601 +static struct au_dyaop *dy_aget(struct au_branch *br,
12602 + const struct address_space_operations *h_aop,
12605 + struct au_dyaop *dyaop;
12606 + struct au_dynop op;
12608 + op.dy_type = AuDy_AOP;
12609 + op.dy_haop = h_aop;
12610 + dyaop = (void *)dy_get(&op, br);
12611 + if (IS_ERR(dyaop))
12613 + dy_adx(dyaop, do_dx);
12619 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12620 + struct inode *h_inode)
12623 + struct super_block *sb;
12624 + struct au_branch *br;
12625 + struct au_dyaop *dyaop;
12627 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12628 + IiMustWriteLock(inode);
12630 + sb = inode->i_sb;
12631 + br = au_sbr(sb, bindex);
12632 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12633 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12634 + err = PTR_ERR(dyaop);
12635 + if (IS_ERR(dyaop))
12636 + /* unnecessary to call dy_fput() */
12640 + inode->i_mapping->a_ops = &dyaop->da_op;
12647 + * Is it safe to replace a_ops during the inode/file is in operation?
12648 + * Yes, I hope so.
12650 +int au_dy_irefresh(struct inode *inode)
12653 + aufs_bindex_t btop;
12654 + struct inode *h_inode;
12657 + if (S_ISREG(inode->i_mode)) {
12658 + btop = au_ibtop(inode);
12659 + h_inode = au_h_iptr(inode, btop);
12660 + err = au_dy_iaop(inode, btop, h_inode);
12665 +void au_dy_arefresh(int do_dx)
12667 + struct hlist_bl_head *hbl;
12668 + struct hlist_bl_node *pos;
12669 + struct au_dykey *key;
12671 + hbl = dynop + AuDy_AOP;
12672 + hlist_bl_lock(hbl);
12673 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12674 + dy_adx((void *)key, do_dx);
12675 + hlist_bl_unlock(hbl);
12678 +/* ---------------------------------------------------------------------- */
12680 +void __init au_dy_init(void)
12684 + for (i = 0; i < AuDyLast; i++)
12685 + INIT_HLIST_BL_HEAD(dynop + i);
12688 +void au_dy_fin(void)
12692 + for (i = 0; i < AuDyLast; i++)
12693 + WARN_ON(!hlist_bl_empty(dynop + i));
12695 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12696 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12697 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12699 +/* SPDX-License-Identifier: GPL-2.0 */
12701 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12703 + * This program is free software; you can redistribute it and/or modify
12704 + * it under the terms of the GNU General Public License as published by
12705 + * the Free Software Foundation; either version 2 of the License, or
12706 + * (at your option) any later version.
12708 + * This program is distributed in the hope that it will be useful,
12709 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12710 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12711 + * GNU General Public License for more details.
12713 + * You should have received a copy of the GNU General Public License
12714 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12718 + * dynamically customizable operations (for regular files only)
12721 +#ifndef __AUFS_DYNOP_H__
12722 +#define __AUFS_DYNOP_H__
12726 +#include <linux/fs.h>
12727 +#include <linux/kref.h>
12729 +enum {AuDy_AOP, AuDyLast};
12734 + const void *dy_hop;
12735 + const struct address_space_operations *dy_haop;
12741 + struct hlist_bl_node dk_hnode;
12742 + struct rcu_head dk_rcu;
12744 + struct au_dynop dk_op;
12747 + * during I am in the branch local array, kref is gotten. when the
12748 + * branch is removed, kref is put.
12750 + struct kref dk_kref;
12753 +/* stop unioning since their sizes are very different from each other */
12755 + struct au_dykey da_key;
12756 + struct address_space_operations da_op; /* not const */
12758 +/* make sure that 'struct au_dykey *' can be any type */
12759 +static_assert(!offsetof(struct au_dyaop, da_key));
12761 +/* ---------------------------------------------------------------------- */
12765 +void au_dy_put(struct au_dykey *key);
12766 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12767 + struct inode *h_inode);
12768 +int au_dy_irefresh(struct inode *inode);
12769 +void au_dy_arefresh(int do_dio);
12771 +void __init au_dy_init(void);
12772 +void au_dy_fin(void);
12774 +#endif /* __KERNEL__ */
12775 +#endif /* __AUFS_DYNOP_H__ */
12776 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12777 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12778 +++ linux/fs/aufs/export.c 2022-12-17 09:21:34.796521861 +0100
12780 +// SPDX-License-Identifier: GPL-2.0
12782 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12784 + * This program is free software; you can redistribute it and/or modify
12785 + * it under the terms of the GNU General Public License as published by
12786 + * the Free Software Foundation; either version 2 of the License, or
12787 + * (at your option) any later version.
12789 + * This program is distributed in the hope that it will be useful,
12790 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12791 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12792 + * GNU General Public License for more details.
12794 + * You should have received a copy of the GNU General Public License
12795 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12802 +#include <linux/exportfs.h>
12803 +#include <linux/fs_struct.h>
12804 +#include <linux/nsproxy.h>
12805 +#include <linux/random.h>
12806 +#include <linux/writeback.h>
12810 +#ifdef CONFIG_AUFS_INO_T_64
12818 +static ino_t decode_ino(__u32 *a)
12822 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12824 +#ifdef CONFIG_AUFS_INO_T_64
12830 +static void encode_ino(__u32 *a, ino_t ino)
12836 +#ifdef CONFIG_AUFS_INO_T_64
12841 +/* NFS file handle */
12845 +#ifdef CONFIG_AUFS_INO_T_64
12846 + /* support 64bit inode number */
12859 + Fh_ino = Fh_ino1,
12860 + Fh_dir_ino = Fh_dir_ino1
12863 +static int au_test_anon(struct dentry *dentry)
12865 + /* note: read d_flags without d_lock */
12866 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12869 +int au_test_nfsd(void)
12872 + struct task_struct *tsk = current;
12873 + char comm[sizeof(tsk->comm)];
12876 + if (tsk->flags & PF_KTHREAD) {
12877 + get_task_comm(comm, tsk);
12878 + ret = !strcmp(comm, "nfsd");
12884 +/* ---------------------------------------------------------------------- */
12885 +/* inode generation external table */
12887 +void au_xigen_inc(struct inode *inode)
12892 + struct super_block *sb;
12893 + struct au_sbinfo *sbinfo;
12895 + sb = inode->i_sb;
12896 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12898 + sbinfo = au_sbi(sb);
12899 + pos = inode->i_ino;
12900 + pos *= sizeof(igen);
12901 + igen = inode->i_generation + 1;
12902 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12903 + if (sz == sizeof(igen))
12904 + return; /* success */
12906 + if (unlikely(sz >= 0))
12907 + AuIOErr("xigen error (%zd)\n", sz);
12910 +int au_xigen_new(struct inode *inode)
12915 + struct super_block *sb;
12916 + struct au_sbinfo *sbinfo;
12917 + struct file *file;
12920 + /* todo: dirty, at mount time */
12921 + if (inode->i_ino == AUFS_ROOT_INO)
12923 + sb = inode->i_sb;
12924 + SiMustAnyLock(sb);
12925 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12929 + pos = inode->i_ino;
12930 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12931 + AuIOErr1("too large i%lld\n", pos);
12934 + pos *= sizeof(inode->i_generation);
12937 + sbinfo = au_sbi(sb);
12938 + file = sbinfo->si_xigen;
12941 + if (vfsub_f_size_read(file)
12942 + < pos + sizeof(inode->i_generation)) {
12943 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12944 + sz = xino_fwrite(file, &inode->i_generation,
12945 + sizeof(inode->i_generation), &pos);
12947 + sz = xino_fread(file, &inode->i_generation,
12948 + sizeof(inode->i_generation), &pos);
12949 + if (sz == sizeof(inode->i_generation))
12950 + goto out; /* success */
12953 + if (unlikely(sz >= 0)) {
12955 + AuIOErr("xigen error (%zd)\n", sz);
12962 +int au_xigen_set(struct super_block *sb, struct path *path)
12965 + struct au_sbinfo *sbinfo;
12966 + struct file *file;
12968 + SiMustWriteLock(sb);
12970 + sbinfo = au_sbi(sb);
12971 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12972 + err = PTR_ERR(file);
12973 + if (IS_ERR(file))
12976 + if (sbinfo->si_xigen)
12977 + fput(sbinfo->si_xigen);
12978 + sbinfo->si_xigen = file;
12985 +void au_xigen_clr(struct super_block *sb)
12987 + struct au_sbinfo *sbinfo;
12989 + SiMustWriteLock(sb);
12991 + sbinfo = au_sbi(sb);
12992 + if (sbinfo->si_xigen) {
12993 + fput(sbinfo->si_xigen);
12994 + sbinfo->si_xigen = NULL;
12998 +/* ---------------------------------------------------------------------- */
13000 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13003 + struct dentry *dentry, *d;
13004 + struct inode *inode;
13005 + unsigned int sigen;
13008 + inode = ilookup(sb, ino);
13012 + dentry = ERR_PTR(-ESTALE);
13013 + sigen = au_sigen(sb);
13014 + if (unlikely(au_is_bad_inode(inode)
13015 + || IS_DEADDIR(inode)
13016 + || sigen != au_iigen(inode, NULL)))
13020 + if (!dir_ino || S_ISDIR(inode->i_mode))
13021 + dentry = d_find_alias(inode);
13023 + spin_lock(&inode->i_lock);
13024 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13025 + spin_lock(&d->d_lock);
13026 + if (!au_test_anon(d)
13027 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13028 + dentry = dget_dlock(d);
13029 + spin_unlock(&d->d_lock);
13032 + spin_unlock(&d->d_lock);
13034 + spin_unlock(&inode->i_lock);
13036 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13037 + /* need to refresh */
13045 + AuTraceErrPtr(dentry);
13049 +/* ---------------------------------------------------------------------- */
13051 +/* todo: dirty? */
13052 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13054 +struct au_compare_mnt_args {
13056 + struct super_block *sb;
13059 + struct vfsmount *mnt;
13062 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13064 + struct au_compare_mnt_args *a = arg;
13066 + if (mnt->mnt_sb != a->sb)
13068 + a->mnt = mntget(mnt);
13072 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13075 + struct path root;
13076 + struct au_compare_mnt_args args = {
13080 + get_fs_root(current->fs, &root);
13082 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13083 + rcu_read_unlock();
13086 + AuDebugOn(!args.mnt);
13090 +struct au_nfsd_si_lock {
13091 + unsigned int sigen;
13092 + aufs_bindex_t bindex, br_id;
13093 + unsigned char force_lock;
13096 +static int si_nfsd_read_lock(struct super_block *sb,
13097 + struct au_nfsd_si_lock *nsi_lock)
13100 + aufs_bindex_t bindex;
13102 + si_read_lock(sb, AuLock_FLUSH);
13104 + /* branch id may be wrapped around */
13106 + bindex = au_br_index(sb, nsi_lock->br_id);
13107 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13108 + goto out; /* success */
13112 + if (!nsi_lock->force_lock)
13113 + si_read_unlock(sb);
13116 + nsi_lock->bindex = bindex;
13120 +struct find_name_by_ino {
13121 + struct dir_context ctx;
13122 + int called, found;
13129 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13130 + loff_t offset, u64 ino, unsigned int d_type)
13132 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13136 + if (a->ino != ino)
13139 + memcpy(a->name, name, namelen);
13140 + a->namelen = namelen;
13145 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13146 + struct au_nfsd_si_lock *nsi_lock)
13148 + struct dentry *dentry, *parent;
13149 + struct file *file;
13150 + struct inode *dir;
13151 + struct find_name_by_ino arg = {
13153 + .actor = find_name_by_ino
13158 + parent = path->dentry;
13160 + si_read_unlock(parent->d_sb);
13161 + file = vfsub_dentry_open(path, au_dir_roflags);
13162 + dentry = (void *)file;
13163 + if (IS_ERR(file))
13166 + dentry = ERR_PTR(-ENOMEM);
13167 + arg.name = (void *)__get_free_page(GFP_NOFS);
13168 + if (unlikely(!arg.name))
13175 + err = vfsub_iterate_dir(file, &arg.ctx);
13176 + } while (!err && !arg.found && arg.called);
13177 + dentry = ERR_PTR(err);
13178 + if (unlikely(err))
13180 + /* instead of ENOENT */
13181 + dentry = ERR_PTR(-ESTALE);
13185 + /* do not call vfsub_lkup_one() */
13186 + dir = d_inode(parent);
13187 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13188 + AuTraceErrPtr(dentry);
13189 + if (IS_ERR(dentry))
13191 + AuDebugOn(au_test_anon(dentry));
13192 + if (unlikely(d_really_is_negative(dentry))) {
13194 + dentry = ERR_PTR(-ENOENT);
13198 + free_page((unsigned long)arg.name);
13202 + if (unlikely(nsi_lock
13203 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13204 + if (!IS_ERR(dentry)) {
13206 + dentry = ERR_PTR(-ESTALE);
13208 + AuTraceErrPtr(dentry);
13212 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13214 + struct au_nfsd_si_lock *nsi_lock)
13216 + struct dentry *dentry;
13217 + struct path path;
13219 + if (dir_ino != AUFS_ROOT_INO) {
13220 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13221 + dentry = path.dentry;
13222 + if (!path.dentry || IS_ERR(path.dentry))
13224 + AuDebugOn(au_test_anon(path.dentry));
13226 + path.dentry = dget(sb->s_root);
13228 + path.mnt = au_mnt_get(sb);
13229 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13233 + AuTraceErrPtr(dentry);
13237 +/* ---------------------------------------------------------------------- */
13239 +static int h_acceptable(void *expv, struct dentry *dentry)
13244 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13245 + char *buf, int len, struct super_block *sb)
13249 + struct path path;
13251 + p = d_path(h_rootpath, buf, len);
13256 + path.mnt = h_rootpath->mnt;
13257 + path.dentry = h_parent;
13258 + p = d_path(&path, buf, len);
13264 + path.mnt = au_mnt_get(sb);
13265 + path.dentry = sb->s_root;
13266 + p = d_path(&path, buf, len - strlen(p));
13267 + mntput(path.mnt);
13271 + p[strlen(p)] = '/';
13274 + AuTraceErrPtr(p);
13279 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13280 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13282 + struct dentry *dentry, *h_parent, *root;
13283 + struct super_block *h_sb;
13284 + char *pathname, *p;
13285 + struct vfsmount *h_mnt;
13286 + struct au_branch *br;
13288 + struct path path;
13290 + br = au_sbr(sb, nsi_lock->bindex);
13291 + h_mnt = au_br_mnt(br);
13292 + h_sb = h_mnt->mnt_sb;
13293 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13295 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13296 + fh_len - Fh_tail, fh[Fh_h_type],
13297 + h_acceptable, /*context*/NULL);
13299 + dentry = h_parent;
13300 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13301 + AuWarn1("%s decode_fh failed, %ld\n",
13302 + au_sbtype(h_sb), PTR_ERR(h_parent));
13306 + if (unlikely(au_test_anon(h_parent))) {
13307 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13308 + au_sbtype(h_sb));
13309 + goto out_h_parent;
13312 + dentry = ERR_PTR(-ENOMEM);
13313 + pathname = (void *)__get_free_page(GFP_NOFS);
13314 + if (unlikely(!pathname))
13315 + goto out_h_parent;
13317 + root = sb->s_root;
13318 + path.mnt = h_mnt;
13319 + di_read_lock_parent(root, !AuLock_IR);
13320 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13321 + di_read_unlock(root, !AuLock_IR);
13322 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13323 + dentry = (void *)p;
13325 + goto out_pathname;
13327 + si_read_unlock(sb);
13328 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13329 + dentry = ERR_PTR(err);
13330 + if (unlikely(err))
13333 + dentry = ERR_PTR(-ENOENT);
13334 + AuDebugOn(au_test_anon(path.dentry));
13335 + if (unlikely(d_really_is_negative(path.dentry)))
13338 + if (ino != d_inode(path.dentry)->i_ino)
13339 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13341 + dentry = dget(path.dentry);
13346 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13347 + if (!IS_ERR(dentry)) {
13349 + dentry = ERR_PTR(-ESTALE);
13352 + free_page((unsigned long)pathname);
13356 + AuTraceErrPtr(dentry);
13360 +/* ---------------------------------------------------------------------- */
13362 +static struct dentry *
13363 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13366 + struct dentry *dentry;
13367 + __u32 *fh = fid->raw;
13368 + struct au_branch *br;
13369 + ino_t ino, dir_ino;
13370 + struct au_nfsd_si_lock nsi_lock = {
13374 + dentry = ERR_PTR(-ESTALE);
13375 + /* it should never happen, but the file handle is unreliable */
13376 + if (unlikely(fh_len < Fh_tail))
13378 + nsi_lock.sigen = fh[Fh_sigen];
13379 + nsi_lock.br_id = fh[Fh_br_id];
13381 + /* branch id may be wrapped around */
13383 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13385 + nsi_lock.force_lock = 1;
13387 + /* is this inode still cached? */
13388 + ino = decode_ino(fh + Fh_ino);
13389 + /* it should never happen */
13390 + if (unlikely(ino == AUFS_ROOT_INO))
13393 + dir_ino = decode_ino(fh + Fh_dir_ino);
13394 + dentry = decode_by_ino(sb, ino, dir_ino);
13395 + if (IS_ERR(dentry))
13400 + /* is the parent dir cached? */
13401 + br = au_sbr(sb, nsi_lock.bindex);
13402 + au_lcnt_inc(&br->br_nfiles);
13403 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13404 + if (IS_ERR(dentry))
13409 + /* lookup path */
13410 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13411 + if (IS_ERR(dentry))
13413 + if (unlikely(!dentry))
13414 + /* todo?: make it ESTALE */
13418 + if (!au_digen_test(dentry, au_sigen(sb))
13419 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13420 + goto out_unlock; /* success */
13423 + dentry = ERR_PTR(-ESTALE);
13426 + au_lcnt_dec(&br->br_nfiles);
13427 + si_read_unlock(sb);
13429 + AuTraceErrPtr(dentry);
13433 +#if 0 /* reserved for future use */
13434 +/* support subtreecheck option */
13435 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13436 + int fh_len, int fh_type)
13438 + struct dentry *parent;
13439 + __u32 *fh = fid->raw;
13442 + dir_ino = decode_ino(fh + Fh_dir_ino);
13443 + parent = decode_by_ino(sb, dir_ino, 0);
13444 + if (IS_ERR(parent))
13447 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13448 + dir_ino, fh, fh_len);
13451 + AuTraceErrPtr(parent);
13456 +/* ---------------------------------------------------------------------- */
13458 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13459 + struct inode *dir)
13462 + aufs_bindex_t bindex;
13463 + struct super_block *sb, *h_sb;
13464 + struct dentry *dentry, *parent, *h_parent;
13465 + struct inode *h_dir;
13466 + struct au_branch *br;
13469 + if (unlikely(*max_len <= Fh_tail)) {
13470 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13474 + err = FILEID_ROOT;
13475 + if (inode->i_ino == AUFS_ROOT_INO) {
13476 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13481 + sb = inode->i_sb;
13482 + err = si_read_lock(sb, AuLock_FLUSH);
13483 + if (unlikely(err))
13486 +#ifdef CONFIG_AUFS_DEBUG
13487 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13488 + AuWarn1("NFS-exporting requires xino\n");
13492 + ii_read_lock_child(inode);
13493 + bindex = au_ibtop(inode);
13495 + dentry = d_find_any_alias(inode);
13496 + if (unlikely(!dentry))
13498 + AuDebugOn(au_test_anon(dentry));
13499 + parent = dget_parent(dentry);
13501 + if (unlikely(!parent))
13503 + if (d_really_is_positive(parent))
13504 + dir = d_inode(parent);
13507 + ii_read_lock_parent(dir);
13508 + h_dir = au_h_iptr(dir, bindex);
13509 + ii_read_unlock(dir);
13510 + if (unlikely(!h_dir))
13512 + h_parent = d_find_any_alias(h_dir);
13513 + if (unlikely(!h_parent))
13514 + goto out_hparent;
13517 + br = au_sbr(sb, bindex);
13518 + h_sb = au_br_sb(br);
13519 + if (unlikely(!h_sb->s_export_op)) {
13520 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13521 + goto out_hparent;
13524 + fh[Fh_br_id] = br->br_id;
13525 + fh[Fh_sigen] = au_sigen(sb);
13526 + encode_ino(fh + Fh_ino, inode->i_ino);
13527 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13528 + fh[Fh_igen] = inode->i_generation;
13530 + *max_len -= Fh_tail;
13531 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13533 + /*connectable or subtreecheck*/0);
13534 + err = fh[Fh_h_type];
13535 + *max_len += Fh_tail;
13536 + /* todo: macros? */
13537 + if (err != FILEID_INVALID)
13540 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13547 + ii_read_unlock(inode);
13548 + si_read_unlock(sb);
13550 + if (unlikely(err < 0))
13551 + err = FILEID_INVALID;
13555 +/* ---------------------------------------------------------------------- */
13557 +static int aufs_commit_metadata(struct inode *inode)
13560 + aufs_bindex_t bindex;
13561 + struct super_block *sb;
13562 + struct inode *h_inode;
13563 + int (*f)(struct inode *inode);
13565 + sb = inode->i_sb;
13566 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13567 + ii_write_lock_child(inode);
13568 + bindex = au_ibtop(inode);
13569 + AuDebugOn(bindex < 0);
13570 + h_inode = au_h_iptr(inode, bindex);
13572 + f = h_inode->i_sb->s_export_op->commit_metadata;
13574 + err = f(h_inode);
13576 + err = sync_inode_metadata(h_inode, /*wait*/1);
13578 + au_cpup_attr_timesizes(inode);
13579 + ii_write_unlock(inode);
13580 + si_read_unlock(sb);
13584 +/* ---------------------------------------------------------------------- */
13586 +static struct export_operations aufs_export_op = {
13587 + .fh_to_dentry = aufs_fh_to_dentry,
13588 + /* .fh_to_parent = aufs_fh_to_parent, */
13589 + .encode_fh = aufs_encode_fh,
13590 + .commit_metadata = aufs_commit_metadata
13593 +void au_export_init(struct super_block *sb)
13595 + struct au_sbinfo *sbinfo;
13598 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13599 + && IS_MODULE(CONFIG_EXPORTFS),
13600 + AUFS_NAME ": unsupported configuration "
13601 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13603 + sb->s_export_op = &aufs_export_op;
13604 + sbinfo = au_sbi(sb);
13605 + sbinfo->si_xigen = NULL;
13606 + get_random_bytes(&u, sizeof(u));
13607 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13608 + atomic_set(&sbinfo->si_xigen_next, u);
13610 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13611 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13612 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13614 +// SPDX-License-Identifier: GPL-2.0
13616 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13618 + * This program is free software; you can redistribute it and/or modify
13619 + * it under the terms of the GNU General Public License as published by
13620 + * the Free Software Foundation; either version 2 of the License, or
13621 + * (at your option) any later version.
13623 + * This program is distributed in the hope that it will be useful,
13624 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13625 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13626 + * GNU General Public License for more details.
13628 + * You should have received a copy of the GNU General Public License
13629 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13633 + * File-based Hierarchy Storage Management
13636 +#include <linux/anon_inodes.h>
13637 +#include <linux/poll.h>
13638 +#include <linux/seq_file.h>
13639 +#include <linux/statfs.h>
13642 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13644 + struct au_sbinfo *sbinfo;
13645 + struct au_fhsm *fhsm;
13647 + SiMustAnyLock(sb);
13649 + sbinfo = au_sbi(sb);
13650 + fhsm = &sbinfo->si_fhsm;
13651 + AuDebugOn(!fhsm);
13652 + return fhsm->fhsm_bottom;
13655 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13657 + struct au_sbinfo *sbinfo;
13658 + struct au_fhsm *fhsm;
13660 + SiMustWriteLock(sb);
13662 + sbinfo = au_sbi(sb);
13663 + fhsm = &sbinfo->si_fhsm;
13664 + AuDebugOn(!fhsm);
13665 + fhsm->fhsm_bottom = bindex;
13668 +/* ---------------------------------------------------------------------- */
13670 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13672 + struct au_br_fhsm *bf;
13674 + bf = br->br_fhsm;
13675 + MtxMustLock(&bf->bf_lock);
13677 + return !bf->bf_readable
13678 + || time_after(jiffies,
13679 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13682 +/* ---------------------------------------------------------------------- */
13684 +static void au_fhsm_notify(struct super_block *sb, int val)
13686 + struct au_sbinfo *sbinfo;
13687 + struct au_fhsm *fhsm;
13689 + SiMustAnyLock(sb);
13691 + sbinfo = au_sbi(sb);
13692 + fhsm = &sbinfo->si_fhsm;
13693 + if (au_fhsm_pid(fhsm)
13694 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13695 + atomic_set(&fhsm->fhsm_readable, val);
13697 + wake_up(&fhsm->fhsm_wqh);
13701 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13702 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13705 + struct au_branch *br;
13706 + struct au_br_fhsm *bf;
13708 + br = au_sbr(sb, bindex);
13709 + AuDebugOn(au_br_rdonly(br));
13710 + bf = br->br_fhsm;
13714 + mutex_lock(&bf->bf_lock);
13716 + MtxMustLock(&bf->bf_lock);
13718 + /* sb->s_root for NFS is unreliable */
13719 + err = au_br_stfs(br, &bf->bf_stfs);
13720 + if (unlikely(err)) {
13721 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13725 + bf->bf_jiffy = jiffies;
13726 + bf->bf_readable = 1;
13728 + au_fhsm_notify(sb, /*val*/1);
13730 + *rstfs = bf->bf_stfs;
13734 + mutex_unlock(&bf->bf_lock);
13735 + au_fhsm_notify(sb, /*val*/1);
13740 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13743 + struct au_sbinfo *sbinfo;
13744 + struct au_fhsm *fhsm;
13745 + struct au_branch *br;
13746 + struct au_br_fhsm *bf;
13748 + AuDbg("b%d, force %d\n", bindex, force);
13749 + SiMustAnyLock(sb);
13751 + sbinfo = au_sbi(sb);
13752 + fhsm = &sbinfo->si_fhsm;
13753 + if (!au_ftest_si(sbinfo, FHSM)
13754 + || fhsm->fhsm_bottom == bindex)
13757 + br = au_sbr(sb, bindex);
13758 + bf = br->br_fhsm;
13760 + mutex_lock(&bf->bf_lock);
13762 + || au_fhsm_pid(fhsm)
13763 + || au_fhsm_test_jiffy(sbinfo, br))
13764 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13766 + mutex_unlock(&bf->bf_lock);
13769 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13771 + aufs_bindex_t bindex, bbot;
13772 + struct au_branch *br;
13774 + /* exclude the bottom */
13775 + bbot = au_fhsm_bottom(sb);
13776 + for (bindex = 0; bindex < bbot; bindex++) {
13777 + br = au_sbr(sb, bindex);
13778 + if (au_br_fhsm(br->br_perm))
13779 + au_fhsm_wrote(sb, bindex, force);
13783 +/* ---------------------------------------------------------------------- */
13785 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13788 + struct au_sbinfo *sbinfo;
13789 + struct au_fhsm *fhsm;
13792 + sbinfo = file->private_data;
13793 + fhsm = &sbinfo->si_fhsm;
13794 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13795 + if (atomic_read(&fhsm->fhsm_readable))
13796 + mask = EPOLLIN /* | EPOLLRDNORM */;
13799 + AuDbg("mask 0x%x\n", mask);
13803 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13804 + struct aufs_stfs *stfs, __s16 brid)
13808 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13810 + err = __put_user(brid, &stbr->brid);
13811 + if (unlikely(err))
13817 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13818 + struct aufs_stbr __user *stbr, size_t count)
13822 + aufs_bindex_t bindex, bbot;
13823 + struct au_branch *br;
13824 + struct au_br_fhsm *bf;
13826 + /* except the bottom branch */
13829 + bbot = au_fhsm_bottom(sb);
13830 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13831 + br = au_sbr(sb, bindex);
13832 + if (!au_br_fhsm(br->br_perm))
13835 + bf = br->br_fhsm;
13836 + mutex_lock(&bf->bf_lock);
13837 + if (bf->bf_readable) {
13839 + if (count >= sizeof(*stbr))
13840 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13843 + bf->bf_readable = 0;
13844 + count -= sizeof(*stbr);
13848 + mutex_unlock(&bf->bf_lock);
13851 + err = sizeof(*stbr) * nstbr;
13856 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13861 + aufs_bindex_t nfhsm, bindex, bbot;
13862 + struct au_sbinfo *sbinfo;
13863 + struct au_fhsm *fhsm;
13864 + struct au_branch *br;
13865 + struct super_block *sb;
13868 + sbinfo = file->private_data;
13869 + fhsm = &sbinfo->si_fhsm;
13871 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13872 + if (!atomic_read(&fhsm->fhsm_readable)) {
13873 + if (vfsub_file_flags(file) & O_NONBLOCK)
13876 + err = wait_event_interruptible_locked_irq
13878 + atomic_read(&fhsm->fhsm_readable));
13880 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13881 + if (unlikely(err))
13884 + /* sb may already be dead */
13885 + au_rw_read_lock(&sbinfo->si_rwsem);
13886 + readable = atomic_read(&fhsm->fhsm_readable);
13887 + if (readable > 0) {
13888 + sb = sbinfo->si_sb;
13890 + /* exclude the bottom branch */
13892 + bbot = au_fhsm_bottom(sb);
13893 + for (bindex = 0; bindex < bbot; bindex++) {
13894 + br = au_sbr(sb, bindex);
13895 + if (au_br_fhsm(br->br_perm))
13899 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13900 + atomic_set(&fhsm->fhsm_readable, 0);
13901 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13905 + au_rw_read_unlock(&sbinfo->si_rwsem);
13913 +static int au_fhsm_release(struct inode *inode, struct file *file)
13915 + struct au_sbinfo *sbinfo;
13916 + struct au_fhsm *fhsm;
13918 + /* sb may already be dead */
13919 + sbinfo = file->private_data;
13920 + fhsm = &sbinfo->si_fhsm;
13921 + spin_lock(&fhsm->fhsm_spin);
13922 + fhsm->fhsm_pid = 0;
13923 + spin_unlock(&fhsm->fhsm_spin);
13924 + kobject_put(&sbinfo->si_kobj);
13929 +static const struct file_operations au_fhsm_fops = {
13930 + .owner = THIS_MODULE,
13931 + .llseek = noop_llseek,
13932 + .read = au_fhsm_read,
13933 + .poll = au_fhsm_poll,
13934 + .release = au_fhsm_release
13937 +int au_fhsm_fd(struct super_block *sb, int oflags)
13940 + struct au_sbinfo *sbinfo;
13941 + struct au_fhsm *fhsm;
13944 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13948 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13952 + sbinfo = au_sbi(sb);
13953 + fhsm = &sbinfo->si_fhsm;
13954 + spin_lock(&fhsm->fhsm_spin);
13955 + if (!fhsm->fhsm_pid)
13956 + fhsm->fhsm_pid = current->pid;
13959 + spin_unlock(&fhsm->fhsm_spin);
13960 + if (unlikely(err))
13963 + oflags |= O_RDONLY;
13964 + /* oflags |= FMODE_NONOTIFY; */
13965 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13967 + if (unlikely(fd < 0))
13970 + /* succeed regardless 'fhsm' status */
13971 + kobject_get(&sbinfo->si_kobj);
13972 + si_noflush_read_lock(sb);
13973 + if (au_ftest_si(sbinfo, FHSM))
13974 + au_fhsm_wrote_all(sb, /*force*/0);
13975 + si_read_unlock(sb);
13976 + goto out; /* success */
13979 + spin_lock(&fhsm->fhsm_spin);
13980 + fhsm->fhsm_pid = 0;
13981 + spin_unlock(&fhsm->fhsm_spin);
13987 +/* ---------------------------------------------------------------------- */
13989 +int au_fhsm_br_alloc(struct au_branch *br)
13994 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13996 + au_br_fhsm_init(br->br_fhsm);
14003 +/* ---------------------------------------------------------------------- */
14005 +void au_fhsm_fin(struct super_block *sb)
14007 + au_fhsm_notify(sb, /*val*/-1);
14010 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14012 + struct au_fhsm *fhsm;
14014 + fhsm = &sbinfo->si_fhsm;
14015 + spin_lock_init(&fhsm->fhsm_spin);
14016 + init_waitqueue_head(&fhsm->fhsm_wqh);
14017 + atomic_set(&fhsm->fhsm_readable, 0);
14018 + fhsm->fhsm_expire
14019 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14020 + fhsm->fhsm_bottom = -1;
14023 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14025 + sbinfo->si_fhsm.fhsm_expire
14026 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14029 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14033 + if (!au_ftest_si(sbinfo, FHSM))
14036 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14037 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14038 + seq_printf(seq, ",fhsm_sec=%u", u);
14040 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14041 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14042 +++ linux/fs/aufs/file.c 2023-10-31 09:31:04.199880750 +0100
14044 +// SPDX-License-Identifier: GPL-2.0
14046 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14048 + * This program is free software; you can redistribute it and/or modify
14049 + * it under the terms of the GNU General Public License as published by
14050 + * the Free Software Foundation; either version 2 of the License, or
14051 + * (at your option) any later version.
14053 + * This program is distributed in the hope that it will be useful,
14054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14056 + * GNU General Public License for more details.
14058 + * You should have received a copy of the GNU General Public License
14059 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14063 + * handling file/dir, and address_space operation
14066 +#ifdef CONFIG_AUFS_DEBUG
14067 +#include <linux/migrate.h>
14069 +#include <linux/pagemap.h>
14072 +/* drop flags for writing */
14073 +unsigned int au_file_roflags(unsigned int flags)
14075 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14076 + flags |= O_RDONLY | O_NOATIME;
14080 +/* common functions to regular file and dir */
14081 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14082 + struct file *file, int force_wr)
14084 + struct file *h_file;
14085 + struct dentry *h_dentry;
14086 + struct inode *h_inode;
14087 + struct super_block *sb;
14088 + struct au_branch *br;
14089 + struct path h_path;
14092 + /* a race condition can happen between open and unlink/rmdir */
14093 + h_file = ERR_PTR(-ENOENT);
14094 + h_dentry = au_h_dptr(dentry, bindex);
14095 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14097 + h_inode = d_inode(h_dentry);
14098 + spin_lock(&h_dentry->d_lock);
14099 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14100 + /* || !d_inode(dentry)->i_nlink */
14102 + spin_unlock(&h_dentry->d_lock);
14103 + if (unlikely(err))
14106 + sb = dentry->d_sb;
14107 + br = au_sbr(sb, bindex);
14108 + err = au_br_test_oflag(flags, br);
14109 + h_file = ERR_PTR(err);
14110 + if (unlikely(err))
14113 + /* drop flags for writing */
14114 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14115 + if (force_wr && !(flags & O_WRONLY))
14117 + flags = au_file_roflags(flags);
14119 + h_file = ERR_PTR(-EROFS);
14120 + flags = au_file_roflags(flags);
14121 + if (unlikely(vfsub_native_ro(h_inode)
14122 + || IS_APPEND(h_inode)))
14124 + flags &= ~O_ACCMODE;
14125 + flags |= O_WRONLY;
14128 + flags &= ~O_CREAT;
14129 + au_lcnt_inc(&br->br_nfiles);
14130 + h_path.dentry = h_dentry;
14131 + h_path.mnt = au_br_mnt(br);
14133 + * vfs::backing_file_open() looks promising since it can get rid of
14134 + * mm::vm_prfile approach from my mind.
14135 + * but I keep current approach for a while.
14137 + h_file = vfsub_dentry_open(&h_path, flags);
14138 + if (IS_ERR(h_file))
14141 + if (flags & __FMODE_EXEC) {
14142 + err = deny_write_access(h_file);
14143 + if (unlikely(err)) {
14145 + h_file = ERR_PTR(err);
14149 + fsnotify_open(h_file);
14150 + goto out; /* success */
14153 + au_lcnt_dec(&br->br_nfiles);
14158 +static int au_cmoo(struct dentry *dentry)
14160 + int err, cmoo, matched;
14161 + unsigned int udba;
14162 + struct path h_path;
14163 + struct au_pin pin;
14164 + struct au_cp_generic cpg = {
14165 + .dentry = dentry,
14170 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14172 + struct inode *delegated;
14173 + struct super_block *sb;
14174 + struct au_sbinfo *sbinfo;
14175 + struct au_fhsm *fhsm;
14177 + struct au_branch *br;
14178 + struct dentry *parent;
14179 + struct au_hinode *hdir;
14181 + DiMustWriteLock(dentry);
14182 + IiMustWriteLock(d_inode(dentry));
14185 + if (IS_ROOT(dentry))
14187 + cpg.bsrc = au_dbtop(dentry);
14191 + sb = dentry->d_sb;
14192 + sbinfo = au_sbi(sb);
14193 + fhsm = &sbinfo->si_fhsm;
14194 + pid = au_fhsm_pid(fhsm);
14197 + && (current->pid == pid
14198 + || rcu_dereference(current->real_parent)->pid == pid));
14199 + rcu_read_unlock();
14203 + br = au_sbr(sb, cpg.bsrc);
14204 + cmoo = au_br_cmoo(br->br_perm);
14207 + if (!d_is_reg(dentry))
14208 + cmoo &= AuBrAttr_COO_ALL;
14212 + parent = dget_parent(dentry);
14213 + di_write_lock_parent(parent);
14214 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14216 + if (unlikely(err < 0)) {
14217 + err = 0; /* there is no upper writable branch */
14220 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14222 + /* do not respect the coo attrib for the target branch */
14223 + err = au_cpup_dirs(dentry, cpg.bdst);
14224 + if (unlikely(err))
14227 + di_downgrade_lock(parent, AuLock_IR);
14228 + udba = au_opt_udba(sb);
14229 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14230 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14231 + if (unlikely(err))
14234 + err = au_sio_cpup_simple(&cpg);
14236 + if (unlikely(err))
14238 + if (!(cmoo & AuBrWAttr_MOO))
14239 + goto out_parent; /* success */
14241 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14242 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14243 + if (unlikely(err))
14246 + h_path.mnt = au_br_mnt(br);
14247 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14248 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14249 + delegated = NULL;
14250 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14252 + /* todo: keep h_dentry or not? */
14253 + if (unlikely(err == -EWOULDBLOCK)) {
14254 + pr_warn("cannot retry for NFSv4 delegation"
14255 + " for an internal unlink\n");
14258 + if (unlikely(err)) {
14259 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14263 + goto out_parent; /* success */
14266 + di_downgrade_lock(parent, AuLock_IR);
14268 + di_read_unlock(parent, AuLock_IR);
14275 +int au_do_open(struct file *file, struct au_do_open_args *args)
14277 + int err, aopen = args->aopen;
14278 + struct dentry *dentry;
14279 + struct au_finfo *finfo;
14282 + err = au_finfo_init(file, args->fidir);
14285 + err = au_finfo_init(file, args->fidir);
14288 + if (unlikely(err))
14291 + dentry = file->f_path.dentry;
14292 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14293 + di_write_lock_child(dentry);
14294 + err = au_cmoo(dentry);
14297 + err = args->open(file, vfsub_file_flags(file),
14298 + au_di(dentry)->di_htmpfile);
14299 + di_write_unlock(dentry);
14301 + di_downgrade_lock(dentry, AuLock_IR);
14303 + err = args->open(file, vfsub_file_flags(file),
14306 + di_read_unlock(dentry, AuLock_IR);
14310 + finfo = au_fi(file);
14312 + finfo->fi_file = file;
14313 + au_hbl_add(&finfo->fi_hlist,
14314 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14317 + fi_write_unlock(file);
14320 + fi_write_unlock(file);
14323 + if (unlikely(err)) {
14324 + finfo->fi_hdir = NULL;
14325 + au_finfo_fin(file);
14333 +int au_reopen_nondir(struct file *file)
14336 + aufs_bindex_t btop;
14337 + struct dentry *dentry;
14338 + struct au_branch *br;
14339 + struct file *h_file, *h_file_tmp;
14341 + dentry = file->f_path.dentry;
14342 + btop = au_dbtop(dentry);
14343 + br = au_sbr(dentry->d_sb, btop);
14344 + h_file_tmp = NULL;
14345 + if (au_fbtop(file) == btop) {
14346 + h_file = au_hf_top(file);
14347 + if (file->f_mode == h_file->f_mode)
14348 + return 0; /* success */
14349 + h_file_tmp = h_file;
14350 + get_file(h_file_tmp);
14351 + au_lcnt_inc(&br->br_nfiles);
14352 + au_set_h_fptr(file, btop, NULL);
14354 + AuDebugOn(au_fi(file)->fi_hdir);
14357 + * file exists on both of rw and ro
14358 + * open --> dbtop and fbtop are both 0
14359 + * prepend a branch as rw, "rw" become ro
14361 + * delete the top branch, "rw" becomes rw again
14362 + * --> dbtop is 1, fbtop is still 0
14363 + * write --> fbtop is 0 but dbtop is 1
14365 + /* AuDebugOn(au_fbtop(file) < btop); */
14367 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14368 + file, /*force_wr*/0);
14369 + err = PTR_ERR(h_file);
14370 + if (IS_ERR(h_file)) {
14371 + if (h_file_tmp) {
14373 + au_set_h_fptr(file, btop, h_file_tmp);
14374 + h_file_tmp = NULL;
14376 + goto out; /* todo: close all? */
14380 + au_set_fbtop(file, btop);
14381 + au_set_h_fptr(file, btop, h_file);
14382 + au_update_figen(file);
14383 + /* todo: necessary? */
14384 + /* file->f_ra = h_file->f_ra; */
14387 + if (h_file_tmp) {
14388 + fput(h_file_tmp);
14389 + au_lcnt_dec(&br->br_nfiles);
14394 +/* ---------------------------------------------------------------------- */
14396 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14397 + struct dentry *hi_wh)
14400 + aufs_bindex_t btop;
14401 + struct au_dinfo *dinfo;
14402 + struct dentry *h_dentry;
14403 + struct au_hdentry *hdp;
14405 + dinfo = au_di(file->f_path.dentry);
14406 + AuRwMustWriteLock(&dinfo->di_rwsem);
14408 + btop = dinfo->di_btop;
14409 + dinfo->di_btop = btgt;
14410 + hdp = au_hdentry(dinfo, btgt);
14411 + h_dentry = hdp->hd_dentry;
14412 + hdp->hd_dentry = hi_wh;
14413 + err = au_reopen_nondir(file);
14414 + hdp->hd_dentry = h_dentry;
14415 + dinfo->di_btop = btop;
14420 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14421 + aufs_bindex_t bcpup, struct au_pin *pin)
14424 + struct inode *inode, *h_inode;
14425 + struct dentry *h_dentry, *hi_wh;
14426 + struct au_cp_generic cpg = {
14427 + .dentry = file->f_path.dentry,
14434 + au_update_dbtop(cpg.dentry);
14435 + inode = d_inode(cpg.dentry);
14437 + if (au_dbtop(cpg.dentry) <= bcpup
14438 + && au_dbbot(cpg.dentry) >= bcpup) {
14439 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14440 + if (h_dentry && d_is_positive(h_dentry))
14441 + h_inode = d_inode(h_dentry);
14443 + hi_wh = au_hi_wh(inode, bcpup);
14444 + if (!hi_wh && !h_inode)
14445 + err = au_sio_cpup_wh(&cpg, file);
14447 + /* already copied-up after unlink */
14448 + err = au_reopen_wh(file, bcpup, hi_wh);
14451 + && (inode->i_nlink > 1
14452 + || (inode->i_state & I_LINKABLE))
14453 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14454 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14460 + * prepare the @file for writing.
14462 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14465 + aufs_bindex_t dbtop;
14466 + struct dentry *parent;
14467 + struct inode *inode;
14468 + struct super_block *sb;
14469 + struct file *h_file;
14470 + struct au_cp_generic cpg = {
14471 + .dentry = file->f_path.dentry,
14476 + .flags = AuCpup_DTIME
14479 + sb = cpg.dentry->d_sb;
14480 + inode = d_inode(cpg.dentry);
14481 + cpg.bsrc = au_fbtop(file);
14482 + err = au_test_ro(sb, cpg.bsrc, inode);
14483 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14484 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14489 + /* need to cpup or reopen */
14490 + parent = dget_parent(cpg.dentry);
14491 + di_write_lock_parent(parent);
14492 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14494 + if (unlikely(err < 0))
14498 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14499 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14500 + if (unlikely(err))
14504 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14505 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14506 + if (unlikely(err))
14509 + dbtop = au_dbtop(cpg.dentry);
14510 + if (dbtop <= cpg.bdst)
14511 + cpg.bsrc = cpg.bdst;
14513 + if (dbtop <= cpg.bdst /* just reopen */
14514 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14516 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14517 + if (IS_ERR(h_file))
14518 + err = PTR_ERR(h_file);
14520 + di_downgrade_lock(parent, AuLock_IR);
14521 + if (dbtop > cpg.bdst)
14522 + err = au_sio_cpup_simple(&cpg);
14524 + err = au_reopen_nondir(file);
14525 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14527 + } else { /* copyup as wh and reopen */
14529 + * since writable hfsplus branch is not supported,
14530 + * h_open_pre/post() are unnecessary.
14532 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14533 + di_downgrade_lock(parent, AuLock_IR);
14537 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14538 + goto out_dput; /* success */
14544 + di_downgrade_lock(parent, AuLock_IR);
14546 + di_read_unlock(parent, AuLock_IR);
14553 +/* ---------------------------------------------------------------------- */
14555 +int au_do_flush(struct file *file, fl_owner_t id,
14556 + int (*flush)(struct file *file, fl_owner_t id))
14559 + struct super_block *sb;
14560 + struct inode *inode;
14562 + inode = file_inode(file);
14563 + sb = inode->i_sb;
14564 + si_noflush_read_lock(sb);
14565 + fi_read_lock(file);
14566 + ii_read_lock_child(inode);
14568 + err = flush(file, id);
14569 + au_cpup_attr_timesizes(inode);
14571 + ii_read_unlock(inode);
14572 + fi_read_unlock(file);
14573 + si_read_unlock(sb);
14577 +/* ---------------------------------------------------------------------- */
14579 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14582 + struct au_pin pin;
14583 + struct au_finfo *finfo;
14584 + struct dentry *parent, *hi_wh;
14585 + struct inode *inode;
14586 + struct super_block *sb;
14587 + struct au_cp_generic cpg = {
14588 + .dentry = file->f_path.dentry,
14593 + .flags = AuCpup_DTIME
14596 + FiMustWriteLock(file);
14599 + finfo = au_fi(file);
14600 + sb = cpg.dentry->d_sb;
14601 + inode = d_inode(cpg.dentry);
14602 + cpg.bdst = au_ibtop(inode);
14603 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14606 + parent = dget_parent(cpg.dentry);
14607 + if (au_test_ro(sb, cpg.bdst, inode)) {
14608 + di_read_lock_parent(parent, !AuLock_IR);
14609 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14611 + di_read_unlock(parent, !AuLock_IR);
14612 + if (unlikely(err < 0))
14617 + di_read_lock_parent(parent, AuLock_IR);
14618 + hi_wh = au_hi_wh(inode, cpg.bdst);
14619 + if (!S_ISDIR(inode->i_mode)
14620 + && au_opt_test(au_mntflags(sb), PLINK)
14621 + && au_plink_test(inode)
14622 + && !d_unhashed(cpg.dentry)
14623 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14624 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14625 + if (unlikely(err))
14628 + /* always superio. */
14629 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14630 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14632 + err = au_sio_cpup_simple(&cpg);
14635 + } else if (hi_wh) {
14636 + /* already copied-up after unlink */
14637 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14638 + *need_reopen = 0;
14642 + di_read_unlock(parent, AuLock_IR);
14649 +static void au_do_refresh_dir(struct file *file)
14651 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14652 + struct au_hfile *p, tmp, *q;
14653 + struct au_finfo *finfo;
14654 + struct super_block *sb;
14655 + struct au_fidir *fidir;
14657 + FiMustWriteLock(file);
14659 + sb = file->f_path.dentry->d_sb;
14660 + finfo = au_fi(file);
14661 + fidir = finfo->fi_hdir;
14662 + AuDebugOn(!fidir);
14663 + p = fidir->fd_hfile + finfo->fi_btop;
14664 + brid = p->hf_br->br_id;
14665 + bbot = fidir->fd_bbot;
14666 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14670 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14671 + if (new_bindex == bindex)
14673 + if (new_bindex < 0) {
14674 + au_set_h_fptr(file, bindex, NULL);
14678 + /* swap two lower inode, and loop again */
14679 + q = fidir->fd_hfile + new_bindex;
14683 + if (tmp.hf_file) {
14689 + p = fidir->fd_hfile;
14690 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14691 + bbot = au_sbbot(sb);
14692 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14693 + finfo->fi_btop++, p++)
14694 + if (p->hf_file) {
14695 + if (file_inode(p->hf_file))
14697 + au_hfput(p, /*execed*/0);
14700 + bbot = au_br_index(sb, brid);
14701 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14702 + finfo->fi_btop++, p++)
14704 + au_hfput(p, /*execed*/0);
14705 + bbot = au_sbbot(sb);
14708 + p = fidir->fd_hfile + bbot;
14709 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14710 + fidir->fd_bbot--, p--)
14711 + if (p->hf_file) {
14712 + if (file_inode(p->hf_file))
14714 + au_hfput(p, /*execed*/0);
14716 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14720 + * after branch manipulating, refresh the file.
14722 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14724 + int err, need_reopen, nbr;
14725 + aufs_bindex_t bbot, bindex;
14726 + struct dentry *dentry;
14727 + struct super_block *sb;
14728 + struct au_finfo *finfo;
14729 + struct au_hfile *hfile;
14731 + dentry = file->f_path.dentry;
14732 + sb = dentry->d_sb;
14733 + nbr = au_sbbot(sb) + 1;
14734 + finfo = au_fi(file);
14735 + if (!finfo->fi_hdir) {
14736 + hfile = &finfo->fi_htop;
14737 + AuDebugOn(!hfile->hf_file);
14738 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14739 + AuDebugOn(bindex < 0);
14740 + if (bindex != finfo->fi_btop)
14741 + au_set_fbtop(file, bindex);
14743 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14744 + if (unlikely(err))
14746 + au_do_refresh_dir(file);
14751 + if (!au_test_mmapped(file))
14752 + err = au_file_refresh_by_inode(file, &need_reopen);
14753 + if (finfo->fi_hdir)
14754 + /* harmless if err */
14755 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14756 + if (!err && need_reopen && !d_unlinked(dentry))
14757 + err = reopen(file);
14759 + au_update_figen(file);
14760 + goto out; /* success */
14763 + /* error, close all lower files */
14764 + if (finfo->fi_hdir) {
14765 + bbot = au_fbbot_dir(file);
14766 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14767 + au_set_h_fptr(file, bindex, NULL);
14774 +/* common function to regular file and dir */
14775 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14776 + int wlock, unsigned int fi_lsc)
14779 + unsigned int sigen, figen;
14780 + aufs_bindex_t btop;
14781 + unsigned char pseudo_link;
14782 + struct dentry *dentry;
14783 + struct inode *inode;
14786 + dentry = file->f_path.dentry;
14787 + inode = d_inode(dentry);
14788 + sigen = au_sigen(dentry->d_sb);
14789 + fi_write_lock_nested(file, fi_lsc);
14790 + figen = au_figen(file);
14792 + di_write_lock_child(dentry);
14794 + di_write_lock_child2(dentry);
14795 + btop = au_dbtop(dentry);
14796 + pseudo_link = (btop != au_ibtop(inode));
14797 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14799 + di_downgrade_lock(dentry, AuLock_IR);
14800 + fi_downgrade_lock(file);
14802 + goto out; /* success */
14805 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14806 + if (au_digen_test(dentry, sigen)) {
14807 + err = au_reval_dpath(dentry, sigen);
14808 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14812 + err = refresh_file(file, reopen);
14815 + di_downgrade_lock(dentry, AuLock_IR);
14816 + fi_downgrade_lock(file);
14819 + di_write_unlock(dentry);
14820 + fi_write_unlock(file);
14827 +/* ---------------------------------------------------------------------- */
14829 +/* cf. aufs_nopage() */
14830 +/* for madvise(2) */
14831 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14833 + folio_unlock(folio);
14837 +/* it will never be called, but necessary to support O_DIRECT */
14838 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14839 +{ BUG(); return 0; }
14841 +/* they will never be called. */
14842 +#ifdef CONFIG_AUFS_DEBUG
14843 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14844 + loff_t pos, unsigned len,
14845 + struct page **pagep, void **fsdata)
14846 +{ AuUnsupport(); return 0; }
14847 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14848 + loff_t pos, unsigned len, unsigned copied,
14849 + struct page *page, void *fsdata)
14850 +{ AuUnsupport(); return 0; }
14851 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14852 +{ AuUnsupport(); return 0; }
14854 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14855 +{ AuUnsupport(); return true; }
14856 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14857 +{ AuUnsupport(); }
14858 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14859 +{ AuUnsupport(); return true; }
14860 +#if 0 /* called by memory compaction regardless file */
14861 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14862 + struct folio *src, enum migrate_mode mode)
14863 +{ AuUnsupport(); return 0; }
14865 +static int aufs_launder_folio(struct folio *folio)
14866 +{ AuUnsupport(); return 0; }
14867 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14869 +{ AuUnsupport(); return true; }
14870 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14872 +{ AuUnsupport(); }
14873 +static int aufs_error_remove_page(struct address_space *mapping,
14874 + struct page *page)
14875 +{ AuUnsupport(); return 0; }
14876 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14878 +{ AuUnsupport(); return 0; }
14879 +static void aufs_swap_deactivate(struct file *file)
14880 +{ AuUnsupport(); }
14881 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14882 +{ AuUnsupport(); return 0; }
14883 +#endif /* CONFIG_AUFS_DEBUG */
14885 +const struct address_space_operations aufs_aop = {
14886 + .read_folio = aufs_read_folio,
14887 + .direct_IO = aufs_direct_IO,
14888 +#ifdef CONFIG_AUFS_DEBUG
14889 + .writepage = aufs_writepage,
14890 + /* no writepages, because of writepage */
14891 + .dirty_folio = aufs_dirty_folio,
14892 + /* no readpages, because of readpage */
14893 + .write_begin = aufs_write_begin,
14894 + .write_end = aufs_write_end,
14895 + /* no bmap, no block device */
14896 + .invalidate_folio = aufs_invalidate_folio,
14897 + .release_folio = aufs_release_folio,
14898 + /* is fallback_migrate_page ok? */
14899 + /* .migrate_folio = aufs_migrate_folio, */
14900 + .launder_folio = aufs_launder_folio,
14901 + .is_partially_uptodate = aufs_is_partially_uptodate,
14902 + .is_dirty_writeback = aufs_is_dirty_writeback,
14903 + .error_remove_page = aufs_error_remove_page,
14904 + .swap_activate = aufs_swap_activate,
14905 + .swap_deactivate = aufs_swap_deactivate,
14906 + .swap_rw = aufs_swap_rw
14907 +#endif /* CONFIG_AUFS_DEBUG */
14909 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14910 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14911 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14913 +/* SPDX-License-Identifier: GPL-2.0 */
14915 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14917 + * This program is free software; you can redistribute it and/or modify
14918 + * it under the terms of the GNU General Public License as published by
14919 + * the Free Software Foundation; either version 2 of the License, or
14920 + * (at your option) any later version.
14922 + * This program is distributed in the hope that it will be useful,
14923 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14924 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14925 + * GNU General Public License for more details.
14927 + * You should have received a copy of the GNU General Public License
14928 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14932 + * file operations
14935 +#ifndef __AUFS_FILE_H__
14936 +#define __AUFS_FILE_H__
14940 +#include <linux/file.h>
14941 +#include <linux/fs.h>
14942 +#include <linux/mm_types.h>
14943 +#include <linux/poll.h>
14944 +#include "rwsem.h"
14948 + struct file *hf_file;
14949 + struct au_branch *hf_br;
14954 + aufs_bindex_t fd_bbot;
14955 + aufs_bindex_t fd_nent;
14956 + struct au_vdir *fd_vdir_cache;
14957 + struct au_hfile fd_hfile[];
14960 +static inline int au_fidir_sz(int nent)
14962 + AuDebugOn(nent < 0);
14963 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14967 + atomic_t fi_generation;
14969 + struct au_rwsem fi_rwsem;
14970 + aufs_bindex_t fi_btop;
14972 + /* do not union them */
14973 + struct { /* for non-dir */
14974 + struct au_hfile fi_htop;
14975 + atomic_t fi_mmapped;
14977 + struct au_fidir *fi_hdir; /* for dir only */
14979 + struct hlist_bl_node fi_hlist;
14980 + struct file *fi_file; /* very ugly */
14981 + struct rcu_head rcu;
14982 +} ____cacheline_aligned_in_smp;
14984 +/* ---------------------------------------------------------------------- */
14987 +extern const struct address_space_operations aufs_aop;
14988 +unsigned int au_file_roflags(unsigned int flags);
14989 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14990 + struct file *file, int force_wr);
14991 +struct au_do_open_args {
14993 + int (*open)(struct file *file, int flags,
14994 + struct file *h_file);
14995 + struct au_fidir *fidir;
14996 + struct file *h_file;
14998 +int au_do_open(struct file *file, struct au_do_open_args *args);
14999 +int au_reopen_nondir(struct file *file);
15001 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15002 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15003 + int wlock, unsigned int fi_lsc);
15004 +int au_do_flush(struct file *file, fl_owner_t id,
15005 + int (*flush)(struct file *file, fl_owner_t id));
15008 +#ifdef CONFIG_AUFS_POLL
15009 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15012 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15014 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15016 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15017 + struct file *h_file);
15019 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15020 + aufs_bindex_t bindex, int force_wr)
15021 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15022 + struct file *h_file);
15026 +extern const struct file_operations aufs_file_fop;
15027 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15028 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15029 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15032 +void au_hfput(struct au_hfile *hf, int execed);
15033 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15034 + struct file *h_file);
15036 +void au_update_figen(struct file *file);
15037 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15038 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15040 +void au_fi_init_once(void *_fi);
15041 +void au_finfo_fin(struct file *file);
15042 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15045 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15046 +#ifdef CONFIG_COMPAT
15047 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15048 + unsigned long arg);
15049 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15050 + unsigned long arg);
15053 +/* ---------------------------------------------------------------------- */
15055 +static inline struct au_finfo *au_fi(struct file *file)
15057 + return file->private_data;
15060 +/* ---------------------------------------------------------------------- */
15062 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15063 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15064 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15065 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15067 +#define fi_read_trylock_nested(f) \
15068 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15069 +#define fi_write_trylock_nested(f) \
15070 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15073 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15074 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15075 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15077 +/* lock subclass for finfo */
15083 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15085 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15088 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15090 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15094 + * fi_read_lock_1, fi_write_lock_1,
15095 + * fi_read_lock_2, fi_write_lock_2
15097 +#define AuReadLockFunc(name) \
15098 +static inline void fi_read_lock_##name(struct file *f) \
15099 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15101 +#define AuWriteLockFunc(name) \
15102 +static inline void fi_write_lock_##name(struct file *f) \
15103 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15105 +#define AuRWLockFuncs(name) \
15106 + AuReadLockFunc(name) \
15107 + AuWriteLockFunc(name)
15112 +#undef AuReadLockFunc
15113 +#undef AuWriteLockFunc
15114 +#undef AuRWLockFuncs
15116 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15117 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15118 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15120 +/* ---------------------------------------------------------------------- */
15122 +/* todo: hard/soft set? */
15123 +static inline aufs_bindex_t au_fbtop(struct file *file)
15125 + FiMustAnyLock(file);
15126 + return au_fi(file)->fi_btop;
15129 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15131 + FiMustAnyLock(file);
15132 + AuDebugOn(!au_fi(file)->fi_hdir);
15133 + return au_fi(file)->fi_hdir->fd_bbot;
15136 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15138 + FiMustAnyLock(file);
15139 + AuDebugOn(!au_fi(file)->fi_hdir);
15140 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15143 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15145 + FiMustWriteLock(file);
15146 + au_fi(file)->fi_btop = bindex;
15149 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15151 + FiMustWriteLock(file);
15152 + AuDebugOn(!au_fi(file)->fi_hdir);
15153 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15156 +static inline void au_set_fvdir_cache(struct file *file,
15157 + struct au_vdir *vdir_cache)
15159 + FiMustWriteLock(file);
15160 + AuDebugOn(!au_fi(file)->fi_hdir);
15161 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15164 +static inline struct file *au_hf_top(struct file *file)
15166 + FiMustAnyLock(file);
15167 + AuDebugOn(au_fi(file)->fi_hdir);
15168 + return au_fi(file)->fi_htop.hf_file;
15171 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15173 + FiMustAnyLock(file);
15174 + AuDebugOn(!au_fi(file)->fi_hdir);
15175 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15178 +/* todo: memory barrier? */
15179 +static inline unsigned int au_figen(struct file *f)
15181 + return atomic_read(&au_fi(f)->fi_generation);
15184 +static inline void au_set_mmapped(struct file *f)
15186 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15188 + pr_warn("fi_mmapped wrapped around\n");
15189 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15193 +static inline void au_unset_mmapped(struct file *f)
15195 + atomic_dec(&au_fi(f)->fi_mmapped);
15198 +static inline int au_test_mmapped(struct file *f)
15200 + return atomic_read(&au_fi(f)->fi_mmapped);
15203 +/* customize vma->vm_file */
15205 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15206 + struct file *file)
15210 + f = vma->vm_file;
15212 + vma->vm_file = file;
15217 +#define AuDbgVmRegion(file, vma) do {} while (0)
15219 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15220 + struct file *file)
15222 + au_do_vm_file_reset(vma, file);
15225 +#define AuDbgVmRegion(file, vma) \
15226 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15228 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15229 + struct file *file)
15233 + au_do_vm_file_reset(vma, file);
15234 + f = vma->vm_region->vm_file;
15236 + vma->vm_region->vm_file = file;
15239 +#endif /* CONFIG_MMU */
15241 +/* handle vma->vm_prfile */
15242 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15243 + struct file *file)
15246 + vma->vm_prfile = file;
15247 +#ifndef CONFIG_MMU
15249 + vma->vm_region->vm_prfile = file;
15253 +#endif /* __KERNEL__ */
15254 +#endif /* __AUFS_FILE_H__ */
15255 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15256 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15257 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15259 +// SPDX-License-Identifier: GPL-2.0
15261 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15263 + * This program is free software; you can redistribute it and/or modify
15264 + * it under the terms of the GNU General Public License as published by
15265 + * the Free Software Foundation; either version 2 of the License, or
15266 + * (at your option) any later version.
15268 + * This program is distributed in the hope that it will be useful,
15269 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15270 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15271 + * GNU General Public License for more details.
15273 + * You should have received a copy of the GNU General Public License
15274 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15278 + * file private data
15283 +void au_hfput(struct au_hfile *hf, int execed)
15286 + allow_write_access(hf->hf_file);
15287 + fput(hf->hf_file);
15288 + hf->hf_file = NULL;
15289 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15290 + hf->hf_br = NULL;
15293 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15295 + struct au_finfo *finfo = au_fi(file);
15296 + struct au_hfile *hf;
15297 + struct au_fidir *fidir;
15299 + fidir = finfo->fi_hdir;
15301 + AuDebugOn(finfo->fi_btop != bindex);
15302 + hf = &finfo->fi_htop;
15304 + hf = fidir->fd_hfile + bindex;
15306 + if (hf && hf->hf_file)
15307 + au_hfput(hf, vfsub_file_execed(file));
15309 + FiMustWriteLock(file);
15310 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15311 + hf->hf_file = val;
15312 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15316 +void au_update_figen(struct file *file)
15318 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15319 + /* smp_mb(); */ /* atomic_set */
15322 +/* ---------------------------------------------------------------------- */
15324 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15326 + struct au_fidir *fidir;
15329 + nbr = au_sbbot(sb) + 1;
15331 + nbr = 2; /* initial allocate for 2 branches */
15332 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15334 + fidir->fd_bbot = -1;
15335 + fidir->fd_nent = nbr;
15341 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15344 + struct au_fidir *fidir, *p;
15346 + AuRwMustWriteLock(&finfo->fi_rwsem);
15347 + fidir = finfo->fi_hdir;
15348 + AuDebugOn(!fidir);
15351 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15352 + GFP_NOFS, may_shrink);
15354 + p->fd_nent = nbr;
15355 + finfo->fi_hdir = p;
15362 +/* ---------------------------------------------------------------------- */
15364 +void au_finfo_fin(struct file *file)
15366 + struct au_finfo *finfo;
15368 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15370 + finfo = au_fi(file);
15371 + AuDebugOn(finfo->fi_hdir);
15372 + AuRwDestroy(&finfo->fi_rwsem);
15373 + au_cache_free_finfo(finfo);
15376 +void au_fi_init_once(void *_finfo)
15378 + struct au_finfo *finfo = _finfo;
15380 + au_rw_init(&finfo->fi_rwsem);
15383 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15386 + struct au_finfo *finfo;
15387 + struct dentry *dentry;
15390 + dentry = file->f_path.dentry;
15391 + finfo = au_cache_alloc_finfo();
15392 + if (unlikely(!finfo))
15396 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15397 + au_rw_write_lock(&finfo->fi_rwsem);
15398 + finfo->fi_btop = -1;
15399 + finfo->fi_hdir = fidir;
15400 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15401 + /* smp_mb(); */ /* atomic_set */
15403 + file->private_data = finfo;
15408 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15409 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15410 +++ linux/fs/aufs/f_op.c 2023-10-31 09:31:04.196547417 +0100
15412 +// SPDX-License-Identifier: GPL-2.0
15414 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15416 + * This program is free software; you can redistribute it and/or modify
15417 + * it under the terms of the GNU General Public License as published by
15418 + * the Free Software Foundation; either version 2 of the License, or
15419 + * (at your option) any later version.
15421 + * This program is distributed in the hope that it will be useful,
15422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15424 + * GNU General Public License for more details.
15426 + * You should have received a copy of the GNU General Public License
15427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15431 + * file and vm operations
15434 +#include <linux/aio.h>
15435 +#include <linux/fs_stack.h>
15436 +#include <linux/mman.h>
15437 +#include <linux/security.h>
15440 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15443 + aufs_bindex_t bindex;
15444 + struct dentry *dentry, *h_dentry;
15445 + struct au_finfo *finfo;
15446 + struct inode *h_inode;
15448 + FiMustWriteLock(file);
15451 + dentry = file->f_path.dentry;
15452 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15453 + finfo = au_fi(file);
15454 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15455 + atomic_set(&finfo->fi_mmapped, 0);
15456 + bindex = au_dbtop(dentry);
15458 + h_dentry = au_h_dptr(dentry, bindex);
15459 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15460 + if (unlikely(err))
15462 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15463 + if (IS_ERR(h_file)) {
15464 + err = PTR_ERR(h_file);
15468 + h_dentry = h_file->f_path.dentry;
15469 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15470 + if (unlikely(err))
15472 + /* br ref is already inc-ed */
15475 + if (flags & __O_TMPFILE) {
15476 + AuDebugOn(!h_file);
15477 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15478 + au_di(dentry)->di_htmpfile = NULL;
15480 + if (!(flags & O_EXCL)) {
15481 + h_inode = file_inode(h_file);
15482 + spin_lock(&h_inode->i_lock);
15483 + h_inode->i_state |= I_LINKABLE;
15484 + spin_unlock(&h_inode->i_lock);
15487 + au_set_fbtop(file, bindex);
15488 + au_set_h_fptr(file, bindex, h_file);
15489 + au_update_figen(file);
15490 + /* todo: necessary? */
15491 + /* file->f_ra = h_file->f_ra; */
15497 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15498 + struct file *file)
15501 + struct super_block *sb;
15502 + struct au_do_open_args args = {
15503 + .open = au_do_open_nondir
15506 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15507 + file, vfsub_file_flags(file), file->f_mode);
15509 + sb = file->f_path.dentry->d_sb;
15510 + si_read_lock(sb, AuLock_FLUSH);
15511 + err = au_do_open(file, &args);
15512 + si_read_unlock(sb);
15516 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15518 + struct au_finfo *finfo;
15519 + aufs_bindex_t bindex;
15521 + finfo = au_fi(file);
15522 + au_hbl_del(&finfo->fi_hlist,
15523 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15524 + bindex = finfo->fi_btop;
15526 + au_set_h_fptr(file, bindex, NULL);
15528 + au_finfo_fin(file);
15532 +/* ---------------------------------------------------------------------- */
15534 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15537 + struct file *h_file;
15540 + h_file = au_hf_top(file);
15542 + err = vfsub_flush(h_file, id);
15546 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15548 + return au_do_flush(file, id, au_do_flush_nondir);
15551 +/* ---------------------------------------------------------------------- */
15553 + * read and write functions acquire [fdi]_rwsem once, but release before
15554 + * mmap_sem. This is because to stop a race condition between mmap(2).
15555 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15556 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15557 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15560 +/* Callers should call au_read_post() or fput() in the end */
15561 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15563 + struct file *h_file;
15566 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15568 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15569 + h_file = au_hf_top(file);
15570 + get_file(h_file);
15572 + fi_read_unlock(file);
15574 + h_file = ERR_PTR(err);
15579 +static void au_read_post(struct inode *inode, struct file *h_file)
15581 + /* update without lock, I don't think it a problem */
15582 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15586 +struct au_write_pre {
15588 + unsigned int lsc;
15592 + aufs_bindex_t btop;
15596 + * return with iinfo is write-locked
15597 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15600 +static struct file *au_write_pre(struct file *file, int do_ready,
15601 + struct au_write_pre *wpre)
15603 + struct file *h_file;
15604 + struct dentry *dentry;
15606 + unsigned int lsc;
15607 + struct au_pin pin;
15612 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15613 + h_file = ERR_PTR(err);
15614 + if (unlikely(err))
15617 + dentry = file->f_path.dentry;
15619 + err = au_ready_to_write(file, -1, &pin);
15620 + if (unlikely(err)) {
15621 + h_file = ERR_PTR(err);
15622 + di_write_unlock(dentry);
15627 + di_downgrade_lock(dentry, /*flags*/0);
15629 + wpre->btop = au_fbtop(file);
15630 + h_file = au_hf_top(file);
15631 + get_file(h_file);
15633 + wpre->blks = file_inode(h_file)->i_blocks;
15636 + di_read_unlock(dentry, /*flags*/0);
15637 + vfsub_file_start_write(h_file);
15640 + fi_write_unlock(file);
15645 +static void au_write_post(struct inode *inode, struct file *h_file,
15646 + struct au_write_pre *wpre, ssize_t written)
15648 + struct inode *h_inode;
15650 + vfsub_file_end_write(h_file);
15651 + au_cpup_attr_timesizes(inode);
15652 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15653 + h_inode = file_inode(h_file);
15654 + inode->i_mode = h_inode->i_mode;
15655 + ii_write_unlock(inode);
15656 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15658 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15659 + /*force*/h_inode->i_blocks > wpre->blks);
15664 + * todo: very ugly
15665 + * it locks both of i_mutex and si_rwsem for read in safe.
15666 + * if the plink maintenance mode continues forever (that is the problem),
15667 + * may loop forever.
15669 +static void au_mtx_and_read_lock(struct inode *inode)
15672 + struct super_block *sb = inode->i_sb;
15675 + inode_lock(inode);
15676 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15679 + inode_unlock(inode);
15680 + si_read_lock(sb, AuLock_NOPLMW);
15681 + si_read_unlock(sb);
15685 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15686 + struct iov_iter *iov_iter)
15689 + struct file *file;
15690 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15692 + err = security_file_permission(h_file, rw);
15693 + if (unlikely(err))
15696 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15698 + if (rw == MAY_READ)
15699 + iter = h_file->f_op->read_iter;
15700 + else if (rw == MAY_WRITE)
15701 + iter = h_file->f_op->write_iter;
15703 + file = kio->ki_filp;
15704 + kio->ki_filp = h_file;
15707 + err = iter(kio, iov_iter);
15710 + /* currently there is no such fs */
15712 + kio->ki_filp = file;
15718 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15721 + struct file *file, *h_file;
15722 + struct inode *inode;
15723 + struct super_block *sb;
15725 + file = kio->ki_filp;
15726 + inode = file_inode(file);
15727 + sb = inode->i_sb;
15728 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15730 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15731 + err = PTR_ERR(h_file);
15732 + if (IS_ERR(h_file))
15735 + if (au_test_loopback_kthread()) {
15736 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15737 + if (file->f_mapping != h_file->f_mapping) {
15738 + file->f_mapping = h_file->f_mapping;
15739 + smp_mb(); /* unnecessary? */
15742 + fi_read_unlock(file);
15744 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15745 + /* todo: necessary? */
15746 + /* file->f_ra = h_file->f_ra; */
15747 + au_read_post(inode, h_file);
15750 + si_read_unlock(sb);
15754 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15757 + struct au_write_pre wpre;
15758 + struct inode *inode;
15759 + struct file *file, *h_file;
15761 + file = kio->ki_filp;
15762 + inode = file_inode(file);
15763 + au_mtx_and_read_lock(inode);
15766 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15767 + err = PTR_ERR(h_file);
15768 + if (IS_ERR(h_file))
15771 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15772 + au_write_post(inode, h_file, &wpre, err);
15775 + si_read_unlock(inode->i_sb);
15776 + inode_unlock(inode);
15781 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15782 + * don't have their own .splice_{read,write} implimentations, and they use
15783 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15784 + * simple converters to f_op->iter_read() and ->iter_write().
15785 + * But we keep our own implementations because some non-mainlined FSes may have
15786 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15787 + * away an opportunity to co-work with aufs from them.
15789 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15790 + struct pipe_inode_info *pipe, size_t len,
15791 + unsigned int flags)
15794 + struct file *h_file;
15795 + struct inode *inode;
15796 + struct super_block *sb;
15798 + inode = file_inode(file);
15799 + sb = inode->i_sb;
15800 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15802 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15803 + err = PTR_ERR(h_file);
15804 + if (IS_ERR(h_file))
15807 + err = vfsub_splice_read(h_file, ppos, pipe, len, flags);
15808 + /* todo: necessary? */
15809 + /* file->f_ra = h_file->f_ra; */
15810 + au_read_post(inode, h_file);
15813 + si_read_unlock(sb);
15818 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15819 + size_t len, unsigned int flags)
15822 + struct au_write_pre wpre;
15823 + struct inode *inode;
15824 + struct file *h_file;
15826 + inode = file_inode(file);
15827 + au_mtx_and_read_lock(inode);
15830 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15831 + err = PTR_ERR(h_file);
15832 + if (IS_ERR(h_file))
15835 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15836 + au_write_post(inode, h_file, &wpre, err);
15839 + si_read_unlock(inode->i_sb);
15840 + inode_unlock(inode);
15844 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15848 + struct au_write_pre wpre;
15849 + struct inode *inode;
15850 + struct file *h_file;
15852 + inode = file_inode(file);
15853 + au_mtx_and_read_lock(inode);
15856 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15857 + err = PTR_ERR(h_file);
15858 + if (IS_ERR(h_file))
15862 + err = vfs_fallocate(h_file, mode, offset, len);
15865 + * we don't need to call file_modifed() here since au_write_post()
15866 + * is equivalent and copies-up all timestamps and permission bits.
15868 + au_write_post(inode, h_file, &wpre, /*written*/1);
15871 + si_read_unlock(inode->i_sb);
15872 + inode_unlock(inode);
15876 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15877 + struct file *dst, loff_t dst_pos,
15878 + size_t len, unsigned int flags)
15881 + struct au_write_pre wpre;
15882 + enum { SRC, DST };
15884 + struct inode *inode;
15885 + struct file *h_file;
15886 + struct super_block *h_sb;
15888 +#define a_src a[SRC]
15889 +#define a_dst a[DST]
15892 + a_src.inode = file_inode(src);
15893 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15895 + a_dst.inode = file_inode(dst);
15896 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15899 + au_mtx_and_read_lock(a_dst.inode);
15901 + * in order to match the order in di_write_lock2_{child,parent}(),
15902 + * use f_path.dentry for this comparison.
15904 + if (src->f_path.dentry < dst->f_path.dentry) {
15905 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15906 + err = PTR_ERR(a_src.h_file);
15907 + if (IS_ERR(a_src.h_file))
15910 + wpre.lsc = AuLsc_FI_2;
15911 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15912 + err = PTR_ERR(a_dst.h_file);
15913 + if (IS_ERR(a_dst.h_file)) {
15914 + au_read_post(a_src.inode, a_src.h_file);
15918 + wpre.lsc = AuLsc_FI_1;
15919 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15920 + err = PTR_ERR(a_dst.h_file);
15921 + if (IS_ERR(a_dst.h_file))
15924 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15925 + err = PTR_ERR(a_src.h_file);
15926 + if (IS_ERR(a_src.h_file)) {
15927 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15934 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15935 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15936 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15942 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15943 + dst_pos, len, flags);
15946 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15947 + fi_read_unlock(src);
15948 + au_read_post(a_src.inode, a_src.h_file);
15950 + si_read_unlock(a_dst.inode->i_sb);
15951 + inode_unlock(a_dst.inode);
15958 +/* ---------------------------------------------------------------------- */
15961 + * The locking order around current->mmap_sem.
15962 + * - in most and regular cases
15963 + * file I/O syscall -- aufs_read() or something
15964 + * -- si_rwsem for read -- mmap_sem
15965 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15967 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15968 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15969 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15970 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15971 + * It means that when aufs acquires si_rwsem for write, the process should never
15972 + * acquire mmap_sem.
15974 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15975 + * problem either since any directory is not able to be mmap-ed.
15976 + * The similar scenario is applied to aufs_readlink() too.
15979 +#if 0 /* stop calling security_file_mmap() */
15980 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15981 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15983 +static unsigned long au_arch_prot_conv(unsigned long flags)
15985 + /* currently ppc64 only */
15986 +#ifdef CONFIG_PPC64
15987 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15988 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15989 + return AuConv_VM_PROT(flags, SAO);
15991 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15996 +static unsigned long au_prot_conv(unsigned long flags)
15998 + return AuConv_VM_PROT(flags, READ)
15999 + | AuConv_VM_PROT(flags, WRITE)
16000 + | AuConv_VM_PROT(flags, EXEC)
16001 + | au_arch_prot_conv(flags);
16004 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16005 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16007 +static unsigned long au_flag_conv(unsigned long flags)
16009 + return AuConv_VM_MAP(flags, GROWSDOWN)
16010 + | AuConv_VM_MAP(flags, DENYWRITE)
16011 + | AuConv_VM_MAP(flags, LOCKED);
16015 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16018 + const unsigned char wlock
16019 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16020 + struct super_block *sb;
16021 + struct file *h_file;
16022 + struct inode *inode;
16024 + AuDbgVmRegion(file, vma);
16026 + inode = file_inode(file);
16027 + sb = inode->i_sb;
16029 + si_read_lock(sb, AuLock_NOPLMW);
16031 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16033 + err = PTR_ERR(h_file);
16034 + if (IS_ERR(h_file))
16038 + au_set_mmapped(file);
16039 + au_vm_file_reset(vma, h_file);
16041 + * we cannot call security_mmap_file() here since it may acquire
16042 + * mmap_sem or i_mutex.
16044 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16045 + * au_flag_conv(vma->vm_flags));
16048 + err = call_mmap(h_file, vma);
16050 + au_vm_prfile_set(vma, file);
16051 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16052 + goto out_fput; /* success */
16054 + au_unset_mmapped(file);
16055 + au_vm_file_reset(vma, file);
16059 + ii_write_unlock(inode);
16064 + si_read_unlock(sb);
16070 +/* ---------------------------------------------------------------------- */
16072 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16076 + struct au_write_pre wpre;
16077 + struct inode *inode;
16078 + struct file *h_file;
16080 + err = 0; /* -EBADF; */ /* posix? */
16081 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16084 + inode = file_inode(file);
16085 + au_mtx_and_read_lock(inode);
16088 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16089 + err = PTR_ERR(h_file);
16090 + if (IS_ERR(h_file))
16093 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16094 + au_write_post(inode, h_file, &wpre, /*written*/0);
16097 + si_read_unlock(inode->i_sb);
16098 + inode_unlock(inode);
16103 +static int aufs_fasync(int fd, struct file *file, int flag)
16106 + struct file *h_file;
16107 + struct super_block *sb;
16109 + sb = file->f_path.dentry->d_sb;
16110 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16112 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16113 + err = PTR_ERR(h_file);
16114 + if (IS_ERR(h_file))
16117 + if (h_file->f_op->fasync)
16118 + err = h_file->f_op->fasync(fd, h_file, flag);
16119 + fput(h_file); /* instead of au_read_post() */
16122 + si_read_unlock(sb);
16126 +static int aufs_setfl(struct file *file, unsigned long arg)
16129 + struct file *h_file;
16130 + struct super_block *sb;
16132 + sb = file->f_path.dentry->d_sb;
16133 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16135 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16136 + err = PTR_ERR(h_file);
16137 + if (IS_ERR(h_file))
16140 + /* stop calling h_file->fasync */
16141 + arg |= vfsub_file_flags(file) & FASYNC;
16142 + err = setfl(/*unused fd*/-1, h_file, arg);
16143 + fput(h_file); /* instead of au_read_post() */
16146 + si_read_unlock(sb);
16150 +/* ---------------------------------------------------------------------- */
16152 +const struct file_operations aufs_file_fop = {
16153 + .owner = THIS_MODULE,
16155 + .llseek = default_llseek,
16157 + .read_iter = aufs_read_iter,
16158 + .write_iter = aufs_write_iter,
16160 +#ifdef CONFIG_AUFS_POLL
16161 + .poll = aufs_poll,
16163 + .unlocked_ioctl = aufs_ioctl_nondir,
16164 +#ifdef CONFIG_COMPAT
16165 + .compat_ioctl = aufs_compat_ioctl_nondir,
16167 + .mmap = aufs_mmap,
16168 + .open = aufs_open_nondir,
16169 + .flush = aufs_flush_nondir,
16170 + .release = aufs_release_nondir,
16171 + .fsync = aufs_fsync_nondir,
16172 + .fasync = aufs_fasync,
16173 + .setfl = aufs_setfl,
16174 + .splice_write = aufs_splice_write,
16175 + .splice_read = aufs_splice_read,
16176 +#if 0 /* reserved for future use */
16177 + .aio_splice_write = aufs_aio_splice_write,
16178 + .aio_splice_read = aufs_aio_splice_read,
16180 + .fallocate = aufs_fallocate,
16181 + .copy_file_range = aufs_copy_file_range
16183 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16184 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16185 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16187 +// SPDX-License-Identifier: GPL-2.0
16189 + * Copyright (C) 2022 Junjiro R. Okajima
16191 + * This program is free software; you can redistribute it and/or modify
16192 + * it under the terms of the GNU General Public License as published by
16193 + * the Free Software Foundation; either version 2 of the License, or
16194 + * (at your option) any later version.
16196 + * This program is distributed in the hope that it will be useful,
16197 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16198 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16199 + * GNU General Public License for more details.
16201 + * You should have received a copy of the GNU General Public License
16202 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16206 + * fs context, aka new mount api
16209 +#include <linux/fs_context.h>
16212 +struct au_fsctx_opts {
16213 + aufs_bindex_t bindex;
16214 + unsigned char skipped;
16215 + struct au_opt *opt, *opt_tail;
16216 + struct super_block *sb;
16217 + struct au_sbinfo *sbinfo;
16218 + struct au_opts opts;
16221 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16222 +static int cvt_err(int err)
16236 +static int au_fsctx_reconfigure(struct fs_context *fc)
16239 + unsigned int mntflags;
16240 + struct dentry *root;
16241 + struct super_block *sb;
16242 + struct inode *inode;
16243 + struct au_fsctx_opts *a = fc->fs_private;
16245 + AuDbg("fc %p\n", fc);
16249 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16251 + di_write_lock_child(root);
16252 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16253 + aufs_write_unlock(root);
16256 + inode = d_inode(root);
16257 + inode_lock(inode);
16258 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16259 + if (unlikely(err))
16261 + di_write_lock_child(root);
16263 + /* au_opts_remount() may return an error */
16264 + err = au_opts_remount(sb, &a->opts);
16266 + if (au_ftest_opts(a->opts.flags, REFRESH))
16267 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16270 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16271 + mntflags = au_mntflags(sb);
16272 + do_dx = !!au_opt_test(mntflags, DIO);
16273 + au_dy_arefresh(do_dx);
16276 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16277 + aufs_write_unlock(root);
16280 + inode_unlock(inode);
16281 + err = cvt_err(err);
16287 +/* ---------------------------------------------------------------------- */
16289 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16292 + struct au_fsctx_opts *a = fc->fs_private;
16293 + struct au_sbinfo *sbinfo = a->sbinfo;
16294 + struct dentry *root;
16295 + struct inode *inode;
16297 + sbinfo->si_sb = sb;
16298 + sb->s_fs_info = sbinfo;
16299 + kobject_get(&sbinfo->si_kobj);
16301 + __si_write_lock(sb);
16303 + au_sbilist_add(sb);
16305 + /* all timestamps always follow the ones on the branch */
16306 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16307 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16308 + sb->s_op = &aufs_sop;
16309 + sb->s_d_op = &aufs_dop;
16310 + sb->s_magic = AUFS_SUPER_MAGIC;
16311 + sb->s_maxbytes = 0;
16312 + sb->s_stack_depth = 1;
16313 + au_export_init(sb);
16314 + au_xattr_init(sb);
16316 + err = au_alloc_root(sb);
16317 + if (unlikely(err)) {
16318 + si_write_unlock(sb);
16321 + root = sb->s_root;
16322 + inode = d_inode(root);
16323 + ii_write_lock_parent(inode);
16324 + aufs_write_unlock(root);
16326 + /* lock vfs_inode first, then aufs. */
16327 + inode_lock(inode);
16328 + aufs_write_lock(root);
16329 + err = au_opts_mount(sb, &a->opts);
16331 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16332 + sb->s_d_op = &aufs_dop_noreval;
16333 + /* infofc(fc, "%ps", sb->s_d_op); */
16334 + pr_info("%ps\n", sb->s_d_op);
16335 + au_refresh_dop(root, /*force_reval*/0);
16336 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16337 + au_refresh_iop(inode, /*force_getattr*/0);
16339 + aufs_write_unlock(root);
16340 + inode_unlock(inode);
16342 + goto out; /* success */
16345 + sb->s_root = NULL;
16348 + if (unlikely(err))
16349 + kobject_put(&sbinfo->si_kobj);
16351 + err = cvt_err(err);
16356 +static int au_fsctx_get_tree(struct fs_context *fc)
16360 + AuDbg("fc %p\n", fc);
16361 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16367 +/* ---------------------------------------------------------------------- */
16369 +static void au_fsctx_dump(struct au_opts *opts)
16371 +#ifdef CONFIG_AUFS_DEBUG
16372 + /* reduce stack space */
16374 + struct au_opt_add *add;
16375 + struct au_opt_del *del;
16376 + struct au_opt_mod *mod;
16377 + struct au_opt_xino *xino;
16378 + struct au_opt_xino_itrunc *xino_itrunc;
16379 + struct au_opt_wbr_create *create;
16381 + struct au_opt *opt;
16384 + while (opt->type != Opt_tail) {
16385 + switch (opt->type) {
16387 + u.add = &opt->add;
16388 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16389 + u.add->bindex, u.add->pathname, u.add->perm,
16390 + u.add->path.dentry);
16395 + u.del = &opt->del;
16396 + AuDbg("del {%s, %p}\n",
16397 + u.del->pathname, u.del->h_path.dentry);
16402 + u.mod = &opt->mod;
16403 + AuDbg("mod {%s, 0x%x, %p}\n",
16404 + u.mod->path, u.mod->perm, u.mod->h_root);
16407 + u.add = &opt->add;
16408 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16409 + u.add->bindex, u.add->pathname, u.add->perm,
16410 + u.add->path.dentry);
16412 + case Opt_prepend:
16413 + u.add = &opt->add;
16414 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16415 + u.add->bindex, u.add->pathname, u.add->perm,
16416 + u.add->path.dentry);
16420 + AuDbg("dirwh %d\n", opt->dirwh);
16422 + case Opt_rdcache:
16423 + AuDbg("rdcache %d\n", opt->rdcache);
16426 + AuDbg("rdblk %d\n", opt->rdblk);
16429 + AuDbg("rdhash %u\n", opt->rdhash);
16433 + u.xino = &opt->xino;
16434 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16437 +#define au_fsctx_TF(name) \
16438 + case Opt_##name: \
16442 + AuLabel(no##name); \
16445 + /* simple true/false flag */
16446 + au_fsctx_TF(trunc_xino);
16447 + au_fsctx_TF(trunc_xib);
16448 + au_fsctx_TF(dirperm1);
16449 + au_fsctx_TF(plink);
16450 + au_fsctx_TF(shwh);
16451 + au_fsctx_TF(dio);
16452 + au_fsctx_TF(warn_perm);
16453 + au_fsctx_TF(verbose);
16454 + au_fsctx_TF(sum);
16455 + au_fsctx_TF(dirren);
16456 + au_fsctx_TF(acl);
16457 +#undef au_fsctx_TF
16459 + case Opt_trunc_xino_path:
16461 + case Opt_itrunc_xino:
16462 + u.xino_itrunc = &opt->xino_itrunc;
16463 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16469 + case Opt_list_plink:
16470 + AuLabel(list_plink);
16473 + AuDbg("udba %d, %s\n",
16474 + opt->udba, au_optstr_udba(opt->udba));
16476 + case Opt_diropq_a:
16477 + AuLabel(diropq_a);
16479 + case Opt_diropq_w:
16480 + AuLabel(diropq_w);
16485 + case Opt_wbr_create:
16486 + u.create = &opt->wbr_create;
16487 + AuDbg("create %d, %s\n", u.create->wbr_create,
16488 + au_optstr_wbr_create(u.create->wbr_create));
16489 + switch (u.create->wbr_create) {
16490 + case AuWbrCreate_MFSV:
16492 + case AuWbrCreate_PMFSV:
16493 + AuDbg("%d sec\n", u.create->mfs_second);
16495 + case AuWbrCreate_MFSRR:
16497 + case AuWbrCreate_TDMFS:
16498 + AuDbg("%llu watermark\n",
16499 + u.create->mfsrr_watermark);
16501 + case AuWbrCreate_MFSRRV:
16503 + case AuWbrCreate_TDMFSV:
16505 + case AuWbrCreate_PMFSRRV:
16506 + AuDbg("%llu watermark, %d sec\n",
16507 + u.create->mfsrr_watermark,
16508 + u.create->mfs_second);
16512 + case Opt_wbr_copyup:
16513 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16514 + au_optstr_wbr_copyup(opt->wbr_copyup));
16516 + case Opt_fhsm_sec:
16517 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16521 + AuDbg("type %d\n", opt->type);
16529 +/* ---------------------------------------------------------------------- */
16532 + * For conditionally compiled mount options.
16533 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16535 +#define au_ignore_flag(name, action) \
16536 + fsparam_flag(name, action), \
16537 + fsparam_flag("no" name, Opt_ignore_silent)
16539 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16540 + fsparam_string("br", Opt_br),
16542 + /* "add=%d:%s" or "ins=%d:%s" */
16543 + fsparam_string("add", Opt_add),
16544 + fsparam_string("ins", Opt_add),
16545 + fsparam_path("append", Opt_append),
16546 + fsparam_path("prepend", Opt_prepend),
16548 + fsparam_path("del", Opt_del),
16549 + /* fsparam_s32("idel", Opt_idel), */
16550 + fsparam_path("mod", Opt_mod),
16551 + /* fsparam_string("imod", Opt_imod), */
16553 + fsparam_s32("dirwh", Opt_dirwh),
16555 + fsparam_path("xino", Opt_xino),
16556 + fsparam_flag("noxino", Opt_noxino),
16557 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16558 + /* "trunc_xino_v=%d:%d" */
16559 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16560 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16561 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16562 + /* fsparam_path("zxino", Opt_zxino), */
16563 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16565 +#ifdef CONFIG_PROC_FS
16566 + fsparam_flag_no("plink", Opt_plink),
16568 + au_ignore_flag("plink", Opt_ignore),
16571 +#ifdef CONFIG_AUFS_DEBUG
16572 + fsparam_flag("list_plink", Opt_list_plink),
16575 + fsparam_string("udba", Opt_udba),
16577 + fsparam_flag_no("dio", Opt_dio),
16579 +#ifdef CONFIG_AUFS_DIRREN
16580 + fsparam_flag_no("dirren", Opt_dirren),
16582 + au_ignore_flag("dirren", Opt_ignore),
16585 +#ifdef CONFIG_AUFS_FHSM
16586 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16588 + fsparam_s32("fhsm_sec", Opt_ignore),
16591 + /* always | a | whiteouted | w */
16592 + fsparam_string("diropq", Opt_diropq),
16594 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16596 +#ifdef CONFIG_AUFS_SHWH
16597 + fsparam_flag_no("shwh", Opt_shwh),
16599 + au_ignore_flag("shwh", Opt_err),
16602 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16604 + fsparam_flag_no("verbose", Opt_verbose),
16605 + fsparam_flag("v", Opt_verbose),
16606 + fsparam_flag("quiet", Opt_noverbose),
16607 + fsparam_flag("q", Opt_noverbose),
16608 + /* user-space may handle this */
16609 + fsparam_flag("silent", Opt_noverbose),
16611 + fsparam_flag_no("sum", Opt_sum),
16612 + fsparam_flag("wsum", Opt_wsum),
16614 + fsparam_s32("rdcache", Opt_rdcache),
16615 + /* "def" or s32 */
16616 + fsparam_string("rdblk", Opt_rdblk),
16617 + /* "def" or s32 */
16618 + fsparam_string("rdhash", Opt_rdhash),
16620 + fsparam_string("create", Opt_wbr_create),
16621 + fsparam_string("create_policy", Opt_wbr_create),
16622 + fsparam_string("cpup", Opt_wbr_copyup),
16623 + fsparam_string("copyup", Opt_wbr_copyup),
16624 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16626 + /* generic VFS flag */
16627 +#ifdef CONFIG_FS_POSIX_ACL
16628 + fsparam_flag_no("acl", Opt_acl),
16630 + au_ignore_flag("acl", Opt_ignore),
16633 + /* internal use for the scripts */
16634 + fsparam_string("si", Opt_ignore_silent),
16636 + /* obsoleted, keep them temporary */
16637 + fsparam_flag("nodlgt", Opt_ignore_silent),
16638 + fsparam_flag("clean_plink", Opt_ignore),
16639 + fsparam_string("dirs", Opt_br),
16640 + fsparam_u32("debug", Opt_ignore),
16641 + /* "whiteout" or "all" */
16642 + fsparam_string("delete", Opt_ignore),
16643 + fsparam_string("imap", Opt_ignore),
16645 + /* temporary workaround, due to old mount(8)? */
16646 + fsparam_flag("relatime", Opt_ignore_silent),
16651 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16652 + char *brspec, size_t speclen,
16653 + aufs_bindex_t bindex)
16658 + AuDbg("brspec %s\n", brspec);
16662 + speclen = strlen(brspec);
16663 + /* will be freed by au_fsctx_free() */
16664 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16665 + if (unlikely(!p)) {
16666 + errorfc(fc, "failed in %s", brspec);
16669 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16676 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16680 + struct au_fsctx_opts *a = fc->fs_private;
16681 + struct au_opt *opt = a->opt;
16682 + aufs_bindex_t bindex = a->bindex;
16684 + AuDbg("brspec %s\n", brspec);
16687 + while ((p = strsep(&brspec, ":")) && *p) {
16688 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16690 + if (unlikely(err))
16694 + if (unlikely(opt > a->opt_tail)) {
16700 + opt->type = Opt_tail;
16703 + a->bindex = bindex;
16710 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16714 + struct au_fsctx_opts *a = fc->fs_private;
16715 + struct au_opt *opt = a->opt;
16718 + p = strchr(addspec, ':');
16719 + if (unlikely(!p)) {
16720 + errorfc(fc, "bad arg in %s", addspec);
16724 + err = kstrtoint(addspec, 0, &n);
16725 + if (unlikely(err)) {
16726 + errorfc(fc, "bad integer in %s", addspec);
16729 + AuDbg("n %d\n", n);
16730 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16737 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16738 + struct fs_parameter *param)
16743 + /* will be freed by au_fsctx_free() */
16744 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16745 + if (unlikely(!del->pathname))
16747 + AuDbg("del %s\n", del->pathname);
16748 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16749 + if (unlikely(err))
16750 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16757 +#if 0 /* reserved for future use */
16758 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16759 + aufs_bindex_t bindex)
16762 + struct super_block *sb;
16763 + struct dentry *root;
16764 + struct au_fsctx_opts *a = fc->fs_private;
16770 + root = sb->s_root;
16771 + aufs_read_lock(root, AuLock_FLUSH);
16772 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16773 + errorfc(fc, "out of bounds, %d", bindex);
16778 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16779 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16782 + aufs_read_unlock(root, !AuLock_IR);
16788 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16789 + struct fs_parameter *param)
16792 + struct path path;
16796 + /* will be freed by au_fsctx_free() */
16797 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16798 + if (unlikely(!mod->path))
16802 + p = strchr(mod->path, '=');
16803 + if (unlikely(!p)) {
16804 + errorfc(fc, "no permission %s", mod->path);
16809 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16810 + if (unlikely(err)) {
16811 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16815 + mod->perm = au_br_perm_val(p);
16816 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16817 + mod->h_root = dget(path.dentry);
16825 +#if 0 /* reserved for future use */
16826 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16831 + struct super_block *sb;
16832 + struct dentry *root;
16833 + struct au_fsctx_opts *a = fc->fs_private;
16839 + p = strchr(ibrspec, ':');
16840 + if (unlikely(!p)) {
16841 + errorfc(fc, "no index, %s", ibrspec);
16845 + err = kstrtoint(ibrspec, 0, &n);
16846 + if (unlikely(err)) {
16847 + errorfc(fc, "bad integer in %s", ibrspec);
16850 + AuDbg("n %d\n", n);
16852 + root = sb->s_root;
16853 + aufs_read_lock(root, AuLock_FLUSH);
16854 + if (n < 0 || au_sbbot(sb) < n) {
16855 + errorfc(fc, "out of bounds, %d", bindex);
16860 + mod->perm = au_br_perm_val(p);
16861 + AuDbg("mod path %s, perm 0x%x, %s\n",
16862 + mod->path, mod->perm, p);
16863 + mod->h_root = dget(au_h_dptr(root, bindex));
16866 + aufs_read_unlock(root, !AuLock_IR);
16873 +static int au_fsctx_parse_xino(struct fs_context *fc,
16874 + struct au_opt_xino *xino,
16875 + struct fs_parameter *param)
16878 + struct au_fsctx_opts *a = fc->fs_private;
16881 + /* will be freed by au_opts_free() */
16882 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16883 + if (unlikely(!xino->path))
16885 + AuDbg("path %s\n", xino->path);
16887 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16889 + err = PTR_ERR(xino->file);
16890 + if (IS_ERR(xino->file)) {
16891 + xino->file = NULL;
16896 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16898 + errorfc(fc, "%s must be outside", xino->path);
16907 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16908 + struct au_opt_xino_itrunc *xino_itrunc,
16912 + aufs_bindex_t bbot, bindex;
16913 + struct path path;
16914 + struct dentry *root;
16915 + struct au_fsctx_opts *a = fc->fs_private;
16917 + AuDebugOn(!a->sb);
16919 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16920 + if (unlikely(err)) {
16921 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16925 + xino_itrunc->bindex = -1;
16926 + root = a->sb->s_root;
16927 + aufs_read_lock(root, AuLock_FLUSH);
16928 + bbot = au_sbbot(a->sb);
16929 + for (bindex = 0; bindex <= bbot; bindex++) {
16930 + if (au_h_dptr(root, bindex) == path.dentry) {
16931 + xino_itrunc->bindex = bindex;
16935 + aufs_read_unlock(root, !AuLock_IR);
16938 + if (unlikely(xino_itrunc->bindex < 0)) {
16940 + errorfc(fc, "no such branch %s", pathname);
16948 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16949 + struct au_opt_xino_itrunc *xino_itrunc,
16950 + unsigned int bindex)
16953 + aufs_bindex_t bbot;
16954 + struct super_block *sb;
16955 + struct au_fsctx_opts *a = fc->fs_private;
16961 + si_noflush_read_lock(sb);
16962 + bbot = au_sbbot(sb);
16963 + si_read_unlock(sb);
16964 + if (bindex <= bbot)
16965 + xino_itrunc->bindex = bindex;
16968 + errorfc(fc, "out of bounds, %u", bindex);
16975 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16978 + struct fs_parse_result result;
16979 + struct au_fsctx_opts *a = fc->fs_private;
16980 + struct au_opt *opt = a->opt;
16982 + AuDbg("fc %p, param {key %s, string %s}\n",
16983 + fc, param->key, param->string);
16984 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16985 + if (unlikely(err < 0))
16988 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16989 + token, result.negated, result.uint_64);
16995 + err = au_fsctx_parse_br(fc, param->string);
16998 + err = au_fsctx_parse_add(fc, param->string);
17001 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17002 + /*dummy bindex*/1);
17004 + case Opt_prepend:
17005 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17010 + err = au_fsctx_parse_del(fc, &opt->del, param);
17012 +#if 0 /* reserved for future use */
17019 + del->pathname = "(indexed)";
17020 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17025 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17027 +#ifdef IMOD /* reserved for future use */
17034 + u.mod->path = "(indexed)";
17035 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17040 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17042 + case Opt_trunc_xino_path:
17044 + errorfc(fc, "no such branch %s", param->string);
17047 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17051 + case Opt_trunc_xino_v:
17057 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17061 + case Opt_itrunc_xino:
17063 + errorfc(fc, "out of bounds %s", param->string);
17066 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17072 + opt->dirwh = result.int_32;
17075 + case Opt_rdcache:
17076 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17077 + errorfc(fc, "rdcache must be smaller than %d",
17078 + AUFS_RDCACHE_MAX);
17082 + opt->rdcache = result.int_32;
17087 + opt->rdblk = AUFS_RDBLK_DEF;
17088 + if (!strcmp(param->string, "def"))
17091 + err = kstrtoint(param->string, 0, &result.int_32);
17092 + if (unlikely(err)) {
17093 + errorfc(fc, "bad value in %s", param->key);
17097 + if (unlikely(result.int_32 < 0
17098 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17099 + errorfc(fc, "bad value in %s", param->key);
17102 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17103 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17107 + opt->rdblk = result.int_32;
17112 + opt->rdhash = AUFS_RDHASH_DEF;
17113 + if (!strcmp(param->string, "def"))
17116 + err = kstrtoint(param->string, 0, &result.int_32);
17117 + if (unlikely(err)) {
17118 + errorfc(fc, "bad value in %s", param->key);
17121 + /* how about zero? */
17122 + if (result.int_32 < 0
17123 + || result.int_32 * sizeof(struct hlist_head)
17124 + > KMALLOC_MAX_SIZE) {
17126 + errorfc(fc, "bad integer in %s", param->key);
17129 + opt->rdhash = result.int_32;
17134 + * As other options, fs/aufs/opts.c can handle these strings by
17135 + * match_token(). But "diropq=" is deprecated now and will
17136 + * never have other value. So simple strcmp() is enough here.
17138 + if (!strcmp(param->string, "a") ||
17139 + !strcmp(param->string, "always")) {
17141 + opt->type = Opt_diropq_a;
17142 + } else if (!strcmp(param->string, "w") ||
17143 + !strcmp(param->string, "whiteouted")) {
17145 + opt->type = Opt_diropq_w;
17147 + errorfc(fc, "unknown value %s", param->string);
17151 + opt->udba = au_udba_val(param->string);
17152 + if (opt->udba >= 0)
17155 + errorf(fc, "wrong value, %s", param->string);
17158 + case Opt_wbr_create:
17159 + opt->wbr_create.wbr_create
17160 + = au_wbr_create_val(param->string, &opt->wbr_create);
17161 + if (opt->wbr_create.wbr_create >= 0)
17164 + errorf(fc, "wrong value, %s", param->key);
17167 + case Opt_wbr_copyup:
17168 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17169 + if (opt->wbr_copyup >= 0)
17172 + errorfc(fc, "wrong value, %s", param->key);
17175 + case Opt_fhsm_sec:
17176 + if (unlikely(result.int_32 < 0)) {
17177 + errorfc(fc, "bad integer in %s\n", param->key);
17182 + opt->fhsm_second = result.int_32;
17184 + warnfc(fc, "ignored %s %s", param->key, param->string);
17187 + /* simple true/false flag */
17188 +#define au_fsctx_TF(name) \
17189 + case Opt_##name: \
17191 + opt->tf = !result.negated; \
17193 + au_fsctx_TF(trunc_xino);
17194 + au_fsctx_TF(trunc_xib);
17195 + au_fsctx_TF(dirperm1);
17196 + au_fsctx_TF(plink);
17197 + au_fsctx_TF(shwh);
17198 + au_fsctx_TF(dio);
17199 + au_fsctx_TF(warn_perm);
17200 + au_fsctx_TF(verbose);
17201 + au_fsctx_TF(sum);
17202 + au_fsctx_TF(dirren);
17203 + au_fsctx_TF(acl);
17204 +#undef au_fsctx_TF
17206 + case Opt_noverbose:
17208 + opt->type = Opt_verbose;
17214 + case Opt_list_plink:
17221 + warnfc(fc, "ignored %s", param->key);
17223 + case Opt_ignore_silent:
17232 + if (unlikely(err))
17240 + case Opt_noverbose:
17245 + opt->type = token;
17249 + if (unlikely(opt > a->opt_tail)) {
17253 + opt->type = Opt_tail;
17261 + * these options accept both 'name=val' and 'name:val' form.
17262 + * some accept optional '=' in its value.
17263 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17265 +static inline unsigned int is_colonopt(char *str)
17267 +#define do_test(name) \
17268 + if (!strncmp(str, name ":", sizeof(name))) \
17269 + return sizeof(name) - 1
17273 + do_test("append");
17274 + do_test("prepend");
17276 + /* do_test("idel"); */
17278 + /* do_test("imod"); */
17284 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17289 + struct au_fsctx_opts *a = fc->fs_private;
17292 + AuDbg("str %s\n", str);
17294 + u = is_colonopt(str);
17297 + str = strchr(str, ',');
17303 + AuDbg("str %s\n", str);
17305 + err = generic_parse_monolithic(fc, str);
17307 + au_fsctx_dump(&a->opts);
17312 +/* ---------------------------------------------------------------------- */
17314 +static void au_fsctx_opts_free(struct au_opts *opts)
17316 + struct au_opt *opt;
17319 + while (opt->type != Opt_tail) {
17320 + switch (opt->type) {
17325 + case Opt_prepend:
17326 + kfree(opt->add.pathname);
17327 + path_put(&opt->add.path);
17330 + kfree(opt->del.pathname);
17333 + path_put(&opt->del.h_path);
17336 + kfree(opt->mod.path);
17339 + dput(opt->mod.h_root);
17342 + kfree(opt->xino.path);
17343 + fput(opt->xino.file);
17350 +static void au_fsctx_free(struct fs_context *fc)
17352 + struct au_fsctx_opts *a = fc->fs_private;
17354 + /* fs_type=%p, root=%pD */
17355 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17356 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17358 + kobject_put(&a->sbinfo->si_kobj);
17359 + au_fsctx_opts_free(&a->opts);
17360 + free_page((unsigned long)a->opts.opt);
17364 +static const struct fs_context_operations au_fsctx_ops = {
17365 + .free = au_fsctx_free,
17366 + .parse_param = au_fsctx_parse_param,
17367 + .parse_monolithic = au_fsctx_parse_monolithic,
17368 + .get_tree = au_fsctx_get_tree,
17369 + .reconfigure = au_fsctx_reconfigure
17371 + * nfs4 requires ->dup()? No.
17372 + * I don't know what is this ->dup() for.
17376 +int aufs_fsctx_init(struct fs_context *fc)
17379 + struct au_fsctx_opts *a;
17381 + /* fs_type=%p, root=%pD */
17382 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17383 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17385 + /* they will be freed by au_fsctx_free() */
17387 + a = kzalloc(sizeof(*a), GFP_NOFS);
17388 + if (unlikely(!a))
17391 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17392 + if (unlikely(!a->opts.opt))
17394 + a->opt = a->opts.opt;
17395 + a->opt->type = Opt_tail;
17396 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17397 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17398 + a->opts.sb_flags = fc->sb_flags;
17402 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17403 + a->opts.flags = AuOpts_REMOUNT;
17404 + a->sb = fc->root->d_sb;
17405 + a->sbinfo = au_sbi(a->sb);
17406 + kobject_get(&a->sbinfo->si_kobj);
17408 + a->sbinfo = au_si_alloc(a->sb);
17409 + AuDebugOn(!a->sbinfo);
17410 + err = PTR_ERR(a->sbinfo);
17411 + if (IS_ERR(a->sbinfo))
17413 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17417 + fc->fs_private = a;
17418 + fc->ops = &au_fsctx_ops;
17419 + goto out; /* success */
17422 + free_page((unsigned long)a->opts.opt);
17429 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17430 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17431 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17433 +/* SPDX-License-Identifier: GPL-2.0 */
17435 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17437 + * This program is free software; you can redistribute it and/or modify
17438 + * it under the terms of the GNU General Public License as published by
17439 + * the Free Software Foundation; either version 2 of the License, or
17440 + * (at your option) any later version.
17442 + * This program is distributed in the hope that it will be useful,
17443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17445 + * GNU General Public License for more details.
17447 + * You should have received a copy of the GNU General Public License
17448 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17452 + * judging filesystem type
17455 +#ifndef __AUFS_FSTYPE_H__
17456 +#define __AUFS_FSTYPE_H__
17460 +#include <linux/fs.h>
17461 +#include <linux/magic.h>
17462 +#include <linux/nfs_fs.h>
17463 +#include <linux/romfs_fs.h>
17465 +static inline int au_test_aufs(struct super_block *sb)
17467 + return sb->s_magic == AUFS_SUPER_MAGIC;
17470 +static inline const char *au_sbtype(struct super_block *sb)
17472 + return sb->s_type->name;
17475 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17477 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17478 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17484 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17486 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17487 + return sb->s_magic == ROMFS_MAGIC;
17493 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17495 +#if IS_ENABLED(CONFIG_CRAMFS)
17496 + return sb->s_magic == CRAMFS_MAGIC;
17501 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17503 +#if IS_ENABLED(CONFIG_NFS_FS)
17504 + return sb->s_magic == NFS_SUPER_MAGIC;
17510 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17512 +#if IS_ENABLED(CONFIG_FUSE_FS)
17513 + return sb->s_magic == FUSE_SUPER_MAGIC;
17519 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17521 +#if IS_ENABLED(CONFIG_XFS_FS)
17522 + return sb->s_magic == XFS_SB_MAGIC;
17528 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17530 +#ifdef CONFIG_TMPFS
17531 + return sb->s_magic == TMPFS_MAGIC;
17537 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17539 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17540 + return !strcmp(au_sbtype(sb), "ecryptfs");
17546 +static inline int au_test_ramfs(struct super_block *sb)
17548 + return sb->s_magic == RAMFS_MAGIC;
17551 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17553 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17554 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17560 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17562 +#ifdef CONFIG_PROC_FS
17563 + return sb->s_magic == PROC_SUPER_MAGIC;
17569 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17571 +#ifdef CONFIG_SYSFS
17572 + return sb->s_magic == SYSFS_MAGIC;
17578 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17580 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17581 + return sb->s_magic == CONFIGFS_MAGIC;
17587 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17589 +#if IS_ENABLED(CONFIG_MINIX_FS)
17590 + return sb->s_magic == MINIX3_SUPER_MAGIC
17591 + || sb->s_magic == MINIX2_SUPER_MAGIC
17592 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17593 + || sb->s_magic == MINIX_SUPER_MAGIC
17594 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17600 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17602 +#if IS_ENABLED(CONFIG_FAT_FS)
17603 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17609 +static inline int au_test_msdos(struct super_block *sb)
17611 + return au_test_fat(sb);
17614 +static inline int au_test_vfat(struct super_block *sb)
17616 + return au_test_fat(sb);
17619 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17621 +#ifdef CONFIG_SECURITYFS
17622 + return sb->s_magic == SECURITYFS_MAGIC;
17628 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17630 +#if IS_ENABLED(CONFIG_SQUASHFS)
17631 + return sb->s_magic == SQUASHFS_MAGIC;
17637 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17639 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17640 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17646 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17648 +#if IS_ENABLED(CONFIG_XENFS)
17649 + return sb->s_magic == XENFS_SUPER_MAGIC;
17655 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17657 +#ifdef CONFIG_DEBUG_FS
17658 + return sb->s_magic == DEBUGFS_MAGIC;
17664 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17666 +#if IS_ENABLED(CONFIG_NILFS)
17667 + return sb->s_magic == NILFS_SUPER_MAGIC;
17673 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17675 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17676 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17682 +/* ---------------------------------------------------------------------- */
17684 + * they can't be an aufs branch.
17686 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17689 +#ifndef CONFIG_AUFS_BR_RAMFS
17690 + au_test_ramfs(sb) ||
17692 + au_test_procfs(sb)
17693 + || au_test_sysfs(sb)
17694 + || au_test_configfs(sb)
17695 + || au_test_debugfs(sb)
17696 + || au_test_securityfs(sb)
17697 + || au_test_xenfs(sb)
17698 + || au_test_ecryptfs(sb)
17699 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17700 + || au_test_aufs(sb); /* will be supported in next version */
17703 +static inline int au_test_fs_remote(struct super_block *sb)
17705 + return !au_test_tmpfs(sb)
17706 +#ifdef CONFIG_AUFS_BR_RAMFS
17707 + && !au_test_ramfs(sb)
17709 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17712 +/* ---------------------------------------------------------------------- */
17715 + * Note: these functions (below) are created after reading ->getattr() in all
17716 + * filesystems under linux/fs. it means we have to do so in every update...
17720 + * some filesystems require getattr to refresh the inode attributes before
17722 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17723 + * and leave the work for d_revalidate()
17725 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17727 + return au_test_nfs(sb)
17728 + || au_test_fuse(sb)
17729 + /* || au_test_btrfs(sb) */ /* untested */
17734 + * filesystems which don't maintain i_size or i_blocks.
17736 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17738 + return au_test_xfs(sb)
17739 + || au_test_btrfs(sb)
17740 + || au_test_ubifs(sb)
17741 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17742 + /* || au_test_minix(sb) */ /* untested */
17747 + * filesystems which don't store the correct value in some of their inode
17750 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17752 + return au_test_fs_bad_iattr_size(sb)
17753 + || au_test_fat(sb)
17754 + || au_test_msdos(sb)
17755 + || au_test_vfat(sb);
17758 +/* they don't check i_nlink in link(2) */
17759 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17761 + return au_test_tmpfs(sb)
17762 +#ifdef CONFIG_AUFS_BR_RAMFS
17763 + || au_test_ramfs(sb)
17765 + || au_test_ubifs(sb)
17766 + || au_test_hfsplus(sb);
17770 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17772 +static inline int au_test_fs_notime(struct super_block *sb)
17774 + return au_test_nfs(sb)
17775 + || au_test_fuse(sb)
17776 + || au_test_ubifs(sb)
17780 +/* temporary support for i#1 in cramfs */
17781 +static inline int au_test_fs_unique_ino(struct inode *inode)
17783 + if (au_test_cramfs(inode->i_sb))
17784 + return inode->i_ino != 1;
17788 +/* ---------------------------------------------------------------------- */
17791 + * the filesystem where the xino files placed must support i/o after unlink and
17792 + * maintain i_size and i_blocks.
17794 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17796 + return au_test_fs_remote(sb)
17797 + || au_test_fs_bad_iattr_size(sb)
17798 + /* don't want unnecessary work for xino */
17799 + || au_test_aufs(sb)
17800 + || au_test_ecryptfs(sb)
17801 + || au_test_nilfs(sb);
17804 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17806 + return au_test_tmpfs(sb)
17807 + || au_test_ramfs(sb);
17811 + * test if the @sb is real-readonly.
17813 +static inline int au_test_fs_rr(struct super_block *sb)
17815 + return au_test_squashfs(sb)
17816 + || au_test_iso9660(sb)
17817 + || au_test_cramfs(sb)
17818 + || au_test_romfs(sb);
17822 + * test if the @inode is nfs with 'noacl' option
17823 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17825 +static inline int au_test_nfs_noacl(struct inode *inode)
17827 + return au_test_nfs(inode->i_sb)
17828 + /* && IS_POSIXACL(inode) */
17829 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17832 +#endif /* __KERNEL__ */
17833 +#endif /* __AUFS_FSTYPE_H__ */
17834 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17835 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17836 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17838 +/* SPDX-License-Identifier: GPL-2.0 */
17840 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17842 + * This program is free software; you can redistribute it and/or modify
17843 + * it under the terms of the GNU General Public License as published by
17844 + * the Free Software Foundation; either version 2 of the License, or
17845 + * (at your option) any later version.
17847 + * This program is distributed in the hope that it will be useful,
17848 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17849 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17850 + * GNU General Public License for more details.
17852 + * You should have received a copy of the GNU General Public License
17853 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17857 + * helpers for hlist_bl.h
17860 +#ifndef __AUFS_HBL_H__
17861 +#define __AUFS_HBL_H__
17865 +#include <linux/list_bl.h>
17867 +static inline void au_hbl_add(struct hlist_bl_node *node,
17868 + struct hlist_bl_head *hbl)
17870 + hlist_bl_lock(hbl);
17871 + hlist_bl_add_head(node, hbl);
17872 + hlist_bl_unlock(hbl);
17875 +static inline void au_hbl_del(struct hlist_bl_node *node,
17876 + struct hlist_bl_head *hbl)
17878 + hlist_bl_lock(hbl);
17879 + hlist_bl_del(node);
17880 + hlist_bl_unlock(hbl);
17883 +#define au_hbl_for_each(pos, head) \
17884 + for (pos = hlist_bl_first(head); \
17888 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17890 + unsigned long cnt;
17891 + struct hlist_bl_node *pos;
17894 + hlist_bl_lock(hbl);
17895 + au_hbl_for_each(pos, hbl)
17897 + hlist_bl_unlock(hbl);
17901 +#endif /* __KERNEL__ */
17902 +#endif /* __AUFS_HBL_H__ */
17903 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17904 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17905 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17907 +// SPDX-License-Identifier: GPL-2.0
17909 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17911 + * This program is free software; you can redistribute it and/or modify
17912 + * it under the terms of the GNU General Public License as published by
17913 + * the Free Software Foundation; either version 2 of the License, or
17914 + * (at your option) any later version.
17916 + * This program is distributed in the hope that it will be useful,
17917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17919 + * GNU General Public License for more details.
17921 + * You should have received a copy of the GNU General Public License
17922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17926 + * fsnotify for the lower directories
17931 +/* FS_IN_IGNORED is unnecessary */
17932 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17933 + | FS_CREATE | FS_EVENT_ON_CHILD);
17934 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17935 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17937 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17939 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17941 + /* AuDbg("here\n"); */
17942 + au_cache_free_hnotify(hn);
17943 + smp_mb__before_atomic(); /* for atomic64_dec */
17944 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17945 + wake_up(&au_hfsn_wq);
17948 +static int au_hfsn_alloc(struct au_hinode *hinode)
17951 + struct au_hnotify *hn;
17952 + struct super_block *sb;
17953 + struct au_branch *br;
17954 + struct fsnotify_mark *mark;
17955 + aufs_bindex_t bindex;
17957 + hn = hinode->hi_notify;
17958 + sb = hn->hn_aufs_inode->i_sb;
17959 + bindex = au_br_index(sb, hinode->hi_id);
17960 + br = au_sbr(sb, bindex);
17961 + AuDebugOn(!br->br_hfsn);
17963 + mark = &hn->hn_mark;
17964 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17965 + mark->mask = AuHfsnMask;
17967 + * by udba rename or rmdir, aufs assign a new inode to the known
17968 + * h_inode, so specify 1 to allow dups.
17971 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17977 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17979 + struct fsnotify_mark *mark;
17980 + unsigned long long ull;
17981 + struct fsnotify_group *group;
17983 + ull = atomic64_inc_return(&au_hfsn_ifree);
17986 + mark = &hn->hn_mark;
17987 + spin_lock(&mark->lock);
17988 + group = mark->group;
17989 + fsnotify_get_group(group);
17990 + spin_unlock(&mark->lock);
17992 + fsnotify_destroy_mark(mark, group);
17993 + fsnotify_put_mark(mark);
17994 + fsnotify_put_group(group);
17997 + /* free hn by myself */
18001 +/* ---------------------------------------------------------------------- */
18003 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18005 + struct fsnotify_mark *mark;
18007 + mark = &hinode->hi_notify->hn_mark;
18008 + spin_lock(&mark->lock);
18010 + AuDebugOn(mark->mask & AuHfsnMask);
18011 + mark->mask |= AuHfsnMask;
18013 + AuDebugOn(!(mark->mask & AuHfsnMask));
18014 + mark->mask &= ~AuHfsnMask;
18016 + spin_unlock(&mark->lock);
18017 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18020 +/* ---------------------------------------------------------------------- */
18022 +/* #define AuDbgHnotify */
18023 +#ifdef AuDbgHnotify
18024 +static char *au_hfsn_name(u32 mask)
18026 +#ifdef CONFIG_AUFS_DEBUG
18027 +#define test_ret(flag) \
18029 + if (mask & flag) \
18032 + test_ret(FS_ACCESS);
18033 + test_ret(FS_MODIFY);
18034 + test_ret(FS_ATTRIB);
18035 + test_ret(FS_CLOSE_WRITE);
18036 + test_ret(FS_CLOSE_NOWRITE);
18037 + test_ret(FS_OPEN);
18038 + test_ret(FS_MOVED_FROM);
18039 + test_ret(FS_MOVED_TO);
18040 + test_ret(FS_CREATE);
18041 + test_ret(FS_DELETE);
18042 + test_ret(FS_DELETE_SELF);
18043 + test_ret(FS_MOVE_SELF);
18044 + test_ret(FS_UNMOUNT);
18045 + test_ret(FS_Q_OVERFLOW);
18046 + test_ret(FS_IN_IGNORED);
18047 + test_ret(FS_ISDIR);
18048 + test_ret(FS_IN_ONESHOT);
18049 + test_ret(FS_EVENT_ON_CHILD);
18058 +/* ---------------------------------------------------------------------- */
18060 +static void au_hfsn_free_group(struct fsnotify_group *group)
18062 + struct au_br_hfsnotify *hfsn = group->private;
18064 + /* AuDbg("here\n"); */
18065 + au_kfree_try_rcu(hfsn);
18068 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18069 + u32 mask, const void *data, int data_type,
18070 + struct inode *dir,
18071 + const struct qstr *file_name, u32 cookie,
18072 + struct fsnotify_iter_info *iter_info)
18075 + struct au_hnotify *hnotify;
18076 + struct inode *h_dir, *h_inode;
18077 + struct fsnotify_mark *inode_mark;
18079 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18080 + || data_type == FSNOTIFY_EVENT_DENTRY));
18083 + /* if FS_UNMOUNT happens, there must be another bug */
18084 + AuDebugOn(mask & FS_UNMOUNT);
18085 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18090 +#ifdef AuDbgHnotify
18092 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18093 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18094 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18095 + h_dir->i_ino, mask, au_hfsn_name(mask),
18096 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18097 + /* WARN_ON(1); */
18102 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18103 + AuDebugOn(!inode_mark);
18104 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18105 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18111 +static struct fsnotify_ops au_hfsn_ops = {
18112 + .handle_event = au_hfsn_handle_event,
18113 + .free_group_priv = au_hfsn_free_group,
18114 + .free_mark = au_hfsn_free_mark
18117 +/* ---------------------------------------------------------------------- */
18119 +static void au_hfsn_fin_br(struct au_branch *br)
18121 + struct au_br_hfsnotify *hfsn;
18123 + hfsn = br->br_hfsn;
18126 + fsnotify_put_group(hfsn->hfsn_group);
18131 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18134 + struct fsnotify_group *group;
18135 + struct au_br_hfsnotify *hfsn;
18138 + br->br_hfsn = NULL;
18139 + if (!au_br_hnotifyable(perm))
18143 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18144 + if (unlikely(!hfsn))
18148 + group = fsnotify_alloc_group(&au_hfsn_ops,
18149 + /*flags - not for userspace*/0);
18150 + if (IS_ERR(group)) {
18151 + err = PTR_ERR(group);
18152 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18156 + group->private = hfsn;
18157 + hfsn->hfsn_group = group;
18158 + br->br_hfsn = hfsn;
18159 + goto out; /* success */
18162 + au_kfree_try_rcu(hfsn);
18167 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18172 + if (!br->br_hfsn)
18173 + err = au_hfsn_init_br(br, perm);
18178 +/* ---------------------------------------------------------------------- */
18180 +static void au_hfsn_fin(void)
18182 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18183 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18186 +const struct au_hnotify_op au_hnotify_op = {
18187 + .ctl = au_hfsn_ctl,
18188 + .alloc = au_hfsn_alloc,
18189 + .free = au_hfsn_free,
18191 + .fin = au_hfsn_fin,
18193 + .reset_br = au_hfsn_reset_br,
18194 + .fin_br = au_hfsn_fin_br,
18195 + .init_br = au_hfsn_init_br
18197 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18198 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18199 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18201 +// SPDX-License-Identifier: GPL-2.0
18203 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18205 + * This program is free software; you can redistribute it and/or modify
18206 + * it under the terms of the GNU General Public License as published by
18207 + * the Free Software Foundation; either version 2 of the License, or
18208 + * (at your option) any later version.
18210 + * This program is distributed in the hope that it will be useful,
18211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18213 + * GNU General Public License for more details.
18215 + * You should have received a copy of the GNU General Public License
18216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18220 + * special support for filesystems which acquires an inode mutex
18221 + * at final closing a file, eg, hfsplus.
18223 + * This trick is very simple and stupid, just to open the file before really
18224 + * necessary open to tell hfsplus that this is not the final closing.
18225 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18226 + * and au_h_open_post() after releasing it.
18231 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18234 + struct file *h_file;
18235 + struct dentry *h_dentry;
18237 + h_dentry = au_h_dptr(dentry, bindex);
18238 + AuDebugOn(!h_dentry);
18239 + AuDebugOn(d_is_negative(h_dentry));
18242 + if (au_test_hfsplus(h_dentry->d_sb)
18243 + && d_is_reg(h_dentry))
18244 + h_file = au_h_open(dentry, bindex,
18245 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18246 + /*file*/NULL, force_wr);
18250 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18251 + struct file *h_file)
18253 + struct au_branch *br;
18257 + br = au_sbr(dentry->d_sb, bindex);
18258 + au_lcnt_dec(&br->br_nfiles);
18261 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18262 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18263 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18265 +// SPDX-License-Identifier: GPL-2.0
18267 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18269 + * This program is free software; you can redistribute it and/or modify
18270 + * it under the terms of the GNU General Public License as published by
18271 + * the Free Software Foundation; either version 2 of the License, or
18272 + * (at your option) any later version.
18274 + * This program is distributed in the hope that it will be useful,
18275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18277 + * GNU General Public License for more details.
18279 + * You should have received a copy of the GNU General Public License
18280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18284 + * abstraction to notify the direct changes on lower directories
18287 +/* #include <linux/iversion.h> */
18290 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18293 + struct au_hnotify *hn;
18296 + hn = au_cache_alloc_hnotify();
18298 + hn->hn_aufs_inode = inode;
18299 + hinode->hi_notify = hn;
18300 + err = au_hnotify_op.alloc(hinode);
18302 + if (unlikely(err)) {
18303 + hinode->hi_notify = NULL;
18304 + au_cache_free_hnotify(hn);
18306 + * The upper dir was removed by udba, but the same named
18307 + * dir left. In this case, aufs assigns a new inode
18308 + * number and set the monitor again.
18309 + * For the lower dir, the old monitor is still left.
18311 + if (err == -EEXIST)
18320 +void au_hn_free(struct au_hinode *hinode)
18322 + struct au_hnotify *hn;
18324 + hn = hinode->hi_notify;
18326 + hinode->hi_notify = NULL;
18327 + if (au_hnotify_op.free(hinode, hn))
18328 + au_cache_free_hnotify(hn);
18332 +/* ---------------------------------------------------------------------- */
18334 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18336 + if (hinode->hi_notify)
18337 + au_hnotify_op.ctl(hinode, do_set);
18340 +void au_hn_reset(struct inode *inode, unsigned int flags)
18342 + aufs_bindex_t bindex, bbot;
18343 + struct inode *hi;
18344 + struct dentry *iwhdentry;
18346 + bbot = au_ibbot(inode);
18347 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18348 + hi = au_h_iptr(inode, bindex);
18352 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18353 + iwhdentry = au_hi_wh(inode, bindex);
18357 + au_set_h_iptr(inode, bindex, NULL, 0);
18358 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18359 + flags & ~AuHi_XINO);
18362 + /* inode_unlock(hi); */
18366 +/* ---------------------------------------------------------------------- */
18368 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18371 + aufs_bindex_t bindex, bbot, bfound, btop;
18372 + struct inode *h_i;
18375 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18376 + pr_warn("branch root dir was changed\n");
18381 + bbot = au_ibbot(inode);
18382 + btop = au_ibtop(inode);
18383 +#if 0 /* reserved for future use */
18384 + if (bindex == bbot) {
18385 + /* keep this ino in rename case */
18389 + for (bindex = btop; bindex <= bbot; bindex++)
18390 + if (au_h_iptr(inode, bindex) == h_inode) {
18397 + for (bindex = btop; bindex <= bbot; bindex++) {
18398 + h_i = au_h_iptr(inode, bindex);
18402 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18403 + /* ignore this error */
18404 + /* bad action? */
18407 + /* children inode number will be broken */
18414 +static int hn_gen_tree(struct dentry *dentry)
18416 + int err, i, j, ndentry;
18417 + struct au_dcsub_pages dpages;
18418 + struct au_dpage *dpage;
18419 + struct dentry **dentries;
18421 + err = au_dpages_init(&dpages, GFP_NOFS);
18422 + if (unlikely(err))
18424 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18425 + if (unlikely(err))
18428 + for (i = 0; i < dpages.ndpage; i++) {
18429 + dpage = dpages.dpages + i;
18430 + dentries = dpage->dentries;
18431 + ndentry = dpage->ndentry;
18432 + for (j = 0; j < ndentry; j++) {
18433 + struct dentry *d;
18440 + if (d_really_is_positive(d))
18441 + /* todo: reset children xino?
18442 + cached children only? */
18443 + au_iigen_dec(d_inode(d));
18448 + au_dpages_free(&dpages);
18454 + * return 0 if processed.
18456 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18457 + const unsigned int isdir)
18460 + struct dentry *d;
18461 + struct qstr *dname;
18464 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18465 + pr_warn("branch root dir was changed\n");
18471 + AuDebugOn(!name);
18472 + au_iigen_dec(inode);
18473 + spin_lock(&inode->i_lock);
18474 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18475 + spin_lock(&d->d_lock);
18476 + dname = &d->d_name;
18477 + if (dname->len != nlen
18478 + && memcmp(dname->name, name, nlen)) {
18479 + spin_unlock(&d->d_lock);
18484 + spin_unlock(&d->d_lock);
18487 + spin_unlock(&inode->i_lock);
18489 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18490 + d = d_find_any_alias(inode);
18492 + au_iigen_dec(inode);
18496 + spin_lock(&d->d_lock);
18497 + dname = &d->d_name;
18498 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18499 + spin_unlock(&d->d_lock);
18500 + err = hn_gen_tree(d);
18501 + spin_lock(&d->d_lock);
18503 + spin_unlock(&d->d_lock);
18512 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18516 + if (IS_ROOT(dentry)) {
18517 + pr_warn("branch root dir was changed\n");
18523 + au_digen_dec(dentry);
18524 + if (d_really_is_positive(dentry))
18525 + au_iigen_dec(d_inode(dentry));
18527 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18528 + if (d_really_is_positive(dentry))
18529 + err = hn_gen_tree(dentry);
18536 +/* ---------------------------------------------------------------------- */
18538 +/* hnotify job flags */
18539 +#define AuHnJob_XINO0 1
18540 +#define AuHnJob_GEN (1 << 1)
18541 +#define AuHnJob_DIRENT (1 << 2)
18542 +#define AuHnJob_ISDIR (1 << 3)
18543 +#define AuHnJob_TRYXINO0 (1 << 4)
18544 +#define AuHnJob_MNTPNT (1 << 5)
18545 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18546 +#define au_fset_hnjob(flags, name) \
18547 + do { (flags) |= AuHnJob_##name; } while (0)
18548 +#define au_fclr_hnjob(flags, name) \
18549 + do { (flags) &= ~AuHnJob_##name; } while (0)
18557 +struct au_hnotify_args {
18558 + struct inode *h_dir, *dir, *h_child_inode;
18560 + unsigned int flags[AuHnLast];
18561 + unsigned int h_child_nlen;
18562 + char h_child_name[];
18565 +struct hn_job_args {
18566 + unsigned int flags;
18567 + struct inode *inode, *h_inode, *dir, *h_dir;
18568 + struct dentry *dentry;
18573 +static int hn_job(struct hn_job_args *a)
18575 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18579 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18580 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18582 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18585 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18586 + if (!a->h_inode->i_nlink
18587 + && !(a->h_inode->i_state & I_LINKABLE))
18588 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18589 + inode_unlock_shared(a->h_inode);
18592 + /* make the generation obsolete */
18593 + if (au_ftest_hnjob(a->flags, GEN)) {
18596 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18598 + if (e && a->dentry)
18599 + hn_gen_by_name(a->dentry, isdir);
18600 + /* ignore this error */
18603 + /* make dir entries obsolete */
18604 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18605 + struct au_vdir *vdir;
18607 + vdir = au_ivdir(a->inode);
18609 + vdir->vd_jiffy = 0;
18610 + /* IMustLock(a->inode); */
18611 + /* inode_inc_iversion(a->inode); */
18614 + /* can do nothing but warn */
18615 + if (au_ftest_hnjob(a->flags, MNTPNT)
18617 + && d_mountpoint(a->dentry))
18618 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18623 +/* ---------------------------------------------------------------------- */
18625 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18626 + struct inode *dir)
18628 + struct dentry *dentry, *d, *parent;
18629 + struct qstr *dname;
18631 + parent = d_find_any_alias(dir);
18636 + spin_lock(&parent->d_lock);
18637 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18638 + /* AuDbg("%pd\n", d); */
18639 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18640 + dname = &d->d_name;
18641 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18642 + goto cont_unlock;
18646 + goto cont_unlock;
18647 + if (au_dcount(d) > 0) {
18648 + dentry = dget_dlock(d);
18649 + spin_unlock(&d->d_lock);
18654 + spin_unlock(&d->d_lock);
18656 + spin_unlock(&parent->d_lock);
18660 + di_write_lock_child(dentry);
18665 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18666 + aufs_bindex_t bindex, ino_t h_ino)
18668 + struct inode *inode;
18673 + err = au_xino_read(sb, bindex, h_ino, &ino);
18675 + inode = ilookup(sb, ino);
18679 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18680 + pr_warn("wrong root branch\n");
18686 + ii_write_lock_child(inode);
18692 +static void au_hn_bh(void *_args)
18694 + struct au_hnotify_args *a = _args;
18695 + struct super_block *sb;
18696 + aufs_bindex_t bindex, bbot, bfound;
18697 + unsigned char xino, try_iput;
18699 + struct inode *inode;
18701 + struct hn_job_args args;
18702 + struct dentry *dentry;
18703 + struct au_sbinfo *sbinfo;
18705 + AuDebugOn(!_args);
18706 + AuDebugOn(!a->h_dir);
18707 + AuDebugOn(!a->dir);
18708 + AuDebugOn(!a->mask);
18709 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18710 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18711 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18716 + * do not lock a->dir->i_mutex here
18717 + * because of d_revalidate() may cause a deadlock.
18719 + sb = a->dir->i_sb;
18721 + sbinfo = au_sbi(sb);
18722 + AuDebugOn(!sbinfo);
18723 + si_write_lock(sb, AuLock_NOPLMW);
18725 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18726 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18727 + case FS_MOVED_FROM:
18728 + case FS_MOVED_TO:
18729 + AuWarn1("DIRREN with UDBA may not work correctly "
18730 + "for the direct rename(2)\n");
18733 + ii_read_lock_parent(a->dir);
18735 + bbot = au_ibbot(a->dir);
18736 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18737 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18741 + ii_read_unlock(a->dir);
18742 + if (unlikely(bfound < 0))
18745 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18747 + if (a->h_child_inode)
18748 + h_ino = a->h_child_inode->i_ino;
18750 + if (a->h_child_nlen
18751 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18752 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18753 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18756 + if (dentry && d_really_is_positive(dentry))
18757 + inode = d_inode(dentry);
18758 + if (xino && !inode && h_ino
18759 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18760 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18761 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18762 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18766 + args.flags = a->flags[AuHn_CHILD];
18767 + args.dentry = dentry;
18768 + args.inode = inode;
18769 + args.h_inode = a->h_child_inode;
18770 + args.dir = a->dir;
18771 + args.h_dir = a->h_dir;
18772 + args.h_name = a->h_child_name;
18773 + args.h_nlen = a->h_child_nlen;
18774 + err = hn_job(&args);
18776 + if (au_di(dentry))
18777 + di_write_unlock(dentry);
18780 + if (inode && try_iput) {
18781 + ii_write_unlock(inode);
18785 + ii_write_lock_parent(a->dir);
18786 + args.flags = a->flags[AuHn_PARENT];
18787 + args.dentry = NULL;
18788 + args.inode = a->dir;
18789 + args.h_inode = a->h_dir;
18791 + args.h_dir = NULL;
18792 + args.h_name = NULL;
18794 + err = hn_job(&args);
18795 + ii_write_unlock(a->dir);
18798 + iput(a->h_child_inode);
18801 + si_write_unlock(sb);
18802 + au_nwt_done(&sbinfo->si_nowait);
18806 +/* ---------------------------------------------------------------------- */
18808 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18809 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18812 + unsigned int flags[AuHnLast], f;
18813 + unsigned char isdir, isroot, wh;
18814 + struct inode *dir;
18815 + struct au_hnotify_args *args;
18816 + char *p, *h_child_name;
18819 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18820 + dir = igrab(hnotify->hn_aufs_inode);
18824 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18826 + h_child_name = (void *)h_child_qstr->name;
18827 + len = h_child_qstr->len;
18828 + if (h_child_name) {
18829 + if (len > AUFS_WH_PFX_LEN
18830 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18831 + h_child_name += AUFS_WH_PFX_LEN;
18832 + len -= AUFS_WH_PFX_LEN;
18838 + if (h_child_inode)
18839 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18840 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18841 + flags[AuHn_CHILD] = 0;
18843 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18844 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18845 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18846 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18847 + case FS_MOVED_FROM:
18848 + case FS_MOVED_TO:
18849 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18850 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18853 + AuDebugOn(!h_child_name);
18858 + * aufs never be able to get this child inode.
18859 + * revalidation should be in d_revalidate()
18860 + * by checking i_nlink, i_generation or d_unhashed().
18862 + AuDebugOn(!h_child_name);
18863 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18864 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18872 + h_child_inode = NULL;
18875 + /* iput() and kfree() will be called in au_hnotify() */
18876 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18877 + if (unlikely(!args)) {
18878 + AuErr1("no memory\n");
18882 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18883 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18884 + args->mask = mask;
18886 + args->h_dir = igrab(h_dir);
18887 + if (h_child_inode)
18888 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18889 + args->h_child_inode = h_child_inode;
18890 + args->h_child_nlen = len;
18892 + p = (void *)args;
18893 + p += sizeof(*args);
18894 + memcpy(p, h_child_name, len);
18898 + /* NFS fires the event for silly-renamed one from kworker */
18900 + if (!dir->i_nlink
18901 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18903 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18904 + if (unlikely(err)) {
18905 + pr_err("wkq %d\n", err);
18906 + iput(args->h_child_inode);
18907 + iput(args->h_dir);
18909 + au_kfree_rcu(args);
18916 +/* ---------------------------------------------------------------------- */
18918 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18922 + AuDebugOn(!(udba & AuOptMask_UDBA));
18925 + if (au_hnotify_op.reset_br)
18926 + err = au_hnotify_op.reset_br(udba, br, perm);
18931 +int au_hnotify_init_br(struct au_branch *br, int perm)
18936 + if (au_hnotify_op.init_br)
18937 + err = au_hnotify_op.init_br(br, perm);
18942 +void au_hnotify_fin_br(struct au_branch *br)
18944 + if (au_hnotify_op.fin_br)
18945 + au_hnotify_op.fin_br(br);
18948 +static void au_hn_destroy_cache(void)
18950 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18951 + au_cache[AuCache_HNOTIFY] = NULL;
18954 +int __init au_hnotify_init(void)
18959 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18960 + if (au_cache[AuCache_HNOTIFY]) {
18962 + if (au_hnotify_op.init)
18963 + err = au_hnotify_op.init();
18964 + if (unlikely(err))
18965 + au_hn_destroy_cache();
18971 +void au_hnotify_fin(void)
18973 + if (au_hnotify_op.fin)
18974 + au_hnotify_op.fin();
18976 + /* cf. au_cache_fin() */
18977 + if (au_cache[AuCache_HNOTIFY])
18978 + au_hn_destroy_cache();
18980 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18981 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18982 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
18984 +// SPDX-License-Identifier: GPL-2.0
18986 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18988 + * This program is free software; you can redistribute it and/or modify
18989 + * it under the terms of the GNU General Public License as published by
18990 + * the Free Software Foundation; either version 2 of the License, or
18991 + * (at your option) any later version.
18993 + * This program is distributed in the hope that it will be useful,
18994 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18995 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18996 + * GNU General Public License for more details.
18998 + * You should have received a copy of the GNU General Public License
18999 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19003 + * inode private data
19008 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19010 + struct inode *h_inode;
19011 + struct au_hinode *hinode;
19013 + IiMustAnyLock(inode);
19015 + hinode = au_hinode(au_ii(inode), bindex);
19016 + h_inode = hinode->hi_inode;
19017 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19021 +/* todo: hard/soft set? */
19022 +void au_hiput(struct au_hinode *hinode)
19024 + au_hn_free(hinode);
19025 + dput(hinode->hi_whdentry);
19026 + iput(hinode->hi_inode);
19029 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19031 + unsigned int flags;
19032 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19035 + if (au_opt_test(mnt_flags, XINO))
19036 + au_fset_hi(flags, XINO);
19037 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19038 + au_fset_hi(flags, HNOTIFY);
19042 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19043 + struct inode *h_inode, unsigned int flags)
19045 + struct au_hinode *hinode;
19046 + struct inode *hi;
19047 + struct au_iinfo *iinfo = au_ii(inode);
19049 + IiMustWriteLock(inode);
19051 + hinode = au_hinode(iinfo, bindex);
19052 + hi = hinode->hi_inode;
19053 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19056 + au_hiput(hinode);
19057 + hinode->hi_inode = h_inode;
19060 + struct super_block *sb = inode->i_sb;
19061 + struct au_branch *br;
19063 + AuDebugOn(inode->i_mode
19064 + && (h_inode->i_mode & S_IFMT)
19065 + != (inode->i_mode & S_IFMT));
19066 + if (bindex == iinfo->ii_btop)
19067 + au_cpup_igen(inode, h_inode);
19068 + br = au_sbr(sb, bindex);
19069 + hinode->hi_id = br->br_id;
19070 + if (au_ftest_hi(flags, XINO)) {
19071 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19073 + if (unlikely(err))
19074 + AuIOErr1("failed au_xino_write() %d\n", err);
19077 + if (au_ftest_hi(flags, HNOTIFY)
19078 + && au_br_hnotifyable(br->br_perm)) {
19079 + err = au_hn_alloc(hinode, inode);
19080 + if (unlikely(err))
19081 + AuIOErr1("au_hn_alloc() %d\n", err);
19086 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19087 + struct dentry *h_wh)
19089 + struct au_hinode *hinode;
19091 + IiMustWriteLock(inode);
19093 + hinode = au_hinode(au_ii(inode), bindex);
19094 + AuDebugOn(hinode->hi_whdentry);
19095 + hinode->hi_whdentry = h_wh;
19098 +void au_update_iigen(struct inode *inode, int half)
19100 + struct au_iinfo *iinfo;
19101 + struct au_iigen *iigen;
19102 + unsigned int sigen;
19104 + sigen = au_sigen(inode->i_sb);
19105 + iinfo = au_ii(inode);
19106 + iigen = &iinfo->ii_generation;
19107 + spin_lock(&iigen->ig_spin);
19108 + iigen->ig_generation = sigen;
19110 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19112 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19113 + spin_unlock(&iigen->ig_spin);
19116 +/* it may be called at remount time, too */
19117 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19119 + struct au_iinfo *iinfo;
19120 + aufs_bindex_t bindex, bbot;
19122 + AuDebugOn(au_is_bad_inode(inode));
19123 + IiMustWriteLock(inode);
19125 + iinfo = au_ii(inode);
19126 + if (do_put_zero && iinfo->ii_btop >= 0) {
19127 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19129 + struct inode *h_i;
19131 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19134 + && !(h_i->i_state & I_LINKABLE))
19135 + au_set_h_iptr(inode, bindex, NULL, 0);
19139 + iinfo->ii_btop = -1;
19140 + iinfo->ii_bbot = -1;
19141 + bbot = au_sbbot(inode->i_sb);
19142 + for (bindex = 0; bindex <= bbot; bindex++)
19143 + if (au_hinode(iinfo, bindex)->hi_inode) {
19144 + iinfo->ii_btop = bindex;
19147 + if (iinfo->ii_btop >= 0)
19148 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19149 + if (au_hinode(iinfo, bindex)->hi_inode) {
19150 + iinfo->ii_bbot = bindex;
19153 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19156 +/* ---------------------------------------------------------------------- */
19158 +void au_icntnr_init_once(void *_c)
19160 + struct au_icntnr *c = _c;
19161 + struct au_iinfo *iinfo = &c->iinfo;
19163 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19164 + au_rw_init(&iinfo->ii_rwsem);
19165 + inode_init_once(&c->vfs_inode);
19168 +void au_hinode_init(struct au_hinode *hinode)
19170 + hinode->hi_inode = NULL;
19171 + hinode->hi_id = -1;
19172 + au_hn_init(hinode);
19173 + hinode->hi_whdentry = NULL;
19176 +int au_iinfo_init(struct inode *inode)
19178 + struct au_iinfo *iinfo;
19179 + struct super_block *sb;
19180 + struct au_hinode *hi;
19183 + sb = inode->i_sb;
19184 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19185 + nbr = au_sbbot(sb) + 1;
19186 + if (unlikely(nbr <= 0))
19188 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19190 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19192 + iinfo->ii_hinode = hi;
19193 + for (i = 0; i < nbr; i++, hi++)
19194 + au_hinode_init(hi);
19196 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19197 + iinfo->ii_btop = -1;
19198 + iinfo->ii_bbot = -1;
19199 + iinfo->ii_vdir = NULL;
19205 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19208 + struct au_hinode *hip;
19210 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19213 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19216 + iinfo->ii_hinode = hip;
19217 + i = iinfo->ii_bbot + 1;
19219 + for (; i < nbr; i++, hip++)
19220 + au_hinode_init(hip);
19227 +void au_iinfo_fin(struct inode *inode)
19229 + struct au_iinfo *iinfo;
19230 + struct au_hinode *hi;
19231 + struct super_block *sb;
19232 + aufs_bindex_t bindex, bbot;
19233 + const unsigned char unlinked = !inode->i_nlink;
19235 + AuDebugOn(au_is_bad_inode(inode));
19237 + sb = inode->i_sb;
19238 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19239 + if (si_pid_test(sb))
19240 + au_xino_delete_inode(inode, unlinked);
19243 + * it is safe to hide the dependency between sbinfo and
19247 + si_noflush_read_lock(sb);
19248 + au_xino_delete_inode(inode, unlinked);
19249 + si_read_unlock(sb);
19253 + iinfo = au_ii(inode);
19254 + if (iinfo->ii_vdir)
19255 + au_vdir_free(iinfo->ii_vdir);
19257 + bindex = iinfo->ii_btop;
19258 + if (bindex >= 0) {
19259 + hi = au_hinode(iinfo, bindex);
19260 + bbot = iinfo->ii_bbot;
19261 + while (bindex++ <= bbot) {
19262 + if (hi->hi_inode)
19267 + au_kfree_rcu(iinfo->ii_hinode);
19268 + AuRwDestroy(&iinfo->ii_rwsem);
19270 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19271 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19272 +++ linux/fs/aufs/inode.c 2023-10-31 09:31:04.199880750 +0100
19274 +// SPDX-License-Identifier: GPL-2.0
19276 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19278 + * This program is free software; you can redistribute it and/or modify
19279 + * it under the terms of the GNU General Public License as published by
19280 + * the Free Software Foundation; either version 2 of the License, or
19281 + * (at your option) any later version.
19283 + * This program is distributed in the hope that it will be useful,
19284 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19285 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19286 + * GNU General Public License for more details.
19288 + * You should have received a copy of the GNU General Public License
19289 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19293 + * inode functions
19296 +#include <linux/iversion.h>
19299 +struct inode *au_igrab(struct inode *inode)
19302 + AuDebugOn(!atomic_read(&inode->i_count));
19308 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19310 + au_cpup_attr_all(inode, /*force*/0);
19311 + au_update_iigen(inode, /*half*/1);
19313 + inode_inc_iversion(inode);
19316 +static int au_ii_refresh(struct inode *inode, int *update)
19320 + aufs_bindex_t bindex, new_bindex;
19321 + struct super_block *sb;
19322 + struct au_iinfo *iinfo;
19323 + struct au_hinode *p, *q, tmp;
19325 + AuDebugOn(au_is_bad_inode(inode));
19326 + IiMustWriteLock(inode);
19329 + sb = inode->i_sb;
19330 + nbr = au_sbbot(sb) + 1;
19331 + type = inode->i_mode & S_IFMT;
19332 + iinfo = au_ii(inode);
19333 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19334 + if (unlikely(err))
19337 + AuDebugOn(iinfo->ii_btop < 0);
19338 + p = au_hinode(iinfo, iinfo->ii_btop);
19339 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19341 + if (!p->hi_inode)
19344 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19345 + new_bindex = au_br_index(sb, p->hi_id);
19346 + if (new_bindex == bindex)
19349 + if (new_bindex < 0) {
19352 + p->hi_inode = NULL;
19356 + if (new_bindex < iinfo->ii_btop)
19357 + iinfo->ii_btop = new_bindex;
19358 + if (iinfo->ii_bbot < new_bindex)
19359 + iinfo->ii_bbot = new_bindex;
19360 + /* swap two lower inode, and loop again */
19361 + q = au_hinode(iinfo, new_bindex);
19365 + if (tmp.hi_inode) {
19370 + au_update_ibrange(inode, /*do_put_zero*/0);
19371 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19372 + e = au_dy_irefresh(inode);
19373 + if (unlikely(e && !err))
19381 +void au_refresh_iop(struct inode *inode, int force_getattr)
19384 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19385 + const struct inode_operations *iop
19386 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19388 + if (inode->i_op == iop)
19391 + switch (inode->i_mode & S_IFMT) {
19393 + type = AuIop_DIR;
19396 + type = AuIop_SYMLINK;
19399 + type = AuIop_OTHER;
19403 + inode->i_op = iop + type;
19404 + /* unnecessary smp_wmb() */
19407 +int au_refresh_hinode_self(struct inode *inode)
19411 + err = au_ii_refresh(inode, &update);
19413 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19419 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19421 + int err, e, update;
19422 + unsigned int flags;
19424 + aufs_bindex_t bindex, bbot;
19425 + unsigned char isdir;
19426 + struct au_hinode *p;
19427 + struct au_iinfo *iinfo;
19429 + err = au_ii_refresh(inode, &update);
19430 + if (unlikely(err))
19434 + iinfo = au_ii(inode);
19435 + p = au_hinode(iinfo, iinfo->ii_btop);
19436 + mode = (inode->i_mode & S_IFMT);
19437 + isdir = S_ISDIR(mode);
19438 + flags = au_hi_flags(inode, isdir);
19439 + bbot = au_dbbot(dentry);
19440 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19441 + struct inode *h_i, *h_inode;
19442 + struct dentry *h_d;
19444 + h_d = au_h_dptr(dentry, bindex);
19445 + if (!h_d || d_is_negative(h_d))
19448 + h_inode = d_inode(h_d);
19449 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19450 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19451 + h_i = au_h_iptr(inode, bindex);
19453 + if (h_i == h_inode)
19459 + if (bindex < iinfo->ii_btop)
19460 + iinfo->ii_btop = bindex;
19461 + if (iinfo->ii_bbot < bindex)
19462 + iinfo->ii_bbot = bindex;
19463 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19466 + au_update_ibrange(inode, /*do_put_zero*/0);
19467 + e = au_dy_irefresh(inode);
19468 + if (unlikely(e && !err))
19471 + au_refresh_hinode_attr(inode, update && isdir);
19478 +static int set_inode(struct inode *inode, struct dentry *dentry)
19481 + unsigned int flags;
19483 + aufs_bindex_t bindex, btop, btail;
19484 + unsigned char isdir;
19485 + struct dentry *h_dentry;
19486 + struct inode *h_inode;
19487 + struct au_iinfo *iinfo;
19488 + const struct inode_operations *iop;
19490 + IiMustWriteLock(inode);
19494 + iop = au_sbi(inode->i_sb)->si_iop_array;
19495 + btop = au_dbtop(dentry);
19496 + h_dentry = au_h_dptr(dentry, btop);
19497 + h_inode = d_inode(h_dentry);
19498 + mode = h_inode->i_mode;
19499 + switch (mode & S_IFMT) {
19501 + btail = au_dbtail(dentry);
19502 + inode->i_op = iop + AuIop_OTHER;
19503 + inode->i_fop = &aufs_file_fop;
19504 + err = au_dy_iaop(inode, btop, h_inode);
19505 + if (unlikely(err))
19510 + btail = au_dbtaildir(dentry);
19511 + inode->i_op = iop + AuIop_DIR;
19512 + inode->i_fop = &aufs_dir_fop;
19515 + btail = au_dbtail(dentry);
19516 + inode->i_op = iop + AuIop_SYMLINK;
19522 + btail = au_dbtail(dentry);
19523 + inode->i_op = iop + AuIop_OTHER;
19524 + init_special_inode(inode, mode, h_inode->i_rdev);
19527 + AuIOErr("Unknown file type 0%o\n", mode);
19532 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19533 + flags = au_hi_flags(inode, isdir);
19534 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19535 + && au_ftest_hi(flags, HNOTIFY)
19536 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19537 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19538 + au_fclr_hi(flags, HNOTIFY);
19539 + iinfo = au_ii(inode);
19540 + iinfo->ii_btop = btop;
19541 + iinfo->ii_bbot = btail;
19542 + for (bindex = btop; bindex <= btail; bindex++) {
19543 + h_dentry = au_h_dptr(dentry, bindex);
19545 + au_set_h_iptr(inode, bindex,
19546 + au_igrab(d_inode(h_dentry)), flags);
19548 + au_cpup_attr_all(inode, /*force*/1);
19550 + * to force calling aufs_get_inode_acl() every time,
19551 + * do not call cache_no_acl() for aufs inode.
19559 + * successful returns with iinfo write_locked
19561 + * zero: success, matched
19562 + * plus: no error, but unmatched
19564 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19567 + unsigned int gen, igflags;
19568 + aufs_bindex_t bindex, bbot;
19569 + struct inode *h_inode, *h_dinode;
19570 + struct dentry *h_dentry;
19573 + * before this function, if aufs got any iinfo lock, it must be only
19574 + * one, the parent dir.
19575 + * it can happen by UDBA and the obsoleted inode number.
19578 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19582 + ii_write_lock_new_child(inode);
19583 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19584 + h_dinode = d_inode(h_dentry);
19585 + bbot = au_ibbot(inode);
19586 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19587 + h_inode = au_h_iptr(inode, bindex);
19588 + if (!h_inode || h_inode != h_dinode)
19592 + gen = au_iigen(inode, &igflags);
19593 + if (gen == au_digen(dentry)
19594 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19597 + /* fully refresh inode using dentry */
19598 + err = au_refresh_hinode(inode, dentry);
19600 + au_update_iigen(inode, /*half*/0);
19604 + if (unlikely(err))
19605 + ii_write_unlock(inode);
19610 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19611 + unsigned int d_type, ino_t *ino)
19614 + const int isnondir = d_type != DT_DIR;
19616 + /* prevent hardlinked inode number from race condition */
19618 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19619 + if (unlikely(err))
19623 + err = au_xino_read(sb, bindex, h_ino, ino);
19624 + if (unlikely(err))
19625 + goto out_xinondir;
19629 + *ino = au_xino_new_ino(sb);
19630 + if (unlikely(!*ino))
19631 + goto out_xinondir;
19632 + err = au_xino_write(sb, bindex, h_ino, *ino);
19633 + if (unlikely(err))
19634 + goto out_xinondir;
19638 + if (isnondir && idx >= 0)
19639 + au_xinondir_leave(sb, bindex, h_ino, idx);
19644 +/* successful returns with iinfo write_locked */
19645 +/* todo: return with unlocked? */
19646 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19648 + struct inode *inode, *h_inode;
19649 + struct dentry *h_dentry;
19650 + struct super_block *sb;
19651 + ino_t h_ino, ino;
19652 + int err, idx, hlinked;
19653 + aufs_bindex_t btop;
19655 + sb = dentry->d_sb;
19656 + btop = au_dbtop(dentry);
19657 + h_dentry = au_h_dptr(dentry, btop);
19658 + h_inode = d_inode(h_dentry);
19659 + h_ino = h_inode->i_ino;
19660 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19664 + * stop 'race'-ing between hardlinks under different
19668 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19669 + inode = ERR_PTR(err);
19670 + if (unlikely(err))
19674 + err = au_xino_read(sb, btop, h_ino, &ino);
19675 + inode = ERR_PTR(err);
19676 + if (unlikely(err))
19677 + goto out_xinondir;
19680 + ino = au_xino_new_ino(sb);
19681 + if (unlikely(!ino)) {
19682 + inode = ERR_PTR(-EIO);
19683 + goto out_xinondir;
19687 + AuDbg("i%lu\n", (unsigned long)ino);
19688 + inode = au_iget_locked(sb, ino);
19689 + err = PTR_ERR(inode);
19690 + if (IS_ERR(inode))
19691 + goto out_xinondir;
19693 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19694 + if (inode->i_state & I_NEW) {
19695 + ii_write_lock_new_child(inode);
19696 + err = set_inode(inode, dentry);
19698 + unlock_new_inode(inode);
19699 + goto out_xinondir; /* success */
19703 + * iget_failed() calls iput(), but we need to call
19704 + * ii_write_unlock() after iget_failed(). so dirty hack for
19707 + atomic_inc(&inode->i_count);
19708 + iget_failed(inode);
19709 + ii_write_unlock(inode);
19710 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19711 + /* ignore this error */
19713 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19715 + * horrible race condition between lookup, readdir and copyup
19716 + * (or something).
19718 + if (hlinked && idx >= 0)
19719 + au_xinondir_leave(sb, btop, h_ino, idx);
19720 + err = reval_inode(inode, dentry);
19721 + if (unlikely(err < 0)) {
19726 + goto out; /* success */
19727 + else if (hlinked && idx >= 0) {
19728 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19729 + if (unlikely(err)) {
19731 + inode = ERR_PTR(err);
19737 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19738 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19739 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19740 + btop, au_sbtype(h_dentry->d_sb), dentry,
19741 + (unsigned long)h_ino, (unsigned long)ino);
19743 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19746 + if (hlinked && idx >= 0)
19747 + au_xinondir_leave(sb, btop, h_ino, idx);
19753 + inode = ERR_PTR(err);
19755 + if (hlinked && idx >= 0)
19756 + au_xinondir_leave(sb, btop, h_ino, idx);
19761 +/* ---------------------------------------------------------------------- */
19763 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19764 + struct inode *inode)
19767 + struct inode *hi;
19769 + err = au_br_rdonly(au_sbr(sb, bindex));
19771 + /* pseudo-link after flushed may happen out of bounds */
19774 + && au_ibtop(inode) <= bindex
19775 + && bindex <= au_ibbot(inode)) {
19777 + * permission check is unnecessary since vfsub routine
19778 + * will be called later
19780 + hi = au_h_iptr(inode, bindex);
19782 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19788 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19791 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19793 + return inode_permission(h_idmap, h_inode, mask);
19796 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19799 + if (au_test_nfs(h_inode->i_sb)
19800 + && (mask & MAY_WRITE)
19801 + && S_ISDIR(h_inode->i_mode))
19802 + mask |= MAY_READ; /* force permission check */
19803 + return au_test_h_perm(h_idmap, h_inode, mask);
19805 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19806 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19807 +++ linux/fs/aufs/inode.h 2023-10-31 09:31:04.199880750 +0100
19809 +/* SPDX-License-Identifier: GPL-2.0 */
19811 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19813 + * This program is free software; you can redistribute it and/or modify
19814 + * it under the terms of the GNU General Public License as published by
19815 + * the Free Software Foundation; either version 2 of the License, or
19816 + * (at your option) any later version.
19818 + * This program is distributed in the hope that it will be useful,
19819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19821 + * GNU General Public License for more details.
19823 + * You should have received a copy of the GNU General Public License
19824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19828 + * inode operations
19831 +#ifndef __AUFS_INODE_H__
19832 +#define __AUFS_INODE_H__
19836 +#include <linux/fsnotify.h>
19837 +#include "rwsem.h"
19841 +struct au_hnotify {
19842 +#ifdef CONFIG_AUFS_HNOTIFY
19843 +#ifdef CONFIG_AUFS_HFSNOTIFY
19844 + /* never use fsnotify_add_vfsmount_mark() */
19845 + struct fsnotify_mark hn_mark;
19847 + struct inode *hn_aufs_inode; /* no get/put */
19848 + struct rcu_head rcu;
19850 +} ____cacheline_aligned_in_smp;
19852 +struct au_hinode {
19853 + struct inode *hi_inode;
19854 + aufs_bindex_t hi_id;
19855 +#ifdef CONFIG_AUFS_HNOTIFY
19856 + struct au_hnotify *hi_notify;
19859 + /* reference to the copied-up whiteout with get/put */
19860 + struct dentry *hi_whdentry;
19864 +#define AuIG_HALF_REFRESHED 1
19865 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19866 +#define au_ig_fset(flags, name) \
19867 + do { (flags) |= AuIG_##name; } while (0)
19868 +#define au_ig_fclr(flags, name) \
19869 + do { (flags) &= ~AuIG_##name; } while (0)
19872 + spinlock_t ig_spin;
19873 + __u32 ig_generation, ig_flags;
19878 + struct au_iigen ii_generation;
19879 + struct super_block *ii_hsb1; /* no get/put */
19881 + struct au_rwsem ii_rwsem;
19882 + aufs_bindex_t ii_btop, ii_bbot;
19884 + struct au_hinode *ii_hinode;
19885 + struct au_vdir *ii_vdir;
19888 +struct au_icntnr {
19889 + struct au_iinfo iinfo;
19890 + struct inode vfs_inode;
19891 + struct hlist_bl_node plink;
19892 + struct rcu_head rcu;
19893 +} ____cacheline_aligned_in_smp;
19895 +/* au_pin flags */
19896 +#define AuPin_DI_LOCKED 1
19897 +#define AuPin_MNT_WRITE (1 << 1)
19898 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19899 +#define au_fset_pin(flags, name) \
19900 + do { (flags) |= AuPin_##name; } while (0)
19901 +#define au_fclr_pin(flags, name) \
19902 + do { (flags) &= ~AuPin_##name; } while (0)
19906 + struct dentry *dentry;
19907 + unsigned int udba;
19908 + unsigned char lsc_di, lsc_hi, flags;
19909 + aufs_bindex_t bindex;
19912 + struct dentry *parent;
19913 + struct au_hinode *hdir;
19914 + struct vfsmount *h_mnt;
19916 + /* temporary unlock/relock for copyup */
19917 + struct dentry *h_dentry, *h_parent;
19918 + struct au_branch *br;
19919 + struct task_struct *task;
19922 +void au_pin_hdir_unlock(struct au_pin *p);
19923 +int au_pin_hdir_lock(struct au_pin *p);
19924 +int au_pin_hdir_relock(struct au_pin *p);
19925 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19926 +void au_pin_hdir_release(struct au_pin *p);
19928 +/* ---------------------------------------------------------------------- */
19930 +static inline struct au_iinfo *au_ii(struct inode *inode)
19932 + BUG_ON(is_bad_inode(inode));
19933 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19936 +/* ---------------------------------------------------------------------- */
19939 +struct inode *au_igrab(struct inode *inode);
19940 +void au_refresh_iop(struct inode *inode, int force_getattr);
19941 +int au_refresh_hinode_self(struct inode *inode);
19942 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19943 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19944 + unsigned int d_type, ino_t *ino);
19945 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19946 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19947 + struct inode *inode);
19948 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19950 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19953 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19954 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19956 +#ifdef CONFIG_AUFS_SHWH
19957 + return au_ino(sb, bindex, h_ino, d_type, ino);
19970 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19971 + aufs_iop_nogetattr[AuIop_Last];
19973 +/* au_wr_dir flags */
19974 +#define AuWrDir_ADD_ENTRY 1
19975 +#define AuWrDir_ISDIR (1 << 1)
19976 +#define AuWrDir_TMPFILE (1 << 2)
19977 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19978 +#define au_fset_wrdir(flags, name) \
19979 + do { (flags) |= AuWrDir_##name; } while (0)
19980 +#define au_fclr_wrdir(flags, name) \
19981 + do { (flags) &= ~AuWrDir_##name; } while (0)
19983 +struct au_wr_dir_args {
19984 + aufs_bindex_t force_btgt;
19985 + unsigned char flags;
19987 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19988 + struct au_wr_dir_args *args);
19990 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19991 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19992 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19993 + unsigned int udba, unsigned char flags);
19994 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19995 + unsigned int udba, unsigned char flags) __must_check;
19996 +int au_do_pin(struct au_pin *pin) __must_check;
19997 +void au_unpin(struct au_pin *pin);
19998 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20000 +#define AuIcpup_DID_CPUP 1
20001 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20002 +#define au_fset_icpup(flags, name) \
20003 + do { (flags) |= AuIcpup_##name; } while (0)
20004 +#define au_fclr_icpup(flags, name) \
20005 + do { (flags) &= ~AuIcpup_##name; } while (0)
20007 +struct au_icpup_args {
20008 + unsigned char flags;
20009 + unsigned char pin_flags;
20010 + aufs_bindex_t btgt;
20011 + unsigned int udba;
20012 + struct au_pin pin;
20013 + struct path h_path;
20014 + struct inode *h_inode;
20017 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20018 + struct au_icpup_args *a);
20020 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20021 + struct path *h_path, int locked);
20024 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20025 + struct dentry *h_parent, int isdir);
20026 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
20027 + struct dentry *dentry, umode_t mode, dev_t dev);
20028 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
20029 + struct dentry *dentry, const char *symname);
20030 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
20031 + struct dentry *dentry, umode_t mode, bool want_excl);
20032 +struct vfsub_aopen_args;
20033 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20034 + struct vfsub_aopen_args *args);
20035 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
20036 + struct file *file, umode_t mode);
20037 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20038 + struct dentry *dentry);
20039 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
20040 + struct dentry *dentry, umode_t mode);
20043 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20044 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20045 + struct dentry *h_parent, int isdir);
20046 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20047 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20050 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20051 +int aufs_rename(struct mnt_idmap *idmap,
20052 + struct inode *_src_dir, struct dentry *_src_dentry,
20053 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20054 + unsigned int _flags);
20057 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20058 +void au_hiput(struct au_hinode *hinode);
20059 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20060 + struct dentry *h_wh);
20061 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20063 +/* hinode flags */
20064 +#define AuHi_XINO 1
20065 +#define AuHi_HNOTIFY (1 << 1)
20066 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20067 +#define au_fset_hi(flags, name) \
20068 + do { (flags) |= AuHi_##name; } while (0)
20069 +#define au_fclr_hi(flags, name) \
20070 + do { (flags) &= ~AuHi_##name; } while (0)
20072 +#ifndef CONFIG_AUFS_HNOTIFY
20073 +#undef AuHi_HNOTIFY
20074 +#define AuHi_HNOTIFY 0
20077 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20078 + struct inode *h_inode, unsigned int flags);
20080 +void au_update_iigen(struct inode *inode, int half);
20081 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20083 +void au_icntnr_init_once(void *_c);
20084 +void au_hinode_init(struct au_hinode *hinode);
20085 +int au_iinfo_init(struct inode *inode);
20086 +void au_iinfo_fin(struct inode *inode);
20087 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20089 +#ifdef CONFIG_PROC_FS
20091 +int au_plink_maint(struct super_block *sb, int flags);
20093 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20094 +int au_plink_maint_enter(struct super_block *sb);
20095 +#ifdef CONFIG_AUFS_DEBUG
20096 +void au_plink_list(struct super_block *sb);
20098 +AuStubVoid(au_plink_list, struct super_block *sb)
20100 +int au_plink_test(struct inode *inode);
20101 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20102 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20103 + struct dentry *h_dentry);
20104 +void au_plink_put(struct super_block *sb, int verbose);
20105 +void au_plink_clean(struct super_block *sb, int verbose);
20106 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20108 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20109 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20110 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20111 +AuStubVoid(au_plink_list, struct super_block *sb);
20112 +AuStubInt0(au_plink_test, struct inode *inode);
20113 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20114 + struct inode *inode, aufs_bindex_t bindex);
20115 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20116 + struct dentry *h_dentry);
20117 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20118 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20119 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20120 +#endif /* CONFIG_PROC_FS */
20122 +#ifdef CONFIG_AUFS_XATTR
20124 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20125 + unsigned int verbose);
20126 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20127 +void au_xattr_init(struct super_block *sb);
20129 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20130 + int ignore_flags, unsigned int verbose);
20131 +AuStubVoid(au_xattr_init, struct super_block *sb);
20134 +#ifdef CONFIG_FS_POSIX_ACL
20135 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu);
20136 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
20137 + struct dentry *dentry, int type);
20138 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
20139 + struct posix_acl *acl, int type);
20142 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20148 +struct au_sxattr {
20152 + const char *name;
20153 + const void *value;
20158 + struct posix_acl *acl;
20163 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20164 + struct au_sxattr *arg);
20167 +/* ---------------------------------------------------------------------- */
20169 +/* lock subclass for iinfo */
20171 + AuLsc_II_CHILD, /* child first */
20172 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20173 + AuLsc_II_CHILD3, /* copyup dirs */
20174 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20175 + AuLsc_II_PARENT2,
20176 + AuLsc_II_PARENT3, /* copyup dirs */
20177 + AuLsc_II_NEW_CHILD
20181 + * ii_read_lock_child, ii_write_lock_child,
20182 + * ii_read_lock_child2, ii_write_lock_child2,
20183 + * ii_read_lock_child3, ii_write_lock_child3,
20184 + * ii_read_lock_parent, ii_write_lock_parent,
20185 + * ii_read_lock_parent2, ii_write_lock_parent2,
20186 + * ii_read_lock_parent3, ii_write_lock_parent3,
20187 + * ii_read_lock_new_child, ii_write_lock_new_child,
20189 +#define AuReadLockFunc(name, lsc) \
20190 +static inline void ii_read_lock_##name(struct inode *i) \
20192 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20195 +#define AuWriteLockFunc(name, lsc) \
20196 +static inline void ii_write_lock_##name(struct inode *i) \
20198 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20201 +#define AuRWLockFuncs(name, lsc) \
20202 + AuReadLockFunc(name, lsc) \
20203 + AuWriteLockFunc(name, lsc)
20205 +AuRWLockFuncs(child, CHILD);
20206 +AuRWLockFuncs(child2, CHILD2);
20207 +AuRWLockFuncs(child3, CHILD3);
20208 +AuRWLockFuncs(parent, PARENT);
20209 +AuRWLockFuncs(parent2, PARENT2);
20210 +AuRWLockFuncs(parent3, PARENT3);
20211 +AuRWLockFuncs(new_child, NEW_CHILD);
20213 +#undef AuReadLockFunc
20214 +#undef AuWriteLockFunc
20215 +#undef AuRWLockFuncs
20217 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20218 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20219 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20221 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20222 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20223 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20225 +/* ---------------------------------------------------------------------- */
20227 +static inline void au_icntnr_init(struct au_icntnr *c)
20229 +#ifdef CONFIG_AUFS_DEBUG
20230 + c->vfs_inode.i_mode = 0;
20234 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20236 + unsigned int gen;
20237 + struct au_iinfo *iinfo;
20238 + struct au_iigen *iigen;
20240 + iinfo = au_ii(inode);
20241 + iigen = &iinfo->ii_generation;
20242 + spin_lock(&iigen->ig_spin);
20244 + *igflags = iigen->ig_flags;
20245 + gen = iigen->ig_generation;
20246 + spin_unlock(&iigen->ig_spin);
20251 +/* tiny test for inode number */
20252 +/* tmpfs generation is too rough */
20253 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20255 + struct au_iinfo *iinfo;
20257 + iinfo = au_ii(inode);
20258 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20259 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20260 + && iinfo->ii_higen == h_inode->i_generation);
20263 +static inline void au_iigen_dec(struct inode *inode)
20265 + struct au_iinfo *iinfo;
20266 + struct au_iigen *iigen;
20268 + iinfo = au_ii(inode);
20269 + iigen = &iinfo->ii_generation;
20270 + spin_lock(&iigen->ig_spin);
20271 + iigen->ig_generation--;
20272 + spin_unlock(&iigen->ig_spin);
20275 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20280 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20286 +/* ---------------------------------------------------------------------- */
20288 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20289 + aufs_bindex_t bindex)
20291 + return iinfo->ii_hinode + bindex;
20294 +static inline int au_is_bad_inode(struct inode *inode)
20296 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20299 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20300 + aufs_bindex_t bindex)
20302 + IiMustAnyLock(inode);
20303 + return au_hinode(au_ii(inode), bindex)->hi_id;
20306 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20308 + IiMustAnyLock(inode);
20309 + return au_ii(inode)->ii_btop;
20312 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20314 + IiMustAnyLock(inode);
20315 + return au_ii(inode)->ii_bbot;
20318 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20320 + IiMustAnyLock(inode);
20321 + return au_ii(inode)->ii_vdir;
20324 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20326 + IiMustAnyLock(inode);
20327 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20330 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20332 + IiMustWriteLock(inode);
20333 + au_ii(inode)->ii_btop = bindex;
20336 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20338 + IiMustWriteLock(inode);
20339 + au_ii(inode)->ii_bbot = bindex;
20342 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20344 + IiMustWriteLock(inode);
20345 + au_ii(inode)->ii_vdir = vdir;
20348 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20350 + IiMustAnyLock(inode);
20351 + return au_hinode(au_ii(inode), bindex);
20354 +/* ---------------------------------------------------------------------- */
20356 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20359 + return pin->parent;
20363 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20365 + if (pin && pin->hdir)
20366 + return pin->hdir->hi_inode;
20370 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20373 + return pin->hdir;
20377 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20380 + pin->dentry = dentry;
20383 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20384 + unsigned char lflag)
20388 + au_fset_pin(pin->flags, DI_LOCKED);
20390 + au_fclr_pin(pin->flags, DI_LOCKED);
20394 +#if 0 /* reserved */
20395 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20398 + dput(pin->parent);
20399 + pin->parent = dget(parent);
20404 +/* ---------------------------------------------------------------------- */
20407 +#ifdef CONFIG_AUFS_HNOTIFY
20408 +struct au_hnotify_op {
20409 + void (*ctl)(struct au_hinode *hinode, int do_set);
20410 + int (*alloc)(struct au_hinode *hinode);
20413 + * if it returns true, the caller should free hinode->hi_notify,
20414 + * otherwise ->free() frees it.
20416 + int (*free)(struct au_hinode *hinode,
20417 + struct au_hnotify *hn) __must_check;
20419 + void (*fin)(void);
20420 + int (*init)(void);
20422 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20423 + void (*fin_br)(struct au_branch *br);
20424 + int (*init_br)(struct au_branch *br, int perm);
20428 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20429 +void au_hn_free(struct au_hinode *hinode);
20430 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20431 +void au_hn_reset(struct inode *inode, unsigned int flags);
20432 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20433 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20434 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20435 +int au_hnotify_init_br(struct au_branch *br, int perm);
20436 +void au_hnotify_fin_br(struct au_branch *br);
20437 +int __init au_hnotify_init(void);
20438 +void au_hnotify_fin(void);
20441 +extern const struct au_hnotify_op au_hnotify_op;
20444 +void au_hn_init(struct au_hinode *hinode)
20446 + hinode->hi_notify = NULL;
20449 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20451 + return hinode->hi_notify;
20455 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20456 + struct au_hinode *hinode __maybe_unused,
20457 + struct inode *inode __maybe_unused)
20458 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20459 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20460 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20461 + int do_set __maybe_unused)
20462 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20463 + unsigned int flags __maybe_unused)
20464 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20465 + struct au_branch *br __maybe_unused,
20466 + int perm __maybe_unused)
20467 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20468 + int perm __maybe_unused)
20469 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20470 +AuStubInt0(__init au_hnotify_init, void)
20471 +AuStubVoid(au_hnotify_fin, void)
20472 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20473 +#endif /* CONFIG_AUFS_HNOTIFY */
20475 +static inline void au_hn_suspend(struct au_hinode *hdir)
20477 + au_hn_ctl(hdir, /*do_set*/0);
20480 +static inline void au_hn_resume(struct au_hinode *hdir)
20482 + au_hn_ctl(hdir, /*do_set*/1);
20485 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20487 + inode_lock(hdir->hi_inode);
20488 + au_hn_suspend(hdir);
20491 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20492 + unsigned int sc __maybe_unused)
20494 + inode_lock_nested(hdir->hi_inode, sc);
20495 + au_hn_suspend(hdir);
20498 +#if 0 /* unused */
20499 +#include "vfsub.h"
20500 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20503 + inode_lock_shared_nested(hdir->hi_inode, sc);
20504 + au_hn_suspend(hdir);
20508 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20510 + au_hn_resume(hdir);
20511 + inode_unlock(hdir->hi_inode);
20514 +#endif /* __KERNEL__ */
20515 +#endif /* __AUFS_INODE_H__ */
20516 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20517 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20518 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20520 +// SPDX-License-Identifier: GPL-2.0
20522 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20524 + * This program is free software; you can redistribute it and/or modify
20525 + * it under the terms of the GNU General Public License as published by
20526 + * the Free Software Foundation; either version 2 of the License, or
20527 + * (at your option) any later version.
20529 + * This program is distributed in the hope that it will be useful,
20530 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20531 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20532 + * GNU General Public License for more details.
20534 + * You should have received a copy of the GNU General Public License
20535 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20540 + * plink-management and readdir in userspace.
20541 + * assist the pathconf(3) wrapper library.
20543 + * File-based Hierarchical Storage Management.
20546 +#include <linux/compat.h>
20547 +#include <linux/file.h>
20550 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20553 + aufs_bindex_t wbi, bindex, bbot;
20554 + struct file *h_file;
20555 + struct super_block *sb;
20556 + struct dentry *root;
20557 + struct au_branch *br;
20558 + struct aufs_wbr_fd wbrfd = {
20559 + .oflags = au_dir_roflags,
20562 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20563 + | O_NOATIME | O_CLOEXEC;
20565 + AuDebugOn(wbrfd.oflags & ~valid);
20568 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20569 + if (unlikely(err)) {
20575 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20576 + wbrfd.oflags |= au_dir_roflags;
20577 + AuDbg("0%o\n", wbrfd.oflags);
20578 + if (unlikely(wbrfd.oflags & ~valid))
20582 + fd = get_unused_fd_flags(0);
20584 + if (unlikely(fd < 0))
20587 + h_file = ERR_PTR(-EINVAL);
20590 + sb = path->dentry->d_sb;
20591 + root = sb->s_root;
20592 + aufs_read_lock(root, AuLock_IR);
20593 + bbot = au_sbbot(sb);
20594 + if (wbrfd.brid >= 0) {
20595 + wbi = au_br_index(sb, wbrfd.brid);
20596 + if (unlikely(wbi < 0 || wbi > bbot))
20600 + h_file = ERR_PTR(-ENOENT);
20601 + br = au_sbr(sb, wbi);
20602 + if (!au_br_writable(br->br_perm)) {
20606 + bindex = wbi + 1;
20608 + for (; bindex <= bbot; bindex++) {
20609 + br = au_sbr(sb, bindex);
20610 + if (au_br_writable(br->br_perm)) {
20612 + br = au_sbr(sb, wbi);
20617 + AuDbg("wbi %d\n", wbi);
20619 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20623 + aufs_read_unlock(root, AuLock_IR);
20624 + err = PTR_ERR(h_file);
20625 + if (IS_ERR(h_file))
20628 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20629 + fd_install(fd, h_file);
20631 + goto out; /* success */
20634 + put_unused_fd(fd);
20640 +/* ---------------------------------------------------------------------- */
20642 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20645 + struct dentry *dentry;
20648 + case AUFS_CTL_RDU:
20649 + case AUFS_CTL_RDU_INO:
20650 + err = au_rdu_ioctl(file, cmd, arg);
20653 + case AUFS_CTL_WBR_FD:
20654 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20657 + case AUFS_CTL_IBUSY:
20658 + err = au_ibusy_ioctl(file, arg);
20661 + case AUFS_CTL_BRINFO:
20662 + err = au_brinfo_ioctl(file, arg);
20665 + case AUFS_CTL_FHSM_FD:
20666 + dentry = file->f_path.dentry;
20667 + if (IS_ROOT(dentry))
20668 + err = au_fhsm_fd(dentry->d_sb, arg);
20674 + /* do not call the lower */
20675 + AuDbg("0x%x\n", cmd);
20683 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20688 + case AUFS_CTL_MVDOWN:
20689 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20692 + case AUFS_CTL_WBR_FD:
20693 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20697 + /* do not call the lower */
20698 + AuDbg("0x%x\n", cmd);
20706 +#ifdef CONFIG_COMPAT
20707 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20708 + unsigned long arg)
20713 + case AUFS_CTL_RDU:
20714 + case AUFS_CTL_RDU_INO:
20715 + err = au_rdu_compat_ioctl(file, cmd, arg);
20718 + case AUFS_CTL_IBUSY:
20719 + err = au_ibusy_compat_ioctl(file, arg);
20722 + case AUFS_CTL_BRINFO:
20723 + err = au_brinfo_compat_ioctl(file, arg);
20727 + err = aufs_ioctl_dir(file, cmd, arg);
20734 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20735 + unsigned long arg)
20737 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20740 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20741 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20742 +++ linux/fs/aufs/i_op_add.c 2023-10-31 09:31:04.199880750 +0100
20744 +// SPDX-License-Identifier: GPL-2.0
20746 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20748 + * This program is free software; you can redistribute it and/or modify
20749 + * it under the terms of the GNU General Public License as published by
20750 + * the Free Software Foundation; either version 2 of the License, or
20751 + * (at your option) any later version.
20753 + * This program is distributed in the hope that it will be useful,
20754 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20755 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20756 + * GNU General Public License for more details.
20758 + * You should have received a copy of the GNU General Public License
20759 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20763 + * inode operations (add entry)
20766 +#include <linux/iversion.h>
20770 + * final procedure of adding a new entry, except link(2).
20771 + * remove whiteout, instantiate, copyup the parent dir's times and size
20772 + * and update version.
20773 + * if it failed, re-create the removed whiteout.
20775 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20776 + struct dentry *wh_dentry, struct dentry *dentry)
20779 + aufs_bindex_t bwh;
20780 + struct path h_path;
20781 + struct super_block *sb;
20782 + struct inode *inode, *h_dir;
20783 + struct dentry *wh;
20788 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20789 + IMustLock(h_dir);
20790 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20791 + bwh = au_dbwh(dentry);
20792 + h_path.dentry = wh_dentry;
20793 + h_path.mnt = au_sbr_mnt(sb, bindex);
20794 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20796 + if (unlikely(err))
20800 + inode = au_new_inode(dentry, /*must_new*/1);
20801 + if (!IS_ERR(inode)) {
20802 + d_instantiate(dentry, inode);
20803 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20805 + au_dir_ts(dir, bindex);
20806 + inode_inc_iversion(dir);
20807 + au_fhsm_wrote(sb, bindex, /*force*/0);
20808 + return 0; /* success */
20811 + err = PTR_ERR(inode);
20816 + /* dir inode is locked */
20817 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20818 + rerr = PTR_ERR(wh);
20819 + if (IS_ERR(wh)) {
20820 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20821 + dentry, err, rerr);
20830 +static int au_d_may_add(struct dentry *dentry)
20835 + if (unlikely(d_unhashed(dentry)))
20837 + if (unlikely(d_really_is_positive(dentry)))
20843 + * simple tests for the adding inode operations.
20844 + * following the checks in vfs, plus the parent-child relationship.
20846 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20847 + struct dentry *h_parent, int isdir)
20851 + struct dentry *h_dentry;
20852 + struct inode *h_inode;
20854 + err = -ENAMETOOLONG;
20855 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20858 + h_dentry = au_h_dptr(dentry, bindex);
20859 + if (d_really_is_negative(dentry)) {
20861 + if (unlikely(d_is_positive(h_dentry)))
20864 + /* rename(2) case */
20866 + if (unlikely(d_is_negative(h_dentry)))
20868 + h_inode = d_inode(h_dentry);
20869 + if (unlikely(!h_inode->i_nlink))
20872 + h_mode = h_inode->i_mode;
20875 + if (unlikely(S_ISDIR(h_mode)))
20877 + } else if (unlikely(!S_ISDIR(h_mode))) {
20884 + /* expected parent dir is locked */
20885 + if (unlikely(h_parent != h_dentry->d_parent))
20894 + * initial procedure of adding a new entry.
20895 + * prepare writable branch and the parent dir, lock it,
20896 + * and lookup whiteout for the new entry.
20898 +static struct dentry*
20899 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20900 + struct dentry *src_dentry, struct au_pin *pin,
20901 + struct au_wr_dir_args *wr_dir_args)
20903 + struct dentry *wh_dentry, *h_parent;
20904 + struct super_block *sb;
20905 + struct au_branch *br;
20907 + unsigned int udba;
20908 + aufs_bindex_t bcpup;
20910 + AuDbg("%pd\n", dentry);
20912 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20914 + wh_dentry = ERR_PTR(err);
20915 + if (unlikely(err < 0))
20918 + sb = dentry->d_sb;
20919 + udba = au_opt_udba(sb);
20920 + err = au_pin(pin, dentry, bcpup, udba,
20921 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20922 + wh_dentry = ERR_PTR(err);
20923 + if (unlikely(err))
20926 + h_parent = au_pinned_h_parent(pin);
20927 + if (udba != AuOpt_UDBA_NONE
20928 + && au_dbtop(dentry) == bcpup)
20929 + err = au_may_add(dentry, bcpup, h_parent,
20930 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20931 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20932 + err = -ENAMETOOLONG;
20933 + wh_dentry = ERR_PTR(err);
20934 + if (unlikely(err))
20937 + br = au_sbr(sb, bcpup);
20939 + struct path tmp = {
20940 + .dentry = h_parent,
20941 + .mnt = au_br_mnt(br)
20943 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20946 + wh_dentry = NULL;
20947 + if (bcpup != au_dbwh(dentry))
20948 + goto out; /* success */
20951 + * ENAMETOOLONG here means that if we allowed create such name, then it
20952 + * would not be able to removed in the future. So we don't allow such
20953 + * name here and we don't handle ENAMETOOLONG differently here.
20955 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20958 + if (IS_ERR(wh_dentry))
20961 + return wh_dentry;
20964 +/* ---------------------------------------------------------------------- */
20966 +enum { Mknod, Symlink, Creat };
20967 +struct simple_arg {
20974 + struct vfsub_aopen_args *aopen;
20977 + const char *symname;
20986 +static int add_simple(struct inode *dir, struct dentry *dentry,
20987 + struct simple_arg *arg)
20990 + aufs_bindex_t btop;
20991 + unsigned char created;
20992 + const unsigned char try_aopen
20993 + = (arg->type == Creat && arg->u.c.try_aopen);
20994 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20995 + struct dentry *wh_dentry, *parent;
20996 + struct inode *h_dir;
20997 + struct super_block *sb;
20998 + struct au_branch *br;
20999 + /* to reduce stack size */
21001 + struct au_dtime dt;
21002 + struct au_pin pin;
21003 + struct path h_path;
21004 + struct au_wr_dir_args wr_dir_args;
21007 + AuDbg("%pd\n", dentry);
21011 + a = kmalloc(sizeof(*a), GFP_NOFS);
21012 + if (unlikely(!a))
21014 + a->wr_dir_args.force_btgt = -1;
21015 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21017 + parent = dentry->d_parent; /* dir inode is locked */
21018 + if (!try_aopen) {
21019 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21020 + if (unlikely(err))
21023 + err = au_d_may_add(dentry);
21024 + if (unlikely(err))
21027 + di_write_lock_parent(parent);
21028 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21029 + &a->pin, &a->wr_dir_args);
21030 + err = PTR_ERR(wh_dentry);
21031 + if (IS_ERR(wh_dentry))
21034 + btop = au_dbtop(dentry);
21035 + sb = dentry->d_sb;
21036 + br = au_sbr(sb, btop);
21037 + a->h_path.dentry = au_h_dptr(dentry, btop);
21038 + a->h_path.mnt = au_br_mnt(br);
21039 + h_dir = au_pinned_h_dir(&a->pin);
21040 + switch (arg->type) {
21042 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21043 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21044 + arg->u.c.want_excl);
21046 + if (!err && try_aopen)
21047 + aopen->file->f_mode |= FMODE_CREATED;
21050 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21051 + AuDbg("err %d\n", err);
21052 + AuDbgFile(aopen->file);
21053 + created = err >= 0
21054 + && !!(aopen->file->f_mode & FMODE_CREATED);
21058 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21062 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21069 + if (unlikely(err < 0))
21072 + err = epilog(dir, btop, wh_dentry, dentry);
21074 + goto out_unpin; /* success */
21077 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21078 + /* no delegation since it is just created */
21079 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21082 + AuIOErr("%pd revert failure(%d, %d)\n",
21083 + dentry, err, rerr);
21086 + au_dtime_revert(&a->dt);
21088 + if (try_aopen && h_dir->i_op->atomic_open
21089 + && (aopen->file->f_mode & FMODE_OPENED))
21090 + /* aopen->file is still opened */
21091 + au_lcnt_dec(&aopen->br->br_nfiles);
21094 + au_unpin(&a->pin);
21098 + di_write_unlock(parent);
21100 + if (unlikely(err)) {
21101 + au_update_dbtop(dentry);
21105 + aufs_read_unlock(dentry, AuLock_DW);
21112 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
21113 + struct dentry *dentry, umode_t mode, dev_t dev)
21115 + struct simple_arg arg = {
21122 + return add_simple(dir, dentry, &arg);
21125 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
21126 + struct dentry *dentry, const char *symname)
21128 + struct simple_arg arg = {
21130 + .u.s.symname = symname
21132 + return add_simple(dir, dentry, &arg);
21135 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
21136 + struct dentry *dentry, umode_t mode, bool want_excl)
21138 + struct simple_arg arg = {
21142 + .want_excl = want_excl
21145 + return add_simple(dir, dentry, &arg);
21148 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21149 + struct vfsub_aopen_args *aopen_args)
21151 + struct simple_arg arg = {
21154 + .mode = aopen_args->create_mode,
21155 + .want_excl = aopen_args->open_flag & O_EXCL,
21156 + .try_aopen = true,
21157 + .aopen = aopen_args
21160 + return add_simple(dir, dentry, &arg);
21163 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
21164 + struct file *file, umode_t mode)
21167 + aufs_bindex_t bindex;
21168 + struct path h_ppath;
21169 + struct super_block *sb;
21170 + struct au_branch *br;
21171 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21172 + struct inode *h_dir, *inode;
21173 + struct vfsmount *h_mnt;
21174 + struct mnt_idmap *h_idmap;
21175 + struct file *h_file;
21176 + struct au_wr_dir_args wr_dir_args = {
21177 + .force_btgt = -1,
21178 + .flags = AuWrDir_TMPFILE
21181 + /* copy-up may happen */
21186 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21187 + if (unlikely(err))
21190 + dentry = file->f_path.dentry;
21191 + err = au_di_init(dentry);
21192 + if (unlikely(err))
21196 + parent = d_find_any_alias(dir);
21197 + AuDebugOn(!parent);
21198 + di_write_lock_parent(parent);
21199 + if (unlikely(d_inode(parent) != dir))
21202 + err = au_digen_test(parent, au_sigen(sb));
21203 + if (unlikely(err))
21206 + bindex = au_dbtop(parent);
21207 + au_set_dbtop(dentry, bindex);
21208 + au_set_dbbot(dentry, bindex);
21209 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21211 + if (unlikely(err < 0))
21214 + err = -EOPNOTSUPP;
21215 + h_dir = au_h_iptr(dir, bindex);
21216 + if (unlikely(!h_dir->i_op->tmpfile))
21219 + br = au_sbr(sb, bindex);
21220 + h_mnt = au_br_mnt(br);
21221 + err = vfsub_mnt_want_write(h_mnt);
21222 + if (unlikely(err))
21225 + h_idmap = mnt_idmap(h_mnt);
21226 + h_parent = au_h_dptr(parent, bindex);
21227 + h_ppath.mnt = h_mnt;
21228 + h_ppath.dentry = h_parent;
21229 + h_file = kernel_tmpfile_open(h_idmap, &h_ppath, mode, /*open_flag*/0,
21231 + if (IS_ERR(h_file)) {
21232 + err = PTR_ERR(h_file);
21237 + h_dentry = h_file->f_path.dentry;
21238 + au_set_dbtop(dentry, bindex);
21239 + au_set_dbbot(dentry, bindex);
21240 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21241 + inode = au_new_inode(dentry, /*must_new*/1);
21242 + if (IS_ERR(inode)) {
21243 + err = PTR_ERR(inode);
21244 + au_set_h_dptr(dentry, bindex, NULL);
21245 + au_set_dbtop(dentry, -1);
21246 + au_set_dbbot(dentry, -1);
21250 + if (!inode->i_nlink)
21251 + set_nlink(inode, 1);
21252 + d_tmpfile(file, inode);
21253 + au_di(dentry)->di_tmpfile = 1;
21254 + get_file(h_file);
21255 + au_di(dentry)->di_htmpfile = h_file;
21257 + /* update without i_mutex */
21258 + if (au_ibtop(dir) == au_dbtop(dentry))
21259 + au_cpup_attr_timesizes(dir);
21264 + vfsub_mnt_drop_write(h_mnt);
21266 + di_write_unlock(parent);
21268 + di_write_unlock(dentry);
21273 + au_di(dentry)->di_htmpfile = NULL;
21274 + au_di_fin(dentry);
21275 + dentry->d_fsdata = NULL;
21277 + si_read_unlock(sb);
21278 + if (!err && h_file) {
21280 + err = finish_open_simple(file, err);
21282 + au_lcnt_inc(&br->br_nfiles);
21285 + au_di(dentry)->di_htmpfile = NULL;
21286 + au_di_fin(dentry);
21287 + dentry->d_fsdata = NULL;
21291 + inode_unlock(dir);
21296 +/* ---------------------------------------------------------------------- */
21298 +struct au_link_args {
21299 + aufs_bindex_t bdst, bsrc;
21300 + struct au_pin pin;
21301 + struct path h_path;
21302 + struct dentry *src_parent, *parent;
21305 +static int au_cpup_before_link(struct dentry *src_dentry,
21306 + struct au_link_args *a)
21309 + struct dentry *h_src_dentry;
21310 + struct au_cp_generic cpg = {
21311 + .dentry = src_dentry,
21316 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21319 + di_read_lock_parent(a->src_parent, AuLock_IR);
21320 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21321 + if (unlikely(err))
21324 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21325 + err = au_pin(&a->pin, src_dentry, a->bdst,
21326 + au_opt_udba(src_dentry->d_sb),
21327 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21328 + if (unlikely(err))
21331 + err = au_sio_cpup_simple(&cpg);
21332 + au_unpin(&a->pin);
21335 + di_read_unlock(a->src_parent, AuLock_IR);
21339 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21340 + struct au_link_args *a)
21343 + unsigned char plink;
21344 + aufs_bindex_t bbot;
21345 + struct dentry *h_src_dentry;
21346 + struct inode *h_inode, *inode, *delegated;
21347 + struct super_block *sb;
21348 + struct file *h_file;
21352 + sb = src_dentry->d_sb;
21353 + inode = d_inode(src_dentry);
21354 + if (au_ibtop(inode) <= a->bdst)
21355 + h_inode = au_h_iptr(inode, a->bdst);
21356 + if (!h_inode || !h_inode->i_nlink) {
21357 + /* copyup src_dentry as the name of dentry. */
21358 + bbot = au_dbbot(dentry);
21359 + if (bbot < a->bsrc)
21360 + au_set_dbbot(dentry, a->bsrc);
21361 + au_set_h_dptr(dentry, a->bsrc,
21362 + dget(au_h_dptr(src_dentry, a->bsrc)));
21363 + dget(a->h_path.dentry);
21364 + au_set_h_dptr(dentry, a->bdst, NULL);
21365 + AuDbg("temporary d_inode...\n");
21366 + spin_lock(&dentry->d_lock);
21367 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21368 + spin_unlock(&dentry->d_lock);
21369 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21370 + if (IS_ERR(h_file))
21371 + err = PTR_ERR(h_file);
21373 + struct au_cp_generic cpg = {
21374 + .dentry = dentry,
21379 + .flags = AuCpup_KEEPLINO
21381 + err = au_sio_cpup_simple(&cpg);
21382 + au_h_open_post(dentry, a->bsrc, h_file);
21384 + dput(a->h_path.dentry);
21385 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21387 + au_set_h_dptr(dentry, a->bdst,
21388 + a->h_path.dentry);
21390 + spin_lock(&dentry->d_lock);
21391 + dentry->d_inode = NULL; /* restore */
21392 + spin_unlock(&dentry->d_lock);
21393 + AuDbg("temporary d_inode...done\n");
21394 + au_set_h_dptr(dentry, a->bsrc, NULL);
21395 + au_set_dbbot(dentry, bbot);
21397 + /* the inode of src_dentry already exists on a.bdst branch */
21398 + h_src_dentry = d_find_alias(h_inode);
21399 + if (!h_src_dentry && au_plink_test(inode)) {
21401 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21402 + err = PTR_ERR(h_src_dentry);
21403 + if (IS_ERR(h_src_dentry))
21406 + if (unlikely(d_is_negative(h_src_dentry))) {
21407 + dput(h_src_dentry);
21408 + h_src_dentry = NULL;
21412 + if (h_src_dentry) {
21413 + delegated = NULL;
21414 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21415 + &a->h_path, &delegated);
21416 + if (unlikely(err == -EWOULDBLOCK)) {
21417 + pr_warn("cannot retry for NFSv4 delegation"
21418 + " for an internal link\n");
21421 + dput(h_src_dentry);
21423 + AuIOErr("no dentry found for hi%lu on b%d\n",
21424 + h_inode->i_ino, a->bdst);
21429 + if (!err && !plink)
21430 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21437 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21438 + struct dentry *dentry)
21441 + struct au_dtime dt;
21442 + struct au_link_args *a;
21443 + struct dentry *wh_dentry, *h_src_dentry;
21444 + struct inode *inode, *delegated;
21445 + struct super_block *sb;
21446 + struct au_wr_dir_args wr_dir_args = {
21447 + /* .force_btgt = -1, */
21448 + .flags = AuWrDir_ADD_ENTRY
21452 + inode = d_inode(src_dentry);
21453 + IMustLock(inode);
21456 + a = kzalloc(sizeof(*a), GFP_NOFS);
21457 + if (unlikely(!a))
21460 + a->parent = dentry->d_parent; /* dir inode is locked */
21461 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21462 + AuLock_NOPLM | AuLock_GEN);
21463 + if (unlikely(err))
21465 + err = au_d_linkable(src_dentry);
21466 + if (unlikely(err))
21468 + err = au_d_may_add(dentry);
21469 + if (unlikely(err))
21472 + a->src_parent = dget_parent(src_dentry);
21473 + wr_dir_args.force_btgt = au_ibtop(inode);
21475 + di_write_lock_parent(a->parent);
21476 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21477 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21479 + err = PTR_ERR(wh_dentry);
21480 + if (IS_ERR(wh_dentry))
21484 + sb = dentry->d_sb;
21485 + a->bdst = au_dbtop(dentry);
21486 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21487 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21488 + a->bsrc = au_ibtop(inode);
21489 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21490 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21491 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21492 + if (!h_src_dentry) {
21493 + a->bsrc = au_dbtop(src_dentry);
21494 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21495 + AuDebugOn(!h_src_dentry);
21496 + } else if (IS_ERR(h_src_dentry)) {
21497 + err = PTR_ERR(h_src_dentry);
21502 + * aufs doesn't touch the credential so
21503 + * security_dentry_create_files_as() is unnecessary.
21505 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21506 + if (a->bdst < a->bsrc
21507 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21508 + err = au_cpup_or_link(src_dentry, dentry, a);
21510 + delegated = NULL;
21511 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21512 + &a->h_path, &delegated);
21513 + if (unlikely(err == -EWOULDBLOCK)) {
21514 + pr_warn("cannot retry for NFSv4 delegation"
21515 + " for an internal link\n");
21519 + dput(h_src_dentry);
21522 + * copyup src_dentry to the branch we process,
21523 + * and then link(2) to it.
21525 + dput(h_src_dentry);
21526 + if (a->bdst < a->bsrc
21527 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21528 + au_unpin(&a->pin);
21529 + di_write_unlock(a->parent);
21530 + err = au_cpup_before_link(src_dentry, a);
21531 + di_write_lock_parent(a->parent);
21533 + err = au_pin(&a->pin, dentry, a->bdst,
21535 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21536 + if (unlikely(err))
21540 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21542 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21543 + delegated = NULL;
21544 + err = vfsub_link(h_src_dentry,
21545 + au_pinned_h_dir(&a->pin),
21546 + &a->h_path, &delegated);
21547 + if (unlikely(err == -EWOULDBLOCK)) {
21548 + pr_warn("cannot retry"
21549 + " for NFSv4 delegation"
21550 + " for an internal link\n");
21556 + if (unlikely(err))
21560 + a->h_path.dentry = wh_dentry;
21561 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21563 + if (unlikely(err))
21567 + au_dir_ts(dir, a->bdst);
21568 + inode_inc_iversion(dir);
21569 + inc_nlink(inode);
21570 + inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
21571 + d_instantiate(dentry, au_igrab(inode));
21572 + if (d_unhashed(a->h_path.dentry))
21573 + /* some filesystem calls d_drop() */
21575 + /* some filesystems consume an inode even hardlink */
21576 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21577 + goto out_unpin; /* success */
21580 + /* no delegation since it is just created */
21581 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21582 + /*delegated*/NULL, /*force*/0);
21583 + if (unlikely(rerr)) {
21584 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21587 + au_dtime_revert(&dt);
21589 + au_unpin(&a->pin);
21593 + di_write_unlock(a->parent);
21594 + dput(a->src_parent);
21596 + if (unlikely(err)) {
21597 + au_update_dbtop(dentry);
21600 + aufs_read_and_write_unlock2(dentry, src_dentry);
21608 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
21609 + struct dentry *dentry, umode_t mode)
21612 + aufs_bindex_t bindex;
21613 + unsigned char diropq;
21614 + struct path h_path;
21615 + struct dentry *wh_dentry, *parent, *opq_dentry;
21616 + struct inode *h_inode;
21617 + struct super_block *sb;
21619 + struct au_pin pin;
21620 + struct au_dtime dt;
21621 + } *a; /* reduce the stack usage */
21622 + struct au_wr_dir_args wr_dir_args = {
21623 + .force_btgt = -1,
21624 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21630 + a = kmalloc(sizeof(*a), GFP_NOFS);
21631 + if (unlikely(!a))
21634 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21635 + if (unlikely(err))
21637 + err = au_d_may_add(dentry);
21638 + if (unlikely(err))
21641 + parent = dentry->d_parent; /* dir inode is locked */
21642 + di_write_lock_parent(parent);
21643 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21644 + &a->pin, &wr_dir_args);
21645 + err = PTR_ERR(wh_dentry);
21646 + if (IS_ERR(wh_dentry))
21649 + sb = dentry->d_sb;
21650 + bindex = au_dbtop(dentry);
21651 + h_path.dentry = au_h_dptr(dentry, bindex);
21652 + h_path.mnt = au_sbr_mnt(sb, bindex);
21653 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21654 + if (unlikely(err))
21657 + /* make the dir opaque */
21659 + h_inode = d_inode(h_path.dentry);
21661 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21662 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21663 + opq_dentry = au_diropq_create(dentry, bindex);
21664 + inode_unlock(h_inode);
21665 + err = PTR_ERR(opq_dentry);
21666 + if (IS_ERR(opq_dentry))
21668 + dput(opq_dentry);
21672 + err = epilog(dir, bindex, wh_dentry, dentry);
21675 + goto out_unpin; /* success */
21680 + AuLabel(revert opq);
21681 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21682 + rerr = au_diropq_remove(dentry, bindex);
21683 + inode_unlock(h_inode);
21685 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21686 + dentry, err, rerr);
21692 + AuLabel(revert dir);
21693 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21695 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21696 + dentry, err, rerr);
21699 + au_dtime_revert(&a->dt);
21701 + au_unpin(&a->pin);
21704 + di_write_unlock(parent);
21706 + if (unlikely(err)) {
21707 + au_update_dbtop(dentry);
21710 + aufs_read_unlock(dentry, AuLock_DW);
21716 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21717 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21718 +++ linux/fs/aufs/i_op.c 2023-10-31 09:31:04.199880750 +0100
21720 +// SPDX-License-Identifier: GPL-2.0
21722 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21724 + * This program is free software; you can redistribute it and/or modify
21725 + * it under the terms of the GNU General Public License as published by
21726 + * the Free Software Foundation; either version 2 of the License, or
21727 + * (at your option) any later version.
21729 + * This program is distributed in the hope that it will be useful,
21730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21732 + * GNU General Public License for more details.
21734 + * You should have received a copy of the GNU General Public License
21735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21739 + * inode operations (except add/del/rename)
21742 +#include <linux/device_cgroup.h>
21743 +#include <linux/filelock.h>
21744 +#include <linux/fs_stack.h>
21745 +#include <linux/iversion.h>
21746 +#include <linux/security.h>
21749 +static int h_permission(struct inode *h_inode, int mask,
21750 + struct path *h_path, int brperm)
21753 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21754 + struct mnt_idmap *h_idmap;
21757 + if (write_mask && IS_IMMUTABLE(h_inode))
21761 + if (((mask & MAY_EXEC)
21762 + && S_ISREG(h_inode->i_mode)
21763 + && (path_noexec(h_path)
21764 + || !(h_inode->i_mode & 0111))))
21768 + * - skip the lower fs test in the case of write to ro branch.
21769 + * - nfs dir permission write check is optimized, but a policy for
21770 + * link/rename requires a real check.
21771 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21772 + * in this case, generic_permission() returns -EOPNOTSUPP.
21774 + h_idmap = mnt_idmap(h_path->mnt);
21775 + if ((write_mask && !au_br_writable(brperm))
21776 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21777 + && write_mask && !(mask & MAY_READ))
21778 + || !h_inode->i_op->permission) {
21779 + /* AuLabel(generic_permission); */
21780 + /* AuDbg("get_inode_acl %ps\n",
21781 + h_inode->i_op->get_inode_acl); */
21782 + err = generic_permission(h_idmap, h_inode, mask);
21783 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21784 + err = h_inode->i_op->permission(h_idmap, h_inode,
21788 + /* AuLabel(h_inode->permission); */
21789 + err = h_inode->i_op->permission(h_idmap, h_inode, mask);
21794 + err = devcgroup_inode_permission(h_inode, mask);
21796 + err = security_inode_permission(h_inode, mask);
21802 +static int aufs_permission(struct mnt_idmap *idmap, struct inode *inode,
21806 + aufs_bindex_t bindex, bbot;
21807 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21808 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21809 + struct inode *h_inode;
21810 + struct super_block *sb;
21811 + struct au_branch *br;
21813 + /* todo: support rcu-walk? */
21814 + if (mask & MAY_NOT_BLOCK)
21817 + sb = inode->i_sb;
21818 + si_read_lock(sb, AuLock_FLUSH);
21819 + ii_read_lock_child(inode);
21820 +#if 0 /* reserved for future use */
21822 + * This test may be rather 'too much' since the test is essentially done
21823 + * in the aufs_lookup(). Theoretically it is possible that the inode
21824 + * generation doesn't match to the superblock's here. But it isn't a
21825 + * big deal I suppose.
21827 + err = au_iigen_test(inode, au_sigen(sb));
21828 + if (unlikely(err))
21834 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21835 + err = au_busy_or_stale();
21836 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21837 + if (unlikely(!h_inode
21838 + || (h_inode->i_mode & S_IFMT)
21839 + != (inode->i_mode & S_IFMT)))
21843 + bindex = au_ibtop(inode);
21844 + br = au_sbr(sb, bindex);
21845 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21848 + && !special_file(h_inode->i_mode)) {
21849 + /* test whether the upper writable branch exists */
21851 + for (; bindex >= 0; bindex--)
21852 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21860 + /* non-write to dir */
21862 + bbot = au_ibbot(inode);
21863 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21864 + h_inode = au_h_iptr(inode, bindex);
21866 + err = au_busy_or_stale();
21867 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21870 + br = au_sbr(sb, bindex);
21871 + err = h_permission(h_inode, mask, &br->br_path,
21877 + ii_read_unlock(inode);
21878 + si_read_unlock(sb);
21882 +/* ---------------------------------------------------------------------- */
21884 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21885 + unsigned int flags)
21887 + struct dentry *ret, *parent;
21888 + struct inode *inode;
21889 + struct super_block *sb;
21890 + int err, npositive;
21894 + /* todo: support rcu-walk? */
21895 + ret = ERR_PTR(-ECHILD);
21896 + if (flags & LOOKUP_RCU)
21899 + ret = ERR_PTR(-ENAMETOOLONG);
21900 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21904 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21905 + ret = ERR_PTR(err);
21906 + if (unlikely(err))
21909 + err = au_di_init(dentry);
21910 + ret = ERR_PTR(err);
21911 + if (unlikely(err))
21915 + npositive = 0; /* suppress a warning */
21916 + parent = dentry->d_parent; /* dir inode is locked */
21917 + di_read_lock_parent(parent, AuLock_IR);
21918 + err = au_alive_dir(parent);
21920 + err = au_digen_test(parent, au_sigen(sb));
21922 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21923 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21924 + AuLkup_ALLOW_NEG);
21927 + di_read_unlock(parent, AuLock_IR);
21928 + ret = ERR_PTR(err);
21929 + if (unlikely(err < 0))
21933 + inode = au_new_inode(dentry, /*must_new*/0);
21934 + if (IS_ERR(inode)) {
21935 + ret = (void *)inode;
21942 + atomic_inc(&inode->i_count);
21943 + ret = d_splice_alias(inode, dentry);
21944 +#if 0 /* reserved for future use */
21945 + if (unlikely(d_need_lookup(dentry))) {
21946 + spin_lock(&dentry->d_lock);
21947 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21948 + spin_unlock(&dentry->d_lock);
21952 + if (!IS_ERR(ret)) {
21954 + if (ret && ret != dentry)
21955 + ii_write_unlock(inode);
21957 + ii_write_unlock(inode);
21964 + di_write_unlock(dentry);
21966 + si_read_unlock(sb);
21971 +/* ---------------------------------------------------------------------- */
21974 + * very dirty and complicated aufs ->atomic_open().
21975 + * aufs_atomic_open()
21976 + * + au_aopen_or_create()
21978 + * + vfsub_atomic_open()
21979 + * + branch fs ->atomic_open()
21980 + * may call the actual 'open' for h_file
21981 + * + inc br_nfiles only if opened
21982 + * + au_aopen_no_open() or au_aopen_do_open()
21984 + * au_aopen_do_open()
21985 + * + finish_open()
21986 + * + au_do_aopen()
21987 + * + au_do_open() the body of all 'open'
21988 + * + au_do_open_nondir()
21989 + * set the passed h_file
21991 + * au_aopen_no_open()
21992 + * + finish_no_open()
21995 +struct aopen_node {
21996 + struct hlist_bl_node hblist;
21997 + struct file *file, *h_file;
22000 +static int au_do_aopen(struct inode *inode, struct file *file)
22002 + struct hlist_bl_head *aopen;
22003 + struct hlist_bl_node *pos;
22004 + struct aopen_node *node;
22005 + struct au_do_open_args args = {
22007 + .open = au_do_open_nondir
22010 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22011 + hlist_bl_lock(aopen);
22012 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22013 + if (node->file == file) {
22014 + args.h_file = node->h_file;
22017 + hlist_bl_unlock(aopen);
22018 + /* AuDebugOn(!args.h_file); */
22020 + return au_do_open(file, &args);
22023 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22024 + struct aopen_node *aopen_node)
22027 + struct hlist_bl_head *aopen;
22030 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22031 + au_hbl_add(&aopen_node->hblist, aopen);
22032 + err = finish_open(file, dentry, au_do_aopen);
22033 + au_hbl_del(&aopen_node->hblist, aopen);
22034 + /* AuDbgFile(file); */
22035 + AuDbg("%pd%s%s\n", dentry,
22036 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22037 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22043 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22049 + err = finish_no_open(file, dentry);
22055 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22056 + struct file *file, unsigned int open_flag,
22057 + umode_t create_mode)
22059 + int err, did_open;
22060 + unsigned int lkup_flags;
22061 + aufs_bindex_t bindex;
22062 + struct super_block *sb;
22063 + struct dentry *parent, *d;
22064 + struct vfsub_aopen_args args = {
22065 + .open_flag = open_flag,
22066 + .create_mode = create_mode
22068 + struct aopen_node aopen_node = {
22073 + AuDbg("open_flag 0%o\n", open_flag);
22074 + AuDbgDentry(dentry);
22077 + if (!au_di(dentry)) {
22078 + lkup_flags = LOOKUP_OPEN;
22079 + if (open_flag & O_CREAT)
22080 + lkup_flags |= LOOKUP_CREATE;
22081 + d = aufs_lookup(dir, dentry, lkup_flags);
22083 + err = PTR_ERR(d);
22088 + * obsoleted dentry found.
22089 + * another error will be returned later.
22095 + AuDbgDentry(dentry);
22098 + if (d_is_positive(dentry)
22099 + || d_unhashed(dentry)
22100 + || d_unlinked(dentry)
22101 + || !(open_flag & O_CREAT)) {
22102 + err = au_aopen_no_open(file, dentry);
22103 + goto out; /* success */
22106 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22107 + if (unlikely(err))
22110 + sb = dentry->d_sb;
22111 + parent = dentry->d_parent; /* dir is locked */
22112 + di_write_lock_parent(parent);
22113 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22114 + if (unlikely(err < 0))
22117 + AuDbgDentry(dentry);
22118 + if (d_is_positive(dentry)) {
22119 + err = au_aopen_no_open(file, dentry);
22120 + goto out_parent; /* success */
22123 + args.file = alloc_empty_file(file->f_flags, current_cred());
22124 + err = PTR_ERR(args.file);
22125 + if (IS_ERR(args.file))
22128 + bindex = au_dbtop(dentry);
22129 + err = au_aopen_or_create(dir, dentry, &args);
22131 + AuDbgFile(args.file);
22132 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22133 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22136 + args.file = NULL;
22138 + di_write_unlock(parent);
22139 + di_write_unlock(dentry);
22140 + if (unlikely(err < 0)) {
22147 + err = au_aopen_no_open(file, dentry);
22149 + aopen_node.h_file = args.file;
22150 + err = au_aopen_do_open(file, dentry, &aopen_node);
22152 + if (unlikely(err < 0)) {
22156 + au_lcnt_dec(&args.br->br_nfiles);
22158 + goto out_sb; /* success */
22161 + di_write_unlock(parent);
22162 + di_write_unlock(dentry);
22164 + si_read_unlock(sb);
22172 +/* ---------------------------------------------------------------------- */
22174 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22175 + const unsigned char add_entry, aufs_bindex_t bcpup,
22176 + aufs_bindex_t btop)
22179 + struct dentry *h_parent;
22180 + struct inode *h_dir;
22183 + IMustLock(d_inode(parent));
22185 + di_write_lock_parent(parent);
22188 + if (!au_h_dptr(parent, bcpup)) {
22189 + if (btop > bcpup)
22190 + err = au_cpup_dirs(dentry, bcpup);
22191 + else if (btop < bcpup)
22192 + err = au_cpdown_dirs(dentry, bcpup);
22196 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22197 + h_parent = au_h_dptr(parent, bcpup);
22198 + h_dir = d_inode(h_parent);
22199 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22200 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22201 + /* todo: no unlock here */
22202 + inode_unlock_shared(h_dir);
22204 + AuDbg("bcpup %d\n", bcpup);
22206 + if (d_really_is_negative(dentry))
22207 + au_set_h_dptr(dentry, btop, NULL);
22208 + au_update_dbrange(dentry, /*do_put_zero*/0);
22213 + di_write_unlock(parent);
22215 + err = bcpup; /* success */
22222 + * decide the branch and the parent dir where we will create a new entry.
22223 + * returns new bindex or an error.
22224 + * copyup the parent dir if needed.
22226 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22227 + struct au_wr_dir_args *args)
22230 + unsigned int flags;
22231 + aufs_bindex_t bcpup, btop, src_btop;
22232 + const unsigned char add_entry
22233 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22234 + | au_ftest_wrdir(args->flags, TMPFILE);
22235 + struct super_block *sb;
22236 + struct dentry *parent;
22237 + struct au_sbinfo *sbinfo;
22239 + sb = dentry->d_sb;
22240 + sbinfo = au_sbi(sb);
22241 + parent = dget_parent(dentry);
22242 + btop = au_dbtop(dentry);
22244 + if (args->force_btgt < 0) {
22245 + if (src_dentry) {
22246 + src_btop = au_dbtop(src_dentry);
22247 + if (src_btop < btop)
22248 + bcpup = src_btop;
22249 + } else if (add_entry) {
22251 + if (au_ftest_wrdir(args->flags, ISDIR))
22252 + au_fset_wbr(flags, DIR);
22253 + err = AuWbrCreate(sbinfo, dentry, flags);
22257 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22259 + err = AuWbrCopyup(sbinfo, dentry);
22261 + if (!IS_ROOT(dentry)) {
22262 + di_read_lock_parent(parent, !AuLock_IR);
22263 + err = AuWbrCopyup(sbinfo, dentry);
22264 + di_read_unlock(parent, !AuLock_IR);
22266 + err = AuWbrCopyup(sbinfo, dentry);
22269 + if (unlikely(err < 0))
22273 + bcpup = args->force_btgt;
22274 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22277 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22279 + if (bcpup == btop)
22280 + goto out; /* success */
22282 + /* copyup the new parent into the branch we process */
22283 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22285 + if (d_really_is_negative(dentry)) {
22286 + au_set_h_dptr(dentry, btop, NULL);
22287 + au_set_dbtop(dentry, bcpup);
22288 + au_set_dbbot(dentry, bcpup);
22290 + AuDebugOn(add_entry
22291 + && !au_ftest_wrdir(args->flags, TMPFILE)
22292 + && !au_h_dptr(dentry, bcpup));
22300 +/* ---------------------------------------------------------------------- */
22302 +void au_pin_hdir_unlock(struct au_pin *p)
22305 + au_hn_inode_unlock(p->hdir);
22308 +int au_pin_hdir_lock(struct au_pin *p)
22316 + /* even if an error happens later, keep this lock */
22317 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22320 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22325 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22326 + p->h_parent, p->br);
22332 +int au_pin_hdir_relock(struct au_pin *p)
22335 + struct inode *h_i;
22336 + struct dentry *h_d[] = {
22341 + err = au_pin_hdir_lock(p);
22342 + if (unlikely(err))
22345 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22348 + if (d_is_positive(h_d[i])) {
22349 + h_i = d_inode(h_d[i]);
22350 + err = !h_i->i_nlink;
22358 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22360 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22363 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22366 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22367 + p->lsc_hi, 0, NULL, _RET_IP_);
22368 + au_pin_hdir_set_owner(p, current);
22372 +void au_pin_hdir_release(struct au_pin *p)
22375 + au_pin_hdir_set_owner(p, p->task);
22376 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22380 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22382 + if (pin && pin->parent)
22383 + return au_h_dptr(pin->parent, pin->bindex);
22387 +void au_unpin(struct au_pin *p)
22390 + au_pin_hdir_unlock(p);
22391 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22392 + vfsub_mnt_drop_write(p->h_mnt);
22396 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22397 + di_read_unlock(p->parent, AuLock_IR);
22398 + iput(p->hdir->hi_inode);
22400 + p->parent = NULL;
22403 + /* do not clear p->task */
22406 +int au_do_pin(struct au_pin *p)
22409 + struct super_block *sb;
22410 + struct inode *h_dir;
22413 + sb = p->dentry->d_sb;
22414 + p->br = au_sbr(sb, p->bindex);
22415 + if (IS_ROOT(p->dentry)) {
22416 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22417 + p->h_mnt = au_br_mnt(p->br);
22418 + err = vfsub_mnt_want_write(p->h_mnt);
22419 + if (unlikely(err)) {
22420 + au_fclr_pin(p->flags, MNT_WRITE);
22427 + p->h_dentry = NULL;
22428 + if (p->bindex <= au_dbbot(p->dentry))
22429 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22431 + p->parent = dget_parent(p->dentry);
22432 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22433 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22436 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22437 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22439 + h_dir = p->hdir->hi_inode;
22443 + * if DI_LOCKED is not set, then p->parent may be different
22444 + * and h_parent can be NULL.
22446 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22448 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22449 + di_read_unlock(p->parent, AuLock_IR);
22451 + p->parent = NULL;
22455 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22456 + p->h_mnt = au_br_mnt(p->br);
22457 + err = vfsub_mnt_want_write(p->h_mnt);
22458 + if (unlikely(err)) {
22459 + au_fclr_pin(p->flags, MNT_WRITE);
22460 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22461 + di_read_unlock(p->parent, AuLock_IR);
22463 + p->parent = NULL;
22469 + err = au_pin_hdir_lock(p);
22471 + goto out; /* success */
22476 + pr_err("err %d\n", err);
22477 + err = au_busy_or_stale();
22482 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22483 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22484 + unsigned int udba, unsigned char flags)
22486 + p->dentry = dentry;
22488 + p->lsc_di = lsc_di;
22489 + p->lsc_hi = lsc_hi;
22490 + p->flags = flags;
22491 + p->bindex = bindex;
22493 + p->parent = NULL;
22497 + p->h_dentry = NULL;
22498 + p->h_parent = NULL;
22500 + p->task = current;
22503 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22504 + unsigned int udba, unsigned char flags)
22506 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22508 + return au_do_pin(pin);
22511 +/* ---------------------------------------------------------------------- */
22514 + * ->setattr() and ->getattr() are called in various cases.
22515 + * chmod, stat: dentry is revalidated.
22516 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22518 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22520 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22521 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22524 + struct dentry *parent;
22527 + if (au_digen_test(dentry, sigen)) {
22528 + parent = dget_parent(dentry);
22529 + di_read_lock_parent(parent, AuLock_IR);
22530 + err = au_refresh_dentry(dentry, parent);
22531 + di_read_unlock(parent, AuLock_IR);
22539 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22540 + struct au_icpup_args *a)
22544 + aufs_bindex_t btop, ibtop;
22545 + struct dentry *hi_wh, *parent;
22546 + struct inode *inode;
22547 + struct au_wr_dir_args wr_dir_args = {
22548 + .force_btgt = -1,
22552 + if (d_is_dir(dentry))
22553 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22554 + /* plink or hi_wh() case */
22555 + btop = au_dbtop(dentry);
22556 + inode = d_inode(dentry);
22557 + ibtop = au_ibtop(inode);
22558 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22559 + wr_dir_args.force_btgt = ibtop;
22560 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22561 + if (unlikely(err < 0))
22565 + au_fset_icpup(a->flags, DID_CPUP);
22568 + a->pin_flags = AuPin_MNT_WRITE;
22570 + if (!IS_ROOT(dentry)) {
22571 + au_fset_pin(a->pin_flags, DI_LOCKED);
22572 + parent = dget_parent(dentry);
22573 + di_write_lock_parent(parent);
22576 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22577 + if (unlikely(err))
22581 + a->h_path.dentry = au_h_dptr(dentry, btop);
22582 + a->h_inode = d_inode(a->h_path.dentry);
22583 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22584 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22585 + if (ia->ia_size < i_size_read(a->h_inode))
22586 + sz = ia->ia_size;
22587 + inode_unlock_shared(a->h_inode);
22591 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22592 + hi_wh = au_hi_wh(inode, a->btgt);
22594 + struct au_cp_generic cpg = {
22595 + .dentry = dentry,
22601 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22602 + if (unlikely(err))
22604 + hi_wh = au_hi_wh(inode, a->btgt);
22605 + /* todo: revalidate hi_wh? */
22610 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22611 + di_downgrade_lock(parent, AuLock_IR);
22615 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22616 + goto out; /* success */
22618 + if (!d_unhashed(dentry)) {
22619 + struct au_cp_generic cpg = {
22620 + .dentry = dentry,
22625 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22627 + err = au_sio_cpup_simple(&cpg);
22629 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22630 + } else if (!hi_wh)
22631 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22633 + a->h_path.dentry = hi_wh; /* do not dget here */
22636 + a->h_inode = d_inode(a->h_path.dentry);
22638 + goto out; /* success */
22639 + au_unpin(&a->pin);
22642 + di_write_unlock(parent);
22647 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22651 +static int aufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
22652 + struct iattr *ia)
22655 + struct inode *inode, *delegated;
22656 + struct super_block *sb;
22657 + struct file *file;
22658 + struct au_icpup_args *a;
22659 + struct mnt_idmap *h_idmap;
22661 + inode = d_inode(dentry);
22662 + IMustLock(inode);
22664 + err = setattr_prepare(idmap, dentry, ia);
22665 + if (unlikely(err))
22669 + a = kzalloc(sizeof(*a), GFP_NOFS);
22670 + if (unlikely(!a))
22673 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22674 + ia->ia_valid &= ~ATTR_MODE;
22677 + sb = dentry->d_sb;
22678 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22679 + if (unlikely(err))
22682 + if (ia->ia_valid & ATTR_FILE) {
22683 + /* currently ftruncate(2) only */
22684 + AuDebugOn(!d_is_reg(dentry));
22685 + file = ia->ia_file;
22686 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22688 + if (unlikely(err))
22690 + ia->ia_file = au_hf_top(file);
22691 + a->udba = AuOpt_UDBA_NONE;
22693 + /* fchmod() doesn't pass ia_file */
22694 + a->udba = au_opt_udba(sb);
22695 + di_write_lock_child(dentry);
22696 + /* no d_unlinked(), to set UDBA_NONE for root */
22697 + if (d_unhashed(dentry))
22698 + a->udba = AuOpt_UDBA_NONE;
22699 + if (a->udba != AuOpt_UDBA_NONE) {
22700 + AuDebugOn(IS_ROOT(dentry));
22701 + err = au_reval_for_attr(dentry, au_sigen(sb));
22702 + if (unlikely(err))
22707 + err = au_pin_and_icpup(dentry, ia, a);
22708 + if (unlikely(err < 0))
22710 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22711 + ia->ia_file = NULL;
22712 + ia->ia_valid &= ~ATTR_FILE;
22715 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22716 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22717 + == (ATTR_MODE | ATTR_CTIME)) {
22718 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22719 + if (unlikely(err))
22721 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22722 + && (ia->ia_valid & ATTR_CTIME)) {
22723 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22724 + if (unlikely(err))
22728 + if (ia->ia_valid & ATTR_SIZE) {
22731 + if (ia->ia_size < i_size_read(inode))
22733 + truncate_setsize(inode, ia->ia_size);
22736 + if (ia->ia_valid & ATTR_FILE)
22738 + inode_unlock(a->h_inode);
22739 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22740 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22742 + delegated = NULL;
22744 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22746 + err = break_deleg_wait(&delegated);
22754 + * regardless aufs 'acl' option setting.
22755 + * why don't all acl-aware fs call this func from their ->setattr()?
22757 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22758 + h_idmap = mnt_idmap(a->h_path.mnt);
22759 + err = vfsub_acl_chmod(h_idmap, a->h_path.dentry, ia->ia_mode);
22762 + au_cpup_attr_changeable(inode);
22765 + inode_unlock(a->h_inode);
22766 + au_unpin(&a->pin);
22767 + if (unlikely(err))
22768 + au_update_dbtop(dentry);
22770 + di_write_unlock(dentry);
22772 + fi_write_unlock(file);
22773 + ia->ia_file = file;
22774 + ia->ia_valid |= ATTR_FILE;
22777 + si_read_unlock(sb);
22785 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22786 +static int au_h_path_to_set_attr(struct dentry *dentry,
22787 + struct au_icpup_args *a, struct path *h_path)
22790 + struct super_block *sb;
22792 + sb = dentry->d_sb;
22793 + a->udba = au_opt_udba(sb);
22794 + /* no d_unlinked(), to set UDBA_NONE for root */
22795 + if (d_unhashed(dentry))
22796 + a->udba = AuOpt_UDBA_NONE;
22797 + if (a->udba != AuOpt_UDBA_NONE) {
22798 + AuDebugOn(IS_ROOT(dentry));
22799 + err = au_reval_for_attr(dentry, au_sigen(sb));
22800 + if (unlikely(err))
22803 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22804 + if (unlikely(err < 0))
22807 + h_path->dentry = a->h_path.dentry;
22808 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22814 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22815 + struct au_sxattr *arg)
22818 + struct path h_path;
22819 + struct super_block *sb;
22820 + struct au_icpup_args *a;
22821 + struct inode *h_inode;
22822 + struct mnt_idmap *h_idmap;
22824 + IMustLock(inode);
22827 + a = kzalloc(sizeof(*a), GFP_NOFS);
22828 + if (unlikely(!a))
22831 + sb = dentry->d_sb;
22832 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22833 + if (unlikely(err))
22836 + h_path.dentry = NULL; /* silence gcc */
22837 + di_write_lock_child(dentry);
22838 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22839 + if (unlikely(err))
22841 + h_idmap = mnt_idmap(h_path.mnt);
22843 + inode_unlock(a->h_inode);
22844 + switch (arg->type) {
22845 + case AU_XATTR_SET:
22846 + AuDebugOn(d_is_negative(h_path.dentry));
22847 + err = vfsub_setxattr(h_idmap, h_path.dentry,
22848 + arg->u.set.name, arg->u.set.value,
22849 + arg->u.set.size, arg->u.set.flags);
22852 + err = -EOPNOTSUPP;
22853 + h_inode = d_inode(h_path.dentry);
22854 + if (h_inode->i_op->set_acl) {
22855 + /* this will call posix_acl_update_mode */
22856 + err = h_inode->i_op->set_acl(h_idmap, h_path.dentry,
22857 + arg->u.acl_set.acl,
22858 + arg->u.acl_set.type);
22863 + au_cpup_attr_timesizes(inode);
22865 + au_unpin(&a->pin);
22866 + if (unlikely(err))
22867 + au_update_dbtop(dentry);
22870 + di_write_unlock(dentry);
22871 + si_read_unlock(sb);
22880 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22881 + unsigned int nlink)
22885 + inode->i_mode = st->mode;
22886 + /* don't i_[ug]id_write() here */
22887 + inode->i_uid = st->uid;
22888 + inode->i_gid = st->gid;
22889 + inode->i_atime = st->atime;
22890 + inode->i_mtime = st->mtime;
22891 + inode_set_ctime_to_ts(inode, st->ctime);
22893 + au_cpup_attr_nlink(inode, /*force*/0);
22894 + if (S_ISDIR(inode->i_mode)) {
22895 + n = inode->i_nlink;
22898 + smp_mb(); /* for i_nlink */
22899 + /* 0 can happen */
22900 + set_nlink(inode, n);
22903 + spin_lock(&inode->i_lock);
22904 + inode->i_blocks = st->blocks;
22905 + i_size_write(inode, st->size);
22906 + spin_unlock(&inode->i_lock);
22910 + * common routine for aufs_getattr() and au_getxattr().
22911 + * returns zero or negative (an error).
22912 + * @dentry will be read-locked in success.
22914 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22915 + struct path *h_path, int locked)
22918 + unsigned int mnt_flags, sigen;
22919 + unsigned char udba_none;
22920 + aufs_bindex_t bindex;
22921 + struct super_block *sb, *h_sb;
22923 + h_path->mnt = NULL;
22924 + h_path->dentry = NULL;
22927 + sb = dentry->d_sb;
22928 + mnt_flags = au_mntflags(sb);
22929 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22931 + if (unlikely(locked))
22932 + goto body; /* skip locking dinfo */
22934 + /* support fstat(2) */
22935 + if (!d_unlinked(dentry) && !udba_none) {
22936 + sigen = au_sigen(sb);
22937 + err = au_digen_test(dentry, sigen);
22939 + di_read_lock_child(dentry, AuLock_IR);
22940 + err = au_dbrange_test(dentry);
22941 + if (unlikely(err)) {
22942 + di_read_unlock(dentry, AuLock_IR);
22946 + AuDebugOn(IS_ROOT(dentry));
22947 + di_write_lock_child(dentry);
22948 + err = au_dbrange_test(dentry);
22950 + err = au_reval_for_attr(dentry, sigen);
22952 + di_downgrade_lock(dentry, AuLock_IR);
22954 + di_write_unlock(dentry);
22959 + di_read_lock_child(dentry, AuLock_IR);
22963 + inode = d_inode(dentry);
22964 + if (unlikely(!inode))
22967 + bindex = au_ibtop(inode);
22968 + h_path->mnt = au_sbr_mnt(sb, bindex);
22969 + h_sb = h_path->mnt->mnt_sb;
22971 + && !au_test_fs_bad_iattr(h_sb)
22973 + goto out; /* success */
22975 + if (au_dbtop(dentry) == bindex)
22976 + h_path->dentry = au_h_dptr(dentry, bindex);
22977 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22978 + h_path->dentry = au_plink_lkup(inode, bindex);
22979 + if (IS_ERR(h_path->dentry))
22980 + /* pretending success */
22981 + h_path->dentry = NULL;
22983 + dput(h_path->dentry);
22990 +static int aufs_getattr(struct mnt_idmap *idmap, const struct path *path,
22991 + struct kstat *st, u32 request, unsigned int query)
22994 + unsigned char positive;
22995 + struct path h_path;
22996 + struct dentry *dentry;
22997 + struct inode *inode;
22998 + struct super_block *sb;
23000 + dentry = path->dentry;
23001 + inode = d_inode(dentry);
23002 + sb = dentry->d_sb;
23003 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23004 + if (unlikely(err))
23006 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23008 + if (unlikely(err))
23010 + if (unlikely(!h_path.dentry))
23011 + /* illegally overlapped or something */
23012 + goto out_fill; /* pretending success */
23014 + positive = d_is_positive(h_path.dentry);
23016 + /* no vfsub version */
23017 + err = vfs_getattr(&h_path, st, request, query);
23020 + au_refresh_iattr(inode, st,
23021 + d_inode(h_path.dentry)->i_nlink);
23022 + goto out_fill; /* success */
23028 + generic_fillattr(idmap, request, inode, st);
23030 + di_read_unlock(dentry, AuLock_IR);
23032 + si_read_unlock(sb);
23038 +/* ---------------------------------------------------------------------- */
23040 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23041 + struct delayed_call *done)
23044 + struct dentry *h_dentry;
23045 + struct inode *h_inode;
23047 + aufs_bindex_t bindex;
23049 + ret = NULL; /* suppress a warning */
23054 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23055 + if (unlikely(err))
23058 + err = au_d_hashed_positive(dentry);
23059 + if (unlikely(err))
23063 + inode = d_inode(dentry);
23064 + bindex = au_ibtop(inode);
23065 + h_inode = au_h_iptr(inode, bindex);
23066 + if (unlikely(!h_inode->i_op->get_link))
23071 + if (au_dbtop(dentry) <= bindex) {
23072 + h_dentry = au_h_dptr(dentry, bindex);
23077 + h_dentry = d_find_any_alias(h_inode);
23078 + if (IS_ERR(h_dentry)) {
23079 + err = PTR_ERR(h_dentry);
23083 + if (unlikely(!h_dentry))
23087 + AuDbg("%ps\n", h_inode->i_op->get_link);
23088 + AuDbgDentry(h_dentry);
23089 + ret = vfs_get_link(h_dentry, done);
23092 + err = PTR_ERR(ret);
23095 + aufs_read_unlock(dentry, AuLock_IR);
23097 + if (unlikely(err))
23098 + ret = ERR_PTR(err);
23099 + AuTraceErrPtr(ret);
23103 +/* ---------------------------------------------------------------------- */
23105 +static int au_is_special(struct inode *inode)
23107 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23110 +static int aufs_update_time(struct inode *inode, int flags)
23113 + aufs_bindex_t bindex;
23114 + struct super_block *sb;
23115 + struct inode *h_inode;
23116 + struct vfsmount *h_mnt;
23118 + sb = inode->i_sb;
23119 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23120 + "unexpected s_flags 0x%lx", sb->s_flags);
23122 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23124 + si_read_lock(sb, AuLock_FLUSH);
23125 + ii_write_lock_child(inode);
23128 + bindex = au_ibtop(inode);
23129 + h_inode = au_h_iptr(inode, bindex);
23130 + if (!au_test_ro(sb, bindex, inode)) {
23131 + h_mnt = au_sbr_mnt(sb, bindex);
23132 + err = vfsub_mnt_want_write(h_mnt);
23134 + err = vfsub_update_time(h_inode, flags);
23135 + vfsub_mnt_drop_write(h_mnt);
23137 + } else if (au_is_special(h_inode)) {
23139 + * Never copy-up here.
23140 + * These special files may already be opened and used for
23141 + * communicating. If we copied it up, then the communication
23142 + * would be corrupted.
23144 + AuWarn1("timestamps for i%lu are ignored "
23145 + "since it is on readonly branch (hi%lu).\n",
23146 + inode->i_ino, h_inode->i_ino);
23147 + } else if (flags & ~S_ATIME) {
23149 + AuIOErr1("unexpected flags 0x%x\n", flags);
23154 + au_cpup_attr_timesizes(inode);
23155 + ii_write_unlock(inode);
23156 + si_read_unlock(sb);
23159 + if (!err && (flags & S_VERSION))
23160 + inode_inc_iversion(inode);
23165 +/* ---------------------------------------------------------------------- */
23167 +/* no getattr version will be set by module.c:aufs_init() */
23168 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23170 + [AuIop_SYMLINK] = {
23171 + .permission = aufs_permission,
23172 +#ifdef CONFIG_FS_POSIX_ACL
23173 + .get_inode_acl = aufs_get_inode_acl,
23174 + .get_acl = aufs_get_acl,
23175 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23178 + .setattr = aufs_setattr,
23179 + .getattr = aufs_getattr,
23181 +#ifdef CONFIG_AUFS_XATTR
23182 + .listxattr = aufs_listxattr,
23185 + .get_link = aufs_get_link
23187 + /* .update_time = aufs_update_time */
23190 + .create = aufs_create,
23191 + .lookup = aufs_lookup,
23192 + .link = aufs_link,
23193 + .unlink = aufs_unlink,
23194 + .symlink = aufs_symlink,
23195 + .mkdir = aufs_mkdir,
23196 + .rmdir = aufs_rmdir,
23197 + .mknod = aufs_mknod,
23198 + .rename = aufs_rename,
23200 + .permission = aufs_permission,
23201 +#ifdef CONFIG_FS_POSIX_ACL
23202 + .get_inode_acl = aufs_get_inode_acl,
23203 + .get_acl = aufs_get_acl,
23204 + .set_acl = aufs_set_acl,
23207 + .setattr = aufs_setattr,
23208 + .getattr = aufs_getattr,
23210 +#ifdef CONFIG_AUFS_XATTR
23211 + .listxattr = aufs_listxattr,
23214 + .update_time = aufs_update_time,
23215 + .atomic_open = aufs_atomic_open,
23216 + .tmpfile = aufs_tmpfile
23218 + [AuIop_OTHER] = {
23219 + .permission = aufs_permission,
23220 +#ifdef CONFIG_FS_POSIX_ACL
23221 + .get_inode_acl = aufs_get_inode_acl,
23222 + .get_acl = aufs_get_acl,
23223 + .set_acl = aufs_set_acl,
23226 + .setattr = aufs_setattr,
23227 + .getattr = aufs_getattr,
23229 +#ifdef CONFIG_AUFS_XATTR
23230 + .listxattr = aufs_listxattr,
23233 + .update_time = aufs_update_time
23236 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23237 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23238 +++ linux/fs/aufs/i_op_del.c 2023-10-31 09:31:04.199880750 +0100
23240 +// SPDX-License-Identifier: GPL-2.0
23242 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23244 + * This program is free software; you can redistribute it and/or modify
23245 + * it under the terms of the GNU General Public License as published by
23246 + * the Free Software Foundation; either version 2 of the License, or
23247 + * (at your option) any later version.
23249 + * This program is distributed in the hope that it will be useful,
23250 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23251 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23252 + * GNU General Public License for more details.
23254 + * You should have received a copy of the GNU General Public License
23255 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23259 + * inode operations (del entry)
23262 +#include <linux/iversion.h>
23266 + * decide if a new whiteout for @dentry is necessary or not.
23267 + * when it is necessary, prepare the parent dir for the upper branch whose
23268 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23269 + * be done by caller.
23271 + * 0: wh is unnecessary
23272 + * plus: wh is necessary
23275 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23277 + int need_wh, err;
23278 + aufs_bindex_t btop;
23279 + struct super_block *sb;
23281 + sb = dentry->d_sb;
23282 + btop = au_dbtop(dentry);
23283 + if (*bcpup < 0) {
23285 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23286 + err = AuWbrCopyup(au_sbi(sb), dentry);
23288 + if (unlikely(err < 0))
23292 + AuDebugOn(btop < *bcpup
23293 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23294 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23296 + if (*bcpup != btop) {
23297 + err = au_cpup_dirs(dentry, *bcpup);
23298 + if (unlikely(err))
23302 + struct au_dinfo *dinfo, *tmp;
23304 + need_wh = -ENOMEM;
23305 + dinfo = au_di(dentry);
23306 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23308 + au_di_cp(tmp, dinfo);
23309 + au_di_swap(tmp, dinfo);
23310 + /* returns the number of positive dentries */
23311 + need_wh = au_lkup_dentry(dentry, btop + 1,
23312 + /* AuLkup_IGNORE_PERM */ 0);
23313 + au_di_swap(tmp, dinfo);
23314 + au_rw_write_unlock(&tmp->di_rwsem);
23318 + AuDbg("need_wh %d\n", need_wh);
23326 + * simple tests for the del-entry operations.
23327 + * following the checks in vfs, plus the parent-child relationship.
23329 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23330 + struct dentry *h_parent, int isdir)
23334 + struct dentry *h_dentry, *h_latest;
23335 + struct inode *h_inode;
23336 + struct path h_ppath;
23337 + struct super_block *sb;
23338 + struct au_branch *br;
23339 + struct mnt_idmap *h_idmap;
23341 + h_dentry = au_h_dptr(dentry, bindex);
23342 + if (d_really_is_positive(dentry)) {
23344 + if (unlikely(d_is_negative(h_dentry)))
23346 + h_inode = d_inode(h_dentry);
23347 + if (unlikely(!h_inode->i_nlink))
23350 + h_mode = h_inode->i_mode;
23353 + if (unlikely(S_ISDIR(h_mode)))
23355 + } else if (unlikely(!S_ISDIR(h_mode))) {
23360 + /* rename(2) case */
23362 + if (unlikely(d_is_positive(h_dentry)))
23367 + /* expected parent dir is locked */
23368 + if (unlikely(h_parent != h_dentry->d_parent))
23373 + * rmdir a dir may break the consistency on some filesystem.
23374 + * let's try heavy test.
23377 + sb = dentry->d_sb;
23378 + br = au_sbr(sb, bindex);
23379 + h_idmap = au_br_idmap(br);
23380 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23381 + && au_test_h_perm(h_idmap, d_inode(h_parent),
23382 + MAY_EXEC | MAY_WRITE)))
23385 + h_ppath.dentry = h_parent;
23386 + h_ppath.mnt = au_br_mnt(br);
23387 + h_latest = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
23389 + if (IS_ERR(h_latest))
23391 + if (h_latest == h_dentry)
23400 + * decide the branch where we operate for @dentry. the branch index will be set
23401 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23402 + * dir for reverting.
23403 + * when a new whiteout is necessary, create it.
23405 +static struct dentry*
23406 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23407 + struct au_dtime *dt, struct au_pin *pin)
23409 + struct dentry *wh_dentry;
23410 + struct super_block *sb;
23411 + struct path h_path;
23412 + int err, need_wh;
23413 + unsigned int udba;
23414 + aufs_bindex_t bcpup;
23416 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23417 + wh_dentry = ERR_PTR(need_wh);
23418 + if (unlikely(need_wh < 0))
23421 + sb = dentry->d_sb;
23422 + udba = au_opt_udba(sb);
23424 + err = au_pin(pin, dentry, bcpup, udba,
23425 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23426 + wh_dentry = ERR_PTR(err);
23427 + if (unlikely(err))
23430 + h_path.dentry = au_pinned_h_parent(pin);
23431 + if (udba != AuOpt_UDBA_NONE
23432 + && au_dbtop(dentry) == bcpup) {
23433 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23434 + wh_dentry = ERR_PTR(err);
23435 + if (unlikely(err))
23439 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23440 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23441 + wh_dentry = NULL;
23443 + goto out; /* success, no need to create whiteout */
23445 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23446 + if (IS_ERR(wh_dentry))
23449 + /* returns with the parent is locked and wh_dentry is dget-ed */
23450 + goto out; /* success */
23455 + return wh_dentry;
23459 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23460 + * in order to be revertible and save time for removing many child whiteouts
23462 + * returns 1 when there are too many child whiteout and caller should remove
23463 + * them asynchronously. returns 0 when the number of children is enough small to
23464 + * remove now or the branch fs is a remote fs.
23465 + * otherwise return an error.
23467 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23468 + struct au_nhash *whlist, struct inode *dir)
23470 + int rmdir_later, err, dirwh;
23471 + struct dentry *h_dentry;
23472 + struct super_block *sb;
23473 + struct inode *inode;
23475 + sb = dentry->d_sb;
23476 + SiMustAnyLock(sb);
23477 + h_dentry = au_h_dptr(dentry, bindex);
23478 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23479 + if (unlikely(err))
23482 + /* stop monitoring */
23483 + inode = d_inode(dentry);
23484 + au_hn_free(au_hi(inode, bindex));
23486 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23487 + dirwh = au_sbi(sb)->si_dirwh;
23488 + rmdir_later = (dirwh <= 1);
23489 + if (!rmdir_later)
23490 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23493 + return rmdir_later;
23496 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23497 + if (unlikely(err)) {
23498 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23499 + h_dentry, bindex, err);
23509 + * final procedure for deleting a entry.
23510 + * maintain dentry and iattr.
23512 +static void epilog(struct inode *dir, struct dentry *dentry,
23513 + aufs_bindex_t bindex)
23515 + struct inode *inode;
23517 + inode = d_inode(dentry);
23519 + inode_set_ctime_to_ts(inode, inode_get_ctime(dir));
23521 + au_dir_ts(dir, bindex);
23522 + inode_inc_iversion(dir);
23526 + * when an error happened, remove the created whiteout and revert everything.
23528 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23529 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23530 + struct dentry *dentry, struct au_dtime *dt)
23533 + struct path h_path = {
23534 + .dentry = wh_dentry,
23535 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23538 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23540 + au_set_dbwh(dentry, bwh);
23541 + au_dtime_revert(dt);
23545 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23549 +/* ---------------------------------------------------------------------- */
23551 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23554 + aufs_bindex_t bwh, bindex, btop;
23555 + struct inode *inode, *h_dir, *delegated, *h_inode;
23556 + struct dentry *parent, *wh_dentry;
23557 + /* to reduce stack size */
23559 + struct au_dtime dt;
23560 + struct au_pin pin;
23561 + struct path h_path;
23567 + a = kmalloc(sizeof(*a), GFP_NOFS);
23568 + if (unlikely(!a))
23571 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23572 + if (unlikely(err))
23574 + err = au_d_hashed_positive(dentry);
23575 + if (unlikely(err))
23577 + inode = d_inode(dentry);
23578 + IMustLock(inode);
23580 + if (unlikely(d_is_dir(dentry)))
23581 + goto out_unlock; /* possible? */
23583 + btop = au_dbtop(dentry);
23584 + bwh = au_dbwh(dentry);
23586 + parent = dentry->d_parent; /* dir inode is locked */
23587 + di_write_lock_parent(parent);
23588 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23590 + err = PTR_ERR(wh_dentry);
23591 + if (IS_ERR(wh_dentry))
23594 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23595 + a->h_path.dentry = au_h_dptr(dentry, btop);
23596 + dget(a->h_path.dentry);
23597 + if (bindex == btop) {
23598 + h_dir = au_pinned_h_dir(&a->pin);
23599 + delegated = NULL;
23600 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23601 + if (unlikely(err == -EWOULDBLOCK)) {
23602 + pr_warn("cannot retry for NFSv4 delegation"
23603 + " for an internal unlink\n");
23607 + /* dir inode is locked */
23608 + h_dir = d_inode(wh_dentry->d_parent);
23609 + IMustLock(h_dir);
23614 + vfsub_drop_nlink(inode);
23615 + epilog(dir, dentry, bindex);
23617 + /* update target timestamps */
23618 + if (bindex == btop) {
23619 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23621 + h_inode = d_inode(a->h_path.dentry);
23622 + inode_set_ctime_to_ts(inode, inode_get_ctime(h_inode));
23624 + /* todo: this timestamp may be reverted later */
23625 + inode_set_ctime_to_ts(inode, inode_get_ctime(h_dir));
23626 + goto out_unpin; /* success */
23633 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23640 + au_unpin(&a->pin);
23642 + dput(a->h_path.dentry);
23644 + di_write_unlock(parent);
23646 + aufs_read_unlock(dentry, AuLock_DW);
23653 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23655 + int err, rmdir_later;
23656 + aufs_bindex_t bwh, bindex, btop;
23657 + struct inode *inode;
23658 + struct dentry *parent, *wh_dentry, *h_dentry;
23659 + struct au_whtmp_rmdir *args;
23660 + /* to reduce stack size */
23662 + struct au_dtime dt;
23663 + struct au_pin pin;
23669 + a = kmalloc(sizeof(*a), GFP_NOFS);
23670 + if (unlikely(!a))
23673 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23674 + if (unlikely(err))
23676 + err = au_alive_dir(dentry);
23677 + if (unlikely(err))
23679 + inode = d_inode(dentry);
23680 + IMustLock(inode);
23682 + if (unlikely(!d_is_dir(dentry)))
23683 + goto out_unlock; /* possible? */
23686 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23687 + if (unlikely(!args))
23690 + parent = dentry->d_parent; /* dir inode is locked */
23691 + di_write_lock_parent(parent);
23692 + err = au_test_empty(dentry, &args->whlist);
23693 + if (unlikely(err))
23696 + btop = au_dbtop(dentry);
23697 + bwh = au_dbwh(dentry);
23699 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23701 + err = PTR_ERR(wh_dentry);
23702 + if (IS_ERR(wh_dentry))
23705 + h_dentry = au_h_dptr(dentry, btop);
23708 + if (bindex == btop) {
23709 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23711 + rmdir_later = err;
23715 + /* stop monitoring */
23716 + au_hn_free(au_hi(inode, btop));
23718 + /* dir inode is locked */
23719 + IMustLock(d_inode(wh_dentry->d_parent));
23724 + vfsub_dead_dir(inode);
23725 + au_set_dbdiropq(dentry, -1);
23726 + epilog(dir, dentry, bindex);
23728 + if (rmdir_later) {
23729 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23733 + goto out_unpin; /* success */
23741 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23748 + au_unpin(&a->pin);
23752 + di_write_unlock(parent);
23754 + au_whtmp_rmdir_free(args);
23756 + aufs_read_unlock(dentry, AuLock_DW);
23763 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23764 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23765 +++ linux/fs/aufs/i_op_ren.c 2023-10-31 09:31:04.199880750 +0100
23767 +// SPDX-License-Identifier: GPL-2.0
23769 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23771 + * This program is free software; you can redistribute it and/or modify
23772 + * it under the terms of the GNU General Public License as published by
23773 + * the Free Software Foundation; either version 2 of the License, or
23774 + * (at your option) any later version.
23776 + * This program is distributed in the hope that it will be useful,
23777 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23778 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23779 + * GNU General Public License for more details.
23781 + * You should have received a copy of the GNU General Public License
23782 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23786 + * inode operation (rename entry)
23787 + * todo: this is crazy monster
23790 +#include <linux/iversion.h>
23793 +enum { AuSRC, AuDST, AuSrcDst };
23794 +enum { AuPARENT, AuCHILD, AuParentChild };
23796 +#define AuRen_ISDIR_SRC 1
23797 +#define AuRen_ISDIR_DST (1 << 1)
23798 +#define AuRen_ISSAMEDIR (1 << 2)
23799 +#define AuRen_WHSRC (1 << 3)
23800 +#define AuRen_WHDST (1 << 4)
23801 +#define AuRen_MNT_WRITE (1 << 5)
23802 +#define AuRen_DT_DSTDIR (1 << 6)
23803 +#define AuRen_DIROPQ_SRC (1 << 7)
23804 +#define AuRen_DIROPQ_DST (1 << 8)
23805 +#define AuRen_DIRREN (1 << 9)
23806 +#define AuRen_DROPPED_SRC (1 << 10)
23807 +#define AuRen_DROPPED_DST (1 << 11)
23808 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23809 +#define au_fset_ren(flags, name) \
23810 + do { (flags) |= AuRen_##name; } while (0)
23811 +#define au_fclr_ren(flags, name) \
23812 + do { (flags) &= ~AuRen_##name; } while (0)
23814 +#ifndef CONFIG_AUFS_DIRREN
23815 +#undef AuRen_DIRREN
23816 +#define AuRen_DIRREN 0
23819 +struct au_ren_args {
23821 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23823 + struct inode *dir, *inode;
23824 + struct au_hinode *hdir, *hinode;
23825 + struct au_dtime dt[AuParentChild];
23826 + aufs_bindex_t btop, bdiropq;
23829 +#define src_dentry sd[AuSRC].dentry
23830 +#define src_dir sd[AuSRC].dir
23831 +#define src_inode sd[AuSRC].inode
23832 +#define src_h_dentry sd[AuSRC].h_dentry
23833 +#define src_parent sd[AuSRC].parent
23834 +#define src_h_parent sd[AuSRC].h_parent
23835 +#define src_wh_dentry sd[AuSRC].wh_dentry
23836 +#define src_hdir sd[AuSRC].hdir
23837 +#define src_hinode sd[AuSRC].hinode
23838 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23839 +#define src_dt sd[AuSRC].dt
23840 +#define src_btop sd[AuSRC].btop
23841 +#define src_bdiropq sd[AuSRC].bdiropq
23843 +#define dst_dentry sd[AuDST].dentry
23844 +#define dst_dir sd[AuDST].dir
23845 +#define dst_inode sd[AuDST].inode
23846 +#define dst_h_dentry sd[AuDST].h_dentry
23847 +#define dst_parent sd[AuDST].parent
23848 +#define dst_h_parent sd[AuDST].h_parent
23849 +#define dst_wh_dentry sd[AuDST].wh_dentry
23850 +#define dst_hdir sd[AuDST].hdir
23851 +#define dst_hinode sd[AuDST].hinode
23852 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23853 +#define dst_dt sd[AuDST].dt
23854 +#define dst_btop sd[AuDST].btop
23855 +#define dst_bdiropq sd[AuDST].bdiropq
23857 + struct dentry *h_trap;
23858 + struct au_branch *br;
23859 + struct path h_path;
23860 + struct au_nhash whlist;
23861 + aufs_bindex_t btgt, src_bwh;
23864 + unsigned short auren_flags;
23865 + unsigned char flags; /* syscall parameter */
23866 + unsigned char exchange;
23869 + struct au_whtmp_rmdir *thargs;
23870 + struct dentry *h_dst;
23871 + struct au_hinode *h_root;
23874 +/* ---------------------------------------------------------------------- */
23877 + * functions for reverting.
23878 + * when an error happened in a single rename systemcall, we should revert
23879 + * everything as if nothing happened.
23880 + * we don't need to revert the copied-up/down the parent dir since they are
23884 +#define RevertFailure(fmt, ...) do { \
23885 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23886 + ##__VA_ARGS__, err, rerr); \
23890 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23893 + struct dentry *d;
23894 +#define src_or_dst(member) a->sd[idx].member
23896 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23897 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23898 + rerr = au_diropq_remove(d, a->btgt);
23899 + au_hn_inode_unlock(src_or_dst(hinode));
23900 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23902 + RevertFailure("remove diropq %pd", d);
23904 +#undef src_or_dst_
23907 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23909 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23910 + au_ren_do_rev_diropq(err, a, AuSRC);
23911 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23912 + au_ren_do_rev_diropq(err, a, AuDST);
23915 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23918 + struct inode *delegated;
23919 + struct path h_ppath = {
23920 + .dentry = a->src_h_parent,
23921 + .mnt = a->h_path.mnt
23924 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23925 + rerr = PTR_ERR(a->h_path.dentry);
23926 + if (IS_ERR(a->h_path.dentry)) {
23927 + RevertFailure("lkup one %pd", a->src_dentry);
23931 + delegated = NULL;
23932 + rerr = vfsub_rename(a->dst_h_dir,
23933 + au_h_dptr(a->src_dentry, a->btgt),
23934 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23935 + if (unlikely(rerr == -EWOULDBLOCK)) {
23936 + pr_warn("cannot retry for NFSv4 delegation"
23937 + " for an internal rename\n");
23940 + d_drop(a->h_path.dentry);
23941 + dput(a->h_path.dentry);
23942 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23944 + RevertFailure("rename %pd", a->src_dentry);
23947 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23950 + struct inode *delegated;
23951 + struct path h_ppath = {
23952 + .dentry = a->dst_h_parent,
23953 + .mnt = a->h_path.mnt
23956 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23957 + rerr = PTR_ERR(a->h_path.dentry);
23958 + if (IS_ERR(a->h_path.dentry)) {
23959 + RevertFailure("lkup one %pd", a->dst_dentry);
23962 + if (d_is_positive(a->h_path.dentry)) {
23963 + d_drop(a->h_path.dentry);
23964 + dput(a->h_path.dentry);
23968 + delegated = NULL;
23969 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23970 + &delegated, a->flags);
23971 + if (unlikely(rerr == -EWOULDBLOCK)) {
23972 + pr_warn("cannot retry for NFSv4 delegation"
23973 + " for an internal rename\n");
23976 + d_drop(a->h_path.dentry);
23977 + dput(a->h_path.dentry);
23979 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23981 + RevertFailure("rename %pd", a->h_dst);
23984 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23988 + a->h_path.dentry = a->src_wh_dentry;
23989 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23990 + au_set_dbwh(a->src_dentry, a->src_bwh);
23992 + RevertFailure("unlink %pd", a->src_wh_dentry);
23994 +#undef RevertFailure
23996 +/* ---------------------------------------------------------------------- */
23999 + * when we have to copyup the renaming entry, do it with the rename-target name
24000 + * in order to minimize the cost (the later actual rename is unnecessary).
24001 + * otherwise rename it on the target branch.
24003 +static int au_ren_or_cpup(struct au_ren_args *a)
24006 + struct dentry *d;
24007 + struct inode *delegated;
24009 + d = a->src_dentry;
24010 + if (au_dbtop(d) == a->btgt) {
24011 + a->h_path.dentry = a->dst_h_dentry;
24012 + AuDebugOn(au_dbtop(d) != a->btgt);
24013 + delegated = NULL;
24014 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24015 + a->dst_h_dir, &a->h_path, &delegated,
24017 + if (unlikely(err == -EWOULDBLOCK)) {
24018 + pr_warn("cannot retry for NFSv4 delegation"
24019 + " for an internal rename\n");
24025 + if (!err && a->h_dst)
24026 + /* it will be set to dinfo later */
24032 +/* cf. aufs_rmdir() */
24033 +static int au_ren_del_whtmp(struct au_ren_args *a)
24036 + struct inode *dir;
24038 + dir = a->dst_dir;
24039 + SiMustAnyLock(dir->i_sb);
24040 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24041 + au_sbi(dir->i_sb)->si_dirwh)
24042 + || au_test_fs_remote(a->h_dst->d_sb)) {
24043 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24044 + if (unlikely(err))
24045 + pr_warn("failed removing whtmp dir %pd (%d), "
24046 + "ignored.\n", a->h_dst, err);
24048 + au_nhash_wh_free(&a->thargs->whlist);
24049 + a->thargs->whlist = a->whlist;
24050 + a->whlist.nh_num = 0;
24051 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24053 + a->thargs = NULL;
24059 +/* make it 'opaque' dir. */
24060 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24063 + struct dentry *d, *diropq;
24064 +#define src_or_dst(member) a->sd[idx].member
24067 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24068 + src_or_dst(bdiropq) = au_dbdiropq(d);
24069 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24070 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24071 + diropq = au_diropq_create(d, a->btgt);
24072 + au_hn_inode_unlock(src_or_dst(hinode));
24073 + if (IS_ERR(diropq))
24074 + err = PTR_ERR(diropq);
24078 +#undef src_or_dst_
24082 +static int au_ren_diropq(struct au_ren_args *a)
24085 + unsigned char always;
24086 + struct dentry *d;
24089 + d = a->dst_dentry; /* already renamed on the branch */
24090 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24091 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24092 + && !au_ftest_ren(a->auren_flags, DIRREN)
24093 + && a->btgt != au_dbdiropq(a->src_dentry)
24094 + && (a->dst_wh_dentry
24095 + || a->btgt <= au_dbdiropq(d)
24096 + /* hide the lower to keep xino */
24097 + /* the lowers may not be a dir, but we hide them anyway */
24098 + || a->btgt < au_dbbot(d)
24101 + err = au_ren_do_diropq(a, AuSRC);
24102 + if (unlikely(err))
24104 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24106 + if (!a->exchange)
24107 + goto out; /* success */
24109 + d = a->src_dentry; /* already renamed on the branch */
24110 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24111 + && a->btgt != au_dbdiropq(a->dst_dentry)
24112 + && (a->btgt < au_dbdiropq(d)
24113 + || a->btgt < au_dbbot(d)
24115 + AuDbgDentry(a->src_dentry);
24116 + AuDbgDentry(a->dst_dentry);
24117 + err = au_ren_do_diropq(a, AuDST);
24118 + if (unlikely(err))
24119 + goto out_rev_src;
24120 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24122 + goto out; /* success */
24125 + AuDbg("err %d, reverting src\n", err);
24126 + au_ren_rev_diropq(err, a);
24131 +static int do_rename(struct au_ren_args *a)
24134 + struct dentry *d, *h_d;
24135 + struct inode *h_inode;
24137 + if (!a->exchange) {
24138 + /* prepare workqueue args for asynchronous rmdir */
24139 + h_d = a->dst_h_dentry;
24140 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24141 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24142 + && d_is_positive(h_d)) {
24144 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24146 + if (unlikely(!a->thargs))
24148 + a->h_dst = dget(h_d);
24151 + /* create whiteout for src_dentry */
24152 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24153 + a->src_bwh = au_dbwh(a->src_dentry);
24154 + AuDebugOn(a->src_bwh >= 0);
24155 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24156 + a->src_h_parent);
24157 + err = PTR_ERR(a->src_wh_dentry);
24158 + if (IS_ERR(a->src_wh_dentry))
24162 + /* lookup whiteout for dentry */
24163 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24164 + h_d = au_wh_lkup(a->dst_h_parent,
24165 + &a->dst_dentry->d_name, a->br);
24166 + err = PTR_ERR(h_d);
24169 + if (d_is_negative(h_d))
24172 + a->dst_wh_dentry = h_d;
24175 + /* rename dentry to tmpwh */
24177 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24178 + if (unlikely(err))
24181 + d = a->dst_dentry;
24182 + au_set_h_dptr(d, a->btgt, NULL);
24183 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24184 + if (unlikely(err))
24186 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24190 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24191 +#if 0 /* debugging */
24192 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24193 + && d_is_positive(a->dst_h_dentry)
24194 + && a->src_btop != a->btgt);
24197 + /* rename by vfs_rename or cpup */
24198 + err = au_ren_or_cpup(a);
24199 + if (unlikely(err))
24200 + /* leave the copied-up one */
24203 + /* make dir opaque */
24204 + err = au_ren_diropq(a);
24205 + if (unlikely(err))
24208 + /* update target timestamps */
24209 + if (a->exchange) {
24210 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24211 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24212 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24213 + h_inode = d_inode(a->h_path.dentry);
24214 + inode_set_ctime_to_ts(a->dst_inode, inode_get_ctime(h_inode));
24216 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24217 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24218 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24219 + h_inode = d_inode(a->h_path.dentry);
24220 + inode_set_ctime_to_ts(a->src_inode, inode_get_ctime(h_inode));
24222 + if (!a->exchange) {
24223 + /* remove whiteout for dentry */
24224 + if (a->dst_wh_dentry) {
24225 + a->h_path.dentry = a->dst_wh_dentry;
24226 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24228 + if (unlikely(err))
24232 + /* remove whtmp */
24234 + au_ren_del_whtmp(a); /* ignore this error */
24236 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24239 + goto out_success;
24242 + au_ren_rev_diropq(err, a);
24244 + au_ren_rev_rename(err, a);
24248 + au_ren_rev_whtmp(err, a);
24250 + dput(a->dst_wh_dentry);
24251 + a->dst_wh_dentry = NULL;
24253 + if (a->src_wh_dentry)
24254 + au_ren_rev_whsrc(err, a);
24256 + dput(a->src_wh_dentry);
24257 + dput(a->dst_wh_dentry);
24261 + au_whtmp_rmdir_free(a->thargs);
24262 + a->thargs = NULL;
24268 +/* ---------------------------------------------------------------------- */
24271 + * test if @dentry dir can be rename destination or not.
24272 + * success means, it is a logically empty dir.
24274 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24276 + return au_test_empty(dentry, whlist);
24280 + * test if @a->src_dentry dir can be rename source or not.
24281 + * if it can, return 0.
24283 + * - it is a logically empty dir.
24284 + * - or, it exists on writable branch and has no children including whiteouts
24285 + * on the lower branch unless DIRREN is on.
24287 +static int may_rename_srcdir(struct au_ren_args *a)
24290 + unsigned int rdhash;
24291 + aufs_bindex_t btop, btgt;
24292 + struct dentry *dentry;
24293 + struct super_block *sb;
24294 + struct au_sbinfo *sbinfo;
24296 + dentry = a->src_dentry;
24297 + sb = dentry->d_sb;
24298 + sbinfo = au_sbi(sb);
24299 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24300 + au_fset_ren(a->auren_flags, DIRREN);
24303 + btop = au_dbtop(dentry);
24304 + if (btop != btgt) {
24305 + struct au_nhash whlist;
24307 + SiMustAnyLock(sb);
24308 + rdhash = sbinfo->si_rdhash;
24310 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24312 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24313 + if (unlikely(err))
24315 + err = au_test_empty(dentry, &whlist);
24316 + au_nhash_wh_free(&whlist);
24320 + if (btop == au_dbtaildir(dentry))
24321 + return 0; /* success */
24323 + err = au_test_empty_lower(dentry);
24326 + if (err == -ENOTEMPTY) {
24327 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24330 + AuWarn1("renaming dir who has child(ren) on multiple "
24331 + "branches, is not supported\n");
24338 +/* side effect: sets whlist and h_dentry */
24339 +static int au_ren_may_dir(struct au_ren_args *a)
24342 + unsigned int rdhash;
24343 + struct dentry *d;
24345 + d = a->dst_dentry;
24346 + SiMustAnyLock(d->d_sb);
24349 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24350 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24352 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24353 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24354 + if (unlikely(err))
24357 + if (!a->exchange) {
24358 + au_set_dbtop(d, a->dst_btop);
24359 + err = may_rename_dstdir(d, &a->whlist);
24360 + au_set_dbtop(d, a->btgt);
24362 + err = may_rename_srcdir(a);
24364 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24365 + if (unlikely(err))
24368 + d = a->src_dentry;
24369 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24370 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24371 + err = may_rename_srcdir(a);
24372 + if (unlikely(err)) {
24373 + au_nhash_wh_free(&a->whlist);
24374 + a->whlist.nh_num = 0;
24381 +/* ---------------------------------------------------------------------- */
24384 + * simple tests for rename.
24385 + * following the checks in vfs, plus the parent-child relationship.
24387 +static int au_may_ren(struct au_ren_args *a)
24390 + struct inode *h_inode;
24392 + if (a->src_btop == a->btgt) {
24393 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24394 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24395 + if (unlikely(err))
24398 + if (unlikely(a->src_h_dentry == a->h_trap))
24403 + if (a->dst_btop != a->btgt)
24406 + err = -ENOTEMPTY;
24407 + if (unlikely(a->dst_h_dentry == a->h_trap))
24411 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24412 + if (d_really_is_negative(a->dst_dentry)) {
24413 + if (d_is_negative(a->dst_h_dentry))
24414 + err = au_may_add(a->dst_dentry, a->btgt,
24415 + a->dst_h_parent, isdir);
24417 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24419 + h_inode = d_inode(a->dst_h_dentry);
24420 + if (h_inode->i_nlink)
24421 + err = au_may_del(a->dst_dentry, a->btgt,
24422 + a->dst_h_parent, isdir);
24426 + if (unlikely(err == -ENOENT || err == -EEXIST))
24432 +/* ---------------------------------------------------------------------- */
24437 + * - src_dir and dir by lock_rename()
24438 + * - inode if exists
24441 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24443 + * + di_write_lock2_child()
24444 + * + di_write_lock_child()
24445 + * + ii_write_lock_child()
24446 + * + di_write_lock_child2()
24447 + * + ii_write_lock_child2()
24448 + * + src_parent and parent
24449 + * + di_write_lock_parent()
24450 + * + ii_write_lock_parent()
24451 + * + di_write_lock_parent2()
24452 + * + ii_write_lock_parent2()
24453 + * + lower src_dir and dir by vfsub_lock_rename()
24454 + * + verify the every relationships between child and parent. if any
24455 + * of them failed, unlock all and return -EBUSY.
24457 +static void au_ren_unlock(struct au_ren_args *a)
24459 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24460 + a->dst_h_parent, a->dst_hdir);
24461 + if (au_ftest_ren(a->auren_flags, DIRREN)
24463 + au_hn_inode_unlock(a->h_root);
24464 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24465 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24468 +static int au_ren_lock(struct au_ren_args *a)
24471 + unsigned int udba;
24474 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24475 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24476 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24477 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24479 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24480 + if (unlikely(err))
24482 + au_fset_ren(a->auren_flags, MNT_WRITE);
24483 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24484 + struct dentry *root;
24485 + struct inode *dir;
24488 + * sbinfo is already locked, so this ii_read_lock is
24489 + * unnecessary. but our debugging feature checks it.
24491 + root = a->src_inode->i_sb->s_root;
24492 + if (root != a->src_parent && root != a->dst_parent) {
24493 + dir = d_inode(root);
24494 + ii_read_lock_parent3(dir);
24495 + a->h_root = au_hi(dir, a->btgt);
24496 + ii_read_unlock(dir);
24497 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24500 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24501 + a->dst_h_parent, a->dst_hdir);
24502 + udba = au_opt_udba(a->src_dentry->d_sb);
24503 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24504 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24505 + err = au_busy_or_stale();
24506 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24507 + err = au_h_verify(a->src_h_dentry, udba,
24508 + d_inode(a->src_h_parent), a->src_h_parent,
24510 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24511 + err = au_h_verify(a->dst_h_dentry, udba,
24512 + d_inode(a->dst_h_parent), a->dst_h_parent,
24515 + goto out; /* success */
24517 + err = au_busy_or_stale();
24518 + au_ren_unlock(a);
24524 +/* ---------------------------------------------------------------------- */
24526 +static void au_ren_refresh_dir(struct au_ren_args *a)
24528 + struct inode *dir;
24530 + dir = a->dst_dir;
24531 + inode_inc_iversion(dir);
24532 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24533 + /* is this updating defined in POSIX? */
24534 + au_cpup_attr_timesizes(a->src_inode);
24535 + au_cpup_attr_nlink(dir, /*force*/1);
24537 + au_dir_ts(dir, a->btgt);
24539 + if (a->exchange) {
24540 + dir = a->src_dir;
24541 + inode_inc_iversion(dir);
24542 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24543 + /* is this updating defined in POSIX? */
24544 + au_cpup_attr_timesizes(a->dst_inode);
24545 + au_cpup_attr_nlink(dir, /*force*/1);
24547 + au_dir_ts(dir, a->btgt);
24550 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24553 + dir = a->src_dir;
24554 + inode_inc_iversion(dir);
24555 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24556 + au_cpup_attr_nlink(dir, /*force*/1);
24557 + au_dir_ts(dir, a->btgt);
24560 +static void au_ren_refresh(struct au_ren_args *a)
24562 + aufs_bindex_t bbot, bindex;
24563 + struct dentry *d, *h_d;
24564 + struct inode *i, *h_i;
24565 + struct super_block *sb;
24567 + d = a->dst_dentry;
24570 + /* already dget-ed by au_ren_or_cpup() */
24571 + au_set_h_dptr(d, a->btgt, a->h_dst);
24573 + i = a->dst_inode;
24575 + if (!a->exchange) {
24576 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24577 + vfsub_drop_nlink(i);
24579 + vfsub_dead_dir(i);
24580 + au_cpup_attr_timesizes(i);
24582 + au_update_dbrange(d, /*do_put_zero*/1);
24584 + au_cpup_attr_nlink(i, /*force*/1);
24587 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24588 + au_set_h_dptr(d, bindex, NULL);
24589 + bbot = au_dbbot(d);
24590 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24591 + au_set_h_dptr(d, bindex, NULL);
24592 + au_update_dbrange(d, /*do_put_zero*/0);
24596 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24597 + d_drop(a->src_dentry);
24598 + if (au_ftest_ren(a->auren_flags, DIRREN))
24599 + au_set_dbwh(a->src_dentry, -1);
24603 + d = a->src_dentry;
24604 + au_set_dbwh(d, -1);
24605 + bbot = au_dbbot(d);
24606 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24607 + h_d = au_h_dptr(d, bindex);
24609 + au_set_h_dptr(d, bindex, NULL);
24611 + au_set_dbbot(d, a->btgt);
24614 + i = a->src_inode;
24615 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24616 + return; /* success */
24618 + bbot = au_ibbot(i);
24619 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24620 + h_i = au_h_iptr(i, bindex);
24622 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24623 + /* ignore this error */
24624 + au_set_h_iptr(i, bindex, NULL, 0);
24627 + au_set_ibbot(i, a->btgt);
24630 +/* ---------------------------------------------------------------------- */
24632 +/* mainly for link(2) and rename(2) */
24633 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24635 + aufs_bindex_t bdiropq, bwh;
24636 + struct dentry *parent;
24637 + struct au_branch *br;
24639 + parent = dentry->d_parent;
24640 + IMustLock(d_inode(parent)); /* dir is locked */
24642 + bdiropq = au_dbdiropq(parent);
24643 + bwh = au_dbwh(dentry);
24644 + br = au_sbr(dentry->d_sb, btgt);
24645 + if (au_br_rdonly(br)
24646 + || (0 <= bdiropq && bdiropq < btgt)
24647 + || (0 <= bwh && bwh < btgt))
24650 + AuDbg("btgt %d\n", btgt);
24654 +/* sets src_btop, dst_btop and btgt */
24655 +static int au_ren_wbr(struct au_ren_args *a)
24658 + struct au_wr_dir_args wr_dir_args = {
24659 + /* .force_btgt = -1, */
24660 + .flags = AuWrDir_ADD_ENTRY
24663 + a->src_btop = au_dbtop(a->src_dentry);
24664 + a->dst_btop = au_dbtop(a->dst_dentry);
24665 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24666 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24667 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24668 + wr_dir_args.force_btgt = a->src_btop;
24669 + if (a->dst_inode && a->dst_btop < a->src_btop)
24670 + wr_dir_args.force_btgt = a->dst_btop;
24671 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24672 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24675 + au_update_dbtop(a->dst_dentry);
24680 +static void au_ren_dt(struct au_ren_args *a)
24682 + a->h_path.dentry = a->src_h_parent;
24683 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24684 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24685 + a->h_path.dentry = a->dst_h_parent;
24686 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24689 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24690 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24694 + a->h_path.dentry = a->src_h_dentry;
24695 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24696 + if (d_is_positive(a->dst_h_dentry)) {
24697 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24698 + a->h_path.dentry = a->dst_h_dentry;
24699 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24703 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24705 + struct dentry *h_d;
24706 + struct inode *h_inode;
24708 + au_dtime_revert(a->src_dt + AuPARENT);
24709 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24710 + au_dtime_revert(a->dst_dt + AuPARENT);
24712 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24713 + h_d = a->src_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->src_dt + AuCHILD);
24717 + inode_unlock(h_inode);
24719 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24720 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24721 + h_inode = d_inode(h_d);
24722 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24723 + au_dtime_revert(a->dst_dt + AuCHILD);
24724 + inode_unlock(h_inode);
24729 +/* ---------------------------------------------------------------------- */
24731 +int aufs_rename(struct mnt_idmap *idmap,
24732 + struct inode *_src_dir, struct dentry *_src_dentry,
24733 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24734 + unsigned int _flags)
24736 + int err, lock_flags;
24738 + /* reduce stack space */
24739 + struct au_ren_args *a;
24740 + struct au_pin pin;
24742 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24743 + IMustLock(_src_dir);
24744 + IMustLock(_dst_dir);
24747 + if (unlikely(_flags & RENAME_WHITEOUT))
24751 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24752 + a = kzalloc(sizeof(*a), GFP_NOFS);
24753 + if (unlikely(!a))
24756 + a->flags = _flags;
24757 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24758 + && RENAME_EXCHANGE > U8_MAX);
24759 + a->exchange = _flags & RENAME_EXCHANGE;
24760 + a->src_dir = _src_dir;
24761 + a->src_dentry = _src_dentry;
24762 + a->src_inode = NULL;
24763 + if (d_really_is_positive(a->src_dentry))
24764 + a->src_inode = d_inode(a->src_dentry);
24765 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24766 + a->dst_dir = _dst_dir;
24767 + a->dst_dentry = _dst_dentry;
24768 + a->dst_inode = NULL;
24769 + if (d_really_is_positive(a->dst_dentry))
24770 + a->dst_inode = d_inode(a->dst_dentry);
24771 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24772 + if (a->dst_inode) {
24774 + * if EXCHANGE && src is non-dir && dst is dir,
24775 + * dst is not locked.
24777 + /* IMustLock(a->dst_inode); */
24778 + au_igrab(a->dst_inode);
24782 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24783 + if (d_is_dir(a->src_dentry)) {
24784 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24785 + if (unlikely(!a->exchange
24786 + && d_really_is_positive(a->dst_dentry)
24787 + && !d_is_dir(a->dst_dentry)))
24789 + lock_flags |= AuLock_DIRS;
24791 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24792 + au_fset_ren(a->auren_flags, ISDIR_DST);
24793 + if (unlikely(!a->exchange
24794 + && d_really_is_positive(a->src_dentry)
24795 + && !d_is_dir(a->src_dentry)))
24797 + lock_flags |= AuLock_DIRS;
24799 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24801 + if (unlikely(err))
24804 + err = au_d_hashed_positive(a->src_dentry);
24805 + if (unlikely(err))
24808 + if (a->dst_inode) {
24810 + * If it is a dir, VFS unhash it before this
24811 + * function. It means we cannot rely upon d_unhashed().
24813 + if (unlikely(!a->dst_inode->i_nlink))
24815 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24816 + err = au_d_hashed_positive(a->dst_dentry);
24817 + if (unlikely(err && !a->exchange))
24819 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24821 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24825 + * is it possible?
24826 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24827 + * there may exist a problem somewhere else.
24830 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24833 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24834 + di_write_lock_parent(a->dst_parent);
24836 + /* which branch we process */
24837 + err = au_ren_wbr(a);
24838 + if (unlikely(err < 0))
24840 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24841 + a->h_path.mnt = au_br_mnt(a->br);
24843 + /* are they available to be renamed */
24844 + err = au_ren_may_dir(a);
24845 + if (unlikely(err))
24846 + goto out_children;
24848 + /* prepare the writable parent dir on the same branch */
24849 + if (a->dst_btop == a->btgt) {
24850 + au_fset_ren(a->auren_flags, WHDST);
24852 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24853 + if (unlikely(err))
24854 + goto out_children;
24858 + if (!a->exchange) {
24859 + if (a->src_dir != a->dst_dir) {
24861 + * this temporary unlock is safe,
24862 + * because both dir->i_mutex are locked.
24864 + di_write_unlock(a->dst_parent);
24865 + di_write_lock_parent(a->src_parent);
24866 + err = au_wr_dir_need_wh(a->src_dentry,
24867 + au_ftest_ren(a->auren_flags,
24870 + di_write_unlock(a->src_parent);
24871 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24873 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24875 + err = au_wr_dir_need_wh(a->src_dentry,
24876 + au_ftest_ren(a->auren_flags,
24880 + if (unlikely(err < 0))
24881 + goto out_children;
24883 + au_fset_ren(a->auren_flags, WHSRC);
24886 + if (a->src_btop != a->btgt) {
24887 + err = au_pin(&pin, a->src_dentry, a->btgt,
24888 + au_opt_udba(a->src_dentry->d_sb),
24889 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24891 + struct au_cp_generic cpg = {
24892 + .dentry = a->src_dentry,
24894 + .bsrc = a->src_btop,
24897 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24899 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24900 + err = au_sio_cpup_simple(&cpg);
24903 + if (unlikely(err))
24904 + goto out_children;
24905 + a->src_btop = a->btgt;
24906 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24907 + if (!a->exchange)
24908 + au_fset_ren(a->auren_flags, WHSRC);
24912 + if (a->exchange && a->dst_inode
24913 + && a->dst_btop != a->btgt) {
24914 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24915 + au_opt_udba(a->dst_dentry->d_sb),
24916 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24918 + struct au_cp_generic cpg = {
24919 + .dentry = a->dst_dentry,
24921 + .bsrc = a->dst_btop,
24924 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24926 + err = au_sio_cpup_simple(&cpg);
24929 + if (unlikely(err))
24930 + goto out_children;
24931 + a->dst_btop = a->btgt;
24932 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24935 + /* lock them all */
24936 + err = au_ren_lock(a);
24937 + if (unlikely(err))
24938 + /* leave the copied-up one */
24939 + goto out_children;
24941 + if (!a->exchange) {
24942 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24943 + err = au_may_ren(a);
24944 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24945 + err = -ENAMETOOLONG;
24946 + if (unlikely(err))
24950 + /* store timestamps to be revertible */
24953 + /* store dirren info */
24954 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24955 + err = au_dr_rename(a->src_dentry, a->btgt,
24956 + &a->dst_dentry->d_name, &rev);
24958 + if (unlikely(err))
24963 + err = do_rename(a);
24964 + if (unlikely(err))
24967 + if (au_ftest_ren(a->auren_flags, DIRREN))
24968 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24970 + /* update dir attributes */
24971 + au_ren_refresh_dir(a);
24973 + /* dput/iput all lower dentries */
24974 + au_ren_refresh(a);
24976 + goto out_hdir; /* success */
24979 + if (au_ftest_ren(a->auren_flags, DIRREN))
24980 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24982 + au_ren_rev_dt(err, a);
24984 + au_ren_unlock(a);
24986 + au_nhash_wh_free(&a->whlist);
24987 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24988 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24989 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24990 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24994 + if (d_unhashed(a->src_dentry))
24995 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24996 + if (d_unhashed(a->dst_dentry))
24997 + au_fset_ren(a->auren_flags, DROPPED_DST);
24998 + if (!a->exchange)
24999 + d_move(a->src_dentry, a->dst_dentry);
25001 + d_exchange(a->src_dentry, a->dst_dentry);
25002 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
25003 + d_drop(a->dst_dentry);
25005 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
25006 + d_drop(a->src_dentry);
25008 + au_update_dbtop(a->dst_dentry);
25009 + if (!a->dst_inode)
25010 + d_drop(a->dst_dentry);
25012 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25013 + di_write_unlock(a->dst_parent);
25015 + di_write_unlock2(a->src_parent, a->dst_parent);
25017 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25019 + iput(a->dst_inode);
25021 + au_whtmp_rmdir_free(a->thargs);
25027 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25028 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25029 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
25031 +# SPDX-License-Identifier: GPL-2.0
25033 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25035 + Aufs is a stackable unification filesystem such as Unionfs,
25036 + which unifies several directories and provides a merged single
25038 + In the early days, aufs was entirely re-designed and
25039 + re-implemented Unionfs Version 1.x series. Introducing many
25040 + original ideas, approaches and improvements, it becomes totally
25041 + different from Unionfs while keeping the basic features.
25045 + prompt "Maximum number of branches"
25046 + default AUFS_BRANCH_MAX_127
25048 + Specifies the maximum number of branches (or member directories)
25049 + in a single aufs. The larger value consumes more system
25050 + resources and has a minor impact to performance.
25051 +config AUFS_BRANCH_MAX_127
25054 + Specifies the maximum number of branches (or member directories)
25055 + in a single aufs. The larger value consumes more system
25056 + resources and has a minor impact to performance.
25057 +config AUFS_BRANCH_MAX_511
25060 + Specifies the maximum number of branches (or member directories)
25061 + in a single aufs. The larger value consumes more system
25062 + resources and has a minor impact to performance.
25063 +config AUFS_BRANCH_MAX_1023
25066 + Specifies the maximum number of branches (or member directories)
25067 + in a single aufs. The larger value consumes more system
25068 + resources and has a minor impact to performance.
25069 +config AUFS_BRANCH_MAX_32767
25072 + Specifies the maximum number of branches (or member directories)
25073 + in a single aufs. The larger value consumes more system
25074 + resources and has a minor impact to performance.
25077 +config AUFS_SBILIST
25079 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25082 + Automatic configuration for internal use.
25083 + When aufs supports Magic SysRq or /proc, enabled automatically.
25085 +config AUFS_HNOTIFY
25086 + bool "Detect direct branch access (bypassing aufs)"
25088 + If you want to modify files on branches directly, eg. bypassing aufs,
25089 + and want aufs to detect the changes of them fully, then enable this
25090 + option and use 'udba=notify' mount option.
25091 + Currently there is only one available configuration, "fsnotify".
25092 + It will have a negative impact to the performance.
25093 + See detail in aufs.5.
25096 + prompt "method" if AUFS_HNOTIFY
25097 + default AUFS_HFSNOTIFY
25098 +config AUFS_HFSNOTIFY
25103 +config AUFS_EXPORT
25104 + bool "NFS-exportable aufs"
25105 + depends on EXPORTFS
25107 + If you want to export your mounted aufs via NFS, then enable this
25108 + option. There are several requirements for this configuration.
25109 + See detail in aufs.5.
25111 +config AUFS_INO_T_64
25113 + depends on AUFS_EXPORT
25114 + depends on 64BIT && !(ALPHA || S390)
25117 + Automatic configuration for internal use.
25118 + /* typedef unsigned long/int __kernel_ino_t */
25119 + /* alpha and s390x are int */
25122 + bool "support for XATTR/EA (including Security Labels)"
25124 + If your branch fs supports XATTR/EA and you want to make them
25125 + available in aufs too, then enable this opsion and specify the
25126 + branch attributes for EA.
25127 + See detail in aufs.5.
25130 + bool "File-based Hierarchical Storage Management"
25132 + Hierarchical Storage Management (or HSM) is a well-known feature
25133 + in the storage world. Aufs provides this feature as file-based.
25134 + with multiple branches.
25135 + These multiple branches are prioritized, ie. the topmost one
25136 + should be the fastest drive and be used heavily.
25139 + bool "Readdir in userspace"
25141 + Aufs has two methods to provide a merged view for a directory,
25142 + by a user-space library and by kernel-space natively. The latter
25143 + is always enabled but sometimes large and slow.
25144 + If you enable this option, install the library in aufs2-util
25145 + package, and set some environment variables for your readdir(3),
25146 + then the work will be handled in user-space which generally
25147 + shows better performance in most cases.
25148 + See detail in aufs.5.
25150 +config AUFS_DIRREN
25151 + bool "Workaround for rename(2)-ing a directory"
25153 + By default, aufs returns EXDEV error in renameing a dir who has
25154 + his child on the lower branch, since it is a bad idea to issue
25155 + rename(2) internally for every lower branch. But user may not
25156 + accept this behaviour. So here is a workaround to allow such
25157 + rename(2) and store some extra information on the writable
25158 + branch. Obviously this costs high (and I don't like it).
25159 + To use this feature, you need to enable this configuration AND
25160 + to specify the mount option `dirren.'
25161 + See details in aufs.5 and the design documents.
25164 + bool "Show whiteouts"
25166 + If you want to make the whiteouts in aufs visible, then enable
25167 + this option and specify 'shwh' mount option. Although it may
25168 + sounds like philosophy or something, but in technically it
25169 + simply shows the name of whiteout with keeping its behaviour.
25171 +config AUFS_BR_RAMFS
25172 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25174 + If you want to use ramfs as an aufs branch fs, then enable this
25175 + option. Generally tmpfs is recommended.
25176 + Aufs prohibited them to be a branch fs by default, because
25177 + initramfs becomes unusable after switch_root or something
25178 + generally. If you sets initramfs as an aufs branch and boot your
25179 + system by switch_root, you will meet a problem easily since the
25180 + files in initramfs may be inaccessible.
25181 + Unless you are going to use ramfs as an aufs branch fs without
25182 + switch_root or something, leave it N.
25184 +config AUFS_BR_FUSE
25185 + bool "Fuse fs as an aufs branch"
25186 + depends on FUSE_FS
25189 + If you want to use fuse-based userspace filesystem as an aufs
25190 + branch fs, then enable this option.
25191 + It implements the internal poll(2) operation which is
25192 + implemented by fuse only (curretnly).
25197 + Automatic configuration for internal use.
25199 +config AUFS_BR_HFSPLUS
25200 + bool "Hfsplus as an aufs branch"
25201 + depends on HFSPLUS_FS
25204 + If you want to use hfsplus fs as an aufs branch fs, then enable
25205 + this option. This option introduces a small overhead at
25206 + copying-up a file on hfsplus.
25208 +config AUFS_BDEV_LOOP
25210 + depends on BLK_DEV_LOOP
25213 + Automatic configuration for internal use.
25214 + Convert =[ym] into =y.
25217 + bool "Debug aufs"
25219 + Enable this to compile aufs internal debug code.
25220 + It will have a negative impact to the performance.
25222 +config AUFS_MAGIC_SYSRQ
25224 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25227 + Automatic configuration for internal use.
25228 + When aufs supports Magic SysRq, enabled automatically.
25230 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25231 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25232 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25234 +/* SPDX-License-Identifier: GPL-2.0 */
25236 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25238 + * This program is free software; you can redistribute it and/or modify
25239 + * it under the terms of the GNU General Public License as published by
25240 + * the Free Software Foundation; either version 2 of the License, or
25241 + * (at your option) any later version.
25243 + * This program is distributed in the hope that it will be useful,
25244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25246 + * GNU General Public License for more details.
25248 + * You should have received a copy of the GNU General Public License
25249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25253 + * simple long counter wrapper
25256 +#ifndef __AUFS_LCNT_H__
25257 +#define __AUFS_LCNT_H__
25261 +#include "debug.h"
25263 +#define AuLCntATOMIC 1
25264 +#define AuLCntPCPUCNT 2
25266 + * why does percpu_refcount require extra synchronize_rcu()s in
25267 + * au_br_do_free()
25269 +#define AuLCntPCPUREF 3
25271 +/* #define AuLCntChosen AuLCntATOMIC */
25272 +#define AuLCntChosen AuLCntPCPUCNT
25273 +/* #define AuLCntChosen AuLCntPCPUREF */
25275 +#if AuLCntChosen == AuLCntATOMIC
25276 +#include <linux/atomic.h>
25278 +typedef atomic_long_t au_lcnt_t;
25280 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25282 + atomic_long_set(cnt, 0);
25286 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25291 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25292 + int do_sync __maybe_unused)
25297 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25299 + atomic_long_inc(cnt);
25302 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25304 + atomic_long_dec(cnt);
25307 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25309 + return atomic_long_read(cnt);
25313 +#if AuLCntChosen == AuLCntPCPUCNT
25314 +#include <linux/percpu_counter.h>
25316 +typedef struct percpu_counter au_lcnt_t;
25318 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25320 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25323 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25328 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25330 + percpu_counter_destroy(cnt);
25333 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25335 + percpu_counter_inc(cnt);
25338 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25340 + percpu_counter_dec(cnt);
25343 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25347 + n = percpu_counter_sum(cnt);
25349 + if (LONG_MAX != LLONG_MAX
25351 + AuWarn1("%s\n", "wrap-around");
25357 +#if AuLCntChosen == AuLCntPCPUREF
25358 +#include <linux/percpu-refcount.h>
25360 +typedef struct percpu_ref au_lcnt_t;
25362 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25365 + release = percpu_ref_exit;
25366 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25369 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25371 + synchronize_rcu();
25374 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25376 + percpu_ref_kill(cnt);
25378 + au_lcnt_wait_for_fin(cnt);
25381 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25383 + percpu_ref_get(cnt);
25386 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25388 + percpu_ref_put(cnt);
25392 + * avoid calling this func as possible.
25394 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25398 + percpu_ref_switch_to_atomic_sync(cnt);
25399 + l = atomic_long_read(&cnt->count);
25401 + percpu_ref_switch_to_percpu(cnt);
25403 + /* percpu_ref is initialized by 1 instead of 0 */
25408 +#ifdef CONFIG_AUFS_DEBUG
25409 +#define AuLCntZero(val) do { \
25412 + AuDbg("%s = %ld\n", #val, l); \
25415 +#define AuLCntZero(val) do {} while (0)
25418 +#endif /* __KERNEL__ */
25419 +#endif /* __AUFS_LCNT_H__ */
25420 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25421 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25422 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25424 +// SPDX-License-Identifier: GPL-2.0
25426 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25428 + * This program is free software; you can redistribute it and/or modify
25429 + * it under the terms of the GNU General Public License as published by
25430 + * the Free Software Foundation; either version 2 of the License, or
25431 + * (at your option) any later version.
25433 + * This program is distributed in the hope that it will be useful,
25434 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25435 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25436 + * GNU General Public License for more details.
25438 + * You should have received a copy of the GNU General Public License
25439 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25443 + * support for loopback block device as a branch
25448 +/* added into drivers/block/loop.c */
25449 +static struct file *(*backing_file_func)(struct super_block *sb);
25452 + * test if two lower dentries have overlapping branches.
25454 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25456 + struct super_block *h_sb;
25457 + struct file *backing_file;
25459 + if (unlikely(!backing_file_func)) {
25460 + /* don't load "loop" module here */
25461 + backing_file_func = symbol_get(loop_backing_file);
25462 + if (unlikely(!backing_file_func))
25463 + /* "loop" module is not loaded */
25467 + h_sb = h_adding->d_sb;
25468 + backing_file = backing_file_func(h_sb);
25469 + if (!backing_file)
25472 + h_adding = backing_file->f_path.dentry;
25474 + * h_adding can be local NFS.
25475 + * in this case aufs cannot detect the loop.
25477 + if (unlikely(h_adding->d_sb == sb))
25479 + return !!au_test_subdir(h_adding, sb->s_root);
25482 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25483 +int au_test_loopback_kthread(void)
25486 + struct task_struct *tsk = current;
25487 + char c, comm[sizeof(tsk->comm)];
25490 + if (tsk->flags & PF_KTHREAD) {
25491 + get_task_comm(comm, tsk);
25493 + ret = ('0' <= c && c <= '9'
25494 + && !strncmp(comm, "loop", 4));
25500 +/* ---------------------------------------------------------------------- */
25502 +#define au_warn_loopback_step 16
25503 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25504 +static unsigned long *au_warn_loopback_array;
25506 +void au_warn_loopback(struct super_block *h_sb)
25508 + int i, new_nelem;
25509 + unsigned long *a, magic;
25510 + static DEFINE_SPINLOCK(spin);
25512 + magic = h_sb->s_magic;
25513 + spin_lock(&spin);
25514 + a = au_warn_loopback_array;
25515 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25516 + if (a[i] == magic) {
25517 + spin_unlock(&spin);
25521 + /* h_sb is new to us, print it */
25522 + if (i < au_warn_loopback_nelem) {
25527 + /* expand the array */
25528 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25529 + a = au_kzrealloc(au_warn_loopback_array,
25530 + au_warn_loopback_nelem * sizeof(unsigned long),
25531 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25532 + /*may_shrink*/0);
25534 + au_warn_loopback_nelem = new_nelem;
25535 + au_warn_loopback_array = a;
25540 + spin_unlock(&spin);
25541 + AuWarn1("realloc failed, ignored\n");
25545 + spin_unlock(&spin);
25546 + pr_warn("you may want to try another patch for loopback file "
25547 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25550 +int au_loopback_init(void)
25553 + struct super_block *sb __maybe_unused;
25555 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25558 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25559 + sizeof(unsigned long), GFP_NOFS);
25560 + if (unlikely(!au_warn_loopback_array))
25566 +void au_loopback_fin(void)
25568 + if (backing_file_func)
25569 + symbol_put(loop_backing_file);
25570 + au_kfree_try_rcu(au_warn_loopback_array);
25572 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25573 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25574 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25576 +/* SPDX-License-Identifier: GPL-2.0 */
25578 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25580 + * This program is free software; you can redistribute it and/or modify
25581 + * it under the terms of the GNU General Public License as published by
25582 + * the Free Software Foundation; either version 2 of the License, or
25583 + * (at your option) any later version.
25585 + * This program is distributed in the hope that it will be useful,
25586 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25587 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25588 + * GNU General Public License for more details.
25590 + * You should have received a copy of the GNU General Public License
25591 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25595 + * support for loopback mount as a branch
25598 +#ifndef __AUFS_LOOP_H__
25599 +#define __AUFS_LOOP_H__
25604 +struct super_block;
25606 +#ifdef CONFIG_AUFS_BDEV_LOOP
25607 +/* drivers/block/loop.c */
25608 +struct file *loop_backing_file(struct super_block *sb);
25611 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25612 +int au_test_loopback_kthread(void);
25613 +void au_warn_loopback(struct super_block *h_sb);
25615 +int au_loopback_init(void);
25616 +void au_loopback_fin(void);
25618 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25620 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25621 + struct dentry *h_adding)
25622 +AuStubInt0(au_test_loopback_kthread, void)
25623 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25625 +AuStubInt0(au_loopback_init, void)
25626 +AuStubVoid(au_loopback_fin, void)
25627 +#endif /* BLK_DEV_LOOP */
25629 +#endif /* __KERNEL__ */
25630 +#endif /* __AUFS_LOOP_H__ */
25631 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25632 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25633 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25635 +# SPDX-License-Identifier: GPL-2.0
25637 +# defined in ${srctree}/fs/fuse/inode.c
25639 +ifdef CONFIG_FUSE_FS
25640 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25643 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25645 +ifdef CONFIG_XFS_FS
25646 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25649 +# defined in ${srctree}/fs/configfs/mount.c
25651 +ifdef CONFIG_CONFIGFS_FS
25652 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25655 +# defined in ${srctree}/fs/ubifs/ubifs.h
25657 +ifdef CONFIG_UBIFS_FS
25658 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25661 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25663 +ifdef CONFIG_HFSPLUS_FS
25664 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25666 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25667 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25668 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25670 +# SPDX-License-Identifier: GPL-2.0
25672 +include ${src}/magic.mk
25673 +ifeq (${CONFIG_AUFS_FS},m)
25674 +include ${src}/conf.mk
25676 +-include ${src}/priv_def.mk
25678 +# cf. include/linux/kernel.h
25680 +ccflags-y += -DDEBUG
25681 +# sparse requires the full pathname
25683 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25685 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25688 +obj-$(CONFIG_AUFS_FS) += aufs.o
25689 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25690 + wkq.o vfsub.o dcsub.o \
25691 + cpup.o whout.o wbr_policy.o \
25692 + dinfo.o dentry.o \
25694 + finfo.o file.o f_op.o \
25696 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25700 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25701 +aufs-$(CONFIG_SYSFS) += sysfs.o
25702 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25703 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25704 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25705 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25706 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25707 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25708 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25709 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25710 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25711 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25712 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25713 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25714 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25715 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25716 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25717 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25718 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25720 +// SPDX-License-Identifier: GPL-2.0
25722 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25724 + * This program is free software; you can redistribute it and/or modify
25725 + * it under the terms of the GNU General Public License as published by
25726 + * the Free Software Foundation; either version 2 of the License, or
25727 + * (at your option) any later version.
25729 + * This program is distributed in the hope that it will be useful,
25730 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25731 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25732 + * GNU General Public License for more details.
25734 + * You should have received a copy of the GNU General Public License
25735 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25739 + * module global variables and operations
25742 +#include <linux/module.h>
25743 +#include <linux/seq_file.h>
25746 +/* shrinkable realloc */
25747 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25755 +#if 0 /* unused */
25762 + AuDebugOn(!new_sz);
25765 + diff = au_kmidx_sub(sz, new_sz);
25771 + /* expand or SLOB */
25772 + p = krealloc(p, new_sz, gfp);
25773 + else if (new_sz < sz && may_shrink) {
25777 + q = kmalloc(new_sz, gfp);
25780 + memcpy(q, p, new_sz);
25781 + au_kfree_try_rcu(p);
25792 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25795 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25796 + if (p && new_sz > nused)
25797 + memset(p + nused, 0, new_sz - nused);
25801 +/* ---------------------------------------------------------------------- */
25805 +struct kmem_cache *au_cache[AuCache_Last];
25807 +static void au_cache_fin(void)
25812 + * Make sure all delayed rcu free inodes are flushed before we
25817 + /* excluding AuCache_HNOTIFY */
25818 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25819 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25820 + kmem_cache_destroy(au_cache[i]);
25821 + au_cache[i] = NULL;
25825 +static int __init au_cache_init(void)
25827 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25828 + if (au_cache[AuCache_DINFO])
25829 + /* SLAB_DESTROY_BY_RCU */
25830 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25831 + au_icntnr_init_once);
25832 + if (au_cache[AuCache_ICNTNR])
25833 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25834 + au_fi_init_once);
25835 + if (au_cache[AuCache_FINFO])
25836 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25837 + if (au_cache[AuCache_VDIR])
25838 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25839 + if (au_cache[AuCache_DEHSTR])
25846 +/* ---------------------------------------------------------------------- */
25848 +int au_dir_roflags;
25850 +#ifdef CONFIG_AUFS_SBILIST
25852 + * iterate_supers_type() doesn't protect us from
25853 + * remounting (branch management)
25855 +struct hlist_bl_head au_sbilist;
25859 + * functions for module interface.
25861 +MODULE_LICENSE("GPL");
25862 +/* MODULE_LICENSE("GPL v2"); */
25863 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25864 +MODULE_DESCRIPTION(AUFS_NAME
25865 + " -- Advanced multi layered unification filesystem");
25866 +MODULE_VERSION(AUFS_VERSION);
25867 +MODULE_ALIAS_FS(AUFS_NAME);
25869 +/* this module parameter has no meaning when SYSFS is disabled */
25870 +int sysaufs_brs = 1;
25871 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25872 +module_param_named(brs, sysaufs_brs, int, 0444);
25874 +/* this module parameter has no meaning when USER_NS is disabled */
25876 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25877 +module_param_named(allow_userns, au_userns, bool, 0444);
25879 +/* ---------------------------------------------------------------------- */
25881 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25883 +int au_seq_path(struct seq_file *seq, struct path *path)
25887 + err = seq_path(seq, path, au_esc_chars);
25896 +/* ---------------------------------------------------------------------- */
25898 +static int __init aufs_init(void)
25903 + p = au_esc_chars;
25904 + for (i = 1; i <= ' '; i++)
25910 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25912 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25913 + for (i = 0; i < AuIop_Last; i++)
25914 + aufs_iop_nogetattr[i].getattr = NULL;
25916 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25918 + au_sbilist_init();
25919 + sysaufs_brs_init();
25922 + err = sysaufs_init();
25923 + if (unlikely(err))
25925 + err = dbgaufs_init();
25926 + if (unlikely(err))
25927 + goto out_sysaufs;
25928 + err = au_procfs_init();
25929 + if (unlikely(err))
25930 + goto out_dbgaufs;
25931 + err = au_wkq_init();
25932 + if (unlikely(err))
25934 + err = au_loopback_init();
25935 + if (unlikely(err))
25937 + err = au_hnotify_init();
25938 + if (unlikely(err))
25939 + goto out_loopback;
25940 + err = au_sysrq_init();
25941 + if (unlikely(err))
25943 + err = au_cache_init();
25944 + if (unlikely(err))
25947 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25948 + err = register_filesystem(&aufs_fs_type);
25949 + if (unlikely(err))
25952 + /* since we define pr_fmt, call printk directly */
25953 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25954 + goto out; /* success */
25961 + au_hnotify_fin();
25963 + au_loopback_fin();
25977 +static void __exit aufs_exit(void)
25979 + unregister_filesystem(&aufs_fs_type);
25982 + au_hnotify_fin();
25983 + au_loopback_fin();
25991 +module_init(aufs_init);
25992 +module_exit(aufs_exit);
25993 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25994 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25995 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
25997 +/* SPDX-License-Identifier: GPL-2.0 */
25999 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26001 + * This program is free software; you can redistribute it and/or modify
26002 + * it under the terms of the GNU General Public License as published by
26003 + * the Free Software Foundation; either version 2 of the License, or
26004 + * (at your option) any later version.
26006 + * This program is distributed in the hope that it will be useful,
26007 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26008 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26009 + * GNU General Public License for more details.
26011 + * You should have received a copy of the GNU General Public License
26012 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26016 + * module initialization and module-global
26019 +#ifndef __AUFS_MODULE_H__
26020 +#define __AUFS_MODULE_H__
26024 +#include <linux/slab.h>
26025 +#include "debug.h"
26026 +#include "dentry.h"
26029 +#include "inode.h"
26034 +/* module parameters */
26035 +extern int sysaufs_brs;
26036 +extern bool au_userns;
26038 +/* ---------------------------------------------------------------------- */
26040 +extern int au_dir_roflags;
26042 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26043 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26047 + * Comparing the size of the object with sizeof(struct rcu_head)
26048 + * case 1: object is always larger
26049 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26050 + * case 2: object is always smaller
26051 + * --> au_kfree_small()
26052 + * case 3: object can be any size
26053 + * --> au_kfree_try_rcu()
26056 +static inline void au_kfree_do_rcu(const void *p)
26059 + struct rcu_head rcu;
26060 + } *a = (void *)p;
26062 + kfree_rcu(a, rcu);
26065 +#define au_kfree_rcu(_p) do { \
26066 + typeof(_p) p = (_p); \
26067 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26069 + au_kfree_do_rcu(p); \
26072 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26073 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26075 +static inline void au_kfree_try_rcu(const void *p)
26079 + if (au_kfree_sz_test(p))
26080 + au_kfree_do_rcu(p);
26085 +static inline void au_kfree_small(const void *p)
26089 + AuDebugOn(au_kfree_sz_test(p));
26093 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26095 +#ifndef CONFIG_SLOB
26096 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26098 + return -1; /* SLOB is untested */
26102 +int au_seq_path(struct seq_file *seq, struct path *path);
26104 +#ifdef CONFIG_PROC_FS
26106 +int __init au_procfs_init(void);
26107 +void au_procfs_fin(void);
26109 +AuStubInt0(au_procfs_init, void);
26110 +AuStubVoid(au_procfs_fin, void);
26113 +/* ---------------------------------------------------------------------- */
26122 + AuCache_HNOTIFY, /* must be last */
26126 +extern struct kmem_cache *au_cache[AuCache_Last];
26128 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26129 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26130 +#define AuCacheCtor(type, ctor) \
26131 + kmem_cache_create(#type, sizeof(struct type), \
26132 + __alignof__(struct type), AuCacheFlags, ctor)
26134 +#define AuCacheFuncAlloc(name, index) \
26135 + static inline struct au_##name *au_cache_alloc_##name(void) \
26136 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26138 +#define AuCacheFuncs(name, index) \
26139 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26140 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26142 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26143 + { void *p = rcu; \
26144 + p -= offsetof(struct au_##name, rcu); \
26145 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26146 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26147 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26148 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26150 + static inline void au_cache_free_##name(struct au_##name *p) \
26151 + { /* au_cache_free_##name##_norcu(p); */ \
26152 + au_cache_free_##name##_rcu(p); }
26154 +AuCacheFuncs(dinfo, DINFO);
26155 +AuCacheFuncAlloc(dinfo, DINFO);
26157 +AuCacheFuncs(icntnr, ICNTNR);
26158 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26159 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26161 +AuCacheFuncs(finfo, FINFO);
26162 +AuCacheFuncAlloc(finfo, FINFO);
26164 +AuCacheFuncs(vdir, VDIR);
26165 +AuCacheFuncAlloc(vdir, VDIR);
26167 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26168 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26170 +#ifdef CONFIG_AUFS_HNOTIFY
26171 +AuCacheFuncs(hnotify, HNOTIFY);
26172 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26175 +#endif /* __KERNEL__ */
26176 +#endif /* __AUFS_MODULE_H__ */
26177 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26178 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26179 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26181 +// SPDX-License-Identifier: GPL-2.0
26183 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26185 + * This program is free software; you can redistribute it and/or modify
26186 + * it under the terms of the GNU General Public License as published by
26187 + * the Free Software Foundation; either version 2 of the License, or
26188 + * (at your option) any later version.
26190 + * This program is distributed in the hope that it will be useful,
26191 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26192 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26193 + * GNU General Public License for more details.
26195 + * You should have received a copy of the GNU General Public License
26196 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26200 + * move-down, opposite of copy-up
26205 +struct au_mvd_args {
26207 + struct super_block *h_sb;
26208 + struct dentry *h_parent;
26209 + struct au_hinode *hdir;
26210 + struct inode *h_dir, *h_inode;
26211 + struct au_pin pin;
26212 + } info[AUFS_MVDOWN_NARRAY];
26214 + struct aufs_mvdown mvdown;
26215 + struct dentry *dentry, *parent;
26216 + struct inode *inode, *dir;
26217 + struct super_block *sb;
26218 + aufs_bindex_t bopq, bwh, bfound;
26219 + unsigned char rename_lock;
26222 +#define mvd_errno mvdown.au_errno
26223 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26224 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26225 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26226 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26228 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26229 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26230 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26231 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26232 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26233 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26235 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26236 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26237 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26238 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26239 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26240 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26242 +#define AU_MVD_PR(flag, ...) do { \
26244 + pr_err(__VA_ARGS__); \
26247 +static int find_lower_writable(struct au_mvd_args *a)
26249 + struct super_block *sb;
26250 + aufs_bindex_t bindex, bbot;
26251 + struct au_branch *br;
26254 + bindex = a->mvd_bsrc;
26255 + bbot = au_sbbot(sb);
26256 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26257 + for (bindex++; bindex <= bbot; bindex++) {
26258 + br = au_sbr(sb, bindex);
26259 + if (au_br_fhsm(br->br_perm)
26260 + && !sb_rdonly(au_br_sb(br)))
26263 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26264 + for (bindex++; bindex <= bbot; bindex++) {
26265 + br = au_sbr(sb, bindex);
26266 + if (!au_br_rdonly(br))
26270 + for (bindex++; bindex <= bbot; bindex++) {
26271 + br = au_sbr(sb, bindex);
26272 + if (!sb_rdonly(au_br_sb(br))) {
26273 + if (au_br_rdonly(br))
26275 + |= AUFS_MVDOWN_ROLOWER_R;
26283 +/* make the parent dir on bdst */
26284 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26289 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26290 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26291 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26292 + a->mvd_h_dst_parent = NULL;
26293 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26294 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26295 + if (!a->mvd_h_dst_parent) {
26296 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26297 + if (unlikely(err)) {
26298 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26301 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26309 +/* lock them all */
26310 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26313 + struct dentry *h_trap;
26315 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26316 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26317 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26318 + au_opt_udba(a->sb),
26319 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26321 + if (unlikely(err)) {
26322 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26326 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26327 + a->rename_lock = 0;
26328 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26329 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26330 + au_opt_udba(a->sb),
26331 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26332 + err = au_do_pin(&a->mvd_pin_src);
26334 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26335 + if (unlikely(err)) {
26336 + AU_MVD_PR(dmsg, "pin_src failed\n");
26339 + goto out; /* success */
26342 + a->rename_lock = 1;
26343 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26344 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26345 + au_opt_udba(a->sb),
26346 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26348 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26349 + if (unlikely(err)) {
26350 + AU_MVD_PR(dmsg, "pin_src failed\n");
26351 + au_pin_hdir_lock(&a->mvd_pin_dst);
26354 + au_pin_hdir_unlock(&a->mvd_pin_src);
26355 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26356 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26358 + err = (h_trap != a->mvd_h_src_parent);
26360 + err = (h_trap != a->mvd_h_dst_parent);
26362 + BUG_ON(err); /* it should never happen */
26363 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26366 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26367 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26368 + au_pin_hdir_lock(&a->mvd_pin_src);
26369 + au_unpin(&a->mvd_pin_src);
26370 + au_pin_hdir_lock(&a->mvd_pin_dst);
26373 + goto out; /* success */
26376 + au_unpin(&a->mvd_pin_dst);
26382 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26384 + if (!a->rename_lock)
26385 + au_unpin(&a->mvd_pin_src);
26387 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26388 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26389 + au_pin_hdir_lock(&a->mvd_pin_src);
26390 + au_unpin(&a->mvd_pin_src);
26391 + au_pin_hdir_lock(&a->mvd_pin_dst);
26393 + au_unpin(&a->mvd_pin_dst);
26396 +/* copy-down the file */
26397 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26400 + struct au_cp_generic cpg = {
26401 + .dentry = a->dentry,
26402 + .bdst = a->mvd_bdst,
26403 + .bsrc = a->mvd_bsrc,
26405 + .pin = &a->mvd_pin_dst,
26406 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26409 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26410 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26411 + au_fset_cpup(cpg.flags, OVERWRITE);
26412 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26413 + au_fset_cpup(cpg.flags, RWDST);
26414 + err = au_sio_cpdown_simple(&cpg);
26415 + if (unlikely(err))
26416 + AU_MVD_PR(dmsg, "cpdown failed\n");
26423 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26426 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26429 + struct path h_path;
26430 + struct au_branch *br;
26431 + struct inode *delegated;
26433 + br = au_sbr(a->sb, a->mvd_bdst);
26434 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26435 + err = PTR_ERR(h_path.dentry);
26436 + if (IS_ERR(h_path.dentry)) {
26437 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26442 + if (d_is_positive(h_path.dentry)) {
26443 + h_path.mnt = au_br_mnt(br);
26444 + delegated = NULL;
26445 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26446 + &delegated, /*force*/0);
26447 + if (unlikely(err == -EWOULDBLOCK)) {
26448 + pr_warn("cannot retry for NFSv4 delegation"
26449 + " for an internal unlink\n");
26452 + if (unlikely(err))
26453 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26455 + dput(h_path.dentry);
26463 + * unlink the topmost h_dentry
26465 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26468 + struct path h_path;
26469 + struct inode *delegated;
26471 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26472 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26473 + delegated = NULL;
26474 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26475 + if (unlikely(err == -EWOULDBLOCK)) {
26476 + pr_warn("cannot retry for NFSv4 delegation"
26477 + " for an internal unlink\n");
26480 + if (unlikely(err))
26481 + AU_MVD_PR(dmsg, "unlink failed\n");
26487 +/* Since mvdown succeeded, we ignore an error of this function */
26488 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26491 + struct au_branch *br;
26493 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26494 + br = au_sbr(a->sb, a->mvd_bsrc);
26495 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26497 + br = au_sbr(a->sb, a->mvd_bdst);
26498 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26499 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26502 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26504 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26508 + * copy-down the file and unlink the bsrc file.
26509 + * - unlink the bdst whout if exist
26510 + * - copy-down the file (with whtmp name and rename)
26511 + * - unlink the bsrc file
26513 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26517 + err = au_do_mkdir(dmsg, a);
26519 + err = au_do_lock(dmsg, a);
26520 + if (unlikely(err))
26524 + * do not revert the activities we made on bdst since they should be
26525 + * harmless in aufs.
26528 + err = au_do_cpdown(dmsg, a);
26530 + err = au_do_unlink_wh(dmsg, a);
26531 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26532 + err = au_do_unlink(dmsg, a);
26533 + if (unlikely(err))
26536 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26537 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26538 + if (find_lower_writable(a) < 0)
26539 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26541 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26542 + au_do_stfs(dmsg, a);
26544 + /* maintain internal array */
26545 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26546 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26547 + au_set_dbtop(a->dentry, a->mvd_bdst);
26548 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26549 + au_set_ibtop(a->inode, a->mvd_bdst);
26551 + /* hide the lower */
26552 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26553 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26554 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26555 + au_set_ibbot(a->inode, a->mvd_bsrc);
26557 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26558 + au_set_dbbot(a->dentry, a->mvd_bdst);
26559 + if (au_ibbot(a->inode) < a->mvd_bdst)
26560 + au_set_ibbot(a->inode, a->mvd_bdst);
26563 + au_do_unlock(dmsg, a);
26569 +/* ---------------------------------------------------------------------- */
26571 +/* make sure the file is idle */
26572 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26574 + int err, plinked;
26577 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26578 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26579 + && au_dcount(a->dentry) == 1
26580 + && atomic_read(&a->inode->i_count) == 1
26581 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26582 + && (!plinked || !au_plink_test(a->inode))
26583 + && a->inode->i_nlink == 1)
26588 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26589 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26590 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26591 + a->mvd_h_src_inode->i_nlink,
26592 + plinked, plinked ? au_plink_test(a->inode) : 0);
26599 +/* make sure the parent dir is fine */
26600 +static int au_mvd_args_parent(const unsigned char dmsg,
26601 + struct au_mvd_args *a)
26604 + aufs_bindex_t bindex;
26607 + if (unlikely(au_alive_dir(a->parent))) {
26609 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26613 + a->bopq = au_dbdiropq(a->parent);
26614 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26615 + AuDbg("b%d\n", bindex);
26616 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26617 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26619 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26620 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26621 + a->bopq, a->mvd_bdst);
26629 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26630 + struct au_mvd_args *a)
26633 + struct au_dinfo *dinfo, *tmp;
26635 + /* lookup the next lower positive entry */
26637 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26638 + if (unlikely(!tmp))
26643 + dinfo = au_di(a->dentry);
26644 + au_di_cp(tmp, dinfo);
26645 + au_di_swap(tmp, dinfo);
26647 + /* returns the number of positive dentries */
26648 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26649 + /* AuLkup_IGNORE_PERM */ 0);
26651 + a->bwh = au_dbwh(a->dentry);
26652 + else if (err > 0)
26653 + a->bfound = au_dbtop(a->dentry);
26655 + au_di_swap(tmp, dinfo);
26656 + au_rw_write_unlock(&tmp->di_rwsem);
26658 + if (unlikely(err < 0))
26659 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26662 + * here, we have these cases.
26664 + * no positive dentry under bsrc. there are more sub-cases.
26666 + * there no whiteout, we can safely move-down.
26669 + * bsrc < bwh && bwh < bdst
26670 + * there is a whiteout on RO branch. cannot proceed.
26672 + * there is a whiteout on the RW target branch. it should
26675 + * there is a whiteout somewhere unrelated branch.
26676 + * -1 < bfound && bfound <= bsrc
26679 + * found, but it is on RO branch between bsrc and bdst. cannot
26682 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26685 + * found, after we create the file on bdst, it will be hidden.
26688 + AuDebugOn(a->bfound == -1
26690 + && a->bwh <= a->mvd_bsrc);
26691 + AuDebugOn(-1 < a->bfound
26692 + && a->bfound <= a->mvd_bsrc);
26695 + if (a->bfound == -1
26696 + && a->mvd_bsrc < a->bwh
26698 + && a->bwh < a->mvd_bdst) {
26699 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26700 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26701 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26703 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26704 + a->mvd_errno = EAU_MVDOWN_UPPER;
26705 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26706 + a->mvd_bdst, a->bfound);
26710 + err = 0; /* success */
26717 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26722 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26723 + && a->bfound == a->mvd_bdst)
26729 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26732 + struct au_branch *br;
26735 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26739 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26740 + a->mvd_bsrc = au_ibtop(a->inode);
26742 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26743 + if (unlikely(a->mvd_bsrc < 0
26744 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26745 + || au_dbbot(a->dentry) < a->mvd_bsrc
26746 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26747 + || (a->mvd_bsrc < au_ibtop(a->inode)
26748 + || au_ibbot(a->inode) < a->mvd_bsrc
26749 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26750 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26751 + AU_MVD_PR(dmsg, "no upper\n");
26755 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26756 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26757 + AU_MVD_PR(dmsg, "on the bottom\n");
26760 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26761 + br = au_sbr(a->sb, a->mvd_bsrc);
26762 + err = au_br_rdonly(br);
26763 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26764 + if (unlikely(err))
26766 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26767 + || IS_APPEND(a->mvd_h_src_inode))) {
26769 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26775 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26776 + a->mvd_bdst = find_lower_writable(a);
26777 + if (unlikely(a->mvd_bdst < 0)) {
26778 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26779 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26783 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26784 + if (unlikely(a->mvd_bdst < 0
26785 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26786 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26787 + AU_MVD_PR(dmsg, "no lower brid\n");
26792 + err = au_mvd_args_busy(dmsg, a);
26794 + err = au_mvd_args_parent(dmsg, a);
26796 + err = au_mvd_args_intermediate(dmsg, a);
26798 + err = au_mvd_args_exist(dmsg, a);
26800 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26807 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26810 + unsigned char dmsg;
26811 + struct au_mvd_args *args;
26812 + struct inode *inode;
26814 + inode = d_inode(dentry);
26816 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26820 + args = kmalloc(sizeof(*args), GFP_NOFS);
26821 + if (unlikely(!args))
26824 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26826 + /* VERIFY_WRITE */
26827 + err = !access_ok(uarg, sizeof(*uarg));
26828 + if (unlikely(err)) {
26833 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26834 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26835 + args->mvdown.au_errno = 0;
26836 + args->dentry = dentry;
26837 + args->inode = inode;
26838 + args->sb = dentry->d_sb;
26841 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26842 + args->parent = dget_parent(dentry);
26843 + args->dir = d_inode(args->parent);
26844 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26845 + dput(args->parent);
26846 + if (unlikely(args->parent != dentry->d_parent)) {
26847 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26851 + inode_lock_nested(inode, I_MUTEX_CHILD);
26852 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26853 + if (unlikely(err))
26856 + di_write_lock_parent(args->parent);
26857 + err = au_mvd_args(dmsg, args);
26858 + if (unlikely(err))
26861 + err = au_do_mvdown(dmsg, args);
26862 + if (unlikely(err))
26865 + au_cpup_attr_timesizes(args->dir);
26866 + au_cpup_attr_timesizes(inode);
26867 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26868 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26869 + /* au_digen_dec(dentry); */
26872 + di_write_unlock(args->parent);
26873 + aufs_read_unlock(dentry, AuLock_DW);
26875 + inode_unlock(inode);
26877 + inode_unlock(args->dir);
26879 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26882 + au_kfree_rcu(args);
26887 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26888 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26889 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26891 +// SPDX-License-Identifier: GPL-2.0
26893 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26895 + * This program is free software; you can redistribute it and/or modify
26896 + * it under the terms of the GNU General Public License as published by
26897 + * the Free Software Foundation; either version 2 of the License, or
26898 + * (at your option) any later version.
26900 + * This program is distributed in the hope that it will be useful,
26901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26903 + * GNU General Public License for more details.
26905 + * You should have received a copy of the GNU General Public License
26906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26910 + * mount options/flags
26913 +#include <linux/types.h> /* a distribution requires */
26914 +#include <linux/parser.h>
26917 +/* ---------------------------------------------------------------------- */
26919 +static const char *au_parser_pattern(int val, match_table_t tbl)
26921 + struct match_token *p;
26924 + while (p->pattern) {
26925 + if (p->token == val)
26926 + return p->pattern;
26933 +static const char *au_optstr(int *val, match_table_t tbl)
26935 + struct match_token *p;
26942 + while (p->pattern) {
26944 + && (v & p->token) == p->token) {
26945 + *val &= ~p->token;
26946 + return p->pattern;
26955 +/* ---------------------------------------------------------------------- */
26957 +static match_table_t brperm = {
26958 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26959 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26960 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26964 +static match_table_t brattr = {
26966 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26967 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26968 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26969 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26970 +#ifdef CONFIG_AUFS_FHSM
26971 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26973 +#ifdef CONFIG_AUFS_XATTR
26974 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26975 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26976 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26977 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26978 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26979 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26982 + /* ro/rr branch */
26983 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26986 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26987 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26992 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26999 + p = strchr(str, '+');
27002 + v = match_token(str, table, args);
27004 + if (v & AuBrAttr_CMOO_Mask)
27005 + attr &= ~AuBrAttr_CMOO_Mask;
27010 + pr_warn("ignored branch attribute %s\n", str);
27020 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27028 + p = au_optstr(&perm, brattr);
27031 + memcpy(q, p, sz + 1);
27037 + p = au_optstr(&perm, brattr);
27041 + memcpy(q, p, sz + 1);
27047 + return q - str->a;
27050 +int au_br_perm_val(char *perm)
27052 + int val, bad, sz;
27054 + substring_t args[MAX_OPT_ARGS];
27055 + au_br_perm_str_t attr;
27057 + p = strchr(perm, '+');
27060 + val = match_token(perm, brperm, args);
27064 + pr_warn("ignored branch permission %s\n", perm);
27065 + val = AuBrPerm_RO;
27071 + val |= br_attr_val(p + 1, brattr, args);
27074 + switch (val & AuBrPerm_Mask) {
27075 + case AuBrPerm_RO:
27076 + case AuBrPerm_RR:
27077 + bad = val & AuBrWAttr_Mask;
27078 + val &= ~AuBrWAttr_Mask;
27080 + case AuBrPerm_RW:
27081 + bad = val & AuBrRAttr_Mask;
27082 + val &= ~AuBrRAttr_Mask;
27087 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27088 + * does not treat it as an error, just warning.
27089 + * this is a tiny guard for the user operation.
27091 + if (val & AuBrAttr_UNPIN) {
27092 + bad |= AuBrAttr_UNPIN;
27093 + val &= ~AuBrAttr_UNPIN;
27096 + if (unlikely(bad)) {
27097 + sz = au_do_optstr_br_attr(&attr, bad);
27099 + pr_warn("ignored branch attribute %s\n", attr.a);
27106 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27108 + au_br_perm_str_t attr;
27114 + p = au_optstr(&perm, brperm);
27115 + AuDebugOn(!p || !*p);
27117 + memcpy(q, p, sz + 1);
27120 + sz = au_do_optstr_br_attr(&attr, perm);
27123 + memcpy(q, attr.a, sz + 1);
27126 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27129 +/* ---------------------------------------------------------------------- */
27131 +static match_table_t udbalevel = {
27132 + {AuOpt_UDBA_REVAL, "reval"},
27133 + {AuOpt_UDBA_NONE, "none"},
27134 +#ifdef CONFIG_AUFS_HNOTIFY
27135 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27136 +#ifdef CONFIG_AUFS_HFSNOTIFY
27137 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27143 +int au_udba_val(char *str)
27145 + substring_t args[MAX_OPT_ARGS];
27147 + return match_token(str, udbalevel, args);
27150 +const char *au_optstr_udba(int udba)
27152 + return au_parser_pattern(udba, udbalevel);
27155 +/* ---------------------------------------------------------------------- */
27157 +static match_table_t au_wbr_create_policy = {
27158 + {AuWbrCreate_TDP, "tdp"},
27159 + {AuWbrCreate_TDP, "top-down-parent"},
27160 + {AuWbrCreate_RR, "rr"},
27161 + {AuWbrCreate_RR, "round-robin"},
27162 + {AuWbrCreate_MFS, "mfs"},
27163 + {AuWbrCreate_MFS, "most-free-space"},
27164 + {AuWbrCreate_MFSV, "mfs:%d"},
27165 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27167 + /* top-down regardless the parent, and then mfs */
27168 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27169 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27171 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27172 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27173 + {AuWbrCreate_PMFS, "pmfs"},
27174 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27175 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27176 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27181 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27182 + struct au_opt_wbr_create *create)
27185 + unsigned long long ull;
27188 + if (!match_u64(arg, &ull))
27189 + create->mfsrr_watermark = ull;
27191 + pr_err("bad integer in %s\n", str);
27198 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27199 + struct au_opt_wbr_create *create)
27204 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27205 + create->mfs_second = n;
27207 + pr_err("bad integer in %s\n", str);
27214 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27217 + substring_t args[MAX_OPT_ARGS];
27219 + err = match_token(str, au_wbr_create_policy, args);
27220 + create->wbr_create = err;
27222 + case AuWbrCreate_MFSRRV:
27223 + case AuWbrCreate_TDMFSV:
27224 + case AuWbrCreate_PMFSRRV:
27225 + e = au_wbr_mfs_wmark(&args[0], str, create);
27227 + e = au_wbr_mfs_sec(&args[1], str, create);
27231 + case AuWbrCreate_MFSRR:
27232 + case AuWbrCreate_TDMFS:
27233 + case AuWbrCreate_PMFSRR:
27234 + e = au_wbr_mfs_wmark(&args[0], str, create);
27235 + if (unlikely(e)) {
27240 + case AuWbrCreate_MFS:
27241 + case AuWbrCreate_PMFS:
27242 + create->mfs_second = AUFS_MFS_DEF_SEC;
27244 + case AuWbrCreate_MFSV:
27245 + case AuWbrCreate_PMFSV:
27246 + e = au_wbr_mfs_sec(&args[0], str, create);
27255 +const char *au_optstr_wbr_create(int wbr_create)
27257 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27260 +static match_table_t au_wbr_copyup_policy = {
27261 + {AuWbrCopyup_TDP, "tdp"},
27262 + {AuWbrCopyup_TDP, "top-down-parent"},
27263 + {AuWbrCopyup_BUP, "bup"},
27264 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27265 + {AuWbrCopyup_BU, "bu"},
27266 + {AuWbrCopyup_BU, "bottom-up"},
27270 +int au_wbr_copyup_val(char *str)
27272 + substring_t args[MAX_OPT_ARGS];
27274 + return match_token(str, au_wbr_copyup_policy, args);
27277 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27279 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27282 +/* ---------------------------------------------------------------------- */
27284 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27285 + aufs_bindex_t bindex)
27288 + struct au_opt_add *add = &opt->add;
27291 + add->bindex = bindex;
27292 + add->perm = AuBrPerm_RO;
27293 + add->pathname = opt_str;
27294 + p = strchr(opt_str, '=');
27298 + add->perm = au_br_perm_val(p);
27301 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27304 + add->perm = AuBrPerm_RO;
27305 + if (au_test_fs_rr(add->path.dentry->d_sb))
27306 + add->perm = AuBrPerm_RR;
27307 + else if (!bindex && !(sb_flags & SB_RDONLY))
27308 + add->perm = AuBrPerm_RW;
27310 + opt->type = Opt_add;
27313 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27320 +static int au_opt_wbr_create(struct super_block *sb,
27321 + struct au_opt_wbr_create *create)
27324 + struct au_sbinfo *sbinfo;
27326 + SiMustWriteLock(sb);
27328 + err = 1; /* handled */
27329 + sbinfo = au_sbi(sb);
27330 + if (sbinfo->si_wbr_create_ops->fin) {
27331 + err = sbinfo->si_wbr_create_ops->fin(sb);
27336 + sbinfo->si_wbr_create = create->wbr_create;
27337 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27338 + switch (create->wbr_create) {
27339 + case AuWbrCreate_MFSRRV:
27340 + case AuWbrCreate_MFSRR:
27341 + case AuWbrCreate_TDMFS:
27342 + case AuWbrCreate_TDMFSV:
27343 + case AuWbrCreate_PMFSRR:
27344 + case AuWbrCreate_PMFSRRV:
27345 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27347 + case AuWbrCreate_MFS:
27348 + case AuWbrCreate_MFSV:
27349 + case AuWbrCreate_PMFS:
27350 + case AuWbrCreate_PMFSV:
27351 + sbinfo->si_wbr_mfs.mfs_expire
27352 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27356 + if (sbinfo->si_wbr_create_ops->init)
27357 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27364 + * plus: processed without an error
27365 + * zero: unprocessed
27367 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27368 + struct au_opts *opts)
27371 + struct au_sbinfo *sbinfo;
27373 + SiMustWriteLock(sb);
27375 + err = 1; /* handled */
27376 + sbinfo = au_sbi(sb);
27377 + switch (opt->type) {
27379 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27380 + sbinfo->si_mntflags |= opt->udba;
27381 + opts->given_udba |= opt->udba;
27386 + au_opt_set(sbinfo->si_mntflags, PLINK);
27388 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27389 + au_plink_put(sb, /*verbose*/1);
27390 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27393 + case Opt_list_plink:
27394 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27395 + au_plink_list(sb);
27400 + au_opt_set(sbinfo->si_mntflags, DIO);
27401 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27403 + au_opt_clr(sbinfo->si_mntflags, DIO);
27404 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27408 + case Opt_fhsm_sec:
27409 + au_fhsm_set(sbinfo, opt->fhsm_second);
27412 + case Opt_diropq_a:
27413 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27415 + case Opt_diropq_w:
27416 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27419 + case Opt_warn_perm:
27421 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27423 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27426 + case Opt_verbose:
27428 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27430 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27435 + au_opt_set(sbinfo->si_mntflags, SUM);
27437 + au_opt_clr(sbinfo->si_mntflags, SUM);
27438 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27442 + au_opt_clr(sbinfo->si_mntflags, SUM);
27443 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27446 + case Opt_wbr_create:
27447 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27449 + case Opt_wbr_copyup:
27450 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27451 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27455 + sbinfo->si_dirwh = opt->dirwh;
27458 + case Opt_rdcache:
27459 + sbinfo->si_rdcache
27460 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27463 + sbinfo->si_rdblk = opt->rdblk;
27466 + sbinfo->si_rdhash = opt->rdhash;
27471 + au_opt_set(sbinfo->si_mntflags, SHWH);
27473 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27476 + case Opt_dirperm1:
27478 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27480 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27483 + case Opt_trunc_xino:
27485 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27487 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27490 + case Opt_trunc_xino_path:
27491 + case Opt_itrunc_xino:
27492 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27498 + case Opt_trunc_xib:
27500 + au_fset_opts(opts->flags, TRUNC_XIB);
27502 + au_fclr_opts(opts->flags, TRUNC_XIB);
27508 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27509 + err = au_dr_opt_set(sb);
27514 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27516 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27517 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27523 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27529 + sb->s_flags |= SB_POSIXACL;
27531 + sb->s_flags &= ~SB_POSIXACL;
27543 + * returns tri-state.
27544 + * plus: processed without an error
27545 + * zero: unprocessed
27548 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27549 + struct au_opts *opts)
27551 + int err, do_refresh;
27554 + switch (opt->type) {
27556 + opt->add.bindex = au_sbbot(sb) + 1;
27557 + if (opt->add.bindex < 0)
27558 + opt->add.bindex = 0;
27560 + /* Always goto add, not fallthrough */
27561 + case Opt_prepend:
27562 + opt->add.bindex = 0;
27564 + add: /* indented label */
27566 + err = au_br_add(sb, &opt->add,
27567 + au_ftest_opts(opts->flags, REMOUNT));
27570 + au_fset_opts(opts->flags, REFRESH);
27576 + err = au_br_del(sb, &opt->del,
27577 + au_ftest_opts(opts->flags, REMOUNT));
27580 + au_fset_opts(opts->flags, TRUNC_XIB);
27581 + au_fset_opts(opts->flags, REFRESH);
27587 + err = au_br_mod(sb, &opt->mod,
27588 + au_ftest_opts(opts->flags, REMOUNT),
27593 + au_fset_opts(opts->flags, REFRESH);
27600 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27601 + struct au_opt_xino **opt_xino,
27602 + struct au_opts *opts)
27607 + switch (opt->type) {
27609 + err = au_xino_set(sb, &opt->xino,
27610 + !!au_ftest_opts(opts->flags, REMOUNT));
27612 + *opt_xino = &opt->xino;
27616 + *opt_xino = (void *)-1;
27623 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27624 + unsigned int pending)
27627 + aufs_bindex_t bindex, bbot;
27628 + unsigned char do_plink, skip, do_free, can_no_dreval;
27629 + struct au_branch *br;
27630 + struct au_wbr *wbr;
27631 + struct dentry *root, *dentry;
27632 + struct inode *dir, *h_dir;
27633 + struct au_sbinfo *sbinfo;
27634 + struct au_hinode *hdir;
27636 + SiMustAnyLock(sb);
27638 + sbinfo = au_sbi(sb);
27639 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27641 + if (!(sb_flags & SB_RDONLY)) {
27642 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27643 + pr_warn("first branch should be rw\n");
27644 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27645 + pr_warn_once("shwh should be used with ro\n");
27648 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27649 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27650 + pr_warn_once("udba=*notify requires xino\n");
27652 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27653 + pr_warn_once("dirperm1 breaks the protection"
27654 + " by the permission bits on the lower branch\n");
27658 + root = sb->s_root;
27659 + dir = d_inode(root);
27660 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27661 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27663 + bbot = au_sbbot(sb);
27664 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27666 + h_dir = au_h_iptr(dir, bindex);
27667 + br = au_sbr(sb, bindex);
27669 + if ((br->br_perm & AuBrAttr_ICEX)
27670 + && !h_dir->i_op->listxattr)
27671 + br->br_perm &= ~AuBrAttr_ICEX;
27672 +#if 0 /* untested */
27673 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27674 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27675 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27679 + wbr = br->br_wbr;
27681 + wbr_wh_read_lock(wbr);
27683 + if (!au_br_writable(br->br_perm)) {
27686 + || (!wbr->wbr_whbase
27687 + && !wbr->wbr_plink
27688 + && !wbr->wbr_orph));
27689 + } else if (!au_br_wh_linkable(br->br_perm)) {
27690 + /* skip = (!br->br_whbase && !br->br_orph); */
27691 + skip = (!wbr || !wbr->wbr_whbase);
27692 + if (skip && wbr) {
27694 + skip = !!wbr->wbr_plink;
27696 + skip = !wbr->wbr_plink;
27699 + /* skip = (br->br_whbase && br->br_ohph); */
27700 + skip = (wbr && wbr->wbr_whbase);
27703 + skip = !!wbr->wbr_plink;
27705 + skip = !wbr->wbr_plink;
27709 + wbr_wh_read_unlock(wbr);
27711 + if (can_no_dreval) {
27712 + dentry = br->br_path.dentry;
27713 + spin_lock(&dentry->d_lock);
27714 + if (dentry->d_flags &
27715 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27716 + can_no_dreval = 0;
27717 + spin_unlock(&dentry->d_lock);
27720 + if (au_br_fhsm(br->br_perm)) {
27722 + AuDebugOn(!br->br_fhsm);
27728 + hdir = au_hi(dir, bindex);
27729 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27731 + wbr_wh_write_lock(wbr);
27732 + err = au_wh_init(br, sb);
27734 + wbr_wh_write_unlock(wbr);
27735 + au_hn_inode_unlock(hdir);
27737 + if (!err && do_free) {
27738 + au_kfree_rcu(wbr);
27739 + br->br_wbr = NULL;
27743 + if (can_no_dreval)
27744 + au_fset_si(sbinfo, NO_DREVAL);
27746 + au_fclr_si(sbinfo, NO_DREVAL);
27749 + au_fset_si(sbinfo, FHSM);
27750 + for (bindex = bbot; bindex >= 0; bindex--) {
27751 + br = au_sbr(sb, bindex);
27752 + if (au_br_fhsm(br->br_perm)) {
27753 + au_fhsm_set_bottom(sb, bindex);
27758 + au_fclr_si(sbinfo, FHSM);
27759 + au_fhsm_set_bottom(sb, -1);
27765 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27768 + unsigned int tmp;
27769 + aufs_bindex_t bindex, bbot;
27770 + struct au_opt *opt;
27771 + struct au_opt_xino *opt_xino, xino;
27772 + struct au_sbinfo *sbinfo;
27773 + struct au_branch *br;
27774 + struct inode *dir;
27776 + SiMustWriteLock(sb);
27781 + while (err >= 0 && opt->type != Opt_tail)
27782 + err = au_opt_simple(sb, opt++, opts);
27785 + else if (unlikely(err < 0))
27788 + /* disable xino and udba temporary */
27789 + sbinfo = au_sbi(sb);
27790 + tmp = sbinfo->si_mntflags;
27791 + au_opt_clr(sbinfo->si_mntflags, XINO);
27792 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27795 + while (err >= 0 && opt->type != Opt_tail)
27796 + err = au_opt_br(sb, opt++, opts);
27799 + else if (unlikely(err < 0))
27802 + bbot = au_sbbot(sb);
27803 + if (unlikely(bbot < 0)) {
27805 + pr_err("no branches\n");
27809 + if (au_opt_test(tmp, XINO))
27810 + au_opt_set(sbinfo->si_mntflags, XINO);
27812 + while (!err && opt->type != Opt_tail)
27813 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27814 + if (unlikely(err))
27817 + err = au_opts_verify(sb, sb->s_flags, tmp);
27818 + if (unlikely(err))
27821 + /* restore xino */
27822 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27823 + xino.file = au_xino_def(sb);
27824 + err = PTR_ERR(xino.file);
27825 + if (IS_ERR(xino.file))
27828 + err = au_xino_set(sb, &xino, /*remount*/0);
27830 + if (unlikely(err))
27834 + /* restore udba */
27835 + tmp &= AuOptMask_UDBA;
27836 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27837 + sbinfo->si_mntflags |= tmp;
27838 + bbot = au_sbbot(sb);
27839 + for (bindex = 0; bindex <= bbot; bindex++) {
27840 + br = au_sbr(sb, bindex);
27841 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27842 + if (unlikely(err))
27843 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27845 + /* go on even if err */
27847 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27848 + dir = d_inode(sb->s_root);
27849 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27856 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27859 + unsigned char no_dreval;
27860 + struct inode *dir;
27861 + struct au_opt_xino *opt_xino;
27862 + struct au_opt *opt;
27863 + struct au_sbinfo *sbinfo;
27865 + SiMustWriteLock(sb);
27867 + err = au_dr_opt_flush(sb);
27868 + if (unlikely(err))
27870 + au_fset_opts(opts->flags, DR_FLUSHED);
27872 + dir = d_inode(sb->s_root);
27873 + sbinfo = au_sbi(sb);
27876 + while (err >= 0 && opt->type != Opt_tail) {
27877 + err = au_opt_simple(sb, opt, opts);
27879 + err = au_opt_br(sb, opt, opts);
27881 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27887 + /* go on even err */
27889 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27890 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27891 + if (unlikely(rerr && !err))
27894 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27895 + au_fset_opts(opts->flags, REFRESH_IDOP);
27897 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27898 + rerr = au_xib_trunc(sb);
27899 + if (unlikely(rerr && !err))
27903 + /* will be handled by the caller */
27904 + if (!au_ftest_opts(opts->flags, REFRESH)
27905 + && (opts->given_udba
27906 + || au_opt_test(sbinfo->si_mntflags, XINO)
27907 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27909 + au_fset_opts(opts->flags, REFRESH);
27911 + AuDbg("status 0x%x\n", opts->flags);
27917 +/* ---------------------------------------------------------------------- */
27919 +unsigned int au_opt_udba(struct super_block *sb)
27921 + return au_mntflags(sb) & AuOptMask_UDBA;
27923 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27924 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27925 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27927 +/* SPDX-License-Identifier: GPL-2.0 */
27929 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27931 + * This program is free software; you can redistribute it and/or modify
27932 + * it under the terms of the GNU General Public License as published by
27933 + * the Free Software Foundation; either version 2 of the License, or
27934 + * (at your option) any later version.
27936 + * This program is distributed in the hope that it will be useful,
27937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27939 + * GNU General Public License for more details.
27941 + * You should have received a copy of the GNU General Public License
27942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27946 + * mount options/flags
27949 +#ifndef __AUFS_OPTS_H__
27950 +#define __AUFS_OPTS_H__
27954 +#include <linux/fs_parser.h>
27955 +#include <linux/namei.h>
27956 +#include <linux/path.h>
27960 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27961 + Opt_idel, Opt_imod,
27962 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27963 + Opt_xino, Opt_noxino,
27964 + Opt_trunc_xino, Opt_trunc_xino_v,
27965 + Opt_trunc_xino_path, Opt_itrunc_xino,
27968 + Opt_plink, Opt_list_plink,
27971 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27973 + Opt_wbr_copyup, Opt_wbr_create,
27975 + Opt_verbose, Opt_noverbose,
27976 + Opt_sum, Opt_wsum,
27980 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27983 +/* ---------------------------------------------------------------------- */
27986 +#define AuOpt_XINO 1 /* external inode number bitmap
27987 + and translation table */
27988 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27989 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27990 +#define AuOpt_UDBA_REVAL (1 << 3)
27991 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27992 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27993 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27994 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27996 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27997 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27998 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27999 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
28000 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
28001 +#define AuOpt_DIO (1 << 14) /* direct io */
28002 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
28004 +#ifndef CONFIG_AUFS_HNOTIFY
28005 +#undef AuOpt_UDBA_HNOTIFY
28006 +#define AuOpt_UDBA_HNOTIFY 0
28008 +#ifndef CONFIG_AUFS_DIRREN
28009 +#undef AuOpt_DIRREN
28010 +#define AuOpt_DIRREN 0
28012 +#ifndef CONFIG_AUFS_SHWH
28014 +#define AuOpt_SHWH 0
28017 +#define AuOpt_Def (AuOpt_XINO \
28018 + | AuOpt_UDBA_REVAL \
28020 + /* | AuOpt_DIRPERM1 */ \
28021 + | AuOpt_WARN_PERM)
28022 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28023 + | AuOpt_UDBA_REVAL \
28024 + | AuOpt_UDBA_HNOTIFY)
28026 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28028 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28029 +#define au_opt_set(flags, name) do { \
28030 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28031 + ((flags) |= AuOpt_##name); \
28033 +#define au_opt_set_udba(flags, name) do { \
28034 + (flags) &= ~AuOptMask_UDBA; \
28035 + ((flags) |= AuOpt_##name); \
28037 +#define au_opt_clr(flags, name) do { \
28038 + ((flags) &= ~AuOpt_##name); \
28041 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28043 +#ifdef CONFIG_PROC_FS
28046 + return mntflags & ~AuOpt_PLINK;
28050 +/* ---------------------------------------------------------------------- */
28052 +/* policies to select one among multiple writable branches */
28054 + AuWbrCreate_TDP, /* top down parent */
28055 + AuWbrCreate_RR, /* round robin */
28056 + AuWbrCreate_MFS, /* most free space */
28057 + AuWbrCreate_MFSV, /* mfs with seconds */
28058 + AuWbrCreate_MFSRR, /* mfs then rr */
28059 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28060 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28061 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28062 + AuWbrCreate_PMFS, /* parent and mfs */
28063 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28064 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28065 + AuWbrCreate_PMFSRRV, /* plus seconds */
28067 + AuWbrCreate_Def = AuWbrCreate_TDP
28071 + AuWbrCopyup_TDP, /* top down parent */
28072 + AuWbrCopyup_BUP, /* bottom up parent */
28073 + AuWbrCopyup_BU, /* bottom up */
28075 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28078 +/* ---------------------------------------------------------------------- */
28082 +struct au_opt_add {
28083 + aufs_bindex_t bindex;
28086 + struct path path;
28089 +struct au_opt_del {
28091 + struct path h_path;
28094 +struct au_opt_mod {
28097 + struct dentry *h_root;
28100 +struct au_opt_xino {
28102 + struct file *file;
28105 +struct au_opt_xino_itrunc {
28106 + aufs_bindex_t bindex;
28109 +struct au_opt_wbr_create {
28112 + unsigned long long mfsrr_watermark;
28118 + struct au_opt_xino xino;
28119 + struct au_opt_xino_itrunc xino_itrunc;
28120 + struct au_opt_add add;
28121 + struct au_opt_del del;
28122 + struct au_opt_mod mod;
28125 + unsigned int rdblk;
28126 + unsigned int rdhash;
28128 + struct au_opt_wbr_create wbr_create;
28130 + unsigned int fhsm_second;
28131 + bool tf; /* generic flag, true or false */
28136 +#define AuOpts_REMOUNT 1
28137 +#define AuOpts_REFRESH (1 << 1)
28138 +#define AuOpts_TRUNC_XIB (1 << 2)
28139 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28140 +#define AuOpts_REFRESH_IDOP (1 << 4)
28141 +#define AuOpts_DR_FLUSHED (1 << 5)
28142 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28143 +#define au_fset_opts(flags, name) \
28144 + do { (flags) |= AuOpts_##name; } while (0)
28145 +#define au_fclr_opts(flags, name) \
28146 + do { (flags) &= ~AuOpts_##name; } while (0)
28148 +#ifndef CONFIG_AUFS_DIRREN
28149 +#undef AuOpts_DR_FLUSHED
28150 +#define AuOpts_DR_FLUSHED 0
28154 + struct au_opt *opt;
28157 + unsigned int given_udba;
28158 + unsigned int flags;
28159 + unsigned long sb_flags;
28162 +/* ---------------------------------------------------------------------- */
28165 +int au_br_perm_val(char *perm);
28166 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28167 +int au_udba_val(char *str);
28168 +const char *au_optstr_udba(int udba);
28169 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28170 +const char *au_optstr_wbr_create(int wbr_create);
28171 +int au_wbr_copyup_val(char *str);
28172 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28174 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28175 + aufs_bindex_t bindex);
28176 +struct super_block;
28177 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28178 + unsigned int pending);
28179 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28180 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28182 +unsigned int au_opt_udba(struct super_block *sb);
28185 +int aufs_fsctx_init(struct fs_context *fc);
28186 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28188 +#endif /* __KERNEL__ */
28189 +#endif /* __AUFS_OPTS_H__ */
28190 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28191 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28192 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28194 +// SPDX-License-Identifier: GPL-2.0
28196 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28198 + * This program is free software; you can redistribute it and/or modify
28199 + * it under the terms of the GNU General Public License as published by
28200 + * the Free Software Foundation; either version 2 of the License, or
28201 + * (at your option) any later version.
28203 + * This program is distributed in the hope that it will be useful,
28204 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28205 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28206 + * GNU General Public License for more details.
28208 + * You should have received a copy of the GNU General Public License
28209 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28219 + * the pseudo-link maintenance mode.
28220 + * during a user process maintains the pseudo-links,
28221 + * prohibit adding a new plink and branch manipulation.
28225 + * For entry functions which will handle plink, and i_mutex is already held
28227 + * They cannot wait and should return an error at once.
28228 + * Callers has to check the error.
28230 + * For entry functions which will handle plink, but i_mutex is not held
28232 + * They can wait the plink maintenance mode to finish.
28234 + * They behave like F_SETLK and F_SETLKW.
28235 + * If the caller never handle plink, then both flags are unnecessary.
28238 +int au_plink_maint(struct super_block *sb, int flags)
28242 + struct task_struct *parent, *prev;
28243 + struct au_sbinfo *sbi;
28245 + SiMustAnyLock(sb);
28248 + if (!au_opt_test(au_mntflags(sb), PLINK))
28251 + sbi = au_sbi(sb);
28252 + pid = sbi->si_plink_maint_pid;
28253 + if (!pid || pid == current->pid)
28256 + /* todo: it highly depends upon /sbin/mount.aufs */
28258 + parent = current;
28262 + parent = rcu_dereference(parent->real_parent);
28263 + if (parent == prev)
28265 + ppid = task_pid_vnr(parent);
28266 + if (pid == ppid) {
28267 + rcu_read_unlock();
28272 + rcu_read_unlock();
28274 + if (au_ftest_lock(flags, NOPLMW)) {
28275 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28276 + /* AuDebugOn(!lockdep_depth(current)); */
28277 + while (sbi->si_plink_maint_pid) {
28278 + si_read_unlock(sb);
28279 + /* gave up wake_up_bit() */
28280 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28282 + if (au_ftest_lock(flags, FLUSH))
28283 + au_nwt_flush(&sbi->si_nowait);
28284 + si_noflush_read_lock(sb);
28286 + } else if (au_ftest_lock(flags, NOPLM)) {
28287 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28295 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28297 + spin_lock(&sbinfo->si_plink_maint_lock);
28298 + sbinfo->si_plink_maint_pid = 0;
28299 + spin_unlock(&sbinfo->si_plink_maint_lock);
28300 + wake_up_all(&sbinfo->si_plink_wq);
28303 +int au_plink_maint_enter(struct super_block *sb)
28306 + struct au_sbinfo *sbinfo;
28309 + sbinfo = au_sbi(sb);
28310 + /* make sure i am the only one in this fs */
28311 + si_write_lock(sb, AuLock_FLUSH);
28312 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28313 + spin_lock(&sbinfo->si_plink_maint_lock);
28314 + if (!sbinfo->si_plink_maint_pid)
28315 + sbinfo->si_plink_maint_pid = current->pid;
28318 + spin_unlock(&sbinfo->si_plink_maint_lock);
28320 + si_write_unlock(sb);
28325 +/* ---------------------------------------------------------------------- */
28327 +#ifdef CONFIG_AUFS_DEBUG
28328 +void au_plink_list(struct super_block *sb)
28331 + struct au_sbinfo *sbinfo;
28332 + struct hlist_bl_head *hbl;
28333 + struct hlist_bl_node *pos;
28334 + struct au_icntnr *icntnr;
28336 + SiMustAnyLock(sb);
28338 + sbinfo = au_sbi(sb);
28339 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28340 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28342 + for (i = 0; i < AuPlink_NHASH; i++) {
28343 + hbl = sbinfo->si_plink + i;
28344 + hlist_bl_lock(hbl);
28345 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28346 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28347 + hlist_bl_unlock(hbl);
28352 +/* is the inode pseudo-linked? */
28353 +int au_plink_test(struct inode *inode)
28356 + struct au_sbinfo *sbinfo;
28357 + struct hlist_bl_head *hbl;
28358 + struct hlist_bl_node *pos;
28359 + struct au_icntnr *icntnr;
28361 + sbinfo = au_sbi(inode->i_sb);
28362 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28363 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28364 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28367 + i = au_plink_hash(inode->i_ino);
28368 + hbl = sbinfo->si_plink + i;
28369 + hlist_bl_lock(hbl);
28370 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28371 + if (&icntnr->vfs_inode == inode) {
28375 + hlist_bl_unlock(hbl);
28379 +/* ---------------------------------------------------------------------- */
28382 + * generate a name for plink.
28383 + * the file will be stored under AUFS_WH_PLINKDIR.
28385 +/* 20 is max digits length of ulong 64 */
28386 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28388 +static int plink_name(char *name, int len, struct inode *inode,
28389 + aufs_bindex_t bindex)
28392 + struct inode *h_inode;
28394 + h_inode = au_h_iptr(inode, bindex);
28395 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28399 +struct au_do_plink_lkup_args {
28400 + struct dentry **errp;
28401 + struct qstr *tgtname;
28402 + struct path *h_ppath;
28405 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28406 + struct path *h_ppath)
28408 + struct dentry *h_dentry;
28409 + struct inode *h_inode;
28411 + h_inode = d_inode(h_ppath->dentry);
28412 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28413 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28414 + inode_unlock_shared(h_inode);
28419 +static void au_call_do_plink_lkup(void *args)
28421 + struct au_do_plink_lkup_args *a = args;
28422 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28425 +/* lookup the plink-ed @inode under the branch at @bindex */
28426 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28428 + struct dentry *h_dentry;
28429 + struct au_branch *br;
28430 + struct path h_ppath;
28432 + char a[PLINK_NAME_LEN];
28433 + struct qstr tgtname = QSTR_INIT(a, 0);
28435 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28437 + br = au_sbr(inode->i_sb, bindex);
28438 + h_ppath.dentry = br->br_wbr->wbr_plink;
28439 + h_ppath.mnt = au_br_mnt(br);
28440 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28442 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28443 + struct au_do_plink_lkup_args args = {
28444 + .errp = &h_dentry,
28445 + .tgtname = &tgtname,
28446 + .h_ppath = &h_ppath
28449 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28450 + if (unlikely(wkq_err))
28451 + h_dentry = ERR_PTR(wkq_err);
28453 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28458 +/* create a pseudo-link */
28459 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28460 + struct dentry *h_dentry)
28463 + struct path h_path;
28464 + struct inode *h_dir, *delegated;
28466 + h_dir = d_inode(h_ppath->dentry);
28467 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28468 + h_path.mnt = h_ppath->mnt;
28470 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28471 + err = PTR_ERR(h_path.dentry);
28472 + if (IS_ERR(h_path.dentry))
28476 + /* wh.plink dir is not monitored */
28477 + /* todo: is it really safe? */
28478 + if (d_is_positive(h_path.dentry)
28479 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28480 + delegated = NULL;
28481 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28482 + if (unlikely(err == -EWOULDBLOCK)) {
28483 + pr_warn("cannot retry for NFSv4 delegation"
28484 + " for an internal unlink\n");
28487 + dput(h_path.dentry);
28488 + h_path.dentry = NULL;
28492 + if (!err && d_is_negative(h_path.dentry)) {
28493 + delegated = NULL;
28494 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28495 + if (unlikely(err == -EWOULDBLOCK)) {
28496 + pr_warn("cannot retry for NFSv4 delegation"
28497 + " for an internal link\n");
28501 + dput(h_path.dentry);
28504 + inode_unlock(h_dir);
28508 +struct do_whplink_args {
28510 + struct qstr *tgt;
28511 + struct path *h_ppath;
28512 + struct dentry *h_dentry;
28515 +static void call_do_whplink(void *args)
28517 + struct do_whplink_args *a = args;
28518 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28521 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28522 + aufs_bindex_t bindex)
28524 + int err, wkq_err;
28525 + struct au_branch *br;
28526 + struct au_wbr *wbr;
28527 + struct path h_ppath;
28528 + char a[PLINK_NAME_LEN];
28529 + struct qstr tgtname = QSTR_INIT(a, 0);
28531 + br = au_sbr(inode->i_sb, bindex);
28532 + wbr = br->br_wbr;
28533 + h_ppath.dentry = wbr->wbr_plink;
28534 + h_ppath.mnt = au_br_mnt(br);
28535 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28537 + /* always superio. */
28538 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28539 + struct do_whplink_args args = {
28542 + .h_ppath = &h_ppath,
28543 + .h_dentry = h_dentry
28545 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28546 + if (unlikely(wkq_err))
28549 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28555 + * create a new pseudo-link for @h_dentry on @bindex.
28556 + * the linked inode is held in aufs @inode.
28558 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28559 + struct dentry *h_dentry)
28561 + struct super_block *sb;
28562 + struct au_sbinfo *sbinfo;
28563 + struct hlist_bl_head *hbl;
28564 + struct hlist_bl_node *pos;
28565 + struct au_icntnr *icntnr;
28566 + int found, err, cnt, i;
28568 + sb = inode->i_sb;
28569 + sbinfo = au_sbi(sb);
28570 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28571 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28573 + found = au_plink_test(inode);
28577 + i = au_plink_hash(inode->i_ino);
28578 + hbl = sbinfo->si_plink + i;
28581 + hlist_bl_lock(hbl);
28582 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28583 + if (&icntnr->vfs_inode == inode) {
28589 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28590 + hlist_bl_add_head(&icntnr->plink, hbl);
28592 + hlist_bl_unlock(hbl);
28594 + cnt = au_hbl_count(hbl);
28595 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28596 + if (cnt > AUFS_PLINK_WARN)
28597 + AuWarn1(msg ", %d\n", cnt);
28599 + err = whplink(h_dentry, inode, bindex);
28600 + if (unlikely(err)) {
28601 + pr_warn("err %d, damaged pseudo link.\n", err);
28602 + au_hbl_del(&icntnr->plink, hbl);
28603 + iput(&icntnr->vfs_inode);
28606 + iput(&icntnr->vfs_inode);
28609 +/* free all plinks */
28610 +void au_plink_put(struct super_block *sb, int verbose)
28613 + struct au_sbinfo *sbinfo;
28614 + struct hlist_bl_head *hbl;
28615 + struct hlist_bl_node *pos, *tmp;
28616 + struct au_icntnr *icntnr;
28618 + SiMustWriteLock(sb);
28620 + sbinfo = au_sbi(sb);
28621 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28622 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28624 + /* no spin_lock since sbinfo is write-locked */
28626 + for (i = 0; i < AuPlink_NHASH; i++) {
28627 + hbl = sbinfo->si_plink + i;
28628 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28629 + pr_warn("pseudo-link is not flushed");
28632 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28633 + iput(&icntnr->vfs_inode);
28634 + INIT_HLIST_BL_HEAD(hbl);
28638 +void au_plink_clean(struct super_block *sb, int verbose)
28640 + struct dentry *root;
28642 + root = sb->s_root;
28643 + aufs_write_lock(root);
28644 + if (au_opt_test(au_mntflags(sb), PLINK))
28645 + au_plink_put(sb, verbose);
28646 + aufs_write_unlock(root);
28649 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28652 + aufs_bindex_t btop, bbot, bindex;
28655 + btop = au_ibtop(inode);
28656 + bbot = au_ibbot(inode);
28658 + for (bindex = btop; bindex <= bbot; bindex++) {
28659 + if (!au_h_iptr(inode, bindex)
28660 + || au_ii_br_id(inode, bindex) != br_id)
28662 + au_set_h_iptr(inode, bindex, NULL, 0);
28667 + for (bindex = btop; bindex <= bbot; bindex++)
28668 + if (au_h_iptr(inode, bindex)) {
28678 +/* free the plinks on a branch specified by @br_id */
28679 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28681 + struct au_sbinfo *sbinfo;
28682 + struct hlist_bl_head *hbl;
28683 + struct hlist_bl_node *pos, *tmp;
28684 + struct au_icntnr *icntnr;
28685 + struct inode *inode;
28688 + SiMustWriteLock(sb);
28690 + sbinfo = au_sbi(sb);
28691 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28692 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28694 + /* no bit_lock since sbinfo is write-locked */
28695 + for (i = 0; i < AuPlink_NHASH; i++) {
28696 + hbl = sbinfo->si_plink + i;
28697 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28698 + inode = au_igrab(&icntnr->vfs_inode);
28699 + ii_write_lock_child(inode);
28700 + do_put = au_plink_do_half_refresh(inode, br_id);
28702 + hlist_bl_del(&icntnr->plink);
28705 + ii_write_unlock(inode);
28710 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28711 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28712 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28714 +// SPDX-License-Identifier: GPL-2.0
28716 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28718 + * This program is free software; you can redistribute it and/or modify
28719 + * it under the terms of the GNU General Public License as published by
28720 + * the Free Software Foundation; either version 2 of the License, or
28721 + * (at your option) any later version.
28723 + * This program is distributed in the hope that it will be useful,
28724 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28725 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28726 + * GNU General Public License for more details.
28728 + * You should have received a copy of the GNU General Public License
28729 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28734 + * There is only one filesystem which implements ->poll operation, currently.
28739 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28742 + struct file *h_file;
28743 + struct super_block *sb;
28745 + /* We should pretend an error happened. */
28746 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28747 + sb = file->f_path.dentry->d_sb;
28748 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28750 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28751 + if (IS_ERR(h_file)) {
28752 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28756 + mask = vfs_poll(h_file, pt);
28757 + fput(h_file); /* instead of au_read_post() */
28760 + si_read_unlock(sb);
28761 + if (mask & EPOLLERR)
28762 + AuDbg("mask 0x%x\n", mask);
28765 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28766 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28767 +++ linux/fs/aufs/posix_acl.c 2023-10-31 09:31:04.199880750 +0100
28769 +// SPDX-License-Identifier: GPL-2.0
28771 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28773 + * This program is free software; you can redistribute it and/or modify
28774 + * it under the terms of the GNU General Public License as published by
28775 + * the Free Software Foundation; either version 2 of the License, or
28776 + * (at your option) any later version.
28778 + * This program is distributed in the hope that it will be useful,
28779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28781 + * GNU General Public License for more details.
28783 + * You should have received a copy of the GNU General Public License
28784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28788 + * posix acl operations
28791 +#include <linux/fs.h>
28794 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu)
28796 + struct posix_acl *acl;
28798 + aufs_bindex_t bindex;
28799 + struct inode *h_inode;
28800 + struct super_block *sb;
28802 + acl = ERR_PTR(-ECHILD);
28807 + sb = inode->i_sb;
28808 + si_read_lock(sb, AuLock_FLUSH);
28809 + ii_read_lock_child(inode);
28810 + if (!(sb->s_flags & SB_POSIXACL))
28813 + bindex = au_ibtop(inode);
28814 + h_inode = au_h_iptr(inode, bindex);
28815 + if (unlikely(!h_inode
28816 + || ((h_inode->i_mode & S_IFMT)
28817 + != (inode->i_mode & S_IFMT)))) {
28818 + err = au_busy_or_stale();
28819 + acl = ERR_PTR(err);
28823 + /* always topmost only */
28824 + acl = get_inode_acl(h_inode, type);
28826 + forget_cached_acl(inode, type);
28828 + set_cached_acl(inode, type, acl);
28831 + ii_read_unlock(inode);
28832 + si_read_unlock(sb);
28835 + AuTraceErrPtr(acl);
28839 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
28840 + struct dentry *dentry, int type)
28842 + struct posix_acl *acl;
28843 + struct inode *inode;
28845 + inode = d_inode(dentry);
28846 + acl = aufs_get_inode_acl(inode, type, /*rcu*/false);
28851 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
28852 + struct posix_acl *acl, int type)
28856 + struct inode *inode;
28857 + struct au_sxattr arg = {
28858 + .type = AU_ACL_SET,
28865 + inode = d_inode(dentry);
28866 + IMustLock(inode);
28868 + ssz = au_sxattr(dentry, inode, &arg);
28869 + /* forget even it if succeeds since the branch might set differently */
28870 + forget_cached_acl(inode, type);
28877 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28878 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28879 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28881 +// SPDX-License-Identifier: GPL-2.0
28883 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28885 + * This program is free software; you can redistribute it and/or modify
28886 + * it under the terms of the GNU General Public License as published by
28887 + * the Free Software Foundation; either version 2 of the License, or
28888 + * (at your option) any later version.
28890 + * This program is distributed in the hope that it will be useful,
28891 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28892 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28893 + * GNU General Public License for more details.
28895 + * You should have received a copy of the GNU General Public License
28896 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28900 + * procfs interfaces
28903 +#include <linux/proc_fs.h>
28906 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28908 + struct au_sbinfo *sbinfo;
28910 + sbinfo = file->private_data;
28912 + au_plink_maint_leave(sbinfo);
28913 + kobject_put(&sbinfo->si_kobj);
28919 +static void au_procfs_plm_write_clean(struct file *file)
28921 + struct au_sbinfo *sbinfo;
28923 + sbinfo = file->private_data;
28925 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28928 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28931 + struct super_block *sb;
28932 + struct au_sbinfo *sbinfo;
28933 + struct hlist_bl_node *pos;
28936 + if (unlikely(file->private_data))
28940 + /* don't use au_sbilist_lock() here */
28941 + hlist_bl_lock(&au_sbilist);
28942 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28943 + if (id == sysaufs_si_id(sbinfo)) {
28944 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28945 + sb = sbinfo->si_sb;
28948 + hlist_bl_unlock(&au_sbilist);
28951 + if (unlikely(!sb))
28954 + err = au_plink_maint_enter(sb);
28956 + /* keep kobject_get() */
28957 + file->private_data = sbinfo;
28959 + kobject_put(&sbinfo->si_kobj);
28965 + * Accept a valid "si=xxxx" only.
28966 + * Once it is accepted successfully, accept "clean" too.
28968 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28969 + size_t count, loff_t *ppos)
28972 + unsigned long id;
28973 + /* last newline is allowed */
28974 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28977 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28981 + if (unlikely(count > sizeof(buf)))
28984 + err = copy_from_user(buf, ubuf, count);
28985 + if (unlikely(err)) {
28992 + if (!strcmp("clean", buf)) {
28993 + au_procfs_plm_write_clean(file);
28994 + goto out_success;
28995 + } else if (unlikely(strncmp("si=", buf, 3)))
28998 + err = kstrtoul(buf + 3, 16, &id);
28999 + if (unlikely(err))
29002 + err = au_procfs_plm_write_si(file, id);
29003 + if (unlikely(err))
29007 + err = count; /* success */
29012 +static const struct proc_ops au_procfs_plm_op = {
29013 + .proc_write = au_procfs_plm_write,
29014 + .proc_release = au_procfs_plm_release
29017 +/* ---------------------------------------------------------------------- */
29019 +static struct proc_dir_entry *au_procfs_dir;
29021 +void au_procfs_fin(void)
29023 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29024 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29027 +int __init au_procfs_init(void)
29030 + struct proc_dir_entry *entry;
29033 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29034 + if (unlikely(!au_procfs_dir))
29037 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29038 + au_procfs_dir, &au_procfs_plm_op);
29039 + if (unlikely(!entry))
29043 + goto out; /* success */
29047 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29051 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29052 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29053 +++ linux/fs/aufs/rdu.c 2023-10-31 09:31:04.199880750 +0100
29055 +// SPDX-License-Identifier: GPL-2.0
29057 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29059 + * This program is free software; you can redistribute it and/or modify
29060 + * it under the terms of the GNU General Public License as published by
29061 + * the Free Software Foundation; either version 2 of the License, or
29062 + * (at your option) any later version.
29064 + * This program is distributed in the hope that it will be useful,
29065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29067 + * GNU General Public License for more details.
29069 + * You should have received a copy of the GNU General Public License
29070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29074 + * readdir in userspace.
29077 +#include <linux/compat.h>
29078 +#include <linux/fs_stack.h>
29079 +#include <linux/security.h>
29082 +/* bits for struct aufs_rdu.flags */
29083 +#define AuRdu_CALLED 1
29084 +#define AuRdu_CONT (1 << 1)
29085 +#define AuRdu_FULL (1 << 2)
29086 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29087 +#define au_fset_rdu(flags, name) \
29088 + do { (flags) |= AuRdu_##name; } while (0)
29089 +#define au_fclr_rdu(flags, name) \
29090 + do { (flags) &= ~AuRdu_##name; } while (0)
29092 +struct au_rdu_arg {
29093 + struct dir_context ctx;
29094 + struct aufs_rdu *rdu;
29095 + union au_rdu_ent_ul ent;
29096 + unsigned long end;
29098 + struct super_block *sb;
29102 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29103 + loff_t offset, u64 h_ino, unsigned int d_type)
29106 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29107 + struct aufs_rdu *rdu = arg->rdu;
29108 + struct au_rdu_ent ent;
29112 + au_fset_rdu(rdu->cookie.flags, CALLED);
29113 + len = au_rdu_len(nlen);
29114 + if (arg->ent.ul + len < arg->end) {
29116 + ent.bindex = rdu->cookie.bindex;
29117 + ent.type = d_type;
29119 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29120 + ent.type = DT_UNKNOWN;
29122 + /* unnecessary to support mmap_sem since this is a dir */
29124 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29126 + if (copy_to_user(arg->ent.e->name, name, nlen))
29128 + /* the terminating NULL */
29129 + if (__put_user(0, arg->ent.e->name + nlen))
29132 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29133 + arg->ent.ul += len;
29137 + au_fset_rdu(rdu->cookie.flags, FULL);
29139 + rdu->tail = arg->ent;
29143 + /* AuTraceErr(err); */
29147 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29151 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29153 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29154 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29156 + if (unlikely(offset != cookie->h_pos))
29162 + au_fclr_rdu(cookie->flags, CALLED);
29164 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29168 + && au_ftest_rdu(cookie->flags, CALLED)
29169 + && !au_ftest_rdu(cookie->flags, FULL));
29170 + cookie->h_pos = h_file->f_pos;
29177 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29180 + aufs_bindex_t bbot;
29181 + struct au_rdu_arg arg = {
29183 + .actor = au_rdu_fill
29186 + struct dentry *dentry;
29187 + struct inode *inode;
29188 + struct file *h_file;
29189 + struct au_rdu_cookie *cookie = &rdu->cookie;
29191 + /* VERIFY_WRITE */
29192 + err = !access_ok(rdu->ent.e, rdu->sz);
29193 + if (unlikely(err)) {
29199 + rdu->tail = rdu->ent;
29202 + arg.ent = rdu->ent;
29203 + arg.end = arg.ent.ul;
29204 + arg.end += rdu->sz;
29207 + if (unlikely(!file->f_op->iterate_shared))
29210 + err = security_file_permission(file, MAY_READ);
29212 + if (unlikely(err))
29215 + dentry = file->f_path.dentry;
29216 + inode = d_inode(dentry);
29217 + inode_lock_shared(inode);
29219 + arg.sb = inode->i_sb;
29220 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29221 + if (unlikely(err))
29223 + err = au_alive_dir(dentry);
29224 + if (unlikely(err))
29226 + /* todo: reval? */
29227 + fi_read_lock(file);
29230 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29231 + && cookie->generation != au_figen(file)))
29236 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29238 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29240 + bbot = au_fbtop(file);
29241 + if (cookie->bindex < bbot)
29242 + cookie->bindex = bbot;
29243 + bbot = au_fbbot_dir(file);
29244 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29245 + for (; !err && cookie->bindex <= bbot;
29246 + cookie->bindex++, cookie->h_pos = 0) {
29247 + h_file = au_hf_dir(file, cookie->bindex);
29251 + au_fclr_rdu(cookie->flags, FULL);
29252 + err = au_rdu_do(h_file, &arg);
29254 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29257 + AuDbg("rent %llu\n", rdu->rent);
29259 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29260 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29261 + au_fset_rdu(cookie->flags, CONT);
29262 + cookie->generation = au_figen(file);
29265 + ii_read_lock_child(inode);
29266 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29267 + ii_read_unlock(inode);
29270 + fi_read_unlock(file);
29272 + si_read_unlock(arg.sb);
29274 + inode_unlock_shared(inode);
29280 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29284 + unsigned long long nent;
29285 + union au_rdu_ent_ul *u;
29286 + struct au_rdu_ent ent;
29287 + struct super_block *sb;
29290 + nent = rdu->nent;
29292 + sb = file->f_path.dentry->d_sb;
29293 + si_read_lock(sb, AuLock_FLUSH);
29294 + while (nent-- > 0) {
29295 + /* unnecessary to support mmap_sem since this is a dir */
29296 + err = copy_from_user(&ent, u->e, sizeof(ent));
29298 + /* VERIFY_WRITE */
29299 + err = !access_ok(&u->e->ino, sizeof(ino));
29300 + if (unlikely(err)) {
29306 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29308 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29310 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29312 + if (unlikely(err)) {
29317 + err = __put_user(ino, &u->e->ino);
29318 + if (unlikely(err)) {
29323 + u->ul += au_rdu_len(ent.nlen);
29325 + si_read_unlock(sb);
29330 +/* ---------------------------------------------------------------------- */
29332 +static int au_rdu_verify(struct aufs_rdu *rdu)
29334 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29335 + "%llu, b%d, 0x%x, g%u}\n",
29336 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29338 + rdu->rent, rdu->shwh, rdu->full,
29339 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29340 + rdu->cookie.generation);
29342 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29346 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29350 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29353 + struct aufs_rdu rdu;
29354 + void __user *p = (void __user *)arg;
29356 + err = copy_from_user(&rdu, p, sizeof(rdu));
29357 + if (unlikely(err)) {
29362 + err = au_rdu_verify(&rdu);
29363 + if (unlikely(err))
29367 + case AUFS_CTL_RDU:
29368 + err = au_rdu(file, &rdu);
29369 + if (unlikely(err))
29372 + e = copy_to_user(p, &rdu, sizeof(rdu));
29373 + if (unlikely(e)) {
29378 + case AUFS_CTL_RDU_INO:
29379 + err = au_rdu_ino(file, &rdu);
29383 + /* err = -ENOTTY; */
29392 +#ifdef CONFIG_COMPAT
29393 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29396 + struct aufs_rdu rdu;
29397 + void __user *p = compat_ptr(arg);
29399 + /* todo: get_user()? */
29400 + err = copy_from_user(&rdu, p, sizeof(rdu));
29401 + if (unlikely(err)) {
29406 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29407 + err = au_rdu_verify(&rdu);
29408 + if (unlikely(err))
29412 + case AUFS_CTL_RDU:
29413 + err = au_rdu(file, &rdu);
29414 + if (unlikely(err))
29417 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29418 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29419 + e = copy_to_user(p, &rdu, sizeof(rdu));
29420 + if (unlikely(e)) {
29425 + case AUFS_CTL_RDU_INO:
29426 + err = au_rdu_ino(file, &rdu);
29430 + /* err = -ENOTTY; */
29439 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29440 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29441 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29443 +/* SPDX-License-Identifier: GPL-2.0 */
29445 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29447 + * This program is free software; you can redistribute it and/or modify
29448 + * it under the terms of the GNU General Public License as published by
29449 + * the Free Software Foundation; either version 2 of the License, or
29450 + * (at your option) any later version.
29452 + * This program is distributed in the hope that it will be useful,
29453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29455 + * GNU General Public License for more details.
29457 + * You should have received a copy of the GNU General Public License
29458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29462 + * simple read-write semaphore wrappers
29465 +#ifndef __AUFS_RWSEM_H__
29466 +#define __AUFS_RWSEM_H__
29470 +#include "debug.h"
29472 +/* in the future, the name 'au_rwsem' will be totally gone */
29473 +#define au_rwsem rw_semaphore
29475 +/* to debug easier, do not make them inlined functions */
29476 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29478 +#ifdef CONFIG_LOCKDEP
29479 +/* rwsem_is_locked() is unusable */
29480 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29481 + && !lockdep_recursing(current) \
29483 + && !lockdep_is_held_type(rw, 1))
29484 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29485 + && !lockdep_recursing(current) \
29487 + && !lockdep_is_held_type(rw, 0))
29488 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29489 + && !lockdep_recursing(current) \
29491 + && !lockdep_is_held(rw))
29492 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29493 + && !lockdep_recursing(current) \
29495 + && lockdep_is_held(rw))
29497 +#define AuRwMustReadLock(rw) do {} while (0)
29498 +#define AuRwMustWriteLock(rw) do {} while (0)
29499 +#define AuRwMustAnyLock(rw) do {} while (0)
29500 +#define AuRwDestroy(rw) do {} while (0)
29503 +#define au_rw_init(rw) init_rwsem(rw)
29505 +#define au_rw_init_wlock(rw) do { \
29506 + au_rw_init(rw); \
29507 + down_write(rw); \
29510 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29511 + au_rw_init(rw); \
29512 + down_write_nested(rw, lsc); \
29515 +#define au_rw_read_lock(rw) down_read(rw)
29516 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29517 +#define au_rw_read_unlock(rw) up_read(rw)
29518 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29519 +#define au_rw_write_lock(rw) down_write(rw)
29520 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29521 +#define au_rw_write_unlock(rw) up_write(rw)
29522 +/* why is not _nested version defined? */
29523 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29524 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29526 +#endif /* __KERNEL__ */
29527 +#endif /* __AUFS_RWSEM_H__ */
29528 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29529 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29530 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29532 +// SPDX-License-Identifier: GPL-2.0
29534 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29536 + * This program is free software; you can redistribute it and/or modify
29537 + * it under the terms of the GNU General Public License as published by
29538 + * the Free Software Foundation; either version 2 of the License, or
29539 + * (at your option) any later version.
29541 + * This program is distributed in the hope that it will be useful,
29542 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29543 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29544 + * GNU General Public License for more details.
29546 + * You should have received a copy of the GNU General Public License
29547 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29551 + * superblock private data
29554 +#include <linux/iversion.h>
29558 + * they are necessary regardless sysfs is disabled.
29560 +void au_si_free(struct kobject *kobj)
29563 + struct au_sbinfo *sbinfo;
29564 + char *locked __maybe_unused; /* debug only */
29566 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29567 + for (i = 0; i < AuPlink_NHASH; i++)
29568 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29569 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29571 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29572 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29573 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29574 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29576 + dbgaufs_si_fin(sbinfo);
29577 + au_rw_write_lock(&sbinfo->si_rwsem);
29578 + au_br_free(sbinfo);
29579 + au_rw_write_unlock(&sbinfo->si_rwsem);
29581 + au_kfree_try_rcu(sbinfo->si_branch);
29582 + mutex_destroy(&sbinfo->si_xib_mtx);
29583 + AuRwDestroy(&sbinfo->si_rwsem);
29585 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29586 + /* si_nfiles is waited too */
29587 + au_kfree_rcu(sbinfo);
29590 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29592 + struct au_sbinfo *sbinfo;
29596 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29597 + if (unlikely(!sbinfo))
29600 + /* will be reallocated separately */
29601 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29602 + if (unlikely(!sbinfo->si_branch))
29605 + err = sysaufs_si_init(sbinfo);
29607 + dbgaufs_si_null(sbinfo);
29608 + err = dbgaufs_si_init(sbinfo);
29609 + if (unlikely(err))
29610 + kobject_put(&sbinfo->si_kobj);
29612 + if (unlikely(err))
29615 + au_nwt_init(&sbinfo->si_nowait);
29616 + au_rw_init_wlock(&sbinfo->si_rwsem);
29618 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29619 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29621 + sbinfo->si_bbot = -1;
29622 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29624 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29625 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29626 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29627 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29629 + au_fhsm_init(sbinfo);
29631 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29633 + sbinfo->si_xino_jiffy = jiffies;
29634 + sbinfo->si_xino_expire
29635 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29636 + mutex_init(&sbinfo->si_xib_mtx);
29637 + /* leave si_xib_last_pindex and si_xib_next_bit */
29639 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29641 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29642 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29643 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29644 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29646 + for (i = 0; i < AuPlink_NHASH; i++)
29647 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29648 + init_waitqueue_head(&sbinfo->si_plink_wq);
29649 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29651 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29653 + /* with getattr by default */
29654 + sbinfo->si_iop_array = aufs_iop;
29656 + /* leave other members for sysaufs and si_mnt. */
29657 + sbinfo->si_sb = sb;
29659 + sb->s_fs_info = sbinfo;
29662 + return sbinfo; /* success */
29665 + au_kfree_try_rcu(sbinfo->si_branch);
29667 + au_kfree_rcu(sbinfo);
29669 + return ERR_PTR(err);
29672 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29675 + struct au_branch **brp;
29677 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29680 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29681 + if (unlikely(!sz))
29682 + sz = sizeof(*brp);
29683 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29686 + sbinfo->si_branch = brp;
29693 +/* ---------------------------------------------------------------------- */
29695 +unsigned int au_sigen_inc(struct super_block *sb)
29697 + unsigned int gen;
29698 + struct inode *inode;
29700 + SiMustWriteLock(sb);
29702 + gen = ++au_sbi(sb)->si_generation;
29703 + au_update_digen(sb->s_root);
29704 + inode = d_inode(sb->s_root);
29705 + au_update_iigen(inode, /*half*/0);
29706 + inode_inc_iversion(inode);
29710 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29712 + aufs_bindex_t br_id;
29714 + struct au_sbinfo *sbinfo;
29716 + SiMustWriteLock(sb);
29718 + sbinfo = au_sbi(sb);
29719 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29720 + br_id = ++sbinfo->si_last_br_id;
29721 + AuDebugOn(br_id < 0);
29722 + if (br_id && au_br_index(sb, br_id) < 0)
29729 +/* ---------------------------------------------------------------------- */
29731 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29732 +int si_read_lock(struct super_block *sb, int flags)
29737 + if (au_ftest_lock(flags, FLUSH))
29738 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29740 + si_noflush_read_lock(sb);
29741 + err = au_plink_maint(sb, flags);
29742 + if (unlikely(err))
29743 + si_read_unlock(sb);
29748 +int si_write_lock(struct super_block *sb, int flags)
29752 + if (au_ftest_lock(flags, FLUSH))
29753 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29755 + si_noflush_write_lock(sb);
29756 + err = au_plink_maint(sb, flags);
29757 + if (unlikely(err))
29758 + si_write_unlock(sb);
29763 +/* dentry and super_block lock. call at entry point */
29764 +int aufs_read_lock(struct dentry *dentry, int flags)
29767 + struct super_block *sb;
29769 + sb = dentry->d_sb;
29770 + err = si_read_lock(sb, flags);
29771 + if (unlikely(err))
29774 + if (au_ftest_lock(flags, DW))
29775 + di_write_lock_child(dentry);
29777 + di_read_lock_child(dentry, flags);
29779 + if (au_ftest_lock(flags, GEN)) {
29780 + err = au_digen_test(dentry, au_sigen(sb));
29781 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29782 + AuDebugOn(!err && au_dbrange_test(dentry));
29784 + err = au_dbrange_test(dentry);
29785 + if (unlikely(err))
29786 + aufs_read_unlock(dentry, flags);
29793 +void aufs_read_unlock(struct dentry *dentry, int flags)
29795 + if (au_ftest_lock(flags, DW))
29796 + di_write_unlock(dentry);
29798 + di_read_unlock(dentry, flags);
29799 + si_read_unlock(dentry->d_sb);
29802 +void aufs_write_lock(struct dentry *dentry)
29804 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29805 + di_write_lock_child(dentry);
29808 +void aufs_write_unlock(struct dentry *dentry)
29810 + di_write_unlock(dentry);
29811 + si_write_unlock(dentry->d_sb);
29814 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29817 + unsigned int sigen;
29818 + struct super_block *sb;
29821 + err = si_read_lock(sb, flags);
29822 + if (unlikely(err))
29825 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29827 + if (au_ftest_lock(flags, GEN)) {
29828 + sigen = au_sigen(sb);
29829 + err = au_digen_test(d1, sigen);
29830 + AuDebugOn(!err && au_dbrange_test(d1));
29832 + err = au_digen_test(d2, sigen);
29833 + AuDebugOn(!err && au_dbrange_test(d2));
29835 + if (unlikely(err))
29836 + aufs_read_and_write_unlock2(d1, d2);
29843 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29845 + di_write_unlock2(d1, d2);
29846 + si_read_unlock(d1->d_sb);
29848 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29849 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29850 +++ linux/fs/aufs/super.c 2023-10-10 22:51:18.033248030 +0200
29852 +// SPDX-License-Identifier: GPL-2.0
29854 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29856 + * This program is free software; you can redistribute it and/or modify
29857 + * it under the terms of the GNU General Public License as published by
29858 + * the Free Software Foundation; either version 2 of the License, or
29859 + * (at your option) any later version.
29861 + * This program is distributed in the hope that it will be useful,
29862 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29863 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29864 + * GNU General Public License for more details.
29866 + * You should have received a copy of the GNU General Public License
29867 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29871 + * mount and super_block operations
29874 +#include <linux/iversion.h>
29875 +#include <linux/mm.h>
29876 +#include <linux/seq_file.h>
29877 +#include <linux/statfs.h>
29878 +#include <linux/vmalloc.h>
29882 + * super_operations
29884 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29886 + struct au_icntnr *c;
29888 + c = au_cache_alloc_icntnr(sb);
29890 + au_icntnr_init(c);
29891 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29892 + c->iinfo.ii_hinode = NULL;
29893 + return &c->vfs_inode;
29898 +static void aufs_destroy_inode(struct inode *inode)
29900 + if (!au_is_bad_inode(inode))
29901 + au_iinfo_fin(inode);
29904 +static void aufs_free_inode(struct inode *inode)
29906 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29909 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29911 + struct inode *inode;
29914 + inode = iget_locked(sb, ino);
29915 + if (unlikely(!inode)) {
29916 + inode = ERR_PTR(-ENOMEM);
29919 + if (!(inode->i_state & I_NEW))
29922 + err = au_xigen_new(inode);
29924 + err = au_iinfo_init(inode);
29926 + inode_inc_iversion(inode);
29928 + iget_failed(inode);
29929 + inode = ERR_PTR(err);
29933 + /* never return NULL */
29934 + AuDebugOn(!inode);
29935 + AuTraceErrPtr(inode);
29939 +/* lock free root dinfo */
29940 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29943 + aufs_bindex_t bindex, bbot;
29944 + struct path path;
29945 + struct au_hdentry *hdp;
29946 + struct au_branch *br;
29947 + au_br_perm_str_t perm;
29950 + bbot = au_sbbot(sb);
29952 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29953 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29954 + br = au_sbr(sb, bindex);
29955 + path.mnt = au_br_mnt(br);
29956 + path.dentry = hdp->hd_dentry;
29957 + err = au_seq_path(seq, &path);
29959 + au_optstr_br_perm(&perm, br->br_perm);
29960 + seq_printf(seq, "=%s", perm.a);
29961 + if (bindex != bbot)
29962 + seq_putc(seq, ':');
29965 + if (unlikely(err || seq_has_overflowed(seq)))
29971 +static void au_gen_fmt(char *fmt, int len, const char *pat,
29972 + const char *append)
29977 + while (*pat != ':')
29980 + strscpy(p, append, len - (p - fmt));
29981 + AuDebugOn(strlen(fmt) >= len);
29984 +static void au_show_wbr_create(struct seq_file *m, int v,
29985 + struct au_sbinfo *sbinfo)
29989 + struct au_wbr_mfs *mfs;
29991 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29993 + seq_puts(m, ",create=");
29994 + pat = au_optstr_wbr_create(v);
29995 + mfs = &sbinfo->si_wbr_mfs;
29997 + case AuWbrCreate_TDP:
29998 + case AuWbrCreate_RR:
29999 + case AuWbrCreate_MFS:
30000 + case AuWbrCreate_PMFS:
30001 + seq_puts(m, pat);
30003 + case AuWbrCreate_MFSRR:
30004 + case AuWbrCreate_TDMFS:
30005 + case AuWbrCreate_PMFSRR:
30006 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30007 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30009 + case AuWbrCreate_MFSV:
30010 + case AuWbrCreate_PMFSV:
30011 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30012 + seq_printf(m, fmt,
30013 + jiffies_to_msecs(mfs->mfs_expire)
30016 + case AuWbrCreate_MFSRRV:
30017 + case AuWbrCreate_TDMFSV:
30018 + case AuWbrCreate_PMFSRRV:
30019 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30020 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30021 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30028 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30030 +#ifdef CONFIG_SYSFS
30034 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30035 + aufs_bindex_t bindex, brid;
30036 + struct qstr *name;
30038 + struct dentry *d, *h_root;
30039 + struct au_branch *br;
30041 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30044 + f = au_sbi(sb)->si_xib;
30048 + /* stop printing the default xino path on the first writable branch */
30050 + bindex = au_xi_root(sb, f->f_path.dentry);
30051 + if (bindex >= 0) {
30052 + br = au_sbr_sb(sb, bindex);
30053 + h_root = au_br_dentry(br);
30056 + d = f->f_path.dentry;
30057 + name = &d->d_name;
30058 + /* safe ->d_parent because the file is unlinked */
30059 + if (d->d_parent == h_root
30060 + && name->len == len
30061 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30064 + seq_puts(seq, ",xino=");
30065 + err = au_xino_path(seq, f);
30072 +/* seq_file will re-call me in case of too long string */
30073 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30076 + unsigned int mnt_flags, v;
30077 + struct super_block *sb;
30078 + struct au_sbinfo *sbinfo;
30080 +#define AuBool(name, str) do { \
30081 + v = au_opt_test(mnt_flags, name); \
30082 + if (v != au_opt_test(AuOpt_Def, name)) \
30083 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30086 +#define AuStr(name, str) do { \
30087 + v = mnt_flags & AuOptMask_##name; \
30088 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30089 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30092 +#define AuUInt(name, str, val) do { \
30093 + if (val != AUFS_##name##_DEF) \
30094 + seq_printf(m, "," #str "=%u", val); \
30097 + sb = dentry->d_sb;
30098 + if (sb->s_flags & SB_POSIXACL)
30099 + seq_puts(m, ",acl");
30100 +#if 0 /* reserved for future use */
30101 + if (sb->s_flags & SB_I_VERSION)
30102 + seq_puts(m, ",i_version");
30105 + /* lock free root dinfo */
30106 + si_noflush_read_lock(sb);
30107 + sbinfo = au_sbi(sb);
30108 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30110 + mnt_flags = au_mntflags(sb);
30111 + if (au_opt_test(mnt_flags, XINO)) {
30112 + err = au_show_xino(m, sb);
30113 + if (unlikely(err))
30116 + seq_puts(m, ",noxino");
30118 + AuBool(TRUNC_XINO, trunc_xino);
30119 + AuStr(UDBA, udba);
30120 + AuBool(SHWH, shwh);
30121 + AuBool(PLINK, plink);
30122 + AuBool(DIO, dio);
30123 + AuBool(DIRPERM1, dirperm1);
30125 + v = sbinfo->si_wbr_create;
30126 + if (v != AuWbrCreate_Def)
30127 + au_show_wbr_create(m, v, sbinfo);
30129 + v = sbinfo->si_wbr_copyup;
30130 + if (v != AuWbrCopyup_Def)
30131 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30133 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30134 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30135 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30137 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30139 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30140 + AuUInt(RDCACHE, rdcache, v);
30142 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30143 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30145 + au_fhsm_show(m, sbinfo);
30147 + AuBool(DIRREN, dirren);
30148 + AuBool(SUM, sum);
30149 + /* AuBool(SUM_W, wsum); */
30150 + AuBool(WARN_PERM, warn_perm);
30151 + AuBool(VERBOSE, verbose);
30154 + /* be sure to print "br:" last */
30155 + if (!sysaufs_brs) {
30156 + seq_puts(m, ",br:");
30157 + au_show_brs(m, sb);
30159 + si_read_unlock(sb);
30167 +/* ---------------------------------------------------------------------- */
30169 +/* sum mode which returns the summation for statfs(2) */
30171 +static u64 au_add_till_max(u64 a, u64 b)
30179 + return ULLONG_MAX;
30182 +static u64 au_mul_till_max(u64 a, long mul)
30190 + return ULLONG_MAX;
30193 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30196 + long bsize, factor;
30197 + u64 blocks, bfree, bavail, files, ffree;
30198 + aufs_bindex_t bbot, bindex, i;
30199 + unsigned char shared;
30200 + struct path h_path;
30201 + struct super_block *h_sb;
30204 + bsize = LONG_MAX;
30210 + bbot = au_sbbot(sb);
30211 + for (bindex = 0; bindex <= bbot; bindex++) {
30212 + h_path.mnt = au_sbr_mnt(sb, bindex);
30213 + h_sb = h_path.mnt->mnt_sb;
30215 + for (i = 0; !shared && i < bindex; i++)
30216 + shared = (au_sbr_sb(sb, i) == h_sb);
30220 + /* sb->s_root for NFS is unreliable */
30221 + h_path.dentry = h_path.mnt->mnt_root;
30222 + err = vfs_statfs(&h_path, buf);
30223 + if (unlikely(err))
30226 + if (bsize > buf->f_bsize) {
30228 + * we will reduce bsize, so we have to expand blocks
30229 + * etc. to match them again
30231 + factor = (bsize / buf->f_bsize);
30232 + blocks = au_mul_till_max(blocks, factor);
30233 + bfree = au_mul_till_max(bfree, factor);
30234 + bavail = au_mul_till_max(bavail, factor);
30235 + bsize = buf->f_bsize;
30238 + factor = (buf->f_bsize / bsize);
30239 + blocks = au_add_till_max(blocks,
30240 + au_mul_till_max(buf->f_blocks, factor));
30241 + bfree = au_add_till_max(bfree,
30242 + au_mul_till_max(buf->f_bfree, factor));
30243 + bavail = au_add_till_max(bavail,
30244 + au_mul_till_max(buf->f_bavail, factor));
30245 + files = au_add_till_max(files, buf->f_files);
30246 + ffree = au_add_till_max(ffree, buf->f_ffree);
30249 + buf->f_bsize = bsize;
30250 + buf->f_blocks = blocks;
30251 + buf->f_bfree = bfree;
30252 + buf->f_bavail = bavail;
30253 + buf->f_files = files;
30254 + buf->f_ffree = ffree;
30255 + buf->f_frsize = 0;
30261 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30264 + struct path h_path;
30265 + struct super_block *sb;
30267 + /* lock free root dinfo */
30268 + sb = dentry->d_sb;
30269 + si_noflush_read_lock(sb);
30270 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30271 + /* sb->s_root for NFS is unreliable */
30272 + h_path.mnt = au_sbr_mnt(sb, 0);
30273 + h_path.dentry = h_path.mnt->mnt_root;
30274 + err = vfs_statfs(&h_path, buf);
30276 + err = au_statfs_sum(sb, buf);
30277 + si_read_unlock(sb);
30280 + buf->f_type = AUFS_SUPER_MAGIC;
30281 + buf->f_namelen = AUFS_MAX_NAMELEN;
30282 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30284 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30289 +/* ---------------------------------------------------------------------- */
30291 +static int aufs_sync_fs(struct super_block *sb, int wait)
30294 + aufs_bindex_t bbot, bindex;
30295 + struct au_branch *br;
30296 + struct super_block *h_sb;
30299 + si_noflush_read_lock(sb);
30300 + bbot = au_sbbot(sb);
30301 + for (bindex = 0; bindex <= bbot; bindex++) {
30302 + br = au_sbr(sb, bindex);
30303 + if (!au_br_writable(br->br_perm))
30306 + h_sb = au_sbr_sb(sb, bindex);
30307 + e = vfsub_sync_filesystem(h_sb);
30308 + if (unlikely(e && !err))
30310 + /* go on even if an error happens */
30312 + si_read_unlock(sb);
30317 +/* ---------------------------------------------------------------------- */
30319 +/* final actions when unmounting a file system */
30320 +static void aufs_put_super(struct super_block *sb)
30322 + struct au_sbinfo *sbinfo;
30324 + sbinfo = au_sbi(sb);
30326 + kobject_put(&sbinfo->si_kobj);
30329 +/* ---------------------------------------------------------------------- */
30331 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30332 + struct super_block *sb, void *arg)
30335 + unsigned long long n, sz;
30342 + if (*hint > ULLONG_MAX / sizeof(array)) {
30343 + array = ERR_PTR(-EMFILE);
30344 + pr_err("hint %llu\n", *hint);
30348 + sz = sizeof(array) * *hint;
30349 + array = kzalloc(sz, GFP_NOFS);
30350 + if (unlikely(!array))
30351 + array = vzalloc(sz);
30352 + if (unlikely(!array)) {
30353 + array = ERR_PTR(-ENOMEM);
30357 + n = cb(sb, array, *hint, arg);
30358 + AuDebugOn(n > *hint);
30365 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30366 + unsigned long long max __maybe_unused,
30369 + unsigned long long n;
30370 + struct inode **p, *inode;
30371 + struct list_head *head;
30376 + spin_lock(&sb->s_inode_list_lock);
30377 + list_for_each_entry(inode, head, i_sb_list) {
30378 + if (!au_is_bad_inode(inode)
30379 + && au_ii(inode)->ii_btop >= 0) {
30380 + spin_lock(&inode->i_lock);
30381 + if (atomic_read(&inode->i_count)) {
30385 + AuDebugOn(n > max);
30387 + spin_unlock(&inode->i_lock);
30390 + spin_unlock(&sb->s_inode_list_lock);
30395 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30397 + struct au_sbinfo *sbi;
30399 + sbi = au_sbi(sb);
30400 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30401 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30404 +void au_iarray_free(struct inode **a, unsigned long long max)
30406 + unsigned long long ull;
30408 + for (ull = 0; ull < max; ull++)
30413 +/* ---------------------------------------------------------------------- */
30416 + * refresh dentry and inode at remount time.
30418 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30419 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30420 + struct dentry *parent)
30424 + di_write_lock_child(dentry);
30425 + di_read_lock_parent(parent, AuLock_IR);
30426 + err = au_refresh_dentry(dentry, parent);
30427 + if (!err && dir_flags)
30428 + au_hn_reset(d_inode(dentry), dir_flags);
30429 + di_read_unlock(parent, AuLock_IR);
30430 + di_write_unlock(dentry);
30435 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30436 + struct au_sbinfo *sbinfo,
30437 + const unsigned int dir_flags, unsigned int do_idop)
30440 + struct dentry *parent;
30443 + parent = dget_parent(dentry);
30444 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30445 + if (d_really_is_positive(dentry)) {
30446 + if (!d_is_dir(dentry))
30447 + err = au_do_refresh(dentry, /*dir_flags*/0,
30450 + err = au_do_refresh(dentry, dir_flags, parent);
30451 + if (unlikely(err))
30452 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30455 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30456 + AuDbgDentry(dentry);
30462 + au_refresh_dop(dentry, /*force_reval*/0);
30464 + au_refresh_dop(dentry, /*force_reval*/1);
30470 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30472 + int err, i, j, ndentry, e;
30473 + unsigned int sigen;
30474 + struct au_dcsub_pages dpages;
30475 + struct au_dpage *dpage;
30476 + struct dentry **dentries, *d;
30477 + struct au_sbinfo *sbinfo;
30478 + struct dentry *root = sb->s_root;
30479 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30482 + au_refresh_dop(root, /*force_reval*/0);
30484 + err = au_dpages_init(&dpages, GFP_NOFS);
30485 + if (unlikely(err))
30487 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30488 + if (unlikely(err))
30491 + sigen = au_sigen(sb);
30492 + sbinfo = au_sbi(sb);
30493 + for (i = 0; i < dpages.ndpage; i++) {
30494 + dpage = dpages.dpages + i;
30495 + dentries = dpage->dentries;
30496 + ndentry = dpage->ndentry;
30497 + for (j = 0; j < ndentry; j++) {
30499 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30501 + if (unlikely(e && !err))
30503 + /* go on even err */
30508 + au_dpages_free(&dpages);
30513 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30516 + unsigned int sigen;
30517 + unsigned long long max, ull;
30518 + struct inode *inode, **array;
30520 + array = au_iarray_alloc(sb, &max);
30521 + err = PTR_ERR(array);
30522 + if (IS_ERR(array))
30526 + sigen = au_sigen(sb);
30527 + for (ull = 0; ull < max; ull++) {
30528 + inode = array[ull];
30529 + if (unlikely(!inode))
30533 + ii_write_lock_child(inode);
30534 + if (au_iigen(inode, NULL) != sigen) {
30535 + e = au_refresh_hinode_self(inode);
30536 + if (unlikely(e)) {
30537 + au_refresh_iop(inode, /*force_getattr*/1);
30538 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30541 + /* go on even if err */
30544 + if (!e && do_idop)
30545 + au_refresh_iop(inode, /*force_getattr*/0);
30546 + ii_write_unlock(inode);
30549 + au_iarray_free(array, max);
30555 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30558 + unsigned int udba;
30559 + aufs_bindex_t bindex, bbot;
30560 + struct dentry *root;
30561 + struct inode *inode;
30562 + struct au_branch *br;
30563 + struct au_sbinfo *sbi;
30565 + au_sigen_inc(sb);
30566 + sbi = au_sbi(sb);
30567 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30569 + root = sb->s_root;
30570 + DiMustNoWaiters(root);
30571 + inode = d_inode(root);
30572 + IiMustNoWaiters(inode);
30574 + udba = au_opt_udba(sb);
30575 + bbot = au_sbbot(sb);
30576 + for (bindex = 0; bindex <= bbot; bindex++) {
30577 + br = au_sbr(sb, bindex);
30578 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30579 + if (unlikely(err))
30580 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30582 + /* go on even if err */
30584 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30587 + if (au_ftest_si(sbi, NO_DREVAL)) {
30588 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30589 + sb->s_d_op = &aufs_dop_noreval;
30590 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30591 + sbi->si_iop_array = aufs_iop_nogetattr;
30593 + AuDebugOn(sb->s_d_op == &aufs_dop);
30594 + sb->s_d_op = &aufs_dop;
30595 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30596 + sbi->si_iop_array = aufs_iop;
30598 + pr_info("reset to %ps and %ps\n",
30599 + sb->s_d_op, sbi->si_iop_array);
30602 + di_write_unlock(root);
30603 + err = au_refresh_d(sb, do_idop);
30604 + e = au_refresh_i(sb, do_idop);
30605 + if (unlikely(e && !err))
30607 + /* aufs_write_lock() calls ..._child() */
30608 + di_write_lock_child(root);
30610 + au_cpup_attr_all(inode, /*force*/1);
30612 + if (unlikely(err))
30613 + AuIOErr("refresh failed, ignored, %d\n", err);
30616 +const struct super_operations aufs_sop = {
30617 + .alloc_inode = aufs_alloc_inode,
30618 + .destroy_inode = aufs_destroy_inode,
30619 + .free_inode = aufs_free_inode,
30620 + /* always deleting, no clearing */
30621 + .drop_inode = generic_delete_inode,
30622 + .show_options = aufs_show_options,
30623 + .statfs = aufs_statfs,
30624 + .put_super = aufs_put_super,
30625 + .sync_fs = aufs_sync_fs
30628 +/* ---------------------------------------------------------------------- */
30630 +int au_alloc_root(struct super_block *sb)
30633 + struct inode *inode;
30634 + struct dentry *root;
30637 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30638 + err = PTR_ERR(inode);
30639 + if (IS_ERR(inode))
30642 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30643 + inode->i_fop = &aufs_dir_fop;
30644 + inode->i_mode = S_IFDIR;
30645 + set_nlink(inode, 2);
30646 + unlock_new_inode(inode);
30648 + root = d_make_root(inode);
30649 + if (unlikely(!root))
30651 + err = PTR_ERR(root);
30652 + if (IS_ERR(root))
30655 + err = au_di_init(root);
30657 + sb->s_root = root;
30658 + return 0; /* success */
30666 +/* ---------------------------------------------------------------------- */
30668 +static void aufs_kill_sb(struct super_block *sb)
30670 + struct au_sbinfo *sbinfo;
30671 + struct dentry *root;
30673 + sbinfo = au_sbi(sb);
30677 + au_sbilist_del(sb);
30679 + root = sb->s_root;
30681 + aufs_write_lock(root);
30683 + __si_write_lock(sb);
30686 + if (sbinfo->si_wbr_create_ops->fin)
30687 + sbinfo->si_wbr_create_ops->fin(sb);
30688 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30689 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30690 + au_remount_refresh(sb, /*do_idop*/0);
30692 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30693 + au_plink_put(sb, /*verbose*/1);
30696 + au_dr_opt_flush(sb);
30699 + aufs_write_unlock(root);
30701 + __si_write_unlock(sb);
30703 + sbinfo->si_sb = NULL;
30704 + au_nwt_flush(&sbinfo->si_nowait);
30707 + kill_anon_super(sb);
30710 +struct file_system_type aufs_fs_type = {
30711 + .name = AUFS_FSTYPE,
30712 + /* a race between rename and others */
30713 + .fs_flags = FS_RENAME_DOES_D_MOVE
30715 + /*| FS_ALLOW_IDMAP*/
30717 + .init_fs_context = aufs_fsctx_init,
30718 + .parameters = aufs_fsctx_paramspec,
30719 + .kill_sb = aufs_kill_sb,
30720 + /* no need to __module_get() and module_put(). */
30721 + .owner = THIS_MODULE,
30723 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30724 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30725 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30727 +/* SPDX-License-Identifier: GPL-2.0 */
30729 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30731 + * This program is free software; you can redistribute it and/or modify
30732 + * it under the terms of the GNU General Public License as published by
30733 + * the Free Software Foundation; either version 2 of the License, or
30734 + * (at your option) any later version.
30736 + * This program is distributed in the hope that it will be useful,
30737 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30738 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30739 + * GNU General Public License for more details.
30741 + * You should have received a copy of the GNU General Public License
30742 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30746 + * super_block operations
30749 +#ifndef __AUFS_SUPER_H__
30750 +#define __AUFS_SUPER_H__
30754 +#include <linux/fs.h>
30755 +#include <linux/kobject.h>
30758 +#include "rwsem.h"
30761 +/* policies to select one among multiple writable branches */
30762 +struct au_wbr_copyup_operations {
30763 + int (*copyup)(struct dentry *dentry);
30766 +#define AuWbr_DIR 1 /* target is a dir */
30767 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30769 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30770 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30771 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30773 +struct au_wbr_create_operations {
30774 + int (*create)(struct dentry *dentry, unsigned int flags);
30775 + int (*init)(struct super_block *sb);
30776 + int (*fin)(struct super_block *sb);
30779 +struct au_wbr_mfs {
30780 + struct mutex mfs_lock; /* protect this structure */
30781 + unsigned long mfs_jiffy;
30782 + unsigned long mfs_expire;
30783 + aufs_bindex_t mfs_bindex;
30785 + unsigned long long mfsrr_bytes;
30786 + unsigned long long mfsrr_watermark;
30789 +#define AuPlink_NHASH 100
30790 +static inline int au_plink_hash(ino_t ino)
30792 + return ino % AuPlink_NHASH;
30795 +/* File-based Hierarchical Storage Management */
30797 +#ifdef CONFIG_AUFS_FHSM
30798 + /* allow only one process who can receive the notification */
30799 + spinlock_t fhsm_spin;
30801 + wait_queue_head_t fhsm_wqh;
30802 + atomic_t fhsm_readable;
30804 + /* these are protected by si_rwsem */
30805 + unsigned long fhsm_expire;
30806 + aufs_bindex_t fhsm_bottom;
30811 +struct au_sbinfo {
30812 + /* nowait tasks in the system-wide workqueue */
30813 + struct au_nowait_tasks si_nowait;
30816 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30817 + * rwsem for au_sbinfo is necessary.
30819 + struct au_rwsem si_rwsem;
30822 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30825 + au_lcnt_t si_ninodes, si_nfiles;
30827 + /* branch management */
30828 + unsigned int si_generation;
30830 + /* see AuSi_ flags */
30831 + unsigned char au_si_status;
30833 + aufs_bindex_t si_bbot;
30835 + /* dirty trick to keep br_id plus */
30836 + unsigned int si_last_br_id :
30837 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30838 + struct au_branch **si_branch;
30840 + /* policy to select a writable branch */
30841 + unsigned char si_wbr_copyup;
30842 + unsigned char si_wbr_create;
30843 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30844 + struct au_wbr_create_operations *si_wbr_create_ops;
30846 + /* round robin */
30847 + atomic_t si_wbr_rr_next;
30849 + /* most free space */
30850 + struct au_wbr_mfs si_wbr_mfs;
30852 + /* File-based Hierarchical Storage Management */
30853 + struct au_fhsm si_fhsm;
30855 + /* mount flags */
30856 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30857 + unsigned int si_mntflags;
30859 + /* external inode number (bitmap and translation table) */
30860 + loff_t si_ximaxent; /* max entries in a xino */
30862 + struct file *si_xib;
30863 + struct mutex si_xib_mtx; /* protect xib members */
30864 + unsigned long *si_xib_buf;
30865 + unsigned long si_xib_last_pindex;
30866 + int si_xib_next_bit;
30868 + unsigned long si_xino_jiffy;
30869 + unsigned long si_xino_expire;
30870 + /* reserved for future use */
30871 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30873 +#ifdef CONFIG_AUFS_EXPORT
30874 + /* i_generation */
30875 + /* todo: make xigen file an array to support many inode numbers */
30876 + struct file *si_xigen;
30877 + atomic_t si_xigen_next;
30880 + /* dirty trick to support atomic_open */
30881 + struct hlist_bl_head si_aopen;
30883 + /* vdir parameters */
30884 + unsigned long si_rdcache; /* max cache time in jiffies */
30885 + unsigned int si_rdblk; /* deblk size */
30886 + unsigned int si_rdhash; /* hash size */
30889 + * If the number of whiteouts are larger than si_dirwh, leave all of
30890 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30891 + * future fsck.aufs or kernel thread will remove them later.
30892 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30894 + unsigned int si_dirwh;
30896 + /* pseudo_link list */
30897 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30898 + wait_queue_head_t si_plink_wq;
30899 + spinlock_t si_plink_maint_lock;
30900 + pid_t si_plink_maint_pid;
30903 + struct hlist_bl_head si_files;
30905 + /* with/without getattr, brother of sb->s_d_op */
30906 + const struct inode_operations *si_iop_array;
30909 + * sysfs and lifetime management.
30910 + * this is not a small structure and it may be a waste of memory in case
30911 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30912 + * but using sysfs is majority.
30914 + struct kobject si_kobj;
30915 +#ifdef CONFIG_DEBUG_FS
30916 + struct dentry *si_dbgaufs;
30917 + struct dentry *si_dbgaufs_plink;
30918 + struct dentry *si_dbgaufs_xib;
30919 +#ifdef CONFIG_AUFS_EXPORT
30920 + struct dentry *si_dbgaufs_xigen;
30924 +#ifdef CONFIG_AUFS_SBILIST
30925 + struct hlist_bl_node si_list;
30928 + /* dirty, necessary for unmounting, sysfs and sysrq */
30929 + struct super_block *si_sb;
30932 +/* sbinfo status flags */
30934 + * set true when refresh_dirs() failed at remount time.
30935 + * then try refreshing dirs at access time again.
30936 + * if it is false, refreshing dirs at access time is unnecessary
30938 +#define AuSi_FAILED_REFRESH_DIR 1
30939 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30940 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30942 +#ifndef CONFIG_AUFS_FHSM
30944 +#define AuSi_FHSM 0
30947 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30948 + unsigned int flag)
30950 + AuRwMustAnyLock(&sbi->si_rwsem);
30951 + return sbi->au_si_status & flag;
30953 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30954 +#define au_fset_si(sbinfo, name) do { \
30955 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30956 + (sbinfo)->au_si_status |= AuSi_##name; \
30958 +#define au_fclr_si(sbinfo, name) do { \
30959 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30960 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30963 +/* ---------------------------------------------------------------------- */
30965 +/* policy to select one among writable branches */
30966 +#define AuWbrCopyup(sbinfo, ...) \
30967 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30968 +#define AuWbrCreate(sbinfo, ...) \
30969 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30971 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30972 +#define AuLock_DW 1 /* write-lock dentry */
30973 +#define AuLock_IR (1 << 1) /* read-lock inode */
30974 +#define AuLock_IW (1 << 2) /* write-lock inode */
30975 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30976 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30977 + /* except RENAME_EXCHANGE */
30978 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30979 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30980 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30981 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30982 +#define au_fset_lock(flags, name) \
30983 + do { (flags) |= AuLock_##name; } while (0)
30984 +#define au_fclr_lock(flags, name) \
30985 + do { (flags) &= ~AuLock_##name; } while (0)
30987 +/* ---------------------------------------------------------------------- */
30990 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30992 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30993 + unsigned long long max, void *arg);
30994 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30995 + struct super_block *sb, void *arg);
30996 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30997 +void au_iarray_free(struct inode **a, unsigned long long max);
30999 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
31000 +extern const struct super_operations aufs_sop;
31001 +int au_alloc_root(struct super_block *sb);
31002 +extern struct file_system_type aufs_fs_type;
31005 +void au_si_free(struct kobject *kobj);
31006 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31007 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31009 +unsigned int au_sigen_inc(struct super_block *sb);
31010 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31012 +int si_read_lock(struct super_block *sb, int flags);
31013 +int si_write_lock(struct super_block *sb, int flags);
31014 +int aufs_read_lock(struct dentry *dentry, int flags);
31015 +void aufs_read_unlock(struct dentry *dentry, int flags);
31016 +void aufs_write_lock(struct dentry *dentry);
31017 +void aufs_write_unlock(struct dentry *dentry);
31018 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31019 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31021 +/* wbr_policy.c */
31022 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31023 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31024 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31025 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31026 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31029 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31031 +#ifdef CONFIG_AUFS_FHSM
31034 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31038 + spin_lock(&fhsm->fhsm_spin);
31039 + pid = fhsm->fhsm_pid;
31040 + spin_unlock(&fhsm->fhsm_spin);
31045 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31046 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31047 +int au_fhsm_fd(struct super_block *sb, int oflags);
31048 +int au_fhsm_br_alloc(struct au_branch *br);
31049 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31050 +void au_fhsm_fin(struct super_block *sb);
31051 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31052 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31053 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31055 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31057 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31058 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31059 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31060 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31061 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31062 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31063 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31064 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31065 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31068 +/* ---------------------------------------------------------------------- */
31070 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31072 + return sb->s_fs_info;
31075 +/* ---------------------------------------------------------------------- */
31077 +#ifdef CONFIG_AUFS_EXPORT
31078 +int au_test_nfsd(void);
31079 +void au_export_init(struct super_block *sb);
31080 +void au_xigen_inc(struct inode *inode);
31081 +int au_xigen_new(struct inode *inode);
31082 +int au_xigen_set(struct super_block *sb, struct path *path);
31083 +void au_xigen_clr(struct super_block *sb);
31085 +static inline int au_busy_or_stale(void)
31087 + if (!au_test_nfsd())
31092 +AuStubInt0(au_test_nfsd, void)
31093 +AuStubVoid(au_export_init, struct super_block *sb)
31094 +AuStubVoid(au_xigen_inc, struct inode *inode)
31095 +AuStubInt0(au_xigen_new, struct inode *inode)
31096 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31097 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31098 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31099 +#endif /* CONFIG_AUFS_EXPORT */
31101 +/* ---------------------------------------------------------------------- */
31103 +#ifdef CONFIG_AUFS_SBILIST
31105 +extern struct hlist_bl_head au_sbilist;
31107 +static inline void au_sbilist_init(void)
31109 + INIT_HLIST_BL_HEAD(&au_sbilist);
31112 +static inline void au_sbilist_add(struct super_block *sb)
31114 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31117 +static inline void au_sbilist_del(struct super_block *sb)
31119 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31122 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31123 +static inline void au_sbilist_lock(void)
31125 + hlist_bl_lock(&au_sbilist);
31128 +static inline void au_sbilist_unlock(void)
31130 + hlist_bl_unlock(&au_sbilist);
31132 +#define AuGFP_SBILIST GFP_ATOMIC
31134 +AuStubVoid(au_sbilist_lock, void)
31135 +AuStubVoid(au_sbilist_unlock, void)
31136 +#define AuGFP_SBILIST GFP_NOFS
31137 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31139 +AuStubVoid(au_sbilist_init, void)
31140 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31141 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31142 +AuStubVoid(au_sbilist_lock, void)
31143 +AuStubVoid(au_sbilist_unlock, void)
31144 +#define AuGFP_SBILIST GFP_NOFS
31147 +/* ---------------------------------------------------------------------- */
31149 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31152 + * This function is a dynamic '__init' function actually,
31153 + * so the tiny check for si_rwsem is unnecessary.
31155 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31156 +#ifdef CONFIG_DEBUG_FS
31157 + sbinfo->si_dbgaufs = NULL;
31158 + sbinfo->si_dbgaufs_plink = NULL;
31159 + sbinfo->si_dbgaufs_xib = NULL;
31160 +#ifdef CONFIG_AUFS_EXPORT
31161 + sbinfo->si_dbgaufs_xigen = NULL;
31166 +/* ---------------------------------------------------------------------- */
31168 +/* current->atomic_flags */
31169 +/* this value should never corrupt the ones defined in linux/sched.h */
31170 +#define PFA_AUFS 0x10
31172 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31173 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31174 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31176 +static inline int si_pid_test(struct super_block *sb)
31178 + return !!task_test_aufs(current);
31181 +static inline void si_pid_clr(struct super_block *sb)
31183 + AuDebugOn(!task_test_aufs(current));
31184 + task_clear_aufs(current);
31187 +static inline void si_pid_set(struct super_block *sb)
31189 + AuDebugOn(task_test_aufs(current));
31190 + task_set_aufs(current);
31193 +/* ---------------------------------------------------------------------- */
31195 +/* lock superblock. mainly for entry point functions */
31196 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31197 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31198 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31199 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31201 +#define __si_read_trylock_nested(sb) \
31202 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31203 +#define __si_write_trylock_nested(sb) \
31204 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31207 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31208 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31209 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31211 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31212 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31213 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31215 +static inline void si_noflush_read_lock(struct super_block *sb)
31217 + __si_read_lock(sb);
31221 +static inline int si_noflush_read_trylock(struct super_block *sb)
31225 + locked = __si_read_trylock(sb);
31231 +static inline void si_noflush_write_lock(struct super_block *sb)
31233 + __si_write_lock(sb);
31237 +static inline int si_noflush_write_trylock(struct super_block *sb)
31241 + locked = __si_write_trylock(sb);
31247 +#if 0 /* reserved */
31248 +static inline int si_read_trylock(struct super_block *sb, int flags)
31250 + if (au_ftest_lock(flags, FLUSH))
31251 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31252 + return si_noflush_read_trylock(sb);
31256 +static inline void si_read_unlock(struct super_block *sb)
31259 + __si_read_unlock(sb);
31262 +#if 0 /* reserved */
31263 +static inline int si_write_trylock(struct super_block *sb, int flags)
31265 + if (au_ftest_lock(flags, FLUSH))
31266 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31267 + return si_noflush_write_trylock(sb);
31271 +static inline void si_write_unlock(struct super_block *sb)
31274 + __si_write_unlock(sb);
31277 +#if 0 /* reserved */
31278 +static inline void si_downgrade_lock(struct super_block *sb)
31280 + __si_downgrade_lock(sb);
31284 +/* ---------------------------------------------------------------------- */
31286 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31288 + SiMustAnyLock(sb);
31289 + return au_sbi(sb)->si_bbot;
31292 +static inline unsigned int au_mntflags(struct super_block *sb)
31294 + SiMustAnyLock(sb);
31295 + return au_sbi(sb)->si_mntflags;
31298 +static inline unsigned int au_sigen(struct super_block *sb)
31300 + SiMustAnyLock(sb);
31301 + return au_sbi(sb)->si_generation;
31304 +static inline struct au_branch *au_sbr(struct super_block *sb,
31305 + aufs_bindex_t bindex)
31307 + SiMustAnyLock(sb);
31308 + return au_sbi(sb)->si_branch[0 + bindex];
31311 +static inline loff_t au_xi_maxent(struct super_block *sb)
31313 + SiMustAnyLock(sb);
31314 + return au_sbi(sb)->si_ximaxent;
31317 +#endif /* __KERNEL__ */
31318 +#endif /* __AUFS_SUPER_H__ */
31319 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31320 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31321 +++ linux/fs/aufs/sysaufs.c 2023-10-10 22:51:18.033248030 +0200
31323 +// SPDX-License-Identifier: GPL-2.0
31325 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31327 + * This program is free software; you can redistribute it and/or modify
31328 + * it under the terms of the GNU General Public License as published by
31329 + * the Free Software Foundation; either version 2 of the License, or
31330 + * (at your option) any later version.
31332 + * This program is distributed in the hope that it will be useful,
31333 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31334 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31335 + * GNU General Public License for more details.
31337 + * You should have received a copy of the GNU General Public License
31338 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31342 + * sysfs interface and lifetime management
31343 + * they are necessary regardless sysfs is disabled.
31346 +#include <linux/random.h>
31349 +unsigned long sysaufs_si_mask;
31350 +struct kset *sysaufs_kset;
31352 +#define AuSiAttr(_name) { \
31353 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31354 + .show = sysaufs_si_##_name, \
31357 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31358 +struct attribute *sysaufs_si_attrs[] = {
31359 + &sysaufs_si_attr_xi_path.attr,
31362 +ATTRIBUTE_GROUPS(sysaufs_si);
31364 +static const struct sysfs_ops au_sbi_ops = {
31365 + .show = sysaufs_si_show
31368 +static const struct kobj_type au_sbi_ktype = {
31369 + .release = au_si_free,
31370 + .sysfs_ops = &au_sbi_ops,
31371 + .default_groups = sysaufs_si_groups
31374 +/* ---------------------------------------------------------------------- */
31376 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31380 + sbinfo->si_kobj.kset = sysaufs_kset;
31381 + /* cf. sysaufs_name() */
31382 + err = kobject_init_and_add
31383 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31384 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31389 +void sysaufs_fin(void)
31391 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31392 + kset_unregister(sysaufs_kset);
31395 +int __init sysaufs_init(void)
31400 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31401 + } while (!sysaufs_si_mask);
31404 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31405 + if (unlikely(!sysaufs_kset))
31407 + err = PTR_ERR(sysaufs_kset);
31408 + if (IS_ERR(sysaufs_kset))
31410 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31411 + if (unlikely(err))
31412 + kset_unregister(sysaufs_kset);
31417 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31418 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31419 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31421 +/* SPDX-License-Identifier: GPL-2.0 */
31423 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31425 + * This program is free software; you can redistribute it and/or modify
31426 + * it under the terms of the GNU General Public License as published by
31427 + * the Free Software Foundation; either version 2 of the License, or
31428 + * (at your option) any later version.
31430 + * This program is distributed in the hope that it will be useful,
31431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31433 + * GNU General Public License for more details.
31435 + * You should have received a copy of the GNU General Public License
31436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31440 + * sysfs interface and mount lifetime management
31443 +#ifndef __SYSAUFS_H__
31444 +#define __SYSAUFS_H__
31448 +#include <linux/sysfs.h>
31449 +#include "module.h"
31451 +struct super_block;
31454 +struct sysaufs_si_attr {
31455 + struct attribute attr;
31456 + int (*show)(struct seq_file *seq, struct super_block *sb);
31459 +/* ---------------------------------------------------------------------- */
31462 +extern unsigned long sysaufs_si_mask;
31463 +extern struct kset *sysaufs_kset;
31464 +extern struct attribute *sysaufs_si_attrs[];
31465 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31466 +int __init sysaufs_init(void);
31467 +void sysaufs_fin(void);
31469 +/* ---------------------------------------------------------------------- */
31471 +/* some people doesn't like to show a pointer in kernel */
31472 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31474 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31477 +#define SysaufsSiNamePrefix "si_"
31478 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31479 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31481 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31482 + sysaufs_si_id(sbinfo));
31486 +#ifdef CONFIG_SYSFS
31488 +extern struct attribute_group *sysaufs_attr_group;
31490 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31491 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31493 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31494 +#ifdef CONFIG_COMPAT
31495 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31498 +void sysaufs_br_init(struct au_branch *br);
31499 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31500 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31502 +#define sysaufs_brs_init() do {} while (0)
31505 +#define sysaufs_attr_group NULL
31507 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31508 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31509 + struct attribute *attr, char *buf)
31510 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31511 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31512 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31514 +static inline void sysaufs_brs_init(void)
31519 +#endif /* CONFIG_SYSFS */
31521 +#endif /* __KERNEL__ */
31522 +#endif /* __SYSAUFS_H__ */
31523 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31524 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31525 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31527 +// SPDX-License-Identifier: GPL-2.0
31529 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31531 + * This program is free software; you can redistribute it and/or modify
31532 + * it under the terms of the GNU General Public License as published by
31533 + * the Free Software Foundation; either version 2 of the License, or
31534 + * (at your option) any later version.
31536 + * This program is distributed in the hope that it will be useful,
31537 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31538 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31539 + * GNU General Public License for more details.
31541 + * You should have received a copy of the GNU General Public License
31542 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31546 + * sysfs interface
31549 +#include <linux/compat.h>
31550 +#include <linux/seq_file.h>
31553 +#ifdef CONFIG_AUFS_FS_MODULE
31554 +/* this entry violates the "one line per file" policy of sysfs */
31555 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31559 + static char *conf =
31560 +/* this file is generated at compiling */
31561 +#include "conf.str"
31564 + err = snprintf(buf, PAGE_SIZE, conf);
31565 + if (unlikely(err >= PAGE_SIZE))
31570 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31573 +static struct attribute *au_attr[] = {
31574 +#ifdef CONFIG_AUFS_FS_MODULE
31575 + &au_config_attr.attr,
31577 + NULL, /* need to NULL terminate the list of attributes */
31580 +static struct attribute_group sysaufs_attr_group_body = {
31584 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31586 +/* ---------------------------------------------------------------------- */
31588 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31592 + SiMustAnyLock(sb);
31595 + if (au_opt_test(au_mntflags(sb), XINO)) {
31596 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31597 + seq_putc(seq, '\n');
31603 + * the lifetime of branch is independent from the entry under sysfs.
31604 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31607 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31608 + aufs_bindex_t bindex, int idx)
31611 + struct path path;
31612 + struct dentry *root;
31613 + struct au_branch *br;
31614 + au_br_perm_str_t perm;
31616 + AuDbg("b%d\n", bindex);
31619 + root = sb->s_root;
31620 + di_read_lock_parent(root, !AuLock_IR);
31621 + br = au_sbr(sb, bindex);
31624 + case AuBrSysfs_BR:
31625 + path.mnt = au_br_mnt(br);
31626 + path.dentry = au_h_dptr(root, bindex);
31627 + err = au_seq_path(seq, &path);
31629 + au_optstr_br_perm(&perm, br->br_perm);
31630 + seq_printf(seq, "=%s\n", perm.a);
31633 + case AuBrSysfs_BRID:
31634 + seq_printf(seq, "%d\n", br->br_id);
31637 + di_read_unlock(root, !AuLock_IR);
31638 + if (unlikely(err || seq_has_overflowed(seq)))
31644 +/* ---------------------------------------------------------------------- */
31646 +static struct seq_file *au_seq(char *p, ssize_t len)
31648 + struct seq_file *seq;
31650 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31652 + /* mutex_init(&seq.lock); */
31655 + return seq; /* success */
31658 + seq = ERR_PTR(-ENOMEM);
31662 +#define SysaufsBr_PREFIX "br"
31663 +#define SysaufsBrid_PREFIX "brid"
31665 +/* todo: file size may exceed PAGE_SIZE */
31666 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31672 + aufs_bindex_t bbot;
31673 + struct au_sbinfo *sbinfo;
31674 + struct super_block *sb;
31675 + struct seq_file *seq;
31677 + struct attribute **cattr;
31679 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31680 + sb = sbinfo->si_sb;
31683 + * prevent a race condition between sysfs and aufs.
31684 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31685 + * prohibits maintaining the sysfs entries.
31686 + * hew we acquire read lock after sysfs_get_active_two().
31687 + * on the other hand, the remount process may maintain the sysfs/aufs
31688 + * entries after acquiring write lock.
31689 + * it can cause a deadlock.
31690 + * simply we gave up processing read here.
31693 + if (unlikely(!si_noflush_read_trylock(sb)))
31696 + seq = au_seq(buf, PAGE_SIZE);
31697 + err = PTR_ERR(seq);
31701 + name = (void *)attr->name;
31702 + cattr = sysaufs_si_attrs;
31704 + if (!strcmp(name, (*cattr)->name)) {
31705 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31712 + if (!strncmp(name, SysaufsBrid_PREFIX,
31713 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31714 + idx = AuBrSysfs_BRID;
31715 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31716 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31717 + sizeof(SysaufsBr_PREFIX) - 1)) {
31718 + idx = AuBrSysfs_BR;
31719 + name += sizeof(SysaufsBr_PREFIX) - 1;
31723 + err = kstrtol(name, 10, &l);
31725 + bbot = au_sbbot(sb);
31727 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31734 + err = seq->count;
31735 + /* sysfs limit */
31736 + if (unlikely(err == PAGE_SIZE))
31739 + au_kfree_rcu(seq);
31741 + si_read_unlock(sb);
31746 +/* ---------------------------------------------------------------------- */
31748 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31752 + aufs_bindex_t bindex, bbot;
31755 + struct seq_file *seq;
31756 + struct au_branch *br;
31758 + si_read_lock(sb, AuLock_FLUSH);
31759 + bbot = au_sbbot(sb);
31765 + buf = (void *)__get_free_page(GFP_NOFS);
31766 + if (unlikely(!buf))
31769 + seq = au_seq(buf, PAGE_SIZE);
31770 + err = PTR_ERR(seq);
31774 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31775 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31776 + /* VERIFY_WRITE */
31777 + err = !access_ok(arg, sizeof(*arg));
31778 + if (unlikely(err))
31781 + br = au_sbr(sb, bindex);
31782 + brid = br->br_id;
31783 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31784 + err = __put_user(brid, &arg->id);
31785 + if (unlikely(err))
31788 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31789 + err = __put_user(br->br_perm, &arg->perm);
31790 + if (unlikely(err))
31793 + err = au_seq_path(seq, &br->br_path);
31794 + if (unlikely(err))
31796 + seq_putc(seq, '\0');
31797 + if (!seq_has_overflowed(seq)) {
31798 + err = copy_to_user(arg->path, seq->buf, seq->count);
31800 + if (unlikely(err))
31807 + if (unlikely(err))
31811 + au_kfree_rcu(seq);
31813 + free_page((unsigned long)buf);
31815 + si_read_unlock(sb);
31819 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31821 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31824 +#ifdef CONFIG_COMPAT
31825 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31827 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31831 +/* ---------------------------------------------------------------------- */
31833 +void sysaufs_br_init(struct au_branch *br)
31836 + struct au_brsysfs *br_sysfs;
31837 + struct attribute *attr;
31839 + br_sysfs = br->br_sysfs;
31840 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31841 + attr = &br_sysfs->attr;
31842 + sysfs_attr_init(attr);
31843 + attr->name = br_sysfs->name;
31844 + attr->mode = 0444;
31849 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31851 + struct au_branch *br;
31852 + struct kobject *kobj;
31853 + struct au_brsysfs *br_sysfs;
31855 + aufs_bindex_t bbot;
31857 + if (!sysaufs_brs)
31860 + kobj = &au_sbi(sb)->si_kobj;
31861 + bbot = au_sbbot(sb);
31862 + for (; bindex <= bbot; bindex++) {
31863 + br = au_sbr(sb, bindex);
31864 + br_sysfs = br->br_sysfs;
31865 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31866 + sysfs_remove_file(kobj, &br_sysfs->attr);
31872 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31875 + aufs_bindex_t bbot;
31876 + struct kobject *kobj;
31877 + struct au_branch *br;
31878 + struct au_brsysfs *br_sysfs;
31880 + if (!sysaufs_brs)
31883 + kobj = &au_sbi(sb)->si_kobj;
31884 + bbot = au_sbbot(sb);
31885 + for (; bindex <= bbot; bindex++) {
31886 + br = au_sbr(sb, bindex);
31887 + br_sysfs = br->br_sysfs;
31888 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31889 + SysaufsBr_PREFIX "%d", bindex);
31890 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31891 + SysaufsBrid_PREFIX "%d", bindex);
31892 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31893 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31894 + if (unlikely(err))
31895 + pr_warn("failed %s under sysfs(%d)\n",
31896 + br_sysfs->name, err);
31901 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31902 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31903 +++ linux/fs/aufs/sysrq.c 2023-10-31 09:31:04.199880750 +0100
31905 +// SPDX-License-Identifier: GPL-2.0
31907 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31909 + * This program is free software; you can redistribute it and/or modify
31910 + * it under the terms of the GNU General Public License as published by
31911 + * the Free Software Foundation; either version 2 of the License, or
31912 + * (at your option) any later version.
31914 + * This program is distributed in the hope that it will be useful,
31915 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31916 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31917 + * GNU General Public License for more details.
31919 + * You should have received a copy of the GNU General Public License
31920 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31924 + * magic sysrq handler
31927 +/* #include <linux/sysrq.h> */
31928 +#include <linux/writeback.h>
31931 +/* ---------------------------------------------------------------------- */
31933 +static void sysrq_sb(struct super_block *sb)
31936 + struct au_sbinfo *sbinfo;
31937 + struct file *file;
31938 + struct hlist_bl_head *files;
31939 + struct hlist_bl_node *pos;
31940 + struct au_finfo *finfo;
31943 + plevel = au_plevel;
31944 + au_plevel = KERN_WARNING;
31946 + /* since we define pr_fmt, call printk directly */
31947 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31949 + sbinfo = au_sbi(sb);
31950 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31951 + pr("superblock\n");
31954 +#if 0 /* reserved */
31956 + int err, i, j, ndentry;
31957 + struct au_dcsub_pages dpages;
31958 + struct au_dpage *dpage;
31960 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31961 + if (unlikely(err))
31963 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31965 + for (i = 0; i < dpages.ndpage; i++) {
31966 + dpage = dpages.dpages + i;
31967 + ndentry = dpage->ndentry;
31968 + for (j = 0; j < ndentry; j++)
31969 + au_dpri_dentry(dpage->dentries[j]);
31971 + au_dpages_free(&dpages);
31975 + pr("isolated inode\n");
31976 + spin_lock(&sb->s_inode_list_lock);
31977 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31978 + spin_lock(&i->i_lock);
31979 + if (hlist_empty(&i->i_dentry))
31980 + au_dpri_inode(i);
31981 + spin_unlock(&i->i_lock);
31983 + spin_unlock(&sb->s_inode_list_lock);
31986 + files = &au_sbi(sb)->si_files;
31987 + hlist_bl_lock(files);
31988 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31991 + file = finfo->fi_file;
31992 + mode = file_inode(file)->i_mode;
31993 + if (!special_file(mode))
31994 + au_dpri_file(file);
31996 + hlist_bl_unlock(files);
32000 + au_plevel = plevel;
32003 +/* ---------------------------------------------------------------------- */
32005 +/* module parameter */
32006 +static char *aufs_sysrq_key = "a";
32007 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32008 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32010 +static void au_sysrq(u8 key __maybe_unused)
32012 + struct au_sbinfo *sbinfo;
32013 + struct hlist_bl_node *pos;
32016 + au_sbilist_lock();
32017 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32018 + sysrq_sb(sbinfo->si_sb);
32019 + au_sbilist_unlock();
32023 +static struct sysrq_key_op au_sysrq_op = {
32024 + .handler = au_sysrq,
32025 + .help_msg = "Aufs",
32026 + .action_msg = "Aufs",
32027 + .enable_mask = SYSRQ_ENABLE_DUMP
32030 +/* ---------------------------------------------------------------------- */
32032 +int __init au_sysrq_init(void)
32038 + key = *aufs_sysrq_key;
32039 + if ('a' <= key && key <= 'z')
32040 + err = register_sysrq_key(key, &au_sysrq_op);
32041 + if (unlikely(err))
32042 + pr_err("err %d, sysrq=%c\n", err, key);
32046 +void au_sysrq_fin(void)
32050 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32051 + if (unlikely(err))
32052 + pr_err("err %d (ignored)\n", err);
32054 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32055 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32056 +++ linux/fs/aufs/vdir.c 2022-12-17 09:21:34.799855195 +0100
32058 +// SPDX-License-Identifier: GPL-2.0
32060 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32062 + * This program is free software; you can redistribute it and/or modify
32063 + * it under the terms of the GNU General Public License as published by
32064 + * the Free Software Foundation; either version 2 of the License, or
32065 + * (at your option) any later version.
32067 + * This program is distributed in the hope that it will be useful,
32068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32070 + * GNU General Public License for more details.
32072 + * You should have received a copy of the GNU General Public License
32073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32077 + * virtual or vertical directory
32080 +#include <linux/iversion.h>
32083 +static unsigned int calc_size(int nlen)
32085 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32088 +static int set_deblk_end(union au_vdir_deblk_p *p,
32089 + union au_vdir_deblk_p *deblk_end)
32091 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32092 + p->de->de_str.len = 0;
32096 + return -1; /* error */
32099 +/* returns true or false */
32100 +static int is_deblk_end(union au_vdir_deblk_p *p,
32101 + union au_vdir_deblk_p *deblk_end)
32103 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32104 + return !p->de->de_str.len;
32108 +static unsigned char *last_deblk(struct au_vdir *vdir)
32110 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32113 +/* ---------------------------------------------------------------------- */
32115 +/* estimate the appropriate size for name hash table */
32116 +unsigned int au_rdhash_est(loff_t sz)
32124 + if (sz < AUFS_RDHASH_DEF)
32125 + n = AUFS_RDHASH_DEF;
32126 + /* pr_info("n %u\n", n); */
32131 + * the allocated memory has to be freed by
32132 + * au_nhash_wh_free() or au_nhash_de_free().
32134 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32136 + struct hlist_head *head;
32140 + sz = sizeof(*nhash->nh_head) * num_hash;
32141 + head = kmalloc(sz, gfp);
32143 + nhash->nh_num = num_hash;
32144 + nhash->nh_head = head;
32145 + for (u = 0; u < num_hash; u++)
32146 + INIT_HLIST_HEAD(head++);
32147 + return 0; /* success */
32153 +static void nhash_count(struct hlist_head *head)
32155 +#if 0 /* debugging */
32157 + struct hlist_node *pos;
32160 + hlist_for_each(pos, head)
32162 + pr_info("%lu\n", n);
32166 +static void au_nhash_wh_do_free(struct hlist_head *head)
32168 + struct au_vdir_wh *pos;
32169 + struct hlist_node *node;
32171 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32172 + au_kfree_rcu(pos);
32175 +static void au_nhash_de_do_free(struct hlist_head *head)
32177 + struct au_vdir_dehstr *pos;
32178 + struct hlist_node *node;
32180 + hlist_for_each_entry_safe(pos, node, head, hash)
32181 + au_cache_free_vdir_dehstr(pos);
32184 +static void au_nhash_do_free(struct au_nhash *nhash,
32185 + void (*free)(struct hlist_head *head))
32188 + struct hlist_head *head;
32190 + n = nhash->nh_num;
32194 + head = nhash->nh_head;
32195 + while (n-- > 0) {
32196 + nhash_count(head);
32199 + au_kfree_try_rcu(nhash->nh_head);
32202 +void au_nhash_wh_free(struct au_nhash *whlist)
32204 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32207 +static void au_nhash_de_free(struct au_nhash *delist)
32209 + au_nhash_do_free(delist, au_nhash_de_do_free);
32212 +/* ---------------------------------------------------------------------- */
32214 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32218 + unsigned int u, n;
32219 + struct hlist_head *head;
32220 + struct au_vdir_wh *pos;
32223 + n = whlist->nh_num;
32224 + head = whlist->nh_head;
32225 + for (u = 0; u < n; u++, head++)
32226 + hlist_for_each_entry(pos, head, wh_hash)
32227 + if (pos->wh_bindex == btgt && ++num > limit)
32232 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32233 + unsigned char *name,
32234 + unsigned int len)
32237 + /* const unsigned int magic_bit = 12; */
32239 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32246 + /* v = hash_long(v, magic_bit); */
32247 + v %= nhash->nh_num;
32248 + return nhash->nh_head + v;
32251 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32254 + return str->len == nlen && !memcmp(str->name, name, nlen);
32257 +/* returns found or not */
32258 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32260 + struct hlist_head *head;
32261 + struct au_vdir_wh *pos;
32262 + struct au_vdir_destr *str;
32264 + head = au_name_hash(whlist, name, nlen);
32265 + hlist_for_each_entry(pos, head, wh_hash) {
32266 + str = &pos->wh_str;
32267 + AuDbg("%.*s\n", str->len, str->name);
32268 + if (au_nhash_test_name(str, name, nlen))
32274 +/* returns found(true) or not */
32275 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32277 + struct hlist_head *head;
32278 + struct au_vdir_dehstr *pos;
32279 + struct au_vdir_destr *str;
32281 + head = au_name_hash(delist, name, nlen);
32282 + hlist_for_each_entry(pos, head, hash) {
32284 + AuDbg("%.*s\n", str->len, str->name);
32285 + if (au_nhash_test_name(str, name, nlen))
32291 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32292 + unsigned char d_type)
32294 +#ifdef CONFIG_AUFS_SHWH
32295 + wh->wh_ino = ino;
32296 + wh->wh_type = d_type;
32300 +/* ---------------------------------------------------------------------- */
32302 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32303 + unsigned int d_type, aufs_bindex_t bindex,
32304 + unsigned char shwh)
32307 + struct au_vdir_destr *str;
32308 + struct au_vdir_wh *wh;
32310 + AuDbg("%.*s\n", nlen, name);
32311 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32314 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32315 + if (unlikely(!wh))
32319 + wh->wh_bindex = bindex;
32321 + au_shwh_init_wh(wh, ino, d_type);
32322 + str = &wh->wh_str;
32324 + memcpy(str->name, name, nlen);
32325 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32332 +static int append_deblk(struct au_vdir *vdir)
32335 + unsigned long ul;
32336 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32337 + union au_vdir_deblk_p p, deblk_end;
32338 + unsigned char **o;
32341 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32342 + GFP_NOFS, /*may_shrink*/0);
32343 + if (unlikely(!o))
32346 + vdir->vd_deblk = o;
32347 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32349 + ul = vdir->vd_nblk++;
32350 + vdir->vd_deblk[ul] = p.deblk;
32351 + vdir->vd_last.ul = ul;
32352 + vdir->vd_last.p.deblk = p.deblk;
32353 + deblk_end.deblk = p.deblk + deblk_sz;
32354 + err = set_deblk_end(&p, &deblk_end);
32361 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32362 + unsigned int d_type, struct au_nhash *delist)
32366 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32367 + union au_vdir_deblk_p p, *room, deblk_end;
32368 + struct au_vdir_dehstr *dehstr;
32370 + p.deblk = last_deblk(vdir);
32371 + deblk_end.deblk = p.deblk + deblk_sz;
32372 + room = &vdir->vd_last.p;
32373 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32374 + || !is_deblk_end(room, &deblk_end));
32376 + sz = calc_size(nlen);
32377 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32378 + err = append_deblk(vdir);
32379 + if (unlikely(err))
32382 + p.deblk = last_deblk(vdir);
32383 + deblk_end.deblk = p.deblk + deblk_sz;
32385 + AuDebugOn(room->deblk != p.deblk);
32389 + dehstr = au_cache_alloc_vdir_dehstr();
32390 + if (unlikely(!dehstr))
32393 + dehstr->str = &room->de->de_str;
32394 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32395 + room->de->de_ino = ino;
32396 + room->de->de_type = d_type;
32397 + room->de->de_str.len = nlen;
32398 + memcpy(room->de->de_str.name, name, nlen);
32401 + room->deblk += sz;
32402 + if (unlikely(set_deblk_end(room, &deblk_end)))
32403 + err = append_deblk(vdir);
32410 +/* ---------------------------------------------------------------------- */
32412 +void au_vdir_free(struct au_vdir *vdir)
32414 + unsigned char **deblk;
32416 + deblk = vdir->vd_deblk;
32417 + while (vdir->vd_nblk--)
32418 + au_kfree_try_rcu(*deblk++);
32419 + au_kfree_try_rcu(vdir->vd_deblk);
32420 + au_cache_free_vdir(vdir);
32423 +static struct au_vdir *alloc_vdir(struct file *file)
32425 + struct au_vdir *vdir;
32426 + struct super_block *sb;
32429 + sb = file->f_path.dentry->d_sb;
32430 + SiMustAnyLock(sb);
32433 + vdir = au_cache_alloc_vdir();
32434 + if (unlikely(!vdir))
32437 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32438 + if (unlikely(!vdir->vd_deblk))
32441 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32442 + if (!vdir->vd_deblk_sz) {
32443 + /* estimate the appropriate size for deblk */
32444 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32445 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32447 + vdir->vd_nblk = 0;
32448 + vdir->vd_version = 0;
32449 + vdir->vd_jiffy = 0;
32450 + err = append_deblk(vdir);
32452 + return vdir; /* success */
32454 + au_kfree_try_rcu(vdir->vd_deblk);
32457 + au_cache_free_vdir(vdir);
32459 + vdir = ERR_PTR(err);
32463 +static int reinit_vdir(struct au_vdir *vdir)
32466 + union au_vdir_deblk_p p, deblk_end;
32468 + while (vdir->vd_nblk > 1) {
32469 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32470 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32473 + p.deblk = vdir->vd_deblk[0];
32474 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32475 + err = set_deblk_end(&p, &deblk_end);
32476 + /* keep vd_dblk_sz */
32477 + vdir->vd_last.ul = 0;
32478 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32479 + vdir->vd_version = 0;
32480 + vdir->vd_jiffy = 0;
32485 +/* ---------------------------------------------------------------------- */
32487 +#define AuFillVdir_CALLED 1
32488 +#define AuFillVdir_WHABLE (1 << 1)
32489 +#define AuFillVdir_SHWH (1 << 2)
32490 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32491 +#define au_fset_fillvdir(flags, name) \
32492 + do { (flags) |= AuFillVdir_##name; } while (0)
32493 +#define au_fclr_fillvdir(flags, name) \
32494 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32496 +#ifndef CONFIG_AUFS_SHWH
32497 +#undef AuFillVdir_SHWH
32498 +#define AuFillVdir_SHWH 0
32501 +struct fillvdir_arg {
32502 + struct dir_context ctx;
32503 + struct file *file;
32504 + struct au_vdir *vdir;
32505 + struct au_nhash delist;
32506 + struct au_nhash whlist;
32507 + aufs_bindex_t bindex;
32508 + unsigned int flags;
32512 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32513 + loff_t offset __maybe_unused, u64 h_ino,
32514 + unsigned int d_type)
32516 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32517 + char *name = (void *)__name;
32518 + struct super_block *sb;
32520 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32523 + sb = arg->file->f_path.dentry->d_sb;
32524 + au_fset_fillvdir(arg->flags, CALLED);
32526 + if (nlen <= AUFS_WH_PFX_LEN
32527 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32528 + if (test_known(&arg->delist, name, nlen)
32529 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32530 + goto out; /* already exists or whiteouted */
32532 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32534 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32535 + d_type = DT_UNKNOWN;
32536 + arg->err = append_de(arg->vdir, name, nlen, ino,
32537 + d_type, &arg->delist);
32539 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32540 + name += AUFS_WH_PFX_LEN;
32541 + nlen -= AUFS_WH_PFX_LEN;
32542 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32543 + goto out; /* already whiteouted */
32545 + ino = 0; /* just to suppress a warning */
32547 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32550 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32551 + d_type = DT_UNKNOWN;
32552 + arg->err = au_nhash_append_wh
32553 + (&arg->whlist, name, nlen, ino, d_type,
32554 + arg->bindex, shwh);
32560 + arg->vdir->vd_jiffy = jiffies;
32562 + AuTraceErr(arg->err);
32563 + return !arg->err;
32566 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32567 + struct au_nhash *whlist, struct au_nhash *delist)
32569 +#ifdef CONFIG_AUFS_SHWH
32571 + unsigned int nh, u;
32572 + struct hlist_head *head;
32573 + struct au_vdir_wh *pos;
32574 + struct hlist_node *n;
32576 + struct au_vdir_destr *destr;
32578 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32581 + o = p = (void *)__get_free_page(GFP_NOFS);
32582 + if (unlikely(!p))
32586 + nh = whlist->nh_num;
32587 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32588 + p += AUFS_WH_PFX_LEN;
32589 + for (u = 0; u < nh; u++) {
32590 + head = whlist->nh_head + u;
32591 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32592 + destr = &pos->wh_str;
32593 + memcpy(p, destr->name, destr->len);
32594 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32595 + pos->wh_ino, pos->wh_type, delist);
32596 + if (unlikely(err))
32601 + free_page((unsigned long)o);
32611 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32614 + unsigned int rdhash;
32616 + aufs_bindex_t bbot, bindex, btop;
32617 + unsigned char shwh;
32618 + struct file *hf, *file;
32619 + struct super_block *sb;
32621 + file = arg->file;
32622 + sb = file->f_path.dentry->d_sb;
32623 + SiMustAnyLock(sb);
32625 + rdhash = au_sbi(sb)->si_rdhash;
32627 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32628 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32629 + if (unlikely(err))
32631 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32632 + if (unlikely(err))
32638 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32640 + au_fset_fillvdir(arg->flags, SHWH);
32642 + btop = au_fbtop(file);
32643 + bbot = au_fbbot_dir(file);
32644 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32645 + hf = au_hf_dir(file, bindex);
32649 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32651 + if (unlikely(offset))
32654 + arg->bindex = bindex;
32655 + au_fclr_fillvdir(arg->flags, WHABLE);
32657 + || (bindex != bbot
32658 + && au_br_whable(au_sbr_perm(sb, bindex))))
32659 + au_fset_fillvdir(arg->flags, WHABLE);
32662 + au_fclr_fillvdir(arg->flags, CALLED);
32664 + err = vfsub_iterate_dir(hf, &arg->ctx);
32667 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32670 + * dir_relax() may be good for concurrency, but aufs should not
32671 + * use it since it will cause a lockdep problem.
32675 + if (!err && shwh)
32676 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32678 + au_nhash_wh_free(&arg->whlist);
32681 + au_nhash_de_free(&arg->delist);
32686 +static int read_vdir(struct file *file, int may_read)
32689 + unsigned long expire;
32690 + unsigned char do_read;
32691 + struct fillvdir_arg arg = {
32693 + .actor = fillvdir
32696 + struct inode *inode;
32697 + struct au_vdir *vdir, *allocated;
32700 + inode = file_inode(file);
32701 + IMustLock(inode);
32702 + IiMustWriteLock(inode);
32703 + SiMustAnyLock(inode->i_sb);
32705 + allocated = NULL;
32707 + expire = au_sbi(inode->i_sb)->si_rdcache;
32708 + vdir = au_ivdir(inode);
32711 + vdir = alloc_vdir(file);
32712 + err = PTR_ERR(vdir);
32713 + if (IS_ERR(vdir))
32716 + allocated = vdir;
32717 + } else if (may_read
32718 + && (!inode_eq_iversion(inode, vdir->vd_version)
32719 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32721 + err = reinit_vdir(vdir);
32722 + if (unlikely(err))
32727 + return 0; /* success */
32731 + err = au_do_read_vdir(&arg);
32733 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32734 + vdir->vd_version = inode_query_iversion(inode);
32735 + vdir->vd_last.ul = 0;
32736 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32738 + au_set_ivdir(inode, allocated);
32739 + } else if (allocated)
32740 + au_vdir_free(allocated);
32746 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32749 + unsigned long ul, n;
32750 + const unsigned int deblk_sz = src->vd_deblk_sz;
32752 + AuDebugOn(tgt->vd_nblk != 1);
32755 + if (tgt->vd_nblk < src->vd_nblk) {
32756 + unsigned char **p;
32758 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32759 + GFP_NOFS, /*may_shrink*/0);
32760 + if (unlikely(!p))
32762 + tgt->vd_deblk = p;
32765 + if (tgt->vd_deblk_sz != deblk_sz) {
32766 + unsigned char *p;
32768 + tgt->vd_deblk_sz = deblk_sz;
32769 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32770 + /*may_shrink*/1);
32771 + if (unlikely(!p))
32773 + tgt->vd_deblk[0] = p;
32775 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32776 + tgt->vd_version = src->vd_version;
32777 + tgt->vd_jiffy = src->vd_jiffy;
32779 + n = src->vd_nblk;
32780 + for (ul = 1; ul < n; ul++) {
32781 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32783 + if (unlikely(!tgt->vd_deblk[ul]))
32787 + tgt->vd_nblk = n;
32788 + tgt->vd_last.ul = tgt->vd_last.ul;
32789 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32790 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32791 + - src->vd_deblk[src->vd_last.ul];
32793 + return 0; /* success */
32796 + rerr = reinit_vdir(tgt);
32801 +int au_vdir_init(struct file *file)
32804 + struct inode *inode;
32805 + struct au_vdir *vdir_cache, *allocated;
32807 + /* test file->f_pos here instead of ctx->pos */
32808 + err = read_vdir(file, !file->f_pos);
32809 + if (unlikely(err))
32812 + allocated = NULL;
32813 + vdir_cache = au_fvdir_cache(file);
32814 + if (!vdir_cache) {
32815 + vdir_cache = alloc_vdir(file);
32816 + err = PTR_ERR(vdir_cache);
32817 + if (IS_ERR(vdir_cache))
32819 + allocated = vdir_cache;
32820 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32821 + /* test file->f_pos here instead of ctx->pos */
32822 + err = reinit_vdir(vdir_cache);
32823 + if (unlikely(err))
32826 + return 0; /* success */
32828 + inode = file_inode(file);
32829 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32831 + file->f_version = inode_query_iversion(inode);
32833 + au_set_fvdir_cache(file, allocated);
32834 + } else if (allocated)
32835 + au_vdir_free(allocated);
32841 +static loff_t calc_offset(struct au_vdir *vdir)
32844 + union au_vdir_deblk_p p;
32846 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32847 + offset = vdir->vd_last.p.deblk - p.deblk;
32848 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32852 +/* returns true or false */
32853 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32856 + unsigned int deblk_sz;
32857 + unsigned long ul, n;
32859 + union au_vdir_deblk_p p, deblk_end;
32860 + struct au_vdir *vdir_cache;
32863 + vdir_cache = au_fvdir_cache(file);
32864 + offset = calc_offset(vdir_cache);
32865 + AuDbg("offset %lld\n", offset);
32866 + if (ctx->pos == offset)
32869 + vdir_cache->vd_last.ul = 0;
32870 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32875 + deblk_sz = vdir_cache->vd_deblk_sz;
32876 + ul = div64_u64(ctx->pos, deblk_sz);
32877 + AuDbg("ul %lu\n", ul);
32878 + if (ul >= vdir_cache->vd_nblk)
32881 + n = vdir_cache->vd_nblk;
32882 + for (; ul < n; ul++) {
32883 + p.deblk = vdir_cache->vd_deblk[ul];
32884 + deblk_end.deblk = p.deblk + deblk_sz;
32886 + offset *= deblk_sz;
32887 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32890 + l = calc_size(p.de->de_str.len);
32894 + if (!is_deblk_end(&p, &deblk_end)) {
32896 + vdir_cache->vd_last.ul = ul;
32897 + vdir_cache->vd_last.p = p;
32905 + AuDbg("valid %d\n", !valid);
32909 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32911 + unsigned int l, deblk_sz;
32912 + union au_vdir_deblk_p deblk_end;
32913 + struct au_vdir *vdir_cache;
32914 + struct au_vdir_de *de;
32916 + if (!seek_vdir(file, ctx))
32919 + vdir_cache = au_fvdir_cache(file);
32920 + deblk_sz = vdir_cache->vd_deblk_sz;
32922 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32923 + deblk_end.deblk += deblk_sz;
32924 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32925 + de = vdir_cache->vd_last.p.de;
32926 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32927 + de->de_str.len, de->de_str.name, ctx->pos,
32928 + (unsigned long)de->de_ino, de->de_type);
32929 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32930 + de->de_str.len, de->de_ino,
32932 + /* todo: ignore the error caused by udba? */
32933 + /* return err; */
32937 + l = calc_size(de->de_str.len);
32938 + vdir_cache->vd_last.p.deblk += l;
32941 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32942 + vdir_cache->vd_last.ul++;
32943 + vdir_cache->vd_last.p.deblk
32944 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32945 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32954 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32955 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32956 +++ linux/fs/aufs/vfsub.c 2023-10-31 09:31:04.199880750 +0100
32958 +// SPDX-License-Identifier: GPL-2.0
32960 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32962 + * This program is free software; you can redistribute it and/or modify
32963 + * it under the terms of the GNU General Public License as published by
32964 + * the Free Software Foundation; either version 2 of the License, or
32965 + * (at your option) any later version.
32967 + * This program is distributed in the hope that it will be useful,
32968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32970 + * GNU General Public License for more details.
32972 + * You should have received a copy of the GNU General Public License
32973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32977 + * sub-routines for VFS
32980 +#include <linux/mnt_namespace.h>
32981 +#include <linux/nsproxy.h>
32982 +#include <linux/security.h>
32983 +#include <linux/splice.h>
32986 +#ifdef CONFIG_AUFS_BR_FUSE
32987 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32989 + if (!au_test_fuse(h_sb) || !au_userns)
32992 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32996 +int vfsub_sync_filesystem(struct super_block *h_sb)
33001 + down_read(&h_sb->s_umount);
33002 + err = sync_filesystem(h_sb);
33003 + up_read(&h_sb->s_umount);
33009 +/* ---------------------------------------------------------------------- */
33011 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33015 + struct super_block *h_sb;
33018 + * Always needs h_path->mnt for LSM or FUSE branch.
33020 + AuDebugOn(!h_path->mnt);
33022 + /* for remote fs, leave work for its getattr or d_revalidate */
33023 + /* for bad i_attr fs, handle them in aufs_getattr() */
33024 + /* still some fs may acquire i_mutex. we need to skip them */
33028 + h_sb = h_path->dentry->d_sb;
33029 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33031 + err = vfsub_getattr(h_path, &st);
33036 +/* ---------------------------------------------------------------------- */
33038 +struct file *vfsub_dentry_open(struct path *path, int flags)
33040 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33044 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33046 + struct file *file;
33049 + file = filp_open(path,
33050 + oflags /* | __FMODE_NONOTIFY */,
33053 + if (IS_ERR(file))
33055 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33062 + * Ideally this function should call VFS:do_last() in order to keep all its
33063 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33064 + * structure such as nameidata. This is a second (or third) best approach.
33065 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33067 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33068 + struct vfsub_aopen_args *args)
33071 + struct au_branch *br = args->br;
33072 + struct file *file = args->file;
33073 + /* copied from linux/fs/namei.c:atomic_open() */
33074 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33077 + AuDebugOn(!dir->i_op->atomic_open);
33079 + err = au_br_test_oflag(args->open_flag, br);
33080 + if (unlikely(err))
33083 + au_lcnt_inc(&br->br_nfiles);
33084 + file->f_path.dentry = DENTRY_NOT_SET;
33085 + file->f_path.mnt = au_br_mnt(br);
33086 + AuDbg("%ps\n", dir->i_op->atomic_open);
33087 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33088 + args->create_mode);
33089 + if (unlikely(err < 0)) {
33090 + au_lcnt_dec(&br->br_nfiles);
33094 + /* temporary workaround for nfsv4 branch */
33095 + if (au_test_nfs(dir->i_sb))
33096 + nfs_mark_for_revalidate(dir);
33098 + if (file->f_mode & FMODE_CREATED)
33099 + fsnotify_create(dir, dentry);
33100 + if (!(file->f_mode & FMODE_OPENED)) {
33101 + au_lcnt_dec(&br->br_nfiles);
33105 + /* todo: call VFS:may_open() here */
33106 + /* todo: ima_file_check() too? */
33107 + if (!err && (args->open_flag & __FMODE_EXEC))
33108 + err = deny_write_access(file);
33110 + fsnotify_open(file);
33112 + au_lcnt_dec(&br->br_nfiles);
33113 + /* note that the file is created and still opened */
33119 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33123 + err = kern_path(name, flags, path);
33124 + if (!err && d_is_positive(path->dentry))
33125 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33129 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33130 + struct path *ppath, int len)
33132 + struct path path;
33134 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33135 + if (IS_ERR(path.dentry))
33137 + if (d_is_positive(path.dentry)) {
33138 + path.mnt = ppath->mnt;
33139 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33143 + AuTraceErrPtr(path.dentry);
33144 + return path.dentry;
33147 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33150 + struct path path;
33152 + /* VFS checks it too, but by WARN_ON_ONCE() */
33153 + IMustLock(d_inode(ppath->dentry));
33155 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33156 + if (IS_ERR(path.dentry))
33158 + if (d_is_positive(path.dentry)) {
33159 + path.mnt = ppath->mnt;
33160 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33164 + AuTraceErrPtr(path.dentry);
33165 + return path.dentry;
33168 +void vfsub_call_lkup_one(void *args)
33170 + struct vfsub_lkup_one_args *a = args;
33171 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33174 +/* ---------------------------------------------------------------------- */
33176 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33177 + struct dentry *d2, struct au_hinode *hdir2)
33179 + struct dentry *d;
33182 + d = lock_rename(d1, d2);
33184 + au_hn_suspend(hdir1);
33185 + if (hdir1 != hdir2)
33186 + au_hn_suspend(hdir2);
33191 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33192 + struct dentry *d2, struct au_hinode *hdir2)
33194 + au_hn_resume(hdir1);
33195 + if (hdir1 != hdir2)
33196 + au_hn_resume(hdir2);
33198 + unlock_rename(d1, d2);
33202 +/* ---------------------------------------------------------------------- */
33204 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33207 + struct dentry *d;
33208 + struct mnt_idmap *idmap;
33212 + d = path->dentry;
33213 + path->dentry = d->d_parent;
33214 + err = security_path_mknod(path, d, mode, 0);
33215 + path->dentry = d;
33216 + if (unlikely(err))
33218 + idmap = mnt_idmap(path->mnt);
33221 + err = vfs_create(idmap, dir, path->dentry, mode, want_excl);
33224 + struct path tmp = *path;
33227 + vfsub_update_h_iattr(&tmp, &did);
33229 + tmp.dentry = path->dentry->d_parent;
33230 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33239 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33242 + struct dentry *d;
33243 + struct mnt_idmap *idmap;
33247 + d = path->dentry;
33248 + path->dentry = d->d_parent;
33249 + err = security_path_symlink(path, d, symname);
33250 + path->dentry = d;
33251 + if (unlikely(err))
33253 + idmap = mnt_idmap(path->mnt);
33256 + err = vfs_symlink(idmap, dir, path->dentry, symname);
33259 + struct path tmp = *path;
33262 + vfsub_update_h_iattr(&tmp, &did);
33264 + tmp.dentry = path->dentry->d_parent;
33265 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33274 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33277 + struct dentry *d;
33278 + struct mnt_idmap *idmap;
33282 + d = path->dentry;
33283 + path->dentry = d->d_parent;
33284 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33285 + path->dentry = d;
33286 + if (unlikely(err))
33288 + idmap = mnt_idmap(path->mnt);
33291 + err = vfs_mknod(idmap, dir, path->dentry, mode, dev);
33294 + struct path tmp = *path;
33297 + vfsub_update_h_iattr(&tmp, &did);
33299 + tmp.dentry = path->dentry->d_parent;
33300 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33309 +static int au_test_nlink(struct inode *inode)
33311 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33313 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33314 + || inode->i_nlink < link_max)
33319 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33320 + struct inode **delegated_inode)
33323 + struct dentry *d;
33324 + struct mnt_idmap *idmap;
33328 + err = au_test_nlink(d_inode(src_dentry));
33329 + if (unlikely(err))
33332 + /* we don't call may_linkat() */
33333 + d = path->dentry;
33334 + path->dentry = d->d_parent;
33335 + err = security_path_link(src_dentry, path, d);
33336 + path->dentry = d;
33337 + if (unlikely(err))
33339 + idmap = mnt_idmap(path->mnt);
33342 + err = vfs_link(src_dentry, idmap, dir, path->dentry, delegated_inode);
33345 + struct path tmp = *path;
33348 + /* fuse has different memory inode for the same inumber */
33349 + vfsub_update_h_iattr(&tmp, &did);
33351 + tmp.dentry = path->dentry->d_parent;
33352 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33353 + tmp.dentry = src_dentry;
33354 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33363 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33364 + struct inode *dir, struct path *path,
33365 + struct inode **delegated_inode, unsigned int flags)
33368 + struct renamedata rd;
33369 + struct path tmp = {
33372 + struct dentry *d;
33375 + IMustLock(src_dir);
33377 + d = path->dentry;
33378 + path->dentry = d->d_parent;
33379 + tmp.dentry = src_dentry->d_parent;
33380 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33381 + path->dentry = d;
33382 + if (unlikely(err))
33385 + rd.old_mnt_idmap = mnt_idmap(path->mnt);
33386 + rd.old_dir = src_dir;
33387 + rd.old_dentry = src_dentry;
33388 + rd.new_mnt_idmap = rd.old_mnt_idmap;
33389 + rd.new_dir = dir;
33390 + rd.new_dentry = path->dentry;
33391 + rd.delegated_inode = delegated_inode;
33392 + rd.flags = flags;
33394 + err = vfs_rename(&rd);
33399 + tmp.dentry = d->d_parent;
33400 + vfsub_update_h_iattr(&tmp, &did);
33402 + tmp.dentry = src_dentry;
33403 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33404 + tmp.dentry = src_dentry->d_parent;
33405 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33414 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33417 + struct dentry *d;
33418 + struct mnt_idmap *idmap;
33422 + d = path->dentry;
33423 + path->dentry = d->d_parent;
33424 + err = security_path_mkdir(path, d, mode);
33425 + path->dentry = d;
33426 + if (unlikely(err))
33428 + idmap = mnt_idmap(path->mnt);
33431 + err = vfs_mkdir(idmap, dir, path->dentry, mode);
33434 + struct path tmp = *path;
33437 + vfsub_update_h_iattr(&tmp, &did);
33439 + tmp.dentry = path->dentry->d_parent;
33440 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33449 +int vfsub_rmdir(struct inode *dir, struct path *path)
33452 + struct dentry *d;
33453 + struct mnt_idmap *idmap;
33457 + d = path->dentry;
33458 + path->dentry = d->d_parent;
33459 + err = security_path_rmdir(path, d);
33460 + path->dentry = d;
33461 + if (unlikely(err))
33463 + idmap = mnt_idmap(path->mnt);
33466 + err = vfs_rmdir(idmap, dir, path->dentry);
33469 + struct path tmp = {
33470 + .dentry = path->dentry->d_parent,
33474 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33481 +/* ---------------------------------------------------------------------- */
33483 +/* todo: support mmap_sem? */
33484 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33490 + err = vfs_read(file, ubuf, count, ppos);
33493 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33497 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33503 + err = kernel_read(file, kbuf, count, ppos);
33507 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33511 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33517 + err = vfs_write(file, ubuf, count, ppos);
33520 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33524 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33529 + err = kernel_write(file, kbuf, count, ppos);
33532 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33536 +int vfsub_flush(struct file *file, fl_owner_t id)
33541 + if (file->f_op->flush) {
33542 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33543 + err = file->f_op->flush(file, id);
33546 + err = file->f_op->flush(file, id);
33550 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33556 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33560 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33563 + err = iterate_dir(file, ctx);
33566 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33571 +long vfsub_splice_read(struct file *in, loff_t *ppos,
33572 + struct pipe_inode_info *pipe, size_t len,
33573 + unsigned int flags)
33578 + err = vfs_splice_read(in, ppos, pipe, len, flags);
33580 + file_accessed(in);
33582 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33586 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33587 + loff_t *ppos, size_t len, unsigned int flags)
33592 + err = do_splice_from(pipe, out, ppos, len, flags);
33595 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33599 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33603 + /* file can be NULL */
33605 + err = vfs_fsync(file, datasync);
33609 + AuDebugOn(!file);
33610 + path = &file->f_path;
33612 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33617 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33618 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33619 + struct file *h_file)
33622 + struct inode *h_inode;
33623 + struct super_block *h_sb;
33624 + struct mnt_idmap *h_idmap;
33627 + err = vfsub_truncate(h_path, length);
33631 + h_inode = d_inode(h_path->dentry);
33632 + h_sb = h_inode->i_sb;
33634 + sb_start_write(h_sb);
33636 + err = security_file_truncate(h_file);
33638 + h_idmap = mnt_idmap(h_path->mnt);
33640 + err = do_truncate(h_idmap, h_path->dentry, length, attr,
33645 + sb_end_write(h_sb);
33652 +/* ---------------------------------------------------------------------- */
33654 +struct au_vfsub_mkdir_args {
33656 + struct inode *dir;
33657 + struct path *path;
33661 +static void au_call_vfsub_mkdir(void *args)
33663 + struct au_vfsub_mkdir_args *a = args;
33664 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33667 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33669 + int err, do_sio, wkq_err;
33670 + struct mnt_idmap *idmap;
33672 + idmap = mnt_idmap(path->mnt);
33673 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33676 + err = vfsub_mkdir(dir, path, mode);
33679 + struct au_vfsub_mkdir_args args = {
33685 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33686 + if (unlikely(wkq_err))
33693 +struct au_vfsub_rmdir_args {
33695 + struct inode *dir;
33696 + struct path *path;
33699 +static void au_call_vfsub_rmdir(void *args)
33701 + struct au_vfsub_rmdir_args *a = args;
33702 + *a->errp = vfsub_rmdir(a->dir, a->path);
33705 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33707 + int err, do_sio, wkq_err;
33708 + struct mnt_idmap *idmap;
33710 + idmap = mnt_idmap(path->mnt);
33711 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33714 + err = vfsub_rmdir(dir, path);
33717 + struct au_vfsub_rmdir_args args = {
33722 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33723 + if (unlikely(wkq_err))
33730 +/* ---------------------------------------------------------------------- */
33732 +struct notify_change_args {
33734 + struct path *path;
33735 + struct iattr *ia;
33736 + struct inode **delegated_inode;
33739 +static void call_notify_change(void *args)
33741 + struct notify_change_args *a = args;
33742 + struct inode *h_inode;
33743 + struct mnt_idmap *idmap;
33745 + h_inode = d_inode(a->path->dentry);
33746 + IMustLock(h_inode);
33748 + *a->errp = -EPERM;
33749 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33750 + idmap = mnt_idmap(a->path->mnt);
33752 + *a->errp = notify_change(idmap, a->path->dentry, a->ia,
33753 + a->delegated_inode);
33756 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33758 + AuTraceErr(*a->errp);
33761 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33762 + struct inode **delegated_inode)
33765 + struct notify_change_args args = {
33769 + .delegated_inode = delegated_inode
33772 + call_notify_change(&args);
33777 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33778 + struct inode **delegated_inode)
33780 + int err, wkq_err;
33781 + struct notify_change_args args = {
33785 + .delegated_inode = delegated_inode
33788 + wkq_err = au_wkq_wait(call_notify_change, &args);
33789 + if (unlikely(wkq_err))
33795 +/* ---------------------------------------------------------------------- */
33797 +struct unlink_args {
33799 + struct inode *dir;
33800 + struct path *path;
33801 + struct inode **delegated_inode;
33804 +static void call_unlink(void *args)
33806 + struct unlink_args *a = args;
33807 + struct dentry *d = a->path->dentry;
33808 + struct inode *h_inode;
33809 + struct mnt_idmap *idmap;
33810 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33811 + && au_dcount(d) == 1);
33813 + IMustLock(a->dir);
33815 + a->path->dentry = d->d_parent;
33816 + *a->errp = security_path_unlink(a->path, d);
33817 + a->path->dentry = d;
33818 + if (unlikely(*a->errp))
33821 + if (!stop_sillyrename)
33824 + if (d_is_positive(d)) {
33825 + h_inode = d_inode(d);
33829 + idmap = mnt_idmap(a->path->mnt);
33831 + *a->errp = vfs_unlink(idmap, a->dir, d, a->delegated_inode);
33834 + struct path tmp = {
33835 + .dentry = d->d_parent,
33836 + .mnt = a->path->mnt
33838 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33841 + if (!stop_sillyrename)
33846 + AuTraceErr(*a->errp);
33850 + * @dir: must be locked.
33851 + * @dentry: target dentry.
33853 +int vfsub_unlink(struct inode *dir, struct path *path,
33854 + struct inode **delegated_inode, int force)
33857 + struct unlink_args args = {
33861 + .delegated_inode = delegated_inode
33865 + call_unlink(&args);
33869 + wkq_err = au_wkq_wait(call_unlink, &args);
33870 + if (unlikely(wkq_err))
33876 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33877 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33878 +++ linux/fs/aufs/vfsub.h 2023-10-31 09:31:04.199880750 +0100
33880 +/* SPDX-License-Identifier: GPL-2.0 */
33882 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33884 + * This program is free software; you can redistribute it and/or modify
33885 + * it under the terms of the GNU General Public License as published by
33886 + * the Free Software Foundation; either version 2 of the License, or
33887 + * (at your option) any later version.
33889 + * This program is distributed in the hope that it will be useful,
33890 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33891 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33892 + * GNU General Public License for more details.
33894 + * You should have received a copy of the GNU General Public License
33895 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33899 + * sub-routines for VFS
33902 +#ifndef __AUFS_VFSUB_H__
33903 +#define __AUFS_VFSUB_H__
33907 +#include <linux/fs.h>
33908 +#include <linux/mount.h>
33909 +#include <linux/posix_acl.h>
33910 +#include <linux/xattr.h>
33911 +#include "debug.h"
33913 +/* copied from linux/fs/internal.h */
33914 +/* todo: BAD approach!! */
33915 +extern void __mnt_drop_write(struct vfsmount *);
33916 +extern struct file *alloc_empty_file(int, const struct cred *);
33918 +/* ---------------------------------------------------------------------- */
33920 +/* lock subclass for lower inode */
33921 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33922 +/* reduce? gave up. */
33924 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33925 + AuLsc_I_PARENT, /* lower inode, parent first */
33926 + AuLsc_I_PARENT2, /* copyup dirs */
33927 + AuLsc_I_PARENT3, /* copyup wh */
33933 +/* to debug easier, do not make them inlined functions */
33934 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33935 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33937 +/* ---------------------------------------------------------------------- */
33939 +static inline void vfsub_drop_nlink(struct inode *inode)
33941 + AuDebugOn(!inode->i_nlink);
33942 + drop_nlink(inode);
33945 +static inline void vfsub_dead_dir(struct inode *inode)
33947 + AuDebugOn(!S_ISDIR(inode->i_mode));
33948 + inode->i_flags |= S_DEAD;
33949 + clear_nlink(inode);
33952 +static inline int vfsub_native_ro(struct inode *inode)
33954 + return sb_rdonly(inode->i_sb)
33955 + || IS_RDONLY(inode)
33956 + /* || IS_APPEND(inode) */
33957 + || IS_IMMUTABLE(inode);
33960 +#ifdef CONFIG_AUFS_BR_FUSE
33961 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33963 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33966 +int vfsub_sync_filesystem(struct super_block *h_sb);
33968 +/* ---------------------------------------------------------------------- */
33970 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33971 +struct file *vfsub_dentry_open(struct path *path, int flags);
33972 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33974 +struct vfsub_aopen_args {
33975 + struct file *file;
33976 + unsigned int open_flag;
33977 + umode_t create_mode;
33978 + struct au_branch *br;
33980 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33981 + struct vfsub_aopen_args *args);
33982 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33984 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33985 + struct path *ppath, int len);
33986 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33989 +struct vfsub_lkup_one_args {
33990 + struct dentry **errp;
33991 + struct qstr *name;
33992 + struct path *ppath;
33995 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33996 + struct path *ppath)
33998 + return vfsub_lookup_one_len(name->name, ppath, name->len);
34001 +void vfsub_call_lkup_one(void *args);
34003 +/* ---------------------------------------------------------------------- */
34005 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34010 + err = mnt_want_write(mnt);
34015 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34018 + mnt_drop_write(mnt);
34022 +#if 0 /* reserved */
34023 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34026 + mnt_drop_write_file(file);
34031 +static inline void vfsub_file_start_write(struct file *file)
34034 + file_start_write(file);
34038 +static inline void vfsub_file_end_write(struct file *file)
34041 + file_end_write(file);
34045 +/* ---------------------------------------------------------------------- */
34048 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34049 + struct dentry *d2, struct au_hinode *hdir2);
34050 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34051 + struct dentry *d2, struct au_hinode *hdir2);
34053 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34055 +int vfsub_symlink(struct inode *dir, struct path *path,
34056 + const char *symname);
34057 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34058 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34059 + struct path *path, struct inode **delegated_inode);
34060 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34061 + struct inode *hdir, struct path *path,
34062 + struct inode **delegated_inode, unsigned int flags);
34063 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34064 +int vfsub_rmdir(struct inode *dir, struct path *path);
34066 +/* ---------------------------------------------------------------------- */
34068 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34070 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34072 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34074 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34076 +int vfsub_flush(struct file *file, fl_owner_t id);
34077 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34079 +static inline loff_t vfsub_f_size_read(struct file *file)
34081 + return i_size_read(file_inode(file));
34084 +static inline unsigned int vfsub_file_flags(struct file *file)
34086 + unsigned int flags;
34088 + spin_lock(&file->f_lock);
34089 + flags = file->f_flags;
34090 + spin_unlock(&file->f_lock);
34095 +static inline int vfsub_file_execed(struct file *file)
34097 + /* todo: direct access f_flags */
34098 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34101 +#if 0 /* reserved */
34102 +static inline void vfsub_file_accessed(struct file *h_file)
34104 + file_accessed(h_file);
34105 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34109 +#if 0 /* reserved */
34110 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34111 + struct dentry *h_dentry)
34113 + struct path h_path = {
34114 + .dentry = h_dentry,
34117 + touch_atime(&h_path);
34118 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34122 +static inline int vfsub_update_time(struct inode *h_inode, int flags)
34124 + return inode_update_time(h_inode, flags);
34125 + /* no vfsub_update_h_iattr() since we don't have struct path */
34128 +#ifdef CONFIG_FS_POSIX_ACL
34129 +static inline int vfsub_acl_chmod(struct mnt_idmap *h_idmap,
34130 + struct dentry *h_dentry, umode_t h_mode)
34134 + err = posix_acl_chmod(h_idmap, h_dentry, h_mode);
34135 + if (err == -EOPNOTSUPP)
34140 +AuStubInt0(vfsub_acl_chmod, struct mnt_idmap *h_idmap,
34141 + struct dentry *h_dentry, umode_t h_mode);
34144 +long vfsub_splice_read(struct file *in, loff_t *ppos,
34145 + struct pipe_inode_info *pipe, size_t len,
34146 + unsigned int flags);
34147 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34148 + loff_t *ppos, size_t len, unsigned int flags);
34150 +static inline long vfsub_truncate(struct path *path, loff_t length)
34155 + err = vfs_truncate(path, length);
34160 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34161 + struct file *h_file);
34162 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34165 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34168 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34174 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34180 +/* copy_file_range(2) is a systemcall */
34181 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34182 + struct file *dst, loff_t dst_pos,
34183 + size_t len, unsigned int flags)
34188 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34194 +/* ---------------------------------------------------------------------- */
34196 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34201 + err = vfs_llseek(file, offset, origin);
34206 +/* ---------------------------------------------------------------------- */
34208 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34209 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34210 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34211 + struct inode **delegated_inode);
34212 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34213 + struct inode **delegated_inode);
34214 +int vfsub_unlink(struct inode *dir, struct path *path,
34215 + struct inode **delegated_inode, int force);
34217 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34219 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34222 +/* ---------------------------------------------------------------------- */
34224 +static inline int vfsub_setxattr(struct mnt_idmap *idmap,
34225 + struct dentry *dentry, const char *name,
34226 + const void *value, size_t size, int flags)
34231 + err = vfs_setxattr(idmap, dentry, name, value, size, flags);
34237 +static inline int vfsub_removexattr(struct mnt_idmap *idmap,
34238 + struct dentry *dentry, const char *name)
34243 + err = vfs_removexattr(idmap, dentry, name);
34249 +#ifdef CONFIG_FS_POSIX_ACL
34250 +static inline int vfsub_set_acl(struct mnt_idmap *idmap,
34251 + struct dentry *dentry, const char *name,
34252 + struct posix_acl *acl)
34257 + err = vfs_set_acl(idmap, dentry, name, acl);
34263 +static inline int vfsub_remove_acl(struct mnt_idmap *idmap,
34264 + struct dentry *dentry, const char *name)
34269 + err = vfs_remove_acl(idmap, dentry, name);
34275 +AuStubInt0(vfsub_set_acl, struct mnt_idmap *idmap, struct dentry *dentry,
34276 + const char *name, struct posix_acl *acl);
34277 +AuStubInt0(vfsub_remove_acl, struct mnt_idmap *idmap,
34278 + struct dentry *dentry, const char *name);
34281 +#endif /* __KERNEL__ */
34282 +#endif /* __AUFS_VFSUB_H__ */
34283 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34284 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34285 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34287 +// SPDX-License-Identifier: GPL-2.0
34289 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34291 + * This program is free software; you can redistribute it and/or modify
34292 + * it under the terms of the GNU General Public License as published by
34293 + * the Free Software Foundation; either version 2 of the License, or
34294 + * (at your option) any later version.
34296 + * This program is distributed in the hope that it will be useful,
34297 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34298 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34299 + * GNU General Public License for more details.
34301 + * You should have received a copy of the GNU General Public License
34302 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34306 + * policies for selecting one among multiple writable branches
34309 +#include <linux/statfs.h>
34312 +/* subset of cpup_attr() */
34313 +static noinline_for_stack
34314 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34318 + struct inode *h_isrc;
34320 + h_isrc = d_inode(h_src);
34321 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34322 + ia.ia_mode = h_isrc->i_mode;
34323 + ia.ia_uid = h_isrc->i_uid;
34324 + ia.ia_gid = h_isrc->i_gid;
34325 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34326 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34327 + /* no delegation since it is just created */
34328 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34330 + /* is this nfs only? */
34331 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34332 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34333 + ia.ia_mode = h_isrc->i_mode;
34334 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34340 +#define AuCpdown_PARENT_OPQ 1
34341 +#define AuCpdown_WHED (1 << 1)
34342 +#define AuCpdown_MADE_DIR (1 << 2)
34343 +#define AuCpdown_DIROPQ (1 << 3)
34344 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34345 +#define au_fset_cpdown(flags, name) \
34346 + do { (flags) |= AuCpdown_##name; } while (0)
34347 +#define au_fclr_cpdown(flags, name) \
34348 + do { (flags) &= ~AuCpdown_##name; } while (0)
34350 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34351 + unsigned int *flags)
34354 + struct dentry *opq_dentry;
34356 + opq_dentry = au_diropq_create(dentry, bdst);
34357 + err = PTR_ERR(opq_dentry);
34358 + if (IS_ERR(opq_dentry))
34360 + dput(opq_dentry);
34361 + au_fset_cpdown(*flags, DIROPQ);
34367 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34368 + struct inode *dir, aufs_bindex_t bdst)
34371 + struct path h_path;
34372 + struct au_branch *br;
34374 + br = au_sbr(dentry->d_sb, bdst);
34375 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34376 + err = PTR_ERR(h_path.dentry);
34377 + if (IS_ERR(h_path.dentry))
34381 + if (d_is_positive(h_path.dentry)) {
34382 + h_path.mnt = au_br_mnt(br);
34383 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34386 + dput(h_path.dentry);
34392 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34393 + struct au_pin *pin,
34394 + struct dentry *h_parent, void *arg)
34397 + aufs_bindex_t bopq, btop;
34398 + struct path h_path;
34399 + struct dentry *parent;
34400 + struct inode *h_dir, *h_inode, *inode, *dir;
34401 + unsigned int *flags = arg;
34403 + btop = au_dbtop(dentry);
34404 + /* dentry is di-locked */
34405 + parent = dget_parent(dentry);
34406 + dir = d_inode(parent);
34407 + h_dir = d_inode(h_parent);
34408 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34409 + IMustLock(h_dir);
34411 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34412 + if (unlikely(err < 0))
34414 + h_path.dentry = au_h_dptr(dentry, bdst);
34415 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34416 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34417 + if (unlikely(err))
34419 + au_fset_cpdown(*flags, MADE_DIR);
34421 + bopq = au_dbdiropq(dentry);
34422 + au_fclr_cpdown(*flags, WHED);
34423 + au_fclr_cpdown(*flags, DIROPQ);
34424 + if (au_dbwh(dentry) == bdst)
34425 + au_fset_cpdown(*flags, WHED);
34426 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34427 + au_fset_cpdown(*flags, PARENT_OPQ);
34428 + h_inode = d_inode(h_path.dentry);
34429 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34430 + if (au_ftest_cpdown(*flags, WHED)) {
34431 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34432 + if (unlikely(err)) {
34433 + inode_unlock(h_inode);
34438 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34439 + inode_unlock(h_inode);
34440 + if (unlikely(err))
34443 + if (au_ftest_cpdown(*flags, WHED)) {
34444 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34445 + if (unlikely(err))
34449 + inode = d_inode(dentry);
34450 + if (au_ibbot(inode) < bdst)
34451 + au_set_ibbot(inode, bdst);
34452 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34453 + au_hi_flags(inode, /*isdir*/1));
34454 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34455 + goto out; /* success */
34459 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34460 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34461 + rerr = au_diropq_remove(dentry, bdst);
34462 + inode_unlock(h_inode);
34463 + if (unlikely(rerr)) {
34464 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34465 + dentry, bdst, rerr);
34471 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34472 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34473 + if (unlikely(rerr)) {
34474 + AuIOErr("failed removing %pd b%d (%d)\n",
34475 + dentry, bdst, rerr);
34480 + au_set_h_dptr(dentry, bdst, NULL);
34481 + if (au_dbbot(dentry) == bdst)
34482 + au_update_dbbot(dentry);
34488 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34491 + unsigned int flags;
34494 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34499 +/* ---------------------------------------------------------------------- */
34501 +/* policies for create */
34503 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34505 + int err, i, j, ndentry;
34506 + aufs_bindex_t bopq;
34507 + struct au_dcsub_pages dpages;
34508 + struct au_dpage *dpage;
34509 + struct dentry **dentries, *parent, *d;
34511 + err = au_dpages_init(&dpages, GFP_NOFS);
34512 + if (unlikely(err))
34514 + parent = dget_parent(dentry);
34515 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34516 + if (unlikely(err))
34520 + for (i = 0; i < dpages.ndpage; i++) {
34521 + dpage = dpages.dpages + i;
34522 + dentries = dpage->dentries;
34523 + ndentry = dpage->ndentry;
34524 + for (j = 0; j < ndentry; j++) {
34526 + di_read_lock_parent2(d, !AuLock_IR);
34527 + bopq = au_dbdiropq(d);
34528 + di_read_unlock(d, !AuLock_IR);
34529 + if (bopq >= 0 && bopq < err)
34536 + au_dpages_free(&dpages);
34541 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34543 + for (; bindex >= 0; bindex--)
34544 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34549 +/* top down parent */
34550 +static int au_wbr_create_tdp(struct dentry *dentry,
34551 + unsigned int flags __maybe_unused)
34554 + aufs_bindex_t btop, bindex;
34555 + struct super_block *sb;
34556 + struct dentry *parent, *h_parent;
34558 + sb = dentry->d_sb;
34559 + btop = au_dbtop(dentry);
34561 + if (!au_br_rdonly(au_sbr(sb, btop)))
34565 + parent = dget_parent(dentry);
34566 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34567 + h_parent = au_h_dptr(parent, bindex);
34568 + if (!h_parent || d_is_negative(h_parent))
34571 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34578 + /* bottom up here */
34579 + if (unlikely(err < 0)) {
34580 + err = au_wbr_bu(sb, btop - 1);
34582 + err = au_wbr_nonopq(dentry, err);
34586 + AuDbg("b%d\n", err);
34590 +/* ---------------------------------------------------------------------- */
34592 +/* an exception for the policy other than tdp */
34593 +static int au_wbr_create_exp(struct dentry *dentry)
34596 + aufs_bindex_t bwh, bdiropq;
34597 + struct dentry *parent;
34600 + bwh = au_dbwh(dentry);
34601 + parent = dget_parent(dentry);
34602 + bdiropq = au_dbdiropq(parent);
34604 + if (bdiropq >= 0)
34605 + err = min(bdiropq, bwh);
34608 + AuDbg("%d\n", err);
34609 + } else if (bdiropq >= 0) {
34611 + AuDbg("%d\n", err);
34616 + err = au_wbr_nonopq(dentry, err);
34618 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34621 + AuDbg("%d\n", err);
34625 +/* ---------------------------------------------------------------------- */
34628 +static int au_wbr_create_init_rr(struct super_block *sb)
34632 + err = au_wbr_bu(sb, au_sbbot(sb));
34633 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34636 + AuDbg("b%d\n", err);
34640 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34644 + aufs_bindex_t bindex, bbot;
34645 + struct super_block *sb;
34648 + err = au_wbr_create_exp(dentry);
34652 + sb = dentry->d_sb;
34653 + next = &au_sbi(sb)->si_wbr_rr_next;
34654 + bbot = au_sbbot(sb);
34656 + for (bindex = 0; bindex <= bbot; bindex++) {
34657 + if (!au_ftest_wbr(flags, DIR)) {
34658 + err = atomic_dec_return(next) + 1;
34659 + /* modulo for 0 is meaningless */
34660 + if (unlikely(!err))
34661 + err = atomic_dec_return(next) + 1;
34663 + err = atomic_read(next);
34664 + AuDbg("%d\n", err);
34667 + AuDbg("%d\n", err);
34668 + if (!au_br_rdonly(au_sbr(sb, err)))
34674 + err = au_wbr_nonopq(dentry, err);
34677 + AuDbg("%d\n", err);
34681 +/* ---------------------------------------------------------------------- */
34683 +/* most free space */
34684 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34686 + struct super_block *sb;
34687 + struct au_branch *br;
34688 + struct au_wbr_mfs *mfs;
34689 + struct dentry *h_parent;
34690 + aufs_bindex_t bindex, bbot;
34692 + unsigned long long b, bavail;
34693 + struct path h_path;
34694 + /* reduce the stack usage */
34695 + struct kstatfs *st;
34697 + st = kmalloc(sizeof(*st), GFP_NOFS);
34698 + if (unlikely(!st)) {
34699 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34704 + sb = dentry->d_sb;
34705 + mfs = &au_sbi(sb)->si_wbr_mfs;
34706 + MtxMustLock(&mfs->mfs_lock);
34707 + mfs->mfs_bindex = -EROFS;
34708 + mfs->mfsrr_bytes = 0;
34711 + bbot = au_sbbot(sb);
34713 + bindex = au_dbtop(parent);
34714 + bbot = au_dbtaildir(parent);
34717 + for (; bindex <= bbot; bindex++) {
34719 + h_parent = au_h_dptr(parent, bindex);
34720 + if (!h_parent || d_is_negative(h_parent))
34723 + br = au_sbr(sb, bindex);
34724 + if (au_br_rdonly(br))
34727 + /* sb->s_root for NFS is unreliable */
34728 + h_path.mnt = au_br_mnt(br);
34729 + h_path.dentry = h_path.mnt->mnt_root;
34730 + err = vfs_statfs(&h_path, st);
34731 + if (unlikely(err)) {
34732 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34736 + /* when the available size is equal, select the lower one */
34737 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34738 + || sizeof(b) < sizeof(st->f_bsize));
34739 + b = st->f_bavail * st->f_bsize;
34740 + br->br_wbr->wbr_bytes = b;
34741 + if (b >= bavail) {
34743 + mfs->mfs_bindex = bindex;
34744 + mfs->mfs_jiffy = jiffies;
34748 + mfs->mfsrr_bytes = bavail;
34749 + AuDbg("b%d\n", mfs->mfs_bindex);
34750 + au_kfree_rcu(st);
34753 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34756 + struct dentry *parent;
34757 + struct super_block *sb;
34758 + struct au_wbr_mfs *mfs;
34760 + err = au_wbr_create_exp(dentry);
34764 + sb = dentry->d_sb;
34766 + if (au_ftest_wbr(flags, PARENT))
34767 + parent = dget_parent(dentry);
34768 + mfs = &au_sbi(sb)->si_wbr_mfs;
34769 + mutex_lock(&mfs->mfs_lock);
34770 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34771 + || mfs->mfs_bindex < 0
34772 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34773 + au_mfs(dentry, parent);
34774 + mutex_unlock(&mfs->mfs_lock);
34775 + err = mfs->mfs_bindex;
34779 + err = au_wbr_nonopq(dentry, err);
34782 + AuDbg("b%d\n", err);
34786 +static int au_wbr_create_init_mfs(struct super_block *sb)
34788 + struct au_wbr_mfs *mfs;
34790 + mfs = &au_sbi(sb)->si_wbr_mfs;
34791 + mutex_init(&mfs->mfs_lock);
34792 + mfs->mfs_jiffy = 0;
34793 + mfs->mfs_bindex = -EROFS;
34798 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34800 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34804 +/* ---------------------------------------------------------------------- */
34806 +/* top down regardless parent, and then mfs */
34807 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34808 + unsigned int flags __maybe_unused)
34811 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34812 + unsigned long long watermark;
34813 + struct super_block *sb;
34814 + struct au_wbr_mfs *mfs;
34815 + struct au_branch *br;
34816 + struct dentry *parent;
34818 + sb = dentry->d_sb;
34819 + mfs = &au_sbi(sb)->si_wbr_mfs;
34820 + mutex_lock(&mfs->mfs_lock);
34821 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34822 + || mfs->mfs_bindex < 0)
34823 + au_mfs(dentry, /*parent*/NULL);
34824 + watermark = mfs->mfsrr_watermark;
34825 + bmfs = mfs->mfs_bindex;
34826 + mutex_unlock(&mfs->mfs_lock);
34828 + /* another style of au_wbr_create_exp() */
34829 + bwh = au_dbwh(dentry);
34830 + parent = dget_parent(dentry);
34831 + btail = au_dbtaildir(parent);
34832 + if (bwh >= 0 && bwh < btail)
34835 + err = au_wbr_nonopq(dentry, btail);
34836 + if (unlikely(err < 0))
34840 + for (bindex = 0; bindex <= btail; bindex++) {
34841 + br = au_sbr(sb, bindex);
34842 + if (au_br_rdonly(br))
34844 + if (br->br_wbr->wbr_bytes > watermark) {
34855 + AuDbg("b%d\n", err);
34859 +/* ---------------------------------------------------------------------- */
34861 +/* most free space and then round robin */
34862 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34865 + struct au_wbr_mfs *mfs;
34867 + err = au_wbr_create_mfs(dentry, flags);
34869 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34870 + mutex_lock(&mfs->mfs_lock);
34871 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34872 + err = au_wbr_create_rr(dentry, flags);
34873 + mutex_unlock(&mfs->mfs_lock);
34876 + AuDbg("b%d\n", err);
34880 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34884 + au_wbr_create_init_mfs(sb); /* ignore */
34885 + err = au_wbr_create_init_rr(sb);
34890 +/* ---------------------------------------------------------------------- */
34892 +/* top down parent and most free space */
34893 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34896 + unsigned long long b;
34897 + aufs_bindex_t bindex, btop, bbot;
34898 + struct super_block *sb;
34899 + struct dentry *parent, *h_parent;
34900 + struct au_branch *br;
34902 + err = au_wbr_create_tdp(dentry, flags);
34903 + if (unlikely(err < 0))
34905 + parent = dget_parent(dentry);
34906 + btop = au_dbtop(parent);
34907 + bbot = au_dbtaildir(parent);
34908 + if (btop == bbot)
34909 + goto out_parent; /* success */
34911 + e2 = au_wbr_create_mfs(dentry, flags);
34913 + goto out_parent; /* success */
34915 + /* when the available size is equal, select upper one */
34916 + sb = dentry->d_sb;
34917 + br = au_sbr(sb, err);
34918 + b = br->br_wbr->wbr_bytes;
34919 + AuDbg("b%d, %llu\n", err, b);
34921 + for (bindex = btop; bindex <= bbot; bindex++) {
34922 + h_parent = au_h_dptr(parent, bindex);
34923 + if (!h_parent || d_is_negative(h_parent))
34926 + br = au_sbr(sb, bindex);
34927 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34928 + b = br->br_wbr->wbr_bytes;
34930 + AuDbg("b%d, %llu\n", err, b);
34935 + err = au_wbr_nonopq(dentry, err);
34940 + AuDbg("b%d\n", err);
34944 +/* ---------------------------------------------------------------------- */
34947 + * - top down parent
34948 + * - most free space with parent
34949 + * - most free space round-robin regardless parent
34951 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34954 + unsigned long long watermark;
34955 + struct super_block *sb;
34956 + struct au_branch *br;
34957 + struct au_wbr_mfs *mfs;
34959 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34960 + if (unlikely(err < 0))
34963 + sb = dentry->d_sb;
34964 + br = au_sbr(sb, err);
34965 + mfs = &au_sbi(sb)->si_wbr_mfs;
34966 + mutex_lock(&mfs->mfs_lock);
34967 + watermark = mfs->mfsrr_watermark;
34968 + mutex_unlock(&mfs->mfs_lock);
34969 + if (br->br_wbr->wbr_bytes < watermark)
34970 + /* regardless the parent dir */
34971 + err = au_wbr_create_mfsrr(dentry, flags);
34974 + AuDbg("b%d\n", err);
34978 +/* ---------------------------------------------------------------------- */
34980 +/* policies for copyup */
34982 +/* top down parent */
34983 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34985 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34988 +/* bottom up parent */
34989 +static int au_wbr_copyup_bup(struct dentry *dentry)
34992 + aufs_bindex_t bindex, btop;
34993 + struct dentry *parent, *h_parent;
34994 + struct super_block *sb;
34997 + sb = dentry->d_sb;
34998 + parent = dget_parent(dentry);
34999 + btop = au_dbtop(parent);
35000 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
35001 + h_parent = au_h_dptr(parent, bindex);
35002 + if (!h_parent || d_is_negative(h_parent))
35005 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
35012 + /* bottom up here */
35013 + if (unlikely(err < 0))
35014 + err = au_wbr_bu(sb, btop - 1);
35016 + AuDbg("b%d\n", err);
35021 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
35025 + err = au_wbr_bu(dentry->d_sb, btop);
35026 + AuDbg("b%d\n", err);
35028 + err = au_wbr_nonopq(dentry, err);
35030 + AuDbg("b%d\n", err);
35034 +static int au_wbr_copyup_bu(struct dentry *dentry)
35037 + aufs_bindex_t btop;
35039 + btop = au_dbtop(dentry);
35040 + err = au_wbr_do_copyup_bu(dentry, btop);
35044 +/* ---------------------------------------------------------------------- */
35046 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35047 + [AuWbrCopyup_TDP] = {
35048 + .copyup = au_wbr_copyup_tdp
35050 + [AuWbrCopyup_BUP] = {
35051 + .copyup = au_wbr_copyup_bup
35053 + [AuWbrCopyup_BU] = {
35054 + .copyup = au_wbr_copyup_bu
35058 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35059 + [AuWbrCreate_TDP] = {
35060 + .create = au_wbr_create_tdp
35062 + [AuWbrCreate_RR] = {
35063 + .create = au_wbr_create_rr,
35064 + .init = au_wbr_create_init_rr
35066 + [AuWbrCreate_MFS] = {
35067 + .create = au_wbr_create_mfs,
35068 + .init = au_wbr_create_init_mfs,
35069 + .fin = au_wbr_create_fin_mfs
35071 + [AuWbrCreate_MFSV] = {
35072 + .create = au_wbr_create_mfs,
35073 + .init = au_wbr_create_init_mfs,
35074 + .fin = au_wbr_create_fin_mfs
35076 + [AuWbrCreate_MFSRR] = {
35077 + .create = au_wbr_create_mfsrr,
35078 + .init = au_wbr_create_init_mfsrr,
35079 + .fin = au_wbr_create_fin_mfs
35081 + [AuWbrCreate_MFSRRV] = {
35082 + .create = au_wbr_create_mfsrr,
35083 + .init = au_wbr_create_init_mfsrr,
35084 + .fin = au_wbr_create_fin_mfs
35086 + [AuWbrCreate_TDMFS] = {
35087 + .create = au_wbr_create_tdmfs,
35088 + .init = au_wbr_create_init_mfs,
35089 + .fin = au_wbr_create_fin_mfs
35091 + [AuWbrCreate_TDMFSV] = {
35092 + .create = au_wbr_create_tdmfs,
35093 + .init = au_wbr_create_init_mfs,
35094 + .fin = au_wbr_create_fin_mfs
35096 + [AuWbrCreate_PMFS] = {
35097 + .create = au_wbr_create_pmfs,
35098 + .init = au_wbr_create_init_mfs,
35099 + .fin = au_wbr_create_fin_mfs
35101 + [AuWbrCreate_PMFSV] = {
35102 + .create = au_wbr_create_pmfs,
35103 + .init = au_wbr_create_init_mfs,
35104 + .fin = au_wbr_create_fin_mfs
35106 + [AuWbrCreate_PMFSRR] = {
35107 + .create = au_wbr_create_pmfsrr,
35108 + .init = au_wbr_create_init_mfsrr,
35109 + .fin = au_wbr_create_fin_mfs
35111 + [AuWbrCreate_PMFSRRV] = {
35112 + .create = au_wbr_create_pmfsrr,
35113 + .init = au_wbr_create_init_mfsrr,
35114 + .fin = au_wbr_create_fin_mfs
35117 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35118 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35119 +++ linux/fs/aufs/whout.c 2023-10-31 09:31:04.199880750 +0100
35121 +// SPDX-License-Identifier: GPL-2.0
35123 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35125 + * This program is free software; you can redistribute it and/or modify
35126 + * it under the terms of the GNU General Public License as published by
35127 + * the Free Software Foundation; either version 2 of the License, or
35128 + * (at your option) any later version.
35130 + * This program is distributed in the hope that it will be useful,
35131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35133 + * GNU General Public License for more details.
35135 + * You should have received a copy of the GNU General Public License
35136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35140 + * whiteout for logical deletion and opaque directory
35145 +#define WH_MASK 0444
35148 + * If a directory contains this file, then it is opaque. We start with the
35149 + * .wh. flag so that it is blocked by lookup.
35151 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35152 + sizeof(AUFS_WH_DIROPQ) - 1);
35155 + * generate whiteout name, which is NOT terminated by NULL.
35156 + * @name: original d_name.name
35157 + * @len: original d_name.len
35158 + * @wh: whiteout qstr
35159 + * returns zero when succeeds, otherwise error.
35160 + * succeeded value as wh->name should be freed by kfree().
35162 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35166 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35167 + return -ENAMETOOLONG;
35169 + wh->len = name->len + AUFS_WH_PFX_LEN;
35170 + p = kmalloc(wh->len, GFP_NOFS);
35173 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35174 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35181 +/* ---------------------------------------------------------------------- */
35184 + * test if the @wh_name exists under @h_ppath.
35185 + * @try_sio specifies the necessary of super-io.
35187 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
35188 + struct qstr *wh_name, int try_sio)
35191 + struct dentry *wh_dentry;
35194 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35196 + wh_dentry = au_sio_lkup_one(h_idmap, wh_name, h_ppath);
35197 + err = PTR_ERR(wh_dentry);
35198 + if (IS_ERR(wh_dentry)) {
35199 + if (err == -ENAMETOOLONG)
35205 + if (d_is_negative(wh_dentry))
35206 + goto out_wh; /* success */
35209 + if (d_is_reg(wh_dentry))
35210 + goto out_wh; /* success */
35213 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35214 + wh_dentry, d_inode(wh_dentry)->i_mode);
35223 + * test if the @h_path->dentry sets opaque or not.
35225 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path)
35228 + struct inode *h_dir;
35230 + h_dir = d_inode(h_path->dentry);
35231 + err = au_wh_test(h_idmap, h_path, &diropq_name,
35232 + au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC));
35237 + * returns a negative dentry whose name is unique and temporary.
35239 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35240 + struct qstr *prefix)
35242 + struct dentry *dentry;
35244 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35246 + /* strict atomic_t is unnecessary here */
35247 + static unsigned short cnt;
35249 + struct path h_ppath;
35250 + struct mnt_idmap *h_idmap;
35252 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35255 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35256 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35257 + dentry = ERR_PTR(-ENAMETOOLONG);
35258 + if (unlikely(qs.len > NAME_MAX))
35260 + dentry = ERR_PTR(-ENOMEM);
35261 + name = kmalloc(qs.len + 1, GFP_NOFS);
35262 + if (unlikely(!name))
35266 + /* doubly whiteout-ed */
35267 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35268 + p = name + AUFS_WH_PFX_LEN * 2;
35269 + memcpy(p, prefix->name, prefix->len);
35270 + p += prefix->len;
35272 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35274 + h_ppath.dentry = h_parent;
35275 + h_ppath.mnt = au_br_mnt(br);
35276 + h_idmap = au_br_idmap(br);
35278 + for (i = 0; i < 3; i++) {
35279 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35280 + dentry = au_sio_lkup_one(h_idmap, &qs, &h_ppath);
35281 + if (IS_ERR(dentry) || d_is_negative(dentry))
35285 + /* pr_warn("could not get random name\n"); */
35286 + dentry = ERR_PTR(-EEXIST);
35287 + AuDbg("%.*s\n", AuLNPair(&qs));
35291 + if (name != defname)
35292 + au_kfree_try_rcu(name);
35294 + AuTraceErrPtr(dentry);
35299 + * rename the @h_dentry on @br to the whiteouted temporary name.
35301 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35304 + struct path h_path = {
35305 + .mnt = au_br_mnt(br)
35307 + struct inode *h_dir, *delegated;
35308 + struct dentry *h_parent;
35310 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35311 + h_dir = d_inode(h_parent);
35312 + IMustLock(h_dir);
35314 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35315 + err = PTR_ERR(h_path.dentry);
35316 + if (IS_ERR(h_path.dentry))
35319 + /* under the same dir, no need to lock_rename() */
35320 + delegated = NULL;
35321 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35324 + if (unlikely(err == -EWOULDBLOCK)) {
35325 + pr_warn("cannot retry for NFSv4 delegation"
35326 + " for an internal rename\n");
35329 + dput(h_path.dentry);
35336 +/* ---------------------------------------------------------------------- */
35338 + * functions for removing a whiteout
35341 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35344 + struct inode *delegated;
35347 + * forces superio when the dir has a sticky bit.
35348 + * this may be a violation of unix fs semantics.
35350 + force = (h_dir->i_mode & S_ISVTX)
35351 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35352 + delegated = NULL;
35353 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35354 + if (unlikely(err == -EWOULDBLOCK)) {
35355 + pr_warn("cannot retry for NFSv4 delegation"
35356 + " for an internal unlink\n");
35362 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35363 + struct dentry *dentry)
35367 + err = do_unlink_wh(h_dir, h_path);
35368 + if (!err && dentry)
35369 + au_set_dbwh(dentry, -1);
35374 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35377 + struct path h_path;
35380 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35381 + if (IS_ERR(h_path.dentry))
35382 + err = PTR_ERR(h_path.dentry);
35384 + if (d_is_reg(h_path.dentry)) {
35385 + h_path.mnt = h_ppath->mnt;
35386 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35388 + dput(h_path.dentry);
35394 +/* ---------------------------------------------------------------------- */
35396 + * initialize/clean whiteout for a branch
35399 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35403 + struct inode *delegated;
35405 + if (d_is_negative(whpath->dentry))
35409 + err = vfsub_rmdir(h_dir, whpath);
35411 + delegated = NULL;
35412 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35413 + if (unlikely(err == -EWOULDBLOCK)) {
35414 + pr_warn("cannot retry for NFSv4 delegation"
35415 + " for an internal unlink\n");
35419 + if (unlikely(err))
35420 + pr_warn("failed removing %pd (%d), ignored.\n",
35421 + whpath->dentry, err);
35424 +static int test_linkable(struct dentry *h_root)
35426 + struct inode *h_dir = d_inode(h_root);
35428 + if (h_dir->i_op->link)
35431 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35432 + h_root, au_sbtype(h_root->d_sb));
35433 + return -ENOSYS; /* the branch doesn't have its ->link() */
35436 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35437 +static int au_whdir(struct inode *h_dir, struct path *path)
35442 + if (d_is_negative(path->dentry)) {
35445 + if (au_test_nfs(path->dentry->d_sb))
35447 + err = vfsub_mkdir(h_dir, path, mode);
35448 + } else if (d_is_dir(path->dentry))
35451 + pr_err("unknown %pd exists\n", path->dentry);
35456 +struct au_wh_base {
35457 + const struct qstr *name;
35458 + struct dentry *dentry;
35461 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35462 + struct path *h_path)
35464 + h_path->dentry = base[AuBrWh_BASE].dentry;
35465 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35466 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35467 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35468 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35469 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35473 + * returns tri-state,
35474 + * minus: error, caller should print the message
35476 + * plus: error, caller should NOT print the message
35478 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35479 + int do_plink, struct au_wh_base base[],
35480 + struct path *h_path)
35483 + struct inode *h_dir;
35485 + h_dir = d_inode(h_root);
35486 + h_path->dentry = base[AuBrWh_BASE].dentry;
35487 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35488 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35490 + err = test_linkable(h_root);
35491 + if (unlikely(err)) {
35496 + err = au_whdir(h_dir, h_path);
35497 + if (unlikely(err))
35499 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35501 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35502 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35503 + err = au_whdir(h_dir, h_path);
35504 + if (unlikely(err))
35506 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35513 + * for the moment, aufs supports the branch filesystem which does not support
35514 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35515 + * copyup failed. finally, such filesystem will not be used as the writable
35518 + * returns tri-state, see above.
35520 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35521 + int do_plink, struct au_wh_base base[],
35522 + struct path *h_path)
35525 + struct inode *h_dir;
35527 + WbrWhMustWriteLock(wbr);
35529 + err = test_linkable(h_root);
35530 + if (unlikely(err)) {
35536 + * todo: should this create be done in /sbin/mount.aufs helper?
35539 + h_dir = d_inode(h_root);
35540 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35541 + h_path->dentry = base[AuBrWh_BASE].dentry;
35542 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35543 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35546 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35547 + if (unlikely(err))
35550 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35552 + err = au_whdir(h_dir, h_path);
35553 + if (unlikely(err))
35555 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35557 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35558 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35560 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35561 + err = au_whdir(h_dir, h_path);
35562 + if (unlikely(err))
35564 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35571 + * initialize the whiteout base file/dir for @br.
35573 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35576 + const unsigned char do_plink
35577 + = !!au_opt_test(au_mntflags(sb), PLINK);
35578 + struct inode *h_dir;
35579 + struct path path = br->br_path;
35580 + struct dentry *h_root = path.dentry;
35581 + struct au_wbr *wbr = br->br_wbr;
35582 + static const struct qstr base_name[] = {
35583 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35584 + sizeof(AUFS_BASE_NAME) - 1),
35585 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35586 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35587 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35588 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35590 + struct au_wh_base base[] = {
35591 + [AuBrWh_BASE] = {
35592 + .name = base_name + AuBrWh_BASE,
35595 + [AuBrWh_PLINK] = {
35596 + .name = base_name + AuBrWh_PLINK,
35599 + [AuBrWh_ORPH] = {
35600 + .name = base_name + AuBrWh_ORPH,
35606 + WbrWhMustWriteLock(wbr);
35608 + for (i = 0; i < AuBrWh_Last; i++) {
35609 + /* doubly whiteouted */
35610 + struct dentry *d;
35612 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35613 + err = PTR_ERR(d);
35617 + base[i].dentry = d;
35619 + && wbr->wbr_wh[i]
35620 + && wbr->wbr_wh[i] != base[i].dentry);
35624 + for (i = 0; i < AuBrWh_Last; i++) {
35625 + dput(wbr->wbr_wh[i]);
35626 + wbr->wbr_wh[i] = NULL;
35630 + if (!au_br_writable(br->br_perm)) {
35631 + h_dir = d_inode(h_root);
35632 + au_wh_init_ro(h_dir, base, &path);
35633 + } else if (!au_br_wh_linkable(br->br_perm)) {
35634 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35640 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35646 + goto out; /* success */
35649 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35650 + err, h_root, au_sbtype(h_root->d_sb));
35652 + for (i = 0; i < AuBrWh_Last; i++)
35653 + dput(base[i].dentry);
35657 +/* ---------------------------------------------------------------------- */
35659 + * whiteouts are all hard-linked usually.
35660 + * when its link count reaches a ceiling, we create a new whiteout base
35661 + * asynchronously.
35664 +struct reinit_br_wh {
35665 + struct super_block *sb;
35666 + struct au_branch *br;
35669 +static void reinit_br_wh(void *arg)
35672 + aufs_bindex_t bindex;
35673 + struct path h_path;
35674 + struct reinit_br_wh *a = arg;
35675 + struct au_wbr *wbr;
35676 + struct inode *dir, *delegated;
35677 + struct dentry *h_root;
35678 + struct au_hinode *hdir;
35681 + wbr = a->br->br_wbr;
35682 + /* big aufs lock */
35683 + si_noflush_write_lock(a->sb);
35684 + if (!au_br_writable(a->br->br_perm))
35686 + bindex = au_br_index(a->sb, a->br->br_id);
35687 + if (unlikely(bindex < 0))
35690 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35691 + dir = d_inode(a->sb->s_root);
35692 + hdir = au_hi(dir, bindex);
35693 + h_root = au_h_dptr(a->sb->s_root, bindex);
35694 + AuDebugOn(h_root != au_br_dentry(a->br));
35696 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35697 + wbr_wh_write_lock(wbr);
35698 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35701 + h_path.dentry = wbr->wbr_whbase;
35702 + h_path.mnt = au_br_mnt(a->br);
35703 + delegated = NULL;
35704 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35706 + if (unlikely(err == -EWOULDBLOCK)) {
35707 + pr_warn("cannot retry for NFSv4 delegation"
35708 + " for an internal unlink\n");
35712 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35715 + dput(wbr->wbr_whbase);
35716 + wbr->wbr_whbase = NULL;
35718 + err = au_wh_init(a->br, a->sb);
35719 + wbr_wh_write_unlock(wbr);
35720 + au_hn_inode_unlock(hdir);
35721 + di_read_unlock(a->sb->s_root, AuLock_IR);
35723 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35727 + atomic_dec(&wbr->wbr_wh_running);
35728 + au_lcnt_dec(&a->br->br_count);
35729 + si_write_unlock(a->sb);
35730 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35732 + if (unlikely(err))
35733 + AuIOErr("err %d\n", err);
35736 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35738 + int do_dec, wkq_err;
35739 + struct reinit_br_wh *arg;
35742 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35745 + /* ignore ENOMEM */
35746 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35749 + * dec(wh_running), kfree(arg) and dec(br_count)
35750 + * in reinit function
35754 + au_lcnt_inc(&br->br_count);
35755 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35756 + if (unlikely(wkq_err)) {
35757 + atomic_dec(&br->br_wbr->wbr_wh_running);
35758 + au_lcnt_dec(&br->br_count);
35759 + au_kfree_rcu(arg);
35766 + atomic_dec(&br->br_wbr->wbr_wh_running);
35769 +/* ---------------------------------------------------------------------- */
35772 + * create the whiteout @wh.
35774 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35775 + struct dentry *wh)
35778 + struct path h_path = {
35781 + struct au_branch *br;
35782 + struct au_wbr *wbr;
35783 + struct dentry *h_parent;
35784 + struct inode *h_dir, *delegated;
35786 + h_parent = wh->d_parent; /* dir inode is locked */
35787 + h_dir = d_inode(h_parent);
35788 + IMustLock(h_dir);
35790 + br = au_sbr(sb, bindex);
35791 + h_path.mnt = au_br_mnt(br);
35792 + wbr = br->br_wbr;
35793 + wbr_wh_read_lock(wbr);
35794 + if (wbr->wbr_whbase) {
35795 + delegated = NULL;
35796 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35797 + if (unlikely(err == -EWOULDBLOCK)) {
35798 + pr_warn("cannot retry for NFSv4 delegation"
35799 + " for an internal link\n");
35802 + if (!err || err != -EMLINK)
35805 + /* link count full. re-initialize br_whbase. */
35806 + kick_reinit_br_wh(sb, br);
35809 + /* return this error in this context */
35810 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35812 + au_fhsm_wrote(sb, bindex, /*force*/0);
35815 + wbr_wh_read_unlock(wbr);
35819 +/* ---------------------------------------------------------------------- */
35822 + * create or remove the diropq.
35824 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35825 + unsigned int flags)
35827 + struct dentry *opq_dentry;
35828 + struct super_block *sb;
35829 + struct au_branch *br;
35830 + struct path h_path;
35833 + sb = dentry->d_sb;
35834 + br = au_sbr(sb, bindex);
35835 + h_path.dentry = au_h_dptr(dentry, bindex);
35836 + h_path.mnt = au_br_mnt(br);
35837 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35838 + if (IS_ERR(opq_dentry))
35841 + if (au_ftest_diropq(flags, CREATE)) {
35842 + err = link_or_create_wh(sb, bindex, opq_dentry);
35844 + au_set_dbdiropq(dentry, bindex);
35845 + goto out; /* success */
35848 + h_path.dentry = opq_dentry;
35849 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35851 + au_set_dbdiropq(dentry, -1);
35853 + dput(opq_dentry);
35854 + opq_dentry = ERR_PTR(err);
35857 + return opq_dentry;
35860 +struct do_diropq_args {
35861 + struct dentry **errp;
35862 + struct dentry *dentry;
35863 + aufs_bindex_t bindex;
35864 + unsigned int flags;
35867 +static void call_do_diropq(void *args)
35869 + struct do_diropq_args *a = args;
35870 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35873 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35874 + unsigned int flags)
35876 + struct dentry *diropq, *h_dentry;
35877 + struct mnt_idmap *h_idmap;
35879 + h_idmap = au_sbr_idmap(dentry->d_sb, bindex);
35880 + h_dentry = au_h_dptr(dentry, bindex);
35881 + if (!au_test_h_perm_sio(h_idmap, d_inode(h_dentry),
35882 + MAY_EXEC | MAY_WRITE))
35883 + diropq = do_diropq(dentry, bindex, flags);
35886 + struct do_diropq_args args = {
35888 + .dentry = dentry,
35889 + .bindex = bindex,
35893 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35894 + if (unlikely(wkq_err))
35895 + diropq = ERR_PTR(wkq_err);
35901 +/* ---------------------------------------------------------------------- */
35904 + * lookup whiteout dentry.
35905 + * @h_parent: lower parent dentry which must exist and be locked
35906 + * @base_name: name of dentry which will be whiteouted
35907 + * returns dentry for whiteout.
35909 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35910 + struct au_branch *br)
35913 + struct qstr wh_name;
35914 + struct dentry *wh_dentry;
35915 + struct path h_path;
35917 + err = au_wh_name_alloc(&wh_name, base_name);
35918 + wh_dentry = ERR_PTR(err);
35920 + h_path.dentry = h_parent;
35921 + h_path.mnt = au_br_mnt(br);
35922 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35923 + au_kfree_try_rcu(wh_name.name);
35925 + return wh_dentry;
35929 + * link/create a whiteout for @dentry on @bindex.
35931 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35932 + struct dentry *h_parent)
35934 + struct dentry *wh_dentry;
35935 + struct super_block *sb;
35938 + sb = dentry->d_sb;
35939 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35940 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35941 + err = link_or_create_wh(sb, bindex, wh_dentry);
35943 + au_set_dbwh(dentry, bindex);
35944 + au_fhsm_wrote(sb, bindex, /*force*/0);
35947 + wh_dentry = ERR_PTR(err);
35951 + return wh_dentry;
35954 +/* ---------------------------------------------------------------------- */
35956 +/* Delete all whiteouts in this directory on branch bindex. */
35957 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35958 + aufs_bindex_t bindex)
35961 + unsigned long ul, n;
35962 + struct qstr wh_name;
35964 + struct hlist_head *head;
35965 + struct au_vdir_wh *pos;
35966 + struct au_vdir_destr *str;
35969 + p = (void *)__get_free_page(GFP_NOFS);
35970 + wh_name.name = p;
35971 + if (unlikely(!wh_name.name))
35975 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35976 + p += AUFS_WH_PFX_LEN;
35977 + n = whlist->nh_num;
35978 + head = whlist->nh_head;
35979 + for (ul = 0; !err && ul < n; ul++, head++) {
35980 + hlist_for_each_entry(pos, head, wh_hash) {
35981 + if (pos->wh_bindex != bindex)
35984 + str = &pos->wh_str;
35985 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35986 + memcpy(p, str->name, str->len);
35987 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35988 + err = unlink_wh_name(h_path, &wh_name);
35993 + AuIOErr("whiteout name too long %.*s\n",
35994 + str->len, str->name);
35999 + free_page((unsigned long)wh_name.name);
36005 +struct del_wh_children_args {
36007 + struct path *h_path;
36008 + struct au_nhash *whlist;
36009 + aufs_bindex_t bindex;
36012 +static void call_del_wh_children(void *args)
36014 + struct del_wh_children_args *a = args;
36015 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
36018 +/* ---------------------------------------------------------------------- */
36020 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
36022 + struct au_whtmp_rmdir *whtmp;
36024 + unsigned int rdhash;
36026 + SiMustAnyLock(sb);
36028 + whtmp = kzalloc(sizeof(*whtmp), gfp);
36029 + if (unlikely(!whtmp)) {
36030 + whtmp = ERR_PTR(-ENOMEM);
36034 + /* no estimation for dir size */
36035 + rdhash = au_sbi(sb)->si_rdhash;
36037 + rdhash = AUFS_RDHASH_DEF;
36038 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
36039 + if (unlikely(err)) {
36040 + au_kfree_rcu(whtmp);
36041 + whtmp = ERR_PTR(err);
36048 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36051 + au_lcnt_dec(&whtmp->br->br_count);
36052 + dput(whtmp->wh_dentry);
36053 + iput(whtmp->dir);
36054 + au_nhash_wh_free(&whtmp->whlist);
36055 + au_kfree_rcu(whtmp);
36059 + * rmdir the whiteouted temporary named dir @h_dentry.
36060 + * @whlist: whiteouted children.
36062 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36063 + struct dentry *wh_dentry, struct au_nhash *whlist)
36066 + unsigned int h_nlink;
36067 + struct path wh_path;
36068 + struct inode *wh_inode, *h_dir;
36069 + struct au_branch *br;
36070 + struct mnt_idmap *h_idmap;
36072 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36073 + IMustLock(h_dir);
36075 + br = au_sbr(dir->i_sb, bindex);
36076 + wh_path.dentry = wh_dentry;
36077 + wh_path.mnt = au_br_mnt(br);
36078 + h_idmap = au_br_idmap(br);
36079 + wh_inode = d_inode(wh_dentry);
36080 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36083 + * someone else might change some whiteouts while we were sleeping.
36084 + * it means this whlist may have an obsoleted entry.
36086 + if (!au_test_h_perm_sio(h_idmap, wh_inode, MAY_EXEC | MAY_WRITE))
36087 + err = del_wh_children(&wh_path, whlist, bindex);
36090 + struct del_wh_children_args args = {
36092 + .h_path = &wh_path,
36093 + .whlist = whlist,
36097 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36098 + if (unlikely(wkq_err))
36101 + inode_unlock(wh_inode);
36104 + h_nlink = h_dir->i_nlink;
36105 + err = vfsub_rmdir(h_dir, &wh_path);
36106 + /* some fs doesn't change the parent nlink in some cases */
36107 + h_nlink -= h_dir->i_nlink;
36111 + if (au_ibtop(dir) == bindex) {
36112 + /* todo: dir->i_mutex is necessary */
36113 + au_cpup_attr_timesizes(dir);
36115 + vfsub_drop_nlink(dir);
36117 + return 0; /* success */
36120 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36124 +static void call_rmdir_whtmp(void *args)
36127 + aufs_bindex_t bindex;
36128 + struct au_whtmp_rmdir *a = args;
36129 + struct super_block *sb;
36130 + struct dentry *h_parent;
36131 + struct inode *h_dir;
36132 + struct au_hinode *hdir;
36134 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36135 + /* inode_lock(a->dir); */
36137 + sb = a->dir->i_sb;
36138 + si_read_lock(sb, !AuLock_FLUSH);
36139 + if (!au_br_writable(a->br->br_perm))
36141 + bindex = au_br_index(sb, a->br->br_id);
36142 + if (unlikely(bindex < 0))
36146 + ii_write_lock_parent(a->dir);
36147 + h_parent = dget_parent(a->wh_dentry);
36148 + h_dir = d_inode(h_parent);
36149 + hdir = au_hi(a->dir, bindex);
36150 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36151 + if (unlikely(err))
36153 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36154 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36157 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36158 + au_hn_inode_unlock(hdir);
36159 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36163 + ii_write_unlock(a->dir);
36165 + /* inode_unlock(a->dir); */
36166 + au_whtmp_rmdir_free(a);
36167 + si_read_unlock(sb);
36168 + au_nwt_done(&au_sbi(sb)->si_nowait);
36169 + if (unlikely(err))
36170 + AuIOErr("err %d\n", err);
36173 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36174 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36177 + struct super_block *sb;
36181 + /* all post-process will be done in do_rmdir_whtmp(). */
36183 + args->dir = au_igrab(dir);
36184 + args->br = au_sbr(sb, bindex);
36185 + au_lcnt_inc(&args->br->br_count);
36186 + args->wh_dentry = dget(wh_dentry);
36187 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36188 + if (unlikely(wkq_err)) {
36189 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36190 + au_whtmp_rmdir_free(args);
36193 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36194 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36195 +++ linux/fs/aufs/whout.h 2023-10-31 09:31:04.199880750 +0100
36197 +/* SPDX-License-Identifier: GPL-2.0 */
36199 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36201 + * This program is free software; you can redistribute it and/or modify
36202 + * it under the terms of the GNU General Public License as published by
36203 + * the Free Software Foundation; either version 2 of the License, or
36204 + * (at your option) any later version.
36206 + * This program is distributed in the hope that it will be useful,
36207 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36208 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36209 + * GNU General Public License for more details.
36211 + * You should have received a copy of the GNU General Public License
36212 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36216 + * whiteout for logical deletion and opaque directory
36219 +#ifndef __AUFS_WHOUT_H__
36220 +#define __AUFS_WHOUT_H__
36227 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36228 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
36229 + struct qstr *wh_name, int try_sio);
36230 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path);
36232 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36233 + struct qstr *prefix);
36234 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36235 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36236 + struct dentry *dentry);
36237 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36239 +/* diropq flags */
36240 +#define AuDiropq_CREATE 1
36241 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36242 +#define au_fset_diropq(flags, name) \
36243 + do { (flags) |= AuDiropq_##name; } while (0)
36244 +#define au_fclr_diropq(flags, name) \
36245 + do { (flags) &= ~AuDiropq_##name; } while (0)
36247 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36248 + unsigned int flags);
36249 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36250 + struct au_branch *br);
36251 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36252 + struct dentry *h_parent);
36254 +/* real rmdir for the whiteout-ed dir */
36255 +struct au_whtmp_rmdir {
36256 + struct inode *dir;
36257 + struct au_branch *br;
36258 + struct dentry *wh_dentry;
36259 + struct au_nhash whlist;
36262 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36263 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36264 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36265 + struct dentry *wh_dentry, struct au_nhash *whlist);
36266 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36267 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36269 +/* ---------------------------------------------------------------------- */
36271 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36272 + aufs_bindex_t bindex)
36274 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36277 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36279 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36282 +#endif /* __KERNEL__ */
36283 +#endif /* __AUFS_WHOUT_H__ */
36284 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36285 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36286 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36288 +// SPDX-License-Identifier: GPL-2.0
36290 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36292 + * This program is free software; you can redistribute it and/or modify
36293 + * it under the terms of the GNU General Public License as published by
36294 + * the Free Software Foundation; either version 2 of the License, or
36295 + * (at your option) any later version.
36297 + * This program is distributed in the hope that it will be useful,
36298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36300 + * GNU General Public License for more details.
36302 + * You should have received a copy of the GNU General Public License
36303 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36307 + * workqueue for asynchronous/super-io operations
36308 + * todo: try new credential scheme
36311 +#include <linux/module.h>
36314 +/* internal workqueue named AUFS_WKQ_NAME */
36316 +static struct workqueue_struct *au_wkq;
36318 +struct au_wkinfo {
36319 + struct work_struct wk;
36320 + struct kobject *kobj;
36322 + unsigned int flags; /* see wkq.h */
36324 + au_wkq_func_t func;
36327 +#ifdef CONFIG_LOCKDEP
36329 + struct held_lock **hlock;
36332 + struct completion *comp;
36335 +/* ---------------------------------------------------------------------- */
36337 + * Aufs passes some operations to the workqueue such as the internal copyup.
36338 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36339 + * job run by workqueue depends upon the locks acquired in the other task.
36340 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36341 + * information too. And the job in the workqueue restores the info in order to
36342 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36343 + * correctly and expectedly.
36346 +#ifndef CONFIG_LOCKDEP
36347 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36348 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36349 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36350 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36351 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36353 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36355 + wkinfo->hlock = NULL;
36356 + wkinfo->dont_check = 0;
36363 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36365 + static DEFINE_SPINLOCK(spin);
36368 + struct lock_class_key *key;
36370 + { .name = "&sbinfo->si_rwsem" },
36371 + { .name = "&finfo->fi_rwsem" },
36372 + { .name = "&dinfo->di_rwsem" },
36373 + { .name = "&iinfo->ii_rwsem" }
36378 + /* lockless read from 'set.' see below */
36379 + if (set == ARRAY_SIZE(a)) {
36380 + for (i = 0; i < ARRAY_SIZE(a); i++)
36381 + if (a[i].key == key)
36386 + spin_lock(&spin);
36388 + for (i = 0; i < ARRAY_SIZE(a); i++)
36389 + if (a[i].key == key) {
36390 + spin_unlock(&spin);
36393 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36395 + if (unlikely(a[i].key == key)) { /* rare but possible */
36396 + spin_unlock(&spin);
36401 + if (strstr(a[i].name, name)) {
36403 + * the order of these three lines is important for the
36404 + * lockless read above.
36407 + spin_unlock(&spin);
36409 + /* AuDbg("%d, %s\n", set, name); */
36413 + spin_unlock(&spin);
36422 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36425 + struct task_struct *curr;
36426 + struct held_lock **hl, *held_locks, *p;
36430 + wkinfo->dont_check = lockdep_recursing(curr);
36431 + if (wkinfo->dont_check)
36433 + n = curr->lockdep_depth;
36438 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36439 + if (unlikely(!wkinfo->hlock))
36443 +#if 0 /* left for debugging */
36444 + if (0 && au_debug_test())
36445 + lockdep_print_held_locks(curr);
36447 + held_locks = curr->held_locks;
36448 + hl = wkinfo->hlock;
36450 + p = held_locks++;
36451 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36460 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36462 + au_kfree_try_rcu(wkinfo->hlock);
36465 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36467 + struct held_lock *p, **hl = wkinfo->hlock;
36470 + if (wkinfo->dont_check)
36474 + while ((p = *hl++)) { /* assignment */
36475 + subclass = lockdep_hlock_class(p)->subclass;
36476 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36478 + rwsem_acquire_read(p->instance, subclass, 0,
36479 + /*p->acquire_ip*/_RET_IP_);
36481 + rwsem_acquire(p->instance, subclass, 0,
36482 + /*p->acquire_ip*/_RET_IP_);
36486 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36488 + struct held_lock *p, **hl = wkinfo->hlock;
36490 + if (wkinfo->dont_check)
36494 + while ((p = *hl++)) /* assignment */
36495 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36499 +static void wkq_func(struct work_struct *wk)
36501 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36503 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36504 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36506 + au_wkq_lockdep_pre(wkinfo);
36507 + wkinfo->func(wkinfo->args);
36508 + au_wkq_lockdep_post(wkinfo);
36509 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36510 + complete(wkinfo->comp);
36512 + kobject_put(wkinfo->kobj);
36513 + module_put(THIS_MODULE); /* todo: ?? */
36514 + au_kfree_rcu(wkinfo);
36519 + * Since struct completion is large, try allocating it dynamically.
36521 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36523 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36525 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36527 + init_completion(*comp);
36528 + wkinfo->comp = *comp;
36534 +static void au_wkq_comp_free(struct completion *comp)
36536 + au_kfree_rcu(comp);
36539 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36541 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36542 + if (au_wkq_test()) {
36543 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36544 + " due to a dead dir by UDBA,"
36545 + " or async xino write?\n");
36546 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36549 + au_dbg_verify_kthread();
36551 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36552 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36553 + queue_work(au_wkq, &wkinfo->wk);
36555 + INIT_WORK(&wkinfo->wk, wkq_func);
36556 + schedule_work(&wkinfo->wk);
36561 + * Be careful. It is easy to make deadlock happen.
36562 + * processA: lock, wkq and wait
36563 + * processB: wkq and wait, lock in wkq
36566 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36569 + AuWkqCompDeclare(comp);
36570 + struct au_wkinfo wkinfo = {
36576 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36577 + if (unlikely(err))
36579 + err = au_wkq_lockdep_alloc(&wkinfo);
36580 + if (unlikely(err))
36583 + au_wkq_run(&wkinfo);
36584 + /* no timeout, no interrupt */
36585 + wait_for_completion(wkinfo.comp);
36587 + au_wkq_lockdep_free(&wkinfo);
36590 + au_wkq_comp_free(comp);
36592 + destroy_work_on_stack(&wkinfo.wk);
36597 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36598 + * problem in a concurrent umounting.
36600 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36601 + unsigned int flags)
36604 + struct au_wkinfo *wkinfo;
36606 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36609 + * wkq_func() must free this wkinfo.
36610 + * it highly depends upon the implementation of workqueue.
36613 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36615 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36616 + wkinfo->flags = flags & ~AuWkq_WAIT;
36617 + wkinfo->func = func;
36618 + wkinfo->args = args;
36619 + wkinfo->comp = NULL;
36620 + au_wkq_lockdep_init(wkinfo);
36621 + kobject_get(wkinfo->kobj);
36622 + __module_get(THIS_MODULE); /* todo: ?? */
36624 + au_wkq_run(wkinfo);
36627 + au_nwt_done(&au_sbi(sb)->si_nowait);
36633 +/* ---------------------------------------------------------------------- */
36635 +void au_nwt_init(struct au_nowait_tasks *nwt)
36637 + atomic_set(&nwt->nw_len, 0);
36638 + /* smp_mb(); */ /* atomic_set */
36639 + init_waitqueue_head(&nwt->nw_wq);
36642 +void au_wkq_fin(void)
36644 + destroy_workqueue(au_wkq);
36647 +int __init au_wkq_init(void)
36652 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36653 + if (IS_ERR(au_wkq))
36654 + err = PTR_ERR(au_wkq);
36655 + else if (!au_wkq)
36660 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36661 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36662 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36664 +/* SPDX-License-Identifier: GPL-2.0 */
36666 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36668 + * This program is free software; you can redistribute it and/or modify
36669 + * it under the terms of the GNU General Public License as published by
36670 + * the Free Software Foundation; either version 2 of the License, or
36671 + * (at your option) any later version.
36673 + * This program is distributed in the hope that it will be useful,
36674 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36675 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36676 + * GNU General Public License for more details.
36678 + * You should have received a copy of the GNU General Public License
36679 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36683 + * workqueue for asynchronous/super-io operations
36684 + * todo: try new credentials management scheme
36687 +#ifndef __AUFS_WKQ_H__
36688 +#define __AUFS_WKQ_H__
36692 +#include <linux/wait.h>
36694 +struct super_block;
36696 +/* ---------------------------------------------------------------------- */
36699 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36701 +struct au_nowait_tasks {
36703 + wait_queue_head_t nw_wq;
36706 +/* ---------------------------------------------------------------------- */
36708 +typedef void (*au_wkq_func_t)(void *args);
36711 +#define AuWkq_WAIT 1
36712 +#define AuWkq_NEST (1 << 1)
36713 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36714 +#define au_fset_wkq(flags, name) \
36715 + do { (flags) |= AuWkq_##name; } while (0)
36716 +#define au_fclr_wkq(flags, name) \
36717 + do { (flags) &= ~AuWkq_##name; } while (0)
36720 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36721 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36722 + unsigned int flags);
36723 +void au_nwt_init(struct au_nowait_tasks *nwt);
36724 +int __init au_wkq_init(void);
36725 +void au_wkq_fin(void);
36727 +/* ---------------------------------------------------------------------- */
36729 +static inline int au_wkq_test(void)
36731 + return current->flags & PF_WQ_WORKER;
36734 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36736 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36739 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36741 + if (atomic_dec_and_test(&nwt->nw_len))
36742 + wake_up_all(&nwt->nw_wq);
36745 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36747 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36751 +#endif /* __KERNEL__ */
36752 +#endif /* __AUFS_WKQ_H__ */
36753 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36754 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36755 +++ linux/fs/aufs/xattr.c 2023-10-31 09:31:04.203214083 +0100
36757 +// SPDX-License-Identifier: GPL-2.0
36759 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36761 + * This program is free software; you can redistribute it and/or modify
36762 + * it under the terms of the GNU General Public License as published by
36763 + * the Free Software Foundation; either version 2 of the License, or
36764 + * (at your option) any later version.
36766 + * This program is distributed in the hope that it will be useful,
36767 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36768 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36769 + * GNU General Public License for more details.
36771 + * You should have received a copy of the GNU General Public License
36772 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36776 + * handling xattr functions
36779 +#include <linux/fs.h>
36780 +#include <linux/xattr.h>
36783 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36785 + if (!ignore_flags)
36793 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36798 +#define cmp(brattr, prefix) do { \
36799 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36800 + XATTR_##prefix##_PREFIX_LEN)) { \
36801 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36807 + cmp(SEC, SECURITY);
36808 + cmp(SYS, SYSTEM);
36809 + cmp(TR, TRUSTED);
36813 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36820 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36822 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36823 + char *name, char **buf, unsigned int ignore_flags,
36824 + unsigned int verbose)
36828 + struct inode *h_idst;
36829 + struct dentry *h_dst_dentry, *h_src_dentry;
36830 + struct mnt_idmap *h_dst_idmap, *h_src_idmap;
36831 + struct posix_acl *acl;
36833 + is_acl = !!is_posix_acl_xattr(name);
36834 + h_src_idmap = mnt_idmap(h_src->mnt);
36835 + h_src_dentry = h_src->dentry;
36837 + acl = vfs_get_acl(h_src_idmap, h_src_dentry, name);
36839 + if (unlikely(IS_ERR(acl))) {
36840 + err = PTR_ERR(acl);
36841 + if (err == -ENODATA)
36843 + else if (err == -EOPNOTSUPP
36844 + && au_test_nfs_noacl(d_inode(h_src_dentry)))
36846 + else if (verbose || au_debug_test())
36847 + pr_err("%s, err %d\n", name, err);
36851 + ssz = vfs_getxattr_alloc(h_src_idmap, h_src_dentry, name, buf,
36853 + if (unlikely(ssz <= 0)) {
36855 + if (err == -ENODATA)
36857 + else if (err == -EOPNOTSUPP
36858 + && (ignore_flags & au_xattr_out_of_list))
36860 + else if (err && (verbose || au_debug_test()))
36861 + pr_err("%s, err %d\n", name, err);
36866 + /* unlock it temporary */
36867 + h_dst_idmap = mnt_idmap(h_dst->mnt);
36868 + h_dst_dentry = h_dst->dentry;
36869 + h_idst = d_inode(h_dst_dentry);
36870 + inode_unlock(h_idst);
36872 + err = vfsub_set_acl(h_dst_idmap, h_dst_dentry, name, acl);
36873 + posix_acl_release(acl);
36875 + err = vfsub_setxattr(h_dst_idmap, h_dst_dentry, name, *buf,
36876 + ssz, /*flags*/0);
36877 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36878 + if (unlikely(err)) {
36879 + if (verbose || au_debug_test())
36880 + pr_err("%s, err %d\n", name, err);
36881 + err = au_xattr_ignore(err, name, ignore_flags);
36888 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36889 + unsigned int verbose)
36891 + int err, unlocked;
36893 + struct dentry *h_dst_dentry, *h_src_dentry;
36894 + struct inode *h_isrc, *h_idst;
36895 + char *value, *p, *o, *e;
36897 + /* try stopping to update the source inode while we are referencing */
36898 + /* there should not be the parent-child relationship between them */
36899 + h_dst_dentry = h_dst->dentry;
36900 + h_idst = d_inode(h_dst_dentry);
36901 + h_src_dentry = h_src->dentry;
36902 + h_isrc = d_inode(h_src_dentry);
36903 + inode_unlock(h_idst);
36904 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36905 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36908 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36909 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36911 + if (unlikely(err < 0)) {
36913 + if (err == -ENODATA
36914 + || err == -EOPNOTSUPP)
36915 + err = 0; /* ignore */
36924 + p = kmalloc(ssz, GFP_NOFS);
36926 + if (unlikely(!p))
36928 + err = vfs_listxattr(h_src_dentry, p, ssz);
36930 + inode_unlock_shared(h_isrc);
36932 + AuDbg("err %d, ssz %zd\n", err, ssz);
36933 + if (unlikely(err < 0))
36939 + ignore_flags |= au_xattr_out_of_list;
36940 + while (!err && p < e) {
36941 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36943 + p += strlen(p) + 1;
36945 + au_kfree_try_rcu(value);
36948 + au_kfree_try_rcu(o);
36951 + inode_unlock_shared(h_isrc);
36956 +/* ---------------------------------------------------------------------- */
36958 +static int au_smack_reentering(struct super_block *sb)
36960 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36962 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36963 + * i_op->getxattr(). ouch.
36965 + return si_pid_test(sb);
36976 +struct au_lgxattr {
36984 + const char *name;
36991 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36992 + struct au_lgxattr *arg)
36996 + struct path h_path;
36997 + struct super_block *sb;
36999 + sb = dentry->d_sb;
37000 + reenter = au_smack_reentering(sb);
37002 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
37003 + if (unlikely(err))
37006 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
37007 + if (unlikely(err))
37009 + if (unlikely(!h_path.dentry))
37010 + /* illegally overlapped or something */
37011 + goto out_di; /* pretending success */
37013 + /* always topmost entry only */
37014 + switch (arg->type) {
37015 + case AU_XATTR_LIST:
37016 + err = vfs_listxattr(h_path.dentry,
37017 + arg->u.list.list, arg->u.list.size);
37019 + case AU_XATTR_GET:
37020 + AuDebugOn(d_is_negative(h_path.dentry));
37021 + err = vfs_getxattr(mnt_idmap(h_path.mnt), h_path.dentry,
37022 + arg->u.get.name, arg->u.get.value,
37023 + arg->u.get.size);
37029 + di_read_unlock(dentry, AuLock_IR);
37032 + si_read_unlock(sb);
37038 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37040 + struct au_lgxattr arg = {
37041 + .type = AU_XATTR_LIST,
37048 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37051 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37052 + const char *name, void *value, size_t size)
37054 + struct au_lgxattr arg = {
37055 + .type = AU_XATTR_GET,
37063 + return au_lgxattr(dentry, inode, &arg);
37066 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37067 + const char *name, const void *value, size_t size,
37070 + struct au_sxattr arg = {
37071 + .type = AU_XATTR_SET,
37080 + return au_sxattr(dentry, inode, &arg);
37083 +/* ---------------------------------------------------------------------- */
37085 +static int au_xattr_get(const struct xattr_handler *handler,
37086 + struct dentry *dentry, struct inode *inode,
37087 + const char *name, void *buffer, size_t size)
37089 + return au_getxattr(dentry, inode, name, buffer, size);
37092 +static int au_xattr_set(const struct xattr_handler *handler,
37093 + struct mnt_idmap *idmap,
37094 + struct dentry *dentry, struct inode *inode,
37095 + const char *name, const void *value, size_t size,
37098 + return au_setxattr(dentry, inode, name, value, size, flags);
37101 +static const struct xattr_handler au_xattr_handler = {
37104 + .get = au_xattr_get,
37105 + .set = au_xattr_set
37108 +static const struct xattr_handler *au_xattr_handlers[] = {
37109 + &au_xattr_handler, /* must be last */
37113 +void au_xattr_init(struct super_block *sb)
37115 + sb->s_xattr = au_xattr_handlers;
37117 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37118 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37119 +++ linux/fs/aufs/xino.c 2023-10-31 09:31:04.203214083 +0100
37121 +// SPDX-License-Identifier: GPL-2.0
37123 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37125 + * This program is free software; you can redistribute it and/or modify
37126 + * it under the terms of the GNU General Public License as published by
37127 + * the Free Software Foundation; either version 2 of the License, or
37128 + * (at your option) any later version.
37130 + * This program is distributed in the hope that it will be useful,
37131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37133 + * GNU General Public License for more details.
37135 + * You should have received a copy of the GNU General Public License
37136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37140 + * external inode number translation table and bitmap
37142 + * things to consider
37144 + * + au_xino object
37145 + * + XINO files (xino, xib, xigen)
37146 + * + dynamic debugfs entries (xiN)
37147 + * + static debugfs entries (xib, xigen)
37148 + * + static sysfs entry (xi_path)
37149 + * - several entry points to handle them.
37150 + * + mount(2) without xino option (default)
37151 + * + mount(2) with xino option
37152 + * + mount(2) with noxino option
37154 + * + remount with add/del branches
37155 + * + remount with xino/noxino options
37158 +#include <linux/seq_file.h>
37159 +#include <linux/statfs.h>
37162 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37163 + aufs_bindex_t bbot,
37164 + struct super_block *h_sb)
37166 + /* todo: try binary-search if the branches are many */
37167 + for (; btop <= bbot; btop++)
37168 + if (h_sb == au_sbr_sb(sb, btop))
37174 + * find another branch who is on the same filesystem of the specified
37175 + * branch{@btgt}. search until @bbot.
37177 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37178 + aufs_bindex_t bbot)
37180 + aufs_bindex_t bindex;
37181 + struct super_block *tgt_sb;
37183 + tgt_sb = au_sbr_sb(sb, btgt);
37184 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37186 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37191 +/* ---------------------------------------------------------------------- */
37194 + * stop unnecessary notify events at creating xino files
37197 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37199 + aufs_bindex_t bfound, bindex, bbot;
37200 + struct dentry *parent;
37201 + struct au_branch *br;
37204 + parent = dentry->d_parent; /* safe d_parent access */
37205 + bbot = au_sbbot(sb);
37206 + for (bindex = 0; bindex <= bbot; bindex++) {
37207 + br = au_sbr(sb, bindex);
37208 + if (au_br_dentry(br) == parent) {
37214 + AuDbg("bfound b%d\n", bfound);
37218 +struct au_xino_lock_dir {
37219 + struct au_hinode *hdir;
37220 + struct dentry *parent;
37221 + struct inode *dir;
37224 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37225 + unsigned int lsc)
37227 + struct dentry *parent;
37228 + struct inode *dir;
37230 + parent = dget_parent(dentry);
37231 + dir = d_inode(parent);
37232 + inode_lock_nested(dir, lsc);
37233 +#if 0 /* it should not happen */
37234 + spin_lock(&dentry->d_lock);
37235 + if (unlikely(dentry->d_parent != parent)) {
37236 + spin_unlock(&dentry->d_lock);
37237 + inode_unlock(dir);
37242 + spin_unlock(&dentry->d_lock);
37249 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37250 + struct au_xino_lock_dir *ldir)
37252 + aufs_bindex_t bindex;
37254 + ldir->hdir = NULL;
37255 + bindex = au_xi_root(sb, xipath->dentry);
37256 + if (bindex >= 0) {
37257 + /* rw branch root */
37258 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37259 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37262 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37264 + ldir->dir = d_inode(ldir->parent);
37268 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37271 + au_hn_inode_unlock(ldir->hdir);
37273 + inode_unlock(ldir->dir);
37274 + dput(ldir->parent);
37278 +/* ---------------------------------------------------------------------- */
37281 + * create and set a new xino file
37283 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37286 + struct file *file;
37287 + struct dentry *h_parent, *d;
37288 + struct inode *h_dir, *inode;
37290 + static DEFINE_MUTEX(mtx);
37293 + * at mount-time, and the xino file is the default path,
37294 + * hnotify is disabled so we have no notify events to ignore.
37295 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37298 + mutex_lock(&mtx);
37299 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37300 + /* | __FMODE_NONOTIFY */,
37302 + if (IS_ERR(file)) {
37304 + mutex_unlock(&mtx);
37306 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37310 + /* keep file count */
37312 + d = file->f_path.dentry;
37313 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37315 + mutex_unlock(&mtx);
37316 + /* mnt_want_write() is unnecessary here */
37317 + h_dir = d_inode(h_parent);
37318 + inode = file_inode(file);
37319 + /* no delegation since it is just created */
37320 + if (inode->i_nlink)
37321 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37323 + inode_unlock(h_dir);
37325 + if (unlikely(err)) {
37327 + pr_err("unlink %s(%d)\n", fpath, err);
37332 + if (unlikely(sb && sb == d->d_sb)) {
37334 + pr_err("%s must be outside\n", fpath);
37337 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37339 + pr_err("xino doesn't support %s(%s)\n",
37340 + fpath, au_sbtype(d->d_sb));
37343 + return file; /* success */
37347 + file = ERR_PTR(err);
37352 + * create a new xinofile at the same place/path as @base.
37354 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37355 + struct file *copy_src)
37357 + struct file *file;
37358 + struct dentry *dentry;
37359 + struct inode *dir, *delegated;
37360 + struct qstr *name;
37361 + struct path ppath, path;
37362 + int err, do_unlock;
37363 + struct au_xino_lock_dir ldir;
37366 + au_xino_lock_dir(sb, base, &ldir);
37367 + dentry = base->dentry;
37368 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37369 + ppath.mnt = base->mnt;
37370 + dir = d_inode(ppath.dentry);
37373 + name = &dentry->d_name;
37374 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37375 + if (IS_ERR(path.dentry)) {
37376 + file = (void *)path.dentry;
37377 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37381 + /* no need to mnt_want_write() since we call dentry_open() later */
37382 + err = vfs_create(mnt_idmap(base->mnt), dir, path.dentry, 0666, NULL);
37383 + if (unlikely(err)) {
37384 + file = ERR_PTR(err);
37385 + pr_err("%pd create err %d\n", dentry, err);
37389 + path.mnt = base->mnt;
37390 + file = vfsub_dentry_open(&path,
37391 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37392 + /* | __FMODE_NONOTIFY */);
37393 + if (IS_ERR(file)) {
37394 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37398 + delegated = NULL;
37399 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37400 + au_xino_unlock_dir(&ldir);
37402 + if (unlikely(err == -EWOULDBLOCK)) {
37403 + pr_warn("cannot retry for NFSv4 delegation"
37404 + " for an internal unlink\n");
37407 + if (unlikely(err)) {
37408 + pr_err("%pd unlink err %d\n", dentry, err);
37413 + /* no one can touch copy_src xino */
37414 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37415 + if (unlikely(err)) {
37416 + pr_err("%pd copy err %d\n", dentry, err);
37420 + goto out_dput; /* success */
37424 + file = ERR_PTR(err);
37426 + dput(path.dentry);
37429 + au_xino_unlock_dir(&ldir);
37433 +struct file *au_xino_file1(struct au_xino *xi)
37435 + struct file *file;
37436 + unsigned int u, nfile;
37439 + nfile = xi->xi_nfile;
37440 + for (u = 0; u < nfile; u++) {
37441 + file = xi->xi_file[u];
37449 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37460 + if (idx < xi->xi_nfile) {
37461 + f = xi->xi_file[idx];
37465 + p = au_kzrealloc(xi->xi_file,
37466 + sizeof(*xi->xi_file) * xi->xi_nfile,
37467 + sizeof(*xi->xi_file) * (idx + 1),
37468 + GFP_NOFS, /*may_shrink*/0);
37470 + MtxMustLock(&xi->xi_mtx);
37472 + xi->xi_nfile = idx + 1;
37480 + xi->xi_file[idx] = file;
37487 + * if @xinew->xi is not set, then create new xigen file.
37489 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37491 + struct file *file;
37494 + SiMustAnyLock(sb);
37496 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37497 + if (IS_ERR(file)) {
37498 + err = PTR_ERR(file);
37499 + pr_err("%s[%d], err %d\n",
37500 + xinew->xi ? "xino" : "xigen",
37501 + xinew->idx, err);
37506 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37509 + /* todo: make xigen file an array */
37510 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37513 + if (unlikely(err))
37514 + file = ERR_PTR(err);
37520 +/* ---------------------------------------------------------------------- */
37523 + * truncate xino files
37525 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37526 + int idx, struct kstatfs *st)
37530 + struct file *file, *new_xino;
37531 + struct au_xi_new xinew = {
37536 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37537 + file = au_xino_file(xinew.xi, idx);
37541 + xinew.base = &file->f_path;
37542 + err = vfs_statfs(xinew.base, st);
37543 + if (unlikely(err)) {
37544 + AuErr1("statfs err %d, ignored\n", err);
37549 + blocks = file_inode(file)->i_blocks;
37550 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37551 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37553 + xinew.copy_src = file;
37554 + new_xino = au_xi_new(sb, &xinew);
37555 + if (IS_ERR(new_xino)) {
37556 + err = PTR_ERR(new_xino);
37557 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37561 + err = vfs_statfs(&new_xino->f_path, st);
37563 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37564 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37565 + st->f_bfree, st->f_blocks);
37567 + AuErr1("statfs err %d, ignored\n", err);
37575 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37578 + unsigned long jiffy;
37579 + aufs_bindex_t bbot;
37580 + struct kstatfs *st;
37581 + struct au_branch *br;
37582 + struct au_xino *xi;
37585 + st = kmalloc(sizeof(*st), GFP_NOFS);
37586 + if (unlikely(!st))
37590 + bbot = au_sbbot(sb);
37591 + if (unlikely(bindex < 0 || bbot < bindex))
37596 + br = au_sbr(sb, bindex);
37597 + xi = br->br_xino;
37598 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37599 + err = au_xino_do_trunc(sb, bindex, i, st);
37601 + au_sbi(sb)->si_xino_jiffy = jiffy;
37604 + au_kfree_rcu(st);
37609 +struct xino_do_trunc_args {
37610 + struct super_block *sb;
37611 + struct au_branch *br;
37615 +static void xino_do_trunc(void *_args)
37617 + struct xino_do_trunc_args *args = _args;
37618 + struct super_block *sb;
37619 + struct au_branch *br;
37620 + struct inode *dir;
37622 + aufs_bindex_t bindex;
37626 + dir = d_inode(sb->s_root);
37630 + si_noflush_write_lock(sb);
37631 + ii_read_lock_parent(dir);
37632 + bindex = au_br_index(sb, br->br_id);
37633 + err = au_xino_trunc(sb, bindex, idx);
37634 + ii_read_unlock(dir);
37635 + if (unlikely(err))
37636 + pr_warn("err b%d, (%d)\n", bindex, err);
37637 + atomic_dec(&br->br_xino->xi_truncating);
37638 + au_lcnt_dec(&br->br_count);
37639 + si_write_unlock(sb);
37640 + au_nwt_done(&au_sbi(sb)->si_nowait);
37641 + au_kfree_rcu(args);
37645 + * returns the index in the xi_file array whose corresponding file is necessary
37646 + * to truncate, or -1 which means no need to truncate.
37648 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37652 + struct kstatfs st;
37653 + struct au_sbinfo *sbinfo;
37654 + struct au_xino *xi;
37655 + struct file *file;
37657 + /* todo: si_xino_expire and the ratio should be customizable */
37658 + sbinfo = au_sbi(sb);
37659 + if (time_before(jiffies,
37660 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37663 + /* truncation border */
37664 + xi = br->br_xino;
37665 + for (u = 0; u < xi->xi_nfile; u++) {
37666 + file = au_xino_file(xi, u);
37670 + err = vfs_statfs(&file->f_path, &st);
37671 + if (unlikely(err)) {
37672 + AuErr1("statfs err %d, ignored\n", err);
37675 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37676 + >= AUFS_XINO_DEF_TRUNC)
37683 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37686 + struct xino_do_trunc_args *args;
37689 + idx = xino_trunc_test(sb, br);
37693 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37696 + /* lock and kfree() will be called in trunc_xino() */
37697 + args = kmalloc(sizeof(*args), GFP_NOFS);
37698 + if (unlikely(!args)) {
37699 + AuErr1("no memory\n");
37703 + au_lcnt_inc(&br->br_count);
37707 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37709 + return; /* success */
37711 + pr_err("wkq %d\n", wkq_err);
37712 + au_lcnt_dec(&br->br_count);
37713 + au_kfree_rcu(args);
37716 + atomic_dec(&br->br_xino->xi_truncating);
37719 +/* ---------------------------------------------------------------------- */
37721 +struct au_xi_calc {
37726 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37727 + struct au_xi_calc *calc)
37731 + maxent = au_xi_maxent(sb);
37732 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37733 + calc->pos *= sizeof(ino_t);
37736 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37737 + struct au_xi_calc *calc)
37740 + struct file *file;
37741 + struct au_xino *xi = br->br_xino;
37742 + struct au_xi_new xinew = {
37746 + SiMustAnyLock(sb);
37752 + mutex_lock(&xi->xi_mtx);
37753 + file = au_xino_file(xi, calc->idx);
37757 + file = au_xino_file(xi, /*idx*/-1);
37758 + AuDebugOn(!file);
37759 + xinew.idx = calc->idx;
37760 + xinew.base = &file->f_path;
37761 + /* xinew.copy_src = NULL; */
37762 + file = au_xi_new(sb, &xinew);
37763 + if (IS_ERR(file))
37764 + err = PTR_ERR(file);
37767 + mutex_unlock(&xi->xi_mtx);
37772 +struct au_xino_do_new_async_args {
37773 + struct super_block *sb;
37774 + struct au_branch *br;
37775 + struct au_xi_calc calc;
37779 +struct au_xi_writing {
37780 + struct hlist_bl_node node;
37781 + ino_t h_ino, ino;
37784 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37787 +static void au_xino_call_do_new_async(void *args)
37789 + struct au_xino_do_new_async_args *a = args;
37790 + struct au_branch *br;
37791 + struct super_block *sb;
37792 + struct au_sbinfo *sbi;
37793 + struct inode *root;
37794 + struct file *file;
37795 + struct au_xi_writing *del, *p;
37796 + struct hlist_bl_head *hbl;
37797 + struct hlist_bl_node *pos;
37802 + sbi = au_sbi(sb);
37803 + si_noflush_read_lock(sb);
37804 + root = d_inode(sb->s_root);
37805 + ii_read_lock_child(root);
37806 + err = au_xino_do_new_async(sb, br, &a->calc);
37807 + if (unlikely(err)) {
37808 + AuIOErr("err %d\n", err);
37812 + file = au_xino_file(br->br_xino, a->calc.idx);
37813 + AuDebugOn(!file);
37814 + err = au_xino_do_write(file, &a->calc, a->ino);
37815 + if (unlikely(err)) {
37816 + AuIOErr("err %d\n", err);
37821 + hbl = &br->br_xino->xi_writing;
37822 + hlist_bl_lock(hbl);
37823 + au_hbl_for_each(pos, hbl) {
37824 + p = container_of(pos, struct au_xi_writing, node);
37825 + if (p->ino == a->ino) {
37827 + hlist_bl_del(&p->node);
37831 + hlist_bl_unlock(hbl);
37832 + au_kfree_rcu(del);
37835 + au_lcnt_dec(&br->br_count);
37836 + ii_read_unlock(root);
37837 + si_read_unlock(sb);
37838 + au_nwt_done(&sbi->si_nowait);
37843 + * create a new xino file asynchronously
37845 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37846 + struct au_xi_calc *calc, ino_t ino)
37849 + struct au_xino_do_new_async_args *arg;
37852 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37853 + if (unlikely(!arg))
37858 + arg->calc = *calc;
37860 + au_lcnt_inc(&br->br_count);
37861 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37862 + if (unlikely(err)) {
37863 + pr_err("wkq %d\n", err);
37864 + au_lcnt_dec(&br->br_count);
37865 + au_kfree_rcu(arg);
37873 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37874 + * at the position of @h_ino.
37876 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37881 + struct au_xi_calc calc;
37882 + struct au_sbinfo *sbinfo;
37883 + struct file *file;
37884 + struct au_xino *xi;
37885 + struct hlist_bl_head *hbl;
37886 + struct hlist_bl_node *pos;
37887 + struct au_xi_writing *p;
37890 + if (!au_opt_test(au_mntflags(sb), XINO))
37891 + return 0; /* no xino */
37894 + au_xi_calc(sb, h_ino, &calc);
37895 + xi = au_sbr(sb, bindex)->br_xino;
37896 + file = au_xino_file(xi, calc.idx);
37898 + hbl = &xi->xi_writing;
37899 + hlist_bl_lock(hbl);
37900 + au_hbl_for_each(pos, hbl) {
37901 + p = container_of(pos, struct au_xi_writing, node);
37902 + if (p->h_ino == h_ino) {
37903 + AuDbg("hi%llu, i%llu, found\n",
37904 + (u64)p->h_ino, (u64)p->ino);
37909 + hlist_bl_unlock(hbl);
37911 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37912 + return 0; /* no xino */
37914 + sbinfo = au_sbi(sb);
37915 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37916 + if (sz == sizeof(*ino))
37917 + return 0; /* success */
37920 + if (unlikely(sz >= 0)) {
37922 + AuIOErr("xino read error (%zd)\n", sz);
37927 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37932 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37933 + if (sz == sizeof(ino))
37934 + return 0; /* success */
37936 + AuIOErr("write failed (%zd)\n", sz);
37941 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37942 + * at the position of @h_ino.
37943 + * even if @ino is zero, it is written to the xinofile and means no entry.
37944 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37945 + * try truncating it.
37947 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37951 + unsigned int mnt_flags;
37952 + struct au_xi_calc calc;
37953 + struct file *file;
37954 + struct au_branch *br;
37955 + struct au_xino *xi;
37956 + struct au_xi_writing *p;
37958 + SiMustAnyLock(sb);
37960 + mnt_flags = au_mntflags(sb);
37961 + if (!au_opt_test(mnt_flags, XINO))
37964 + au_xi_calc(sb, h_ino, &calc);
37965 + br = au_sbr(sb, bindex);
37966 + xi = br->br_xino;
37967 + file = au_xino_file(xi, calc.idx);
37969 + /* store the inum pair into the list */
37970 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37971 + p->h_ino = h_ino;
37973 + au_hbl_add(&p->node, &xi->xi_writing);
37975 + /* create and write a new xino file asynchronously */
37976 + err = au_xino_new_async(sb, br, &calc, ino);
37978 + return 0; /* success */
37982 + err = au_xino_do_write(file, &calc, ino);
37984 + br = au_sbr(sb, bindex);
37985 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37986 + && au_test_fs_trunc_xino(au_br_sb(br)))
37987 + xino_try_trunc(sb, br);
37988 + return 0; /* success */
37992 + AuIOErr("write failed (%d)\n", err);
37996 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37999 +/* todo: unnecessary to support mmap_sem since kernel-space? */
38000 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
38004 + const int prevent_endless = 10;
38008 + err = vfsub_read_k(file, kbuf, size, pos);
38009 + if (err == -EINTR
38010 + && !au_wkq_test()
38011 + && fatal_signal_pending(current)) {
38012 + err = xino_fread_wkq(file, kbuf, size, pos);
38013 + BUG_ON(err == -EINTR);
38015 + } while (i++ < prevent_endless
38016 + && (err == -EAGAIN || err == -EINTR));
38018 +#if 0 /* reserved for future use */
38020 + fsnotify_access(file->f_path.dentry);
38026 +struct xino_fread_args {
38028 + struct file *file;
38034 +static void call_xino_fread(void *args)
38036 + struct xino_fread_args *a = args;
38037 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38040 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38045 + struct xino_fread_args args = {
38053 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38054 + if (unlikely(wkq_err))
38060 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38063 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38068 + const int prevent_endless = 10;
38072 + err = vfsub_write_k(file, kbuf, size, pos);
38073 + if (err == -EINTR
38074 + && !au_wkq_test()
38075 + && fatal_signal_pending(current)) {
38076 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38077 + BUG_ON(err == -EINTR);
38079 + } while (i++ < prevent_endless
38080 + && (err == -EAGAIN || err == -EINTR));
38082 +#if 0 /* reserved for future use */
38084 + fsnotify_modify(file->f_path.dentry);
38090 +struct do_xino_fwrite_args {
38092 + struct file *file;
38098 +static void call_do_xino_fwrite(void *args)
38100 + struct do_xino_fwrite_args *a = args;
38101 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38104 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38109 + struct do_xino_fwrite_args args = {
38118 + * it breaks RLIMIT_FSIZE and normal user's limit,
38119 + * users should care about quota and real 'filesystem full.'
38121 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38122 + if (unlikely(wkq_err))
38128 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38132 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38134 + err = do_xino_fwrite(file, buf, size, pos);
38138 + err = xino_fwrite_wkq(file, buf, size, pos);
38145 +/* ---------------------------------------------------------------------- */
38148 + * inode number bitmap
38150 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38151 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38155 + AuDebugOn(bit < 0 || page_bits <= bit);
38156 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38160 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38162 + AuDebugOn(ino < AUFS_FIRST_INO);
38163 + ino -= AUFS_FIRST_INO;
38164 + *pindex = ino / page_bits;
38165 + *bit = ino % page_bits;
38168 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38173 + struct au_sbinfo *sbinfo;
38174 + struct file *xib;
38175 + unsigned long *p;
38177 + sbinfo = au_sbi(sb);
38178 + MtxMustLock(&sbinfo->si_xib_mtx);
38179 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38180 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38182 + if (pindex == sbinfo->si_xib_last_pindex)
38185 + xib = sbinfo->si_xib;
38186 + p = sbinfo->si_xib_buf;
38187 + pos = sbinfo->si_xib_last_pindex;
38188 + pos *= PAGE_SIZE;
38189 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38190 + if (unlikely(sz != PAGE_SIZE))
38194 + pos *= PAGE_SIZE;
38195 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38196 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38198 + memset(p, 0, PAGE_SIZE);
38199 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38201 + if (sz == PAGE_SIZE) {
38202 + sbinfo->si_xib_last_pindex = pindex;
38203 + return 0; /* success */
38207 + AuIOErr1("write failed (%zd)\n", sz);
38214 +static void au_xib_clear_bit(struct inode *inode)
38217 + unsigned long pindex;
38218 + struct super_block *sb;
38219 + struct au_sbinfo *sbinfo;
38221 + AuDebugOn(inode->i_nlink);
38223 + sb = inode->i_sb;
38224 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38225 + AuDebugOn(page_bits <= bit);
38226 + sbinfo = au_sbi(sb);
38227 + mutex_lock(&sbinfo->si_xib_mtx);
38228 + err = xib_pindex(sb, pindex);
38230 + clear_bit(bit, sbinfo->si_xib_buf);
38231 + sbinfo->si_xib_next_bit = bit;
38233 + mutex_unlock(&sbinfo->si_xib_mtx);
38236 +/* ---------------------------------------------------------------------- */
38239 + * truncate a xino bitmap file
38243 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38247 + unsigned long pindex;
38248 + loff_t pos, pend;
38249 + struct au_sbinfo *sbinfo;
38251 + unsigned long *p;
38254 + sbinfo = au_sbi(sb);
38255 + MtxMustLock(&sbinfo->si_xib_mtx);
38256 + p = sbinfo->si_xib_buf;
38257 + pend = vfsub_f_size_read(file);
38259 + while (pos < pend) {
38260 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38262 + if (unlikely(sz <= 0))
38266 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38267 + if (unlikely(*ino < AUFS_FIRST_INO))
38270 + xib_calc_bit(*ino, &pindex, &bit);
38271 + AuDebugOn(page_bits <= bit);
38272 + err = xib_pindex(sb, pindex);
38284 +static int xib_restore(struct super_block *sb)
38287 + unsigned int nfile;
38288 + aufs_bindex_t bindex, bbot;
38290 + struct au_branch *br;
38291 + struct au_xino *xi;
38292 + struct file *file;
38295 + page = (void *)__get_free_page(GFP_NOFS);
38296 + if (unlikely(!page))
38300 + bbot = au_sbbot(sb);
38301 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38302 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38303 + br = au_sbr(sb, bindex);
38304 + xi = br->br_xino;
38305 + nfile = xi->xi_nfile;
38306 + for (i = 0; i < nfile; i++) {
38307 + file = au_xino_file(xi, i);
38309 + err = do_xib_restore(sb, file, page);
38312 + AuDbg("skip shared b%d\n", bindex);
38313 + free_page((unsigned long)page);
38319 +int au_xib_trunc(struct super_block *sb)
38324 + struct au_sbinfo *sbinfo;
38325 + unsigned long *p;
38326 + struct file *file;
38328 + SiMustWriteLock(sb);
38331 + sbinfo = au_sbi(sb);
38332 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38335 + file = sbinfo->si_xib;
38336 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38339 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38340 + err = PTR_ERR(file);
38341 + if (IS_ERR(file))
38343 + fput(sbinfo->si_xib);
38344 + sbinfo->si_xib = file;
38346 + p = sbinfo->si_xib_buf;
38347 + memset(p, 0, PAGE_SIZE);
38349 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38350 + if (unlikely(sz != PAGE_SIZE)) {
38352 + AuIOErr("err %d\n", err);
38358 + mutex_lock(&sbinfo->si_xib_mtx);
38359 + /* mnt_want_write() is unnecessary here */
38360 + err = xib_restore(sb);
38361 + mutex_unlock(&sbinfo->si_xib_mtx);
38367 +/* ---------------------------------------------------------------------- */
38369 +struct au_xino *au_xino_alloc(unsigned int nfile)
38371 + struct au_xino *xi;
38373 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38374 + if (unlikely(!xi))
38376 + xi->xi_nfile = nfile;
38377 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38378 + if (unlikely(!xi->xi_file))
38381 + xi->xi_nondir.total = 8; /* initial size */
38382 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38384 + if (unlikely(!xi->xi_nondir.array))
38387 + spin_lock_init(&xi->xi_nondir.spin);
38388 + init_waitqueue_head(&xi->xi_nondir.wqh);
38389 + mutex_init(&xi->xi_mtx);
38390 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38391 + atomic_set(&xi->xi_truncating, 0);
38392 + kref_init(&xi->xi_kref);
38393 + goto out; /* success */
38396 + au_kfree_try_rcu(xi->xi_file);
38398 + au_kfree_rcu(xi);
38404 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38407 + struct au_xino *xi;
38410 + xi = au_xino_alloc(idx + 1);
38411 + if (unlikely(!xi)) {
38418 + xi->xi_file[idx] = file;
38419 + AuDebugOn(br->br_xino);
38420 + br->br_xino = xi;
38426 +static void au_xino_release(struct kref *kref)
38428 + struct au_xino *xi;
38430 + unsigned long ul;
38431 + struct hlist_bl_head *hbl;
38432 + struct hlist_bl_node *pos, *n;
38433 + struct au_xi_writing *p;
38435 + xi = container_of(kref, struct au_xino, xi_kref);
38436 + for (i = 0; i < xi->xi_nfile; i++)
38437 + if (xi->xi_file[i])
38438 + fput(xi->xi_file[i]);
38439 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38440 + AuDebugOn(xi->xi_nondir.array[i]);
38441 + mutex_destroy(&xi->xi_mtx);
38442 + hbl = &xi->xi_writing;
38443 + ul = au_hbl_count(hbl);
38444 + if (unlikely(ul)) {
38445 + pr_warn("xi_writing %lu\n", ul);
38446 + hlist_bl_lock(hbl);
38447 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38448 + hlist_bl_del(&p->node);
38449 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38452 + hlist_bl_unlock(hbl);
38454 + au_kfree_try_rcu(xi->xi_file);
38455 + au_kfree_try_rcu(xi->xi_nondir.array);
38456 + au_kfree_rcu(xi);
38459 +int au_xino_put(struct au_branch *br)
38462 + struct au_xino *xi;
38465 + xi = br->br_xino;
38467 + br->br_xino = NULL;
38468 + ret = kref_put(&xi->xi_kref, au_xino_release);
38474 +/* ---------------------------------------------------------------------- */
38477 + * xino mount option handlers
38481 +static void xino_clear_xib(struct super_block *sb)
38483 + struct au_sbinfo *sbinfo;
38485 + SiMustWriteLock(sb);
38487 + sbinfo = au_sbi(sb);
38488 + if (sbinfo->si_xib)
38489 + fput(sbinfo->si_xib);
38490 + sbinfo->si_xib = NULL;
38491 + if (sbinfo->si_xib_buf)
38492 + free_page((unsigned long)sbinfo->si_xib_buf);
38493 + sbinfo->si_xib_buf = NULL;
38496 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38500 + struct au_sbinfo *sbinfo;
38501 + struct file *file;
38502 + struct super_block *xi_sb;
38504 + SiMustWriteLock(sb);
38506 + sbinfo = au_sbi(sb);
38507 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38508 + err = PTR_ERR(file);
38509 + if (IS_ERR(file))
38511 + if (sbinfo->si_xib)
38512 + fput(sbinfo->si_xib);
38513 + sbinfo->si_xib = file;
38514 + xi_sb = file_inode(file)->i_sb;
38515 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38516 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38518 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38519 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38522 + sbinfo->si_ximaxent /= sizeof(ino_t);
38525 + if (!sbinfo->si_xib_buf)
38526 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38527 + if (unlikely(!sbinfo->si_xib_buf))
38530 + sbinfo->si_xib_last_pindex = 0;
38531 + sbinfo->si_xib_next_bit = 0;
38532 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38534 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38535 + if (unlikely(err != PAGE_SIZE))
38539 + goto out; /* success */
38542 + if (sbinfo->si_xib_buf)
38543 + free_page((unsigned long)sbinfo->si_xib_buf);
38544 + sbinfo->si_xib_buf = NULL;
38548 + fput(sbinfo->si_xib);
38549 + sbinfo->si_xib = NULL;
38555 +/* xino for each branch */
38556 +static void xino_clear_br(struct super_block *sb)
38558 + aufs_bindex_t bindex, bbot;
38559 + struct au_branch *br;
38561 + bbot = au_sbbot(sb);
38562 + for (bindex = 0; bindex <= bbot; bindex++) {
38563 + br = au_sbr(sb, bindex);
38569 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38570 + aufs_bindex_t bshared)
38572 + struct au_branch *brshared;
38574 + brshared = au_sbr(sb, bshared);
38575 + AuDebugOn(!brshared->br_xino);
38576 + AuDebugOn(!brshared->br_xino->xi_file);
38577 + if (br->br_xino != brshared->br_xino) {
38578 + au_xino_get(brshared);
38580 + br->br_xino = brshared->br_xino;
38584 +struct au_xino_do_set_br {
38585 + struct au_branch *br;
38587 + aufs_bindex_t bshared;
38590 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38591 + struct au_xino_do_set_br *args)
38594 + struct au_xi_calc calc;
38595 + struct file *file;
38596 + struct au_branch *br;
38597 + struct au_xi_new xinew = {
38602 + xinew.xi = br->br_xino;
38603 + au_xi_calc(sb, args->h_ino, &calc);
38604 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38605 + if (args->bshared >= 0)
38606 + /* shared xino */
38607 + au_xino_set_br_shared(sb, br, args->bshared);
38608 + else if (!xinew.xi) {
38610 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38611 + if (unlikely(err))
38615 + /* force re-creating */
38616 + xinew.xi = br->br_xino;
38617 + xinew.idx = calc.idx;
38618 + mutex_lock(&xinew.xi->xi_mtx);
38619 + file = au_xi_new(sb, &xinew);
38620 + mutex_unlock(&xinew.xi->xi_mtx);
38621 + err = PTR_ERR(file);
38622 + if (IS_ERR(file))
38624 + AuDebugOn(!file);
38626 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38627 + if (unlikely(err))
38635 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38638 + aufs_bindex_t bindex, bbot;
38639 + struct au_xino_do_set_br args;
38640 + struct inode *inode;
38642 + SiMustWriteLock(sb);
38644 + bbot = au_sbbot(sb);
38645 + inode = d_inode(sb->s_root);
38646 + for (bindex = 0; bindex <= bbot; bindex++) {
38647 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38648 + args.br = au_sbr(sb, bindex);
38649 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38650 + err = au_xino_do_set_br(sb, path, &args);
38651 + if (unlikely(err))
38659 +void au_xino_clr(struct super_block *sb)
38661 + struct au_sbinfo *sbinfo;
38663 + au_xigen_clr(sb);
38664 + xino_clear_xib(sb);
38665 + xino_clear_br(sb);
38666 + dbgaufs_brs_del(sb, 0);
38667 + sbinfo = au_sbi(sb);
38668 + /* lvalue, do not call au_mntflags() */
38669 + au_opt_clr(sbinfo->si_mntflags, XINO);
38672 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38675 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38676 + struct qstr *dname, *cur_name;
38677 + struct file *cur_xino;
38678 + struct au_sbinfo *sbinfo;
38679 + struct path *path, *cur_path;
38681 + SiMustWriteLock(sb);
38684 + sbinfo = au_sbi(sb);
38685 + path = &xiopt->file->f_path;
38686 + dentry = path->dentry;
38687 + parent = dget_parent(dentry);
38690 + cur_xino = sbinfo->si_xib;
38692 + cur_path = &cur_xino->f_path;
38693 + cur_dentry = cur_path->dentry;
38694 + cur_parent = dget_parent(cur_dentry);
38695 + cur_name = &cur_dentry->d_name;
38696 + dname = &dentry->d_name;
38697 + skip = (cur_parent == parent
38698 + && au_qstreq(dname, cur_name));
38699 + dput(cur_parent);
38705 + au_opt_set(sbinfo->si_mntflags, XINO);
38706 + err = au_xino_set_xib(sb, path);
38707 + /* si_x{read,write} are set */
38709 + err = au_xigen_set(sb, path);
38711 + err = au_xino_set_br(sb, path);
38713 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38714 + goto out; /* success */
38718 + AuIOErr("failed setting xino(%d).\n", err);
38727 + * create a xinofile at the default place/path.
38729 +struct file *au_xino_def(struct super_block *sb)
38731 + struct file *file;
38733 + struct au_branch *br;
38734 + struct super_block *h_sb;
38735 + struct path path;
38736 + aufs_bindex_t bbot, bindex, bwr;
38739 + bbot = au_sbbot(sb);
38741 + for (bindex = 0; bindex <= bbot; bindex++) {
38742 + br = au_sbr(sb, bindex);
38743 + if (au_br_writable(br->br_perm)
38744 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38751 + file = ERR_PTR(-ENOMEM);
38752 + page = (void *)__get_free_page(GFP_NOFS);
38753 + if (unlikely(!page))
38755 + path.mnt = au_br_mnt(br);
38756 + path.dentry = au_h_dptr(sb->s_root, bwr);
38757 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38758 + file = (void *)p;
38759 + if (!IS_ERR(p)) {
38760 + strcat(p, "/" AUFS_XINO_FNAME);
38761 + AuDbg("%s\n", p);
38762 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38764 + free_page((unsigned long)page);
38766 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38768 + if (IS_ERR(file))
38770 + h_sb = file->f_path.dentry->d_sb;
38771 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38772 + pr_err("xino doesn't support %s(%s)\n",
38773 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38775 + file = ERR_PTR(-EINVAL);
38783 +/* ---------------------------------------------------------------------- */
38786 + * initialize the xinofile for the specified branch @br
38787 + * at the place/path where @base_file indicates.
38788 + * test whether another branch is on the same filesystem or not,
38789 + * if found then share the xinofile with another branch.
38791 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38792 + struct path *base)
38795 + struct au_xino_do_set_br args = {
38800 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38802 + err = au_xino_do_set_br(sb, base, &args);
38803 + if (unlikely(err))
38809 +/* ---------------------------------------------------------------------- */
38812 + * get an unused inode number from bitmap
38814 +ino_t au_xino_new_ino(struct super_block *sb)
38817 + unsigned long *p, pindex, ul, pend;
38818 + struct au_sbinfo *sbinfo;
38819 + struct file *file;
38820 + int free_bit, err;
38822 + if (!au_opt_test(au_mntflags(sb), XINO))
38823 + return iunique(sb, AUFS_FIRST_INO);
38825 + sbinfo = au_sbi(sb);
38826 + mutex_lock(&sbinfo->si_xib_mtx);
38827 + p = sbinfo->si_xib_buf;
38828 + free_bit = sbinfo->si_xib_next_bit;
38829 + if (free_bit < page_bits && !test_bit(free_bit, p))
38830 + goto out; /* success */
38831 + free_bit = find_first_zero_bit(p, page_bits);
38832 + if (free_bit < page_bits)
38833 + goto out; /* success */
38835 + pindex = sbinfo->si_xib_last_pindex;
38836 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38837 + err = xib_pindex(sb, ul);
38838 + if (unlikely(err))
38840 + free_bit = find_first_zero_bit(p, page_bits);
38841 + if (free_bit < page_bits)
38842 + goto out; /* success */
38845 + file = sbinfo->si_xib;
38846 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38847 + for (ul = pindex + 1; ul <= pend; ul++) {
38848 + err = xib_pindex(sb, ul);
38849 + if (unlikely(err))
38851 + free_bit = find_first_zero_bit(p, page_bits);
38852 + if (free_bit < page_bits)
38853 + goto out; /* success */
38858 + set_bit(free_bit, p);
38859 + sbinfo->si_xib_next_bit = free_bit + 1;
38860 + pindex = sbinfo->si_xib_last_pindex;
38861 + mutex_unlock(&sbinfo->si_xib_mtx);
38862 + ino = xib_calc_ino(pindex, free_bit);
38863 + AuDbg("i%lu\n", (unsigned long)ino);
38866 + mutex_unlock(&sbinfo->si_xib_mtx);
38871 +/* for s_op->delete_inode() */
38872 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38875 + unsigned int mnt_flags;
38876 + aufs_bindex_t bindex, bbot, bi;
38877 + unsigned char try_trunc;
38878 + struct au_iinfo *iinfo;
38879 + struct super_block *sb;
38880 + struct au_hinode *hi;
38881 + struct inode *h_inode;
38882 + struct au_branch *br;
38883 + struct au_xi_calc calc;
38884 + struct file *file;
38886 + AuDebugOn(au_is_bad_inode(inode));
38888 + sb = inode->i_sb;
38889 + mnt_flags = au_mntflags(sb);
38890 + if (!au_opt_test(mnt_flags, XINO)
38891 + || inode->i_ino == AUFS_ROOT_INO)
38895 + au_xigen_inc(inode);
38896 + au_xib_clear_bit(inode);
38899 + iinfo = au_ii(inode);
38900 + bindex = iinfo->ii_btop;
38904 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38905 + hi = au_hinode(iinfo, bindex);
38906 + bbot = iinfo->ii_bbot;
38907 + for (; bindex <= bbot; bindex++, hi++) {
38908 + h_inode = hi->hi_inode;
38910 + || (!unlinked && h_inode->i_nlink))
38913 + /* inode may not be revalidated */
38914 + bi = au_br_index(sb, hi->hi_id);
38918 + br = au_sbr(sb, bi);
38919 + au_xi_calc(sb, h_inode->i_ino, &calc);
38920 + file = au_xino_file(br->br_xino, calc.idx);
38921 + if (IS_ERR_OR_NULL(file))
38924 + err = au_xino_do_write(file, &calc, /*ino*/0);
38925 + if (!err && try_trunc
38926 + && au_test_fs_trunc_xino(au_br_sb(br)))
38927 + xino_try_trunc(sb, br);
38931 +/* ---------------------------------------------------------------------- */
38933 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38935 + int found, total, i;
38938 + total = xi->xi_nondir.total;
38939 + for (i = 0; i < total; i++) {
38940 + if (xi->xi_nondir.array[i] != h_ino)
38949 +static int au_xinondir_expand(struct au_xino *xi)
38954 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38957 + sz = xi->xi_nondir.total * sizeof(ino_t);
38958 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38960 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38961 + /*may_shrink*/0);
38963 + xi->xi_nondir.array = p;
38964 + xi->xi_nondir.total <<= 1;
38965 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38973 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38974 + ino_t h_ino, int idx)
38976 + struct au_xino *xi;
38978 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38979 + xi = au_sbr(sb, bindex)->br_xino;
38980 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38982 + spin_lock(&xi->xi_nondir.spin);
38983 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38984 + xi->xi_nondir.array[idx] = 0;
38985 + spin_unlock(&xi->xi_nondir.spin);
38986 + wake_up_all(&xi->xi_nondir.wqh);
38989 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38992 + int err, found, empty;
38993 + struct au_xino *xi;
38997 + if (!au_opt_test(au_mntflags(sb), XINO))
38998 + goto out; /* no xino */
39000 + xi = au_sbr(sb, bindex)->br_xino;
39003 + spin_lock(&xi->xi_nondir.spin);
39004 + found = au_xinondir_find(xi, h_ino);
39005 + if (found == -1) {
39006 + empty = au_xinondir_find(xi, /*h_ino*/0);
39007 + if (empty == -1) {
39008 + empty = xi->xi_nondir.total;
39009 + err = au_xinondir_expand(xi);
39010 + if (unlikely(err))
39013 + xi->xi_nondir.array[empty] = h_ino;
39016 + spin_unlock(&xi->xi_nondir.spin);
39017 + wait_event(xi->xi_nondir.wqh,
39018 + xi->xi_nondir.array[found] != h_ino);
39023 + spin_unlock(&xi->xi_nondir.spin);
39028 +/* ---------------------------------------------------------------------- */
39030 +int au_xino_path(struct seq_file *seq, struct file *file)
39034 + err = au_seq_path(seq, &file->f_path);
39035 + if (unlikely(err))
39038 +#define Deleted "\\040(deleted)"
39039 + seq->count -= sizeof(Deleted) - 1;
39040 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39041 + sizeof(Deleted) - 1));
39047 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39048 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39049 +++ linux/include/uapi/linux/aufs_type.h 2023-10-31 09:31:04.203214083 +0100
39051 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39053 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39055 + * This program is free software; you can redistribute it and/or modify
39056 + * it under the terms of the GNU General Public License as published by
39057 + * the Free Software Foundation; either version 2 of the License, or
39058 + * (at your option) any later version.
39060 + * This program is distributed in the hope that it will be useful,
39061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39063 + * GNU General Public License for more details.
39065 + * You should have received a copy of the GNU General Public License
39066 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39069 +#ifndef __AUFS_TYPE_H__
39070 +#define __AUFS_TYPE_H__
39072 +#define AUFS_NAME "aufs"
39076 + * define it before including all other headers.
39077 + * sched.h may use pr_* macros before defining "current", so define the
39078 + * no-current version first, and re-define later.
39080 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39081 +#include <linux/sched.h>
39083 +#define pr_fmt(fmt) \
39084 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39085 + (int)sizeof(current->comm), current->comm, current->pid
39086 +#include <linux/limits.h>
39088 +#include <stdint.h>
39089 +#include <sys/types.h>
39090 +#include <limits.h>
39091 +#endif /* __KERNEL__ */
39093 +#define AUFS_VERSION "6.x-rcN-20230925"
39095 +/* todo? move this to linux-2.6.19/include/magic.h */
39096 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39098 +/* ---------------------------------------------------------------------- */
39101 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39102 +typedef int8_t aufs_bindex_t;
39103 +#define AUFS_BRANCH_MAX 127
39105 +typedef int16_t aufs_bindex_t;
39106 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39107 +#define AUFS_BRANCH_MAX 511
39108 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39109 +#define AUFS_BRANCH_MAX 1023
39110 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39111 +#define AUFS_BRANCH_MAX 32767
39115 +#ifndef AUFS_BRANCH_MAX
39116 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39118 +#endif /* __KERNEL__ */
39120 +/* ---------------------------------------------------------------------- */
39122 +#define AUFS_FSTYPE AUFS_NAME
39124 +#define AUFS_ROOT_INO 2
39125 +#define AUFS_FIRST_INO 11
39127 +#define AUFS_WH_PFX ".wh."
39128 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39129 +#define AUFS_WH_TMP_LEN 4
39130 +/* a limit for rmdir/rename a dir and copyup */
39131 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39132 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39134 + - AUFS_WH_TMP_LEN) /* hex */
39135 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39136 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39137 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39138 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39139 +#define AUFS_DIRWH_DEF 3
39140 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39141 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39142 +#define AUFS_RDBLK_DEF 512 /* bytes */
39143 +#define AUFS_RDHASH_DEF 32
39144 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39145 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39146 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39147 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39148 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39150 +/* pseudo-link maintenace under /proc */
39151 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39152 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39153 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39155 +/* dirren, renamed dir */
39156 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39157 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39158 +/* whiteouted doubly */
39159 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39160 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39162 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39163 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39165 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39166 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39167 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39169 +/* doubly whiteouted */
39170 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39171 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39172 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39174 +/* branch permissions and attributes */
39175 +#define AUFS_BRPERM_RW "rw"
39176 +#define AUFS_BRPERM_RO "ro"
39177 +#define AUFS_BRPERM_RR "rr"
39178 +#define AUFS_BRATTR_COO_REG "coo_reg"
39179 +#define AUFS_BRATTR_COO_ALL "coo_all"
39180 +#define AUFS_BRATTR_FHSM "fhsm"
39181 +#define AUFS_BRATTR_UNPIN "unpin"
39182 +#define AUFS_BRATTR_ICEX "icex"
39183 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39184 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39185 +#define AUFS_BRATTR_ICEX_TR "icextr"
39186 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39187 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39188 +#define AUFS_BRRATTR_WH "wh"
39189 +#define AUFS_BRWATTR_NLWH "nolwh"
39190 +#define AUFS_BRWATTR_MOO "moo"
39192 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39193 +#define AuBrPerm_RO (1 << 1) /* readonly */
39194 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39195 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39197 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39198 +#define AuBrAttr_COO_ALL (1 << 4)
39199 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39201 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39202 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39203 + branch. meaningless since
39204 + linux-3.18-rc1 */
39206 +/* ignore error in copying XATTR */
39207 +#define AuBrAttr_ICEX_SEC (1 << 7)
39208 +#define AuBrAttr_ICEX_SYS (1 << 8)
39209 +#define AuBrAttr_ICEX_TR (1 << 9)
39210 +#define AuBrAttr_ICEX_USR (1 << 10)
39211 +#define AuBrAttr_ICEX_OTH (1 << 11)
39212 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39213 + | AuBrAttr_ICEX_SYS \
39214 + | AuBrAttr_ICEX_TR \
39215 + | AuBrAttr_ICEX_USR \
39216 + | AuBrAttr_ICEX_OTH)
39218 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39219 +#define AuBrRAttr_Mask AuBrRAttr_WH
39221 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39222 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39223 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39225 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39227 +/* #warning test userspace */
39229 +#ifndef CONFIG_AUFS_FHSM
39230 +#undef AuBrAttr_FHSM
39231 +#define AuBrAttr_FHSM 0
39233 +#ifndef CONFIG_AUFS_XATTR
39234 +#undef AuBrAttr_ICEX
39235 +#define AuBrAttr_ICEX 0
39236 +#undef AuBrAttr_ICEX_SEC
39237 +#define AuBrAttr_ICEX_SEC 0
39238 +#undef AuBrAttr_ICEX_SYS
39239 +#define AuBrAttr_ICEX_SYS 0
39240 +#undef AuBrAttr_ICEX_TR
39241 +#define AuBrAttr_ICEX_TR 0
39242 +#undef AuBrAttr_ICEX_USR
39243 +#define AuBrAttr_ICEX_USR 0
39244 +#undef AuBrAttr_ICEX_OTH
39245 +#define AuBrAttr_ICEX_OTH 0
39249 +/* the longest combination */
39250 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39251 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39252 + "+" AUFS_BRATTR_COO_REG \
39253 + "+" AUFS_BRATTR_FHSM \
39254 + "+" AUFS_BRATTR_UNPIN \
39255 + "+" AUFS_BRATTR_ICEX_SEC \
39256 + "+" AUFS_BRATTR_ICEX_SYS \
39257 + "+" AUFS_BRATTR_ICEX_USR \
39258 + "+" AUFS_BRATTR_ICEX_OTH \
39259 + "+" AUFS_BRWATTR_NLWH)
39262 + char a[AuBrPermStrSz];
39263 +} au_br_perm_str_t;
39265 +static inline int au_br_writable(int brperm)
39267 + return brperm & AuBrPerm_RW;
39270 +static inline int au_br_whable(int brperm)
39272 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39275 +static inline int au_br_wh_linkable(int brperm)
39277 + return !(brperm & AuBrWAttr_NoLinkWH);
39280 +static inline int au_br_cmoo(int brperm)
39282 + return brperm & AuBrAttr_CMOO_Mask;
39285 +static inline int au_br_fhsm(int brperm)
39287 + return brperm & AuBrAttr_FHSM;
39290 +/* ---------------------------------------------------------------------- */
39294 + /* readdir in userspace */
39298 + AuCtl_WBR_FD, /* pathconf wrapper */
39299 + AuCtl_IBUSY, /* busy inode */
39300 + AuCtl_MVDOWN, /* move-down */
39301 + AuCtl_BR, /* info about branches */
39302 + AuCtl_FHSM_FD /* connection for fhsm */
39305 +/* borrowed from linux/include/linux/kernel.h */
39307 +#ifdef _GNU_SOURCE
39308 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39310 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39312 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39315 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39317 +#define __aligned(x) __attribute__((aligned(x)))
39322 +#define __packed __attribute__((packed))
39326 +struct au_rdu_cookie {
39331 + uint32_t generation;
39334 +struct au_rdu_ent {
39343 +static inline int au_rdu_len(int nlen)
39345 + /* include the terminating NULL */
39346 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39347 + sizeof(uint64_t));
39350 +union au_rdu_ent_ul {
39351 + struct au_rdu_ent __user *e;
39363 + uint64_t sz; /* AuCtl_RDU */
39364 + uint64_t nent; /* AuCtl_RDU_INO */
39366 + union au_rdu_ent_ul ent;
39367 + uint16_t verify[AufsCtlRduV_End];
39369 + /* input/output */
39373 + union au_rdu_ent_ul tail;
39374 + /* number of entries which were added in a single call */
39379 + struct au_rdu_cookie cookie;
39382 +/* ---------------------------------------------------------------------- */
39384 +/* dirren. the branch is identified by the filename who contains this */
39385 +struct au_drinfo {
39388 + uint8_t oldnamelen;
39389 + uint64_t _padding;
39391 + uint8_t oldname[];
39394 +struct au_drinfo_fdata {
39396 + struct au_drinfo drinfo;
39399 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39401 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39403 +/* ---------------------------------------------------------------------- */
39405 +struct aufs_wbr_fd {
39410 +/* ---------------------------------------------------------------------- */
39412 +struct aufs_ibusy {
39413 + uint64_t ino, h_ino;
39417 +/* ---------------------------------------------------------------------- */
39419 +/* error code for move-down */
39420 +/* the actual message strings are implemented in aufs-util.git */
39422 + EAU_MVDOWN_OPAQUE = 1,
39423 + EAU_MVDOWN_WHITEOUT,
39424 + EAU_MVDOWN_UPPER,
39425 + EAU_MVDOWN_BOTTOM,
39426 + EAU_MVDOWN_NOUPPER,
39427 + EAU_MVDOWN_NOLOWERBR,
39431 +/* flags for move-down */
39432 +#define AUFS_MVDOWN_DMSG 1
39433 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39434 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39435 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39436 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39437 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39438 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39439 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39440 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39441 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39442 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39443 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39444 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39446 +/* index for move-down */
39448 + AUFS_MVDOWN_UPPER,
39449 + AUFS_MVDOWN_LOWER,
39450 + AUFS_MVDOWN_NARRAY
39454 + * additional info of move-down
39455 + * number of free blocks and inodes.
39456 + * subset of struct kstatfs, but smaller and always 64bit.
39458 +struct aufs_stfs {
39459 + uint64_t f_blocks;
39460 + uint64_t f_bavail;
39461 + uint64_t f_files;
39462 + uint64_t f_ffree;
39465 +struct aufs_stbr {
39466 + int16_t brid; /* optional input */
39467 + int16_t bindex; /* output */
39468 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39471 +struct aufs_mvdown {
39472 + uint32_t flags; /* input/output */
39473 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39474 + int8_t au_errno; /* output */
39477 +/* ---------------------------------------------------------------------- */
39479 +union aufs_brinfo {
39480 + /* PATH_MAX may differ between kernel-space and user-space */
39481 + char _spacer[4096];
39489 +/* ---------------------------------------------------------------------- */
39491 +#define AuCtlType 'A'
39492 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39493 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39494 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39495 + struct aufs_wbr_fd)
39496 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39497 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39498 + struct aufs_mvdown)
39499 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39500 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39502 +#endif /* __AUFS_TYPE_H__ */
39503 SPDX-License-Identifier: GPL-2.0
39504 aufs6.x-rcN loopback patch
39506 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39507 index 1fefc6a8d049..86f1f66305d2 100644
39508 --- a/drivers/block/loop.c
39509 +++ b/drivers/block/loop.c
39510 @@ -54,7 +54,7 @@ struct loop_device {
39512 char lo_file_name[LO_NAME_SIZE];
39514 - struct file * lo_backing_file;
39515 + struct file *lo_backing_file, *lo_backing_virt_file;
39516 struct block_device *lo_device;
39518 gfp_t old_gfp_mask;
39519 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39523 +static struct file *loop_real_file(struct file *file)
39525 + struct file *f = NULL;
39527 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39528 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39532 static void loop_reread_partitions(struct loop_device *lo)
39535 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39537 struct file *file = fget(arg);
39538 struct file *old_file;
39539 + struct file *f, *virt_file = NULL, *old_virt_file;
39543 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39544 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39547 + f = loop_real_file(file);
39549 + virt_file = file;
39554 error = loop_validate_file(file, bdev);
39558 old_file = lo->lo_backing_file;
39559 + old_virt_file = lo->lo_backing_virt_file;
39563 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39564 blk_mq_freeze_queue(lo->lo_queue);
39565 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39566 lo->lo_backing_file = file;
39567 + lo->lo_backing_virt_file = virt_file;
39568 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39569 mapping_set_gfp_mask(file->f_mapping,
39570 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39571 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39575 + if (old_virt_file)
39576 + fput(old_virt_file);
39578 loop_reread_partitions(lo);
39580 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39581 loop_global_unlock(lo, is_loop);
39589 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39590 const struct loop_config *config)
39592 struct file *file = fget(config->fd);
39593 + struct file *f, *virt_file = NULL;
39594 struct inode *inode;
39595 struct address_space *mapping;
39597 @@ -1028,6 +1052,13 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39598 /* This is safe, since we have a reference from open(). */
39599 __module_get(THIS_MODULE);
39601 + f = loop_real_file(file);
39603 + virt_file = file;
39609 * If we don't hold exclusive handle for the device, upgrade to it
39610 * here to avoid changing device under exclusive owner.
39611 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39612 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39613 lo->lo_device = bdev;
39614 lo->lo_backing_file = file;
39615 + lo->lo_backing_virt_file = virt_file;
39616 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39617 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39619 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39620 bd_abort_claiming(bdev, loop_configure);
39625 /* This is safe: open() is still holding a reference. */
39626 module_put(THIS_MODULE);
39628 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
39629 static void __loop_clr_fd(struct loop_device *lo, bool release)
39632 + struct file *virt_filp = lo->lo_backing_virt_file;
39633 gfp_t gfp = lo->old_gfp_mask;
39635 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39636 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39637 spin_lock_irq(&lo->lo_lock);
39638 filp = lo->lo_backing_file;
39639 lo->lo_backing_file = NULL;
39640 + lo->lo_backing_virt_file = NULL;
39641 spin_unlock_irq(&lo->lo_lock);
39643 lo->lo_device = NULL;
39644 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39645 * fput can take open_mutex which is usually taken before lo_mutex.
39652 static int loop_clr_fd(struct loop_device *lo)
39653 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39654 index fa8a517ffd0c..c18f7bcef81b 100644
39655 --- a/fs/aufs/f_op.c
39656 +++ b/fs/aufs/f_op.c
39657 @@ -311,7 +311,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39658 if (IS_ERR(h_file))
39661 - if (au_test_loopback_kthread()) {
39662 + if (0 && au_test_loopback_kthread()) {
39663 au_warn_loopback(h_file->f_path.dentry->d_sb);
39664 if (file->f_mapping != h_file->f_mapping) {
39665 file->f_mapping = h_file->f_mapping;
39666 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39667 index 58043e31e5f3..e2bfae6f9d59 100644
39668 --- a/fs/aufs/loop.c
39669 +++ b/fs/aufs/loop.c
39670 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39671 symbol_put(loop_backing_file);
39672 au_kfree_try_rcu(au_warn_loopback_array);
39675 +/* ---------------------------------------------------------------------- */
39677 +/* support the loopback block device insude aufs */
39679 +struct file *aufs_real_loop(struct file *file)
39683 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39684 + fi_read_lock(file);
39685 + f = au_hf_top(file);
39686 + fi_read_unlock(file);
39690 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39691 index 03d4908a6c03..34d356e181d5 100644
39692 --- a/fs/aufs/loop.h
39693 +++ b/fs/aufs/loop.h
39694 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39696 int au_loopback_init(void);
39697 void au_loopback_fin(void);
39699 +struct file *aufs_real_loop(struct file *file);
39701 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39703 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39705 AuStubInt0(au_loopback_init, void)
39706 AuStubVoid(au_loopback_fin, void)
39708 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39709 #endif /* BLK_DEV_LOOP */
39711 #endif /* __KERNEL__ */
39712 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39713 index 07d3412e950f..c4a00f620e57 100644
39714 --- a/fs/aufs/super.c
39715 +++ b/fs/aufs/super.c
39716 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39717 .show_options = aufs_show_options,
39718 .statfs = aufs_statfs,
39719 .put_super = aufs_put_super,
39720 - .sync_fs = aufs_sync_fs
39721 + .sync_fs = aufs_sync_fs,
39722 +#ifdef CONFIG_AUFS_BDEV_LOOP
39723 + .real_loop = aufs_real_loop
39727 /* ---------------------------------------------------------------------- */
39728 diff --git a/include/linux/fs.h b/include/linux/fs.h
39729 index dd5871d0c429..748091221f2d 100644
39730 --- a/include/linux/fs.h
39731 +++ b/include/linux/fs.h
39732 @@ -2056,6 +2056,11 @@ struct super_operations {
39733 long (*free_cached_objects)(struct super_block *,
39734 struct shrink_control *);
39735 void (*shutdown)(struct super_block *sb);
39737 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39739 + struct file *(*real_loop)(struct file *);