1 SPDX-License-Identifier: GPL-2.0
2 aufs6.x-rcN kbuild patch
4 diff --git a/fs/Kconfig b/fs/Kconfig
5 index cc07a0cd3172..5ee4f1be48ff 100644
8 @@ -316,6 +316,7 @@ source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/erofs/Kconfig"
11 source "fs/vboxsf/Kconfig"
12 +source "fs/aufs/Kconfig"
14 endif # MISC_FILESYSTEMS
16 diff --git a/fs/Makefile b/fs/Makefile
17 index 834f1c3dba46..b5c97dd026cd 100644
20 @@ -137,3 +137,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 e0ad886d3163..a27659e1886b 100644
32 @@ -3380,6 +3380,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 bc31bb7072a2..131294601819 100644
54 --- a/drivers/block/loop.c
55 +++ b/drivers/block/loop.c
56 @@ -645,6 +645,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
62 + * no get/put for file.
64 +struct file *loop_backing_file(struct super_block *sb)
67 + struct loop_device *l;
70 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
71 + l = sb->s_bdev->bd_disk->private_data;
72 + ret = l->lo_backing_file;
76 +EXPORT_SYMBOL_GPL(loop_backing_file);
78 /* loop sysfs attributes */
80 static ssize_t loop_attr_show(struct device *dev, char *page,
81 diff --git a/fs/dcache.c b/fs/dcache.c
82 index 52e6d5fdab6b..519321f32f95 100644
85 @@ -1345,7 +1345,7 @@ enum d_walk_ret {
87 * The @enter() callbacks are called with d_lock held.
89 -static void d_walk(struct dentry *parent, void *data,
90 +void d_walk(struct dentry *parent, void *data,
91 enum d_walk_ret (*enter)(void *, struct dentry *))
93 struct dentry *this_parent;
94 diff --git a/fs/fcntl.c b/fs/fcntl.c
95 index b622be119706..9ea58b7bb580 100644
100 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
102 -static int setfl(int fd, struct file * filp, unsigned long arg)
103 +int setfl(int fd, struct file *filp, unsigned long arg)
105 struct inode * inode = file_inode(filp);
107 @@ -64,6 +64,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
109 if (filp->f_op->check_flags)
110 error = filp->f_op->check_flags(arg);
111 + if (!error && filp->f_op->setfl)
112 + error = filp->f_op->setfl(filp, arg);
116 diff --git a/fs/namespace.c b/fs/namespace.c
117 index 54847db5b819..ebb7b4b057ea 100644
120 @@ -849,6 +849,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 3e06611d19ae..97a66df75d4c 100644
137 @@ -865,8 +865,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 21a981680856..1e3054e5367d 100644
150 --- a/include/linux/fs.h
151 +++ b/include/linux/fs.h
152 @@ -1066,6 +1066,7 @@ extern void fasync_free(struct fasync_struct *);
153 /* can be called from interrupts */
154 extern void kill_fasync(struct fasync_struct **, int, int);
156 +extern int setfl(int fd, struct file *filp, unsigned long arg);
157 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
158 extern int f_setown(struct file *filp, unsigned long arg, int force);
159 extern void f_delown(struct file *filp);
160 @@ -1793,6 +1794,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 b32256e9e944..16bd7230f44b 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 a55179fd60fc..8e21c53cf883 100644
203 --- a/include/linux/splice.h
204 +++ b/include/linux/splice.h
205 @@ -93,4 +93,7 @@ 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);
213 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
214 index dcd1d5bfc1e0..85d1f7e0bc07 100644
215 --- a/kernel/locking/lockdep.c
216 +++ b/kernel/locking/lockdep.c
217 @@ -218,7 +218,7 @@ unsigned long max_lock_class_idx;
218 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
219 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
221 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
222 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
224 unsigned int class_idx = hlock->class_idx;
226 @@ -239,6 +239,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
228 return lock_classes + class_idx;
230 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
232 #ifdef CONFIG_LOCK_STAT
233 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
234 SPDX-License-Identifier: GPL-2.0
235 aufs6.x-rcN mmap patch
237 diff --git a/fs/proc/base.c b/fs/proc/base.c
238 index 05452c3b9872..6b92a8430130 100644
241 @@ -2218,7 +2218,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
243 vma = find_exact_vma(mm, vm_start, vm_end);
244 if (vma && vma->vm_file) {
245 - *path = vma->vm_file->f_path;
246 + *path = vma_pr_or_file(vma)->f_path;
250 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
251 index 4d3493579458..42edd9a42c78 100644
252 --- a/fs/proc/nommu.c
253 +++ b/fs/proc/nommu.c
254 @@ -39,7 +39,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
255 file = region->vm_file;
258 - struct inode *inode = file_inode(region->vm_file);
259 + struct inode *inode;
261 + file = vmr_pr_or_file(region);
262 + inode = file_inode(file);
263 dev = inode->i_sb->s_dev;
266 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
267 index 420510f6a545..edfc0941806a 100644
268 --- a/fs/proc/task_mmu.c
269 +++ b/fs/proc/task_mmu.c
270 @@ -285,7 +285,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
271 const char *name = NULL;
274 - struct inode *inode = file_inode(vma->vm_file);
275 + struct inode *inode;
277 + file = vma_pr_or_file(vma);
278 + inode = file_inode(file);
279 dev = inode->i_sb->s_dev;
281 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
282 @@ -1943,7 +1946,7 @@ static int show_numa_map(struct seq_file *m, void *v)
283 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
284 struct vm_area_struct *vma = v;
285 struct numa_maps *md = &numa_priv->md;
286 - struct file *file = vma->vm_file;
287 + struct file *file = vma_pr_or_file(vma);
288 struct mm_struct *mm = vma->vm_mm;
289 struct mempolicy *pol;
291 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
292 index 0ec35072a8e5..f0f0a03eb2b5 100644
293 --- a/fs/proc/task_nommu.c
294 +++ b/fs/proc/task_nommu.c
295 @@ -150,7 +150,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
299 - struct inode *inode = file_inode(vma->vm_file);
300 + struct inode *inode;
302 + file = vma_pr_or_file(vma);
303 + inode = file_inode(file);
304 dev = inode->i_sb->s_dev;
306 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
307 diff --git a/include/linux/mm.h b/include/linux/mm.h
308 index 27ce77080c79..5f07b972242d 100644
309 --- a/include/linux/mm.h
310 +++ b/include/linux/mm.h
311 @@ -2353,6 +2353,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
312 unmap_mapping_range(mapping, holebegin, holelen, 0);
315 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
316 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
317 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
319 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
320 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
322 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
324 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
326 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
327 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
330 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
331 +extern void vmr_do_fput(struct vm_region *, const char[], int);
333 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
335 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
336 +#endif /* !CONFIG_MMU */
340 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
341 +#define vma_pr_or_file(vma) (vma)->vm_file
342 +#define vma_get_file(vma) get_file((vma)->vm_file)
343 +#define vma_fput(vma) fput((vma)->vm_file)
346 +#define vmr_pr_or_file(region) (region)->vm_file
347 +#define vmr_fput(region) fput((region)->vm_file)
348 +#endif /* !CONFIG_MMU */
350 +#endif /* CONFIG_AUFS_FS */
352 static inline struct vm_area_struct *vma_lookup(struct mm_struct *mm,
355 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
356 index 306a3d1a0fa6..56374f0eb825 100644
357 --- a/include/linux/mm_types.h
358 +++ b/include/linux/mm_types.h
359 @@ -449,6 +449,9 @@ struct vm_region {
360 unsigned long vm_top; /* region allocated to here */
361 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
362 struct file *vm_file; /* the backing file or NULL */
363 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
364 + struct file *vm_prfile; /* the virtual backing file or NULL */
367 int vm_usage; /* region usage count (access under nommu_region_sem) */
368 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
369 @@ -548,6 +551,9 @@ struct vm_area_struct {
370 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
372 struct file * vm_file; /* File we map to (can be NULL). */
373 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
374 + struct file *vm_prfile; /* shadow of vm_file */
376 void * vm_private_data; /* was vm_pte (shared mem) */
378 #ifdef CONFIG_ANON_VMA_NAME
379 diff --git a/kernel/fork.c b/kernel/fork.c
380 index ed4e01daccaa..e945a1639283 100644
383 @@ -733,7 +733,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
385 struct address_space *mapping = file->f_mapping;
389 i_mmap_lock_write(mapping);
390 if (tmp->vm_flags & VM_SHARED)
391 mapping_allow_writable(mapping);
392 diff --git a/mm/Makefile b/mm/Makefile
393 index e29afc890cde..c467601299d4 100644
396 @@ -137,3 +137,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
397 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
398 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
399 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
401 diff --git a/mm/filemap.c b/mm/filemap.c
402 index b4c9bd368b7e..ec4f4e5c1a92 100644
405 @@ -3564,7 +3564,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
406 vm_fault_t ret = VM_FAULT_LOCKED;
408 sb_start_pagefault(mapping->host->i_sb);
409 - file_update_time(vmf->vma->vm_file);
410 + vma_file_update_time(vmf->vma);
412 if (folio->mapping != mapping) {
414 diff --git a/mm/mmap.c b/mm/mmap.c
415 index 13678edaa22c..3b5dd8a8d627 100644
418 @@ -140,7 +140,7 @@ static void remove_vma(struct vm_area_struct *vma, bool unreachable)
419 if (vma->vm_ops && vma->vm_ops->close)
420 vma->vm_ops->close(vma);
422 - fput(vma->vm_file);
424 mpol_put(vma_policy(vma));
427 @@ -607,7 +607,7 @@ static inline void vma_complete(struct vma_prepare *vp,
429 uprobe_munmap(vp->remove, vp->remove->vm_start,
434 if (vp->remove->anon_vma)
435 anon_vma_merge(vp->vma, vp->remove);
436 @@ -2269,7 +2269,7 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
440 - get_file(new->vm_file);
443 if (new->vm_ops && new->vm_ops->open)
444 new->vm_ops->open(new);
445 @@ -2679,7 +2679,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
446 * and cause general protection fault
449 - fput(vma->vm_file);
453 /* Update vm_flags to pick up the change. */
454 @@ -2774,7 +2774,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
456 if (file || vma->vm_file) {
458 - fput(vma->vm_file);
462 /* Undo any partial mapping done by a device driver. */
463 @@ -2843,6 +2843,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
464 unsigned long populate = 0;
465 unsigned long ret = -EINVAL;
467 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
468 + struct file *prfile;
471 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
472 current->comm, current->pid);
473 @@ -2901,10 +2904,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
474 if (vma->vm_flags & VM_LOCKED)
477 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
479 + file = vma->vm_file;
480 + prfile = vma->vm_prfile;
481 + ret = do_mmap(vma->vm_file, start, size,
482 + prot, flags, pgoff, &populate, NULL);
483 + if (!IS_ERR_VALUE(ret) && file && prfile) {
484 + struct vm_area_struct *new_vma;
486 + new_vma = find_vma(mm, ret);
487 + if (!new_vma->vm_prfile)
488 + new_vma->vm_prfile = prfile;
493 + * two fput()s instead of vma_fput(vma),
494 + * coz vma may not be available anymore.
500 file = get_file(vma->vm_file);
501 ret = do_mmap(vma->vm_file, start, size,
502 prot, flags, pgoff, &populate, NULL);
504 +#endif /* CONFIG_AUFS_FS */
506 mmap_write_unlock(mm);
508 @@ -3250,7 +3277,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
509 if (anon_vma_clone(new_vma, vma))
510 goto out_free_mempol;
511 if (new_vma->vm_file)
512 - get_file(new_vma->vm_file);
513 + vma_get_file(new_vma);
514 if (new_vma->vm_ops && new_vma->vm_ops->open)
515 new_vma->vm_ops->open(new_vma);
516 vma_start_write(new_vma);
517 @@ -3266,7 +3293,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
518 new_vma->vm_ops->close(new_vma);
520 if (new_vma->vm_file)
521 - fput(new_vma->vm_file);
524 unlink_anon_vmas(new_vma);
526 diff --git a/mm/nommu.c b/mm/nommu.c
527 index f670d9979a26..94d41bc45915 100644
530 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
531 up_write(&nommu_region_sem);
534 - fput(region->vm_file);
537 /* IO memory and memory shared directly out of the pagecache
538 * from ramfs/tmpfs mustn't be released here */
539 @@ -602,7 +602,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
540 if (vma->vm_ops && vma->vm_ops->close)
541 vma->vm_ops->close(vma);
543 - fput(vma->vm_file);
545 put_nommu_region(vma->vm_region);
548 @@ -1124,7 +1124,7 @@ unsigned long do_mmap(struct file *file,
549 goto error_just_free;
552 - fput(region->vm_file);
554 kmem_cache_free(vm_region_jar, region);
557 @@ -1206,10 +1206,10 @@ unsigned long do_mmap(struct file *file,
561 - fput(region->vm_file);
563 kmem_cache_free(vm_region_jar, region);
565 - fput(vma->vm_file);
570 diff --git a/mm/prfile.c b/mm/prfile.c
572 index 000000000000..8f820a235364
576 +// SPDX-License-Identifier: GPL-2.0
578 + * Mainly for aufs which mmap(2) different file and wants to print different
579 + * path in /proc/PID/maps.
580 + * Call these functions via macros defined in linux/mm.h.
582 + * See Documentation/filesystems/aufs/design/06mmap.txt
584 + * Copyright (c) 2014-2022 Junjro R. Okajima
585 + * Copyright (c) 2014 Ian Campbell
588 +#include <linux/mm.h>
589 +#include <linux/file.h>
590 +#include <linux/fs.h>
592 +/* #define PRFILE_TRACE */
593 +static inline void prfile_trace(struct file *f, struct file *pr,
594 + const char func[], int line, const char func2[])
598 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
602 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
605 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
607 + prfile_trace(f, pr, func, line, __func__);
608 + file_update_time(f);
610 + file_update_time(pr);
613 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
616 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
618 + prfile_trace(f, pr, func, line, __func__);
619 + return (f && pr) ? pr : f;
622 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
624 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
626 + prfile_trace(f, pr, func, line, __func__);
632 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
634 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
636 + prfile_trace(f, pr, func, line, __func__);
643 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
646 + struct file *f = region->vm_file, *pr = region->vm_prfile;
648 + prfile_trace(f, pr, func, line, __func__);
649 + return (f && pr) ? pr : f;
652 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
654 + struct file *f = region->vm_file, *pr = region->vm_prfile;
656 + prfile_trace(f, pr, func, line, __func__);
661 +#endif /* !CONFIG_MMU */
662 SPDX-License-Identifier: GPL-2.0
663 aufs6.x-rcN standalone patch
665 diff --git a/fs/dcache.c b/fs/dcache.c
666 index 519321f32f95..267e0c65914a 100644
669 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
673 +EXPORT_SYMBOL_GPL(d_walk);
676 struct vfsmount *mnt;
677 @@ -3052,6 +3053,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
679 write_sequnlock(&rename_lock);
681 +EXPORT_SYMBOL_GPL(d_exchange);
684 * d_ancestor - search for an ancestor
685 diff --git a/fs/exec.c b/fs/exec.c
686 index a466e797c8e2..c60353b5214f 100644
689 @@ -112,6 +112,7 @@ bool path_noexec(const struct path *path)
690 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
691 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
693 +EXPORT_SYMBOL_GPL(path_noexec);
697 diff --git a/fs/fcntl.c b/fs/fcntl.c
698 index 9ea58b7bb580..99fef189bcd6 100644
701 @@ -87,6 +87,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
705 +EXPORT_SYMBOL_GPL(setfl);
707 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
709 diff --git a/fs/file_table.c b/fs/file_table.c
710 index 372653b92617..69128fe39b6d 100644
711 --- a/fs/file_table.c
712 +++ b/fs/file_table.c
713 @@ -199,6 +199,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
715 return ERR_PTR(-ENFILE);
717 +EXPORT_SYMBOL_GPL(alloc_empty_file);
720 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
721 diff --git a/fs/namespace.c b/fs/namespace.c
722 index ebb7b4b057ea..6ee47677de2f 100644
725 @@ -457,6 +457,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
726 mnt_dec_writers(real_mount(mnt));
729 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
732 * mnt_drop_write - give up write access to a mount
733 @@ -854,6 +855,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
735 return check_mnt(real_mount(mnt));
737 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
740 * vfsmount lock must be held for write
741 @@ -2062,6 +2064,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
745 +EXPORT_SYMBOL_GPL(iterate_mounts);
747 static void lock_mnt_tree(struct mount *mnt)
749 diff --git a/fs/notify/group.c b/fs/notify/group.c
750 index 1de6631a3925..3008eb37a18d 100644
751 --- a/fs/notify/group.c
752 +++ b/fs/notify/group.c
753 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
755 refcount_inc(&group->refcnt);
757 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
760 * Drop a reference to a group. Free it if it's through.
761 diff --git a/fs/open.c b/fs/open.c
762 index 4478adcc4f3a..5a984ff90580 100644
765 @@ -67,6 +67,7 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
766 inode_unlock(dentry->d_inode);
769 +EXPORT_SYMBOL_GPL(do_truncate);
771 long vfs_truncate(const struct path *path, loff_t length)
773 diff --git a/fs/read_write.c b/fs/read_write.c
774 index a21ba3be7dbe..ec40061176b3 100644
775 --- a/fs/read_write.c
776 +++ b/fs/read_write.c
777 @@ -477,6 +477,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
781 +EXPORT_SYMBOL_GPL(vfs_read);
783 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
785 @@ -592,6 +593,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
786 file_end_write(file);
789 +EXPORT_SYMBOL_GPL(vfs_write);
791 /* file_ppos returns &file->f_pos or NULL if file is stream */
792 static inline loff_t *file_ppos(struct file *file)
793 diff --git a/fs/splice.c b/fs/splice.c
794 index 97a66df75d4c..19c8d35f5ebd 100644
797 @@ -872,6 +872,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
798 return warn_unsupported(out, "write");
799 return out->f_op->splice_write(pipe, out, ppos, len, flags);
801 +EXPORT_SYMBOL_GPL(do_splice_from);
804 * Indicate to the caller that there was a premature EOF when reading from the
805 diff --git a/fs/xattr.c b/fs/xattr.c
806 index fcf67d80d7f9..174dfb9285fb 100644
809 @@ -406,6 +406,7 @@ vfs_getxattr_alloc(struct mnt_idmap *idmap, struct dentry *dentry,
810 *xattr_value = value;
813 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
816 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
817 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
818 index 85d1f7e0bc07..5e20504eed24 100644
819 --- a/kernel/locking/lockdep.c
820 +++ b/kernel/locking/lockdep.c
821 @@ -239,6 +239,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
823 return lock_classes + class_idx;
825 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
826 #define hlock_class(hlock) lockdep_hlock_class(hlock)
828 #ifdef CONFIG_LOCK_STAT
829 diff --git a/kernel/task_work.c b/kernel/task_work.c
830 index 065e1ef8fc8d..c623c6f0c645 100644
831 --- a/kernel/task_work.c
832 +++ b/kernel/task_work.c
833 @@ -182,3 +182,4 @@ void task_work_run(void)
837 +EXPORT_SYMBOL_GPL(task_work_run);
838 diff --git a/security/security.c b/security/security.c
839 index d5ff7ff45b77..5cca1f5774ef 100644
840 --- a/security/security.c
841 +++ b/security/security.c
842 @@ -1711,6 +1711,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
844 return call_int_hook(path_rmdir, 0, dir, dentry);
846 +EXPORT_SYMBOL_GPL(security_path_rmdir);
849 * security_path_unlink() - Check if removing a hard link is allowed
850 @@ -1746,6 +1747,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
852 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
854 +EXPORT_SYMBOL_GPL(security_path_symlink);
857 * security_path_link - Check if creating a hard link is allowed
858 @@ -1764,6 +1766,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
860 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
862 +EXPORT_SYMBOL_GPL(security_path_link);
865 * security_path_rename() - Check if renaming a file is allowed
866 @@ -1825,6 +1828,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
868 return call_int_hook(path_chmod, 0, path, mode);
870 +EXPORT_SYMBOL_GPL(security_path_chmod);
873 * security_path_chown() - Check if changing the file's owner/group is allowed
874 @@ -1842,6 +1846,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
876 return call_int_hook(path_chown, 0, path, uid, gid);
878 +EXPORT_SYMBOL_GPL(security_path_chown);
881 * security_path_chroot() - Check if changing the root directory is allowed
882 @@ -2071,6 +2076,7 @@ int security_inode_permission(struct inode *inode, int mask)
884 return call_int_hook(inode_permission, 0, inode, mask);
886 +EXPORT_SYMBOL_GPL(security_inode_permission);
889 * security_inode_setattr() - Check if setting file attributes is allowed
890 @@ -2549,6 +2555,7 @@ int security_file_permission(struct file *file, int mask)
892 return fsnotify_perm(file, mask);
894 +EXPORT_SYMBOL_GPL(security_file_permission);
897 * security_file_alloc() - Allocate and init a file's LSM blob
898 @@ -2815,6 +2822,7 @@ int security_file_truncate(struct file *file)
900 return call_int_hook(file_truncate, 0, file);
902 +EXPORT_SYMBOL_GPL(security_file_truncate);
905 * security_task_alloc() - Allocate a task's LSM blob
906 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
907 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
908 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-11-05 23:02:18.955889283 +0100
910 +What: /debug/aufs/si_<id>/
912 +Contact: J. R. Okajima <hooanon05g@gmail.com>
914 + Under /debug/aufs, a directory named si_<id> is created
915 + per aufs mount, where <id> is a unique id generated
918 +What: /debug/aufs/si_<id>/plink
920 +Contact: J. R. Okajima <hooanon05g@gmail.com>
922 + It has three lines and shows the information about the
923 + pseudo-link. The first line is a single number
924 + representing a number of buckets. The second line is a
925 + number of pseudo-links per buckets (separated by a
926 + blank). The last line is a single number representing a
927 + total number of psedo-links.
928 + When the aufs mount option 'noplink' is specified, it
929 + will show "1\n0\n0\n".
931 +What: /debug/aufs/si_<id>/xib
933 +Contact: J. R. Okajima <hooanon05g@gmail.com>
935 + It shows the consumed blocks by xib (External Inode Number
936 + Bitmap), its block size and file size.
937 + When the aufs mount option 'noxino' is specified, it
938 + will be empty. About XINO files, see the aufs manual.
940 +What: /debug/aufs/si_<id>/xi<branch-index>
942 +Contact: J. R. Okajima <hooanon05g@gmail.com>
944 + It shows the consumed blocks by xino (External Inode Number
945 + Translation Table), its link count, block size and file
947 + Due to the file size limit, there may exist multiple
948 + xino files per branch. In this case, "-N" is added to
949 + the filename and it corresponds to the index of the
950 + internal xino array. "-0" is omitted.
951 + When the aufs mount option 'noxino' is specified, Those
952 + entries won't exist. About XINO files, see the aufs
955 +What: /debug/aufs/si_<id>/xigen
957 +Contact: J. R. Okajima <hooanon05g@gmail.com>
959 + It shows the consumed blocks by xigen (External Inode
960 + Generation Table), its block size and file size.
961 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
963 + When the aufs mount option 'noxino' is specified, it
964 + will be empty. About XINO files, see the aufs manual.
965 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
966 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
967 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-11-05 23:02:18.955889283 +0100
969 +What: /sys/fs/aufs/si_<id>/
971 +Contact: J. R. Okajima <hooanon05g@gmail.com>
973 + Under /sys/fs/aufs, a directory named si_<id> is created
974 + per aufs mount, where <id> is a unique id generated
977 +What: /sys/fs/aufs/si_<id>/br<idx>
979 +Contact: J. R. Okajima <hooanon05g@gmail.com>
981 + It shows the abolute path of a member directory (which
982 + is called branch) in aufs, and its permission.
984 +What: /sys/fs/aufs/si_<id>/brid<idx>
986 +Contact: J. R. Okajima <hooanon05g@gmail.com>
988 + It shows the id of a member directory (which is called
991 +What: /sys/fs/aufs/si_<id>/xi_path
993 +Contact: J. R. Okajima <hooanon05g@gmail.com>
995 + It shows the abolute path of XINO (External Inode Number
996 + Bitmap, Translation Table and Generation Table) file
997 + even if it is the default path.
998 + When the aufs mount option 'noxino' is specified, it
999 + will be empty. About XINO files, see the aufs manual.
1000 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1001 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1002 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-11-05 23:02:18.955889283 +0100
1005 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1007 +# This program is free software; you can redistribute it and/or modify
1008 +# it under the terms of the GNU General Public License as published by
1009 +# the Free Software Foundation; either version 2 of the License, or
1010 +# (at your option) any later version.
1012 +# This program is distributed in the hope that it will be useful,
1013 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1014 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1015 +# GNU General Public License for more details.
1017 +# You should have received a copy of the GNU General Public License
1018 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1021 +----------------------------------------
1023 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1024 +1. abbrev. for "advanced multi-layered unification filesystem".
1025 +2. abbrev. for "another unionfs".
1026 +3. abbrev. for "auf das" in German which means "on the" in English.
1027 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1028 + But "Filesystem aufs Filesystem" is hard to understand.
1029 +4. abbrev. for "African Urban Fashion Show".
1031 +AUFS is a filesystem with features:
1032 +- multi layered stackable unification filesystem, the member directory
1033 + is called as a branch.
1034 +- branch permission and attribute, 'readonly', 'real-readonly',
1035 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1037 +- internal "file copy-on-write".
1038 +- logical deletion, whiteout.
1039 +- dynamic branch manipulation, adding, deleting and changing permission.
1040 +- allow bypassing aufs, user's direct branch access.
1041 +- external inode number translation table and bitmap which maintains the
1042 + persistent aufs inode number.
1043 +- seekable directory, including NFS readdir.
1044 +- file mapping, mmap and sharing pages.
1045 +- pseudo-link, hardlink over branches.
1046 +- loopback mounted filesystem as a branch.
1047 +- several policies to select one among multiple writable branches.
1048 +- revert a single systemcall when an error occurs in aufs.
1052 +Multi Layered Stackable Unification Filesystem
1053 +----------------------------------------------------------------------
1054 +Most people already knows what it is.
1055 +It is a filesystem which unifies several directories and provides a
1056 +merged single directory. When users access a file, the access will be
1057 +passed/re-directed/converted (sorry, I am not sure which English word is
1058 +correct) to the real file on the member filesystem. The member
1059 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1060 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1061 +readonly branch is handled by creating 'whiteout' on the upper writable
1064 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1065 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1066 +different approaches to implement the merged-view.
1067 +The former tries putting it into VFS, and the latter implements as a
1068 +separate filesystem.
1069 +(If I misunderstand about these implementations, please let me know and
1070 +I shall correct it. Because it is a long time ago when I read their
1071 +source files last time).
1073 +UnionMount's approach will be able to small, but may be hard to share
1074 +branches between several UnionMount since the whiteout in it is
1075 +implemented in the inode on branch filesystem and always
1076 +shared. According to Bharata's post, readdir does not seems to be
1078 +There are several missing features known in this implementations such as
1079 +- for users, the inode number may change silently. eg. copy-up.
1080 +- link(2) may break by copy-up.
1081 +- read(2) may get an obsoleted filedata (fstat(2) too).
1082 +- fcntl(F_SETLK) may be broken by copy-up.
1083 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1086 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1087 +merged into mainline. This is another implementation of UnionMount as a
1088 +separated filesystem. All the limitations and known problems which
1089 +UnionMount are equally inherited to "overlay" filesystem.
1091 +Unionfs has a longer history. When I started implementing a stackable
1092 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1093 +inode, dentry and file objects and they have an array pointing lower
1094 +same kind objects. After contributing many patches for Unionfs, I
1095 +re-started my project AUFS (Jun 2006).
1097 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1098 +implemented my own ideas, approaches and enhancements and it became
1099 +totally different one.
1101 +Comparing DM snapshot and fs based implementation
1102 +- the number of bytes to be copied between devices is much smaller.
1103 +- the type of filesystem must be one and only.
1104 +- the fs must be writable, no readonly fs, even for the lower original
1105 + device. so the compression fs will not be usable. but if we use
1106 + loopback mount, we may address this issue.
1108 + mount /cdrom/squashfs.img /sq
1109 + losetup /sq/ext2.img
1110 + losetup /somewhere/cow
1111 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1112 +- it will be difficult (or needs more operations) to extract the
1113 + difference between the original device and COW.
1114 +- DM snapshot-merge may help a lot when users try merging. in the
1115 + fs-layer union, users will use rsync(1).
1117 +You may want to read my old paper "Filesystems in LiveCD"
1118 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1121 +Several characters/aspects/persona of aufs
1122 +----------------------------------------------------------------------
1124 +Aufs has several characters, aspects or persona.
1125 +1. a filesystem, callee of VFS helper
1126 +2. sub-VFS, caller of VFS helper for branches
1127 +3. a virtual filesystem which maintains persistent inode number
1128 +4. reader/writer of files on branches such like an application
1130 +1. Callee of VFS Helper
1131 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1132 +unlink(2) from an application reaches sys_unlink() kernel function and
1133 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1134 +calls filesystem specific unlink operation. Actually aufs implements the
1135 +unlink operation but it behaves like a redirector.
1137 +2. Caller of VFS Helper for Branches
1138 +aufs_unlink() passes the unlink request to the branch filesystem as if
1139 +it were called from VFS. So the called unlink operation of the branch
1140 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1141 +every necessary pre/post operation for the branch filesystem.
1142 +- acquire the lock for the parent dir on a branch
1143 +- lookup in a branch
1144 +- revalidate dentry on a branch
1145 +- mnt_want_write() for a branch
1146 +- vfs_unlink() for a branch
1147 +- mnt_drop_write() for a branch
1148 +- release the lock on a branch
1150 +3. Persistent Inode Number
1151 +One of the most important issue for a filesystem is to maintain inode
1152 +numbers. This is particularly important to support exporting a
1153 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1154 +backend block device for its own. But some storage is necessary to
1155 +keep and maintain the inode numbers. It may be a large space and may not
1156 +suit to keep in memory. Aufs rents some space from its first writable
1157 +branch filesystem (by default) and creates file(s) on it. These files
1158 +are created by aufs internally and removed soon (currently) keeping
1160 +Note: Because these files are removed, they are totally gone after
1161 + unmounting aufs. It means the inode numbers are not persistent
1162 + across unmount or reboot. I have a plan to make them really
1163 + persistent which will be important for aufs on NFS server.
1165 +4. Read/Write Files Internally (copy-on-write)
1166 +Because a branch can be readonly, when you write a file on it, aufs will
1167 +"copy-up" it to the upper writable branch internally. And then write the
1168 +originally requested thing to the file. Generally kernel doesn't
1169 +open/read/write file actively. In aufs, even a single write may cause a
1170 +internal "file copy". This behaviour is very similar to cp(1) command.
1172 +Some people may think it is better to pass such work to user space
1173 +helper, instead of doing in kernel space. Actually I am still thinking
1174 +about it. But currently I have implemented it in kernel space.
1175 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1176 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1177 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-11-05 23:02:18.955889283 +0100
1180 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1182 +# This program is free software; you can redistribute it and/or modify
1183 +# it under the terms of the GNU General Public License as published by
1184 +# the Free Software Foundation; either version 2 of the License, or
1185 +# (at your option) any later version.
1187 +# This program is distributed in the hope that it will be useful,
1188 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1189 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1190 +# GNU General Public License for more details.
1192 +# You should have received a copy of the GNU General Public License
1193 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1195 +Basic Aufs Internal Structure
1197 +Superblock/Inode/Dentry/File Objects
1198 +----------------------------------------------------------------------
1199 +As like an ordinary filesystem, aufs has its own
1200 +superblock/inode/dentry/file objects. All these objects have a
1201 +dynamically allocated array and store the same kind of pointers to the
1202 +lower filesystem, branch.
1203 +For example, when you build a union with one readwrite branch and one
1204 +readonly, mounted /au, /rw and /ro respectively.
1206 +- /ro/fileA exists but /rw/fileA
1208 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1209 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1210 +- [0] = NULL (because /rw/fileA doesn't exist)
1213 +This style of an array is essentially same to the aufs
1214 +superblock/inode/dentry/file objects.
1216 +Because aufs supports manipulating branches, ie. add/delete/change
1217 +branches dynamically, these objects has its own generation. When
1218 +branches are changed, the generation in aufs superblock is
1219 +incremented. And a generation in other object are compared when it is
1220 +accessed. When a generation in other objects are obsoleted, aufs
1221 +refreshes the internal array.
1225 +----------------------------------------------------------------------
1226 +Additionally aufs superblock has some data for policies to select one
1227 +among multiple writable branches, XIB files, pseudo-links and kobject.
1228 +See below in detail.
1229 +About the policies which supports copy-down a directory, see
1230 +wbr_policy.txt too.
1233 +Branch and XINO(External Inode Number Translation Table)
1234 +----------------------------------------------------------------------
1235 +Every branch has its own xino (external inode number translation table)
1236 +file. The xino file is created and unlinked by aufs internally. When two
1237 +members of a union exist on the same filesystem, they share the single
1239 +The struct of a xino file is simple, just a sequence of aufs inode
1240 +numbers which is indexed by the lower inode number.
1241 +In the above sample, assume the inode number of /ro/fileA is i111 and
1242 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1243 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1245 +When the inode numbers are not contiguous, the xino file will be sparse
1246 +which has a hole in it and doesn't consume as much disk space as it
1247 +might appear. If your branch filesystem consumes disk space for such
1248 +holes, then you should specify 'xino=' option at mounting aufs.
1250 +Aufs has a mount option to free the disk blocks for such holes in XINO
1251 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1252 +meet a problem of disk shortage due to XINO files, then you should try
1253 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1254 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1255 +the holes in XINO files.
1257 +Also a writable branch has three kinds of "whiteout bases". All these
1258 +are existed when the branch is joined to aufs, and their names are
1259 +whiteout-ed doubly, so that users will never see their names in aufs
1261 +1. a regular file which will be hardlinked to all whiteouts.
1262 +2. a directory to store a pseudo-link.
1263 +3. a directory to store an "orphan"-ed file temporary.
1266 + When you remove a file on a readonly branch, aufs handles it as a
1267 + logical deletion and creates a whiteout on the upper writable branch
1268 + as a hardlink of this file in order not to consume inode on the
1271 + See below, Pseudo-link.
1273 + When "fileC" exists on the lower readonly branch only and it is
1274 + opened and removed with its parent dir, and then user writes
1275 + something into it, then aufs copies-up fileC to this
1276 + directory. Because there is no other dir to store fileC. After
1277 + creating a file under this dir, the file is unlinked.
1279 +Because aufs supports manipulating branches, ie. add/delete/change
1280 +dynamically, a branch has its own id. When the branch order changes,
1281 +aufs finds the new index by searching the branch id.
1285 +----------------------------------------------------------------------
1286 +Assume "fileA" exists on the lower readonly branch only and it is
1287 +hardlinked to "fileB" on the branch. When you write something to fileA,
1288 +aufs copies-up it to the upper writable branch. Additionally aufs
1289 +creates a hardlink under the Pseudo-link Directory of the writable
1290 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1291 +simple list. If fileB is read after unlinking fileA, aufs returns
1292 +filedata from the pseudo-link instead of the lower readonly
1293 +branch. Because the pseudo-link is based upon the inode, to keep the
1294 +inode number by xino (see above) is essentially necessary.
1296 +All the hardlinks under the Pseudo-link Directory of the writable branch
1297 +should be restored in a proper location later. Aufs provides a utility
1298 +to do this. The userspace helpers executed at remounting and unmounting
1300 +During this utility is running, it puts aufs into the pseudo-link
1301 +maintenance mode. In this mode, only the process which began the
1302 +maintenance mode (and its child processes) is allowed to operate in
1303 +aufs. Some other processes which are not related to the pseudo-link will
1304 +be allowed to run too, but the rest have to return an error or wait
1305 +until the maintenance mode ends. If a process already acquires an inode
1306 +mutex (in VFS), it has to return an error.
1309 +XIB(external inode number bitmap)
1310 +----------------------------------------------------------------------
1311 +Addition to the xino file per a branch, aufs has an external inode number
1312 +bitmap in a superblock object. It is also an internal file such like a
1314 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1316 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1318 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1319 +reduce the number of consumed disk blocks for these files.
1322 +Virtual or Vertical Dir, and Readdir in Userspace
1323 +----------------------------------------------------------------------
1324 +In order to support multiple layers (branches), aufs readdir operation
1325 +constructs a virtual dir block on memory. For readdir, aufs calls
1326 +vfs_readdir() internally for each dir on branches, merges their entries
1327 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1328 +object. So the file object has its entry list until it is closed. The
1329 +entry list will be updated when the file position is zero and becomes
1330 +obsoleted. This decision is made in aufs automatically.
1332 +The dynamically allocated memory block for the name of entries has a
1333 +unit of 512 bytes (by default) and stores the names contiguously (no
1334 +padding). Another block for each entry is handled by kmem_cache too.
1335 +During building dir blocks, aufs creates hash list and judging whether
1336 +the entry is whiteouted by its upper branch or already listed.
1337 +The merged result is cached in the corresponding inode object and
1338 +maintained by a customizable life-time option.
1340 +Some people may call it can be a security hole or invite DoS attack
1341 +since the opened and once readdir-ed dir (file object) holds its entry
1342 +list and becomes a pressure for system memory. But I'd say it is similar
1343 +to files under /proc or /sys. The virtual files in them also holds a
1344 +memory page (generally) while they are opened. When an idea to reduce
1345 +memory for them is introduced, it will be applied to aufs too.
1346 +For those who really hate this situation, I've developed readdir(3)
1347 +library which operates this merging in userspace. You just need to set
1348 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1349 +kernel space for readdir(3).
1353 +----------------------------------------------------------------------
1354 +Aufs sometimes requires privilege access to a branch. For instance,
1355 +in copy-up/down operation. When a user process is going to make changes
1356 +to a file which exists in the lower readonly branch only, and the mode
1357 +of one of ancestor directories may not be writable by a user
1358 +process. Here aufs copy-up the file with its ancestors and they may
1359 +require privilege to set its owner/group/mode/etc.
1360 +This is a typical case of a application character of aufs (see
1363 +Aufs uses workqueue synchronously for this case. It creates its own
1364 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1365 +passes the request to call mkdir or write (for example), and wait for
1366 +its completion. This approach solves a problem of a signal handler
1368 +If aufs didn't adopt the workqueue and changed the privilege of the
1369 +process, then the process may receive the unexpected SIGXFSZ or other
1372 +Also aufs uses the system global workqueue ("events" kernel thread) too
1373 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1374 +whiteout base and etc. This is unrelated to a privilege.
1375 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1376 +superblock at the beginning, at the same time waits for the completion
1377 +of all queued asynchronous tasks.
1381 +----------------------------------------------------------------------
1382 +The whiteout in aufs is very similar to Unionfs's. That is represented
1383 +by its filename. UnionMount takes an approach of a file mode, but I am
1384 +afraid several utilities (find(1) or something) will have to support it.
1386 +Basically the whiteout represents "logical deletion" which stops aufs to
1387 +lookup further, but also it represents "dir is opaque" which also stop
1390 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1391 +In order to make several functions in a single systemcall to be
1392 +revertible, aufs adopts an approach to rename a directory to a temporary
1393 +unique whiteouted name.
1394 +For example, in rename(2) dir where the target dir already existed, aufs
1395 +renames the target dir to a temporary unique whiteouted name before the
1396 +actual rename on a branch, and then handles other actions (make it opaque,
1397 +update the attributes, etc). If an error happens in these actions, aufs
1398 +simply renames the whiteouted name back and returns an error. If all are
1399 +succeeded, aufs registers a function to remove the whiteouted unique
1400 +temporary name completely and asynchronously to the system global
1405 +----------------------------------------------------------------------
1406 +It is a well-known feature or concept.
1407 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1408 +internally and makes change to the new file on the upper writable branch.
1409 +When the trigger systemcall does not update the timestamps of the parent
1410 +dir, aufs reverts it after copy-up.
1413 +Move-down (aufs3.9 and later)
1414 +----------------------------------------------------------------------
1415 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1416 +the lower readonly branch to the upper writable branch when a user
1417 +changes something about the file.
1418 +"Move-down" is an opposite action of copy-up. Basically this action is
1419 +ran manually instead of automatically and internally.
1420 +For desgin and implementation, aufs has to consider these issues.
1421 +- whiteout for the file may exist on the lower branch.
1422 +- ancestor directories may not exist on the lower branch.
1423 +- diropq for the ancestor directories may exist on the upper branch.
1424 +- free space on the lower branch will reduce.
1425 +- another access to the file may happen during moving-down, including
1426 + UDBA (see "Revalidate Dentry and UDBA").
1427 +- the file should not be hard-linked nor pseudo-linked. they should be
1428 + handled by auplink utility later.
1430 +Sometimes users want to move-down a file from the upper writable branch
1431 +to the lower readonly or writable branch. For instance,
1432 +- the free space of the upper writable branch is going to run out.
1433 +- create a new intermediate branch between the upper and lower branch.
1436 +For this purpose, use "aumvdown" command in aufs-util.git.
1437 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1438 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1439 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-11-05 23:02:18.955889283 +0100
1442 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1444 +# This program is free software; you can redistribute it and/or modify
1445 +# it under the terms of the GNU General Public License as published by
1446 +# the Free Software Foundation; either version 2 of the License, or
1447 +# (at your option) any later version.
1449 +# This program is distributed in the hope that it will be useful,
1450 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1451 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1452 +# GNU General Public License for more details.
1454 +# You should have received a copy of the GNU General Public License
1455 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1457 +Support for a branch who has its ->atomic_open()
1458 +----------------------------------------------------------------------
1459 +The filesystems who implement its ->atomic_open() are not majority. For
1460 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1461 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1462 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1463 +sure whether all filesystems who have ->atomic_open() behave like this,
1464 +but NFSv4 surely returns the error.
1466 +In order to support ->atomic_open() for aufs, there are a few
1469 +A. Introduce aufs_atomic_open()
1470 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1472 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1473 + an aufs user Pip Cet's approach
1474 + - calls aufs_create(), VFS finish_open() and notify_change().
1475 + - pass fake-mode to finish_open(), and then correct the mode by
1477 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1478 + - no aufs_atomic_open().
1479 + - aufs_lookup() registers the TID to an aufs internal object.
1480 + - aufs_create() does nothing when the matching TID is registered, but
1481 + registers the mode.
1482 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1483 + TID is registered.
1484 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1486 + - no aufs_atomic_open().
1487 + - aufs_create() registers the TID to an internal object. this info
1488 + represents "this process created this file just now."
1489 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1490 + registered TID and re-try open() with superuser's credential.
1492 +Pros and cons for each approach.
1495 + - straightforward but highly depends upon VFS internal.
1496 + - the atomic behavaiour is kept.
1497 + - some of parameters such as nameidata are hard to reproduce for
1501 + - easy to implement.
1502 + - the atomic behavaiour is lost.
1504 + - the atomic behavaiour is kept.
1505 + - dirty and tricky.
1506 + - VFS checks whether the file is created correctly after calling
1507 + ->create(), which means this approach doesn't work.
1509 + - easy to implement.
1510 + - the atomic behavaiour is lost.
1511 + - to open a file with superuser's credential and give it to a user
1512 + process is a bad idea, since the file object keeps the credential
1513 + in it. It may affect LSM or something. This approach doesn't work
1516 +The approach A is ideal, but it hard to implement. So here is a
1517 +variation of A, which is to be implemented.
1519 +A-1. Introduce aufs_atomic_open()
1520 + - calls branch fs ->atomic_open() if exists. otherwise calls
1521 + vfs_create() and finish_open().
1522 + - the demerit is that the several checks after branch fs
1523 + ->atomic_open() are lost. in the ordinary case, the checks are
1524 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1525 + be implemented in aufs, but not all I am afraid.
1526 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1527 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1528 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-11-05 23:02:18.959222617 +0100
1531 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1533 +# This program is free software; you can redistribute it and/or modify
1534 +# it under the terms of the GNU General Public License as published by
1535 +# the Free Software Foundation; either version 2 of the License, or
1536 +# (at your option) any later version.
1538 +# This program is distributed in the hope that it will be useful,
1539 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1540 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1541 +# GNU General Public License for more details.
1543 +# You should have received a copy of the GNU General Public License
1544 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1547 +----------------------------------------------------------------------
1548 +Since aufs has a character of sub-VFS (see Introduction), it operates
1549 +lookup for branches as VFS does. It may be a heavy work. But almost all
1550 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1551 +directly connected to its parent. Digging down the directory hierarchy
1552 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1555 +When a branch is a remote filesystem, aufs basically relies upon its
1556 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1558 +For d_revalidate, aufs implements three levels of revalidate tests. See
1559 +"Revalidate Dentry and UDBA" in detail.
1562 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1563 +----------------------------------------------------------------------
1564 +Let's try case study.
1565 +- aufs has two branches, upper readwrite and lower readonly.
1567 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1568 +- user invoked "chmod a+rx /au/dirA"
1569 +- the internal copy-up is activated and "/rw/dirA" is created and its
1570 + permission bits are set to world readable.
1571 +- then "/au/dirA" becomes world readable?
1573 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1574 +or it may be a natively readonly filesystem. If aufs respects the lower
1575 +branch, it should not respond readdir request from other users. But user
1576 +allowed it by chmod. Should really aufs rejects showing the entries
1579 +To be honest, I don't have a good solution for this case. So aufs
1580 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1582 +When dirperm1 is specified, aufs checks only the highest one for the
1583 +directory permission, and shows the entries. Otherwise, as usual, checks
1584 +every dir existing on all branches and rejects the request.
1586 +As a side effect, dirperm1 option improves the performance of aufs
1587 +because the number of permission check is reduced when the number of
1591 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1592 +----------------------------------------------------------------------
1593 +Generally VFS helpers re-validate a dentry as a part of lookup.
1594 +0. digging down the directory hierarchy.
1595 +1. lock the parent dir by its i_mutex.
1596 +2. lookup the final (child) entry.
1598 +4. call the actual operation (create, unlink, etc.)
1599 +5. unlock the parent dir
1601 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1602 +called. Actually aufs implements it and checks the dentry on a branch is
1604 +But it is not enough. Because aufs has to release the lock for the
1605 +parent dir on a branch at the end of ->lookup() (step 2) and
1606 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1608 +If the file on a branch is changed directly, eg. bypassing aufs, after
1609 +aufs released the lock, then the subsequent operation may cause
1610 +something unpleasant result.
1612 +This situation is a result of VFS architecture, ->lookup() and
1613 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1614 +design from VFS's point of view. It is just not suitable for sub-VFS
1617 +Aufs supports such case by three level of revalidation which is
1618 +selectable by user.
1619 +1. Simple Revalidate
1620 + Addition to the native flow in VFS's, confirm the child-parent
1621 + relationship on the branch just after locking the parent dir on the
1622 + branch in the "actual operation" (step 4). When this validation
1623 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1624 + checks the validation of the dentry on branches.
1625 +2. Monitor Changes Internally by Inotify/Fsnotify
1626 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1627 + the dentry on the branch, and returns EBUSY if it finds different
1629 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1630 + during it is in cache. When the event is notified, aufs registers a
1631 + function to kernel 'events' thread by schedule_work(). And the
1632 + function sets some special status to the cached aufs dentry and inode
1633 + private data. If they are not cached, then aufs has nothing to
1634 + do. When the same file is accessed through aufs (step 0-3) later,
1635 + aufs will detect the status and refresh all necessary data.
1636 + In this mode, aufs has to ignore the event which is fired by aufs
1638 +3. No Extra Validation
1639 + This is the simplest test and doesn't add any additional revalidation
1640 + test, and skip the revalidation in step 4. It is useful and improves
1641 + aufs performance when system surely hide the aufs branches from user,
1642 + by over-mounting something (or another method).
1643 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1644 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1645 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-11-05 23:02:18.959222617 +0100
1648 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1650 +# This program is free software; you can redistribute it and/or modify
1651 +# it under the terms of the GNU General Public License as published by
1652 +# the Free Software Foundation; either version 2 of the License, or
1653 +# (at your option) any later version.
1655 +# This program is distributed in the hope that it will be useful,
1656 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 +# GNU General Public License for more details.
1660 +# You should have received a copy of the GNU General Public License
1661 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1663 +Branch Manipulation
1665 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1666 +and changing its permission/attribute, there are a lot of works to do.
1670 +----------------------------------------------------------------------
1671 +o Confirm the adding dir exists outside of aufs, including loopback
1672 + mount, and its various attributes.
1673 +o Initialize the xino file and whiteout bases if necessary.
1676 +o Check the owner/group/mode of the directory
1677 + When the owner/group/mode of the adding directory differs from the
1678 + existing branch, aufs issues a warning because it may impose a
1680 + For example, when a upper writable branch has a world writable empty
1681 + top directory, a malicious user can create any files on the writable
1682 + branch directly, like copy-up and modify manually. If something like
1683 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1684 + writable branch, and the writable branch is world-writable, then a
1685 + malicious guy may create /etc/passwd on the writable branch directly
1686 + and the infected file will be valid in aufs.
1687 + I am afraid it can be a security issue, but aufs can do nothing except
1688 + producing a warning.
1692 +----------------------------------------------------------------------
1693 +o Confirm the deleting branch is not busy
1694 + To be general, there is one merit to adopt "remount" interface to
1695 + manipulate branches. It is to discard caches. At deleting a branch,
1696 + aufs checks the still cached (and connected) dentries and inodes. If
1697 + there are any, then they are all in-use. An inode without its
1698 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1700 + For the cached one, aufs checks whether the same named entry exists on
1702 + If the cached one is a directory, because aufs provides a merged view
1703 + to users, as long as one dir is left on any branch aufs can show the
1704 + dir to users. In this case, the branch can be removed from aufs.
1705 + Otherwise aufs rejects deleting the branch.
1707 + If any file on the deleting branch is opened by aufs, then aufs
1711 +Modify the Permission of a Branch
1712 +----------------------------------------------------------------------
1713 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1716 +o rw --> ro: Confirm the modifying branch is not busy
1717 + Aufs rejects the request if any of these conditions are true.
1718 + - a file on the branch is mmap-ed.
1719 + - a regular file on the branch is opened for write and there is no
1720 + same named entry on the upper branch.
1721 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1722 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1723 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-11-05 23:02:18.959222617 +0100
1726 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1728 +# This program is free software; you can redistribute it and/or modify
1729 +# it under the terms of the GNU General Public License as published by
1730 +# the Free Software Foundation; either version 2 of the License, or
1731 +# (at your option) any later version.
1733 +# This program is distributed in the hope that it will be useful,
1734 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1735 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1736 +# GNU General Public License for more details.
1738 +# You should have received a copy of the GNU General Public License
1739 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1741 +Policies to Select One among Multiple Writable Branches
1742 +----------------------------------------------------------------------
1743 +When the number of writable branch is more than one, aufs has to decide
1744 +the target branch for file creation or copy-up. By default, the highest
1745 +writable branch which has the parent (or ancestor) dir of the target
1746 +file is chosen (top-down-parent policy).
1747 +By user's request, aufs implements some other policies to select the
1748 +writable branch, for file creation several policies, round-robin,
1749 +most-free-space, and other policies. For copy-up, top-down-parent,
1750 +bottom-up-parent, bottom-up and others.
1752 +As expected, the round-robin policy selects the branch in circular. When
1753 +you have two writable branches and creates 10 new files, 5 files will be
1754 +created for each branch. mkdir(2) systemcall is an exception. When you
1755 +create 10 new directories, all will be created on the same branch.
1756 +And the most-free-space policy selects the one which has most free
1757 +space among the writable branches. The amount of free space will be
1758 +checked by aufs internally, and users can specify its time interval.
1760 +The policies for copy-up is more simple,
1761 +top-down-parent is equivalent to the same named on in create policy,
1762 +bottom-up-parent selects the writable branch where the parent dir
1763 +exists and the nearest upper one from the copyup-source,
1764 +bottom-up selects the nearest upper writable branch from the
1765 +copyup-source, regardless the existence of the parent dir.
1767 +There are some rules or exceptions to apply these policies.
1768 +- If there is a readonly branch above the policy-selected branch and
1769 + the parent dir is marked as opaque (a variation of whiteout), or the
1770 + target (creating) file is whiteout-ed on the upper readonly branch,
1771 + then the result of the policy is ignored and the target file will be
1772 + created on the nearest upper writable branch than the readonly branch.
1773 +- If there is a writable branch above the policy-selected branch and
1774 + the parent dir is marked as opaque or the target file is whiteouted
1775 + on the branch, then the result of the policy is ignored and the target
1776 + file will be created on the highest one among the upper writable
1777 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1779 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1780 + They try selecting the branch where the source exists as possible
1781 + since copyup a large file will take long time. If it can't be,
1782 + ie. the branch where the source exists is readonly, then they will
1783 + follow the copyup policy.
1784 +- There is an exception for rename(2) when the target exists.
1785 + If the rename target exists, aufs compares the index of the branches
1786 + where the source and the target exists and selects the higher
1787 + one. If the selected branch is readonly, then aufs follows the
1789 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1790 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1791 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-11-05 23:02:18.959222617 +0100
1794 +// to view this graph, run dot(1) command in GRAPHVIZ.
1796 +// This program is free software; you can redistribute it and/or modify
1797 +// it under the terms of the GNU General Public License as published by
1798 +// the Free Software Foundation; either version 2 of the License, or
1799 +// (at your option) any later version.
1801 +// This program is distributed in the hope that it will be useful,
1802 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1803 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1804 +// GNU General Public License for more details.
1806 +// You should have received a copy of the GNU General Public License
1807 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1811 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1815 +aufs_rename -> whinfo [label="store/remove"];
1818 +inode_list [label="h_inum list in branch\ncache"];
1821 +whinode [label="h_inum list file"];
1824 +brmgmt [label="br_add/del/mod/umount"];
1826 +brmgmt -> inode_list [label="create/remove"];
1827 +brmgmt -> whinode [label="load/store"];
1829 +inode_list -> whinode [style=dashed,dir=both];
1831 +aufs_rename -> inode_list [label="add/del"];
1833 +aufs_lookup -> inode_list [label="search"];
1835 +aufs_lookup -> whinfo [label="load/remove"];
1837 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1838 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1839 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-11-05 23:02:18.959222617 +0100
1842 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1844 +# This program is free software; you can redistribute it and/or modify
1845 +# it under the terms of the GNU General Public License as published by
1846 +# the Free Software Foundation; either version 2 of the License, or
1847 +# (at your option) any later version.
1849 +# This program is distributed in the hope that it will be useful,
1850 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1851 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1852 +# GNU General Public License for more details.
1854 +# You should have received a copy of the GNU General Public License
1855 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1857 +Special handling for renaming a directory (DIRREN)
1858 +----------------------------------------------------------------------
1859 +First, let's assume we have a simple usecase.
1863 +- /ro/dirA and /ro/dirA/file exist too
1864 +- there is no dirB on both branches
1865 +- a user issues rename("dirA", "dirB")
1867 +Now, what should aufs behave against this rename(2)?
1868 +There are a few possible cases.
1871 + since dirA exists on a readonly branch which cannot be renamed.
1873 + it is possible to copy-up dirA (only the dir itself), but the child
1874 + entries ("file" in this case) should not be. it must be a bad
1875 + approach to copy-up recursively.
1876 +C. returns a success.
1877 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1878 + is a violation of aufs' policy.
1879 +D. construct an extra information which indicates that /ro/dirA should
1880 + be handled as the name of dirB.
1881 + overlayfs has a similar feature called REDIRECT.
1883 +Until now, aufs implements the case B only which returns EXDEV, and
1884 +expects the userspace application behaves like mv(1) which tries
1885 +issueing rename(2) recursively.
1887 +A new aufs feature called DIRREN is introduced which implements the case
1888 +D. There are several "extra information" added.
1890 +1. detailed info per renamed directory
1891 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1892 +2. the inode-number list of directories on a branch
1893 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1895 +The filename of "detailed info per directory" represents the lower
1896 +branch, and its format is
1897 +- a type of the branch id
1899 + + uuid (not implemented yet)
1902 +- the inode-number of the branch root dir
1904 +And it contains these info in a single regular file.
1906 +- branch's inode-number of the logically renamed dir
1907 +- the name of the before-renamed dir
1909 +The "detailed info per directory" file is created in aufs rename(2), and
1910 +loaded in any lookup.
1911 +The info is considered in lookup for the matching case only. Here
1912 +"matching" means that the root of branch (in the info filename) is same
1913 +to the current looking-up branch. After looking-up the before-renamed
1914 +name, the inode-number is compared. And the matched dentry is used.
1916 +The "inode-number list of directories" is a regular file which contains
1917 +simply the inode-numbers on the branch. The file is created or updated
1918 +in removing the branch, and loaded in adding the branch. Its lifetime is
1919 +equal to the branch.
1920 +The list is referred in lookup, and when the current target inode is
1921 +found in the list, the aufs tries loading the "detailed info per
1922 +directory" and get the changed and valid name of the dir.
1924 +Theoretically these "extra informaiton" may be able to be put into XATTR
1925 +in the dir inode. But aufs doesn't choose this way because
1926 +1. XATTR may not be supported by the branch (or its configuration)
1927 +2. XATTR may have its size limit.
1928 +3. XATTR may be less easy to convert than a regular file, when the
1929 + format of the info is changed in the future.
1930 +At the same time, I agree that the regular file approach is much slower
1931 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1934 +This DIRREN feature is enabled by aufs configuration, and is activated
1935 +by a new mount option.
1937 +For the more complicated case, there is a work with UDBA option, which
1938 +is to dected the direct access to the branches (by-passing aufs) and to
1939 +maintain the cashes in aufs. Since a single cached aufs dentry may
1940 +contains two names, before- and after-rename, the name comparision in
1941 +UDBA handler may not work correctly. In this case, the behaviour will be
1942 +equivalen to udba=reval case.
1943 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1944 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1945 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-11-05 23:02:18.959222617 +0100
1948 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1950 +# This program is free software; you can redistribute it and/or modify
1951 +# it under the terms of the GNU General Public License as published by
1952 +# the Free Software Foundation; either version 2 of the License, or
1953 +# (at your option) any later version.
1955 +# This program is distributed in the hope that it will be useful,
1956 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1957 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1958 +# GNU General Public License for more details.
1960 +# You should have received a copy of the GNU General Public License
1961 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1963 +File-based Hierarchical Storage Management (FHSM)
1964 +----------------------------------------------------------------------
1965 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1966 +storage world. Aufs provides this feature as file-based with multiple
1967 +writable branches, based upon the principle of "Colder, the Lower".
1968 +Here the word "colder" means that the less used files, and "lower" means
1969 +that the position in the order of the stacked branches vertically.
1970 +These multiple writable branches are prioritized, ie. the topmost one
1971 +should be the fastest drive and be used heavily.
1973 +o Characters in aufs FHSM story
1974 +- aufs itself and a new branch attribute.
1975 +- a new ioctl interface to move-down and to establish a connection with
1976 + the daemon ("move-down" is a converse of "copy-up").
1977 +- userspace tool and daemon.
1979 +The userspace daemon establishes a connection with aufs and waits for
1980 +the notification. The notified information is very similar to struct
1981 +statfs containing the number of consumed blocks and inodes.
1982 +When the consumed blocks/inodes of a branch exceeds the user-specified
1983 +upper watermark, the daemon activates its move-down process until the
1984 +consumed blocks/inodes reaches the user-specified lower watermark.
1986 +The actual move-down is done by aufs based upon the request from
1987 +user-space since we need to maintain the inode number and the internal
1988 +pointer arrays in aufs.
1990 +Currently aufs FHSM handles the regular files only. Additionally they
1991 +must not be hard-linked nor pseudo-linked.
1994 +o Cowork of aufs and the user-space daemon
1995 + During the userspace daemon established the connection, aufs sends a
1996 + small notification to it whenever aufs writes something into the
1997 + writable branch. But it may cost high since aufs issues statfs(2)
1998 + internally. So user can specify a new option to cache the
1999 + info. Actually the notification is controlled by these factors.
2000 + + the specified cache time.
2001 + + classified as "force" by aufs internally.
2002 + Until the specified time expires, aufs doesn't send the info
2003 + except the forced cases. When aufs decide forcing, the info is always
2004 + notified to userspace.
2005 + For example, the number of free inodes is generally large enough and
2006 + the shortage of it happens rarely. So aufs doesn't force the
2007 + notification when creating a new file, directory and others. This is
2008 + the typical case which aufs doesn't force.
2009 + When aufs writes the actual filedata and the files consumes any of new
2010 + blocks, the aufs forces notifying.
2013 +o Interfaces in aufs
2014 +- New branch attribute.
2016 + Specifies that the branch is managed by FHSM feature. In other word,
2017 + participant in the FHSM.
2018 + When nofhsm is set to the branch, it will not be the source/target
2019 + branch of the move-down operation. This attribute is set
2020 + independently from coo and moo attributes, and if you want full
2021 + FHSM, you should specify them as well.
2022 +- New mount option.
2024 + Specifies a second to suppress many less important info to be
2027 + + AUFS_CTL_FHSM_FD
2028 + create a new file descriptor which userspace can read the notification
2029 + (a subset of struct statfs) from aufs.
2030 +- Module parameter 'brs'
2031 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2033 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2034 + When there are two or more branches with fhsm attributes,
2035 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2036 + terminates it. As a result of remounting and branch-manipulation, the
2037 + number of branches with fhsm attribute can be one. In this case,
2038 + /sbin/mount.aufs will terminate the user-space daemon.
2041 +Finally the operation is done as these steps in kernel-space.
2043 + + no one else is using the file.
2044 + + the file is not hard-linked.
2045 + + the file is not pseudo-linked.
2046 + + the file is a regular file.
2047 + + the parent dir is not opaqued.
2048 +- find the target writable branch.
2049 +- make sure the file is not whiteout-ed by the upper (than the target)
2051 +- make the parent dir on the target branch.
2052 +- mutex lock the inode on the branch.
2053 +- unlink the whiteout on the target branch (if exists).
2054 +- lookup and create the whiteout-ed temporary name on the target branch.
2055 +- copy the file as the whiteout-ed temporary name on the target branch.
2056 +- rename the whiteout-ed temporary name to the original name.
2057 +- unlink the file on the source branch.
2058 +- maintain the internal pointer array and the external inode number
2060 +- maintain the timestamps and other attributes of the parent dir and the
2063 +And of course, in every step, an error may happen. So the operation
2064 +should restore the original file state after an error happens.
2065 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2066 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2067 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-11-05 23:02:18.959222617 +0100
2070 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2072 +# This program is free software; you can redistribute it and/or modify
2073 +# it under the terms of the GNU General Public License as published by
2074 +# the Free Software Foundation; either version 2 of the License, or
2075 +# (at your option) any later version.
2077 +# This program is distributed in the hope that it will be useful,
2078 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2079 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2080 +# GNU General Public License for more details.
2082 +# You should have received a copy of the GNU General Public License
2083 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2085 +mmap(2) -- File Memory Mapping
2086 +----------------------------------------------------------------------
2087 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2088 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2090 +This approach is simple and good, but there is one problem.
2091 +Under /proc, several entries show the mmapped files by its path (with
2092 +device and inode number), and the printed path will be the path on the
2093 +branch fs's instead of virtual aufs's.
2094 +This is not a problem in most cases, but some utilities lsof(1) (and its
2095 +user) may expect the path on aufs.
2097 +To address this issue, aufs adds a new member called vm_prfile in struct
2098 +vm_area_struct (and struct vm_region). The original vm_file points to
2099 +the file on the branch fs in order to handle everything correctly as
2100 +usual. The new vm_prfile points to a virtual file in aufs, and the
2101 +show-functions in procfs refers to vm_prfile if it is set.
2102 +Also we need to maintain several other places where touching vm_file
2104 +- fork()/clone() copies vma and the reference count of vm_file is
2106 +- merging vma maintains the ref count too.
2108 +This is not a good approach. It just fakes the printed path. But it
2109 +leaves all behaviour around f_mapping unchanged. This is surely an
2111 +Actually aufs had adopted another complicated approach which calls
2112 +generic_file_mmap() and handles struct vm_operations_struct. In this
2113 +approach, aufs met a hard problem and I could not solve it without
2114 +switching the approach.
2116 +There may be one more another approach which is
2117 +- bind-mount the branch-root onto the aufs-root internally
2118 +- grab the new vfsmount (ie. struct mount)
2119 +- lazy-umount the branch-root internally
2120 +- in open(2) the aufs-file, open the branch-file with the hidden
2121 + vfsmount (instead of the original branch's vfsmount)
2122 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2123 + but it may be possible from userspace by the mount helper.
2125 +Adding the internal hidden vfsmount and using it in opening a file, the
2126 +file path under /proc will be printed correctly. This approach looks
2127 +smarter, but is not possible I am afraid.
2128 +- aufs-root may be bind-mount later. when it happens, another hidden
2129 + vfsmount will be required.
2130 +- it is hard to get the chance to bind-mount and lazy-umount
2131 + + in kernel-space, FS can have vfsmount in open(2) via
2132 + file->f_path, and aufs can know its vfsmount. But several locks are
2133 + already acquired, and if aufs tries to bind-mount and lazy-umount
2134 + here, then it may cause a deadlock.
2135 + + in user-space, bind-mount doesn't invoke the mount helper.
2136 +- since /proc shows dev and ino, aufs has to give vma these info. it
2137 + means a new member vm_prinode will be necessary. this is essentially
2138 + equivalent to vm_prfile described above.
2140 +I have to give up this "looks-smater" approach.
2141 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2142 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2143 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-11-05 23:02:18.959222617 +0100
2146 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2148 +# This program is free software; you can redistribute it and/or modify
2149 +# it under the terms of the GNU General Public License as published by
2150 +# the Free Software Foundation; either version 2 of the License, or
2151 +# (at your option) any later version.
2153 +# This program is distributed in the hope that it will be useful,
2154 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2155 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2156 +# GNU General Public License for more details.
2158 +# You should have received a copy of the GNU General Public License
2159 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2161 +Listing XATTR/EA and getting the value
2162 +----------------------------------------------------------------------
2163 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2164 +shows the values from the topmost existing file. This behaviour is good
2165 +for the non-dir entries since the bahaviour exactly matches the shown
2166 +information. But for the directories, aufs considers all the same named
2167 +entries on the lower branches. Which means, if one of the lower entry
2168 +rejects readdir call, then aufs returns an error even if the topmost
2169 +entry allows it. This behaviour is necessary to respect the branch fs's
2170 +security, but can make users confused since the user-visible standard
2171 +attributes don't match the behaviour.
2172 +To address this issue, aufs has a mount option called dirperm1 which
2173 +checks the permission for the topmost entry only, and ignores the lower
2174 +entry's permission.
2176 +A similar issue can happen around XATTR.
2177 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2178 +always set. Otherwise these very unpleasant situation would happen.
2179 +- listxattr(2) may return the duplicated entries.
2180 +- users may not be able to remove or reset the XATTR forever,
2183 +XATTR/EA support in the internal (copy,move)-(up,down)
2184 +----------------------------------------------------------------------
2185 +Generally the extended attributes of inode are categorized as these.
2186 +- "security" for LSM and capability.
2187 +- "system" for posix ACL, 'acl' mount option is required for the branch
2189 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2190 +- "user" for userspace, 'user_xattr' mount option is required for the
2191 + branch fs generally.
2193 +Moreover there are some other categories. Aufs handles these rather
2194 +unpopular categories as the ordinary ones, ie. there is no special
2195 +condition nor exception.
2197 +In copy-up, the support for XATTR on the dst branch may differ from the
2198 +src branch. In this case, the copy-up operation will get an error and
2199 +the original user operation which triggered the copy-up will fail. It
2200 +can happen that even all copy-up will fail.
2201 +When both of src and dst branches support XATTR and if an error occurs
2202 +during copying XATTR, then the copy-up should fail obviously. That is a
2203 +good reason and aufs should return an error to userspace. But when only
2204 +the src branch support that XATTR, aufs should not return an error.
2205 +For example, the src branch supports ACL but the dst branch doesn't
2206 +because the dst branch may natively un-support it or temporary
2207 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2208 +may NOT return an error even if the XATTR is not supported. It is
2209 +totally up to the branch fs.
2211 +Anyway when the aufs internal copy-up gets an error from the dst branch
2212 +fs, then aufs tries removing the just copied entry and returns the error
2213 +to the userspace. The worst case of this situation will be all copy-up
2216 +For the copy-up operation, there two basic approaches.
2217 +- copy the specified XATTR only (by category above), and return the
2218 + error unconditionally if it happens.
2219 +- copy all XATTR, and ignore the error on the specified category only.
2221 +In order to support XATTR and to implement the correct behaviour, aufs
2222 +chooses the latter approach and introduces some new branch attributes,
2223 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2224 +They correspond to the XATTR namespaces (see above). Additionally, to be
2225 +convenient, "icex" is also provided which means all "icex*" attributes
2226 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2228 +The meaning of these attributes is to ignore the error from setting
2229 +XATTR on that branch.
2230 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2231 +error from the dst branch according to the specified attributes.
2233 +Some XATTR may have its default value. The default value may come from
2234 +the parent dir or the environment. If the default value is set at the
2235 +file creating-time, it will be overwritten by copy-up.
2236 +Some contradiction may happen I am afraid.
2237 +Do we need another attribute to stop copying XATTR? I am unsure. For
2238 +now, aufs implements the branch attributes to ignore the error.
2239 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2240 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2241 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-11-05 23:02:18.959222617 +0100
2244 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2246 +# This program is free software; you can redistribute it and/or modify
2247 +# it under the terms of the GNU General Public License as published by
2248 +# the Free Software Foundation; either version 2 of the License, or
2249 +# (at your option) any later version.
2251 +# This program is distributed in the hope that it will be useful,
2252 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2253 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2254 +# GNU General Public License for more details.
2256 +# You should have received a copy of the GNU General Public License
2257 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2259 +Export Aufs via NFS
2260 +----------------------------------------------------------------------
2261 +Here is an approach.
2262 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2264 +- iget_locked(): initialize aufs inode generation for a new inode, and
2265 + store it in xigen file.
2266 +- destroy_inode(): increment aufs inode generation and store it in xigen
2267 + file. it is necessary even if it is not unlinked, because any data of
2268 + inode may be changed by UDBA.
2269 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2270 + build file handle by
2271 + + branch id (4 bytes)
2272 + + superblock generation (4 bytes)
2273 + + inode number (4 or 8 bytes)
2274 + + parent dir inode number (4 or 8 bytes)
2275 + + inode generation (4 bytes))
2276 + + return value of exportfs_encode_fh() for the parent on a branch (4
2278 + + file handle for a branch (by exportfs_encode_fh())
2280 + + find the index of a branch from its id in handle, and check it is
2281 + still exist in aufs.
2282 + + 1st level: get the inode number from handle and search it in cache.
2283 + + 2nd level: if not found in cache, get the parent inode number from
2284 + the handle and search it in cache. and then open the found parent
2285 + dir, find the matching inode number by vfs_readdir() and get its
2286 + name, and call lookup_one_len() for the target dentry.
2287 + + 3rd level: if the parent dir is not cached, call
2288 + exportfs_decode_fh() for a branch and get the parent on a branch,
2289 + build a pathname of it, convert it a pathname in aufs, call
2290 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2292 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2293 + for every branch, but not itself. to get this, (currently) aufs
2294 + searches in current->nsproxy->mnt_ns list. it may not be a good
2295 + idea, but I didn't get other approach.
2296 + + test the generation of the gotten inode.
2297 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2298 + convert it into ESTALE for NFSD.
2299 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2300 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2301 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2302 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2303 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-11-05 23:02:18.959222617 +0100
2306 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2308 +# This program is free software; you can redistribute it and/or modify
2309 +# it under the terms of the GNU General Public License as published by
2310 +# the Free Software Foundation; either version 2 of the License, or
2311 +# (at your option) any later version.
2313 +# This program is distributed in the hope that it will be useful,
2314 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2315 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2316 +# GNU General Public License for more details.
2318 +# You should have received a copy of the GNU General Public License
2319 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2321 +Show Whiteout Mode (shwh)
2322 +----------------------------------------------------------------------
2323 +Generally aufs hides the name of whiteouts. But in some cases, to show
2324 +them is very useful for users. For instance, creating a new middle layer
2325 +(branch) by merging existing layers.
2327 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2328 +When you have three branches,
2329 +- Bottom: 'system', squashfs (underlying base system), read-only
2330 +- Middle: 'mods', squashfs, read-only
2331 +- Top: 'overlay', ram (tmpfs), read-write
2333 +The top layer is loaded at boot time and saved at shutdown, to preserve
2334 +the changes made to the system during the session.
2335 +When larger changes have been made, or smaller changes have accumulated,
2336 +the size of the saved top layer data grows. At this point, it would be
2337 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2338 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2339 +restoring save and load speed.
2341 +This merging is simplified by the use of another aufs mount, of just the
2342 +two overlay branches using the 'shwh' option.
2343 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2344 + aufs /livesys/merge_union
2346 +A merged view of these two branches is then available at
2347 +/livesys/merge_union, and the new feature is that the whiteouts are
2349 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2350 +writing to all branches. Also the default mode for all branches is 'ro'.
2351 +It is now possible to save the combined contents of the two overlay
2352 +branches to a new squashfs, e.g.:
2353 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2355 +This new squashfs archive can be stored on the boot device and the
2356 +initramfs will use it to replace the old one at the next boot.
2357 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2358 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2359 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-11-05 23:02:18.959222617 +0100
2362 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2364 +# This program is free software; you can redistribute it and/or modify
2365 +# it under the terms of the GNU General Public License as published by
2366 +# the Free Software Foundation; either version 2 of the License, or
2367 +# (at your option) any later version.
2369 +# This program is distributed in the hope that it will be useful,
2370 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2371 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2372 +# GNU General Public License for more details.
2374 +# You should have received a copy of the GNU General Public License
2375 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2377 +Dynamically customizable FS operations
2378 +----------------------------------------------------------------------
2379 +Generally FS operations (struct inode_operations, struct
2380 +address_space_operations, struct file_operations, etc.) are defined as
2381 +"static const", but it never means that FS have only one set of
2382 +operation. Some FS have multiple sets of them. For instance, ext2 has
2383 +three sets, one for XIP, for NOBH, and for normal.
2384 +Since aufs overrides and redirects these operations, sometimes aufs has
2385 +to change its behaviour according to the branch FS type. More importantly
2386 +VFS acts differently if a function (member in the struct) is set or
2387 +not. It means aufs should have several sets of operations and select one
2388 +among them according to the branch FS definition.
2390 +In order to solve this problem and not to affect the behaviour of VFS,
2391 +aufs defines these operations dynamically. For instance, aufs defines
2392 +dummy direct_IO function for struct address_space_operations, but it may
2393 +not be set to the address_space_operations actually. When the branch FS
2394 +doesn't have it, aufs doesn't set it to its address_space_operations
2395 +while the function definition itself is still alive. So the behaviour
2396 +itself will not change, and it will return an error when direct_IO is
2399 +The lifetime of these dynamically generated operation object is
2400 +maintained by aufs branch object. When the branch is removed from aufs,
2401 +the reference counter of the object is decremented. When it reaches
2402 +zero, the dynamically generated operation object will be freed.
2404 +This approach is designed to support AIO (io_submit), Direct I/O and
2406 +Currently this approach is applied to address_space_operations for
2407 +regular files only.
2408 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2409 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2410 +++ linux/Documentation/filesystems/aufs/README 2023-08-28 12:34:41.669969465 +0200
2413 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2419 +----------------------------------------
2420 +In the early days, aufs was entirely re-designed and re-implemented
2421 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2422 +improvements and implementations, it became totally different from
2423 +Unionfs while keeping the basic features.
2424 +Later, Unionfs Version 2.x series began taking some of the same
2425 +approaches to aufs1's.
2426 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2427 +University and his team.
2429 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2430 +aufs-linux.git or aufs-standalone.git.
2431 +If you want older kernel version support,
2432 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2433 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2434 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2435 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2436 + or aufs1 from CVS on SourceForge.
2438 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2439 + were changed. Now they are aufs-linux.git and
2440 + aufs-standalone.git and they contain aufs5 and later branches.
2442 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2443 + According to Christoph Hellwig, linux rejects all union-type
2444 + filesystems but UnionMount.
2445 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2447 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2448 + UnionMount, and he pointed out an issue around a directory mutex
2449 + lock and aufs addressed it. But it is still unsure whether aufs will
2450 + be merged (or any other union solution).
2451 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2455 +----------------------------------------
2456 +- unite several directories into a single virtual filesystem. The member
2457 + directory is called as a branch.
2458 +- you can specify the permission flags to the branch, which are 'readonly',
2459 + 'readwrite' and 'whiteout-able.'
2460 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2461 + readonly branch are modifiable logically.
2462 +- dynamic branch manipulation, add, del.
2465 +Also there are many enhancements in aufs, such as:
2466 +- test only the highest one for the directory permission (dirperm1)
2467 +- copyup on open (coo=)
2468 +- 'move' policy for copy-up between two writable branches, after
2469 + checking free space.
2471 +- readdir(3) in userspace.
2472 +- keep inode number by external inode number table
2473 +- keep the timestamps of file/dir in internal copyup operation
2474 +- seekable directory, supporting NFS readdir.
2475 +- whiteout is hardlinked in order to reduce the consumption of inodes
2477 +- do not copyup, nor create a whiteout when it is unnecessary
2478 +- revert a single systemcall when an error occurs in aufs
2479 +- remount interface instead of ioctl
2480 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2481 +- loopback mounted filesystem as a branch
2482 +- kernel thread for removing the dir who has a plenty of whiteouts
2483 +- support copyup sparse file (a file which has a 'hole' in it)
2484 +- default permission flags for branches
2485 +- selectable permission flags for ro branch, whether whiteout can
2488 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2489 +- support multiple writable branches, some policies to select one
2490 + among multiple writable branches.
2491 +- a new semantics for link(2) and rename(2) to support multiple
2492 + writable branches.
2493 +- no glibc changes are required.
2494 +- pseudo hardlink (hardlink over branches)
2495 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2496 + including NFS or remote filesystem branch.
2497 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2500 +Currently these features are dropped temporary from aufs6.
2501 +See design/08plan.txt in detail.
2502 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2504 +- statistics of aufs thread (/sys/fs/aufs/stat)
2506 +Features or just an idea in the future (see also design/*.txt),
2507 +- reorder the branch index without del/re-add.
2508 +- permanent xino files for NFSD
2509 +- an option for refreshing the opened files after add/del branches
2510 +- light version, without branch manipulation. (unnecessary?)
2511 +- copyup in userspace
2512 +- inotify in userspace
2517 +----------------------------------------
2518 +There are three GIT trees for aufs6, aufs-linux.git,
2519 +aufs-standalone.git, and aufs-util.git.
2520 +While the aufs-util is always necessary, you need either of aufs-linux
2521 +or aufs-standalone.
2523 +The aufs-linux tree includes the whole linux mainline GIT tree,
2524 +git://git.kernel.org/.../torvalds/linux.git.
2525 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2526 +build aufs6 as an external kernel module.
2527 +Several extra patches are not included in this tree. Only
2528 +aufs-standalone tree contains them. They are described in the later
2529 +section "Configuration and Compilation."
2531 +On the other hand, the aufs-standalone tree has only aufs source files
2532 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2533 +But you need to apply all aufs patches manually.
2535 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2536 +represents the linux kernel version, "linux-6.x". For instance,
2537 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2538 +"aufs6.x-rcN" branch.
2541 +$ git clone --reference /your/linux/git/tree \
2542 + git://github.com/sfjro/aufs-linux.git aufs-linux.git
2543 +- if you don't have linux GIT tree, then remove "--reference ..."
2544 +$ cd aufs-linux.git
2545 +$ git checkout origin/aufs6.0
2547 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2548 +leave the patch-work to GIT.
2549 +$ cd /your/linux/git/tree
2550 +$ git remote add aufs git://github.com/sfjro/aufs-linux.git
2552 +$ git checkout -b my6.0 v6.0
2553 +$ (add your local change...)
2554 +$ git pull aufs aufs6.0
2555 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2556 +- you may need to solve some conflicts between your_changes and
2557 + aufs6.0. in this case, git-rerere is recommended so that you can
2558 + solve the similar conflicts automatically when you upgrade to 6.1 or
2559 + later in the future.
2561 +o aufs-standalone tree
2562 +$ git clone git://github.com/sfjro/aufs-standalone.git aufs-standalone.git
2563 +$ cd aufs-standalone.git
2564 +$ git checkout origin/aufs6.0
2567 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2568 +- note that the public aufs-util.git is on SourceForge instead of
2571 +$ git checkout origin/aufs6.0
2573 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2574 +The minor version number, 'x' in '6.x', of aufs may not always
2575 +follow the minor version number of the kernel.
2576 +Because changes in the kernel that cause the use of a new
2577 +minor version number do not always require changes to aufs-util.
2579 +Since aufs-util has its own minor version number, you may not be
2580 +able to find a GIT branch in aufs-util for your kernel's
2581 +exact minor version number.
2582 +In this case, you should git-checkout the branch for the
2583 +nearest lower number.
2585 +For (an unreleased) example:
2586 +If you are using "linux-6.10" and the "aufs6.10" branch
2587 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2588 +or something numerically smaller is the branch for your kernel.
2590 +Also you can view all branches by
2594 +3. Configuration and Compilation
2595 +----------------------------------------
2596 +Make sure you have git-checkout'ed the correct branch.
2598 +For aufs-linux tree,
2599 +- enable CONFIG_AUFS_FS.
2600 +- set other aufs configurations if necessary.
2601 +- for aufs5.13 and later
2602 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2603 + also a caller of VFS functions for branch filesystems, subclassing of
2604 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2605 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2606 + need to customize some LOCKDEP numbers. Here are what I use on my
2608 + CONFIG_LOCKDEP_BITS=21
2609 + CONFIG_LOCKDEP_CHAINS_BITS=21
2610 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2611 + Also you will need to expand some constant values in LOCKDEP. Refer
2612 + to lockdep-debug.patch in aufs-standalone.git.
2614 +For aufs-standalone tree,
2615 +There are several ways to build.
2618 +- apply ./aufs6-kbuild.patch to your kernel source files.
2619 +- apply ./aufs6-base.patch too.
2620 +- apply ./aufs6-mmap.patch too.
2621 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2622 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs-standalone.patch.
2623 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2624 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2625 +- enable CONFIG_AUFS_FS, you can select either
2627 +- and build your kernel as usual.
2628 +- install the built kernel.
2629 +- install the header files too by "make headers_install" to the
2630 + directory where you specify. By default, it is $PWD/usr.
2631 + "make help" shows a brief note for headers_install.
2632 +- and reboot your system.
2635 +- module only (CONFIG_AUFS_FS=m).
2636 +- apply ./aufs6-base.patch to your kernel source files.
2637 +- apply ./aufs6-mmap.patch too.
2638 +- apply ./aufs6-standalone.patch too.
2639 +- build your kernel, don't forget "make headers_install", and reboot.
2640 +- edit ./config.mk and set other aufs configurations if necessary.
2641 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2642 + every aufs configurations.
2643 +- build the module by simple "make".
2644 +- you can specify ${KDIR} make variable which points to your kernel
2646 +- install the files
2647 + + run "make install" to install the aufs module, or copy the built
2648 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2649 + + run "make install_headers" (instead of headers_install) to install
2650 + the modified aufs header file (you can specify DESTDIR which is
2651 + available in aufs standalone version's Makefile only), or copy
2652 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2653 + you like manually. By default, the target directory is $PWD/usr.
2654 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2655 + kernel source tree.
2657 +Note: The header file aufs_type.h is necessary to build aufs-util
2658 + as well as "make headers_install" in the kernel source tree.
2659 + headers_install is subject to be forgotten, but it is essentially
2660 + necessary, not only for building aufs-util.
2661 + You may not meet problems without headers_install in some older
2665 +- read README in aufs-util, build and install it
2666 +- note that your distribution may contain an obsoleted version of
2667 + aufs_type.h in /usr/include/linux or something. When you build aufs
2668 + utilities, make sure that your compiler refers the correct aufs header
2669 + file which is built by "make headers_install."
2670 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2671 + then run "make install_ulib" too. And refer to the aufs manual in
2674 +There several other patches in aufs-standalone.git. They are all
2675 +optional. When you meet some problems, they will help you.
2676 +- aufs6-loopback.patch
2677 + Supports a nested loopback mount in a branch-fs. This patch is
2678 + unnecessary until aufs produces a message like "you may want to try
2679 + another patch for loopback file".
2681 + Modifies a system global kernel internal function get_next_ino() in
2682 + order to stop assigning 0 for an inode-number. Not directly related to
2683 + aufs, but recommended generally.
2685 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2686 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2687 + duplication of inode number, which is important for backup tools and
2688 + other utilities. When you find aufs XINO files for tmpfs branch
2689 + growing too much, try this patch.
2690 +- lockdep-debug.patch
2691 + Similar to some kernel configurations for LOCKDEP (see the top of
2692 + this section), you will need expand some constants in LOCKDEP for
2693 + aufs if you enable CONFIG_LOCKDEP.
2697 +----------------------------------------
2698 +At first, make sure aufs-util are installed, and please read the aufs
2699 +manual, aufs.5 in aufs-util.git tree.
2703 +$ mkdir /tmp/rw /tmp/aufs
2704 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2706 +Here is another example. The result is equivalent.
2707 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2709 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2710 +# mount -o remount,append:${HOME} /tmp/aufs
2712 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2713 +you modify a file under /tmp/aufs, the one on your home directory is
2714 +not affected, instead the same named file will be newly created under
2715 +/tmp/rw. And all of your modification to a file will be applied to
2716 +the one under /tmp/rw. This is called the file based Copy on Write
2718 +Aufs mount options are described in aufs.5.
2719 +If you run chroot or something and make your aufs as a root directory,
2720 +then you need to customize the shutdown script. See the aufs manual in
2723 +Additionally, there are some sample usages of aufs which are a
2724 +diskless system with network booting, and LiveCD over NFS.
2725 +See sample dir in CVS tree on SourceForge.
2729 +----------------------------------------
2730 +When you have any problems or strange behaviour in aufs, please let me
2732 +- /proc/mounts (instead of the output of mount(8))
2733 +- /sys/module/aufs/*
2734 +- /sys/fs/aufs/* (if you have them)
2735 +- /debug/aufs/* (if you have them)
2736 +- linux kernel version
2737 + if your kernel is not plain, for example modified by distributor,
2738 + the url where i can download its source is necessary too.
2739 +- aufs version which was printed at loading the module or booting the
2740 + system, instead of the date you downloaded.
2741 +- configuration (define/undefine CONFIG_AUFS_xxx)
2742 +- kernel configuration or /proc/config.gz (if you have it)
2743 +- LSM (linux security module, if you are using)
2744 +- behaviour which you think to be incorrect
2745 +- actual operation, reproducible one is better
2746 +- mailto: aufs-users at lists.sourceforge.net
2748 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2749 +and Feature Requests) on SourceForge. Please join and write to
2753 +6. Acknowledgements
2754 +----------------------------------------
2755 +Thanks to everyone who have tried and are using aufs, whoever
2756 +have reported a bug or any feedback.
2758 +Especially donators:
2759 +Tomas Matejicek(slax.org) made a donation (much more than once).
2760 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2761 + scripts) is making "doubling" donations.
2762 + Unfortunately I cannot list all of the donators, but I really
2764 + It ends Aug 2010, but the ordinary donation URL is still available.
2765 + <http://sourceforge.net/donate/index.php?group_id=167503>
2766 +Dai Itasaka made a donation (2007/8).
2767 +Chuck Smith made a donation (2008/4, 10 and 12).
2768 +Henk Schoneveld made a donation (2008/9).
2769 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2770 +Francois Dupoux made a donation (2008/11).
2771 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2772 + aufs2 GIT tree (2009/2).
2773 +William Grant made a donation (2009/3).
2774 +Patrick Lane made a donation (2009/4).
2775 +The Mail Archive (mail-archive.com) made donations (2009/5).
2776 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2777 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2778 +Pavel Pronskiy made a donation (2011/2).
2779 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2780 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2781 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2783 +Sam Liddicott made a donation (2011/9).
2784 +Era Scarecrow made a donation (2013/4).
2785 +Bor Ratajc made a donation (2013/4).
2786 +Alessandro Gorreta made a donation (2013/4).
2787 +POIRETTE Marc made a donation (2013/4).
2788 +Alessandro Gorreta made a donation (2013/4).
2789 +lauri kasvandik made a donation (2013/5).
2790 +"pemasu from Finland" made a donation (2013/7).
2791 +The Parted Magic Project made a donation (2013/9 and 11).
2792 +Pavel Barta made a donation (2013/10).
2793 +Nikolay Pertsev made a donation (2014/5).
2794 +James B made a donation (2014/7, 2015/7, and 2021/12).
2795 +Stefano Di Biase made a donation (2014/8).
2796 +Daniel Epellei made a donation (2015/1).
2797 +OmegaPhil made a donation (2016/1, 2018/4).
2798 +Tomasz Szewczyk made a donation (2016/4).
2799 +James Burry made a donation (2016/12).
2800 +Carsten Rose made a donation (2018/9).
2801 +Porteus Kiosk made a donation (2018/10).
2802 +huronOS team: Enya Quetzalli made donations (2022/5, 2023/5 and 8).
2803 +Vasily Mikhaylichenko made a donation (2023/5).
2805 +Thank you very much.
2806 +Donations are always, including future donations, very important and
2807 +helpful for me to keep on developing aufs.
2811 +----------------------------------------
2812 +If you are an experienced user, no explanation is needed. Aufs is
2813 +just a linux filesystem.
2818 +# Local variables: ;
2821 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2822 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2823 +++ linux/fs/aufs/aufs.h 2022-11-05 23:02:18.959222617 +0100
2825 +/* SPDX-License-Identifier: GPL-2.0 */
2827 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2829 + * This program is free software; you can redistribute it and/or modify
2830 + * it under the terms of the GNU General Public License as published by
2831 + * the Free Software Foundation; either version 2 of the License, or
2832 + * (at your option) any later version.
2834 + * This program is distributed in the hope that it will be useful,
2835 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2836 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2837 + * GNU General Public License for more details.
2839 + * You should have received a copy of the GNU General Public License
2840 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2844 + * all header files
2852 +#define AuStub(type, name, body, ...) \
2853 + static inline type name(__VA_ARGS__) { body; }
2855 +#define AuStubVoid(name, ...) \
2856 + AuStub(void, name, , __VA_ARGS__)
2857 +#define AuStubInt0(name, ...) \
2858 + AuStub(int, name, return 0, __VA_ARGS__)
2862 +#include "branch.h"
2865 +#include "dbgaufs.h"
2866 +#include "dentry.h"
2868 +#include "dirren.h"
2871 +#include "fstype.h"
2876 +#include "module.h"
2880 +#include "sysaufs.h"
2885 +#endif /* __KERNEL__ */
2886 +#endif /* __AUFS_H__ */
2887 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2888 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2889 +++ linux/fs/aufs/branch.c 2022-11-05 23:02:18.959222617 +0100
2891 +// SPDX-License-Identifier: GPL-2.0
2893 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2895 + * This program is free software; you can redistribute it and/or modify
2896 + * it under the terms of the GNU General Public License as published by
2897 + * the Free Software Foundation; either version 2 of the License, or
2898 + * (at your option) any later version.
2900 + * This program is distributed in the hope that it will be useful,
2901 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2902 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2903 + * GNU General Public License for more details.
2905 + * You should have received a copy of the GNU General Public License
2906 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2910 + * branch management
2913 +#include <linux/compat.h>
2914 +#include <linux/statfs.h>
2918 + * free a single branch
2920 +static void au_br_do_free(struct au_branch *br)
2923 + struct au_wbr *wbr;
2924 + struct au_dykey **key;
2926 + au_hnotify_fin_br(br);
2927 + /* always, regardless the mount option */
2928 + au_dr_hino_free(&br->br_dirren);
2931 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2932 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2933 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2934 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2938 + for (i = 0; i < AuBrWh_Last; i++)
2939 + dput(wbr->wbr_wh[i]);
2940 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2941 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2944 + if (br->br_fhsm) {
2945 + au_br_fhsm_fin(br->br_fhsm);
2946 + au_kfree_try_rcu(br->br_fhsm);
2949 + key = br->br_dykey;
2950 + for (i = 0; i < AuBrDynOp; i++, key++)
2956 + /* recursive lock, s_umount of branch's */
2957 + /* synchronize_rcu(); */ /* why? */
2959 + path_put(&br->br_path);
2961 + au_kfree_rcu(wbr);
2962 + au_lcnt_wait_for_fin(&br->br_nfiles);
2963 + au_lcnt_wait_for_fin(&br->br_count);
2964 + /* I don't know why, but percpu_refcount requires this */
2965 + /* synchronize_rcu(); */
2970 + * frees all branches
2972 +void au_br_free(struct au_sbinfo *sbinfo)
2974 + aufs_bindex_t bmax;
2975 + struct au_branch **br;
2977 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2979 + bmax = sbinfo->si_bbot + 1;
2980 + br = sbinfo->si_branch;
2982 + au_br_do_free(*br++);
2986 + * find the index of a branch which is specified by @br_id.
2988 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2990 + aufs_bindex_t bindex, bbot;
2992 + bbot = au_sbbot(sb);
2993 + for (bindex = 0; bindex <= bbot; bindex++)
2994 + if (au_sbr_id(sb, bindex) == br_id)
2999 +/* ---------------------------------------------------------------------- */
3005 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3006 + struct dentry *h_root)
3008 + if (unlikely(h_adding == h_root
3009 + || au_test_loopback_overlap(sb, h_adding)))
3011 + if (h_adding->d_sb != h_root->d_sb)
3013 + return au_test_subdir(h_adding, h_root)
3014 + || au_test_subdir(h_root, h_adding);
3018 + * returns a newly allocated branch. @new_nbranch is a number of branches
3019 + * after adding a branch.
3021 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3024 + struct au_branch *add_branch;
3025 + struct dentry *root;
3026 + struct inode *inode;
3030 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3031 + if (unlikely(!add_branch))
3033 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3034 + if (unlikely(!add_branch->br_xino))
3036 + err = au_hnotify_init_br(add_branch, perm);
3037 + if (unlikely(err))
3040 + if (au_br_writable(perm)) {
3041 + /* may be freed separately at changing the branch permission */
3042 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3044 + if (unlikely(!add_branch->br_wbr))
3048 + if (au_br_fhsm(perm)) {
3049 + err = au_fhsm_br_alloc(add_branch);
3050 + if (unlikely(err))
3054 + root = sb->s_root;
3055 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3057 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3059 + inode = d_inode(root);
3060 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3064 + return add_branch; /* success */
3067 + au_kfree_rcu(add_branch->br_wbr);
3069 + au_hnotify_fin_br(add_branch);
3071 + au_xino_put(add_branch);
3073 + au_kfree_rcu(add_branch);
3075 + return ERR_PTR(err);
3079 + * test if the branch permission is legal or not.
3081 +static int test_br(struct inode *inode, int brperm, char *path)
3085 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3090 + pr_err("write permission for readonly mount or inode, %s\n", path);
3098 + * 0: success, the caller will add it
3099 + * plus: success, it is already unified, the caller should ignore it
3102 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3105 + aufs_bindex_t bbot, bindex;
3106 + struct dentry *root, *h_dentry;
3107 + struct inode *inode, *h_inode;
3109 + root = sb->s_root;
3110 + bbot = au_sbbot(sb);
3111 + if (unlikely(bbot >= 0
3112 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3116 + pr_err("%s duplicated\n", add->pathname);
3121 + err = -ENOSPC; /* -E2BIG; */
3122 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3123 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3124 + pr_err("number of branches exceeded %s\n", add->pathname);
3129 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3130 + pr_err("bad index %d\n", add->bindex);
3134 + inode = d_inode(add->path.dentry);
3136 + if (unlikely(!inode->i_nlink)) {
3137 + pr_err("no existence %s\n", add->pathname);
3142 + if (unlikely(inode->i_sb == sb)) {
3143 + pr_err("%s must be outside\n", add->pathname);
3147 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3148 + pr_err("unsupported filesystem, %s (%s)\n",
3149 + add->pathname, au_sbtype(inode->i_sb));
3153 + if (unlikely(inode->i_sb->s_stack_depth)) {
3154 + pr_err("already stacked, %s (%s)\n",
3155 + add->pathname, au_sbtype(inode->i_sb));
3159 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3160 + if (unlikely(err))
3164 + return 0; /* success */
3167 + for (bindex = 0; bindex <= bbot; bindex++)
3168 + if (unlikely(test_overlap(sb, add->path.dentry,
3169 + au_h_dptr(root, bindex)))) {
3170 + pr_err("%s is overlapped\n", add->pathname);
3175 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3176 + h_dentry = au_h_dptr(root, 0);
3177 + h_inode = d_inode(h_dentry);
3178 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3179 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3180 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3181 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3183 + i_uid_read(inode), i_gid_read(inode),
3184 + (inode->i_mode & S_IALLUGO),
3185 + i_uid_read(h_inode), i_gid_read(h_inode),
3186 + (h_inode->i_mode & S_IALLUGO));
3194 + * initialize or clean the whiteouts for an adding branch
3196 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3199 + int err, old_perm;
3200 + aufs_bindex_t bindex;
3201 + struct inode *h_inode;
3202 + struct au_wbr *wbr;
3203 + struct au_hinode *hdir;
3204 + struct dentry *h_dentry;
3206 + err = vfsub_mnt_want_write(au_br_mnt(br));
3207 + if (unlikely(err))
3211 + old_perm = br->br_perm;
3212 + br->br_perm = new_perm;
3215 + bindex = au_br_index(sb, br->br_id);
3216 + if (0 <= bindex) {
3217 + hdir = au_hi(d_inode(sb->s_root), bindex);
3218 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3220 + h_dentry = au_br_dentry(br);
3221 + h_inode = d_inode(h_dentry);
3222 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3225 + err = au_wh_init(br, sb);
3227 + wbr_wh_write_lock(wbr);
3228 + err = au_wh_init(br, sb);
3229 + wbr_wh_write_unlock(wbr);
3232 + au_hn_inode_unlock(hdir);
3234 + inode_unlock(h_inode);
3235 + vfsub_mnt_drop_write(au_br_mnt(br));
3236 + br->br_perm = old_perm;
3238 + if (!err && wbr && !au_br_writable(new_perm)) {
3239 + au_kfree_rcu(wbr);
3240 + br->br_wbr = NULL;
3247 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3251 + struct kstatfs kst;
3252 + struct au_wbr *wbr;
3255 + au_rw_init(&wbr->wbr_wh_rwsem);
3256 + atomic_set(&wbr->wbr_wh_running, 0);
3259 + * a limit for rmdir/rename a dir
3260 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3262 + err = vfs_statfs(&br->br_path, &kst);
3263 + if (unlikely(err))
3266 + if (kst.f_namelen >= NAME_MAX)
3267 + err = au_br_init_wh(sb, br, perm);
3269 + pr_err("%pd(%s), unsupported namelen %ld\n",
3271 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3277 +/* initialize a new branch */
3278 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3279 + struct au_opt_add *add)
3282 + struct au_branch *brbase;
3284 + struct inode *h_inode;
3287 + br->br_perm = add->perm;
3288 + br->br_path = add->path; /* set first, path_get() later */
3289 + spin_lock_init(&br->br_dykey_lock);
3290 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3291 + au_lcnt_init(&br->br_count, /*release*/NULL);
3292 + br->br_id = au_new_br_id(sb);
3293 + AuDebugOn(br->br_id < 0);
3295 + /* always, regardless the given option */
3296 + err = au_dr_br_init(sb, br, &add->path);
3297 + if (unlikely(err))
3300 + if (au_br_writable(add->perm)) {
3301 + err = au_wbr_init(br, sb, add->perm);
3302 + if (unlikely(err))
3306 + if (au_opt_test(au_mntflags(sb), XINO)) {
3307 + brbase = au_sbr(sb, 0);
3308 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3310 + h_inode = d_inode(add->path.dentry);
3311 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3312 + if (unlikely(err)) {
3313 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3318 + sysaufs_br_init(br);
3319 + path_get(&br->br_path);
3320 + goto out; /* success */
3323 + memset(&br->br_path, 0, sizeof(br->br_path));
3328 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3329 + struct au_branch *br, aufs_bindex_t bbot,
3330 + aufs_bindex_t amount)
3332 + struct au_branch **brp;
3334 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3336 + brp = sbinfo->si_branch + bindex;
3337 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3339 + sbinfo->si_bbot++;
3340 + if (unlikely(bbot < 0))
3341 + sbinfo->si_bbot = 0;
3344 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3345 + aufs_bindex_t bbot, aufs_bindex_t amount)
3347 + struct au_hdentry *hdp;
3349 + AuRwMustWriteLock(&dinfo->di_rwsem);
3351 + hdp = au_hdentry(dinfo, bindex);
3352 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3353 + au_h_dentry_init(hdp);
3355 + if (unlikely(bbot < 0))
3356 + dinfo->di_btop = 0;
3359 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3360 + aufs_bindex_t bbot, aufs_bindex_t amount)
3362 + struct au_hinode *hip;
3364 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3366 + hip = au_hinode(iinfo, bindex);
3367 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3368 + au_hinode_init(hip);
3370 + if (unlikely(bbot < 0))
3371 + iinfo->ii_btop = 0;
3374 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3375 + aufs_bindex_t bindex)
3377 + struct dentry *root, *h_dentry;
3378 + struct inode *root_inode, *h_inode;
3379 + aufs_bindex_t bbot, amount;
3381 + root = sb->s_root;
3382 + root_inode = d_inode(root);
3383 + bbot = au_sbbot(sb);
3384 + amount = bbot + 1 - bindex;
3385 + h_dentry = au_br_dentry(br);
3386 + au_sbilist_lock();
3387 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3388 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3389 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3390 + au_set_h_dptr(root, bindex, dget(h_dentry));
3391 + h_inode = d_inode(h_dentry);
3392 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3393 + au_sbilist_unlock();
3396 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3399 + aufs_bindex_t bbot, add_bindex;
3400 + struct dentry *root, *h_dentry;
3401 + struct inode *root_inode;
3402 + struct au_branch *add_branch;
3404 + root = sb->s_root;
3405 + root_inode = d_inode(root);
3406 + IMustLock(root_inode);
3407 + IiMustWriteLock(root_inode);
3408 + err = test_add(sb, add, remount);
3409 + if (unlikely(err < 0))
3413 + goto out; /* success */
3416 + bbot = au_sbbot(sb);
3417 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3418 + err = PTR_ERR(add_branch);
3419 + if (IS_ERR(add_branch))
3422 + err = au_br_init(add_branch, sb, add);
3423 + if (unlikely(err)) {
3424 + au_br_do_free(add_branch);
3428 + add_bindex = add->bindex;
3429 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3430 + au_br_do_add(sb, add_branch, add_bindex);
3431 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3432 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3434 + h_dentry = add->path.dentry;
3435 + if (!add_bindex) {
3436 + au_cpup_attr_all(root_inode, /*force*/1);
3437 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3439 + au_add_nlink(root_inode, d_inode(h_dentry));
3445 +/* ---------------------------------------------------------------------- */
3447 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3448 + unsigned long long max __maybe_unused,
3451 + unsigned long long n;
3452 + struct file **p, *f;
3453 + struct hlist_bl_head *files;
3454 + struct hlist_bl_node *pos;
3455 + struct au_finfo *finfo;
3459 + files = &au_sbi(sb)->si_files;
3460 + hlist_bl_lock(files);
3461 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3462 + f = finfo->fi_file;
3464 + && !special_file(file_inode(f)->i_mode)) {
3468 + AuDebugOn(n > max);
3471 + hlist_bl_unlock(files);
3476 +static struct file **au_farray_alloc(struct super_block *sb,
3477 + unsigned long long *max)
3479 + struct au_sbinfo *sbi;
3482 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3483 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3486 +static void au_farray_free(struct file **a, unsigned long long max)
3488 + unsigned long long ull;
3490 + for (ull = 0; ull < max; ull++)
3496 +/* ---------------------------------------------------------------------- */
3502 +/* to show the line number, do not make it inlined function */
3503 +#define AuVerbose(do_info, fmt, ...) do { \
3505 + pr_info(fmt, ##__VA_ARGS__); \
3508 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3509 + aufs_bindex_t bbot)
3511 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3514 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3515 + aufs_bindex_t bbot)
3517 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3521 + * test if the branch is deletable or not.
3523 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3524 + unsigned int sigen, const unsigned int verbose)
3526 + int err, i, j, ndentry;
3527 + aufs_bindex_t btop, bbot;
3528 + struct au_dcsub_pages dpages;
3529 + struct au_dpage *dpage;
3532 + err = au_dpages_init(&dpages, GFP_NOFS);
3533 + if (unlikely(err))
3535 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3536 + if (unlikely(err))
3539 + for (i = 0; !err && i < dpages.ndpage; i++) {
3540 + dpage = dpages.dpages + i;
3541 + ndentry = dpage->ndentry;
3542 + for (j = 0; !err && j < ndentry; j++) {
3543 + d = dpage->dentries[j];
3544 + AuDebugOn(au_dcount(d) <= 0);
3545 + if (!au_digen_test(d, sigen)) {
3546 + di_read_lock_child(d, AuLock_IR);
3547 + if (unlikely(au_dbrange_test(d))) {
3548 + di_read_unlock(d, AuLock_IR);
3552 + di_write_lock_child(d);
3553 + if (unlikely(au_dbrange_test(d))) {
3554 + di_write_unlock(d);
3557 + err = au_reval_dpath(d, sigen);
3559 + di_downgrade_lock(d, AuLock_IR);
3561 + di_write_unlock(d);
3566 + /* AuDbgDentry(d); */
3567 + btop = au_dbtop(d);
3568 + bbot = au_dbbot(d);
3569 + if (btop <= bindex
3571 + && au_h_dptr(d, bindex)
3572 + && au_test_dbusy(d, btop, bbot)) {
3574 + AuVerbose(verbose, "busy %pd\n", d);
3577 + di_read_unlock(d, AuLock_IR);
3582 + au_dpages_free(&dpages);
3587 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3588 + unsigned int sigen, const unsigned int verbose)
3591 + unsigned long long max, ull;
3592 + struct inode *i, **array;
3593 + aufs_bindex_t btop, bbot;
3595 + array = au_iarray_alloc(sb, &max);
3596 + err = PTR_ERR(array);
3597 + if (IS_ERR(array))
3601 + AuDbg("b%d\n", bindex);
3602 + for (ull = 0; !err && ull < max; ull++) {
3606 + if (i->i_ino == AUFS_ROOT_INO)
3609 + /* AuDbgInode(i); */
3610 + if (au_iigen(i, NULL) == sigen)
3611 + ii_read_lock_child(i);
3613 + ii_write_lock_child(i);
3614 + err = au_refresh_hinode_self(i);
3617 + ii_downgrade_lock(i);
3619 + ii_write_unlock(i);
3624 + btop = au_ibtop(i);
3625 + bbot = au_ibbot(i);
3626 + if (btop <= bindex
3628 + && au_h_iptr(i, bindex)
3629 + && au_test_ibusy(i, btop, bbot)) {
3631 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3634 + ii_read_unlock(i);
3636 + au_iarray_free(array, max);
3642 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3643 + const unsigned int verbose)
3646 + unsigned int sigen;
3648 + sigen = au_sigen(root->d_sb);
3649 + DiMustNoWaiters(root);
3650 + IiMustNoWaiters(d_inode(root));
3651 + di_write_unlock(root);
3652 + err = test_dentry_busy(root, bindex, sigen, verbose);
3654 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3655 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3660 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3661 + struct file **to_free, int *idx)
3664 + unsigned char matched, root;
3665 + aufs_bindex_t bindex, bbot;
3666 + struct au_fidir *fidir;
3667 + struct au_hfile *hfile;
3670 + root = IS_ROOT(file->f_path.dentry);
3673 + to_free[*idx] = file;
3679 + fidir = au_fi(file)->fi_hdir;
3680 + AuDebugOn(!fidir);
3681 + bbot = au_fbbot_dir(file);
3682 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3683 + hfile = fidir->fd_hfile + bindex;
3684 + if (!hfile->hf_file)
3687 + if (hfile->hf_br->br_id == br_id) {
3699 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3700 + struct file **to_free, int opened)
3703 + unsigned long long ull, max;
3704 + aufs_bindex_t btop;
3705 + struct file *file, **array;
3706 + struct dentry *root;
3707 + struct au_hfile *hfile;
3709 + array = au_farray_alloc(sb, &max);
3710 + err = PTR_ERR(array);
3711 + if (IS_ERR(array))
3716 + root = sb->s_root;
3717 + di_write_unlock(root);
3718 + for (ull = 0; ull < max; ull++) {
3719 + file = array[ull];
3720 + if (unlikely(!file))
3723 + /* AuDbg("%pD\n", file); */
3724 + fi_read_lock(file);
3725 + btop = au_fbtop(file);
3726 + if (!d_is_dir(file->f_path.dentry)) {
3727 + hfile = &au_fi(file)->fi_htop;
3728 + if (hfile->hf_br->br_id == br_id)
3731 + err = test_dir_busy(file, br_id, to_free, &idx);
3732 + fi_read_unlock(file);
3733 + if (unlikely(err))
3736 + di_write_lock_child(root);
3737 + au_farray_free(array, max);
3738 + AuDebugOn(idx > opened);
3744 +static void br_del_file(struct file **to_free, unsigned long long opened,
3745 + aufs_bindex_t br_id)
3747 + unsigned long long ull;
3748 + aufs_bindex_t bindex, btop, bbot, bfound;
3749 + struct file *file;
3750 + struct au_fidir *fidir;
3751 + struct au_hfile *hfile;
3753 + for (ull = 0; ull < opened; ull++) {
3754 + file = to_free[ull];
3755 + if (unlikely(!file))
3758 + /* AuDbg("%pD\n", file); */
3759 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3761 + fidir = au_fi(file)->fi_hdir;
3762 + AuDebugOn(!fidir);
3763 + fi_write_lock(file);
3764 + btop = au_fbtop(file);
3765 + bbot = au_fbbot_dir(file);
3766 + for (bindex = btop; bindex <= bbot; bindex++) {
3767 + hfile = fidir->fd_hfile + bindex;
3768 + if (!hfile->hf_file)
3771 + if (hfile->hf_br->br_id == br_id) {
3776 + AuDebugOn(bfound < 0);
3777 + au_set_h_fptr(file, bfound, NULL);
3778 + if (bfound == btop) {
3779 + for (btop++; btop <= bbot; btop++)
3780 + if (au_hf_dir(file, btop)) {
3781 + au_set_fbtop(file, btop);
3785 + fi_write_unlock(file);
3789 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3790 + const aufs_bindex_t bindex,
3791 + const aufs_bindex_t bbot)
3793 + struct au_branch **brp, **p;
3795 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3797 + brp = sbinfo->si_branch + bindex;
3798 + if (bindex < bbot)
3799 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3800 + sbinfo->si_branch[0 + bbot] = NULL;
3801 + sbinfo->si_bbot--;
3803 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3806 + sbinfo->si_branch = p;
3807 + /* harmless error */
3810 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3811 + const aufs_bindex_t bbot)
3813 + struct au_hdentry *hdp, *p;
3815 + AuRwMustWriteLock(&dinfo->di_rwsem);
3817 + hdp = au_hdentry(dinfo, bindex);
3818 + if (bindex < bbot)
3819 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3820 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3823 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3826 + dinfo->di_hdentry = p;
3827 + /* harmless error */
3830 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3831 + const aufs_bindex_t bbot)
3833 + struct au_hinode *hip, *p;
3835 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3837 + hip = au_hinode(iinfo, bindex);
3838 + if (bindex < bbot)
3839 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3840 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3843 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3846 + iinfo->ii_hinode = p;
3847 + /* harmless error */
3850 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3851 + struct au_branch *br)
3853 + aufs_bindex_t bbot;
3854 + struct au_sbinfo *sbinfo;
3855 + struct dentry *root, *h_root;
3856 + struct inode *inode, *h_inode;
3857 + struct au_hinode *hinode;
3859 + SiMustWriteLock(sb);
3861 + root = sb->s_root;
3862 + inode = d_inode(root);
3863 + sbinfo = au_sbi(sb);
3864 + bbot = sbinfo->si_bbot;
3866 + h_root = au_h_dptr(root, bindex);
3867 + hinode = au_hi(inode, bindex);
3868 + h_inode = au_igrab(hinode->hi_inode);
3871 + au_sbilist_lock();
3872 + au_br_do_del_brp(sbinfo, bindex, bbot);
3873 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3874 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3875 + au_sbilist_unlock();
3877 + /* ignore an error */
3878 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3882 + au_br_do_free(br);
3885 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3886 + unsigned long long max, void *arg)
3891 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3894 + unsigned long long opened;
3895 + unsigned int mnt_flags;
3896 + aufs_bindex_t bindex, bbot, br_id;
3897 + unsigned char do_wh, verbose;
3898 + struct au_branch *br;
3899 + struct au_wbr *wbr;
3900 + struct dentry *root;
3901 + struct file **to_free;
3906 + root = sb->s_root;
3907 + bindex = au_find_dbindex(root, del->h_path.dentry);
3910 + goto out; /* success */
3912 + pr_err("%s no such branch\n", del->pathname);
3915 + AuDbg("bindex b%d\n", bindex);
3918 + mnt_flags = au_mntflags(sb);
3919 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3920 + bbot = au_sbbot(sb);
3921 + if (unlikely(!bbot)) {
3922 + AuVerbose(verbose, "no more branches left\n");
3926 + br = au_sbr(sb, bindex);
3927 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3928 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3929 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3933 + br_id = br->br_id;
3934 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3935 + if (unlikely(opened)) {
3936 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3937 + err = PTR_ERR(to_free);
3938 + if (IS_ERR(to_free))
3941 + err = test_file_busy(sb, br_id, to_free, opened);
3942 + if (unlikely(err)) {
3943 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3949 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3951 + /* instead of WbrWhMustWriteLock(wbr) */
3952 + SiMustWriteLock(sb);
3953 + for (i = 0; i < AuBrWh_Last; i++) {
3954 + dput(wbr->wbr_wh[i]);
3955 + wbr->wbr_wh[i] = NULL;
3959 + err = test_children_busy(root, bindex, verbose);
3960 + if (unlikely(err)) {
3969 + * now we confirmed the branch is deletable.
3970 + * let's free the remaining opened dirs on the branch.
3972 + di_write_unlock(root);
3973 + br_del_file(to_free, opened, br_id);
3974 + di_write_lock_child(root);
3977 + sysaufs_brs_del(sb, bindex); /* remove successors */
3978 + dbgaufs_xino_del(br); /* remove one */
3979 + au_br_do_del(sb, bindex, br);
3980 + sysaufs_brs_add(sb, bindex); /* append successors */
3981 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
3984 + au_cpup_attr_all(d_inode(root), /*force*/1);
3985 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3987 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3988 + if (au_opt_test(mnt_flags, PLINK))
3989 + au_plink_half_refresh(sb, br_id);
3991 + goto out; /* success */
3995 + rerr = au_br_init_wh(sb, br, br->br_perm);
3997 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3998 + del->pathname, rerr);
4001 + au_farray_free(to_free, opened);
4005 +/* ---------------------------------------------------------------------- */
4007 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4010 + aufs_bindex_t btop, bbot;
4011 + struct aufs_ibusy ibusy;
4012 + struct inode *inode, *h_inode;
4015 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4018 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4020 + /* VERIFY_WRITE */
4021 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4022 + if (unlikely(err)) {
4029 + si_read_lock(sb, AuLock_FLUSH);
4030 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4034 + ibusy.h_ino = 0; /* invalid */
4035 + inode = ilookup(sb, ibusy.ino);
4037 + || inode->i_ino == AUFS_ROOT_INO
4038 + || au_is_bad_inode(inode))
4041 + ii_read_lock_child(inode);
4042 + btop = au_ibtop(inode);
4043 + bbot = au_ibbot(inode);
4044 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4045 + h_inode = au_h_iptr(inode, ibusy.bindex);
4046 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4047 + ibusy.h_ino = h_inode->i_ino;
4049 + ii_read_unlock(inode);
4053 + si_read_unlock(sb);
4055 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4056 + if (unlikely(err)) {
4065 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4067 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4070 +#ifdef CONFIG_COMPAT
4071 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4073 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4077 +/* ---------------------------------------------------------------------- */
4080 + * change a branch permission
4083 +static void au_warn_ima(void)
4086 + /* since it doesn't support mark_files_ro() */
4087 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4091 +static int do_need_sigen_inc(int a, int b)
4093 + return au_br_whable(a) && !au_br_whable(b);
4096 +static int need_sigen_inc(int old, int new)
4098 + return do_need_sigen_inc(old, new)
4099 + || do_need_sigen_inc(new, old);
4102 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4105 + unsigned int mnt_flags;
4106 + unsigned long long ull, max;
4107 + aufs_bindex_t br_id;
4108 + unsigned char verbose, writer;
4109 + struct file *file, *hf, **array;
4110 + struct au_hfile *hfile;
4111 + struct inode *h_inode;
4113 + mnt_flags = au_mntflags(sb);
4114 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4116 + array = au_farray_alloc(sb, &max);
4117 + err = PTR_ERR(array);
4118 + if (IS_ERR(array))
4122 + br_id = au_sbr_id(sb, bindex);
4123 + for (ull = 0; ull < max; ull++) {
4124 + file = array[ull];
4125 + if (unlikely(!file))
4128 + /* AuDbg("%pD\n", file); */
4129 + fi_read_lock(file);
4130 + if (unlikely(au_test_mmapped(file))) {
4132 + AuVerbose(verbose, "mmapped %pD\n", file);
4134 + FiMustNoWaiters(file);
4135 + fi_read_unlock(file);
4139 + hfile = &au_fi(file)->fi_htop;
4140 + hf = hfile->hf_file;
4141 + if (!d_is_reg(file->f_path.dentry)
4142 + || !(file->f_mode & FMODE_WRITE)
4143 + || hfile->hf_br->br_id != br_id
4144 + || !(hf->f_mode & FMODE_WRITE))
4145 + array[ull] = NULL;
4151 + FiMustNoWaiters(file);
4152 + fi_read_unlock(file);
4160 + for (ull = 0; ull < max; ull++) {
4161 + file = array[ull];
4165 + /* todo: already flushed? */
4167 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4168 + * approach which resets f_mode and calls mnt_drop_write() and
4169 + * file_release_write() for each file, because the branch
4170 + * attribute in aufs world is totally different from the native
4173 + /* fi_read_lock(file); */
4174 + hfile = &au_fi(file)->fi_htop;
4175 + hf = hfile->hf_file;
4176 + /* fi_read_unlock(file); */
4177 + spin_lock(&hf->f_lock);
4178 + writer = !!(hf->f_mode & FMODE_WRITER);
4179 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4180 + spin_unlock(&hf->f_lock);
4182 + h_inode = file_inode(hf);
4183 + if (hf->f_mode & FMODE_READ)
4184 + i_readcount_inc(h_inode);
4185 + put_write_access(h_inode);
4186 + __mnt_drop_write(hf->f_path.mnt);
4191 + au_farray_free(array, max);
4197 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4201 + aufs_bindex_t bindex;
4202 + struct dentry *root;
4203 + struct au_branch *br;
4204 + struct au_br_fhsm *bf;
4206 + root = sb->s_root;
4207 + bindex = au_find_dbindex(root, mod->h_root);
4210 + return 0; /* success */
4212 + pr_err("%s no such branch\n", mod->path);
4215 + AuDbg("bindex b%d\n", bindex);
4217 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4218 + if (unlikely(err))
4221 + br = au_sbr(sb, bindex);
4222 + AuDebugOn(mod->h_root != au_br_dentry(br));
4223 + if (br->br_perm == mod->perm)
4224 + return 0; /* success */
4226 + /* pre-allocate for non-fhsm --> fhsm */
4228 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4229 + err = au_fhsm_br_alloc(br);
4230 + if (unlikely(err))
4233 + br->br_fhsm = NULL;
4236 + if (au_br_writable(br->br_perm)) {
4237 + /* remove whiteout base */
4238 + err = au_br_init_wh(sb, br, mod->perm);
4239 + if (unlikely(err))
4242 + if (!au_br_writable(mod->perm)) {
4243 + /* rw --> ro, file might be mmapped */
4244 + DiMustNoWaiters(root);
4245 + IiMustNoWaiters(d_inode(root));
4246 + di_write_unlock(root);
4247 + err = au_br_mod_files_ro(sb, bindex);
4248 + /* aufs_write_lock() calls ..._child() */
4249 + di_write_lock_child(root);
4251 + if (unlikely(err)) {
4253 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4256 + rerr = au_wbr_init(br, sb, br->br_perm);
4257 + if (unlikely(rerr)) {
4258 + AuIOErr("nested error %d (%d)\n",
4260 + br->br_perm = mod->perm;
4264 + } else if (au_br_writable(mod->perm)) {
4267 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4269 + err = au_wbr_init(br, sb, mod->perm);
4270 + if (unlikely(err)) {
4271 + au_kfree_rcu(br->br_wbr);
4272 + br->br_wbr = NULL;
4276 + if (unlikely(err))
4279 + if (au_br_fhsm(br->br_perm)) {
4280 + if (!au_br_fhsm(mod->perm)) {
4281 + /* fhsm --> non-fhsm */
4282 + au_br_fhsm_fin(br->br_fhsm);
4283 + au_kfree_rcu(br->br_fhsm);
4284 + br->br_fhsm = NULL;
4286 + } else if (au_br_fhsm(mod->perm))
4287 + /* non-fhsm --> fhsm */
4290 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4291 + br->br_perm = mod->perm;
4292 + goto out; /* success */
4295 + au_kfree_try_rcu(bf);
4301 +/* ---------------------------------------------------------------------- */
4303 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4306 + struct kstatfs kstfs;
4308 + err = vfs_statfs(&br->br_path, &kstfs);
4310 + stfs->f_blocks = kstfs.f_blocks;
4311 + stfs->f_bavail = kstfs.f_bavail;
4312 + stfs->f_files = kstfs.f_files;
4313 + stfs->f_ffree = kstfs.f_ffree;
4318 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4319 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4320 +++ linux/fs/aufs/branch.h 2023-08-28 12:34:39.956636132 +0200
4322 +/* SPDX-License-Identifier: GPL-2.0 */
4324 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4326 + * This program is free software; you can redistribute it and/or modify
4327 + * it under the terms of the GNU General Public License as published by
4328 + * the Free Software Foundation; either version 2 of the License, or
4329 + * (at your option) any later version.
4331 + * This program is distributed in the hope that it will be useful,
4332 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4333 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4334 + * GNU General Public License for more details.
4336 + * You should have received a copy of the GNU General Public License
4337 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4341 + * branch filesystems and xino for them
4344 +#ifndef __AUFS_BRANCH_H__
4345 +#define __AUFS_BRANCH_H__
4349 +#include <linux/mount.h>
4350 +#include "dirren.h"
4356 +/* ---------------------------------------------------------------------- */
4360 + struct file **xi_file;
4361 + unsigned int xi_nfile;
4367 + /* reserved for future use */
4368 + /* unsigned long *bitmap; */
4369 + wait_queue_head_t wqh;
4372 + struct mutex xi_mtx; /* protects xi_file array */
4373 + struct hlist_bl_head xi_writing;
4375 + atomic_t xi_truncating;
4377 + struct kref xi_kref;
4380 +/* File-based Hierarchical Storage Management */
4381 +struct au_br_fhsm {
4382 +#ifdef CONFIG_AUFS_FHSM
4383 + struct mutex bf_lock;
4384 + unsigned long bf_jiffy;
4385 + struct aufs_stfs bf_stfs;
4390 +/* members for writable branch only */
4391 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4393 + struct au_rwsem wbr_wh_rwsem;
4394 + struct dentry *wbr_wh[AuBrWh_Last];
4395 + atomic_t wbr_wh_running;
4396 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4397 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4398 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4401 + unsigned long long wbr_bytes;
4404 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4405 +#define AuBrDynOp (AuDyLast * 4)
4407 +#ifdef CONFIG_AUFS_HFSNOTIFY
4408 +/* support for asynchronous destruction */
4409 +struct au_br_hfsnotify {
4410 + struct fsnotify_group *hfsn_group;
4414 +/* sysfs entries */
4415 +struct au_brsysfs {
4417 + struct attribute attr;
4426 +/* protected by superblock rwsem */
4428 + struct au_xino *br_xino;
4430 + aufs_bindex_t br_id;
4433 + struct path br_path;
4434 + spinlock_t br_dykey_lock;
4435 + struct au_dykey *br_dykey[AuBrDynOp];
4436 + au_lcnt_t br_nfiles; /* opened files */
4437 + au_lcnt_t br_count; /* in-use for other */
4439 + struct au_wbr *br_wbr;
4440 + struct au_br_fhsm *br_fhsm;
4442 +#ifdef CONFIG_AUFS_HFSNOTIFY
4443 + struct au_br_hfsnotify *br_hfsn;
4446 +#ifdef CONFIG_SYSFS
4447 + /* entries under sysfs per mount-point */
4448 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4451 +#ifdef CONFIG_DEBUG_FS
4452 + struct dentry *br_dbgaufs; /* xino */
4455 + struct au_dr_br br_dirren;
4458 +/* ---------------------------------------------------------------------- */
4460 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4462 + return br->br_path.mnt;
4465 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4467 + return br->br_path.dentry;
4470 +static inline struct mnt_idmap *au_br_idmap(struct au_branch *br)
4472 + return mnt_idmap(br->br_path.mnt);
4475 +static inline struct super_block *au_br_sb(struct au_branch *br)
4477 + return au_br_mnt(br)->mnt_sb;
4480 +static inline int au_br_rdonly(struct au_branch *br)
4482 + return (sb_rdonly(au_br_sb(br))
4483 + || !au_br_writable(br->br_perm))
4487 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4489 +#ifdef CONFIG_AUFS_HNOTIFY
4490 + return !(brperm & AuBrPerm_RR);
4496 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4498 + int err, exec_flag;
4501 + exec_flag = oflag & __FMODE_EXEC;
4502 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4508 +static inline void au_xino_get(struct au_branch *br)
4510 + struct au_xino *xi;
4514 + kref_get(&xi->xi_kref);
4517 +static inline int au_xino_count(struct au_branch *br)
4520 + struct au_xino *xi;
4525 + v = kref_read(&xi->xi_kref);
4530 +/* ---------------------------------------------------------------------- */
4534 +void au_br_free(struct au_sbinfo *sinfo);
4535 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4537 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4539 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4540 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4541 +#ifdef CONFIG_COMPAT
4542 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4545 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4548 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4551 +static const loff_t au_loff_max = LLONG_MAX;
4553 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4554 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4556 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4557 + struct file *copy_src);
4559 + struct au_xino *xi; /* switch between xino and xigen */
4561 + struct path *base;
4562 + struct file *copy_src;
4564 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4566 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4568 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4570 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4571 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4573 +int au_xib_trunc(struct super_block *sb);
4574 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4576 +struct au_xino *au_xino_alloc(unsigned int nfile);
4577 +int au_xino_put(struct au_branch *br);
4578 +struct file *au_xino_file1(struct au_xino *xi);
4580 +struct au_opt_xino;
4581 +void au_xino_clr(struct super_block *sb);
4582 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4583 +struct file *au_xino_def(struct super_block *sb);
4584 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4585 + struct path *base);
4587 +ino_t au_xino_new_ino(struct super_block *sb);
4588 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4590 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4591 + ino_t h_ino, int idx);
4592 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4595 +int au_xino_path(struct seq_file *seq, struct file *file);
4597 +/* ---------------------------------------------------------------------- */
4599 +/* @idx is signed to accept -1 meaning the first file */
4600 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4602 + struct file *file;
4609 + if (idx < xi->xi_nfile)
4610 + file = xi->xi_file[idx];
4612 + file = au_xino_file1(xi);
4618 +/* ---------------------------------------------------------------------- */
4620 +/* Superblock to branch */
4622 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4624 + return au_sbr(sb, bindex)->br_id;
4628 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4630 + return au_br_mnt(au_sbr(sb, bindex));
4634 +struct mnt_idmap *au_sbr_idmap(struct super_block *sb, aufs_bindex_t bindex)
4636 + return au_br_idmap(au_sbr(sb, bindex));
4640 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4642 + return au_br_sb(au_sbr(sb, bindex));
4645 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4647 + return au_sbr(sb, bindex)->br_perm;
4650 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4652 + return au_br_whable(au_sbr_perm(sb, bindex));
4655 +/* ---------------------------------------------------------------------- */
4657 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4658 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4659 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4660 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4662 +#define wbr_wh_read_trylock_nested(wbr) \
4663 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4664 +#define wbr_wh_write_trylock_nested(wbr) \
4665 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4668 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4669 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4670 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4672 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4673 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4674 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4676 +/* ---------------------------------------------------------------------- */
4678 +#ifdef CONFIG_AUFS_FHSM
4679 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4681 + mutex_init(&brfhsm->bf_lock);
4682 + brfhsm->bf_jiffy = 0;
4683 + brfhsm->bf_readable = 0;
4686 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4688 + mutex_destroy(&brfhsm->bf_lock);
4691 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4692 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4695 +#endif /* __KERNEL__ */
4696 +#endif /* __AUFS_BRANCH_H__ */
4697 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4698 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4699 +++ linux/fs/aufs/conf.mk 2022-11-05 23:02:18.959222617 +0100
4701 +# SPDX-License-Identifier: GPL-2.0
4703 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4707 +AuConfStr += ${1}=${${1}}
4711 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4713 + HNOTIFY HFSNOTIFY \
4725 +$(foreach i, ${AuConfAll}, \
4726 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4728 +AuConfName = ${obj}/conf.str
4729 +${AuConfName}.tmp: FORCE
4730 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4731 +${AuConfName}: ${AuConfName}.tmp
4732 + @diff -q $< $@ > /dev/null 2>&1 || { \
4733 + echo ' GEN ' $@; \
4737 +clean-files += ${AuConfName} ${AuConfName}.tmp
4738 +${obj}/sysfs.o: ${AuConfName}
4740 +-include ${srctree}/${src}/conf_priv.mk
4741 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4742 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4743 +++ linux/fs/aufs/cpup.c 2023-08-28 12:34:39.956636132 +0200
4745 +// SPDX-License-Identifier: GPL-2.0
4747 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4749 + * This program is free software; you can redistribute it and/or modify
4750 + * it under the terms of the GNU General Public License as published by
4751 + * the Free Software Foundation; either version 2 of the License, or
4752 + * (at your option) any later version.
4754 + * This program is distributed in the hope that it will be useful,
4755 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4756 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4757 + * GNU General Public License for more details.
4759 + * You should have received a copy of the GNU General Public License
4760 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4764 + * copy-up functions, see wbr_policy.c for copy-down
4767 +#include <linux/fs_stack.h>
4768 +#include <linux/mm.h>
4769 +#include <linux/task_work.h>
4772 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4774 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4775 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4777 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4779 + dst->i_flags |= iflags & ~mask;
4780 + if (au_test_fs_notime(dst->i_sb))
4781 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4784 +void au_cpup_attr_timesizes(struct inode *inode)
4786 + struct inode *h_inode;
4788 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4789 + fsstack_copy_attr_times(inode, h_inode);
4790 + fsstack_copy_inode_size(inode, h_inode);
4793 +void au_cpup_attr_nlink(struct inode *inode, int force)
4795 + struct inode *h_inode;
4796 + struct super_block *sb;
4797 + aufs_bindex_t bindex, bbot;
4800 + bindex = au_ibtop(inode);
4801 + h_inode = au_h_iptr(inode, bindex);
4803 + && !S_ISDIR(h_inode->i_mode)
4804 + && au_opt_test(au_mntflags(sb), PLINK)
4805 + && au_plink_test(inode))
4809 + * 0 can happen in revalidating.
4810 + * h_inode->i_mutex may not be held here, but it is harmless since once
4811 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4813 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4814 + * the incorrect link count.
4816 + set_nlink(inode, h_inode->i_nlink);
4819 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4820 + * it may includes whplink directory.
4822 + if (S_ISDIR(h_inode->i_mode)) {
4823 + bbot = au_ibbot(inode);
4824 + for (bindex++; bindex <= bbot; bindex++) {
4825 + h_inode = au_h_iptr(inode, bindex);
4827 + au_add_nlink(inode, h_inode);
4832 +void au_cpup_attr_changeable(struct inode *inode)
4834 + struct inode *h_inode;
4836 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4837 + inode->i_mode = h_inode->i_mode;
4838 + inode->i_uid = h_inode->i_uid;
4839 + inode->i_gid = h_inode->i_gid;
4840 + au_cpup_attr_timesizes(inode);
4841 + au_cpup_attr_flags(inode, h_inode->i_flags);
4844 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4846 + struct au_iinfo *iinfo = au_ii(inode);
4848 + IiMustWriteLock(inode);
4850 + iinfo->ii_higen = h_inode->i_generation;
4851 + iinfo->ii_hsb1 = h_inode->i_sb;
4854 +void au_cpup_attr_all(struct inode *inode, int force)
4856 + struct inode *h_inode;
4858 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4859 + au_cpup_attr_changeable(inode);
4860 + if (inode->i_nlink > 0)
4861 + au_cpup_attr_nlink(inode, force);
4862 + inode->i_rdev = h_inode->i_rdev;
4863 + inode->i_blkbits = h_inode->i_blkbits;
4864 + au_cpup_igen(inode, h_inode);
4867 +/* ---------------------------------------------------------------------- */
4869 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4871 +/* keep the timestamps of the parent dir when cpup */
4872 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4873 + struct path *h_path)
4875 + struct inode *h_inode;
4877 + dt->dt_dentry = dentry;
4878 + dt->dt_h_path = *h_path;
4879 + h_inode = d_inode(h_path->dentry);
4880 + dt->dt_atime = h_inode->i_atime;
4881 + dt->dt_mtime = h_inode->i_mtime;
4885 +void au_dtime_revert(struct au_dtime *dt)
4887 + struct iattr attr;
4890 + attr.ia_atime = dt->dt_atime;
4891 + attr.ia_mtime = dt->dt_mtime;
4892 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4893 + | ATTR_ATIME | ATTR_ATIME_SET;
4895 + /* no delegation since this is a directory */
4896 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4897 + if (unlikely(err))
4898 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4901 +/* ---------------------------------------------------------------------- */
4903 +/* internal use only */
4904 +struct au_cpup_reg_attr {
4907 + unsigned int iflags; /* inode->i_flags */
4910 +static noinline_for_stack
4911 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4912 + struct au_cpup_reg_attr *h_src_attr)
4914 + int err, sbits, icex;
4915 + unsigned int mnt_flags;
4916 + unsigned char verbose;
4918 + struct path h_path;
4919 + struct inode *h_isrc, *h_idst;
4920 + struct kstat *h_st;
4921 + struct au_branch *br;
4923 + br = au_sbr(dst->d_sb, bindex);
4924 + h_path.mnt = au_br_mnt(br);
4925 + h_path.dentry = au_h_dptr(dst, bindex);
4926 + h_idst = d_inode(h_path.dentry);
4927 + h_isrc = d_inode(h_src->dentry);
4928 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4929 + | ATTR_ATIME | ATTR_MTIME
4930 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4931 + if (h_src_attr && h_src_attr->valid) {
4932 + h_st = &h_src_attr->st;
4933 + ia.ia_uid = h_st->uid;
4934 + ia.ia_gid = h_st->gid;
4935 + ia.ia_atime = h_st->atime;
4936 + ia.ia_mtime = h_st->mtime;
4937 + if (h_idst->i_mode != h_st->mode
4938 + && !S_ISLNK(h_idst->i_mode)) {
4939 + ia.ia_valid |= ATTR_MODE;
4940 + ia.ia_mode = h_st->mode;
4942 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4943 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4945 + ia.ia_uid = h_isrc->i_uid;
4946 + ia.ia_gid = h_isrc->i_gid;
4947 + ia.ia_atime = h_isrc->i_atime;
4948 + ia.ia_mtime = h_isrc->i_mtime;
4949 + if (h_idst->i_mode != h_isrc->i_mode
4950 + && !S_ISLNK(h_idst->i_mode)) {
4951 + ia.ia_valid |= ATTR_MODE;
4952 + ia.ia_mode = h_isrc->i_mode;
4954 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4955 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4957 + /* no delegation since it is just created */
4958 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4960 + /* is this nfs only? */
4961 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4962 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4963 + ia.ia_mode = h_isrc->i_mode;
4964 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4967 + icex = br->br_perm & AuBrAttr_ICEX;
4969 + mnt_flags = au_mntflags(dst->d_sb);
4970 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4971 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
4977 +/* ---------------------------------------------------------------------- */
4979 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4980 + char *buf, unsigned long blksize)
4983 + size_t sz, rbytes, wbytes;
4984 + unsigned char all_zero;
4986 + struct inode *h_inode;
4987 + /* reduce stack usage */
4990 + zp = page_address(ZERO_PAGE(0));
4991 + if (unlikely(!zp))
4992 + return -ENOMEM; /* possible? */
4997 + AuDbg("len %lld\n", len);
4999 + if (len < blksize)
5003 + /* todo: signal_pending? */
5004 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5005 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5008 + if (unlikely(err < 0))
5012 + if (len >= rbytes && rbytes == blksize)
5013 + all_zero = !memcmp(buf, zp, rbytes);
5020 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5022 + /* todo: signal_pending? */
5023 + if (unlikely(err == -EAGAIN || err == -EINTR))
5025 + if (unlikely(err < 0))
5030 + if (unlikely(err < 0))
5036 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5038 + if (unlikely(res < 0))
5045 + /* the last block may be a hole */
5046 + if (!err && all_zero) {
5047 + AuLabel(last hole);
5050 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5051 + /* nfs requires this step to make last hole */
5052 + /* is this only nfs? */
5054 + /* todo: signal_pending? */
5055 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5056 + } while (err == -EAGAIN || err == -EINTR);
5063 + ia->ia_size = dst->f_pos;
5064 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5065 + ia->ia_file = dst;
5066 + h_inode = file_inode(dst);
5067 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5068 + /* no delegation since it is just created */
5069 + err = vfsub_notify_change(&dst->f_path, ia,
5070 + /*delegated*/NULL);
5071 + inode_unlock(h_inode);
5078 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5081 + unsigned long blksize;
5082 + unsigned char do_kfree;
5084 + struct super_block *h_sb;
5087 + h_sb = file_inode(dst)->i_sb;
5088 + blksize = h_sb->s_blocksize;
5089 + if (!blksize || PAGE_SIZE < blksize)
5090 + blksize = PAGE_SIZE;
5091 + AuDbg("blksize %lu\n", blksize);
5092 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5094 + buf = kmalloc(blksize, GFP_NOFS);
5096 + buf = (void *)__get_free_page(GFP_NOFS);
5097 + if (unlikely(!buf))
5100 + if (len > (1 << 22))
5101 + AuDbg("copying a large file %lld\n", (long long)len);
5105 + err = au_do_copy_file(dst, src, len, buf, blksize);
5107 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5108 + au_kfree_do_rcu(buf);
5110 + free_page((unsigned long)buf);
5116 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5119 + struct super_block *h_src_sb;
5120 + struct inode *h_src_inode;
5122 + h_src_inode = file_inode(src);
5123 + h_src_sb = h_src_inode->i_sb;
5125 + /* XFS acquires inode_lock */
5126 + if (!au_test_xfs(h_src_sb))
5127 + err = au_copy_file(dst, src, len);
5129 + inode_unlock_shared(h_src_inode);
5130 + err = au_copy_file(dst, src, len);
5131 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5137 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5141 + struct super_block *h_src_sb;
5142 + struct inode *h_src_inode;
5144 + h_src_inode = file_inode(src);
5145 + h_src_sb = h_src_inode->i_sb;
5146 + if (h_src_sb != file_inode(dst)->i_sb
5147 + || !dst->f_op->remap_file_range) {
5148 + err = au_do_copy(dst, src, len);
5152 + if (!au_test_nfs(h_src_sb)) {
5153 + inode_unlock_shared(h_src_inode);
5154 + lo = vfsub_clone_file_range(src, dst, len);
5155 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5157 + lo = vfsub_clone_file_range(src, dst, len);
5160 + goto out; /* success */
5161 + } else if (lo >= 0)
5162 + /* todo: possible? */
5163 + /* paritially succeeded */
5164 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5165 + else if (lo != -EOPNOTSUPP) {
5166 + /* older XFS has a condition in cloning */
5171 + /* the backend fs on NFS may not support cloning */
5172 + err = au_do_copy(dst, src, len);
5180 + * to support a sparse file which is opened with O_APPEND,
5181 + * we need to close the file.
5183 +static int au_cp_regular(struct au_cp_generic *cpg)
5186 + enum { SRC, DST };
5188 + aufs_bindex_t bindex;
5189 + unsigned int flags;
5190 + struct dentry *dentry;
5192 + struct file *file;
5195 + .bindex = cpg->bsrc,
5196 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5199 + .bindex = cpg->bdst,
5200 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5201 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5204 + struct au_branch *br;
5205 + struct super_block *sb, *h_src_sb;
5206 + struct inode *h_src_inode;
5207 + struct task_struct *tsk = current;
5209 + /* bsrc branch can be ro/rw. */
5210 + sb = cpg->dentry->d_sb;
5212 + for (i = 0; i < 2; i++, f++) {
5213 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5214 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5215 + /*file*/NULL, f->force_wr);
5216 + if (IS_ERR(f->file)) {
5217 + err = PTR_ERR(f->file);
5225 + /* try stopping to update while we copyup */
5226 + h_src_inode = d_inode(file[SRC].dentry);
5227 + h_src_sb = h_src_inode->i_sb;
5228 + if (!au_test_nfs(h_src_sb))
5229 + IMustLock(h_src_inode);
5230 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5232 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5233 + if (tsk->flags & PF_KTHREAD)
5234 + __fput_sync(file[DST].file);
5236 + /* it happened actually */
5237 + fput(file[DST].file);
5240 + * we have to call both since we don't know which place the file
5244 + flush_delayed_fput();
5246 + br = au_sbr(sb, file[DST].bindex);
5247 + au_lcnt_dec(&br->br_nfiles);
5250 + fput(file[SRC].file);
5251 + br = au_sbr(sb, file[SRC].bindex);
5252 + au_lcnt_dec(&br->br_nfiles);
5257 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5258 + struct au_cpup_reg_attr *h_src_attr)
5262 + struct path h_path;
5263 + struct inode *h_src_inode, *h_dst_inode;
5266 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5267 + l = i_size_read(h_src_inode);
5268 + if (cpg->len == -1 || l < cpg->len)
5271 + /* try stopping to update while we are referencing */
5272 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5273 + au_pin_hdir_unlock(cpg->pin);
5275 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5276 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5277 + h_src_attr->iflags = h_src_inode->i_flags;
5278 + if (!au_test_nfs(h_src_inode->i_sb))
5279 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5281 + inode_unlock_shared(h_src_inode);
5282 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5283 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5285 + if (unlikely(err)) {
5286 + inode_unlock_shared(h_src_inode);
5289 + h_src_attr->valid = 1;
5290 + if (!au_test_nfs(h_src_inode->i_sb)) {
5291 + err = au_cp_regular(cpg);
5292 + inode_unlock_shared(h_src_inode);
5294 + inode_unlock_shared(h_src_inode);
5295 + err = au_cp_regular(cpg);
5297 + rerr = au_pin_hdir_relock(cpg->pin);
5301 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5302 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5303 + h_dst_inode = d_inode(h_path.dentry);
5304 + spin_lock(&h_dst_inode->i_lock);
5305 + h_dst_inode->i_state |= I_LINKABLE;
5306 + spin_unlock(&h_dst_inode->i_lock);
5313 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5314 + struct inode *h_dir)
5317 + DEFINE_DELAYED_CALL(done);
5320 + sym = vfs_get_link(h_src, &done);
5321 + err = PTR_ERR(sym);
5325 + err = vfsub_symlink(h_dir, h_path, sym);
5328 + do_delayed_call(&done);
5333 + * regardless 'acl' option, reset all ACL.
5334 + * All ACL will be copied up later from the original entry on the lower branch.
5336 +static int au_reset_acl(struct path *h_path, umode_t mode)
5339 + struct dentry *h_dentry;
5340 + /* struct inode *h_inode; */
5341 + struct mnt_idmap *h_idmap;
5343 + h_idmap = mnt_idmap(h_path->mnt);
5344 + h_dentry = h_path->dentry;
5345 + /* h_inode = d_inode(h_dentry); */
5346 + /* forget_all_cached_acls(h_inode)); */
5347 + err = vfsub_remove_acl(h_idmap, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5349 + if (err == -EOPNOTSUPP)
5352 + err = vfsub_acl_chmod(h_idmap, h_dentry, mode);
5358 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5359 + struct inode *h_dir, struct path *h_path)
5362 + struct inode *dir, *inode;
5363 + struct mnt_idmap *h_idmap;
5365 + h_idmap = mnt_idmap(h_path->mnt);
5366 + err = vfsub_remove_acl(h_idmap, h_path->dentry,
5367 + XATTR_NAME_POSIX_ACL_DEFAULT);
5369 + if (err == -EOPNOTSUPP)
5371 + if (unlikely(err))
5375 + * strange behaviour from the users view,
5376 + * particularly setattr case
5378 + dir = d_inode(dst_parent);
5379 + if (au_ibtop(dir) == cpg->bdst)
5380 + au_cpup_attr_nlink(dir, /*force*/1);
5381 + inode = d_inode(cpg->dentry);
5382 + au_cpup_attr_nlink(inode, /*force*/1);
5388 +static noinline_for_stack
5389 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5390 + struct au_cpup_reg_attr *h_src_attr)
5394 + unsigned int mnt_flags;
5395 + unsigned char isdir, isreg, force;
5396 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5397 + struct au_dtime dt;
5398 + struct path h_path;
5399 + struct dentry *h_src, *h_dst, *h_parent;
5400 + struct inode *h_inode, *h_dir;
5401 + struct super_block *sb;
5403 + /* bsrc branch can be ro/rw. */
5404 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5405 + h_inode = d_inode(h_src);
5406 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5408 + /* try stopping to be referenced while we are creating */
5409 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5410 + if (au_ftest_cpup(cpg->flags, RENAME))
5411 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5412 + AUFS_WH_PFX_LEN));
5413 + h_parent = h_dst->d_parent; /* dir inode is locked */
5414 + h_dir = d_inode(h_parent);
5416 + AuDebugOn(h_parent != h_dst->d_parent);
5418 + sb = cpg->dentry->d_sb;
5419 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5421 + h_path.dentry = h_parent;
5422 + au_dtime_store(&dt, dst_parent, &h_path);
5424 + h_path.dentry = h_dst;
5428 + mode = h_inode->i_mode;
5429 + switch (mode & S_IFMT) {
5432 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5434 + err = au_do_cpup_regular(cpg, h_src_attr);
5438 + err = vfsub_mkdir(h_dir, &h_path, mode);
5440 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5443 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5447 + AuDebugOn(!capable(CAP_MKNOD));
5451 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5454 + AuIOErr("Unknown inode type 0%o\n", mode);
5458 + err = au_reset_acl(&h_path, mode);
5460 + mnt_flags = au_mntflags(sb);
5461 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5463 + && au_opt_test(mnt_flags, XINO)
5464 + && (h_inode->i_nlink == 1
5465 + || (h_inode->i_state & I_LINKABLE))
5466 + /* todo: unnecessary? */
5467 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5468 + && cpg->bdst < cpg->bsrc
5469 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5470 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5471 + /* ignore this error */
5476 + force = !!cpg->len;
5477 + if (cpg->len == -1)
5478 + force = !!i_size_read(h_inode);
5480 + au_fhsm_wrote(sb, cpg->bdst, force);
5484 + au_dtime_revert(&dt);
5488 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5491 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5492 + struct path h_ppath;
5493 + struct inode *h_dir;
5494 + aufs_bindex_t bdst;
5496 + dentry = cpg->dentry;
5498 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5499 + h_dentry = au_h_dptr(dentry, bdst);
5500 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5502 + au_set_h_dptr(dentry, bdst, NULL);
5503 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5505 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5506 + au_set_h_dptr(dentry, bdst, h_dentry);
5509 + parent = dget_parent(dentry);
5510 + h_ppath.dentry = au_h_dptr(parent, bdst);
5512 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5513 + if (IS_ERR(h_path->dentry))
5514 + err = PTR_ERR(h_path->dentry);
5516 + if (unlikely(err))
5519 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5520 + h_dir = d_inode(h_parent);
5522 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5523 + /* no delegation since it is just created */
5524 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5526 + dput(h_path->dentry);
5533 + * copyup the @dentry from @bsrc to @bdst.
5534 + * the caller must set the both of lower dentries.
5535 + * @len is for truncating when it is -1 copyup the entire file.
5536 + * in link/rename cases, @dst_parent may be different from the real one.
5537 + * basic->bsrc can be larger than basic->bdst.
5538 + * aufs doesn't touch the credential so
5539 + * security_inode_copy_up{,_xattr}() are unnecessary.
5541 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5544 + aufs_bindex_t old_ibtop;
5545 + unsigned char isdir, plink;
5546 + struct dentry *h_src, *h_dst, *h_parent;
5547 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5548 + struct super_block *sb;
5549 + struct au_branch *br;
5550 + struct path h_src_path;
5551 + /* to reduce stack size */
5553 + struct au_dtime dt;
5554 + struct path h_path;
5555 + struct au_cpup_reg_attr h_src_attr;
5559 + a = kmalloc(sizeof(*a), GFP_NOFS);
5562 + a->h_src_attr.valid = 0;
5564 + sb = cpg->dentry->d_sb;
5565 + br = au_sbr(sb, cpg->bdst);
5566 + a->h_path.mnt = au_br_mnt(br);
5567 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5568 + h_parent = h_dst->d_parent; /* dir inode is locked */
5569 + h_dir = d_inode(h_parent);
5572 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5573 + inode = d_inode(cpg->dentry);
5576 + dst_parent = dget_parent(cpg->dentry);
5580 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5581 + dst_inode = au_h_iptr(inode, cpg->bdst);
5583 + if (unlikely(!plink)) {
5585 + AuIOErr("hi%lu(i%lu) exists on b%d "
5586 + "but plink is disabled\n",
5587 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5591 + if (dst_inode->i_nlink) {
5592 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5594 + h_src = au_plink_lkup(inode, cpg->bdst);
5595 + err = PTR_ERR(h_src);
5596 + if (IS_ERR(h_src))
5598 + if (unlikely(d_is_negative(h_src))) {
5600 + AuIOErr("i%lu exists on b%d "
5601 + "but not pseudo-linked\n",
5602 + inode->i_ino, cpg->bdst);
5608 + a->h_path.dentry = h_parent;
5609 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5612 + a->h_path.dentry = h_dst;
5614 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5615 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5616 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5618 + au_dtime_revert(&a->dt);
5619 + if (unlikely(err == -EWOULDBLOCK)) {
5620 + pr_warn("cannot retry for NFSv4 delegation"
5621 + " for an internal link\n");
5627 + /* todo: cpup_wh_file? */
5629 + au_update_ibrange(inode, /*do_put_zero*/1);
5632 + isdir = S_ISDIR(inode->i_mode);
5633 + old_ibtop = au_ibtop(inode);
5634 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5635 + if (unlikely(err))
5637 + dst_inode = d_inode(h_dst);
5638 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5639 + /* todo: necessary? */
5640 + /* au_pin_hdir_unlock(cpg->pin); */
5642 + h_src_path.dentry = h_src;
5643 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5644 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5645 + if (unlikely(err)) {
5646 + /* todo: necessary? */
5647 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5648 + inode_unlock(dst_inode);
5652 + if (cpg->bdst < old_ibtop) {
5653 + if (S_ISREG(inode->i_mode)) {
5654 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5655 + if (unlikely(err)) {
5656 + /* ignore an error */
5657 + /* au_pin_hdir_relock(cpg->pin); */
5658 + inode_unlock(dst_inode);
5662 + au_set_ibtop(inode, cpg->bdst);
5664 + au_set_ibbot(inode, cpg->bdst);
5665 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5666 + au_hi_flags(inode, isdir));
5668 + /* todo: necessary? */
5669 + /* err = au_pin_hdir_relock(cpg->pin); */
5670 + inode_unlock(dst_inode);
5671 + if (unlikely(err))
5674 + src_inode = d_inode(h_src);
5676 + && (src_inode->i_nlink > 1
5677 + || src_inode->i_state & I_LINKABLE)
5679 + au_plink_append(inode, cpg->bdst, h_dst);
5681 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5682 + a->h_path.dentry = h_dst;
5683 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5686 + goto out_parent; /* success */
5690 + a->h_path.dentry = h_parent;
5691 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5692 + a->h_path.dentry = h_dst;
5694 + if (d_is_positive(h_dst)) {
5696 + /* no delegation since it is just created */
5697 + rerr = vfsub_unlink(h_dir, &a->h_path,
5698 + /*delegated*/NULL, /*force*/0);
5700 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5702 + au_dtime_revert(&a->dt);
5704 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5714 +#if 0 /* reserved */
5715 +struct au_cpup_single_args {
5717 + struct au_cp_generic *cpg;
5718 + struct dentry *dst_parent;
5721 +static void au_call_cpup_single(void *args)
5723 + struct au_cpup_single_args *a = args;
5725 + au_pin_hdir_acquire_nest(a->cpg->pin);
5726 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5727 + au_pin_hdir_release(a->cpg->pin);
5732 + * prevent SIGXFSZ in copy-up.
5733 + * testing CAP_MKNOD is for generic fs,
5734 + * but CAP_FSETID is for xfs only, currently.
5736 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5739 + struct super_block *sb;
5740 + struct inode *h_dir;
5743 + sb = au_pinned_parent(pin)->d_sb;
5744 + if (!au_wkq_test()
5745 + && (!au_sbi(sb)->si_plink_maint_pid
5746 + || au_plink_maint(sb, AuLock_NOPLM))) {
5747 + switch (mode & S_IFMT) {
5749 + /* no condition about RLIMIT_FSIZE and the file size */
5754 + do_sio = !capable(CAP_MKNOD);
5758 + do_sio = ((mode & (S_ISUID | S_ISGID))
5759 + && !capable(CAP_FSETID));
5760 + /* this workaround may be removed in the future */
5762 + h_dir = au_pinned_h_dir(pin);
5763 + do_sio = h_dir->i_mode & S_ISVTX;
5770 +#if 0 /* reserved */
5771 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5774 + struct dentry *h_dentry;
5776 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5777 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5778 + err = au_cpup_single(cpg, dst_parent);
5780 + struct au_cpup_single_args args = {
5783 + .dst_parent = dst_parent
5785 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5786 + if (unlikely(wkq_err))
5795 + * copyup the @dentry from the first active lower branch to @bdst,
5796 + * using au_cpup_single().
5798 +static int au_cpup_simple(struct au_cp_generic *cpg)
5801 + unsigned int flags_orig;
5802 + struct dentry *dentry;
5804 + AuDebugOn(cpg->bsrc < 0);
5806 + dentry = cpg->dentry;
5807 + DiMustWriteLock(dentry);
5809 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5811 + flags_orig = cpg->flags;
5812 + au_fset_cpup(cpg->flags, RENAME);
5813 + err = au_cpup_single(cpg, NULL);
5814 + cpg->flags = flags_orig;
5816 + return 0; /* success */
5819 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5820 + au_set_dbtop(dentry, cpg->bsrc);
5826 +struct au_cpup_simple_args {
5828 + struct au_cp_generic *cpg;
5831 +static void au_call_cpup_simple(void *args)
5833 + struct au_cpup_simple_args *a = args;
5835 + au_pin_hdir_acquire_nest(a->cpg->pin);
5836 + *a->errp = au_cpup_simple(a->cpg);
5837 + au_pin_hdir_release(a->cpg->pin);
5840 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5843 + struct dentry *dentry, *parent;
5844 + struct file *h_file;
5845 + struct inode *h_dir;
5846 + struct mnt_idmap *h_idmap;
5848 + dentry = cpg->dentry;
5850 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5851 + AuDebugOn(cpg->bsrc < 0);
5852 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5853 + err = PTR_ERR(h_file);
5854 + if (IS_ERR(h_file))
5858 + parent = dget_parent(dentry);
5859 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5860 + h_idmap = au_sbr_idmap(dentry->d_sb, cpg->bdst);
5861 + if (!au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC | MAY_WRITE)
5862 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5863 + err = au_cpup_simple(cpg);
5865 + struct au_cpup_simple_args args = {
5869 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5870 + if (unlikely(wkq_err))
5876 + au_h_open_post(dentry, cpg->bsrc, h_file);
5882 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5884 + aufs_bindex_t bsrc, bbot;
5885 + struct dentry *dentry, *h_dentry;
5887 + if (cpg->bsrc < 0) {
5888 + dentry = cpg->dentry;
5889 + bbot = au_dbbot(dentry);
5890 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5891 + h_dentry = au_h_dptr(dentry, bsrc);
5893 + AuDebugOn(d_is_negative(h_dentry));
5897 + AuDebugOn(bsrc > bbot);
5900 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5901 + return au_do_sio_cpup_simple(cpg);
5904 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5906 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5907 + return au_do_sio_cpup_simple(cpg);
5910 +/* ---------------------------------------------------------------------- */
5913 + * copyup the deleted file for writing.
5915 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5916 + struct file *file)
5919 + unsigned int flags_orig;
5920 + aufs_bindex_t bsrc_orig;
5921 + struct au_dinfo *dinfo;
5923 + struct au_hdentry *hd;
5924 + struct dentry *h_dentry;
5927 + dinfo = au_di(cpg->dentry);
5928 + AuRwMustWriteLock(&dinfo->di_rwsem);
5930 + bsrc_orig = cpg->bsrc;
5931 + cpg->bsrc = dinfo->di_btop;
5932 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5933 + hdst.h_dentry = hdst.hd->hd_dentry;
5934 + hdst.hd->hd_dentry = wh_dentry;
5935 + dinfo->di_btop = cpg->bdst;
5937 + hsrc.h_dentry = NULL;
5939 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5940 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5941 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5943 + flags_orig = cpg->flags;
5944 + cpg->flags = !AuCpup_DTIME;
5945 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5946 + cpg->flags = flags_orig;
5949 + err = au_reopen_nondir(file);
5950 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5952 + hdst.hd->hd_dentry = hdst.h_dentry;
5953 + dinfo->di_btop = cpg->bsrc;
5954 + cpg->bsrc = bsrc_orig;
5959 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5962 + aufs_bindex_t bdst;
5963 + struct au_dtime dt;
5964 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5965 + struct au_branch *br;
5966 + struct path h_path;
5968 + dentry = cpg->dentry;
5970 + br = au_sbr(dentry->d_sb, bdst);
5971 + parent = dget_parent(dentry);
5972 + h_parent = au_h_dptr(parent, bdst);
5973 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5974 + err = PTR_ERR(wh_dentry);
5975 + if (IS_ERR(wh_dentry))
5978 + h_path.dentry = h_parent;
5979 + h_path.mnt = au_br_mnt(br);
5980 + au_dtime_store(&dt, parent, &h_path);
5981 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5982 + if (unlikely(err))
5986 + h_path.dentry = wh_dentry;
5987 + if (!d_is_dir(wh_dentry)) {
5988 + /* no delegation since it is just created */
5989 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5990 + /*delegated*/NULL, /*force*/0);
5992 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5993 + if (unlikely(err)) {
5994 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5998 + au_dtime_revert(&dt);
5999 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6008 +struct au_cpup_wh_args {
6010 + struct au_cp_generic *cpg;
6011 + struct file *file;
6014 +static void au_call_cpup_wh(void *args)
6016 + struct au_cpup_wh_args *a = args;
6018 + au_pin_hdir_acquire_nest(a->cpg->pin);
6019 + *a->errp = au_cpup_wh(a->cpg, a->file);
6020 + au_pin_hdir_release(a->cpg->pin);
6023 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6026 + aufs_bindex_t bdst;
6027 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6028 + struct inode *dir, *h_dir, *h_tmpdir;
6029 + struct au_wbr *wbr;
6030 + struct au_pin wh_pin, *pin_orig;
6031 + struct mnt_idmap *h_idmap;
6033 + dentry = cpg->dentry;
6035 + parent = dget_parent(dentry);
6036 + dir = d_inode(parent);
6039 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6042 + if (!h_dir->i_nlink) {
6043 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6044 + h_orph = wbr->wbr_orph;
6046 + h_parent = dget(au_h_dptr(parent, bdst));
6047 + au_set_h_dptr(parent, bdst, dget(h_orph));
6048 + h_tmpdir = d_inode(h_orph);
6049 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6051 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6052 + /* todo: au_h_open_pre()? */
6054 + pin_orig = cpg->pin;
6055 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6056 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6057 + cpg->pin = &wh_pin;
6060 + h_idmap = au_sbr_idmap(dentry->d_sb, bdst);
6061 + if (!au_test_h_perm_sio(h_idmap, h_tmpdir, MAY_EXEC | MAY_WRITE)
6062 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6063 + err = au_cpup_wh(cpg, file);
6065 + struct au_cpup_wh_args args = {
6070 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6071 + if (unlikely(wkq_err))
6076 + inode_unlock(h_tmpdir);
6077 + /* todo: au_h_open_post()? */
6078 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6079 + au_set_h_dptr(parent, bdst, h_parent);
6080 + AuDebugOn(!pin_orig);
6081 + cpg->pin = pin_orig;
6089 +/* ---------------------------------------------------------------------- */
6092 + * generic routine for both of copy-up and copy-down.
6094 +/* cf. revalidate function in file.c */
6095 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6096 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6097 + struct au_pin *pin,
6098 + struct dentry *h_parent, void *arg),
6102 + struct au_pin pin;
6103 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6106 + parent = dget_parent(dentry);
6107 + if (IS_ROOT(parent))
6110 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6111 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6113 + /* do not use au_dpage */
6114 + real_parent = parent;
6117 + parent = dget_parent(dentry);
6118 + h_parent = au_h_dptr(parent, bdst);
6120 + goto out; /* success */
6122 + /* find top dir which is necessary to cpup */
6126 + parent = dget_parent(d);
6127 + di_read_lock_parent3(parent, !AuLock_IR);
6128 + h_parent = au_h_dptr(parent, bdst);
6129 + di_read_unlock(parent, !AuLock_IR);
6130 + } while (!h_parent);
6132 + if (d != real_parent)
6133 + di_write_lock_child3(d);
6135 + /* somebody else might create while we were sleeping */
6136 + h_dentry = au_h_dptr(d, bdst);
6137 + if (!h_dentry || d_is_negative(h_dentry)) {
6139 + au_update_dbtop(d);
6141 + au_pin_set_dentry(&pin, d);
6142 + err = au_do_pin(&pin);
6144 + err = cp(d, bdst, &pin, h_parent, arg);
6149 + if (d != real_parent)
6150 + di_write_unlock(d);
6151 + if (unlikely(err))
6160 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6161 + struct au_pin *pin,
6162 + struct dentry *h_parent __maybe_unused,
6163 + void *arg __maybe_unused)
6165 + struct au_cp_generic cpg = {
6171 + .flags = AuCpup_DTIME
6173 + return au_sio_cpup_simple(&cpg);
6176 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6178 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6181 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6184 + struct dentry *parent;
6185 + struct inode *dir;
6187 + parent = dget_parent(dentry);
6188 + dir = d_inode(parent);
6190 + if (au_h_iptr(dir, bdst))
6193 + di_read_unlock(parent, AuLock_IR);
6194 + di_write_lock_parent(parent);
6195 + /* someone else might change our inode while we were sleeping */
6196 + if (!au_h_iptr(dir, bdst))
6197 + err = au_cpup_dirs(dentry, bdst);
6198 + di_downgrade_lock(parent, AuLock_IR);
6204 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6205 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6206 +++ linux/fs/aufs/cpup.h 2022-11-05 23:02:18.962555950 +0100
6208 +/* SPDX-License-Identifier: GPL-2.0 */
6210 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6212 + * This program is free software; you can redistribute it and/or modify
6213 + * it under the terms of the GNU General Public License as published by
6214 + * the Free Software Foundation; either version 2 of the License, or
6215 + * (at your option) any later version.
6217 + * This program is distributed in the hope that it will be useful,
6218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6220 + * GNU General Public License for more details.
6222 + * You should have received a copy of the GNU General Public License
6223 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6227 + * copy-up/down functions
6230 +#ifndef __AUFS_CPUP_H__
6231 +#define __AUFS_CPUP_H__
6235 +#include <linux/path.h>
6241 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6242 +void au_cpup_attr_timesizes(struct inode *inode);
6243 +void au_cpup_attr_nlink(struct inode *inode, int force);
6244 +void au_cpup_attr_changeable(struct inode *inode);
6245 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6246 +void au_cpup_attr_all(struct inode *inode, int force);
6248 +/* ---------------------------------------------------------------------- */
6250 +struct au_cp_generic {
6251 + struct dentry *dentry;
6252 + aufs_bindex_t bdst, bsrc;
6254 + struct au_pin *pin;
6255 + unsigned int flags;
6259 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6260 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6262 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6263 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6265 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6267 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6268 + the branch is marked as RO */
6270 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6271 +#undef AuCpup_HOPEN
6272 +#define AuCpup_HOPEN 0
6275 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6276 +#define au_fset_cpup(flags, name) \
6277 + do { (flags) |= AuCpup_##name; } while (0)
6278 +#define au_fclr_cpup(flags, name) \
6279 + do { (flags) &= ~AuCpup_##name; } while (0)
6281 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6282 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6283 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6284 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6286 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6287 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6288 + struct au_pin *pin,
6289 + struct dentry *h_parent, void *arg),
6291 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6292 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6294 +/* ---------------------------------------------------------------------- */
6296 +/* keep timestamps when copyup */
6298 + struct dentry *dt_dentry;
6299 + struct path dt_h_path;
6300 + struct timespec64 dt_atime, dt_mtime;
6302 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6303 + struct path *h_path);
6304 +void au_dtime_revert(struct au_dtime *dt);
6306 +#endif /* __KERNEL__ */
6307 +#endif /* __AUFS_CPUP_H__ */
6308 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6309 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6310 +++ linux/fs/aufs/dbgaufs.c 2022-11-05 23:02:18.962555950 +0100
6312 +// SPDX-License-Identifier: GPL-2.0
6314 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6316 + * This program is free software; you can redistribute it and/or modify
6317 + * it under the terms of the GNU General Public License as published by
6318 + * the Free Software Foundation; either version 2 of the License, or
6319 + * (at your option) any later version.
6321 + * This program is distributed in the hope that it will be useful,
6322 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6323 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6324 + * GNU General Public License for more details.
6326 + * You should have received a copy of the GNU General Public License
6327 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6331 + * debugfs interface
6334 +#include <linux/debugfs.h>
6337 +#ifndef CONFIG_SYSFS
6338 +#error DEBUG_FS depends upon SYSFS
6341 +static struct dentry *dbgaufs;
6342 +static const mode_t dbgaufs_mode = 0444;
6344 +/* 20 is max digits length of ulong 64 */
6345 +struct dbgaufs_arg {
6351 + * common function for all XINO files
6353 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6354 + struct file *file)
6358 + p = file->private_data;
6360 + /* this is struct dbgaufs_arg */
6361 + AuDebugOn(!au_kfree_sz_test(p));
6362 + au_kfree_do_rcu(p);
6367 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6372 + struct dbgaufs_arg *p;
6375 + p = kmalloc(sizeof(*p), GFP_NOFS);
6381 + file->private_data = p;
6385 + err = vfsub_getattr(&xf->f_path, &st);
6389 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6390 + cnt, st.blocks, st.blksize,
6391 + (long long)st.size);
6393 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6394 + st.blocks, st.blksize,
6395 + (long long)st.size);
6396 + AuDebugOn(p->n >= sizeof(p->a));
6398 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6406 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6407 + size_t count, loff_t *ppos)
6409 + struct dbgaufs_arg *p;
6411 + p = file->private_data;
6412 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6415 +/* ---------------------------------------------------------------------- */
6417 +struct dbgaufs_plink_arg {
6422 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6423 + struct file *file)
6425 + free_page((unsigned long)file->private_data);
6429 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6431 + int err, i, limit;
6432 + unsigned long n, sum;
6433 + struct dbgaufs_plink_arg *p;
6434 + struct au_sbinfo *sbinfo;
6435 + struct super_block *sb;
6436 + struct hlist_bl_head *hbl;
6439 + p = (void *)get_zeroed_page(GFP_NOFS);
6444 + sbinfo = inode->i_private;
6445 + sb = sbinfo->si_sb;
6446 + si_noflush_read_lock(sb);
6447 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6448 + limit = PAGE_SIZE - sizeof(p->n);
6450 + /* the number of buckets */
6451 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6456 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6458 + n = au_hbl_count(hbl);
6461 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6464 + if (unlikely(limit <= 0))
6467 + p->a[p->n - 1] = '\n';
6469 + /* the sum of plinks */
6470 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6473 + if (unlikely(limit <= 0))
6476 +#define str "1\n0\n0\n"
6477 + p->n = sizeof(str) - 1;
6478 + strcpy(p->a, str);
6481 + si_read_unlock(sb);
6484 + file->private_data = p;
6485 + goto out; /* success */
6488 + free_page((unsigned long)p);
6493 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6494 + size_t count, loff_t *ppos)
6496 + struct dbgaufs_plink_arg *p;
6498 + p = file->private_data;
6499 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6502 +static const struct file_operations dbgaufs_plink_fop = {
6503 + .owner = THIS_MODULE,
6504 + .open = dbgaufs_plink_open,
6505 + .release = dbgaufs_plink_release,
6506 + .read = dbgaufs_plink_read
6509 +/* ---------------------------------------------------------------------- */
6511 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6514 + struct au_sbinfo *sbinfo;
6515 + struct super_block *sb;
6517 + sbinfo = inode->i_private;
6518 + sb = sbinfo->si_sb;
6519 + si_noflush_read_lock(sb);
6520 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6521 + si_read_unlock(sb);
6525 +static const struct file_operations dbgaufs_xib_fop = {
6526 + .owner = THIS_MODULE,
6527 + .open = dbgaufs_xib_open,
6528 + .release = dbgaufs_xi_release,
6529 + .read = dbgaufs_xi_read
6532 +/* ---------------------------------------------------------------------- */
6534 +#define DbgaufsXi_PREFIX "xi"
6536 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6540 + aufs_bindex_t bindex;
6541 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6542 + struct au_sbinfo *sbinfo;
6543 + struct super_block *sb;
6544 + struct au_xino *xi;
6546 + struct qstr *name;
6547 + struct au_branch *br;
6550 + name = &file->f_path.dentry->d_name;
6551 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6552 + || memcmp(name->name, DbgaufsXi_PREFIX,
6553 + sizeof(DbgaufsXi_PREFIX) - 1)))
6556 + AuDebugOn(name->len >= sizeof(a));
6557 + memcpy(a, name->name, name->len);
6558 + a[name->len] = '\0';
6559 + p = strchr(a, '-');
6562 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6563 + if (unlikely(err))
6568 + err = kstrtol(p + 1, 10, &l);
6569 + if (unlikely(err))
6575 + sbinfo = inode->i_private;
6576 + sb = sbinfo->si_sb;
6577 + si_noflush_read_lock(sb);
6578 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6580 + br = au_sbr(sb, bindex);
6582 + if (unlikely(idx >= xi->xi_nfile))
6584 + xf = au_xino_file(xi, idx);
6586 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6587 + au_xino_count(br));
6590 + si_read_unlock(sb);
6596 +static const struct file_operations dbgaufs_xino_fop = {
6597 + .owner = THIS_MODULE,
6598 + .open = dbgaufs_xino_open,
6599 + .release = dbgaufs_xi_release,
6600 + .read = dbgaufs_xi_read
6603 +void dbgaufs_xino_del(struct au_branch *br)
6605 + struct dentry *dbgaufs;
6607 + dbgaufs = br->br_dbgaufs;
6611 + br->br_dbgaufs = NULL;
6612 + /* debugfs acquires the parent i_mutex */
6614 + debugfs_remove(dbgaufs);
6618 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6620 + aufs_bindex_t bbot;
6621 + struct au_branch *br;
6623 + if (!au_sbi(sb)->si_dbgaufs)
6626 + bbot = au_sbbot(sb);
6627 + for (; bindex <= bbot; bindex++) {
6628 + br = au_sbr(sb, bindex);
6629 + dbgaufs_xino_del(br);
6633 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6634 + unsigned int idx, struct dentry *parent,
6635 + struct au_sbinfo *sbinfo)
6637 + struct au_branch *br;
6639 + /* "xi" bindex(5) "-" idx(2) NULL */
6640 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6643 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6645 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6647 + br = au_sbr(sb, bindex);
6648 + if (br->br_dbgaufs) {
6649 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6651 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6652 + /* debugfs acquires the parent i_mutex */
6654 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6658 + pr_warn("failed renaming %pd/%s, ignored.\n",
6663 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6664 + sbinfo, &dbgaufs_xino_fop);
6666 + if (unlikely(!br->br_dbgaufs))
6667 + pr_warn("failed creating %pd/%s, ignored.\n",
6672 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6673 + struct dentry *parent, struct au_sbinfo *sbinfo)
6675 + struct au_branch *br;
6676 + struct au_xino *xi;
6679 + br = au_sbr(sb, bindex);
6681 + for (u = 0; u < xi->xi_nfile; u++)
6682 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6685 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6687 + struct au_sbinfo *sbinfo;
6688 + struct dentry *parent;
6689 + aufs_bindex_t bbot;
6691 + if (!au_opt_test(au_mntflags(sb), XINO))
6694 + sbinfo = au_sbi(sb);
6695 + parent = sbinfo->si_dbgaufs;
6699 + bbot = au_sbbot(sb);
6701 + for (; bindex <= bbot; bindex++)
6702 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6704 + for (; bbot >= bindex; bbot--)
6705 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6708 +/* ---------------------------------------------------------------------- */
6710 +#ifdef CONFIG_AUFS_EXPORT
6711 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6714 + struct au_sbinfo *sbinfo;
6715 + struct super_block *sb;
6717 + sbinfo = inode->i_private;
6718 + sb = sbinfo->si_sb;
6719 + si_noflush_read_lock(sb);
6720 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6721 + si_read_unlock(sb);
6725 +static const struct file_operations dbgaufs_xigen_fop = {
6726 + .owner = THIS_MODULE,
6727 + .open = dbgaufs_xigen_open,
6728 + .release = dbgaufs_xi_release,
6729 + .read = dbgaufs_xi_read
6732 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6737 + * This function is a dynamic '__init' function actually,
6738 + * so the tiny check for si_rwsem is unnecessary.
6740 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6743 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6744 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6745 + &dbgaufs_xigen_fop);
6746 + if (sbinfo->si_dbgaufs_xigen)
6752 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6756 +#endif /* CONFIG_AUFS_EXPORT */
6758 +/* ---------------------------------------------------------------------- */
6760 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6763 + * This function is a dynamic '__fin' function actually,
6764 + * so the tiny check for si_rwsem is unnecessary.
6766 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6768 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6769 + sbinfo->si_dbgaufs = NULL;
6772 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6775 + char name[SysaufsSiNameLen];
6778 + * This function is a dynamic '__init' function actually,
6779 + * so the tiny check for si_rwsem is unnecessary.
6781 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6785 + AuErr1("/debug/aufs is uninitialized\n");
6790 + sysaufs_name(sbinfo, name);
6791 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6792 + if (unlikely(!sbinfo->si_dbgaufs))
6795 + /* regardless plink/noplink option */
6796 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6797 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6798 + &dbgaufs_plink_fop);
6799 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6802 + /* regardless xino/noxino option */
6803 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6804 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6805 + &dbgaufs_xib_fop);
6806 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6809 + err = dbgaufs_xigen_init(sbinfo);
6811 + goto out; /* success */
6814 + dbgaufs_si_fin(sbinfo);
6816 + if (unlikely(err))
6817 + pr_err("debugfs/aufs failed\n");
6821 +/* ---------------------------------------------------------------------- */
6823 +void dbgaufs_fin(void)
6825 + debugfs_remove(dbgaufs);
6828 +int __init dbgaufs_init(void)
6833 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6838 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6839 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6840 +++ linux/fs/aufs/dbgaufs.h 2022-11-05 23:02:18.962555950 +0100
6842 +/* SPDX-License-Identifier: GPL-2.0 */
6844 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6846 + * This program is free software; you can redistribute it and/or modify
6847 + * it under the terms of the GNU General Public License as published by
6848 + * the Free Software Foundation; either version 2 of the License, or
6849 + * (at your option) any later version.
6851 + * This program is distributed in the hope that it will be useful,
6852 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6853 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6854 + * GNU General Public License for more details.
6856 + * You should have received a copy of the GNU General Public License
6857 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6861 + * debugfs interface
6864 +#ifndef __DBGAUFS_H__
6865 +#define __DBGAUFS_H__
6869 +struct super_block;
6873 +#ifdef CONFIG_DEBUG_FS
6875 +void dbgaufs_xino_del(struct au_branch *br);
6876 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6877 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6878 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6879 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6880 +void dbgaufs_fin(void);
6881 +int __init dbgaufs_init(void);
6883 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6884 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6885 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6887 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6888 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6889 +AuStubVoid(dbgaufs_fin, void)
6890 +AuStubInt0(__init dbgaufs_init, void)
6891 +#endif /* CONFIG_DEBUG_FS */
6893 +#endif /* __KERNEL__ */
6894 +#endif /* __DBGAUFS_H__ */
6895 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6896 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6897 +++ linux/fs/aufs/dcsub.c 2022-11-05 23:02:18.962555950 +0100
6899 +// SPDX-License-Identifier: GPL-2.0
6901 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6903 + * This program is free software; you can redistribute it and/or modify
6904 + * it under the terms of the GNU General Public License as published by
6905 + * the Free Software Foundation; either version 2 of the License, or
6906 + * (at your option) any later version.
6908 + * This program is distributed in the hope that it will be useful,
6909 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6910 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6911 + * GNU General Public License for more details.
6913 + * You should have received a copy of the GNU General Public License
6914 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6918 + * sub-routines for dentry cache
6923 +static void au_dpage_free(struct au_dpage *dpage)
6926 + struct dentry **p;
6928 + p = dpage->dentries;
6929 + for (i = 0; i < dpage->ndentry; i++)
6931 + free_page((unsigned long)dpage->dentries);
6934 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6940 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6941 + if (unlikely(!dpages->dpages))
6944 + p = (void *)__get_free_page(gfp);
6948 + dpages->dpages[0].ndentry = 0;
6949 + dpages->dpages[0].dentries = p;
6950 + dpages->ndpage = 1;
6951 + return 0; /* success */
6954 + au_kfree_try_rcu(dpages->dpages);
6959 +void au_dpages_free(struct au_dcsub_pages *dpages)
6962 + struct au_dpage *p;
6964 + p = dpages->dpages;
6965 + for (i = 0; i < dpages->ndpage; i++)
6966 + au_dpage_free(p++);
6967 + au_kfree_try_rcu(dpages->dpages);
6970 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6971 + struct dentry *dentry, gfp_t gfp)
6974 + struct au_dpage *dpage;
6977 + dpage = dpages->dpages + dpages->ndpage - 1;
6978 + sz = PAGE_SIZE / sizeof(dentry);
6979 + if (unlikely(dpage->ndentry >= sz)) {
6980 + AuLabel(new dpage);
6982 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6983 + p = au_kzrealloc(dpages->dpages, sz,
6984 + sz + sizeof(*dpages->dpages), gfp,
6989 + dpages->dpages = p;
6990 + dpage = dpages->dpages + dpages->ndpage;
6991 + p = (void *)__get_free_page(gfp);
6995 + dpage->ndentry = 0;
6996 + dpage->dentries = p;
7000 + AuDebugOn(au_dcount(dentry) <= 0);
7001 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7002 + return 0; /* success */
7008 +/* todo: BAD approach */
7009 +/* copied from linux/fs/dcache.c */
7017 +extern void d_walk(struct dentry *parent, void *data,
7018 + enum d_walk_ret (*enter)(void *, struct dentry *));
7020 +struct ac_dpages_arg {
7022 + struct au_dcsub_pages *dpages;
7023 + struct super_block *sb;
7024 + au_dpages_test test;
7028 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7030 + enum d_walk_ret ret;
7031 + struct ac_dpages_arg *arg = _arg;
7033 + ret = D_WALK_CONTINUE;
7034 + if (dentry->d_sb == arg->sb
7035 + && !IS_ROOT(dentry)
7036 + && au_dcount(dentry) > 0
7038 + && (!arg->test || arg->test(dentry, arg->arg))) {
7039 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7040 + if (unlikely(arg->err))
7041 + ret = D_WALK_QUIT;
7047 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7048 + au_dpages_test test, void *arg)
7050 + struct ac_dpages_arg args = {
7058 + d_walk(root, &args, au_call_dpages_append);
7063 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7064 + int do_include, au_dpages_test test, void *arg)
7069 + write_seqlock(&rename_lock);
7070 + spin_lock(&dentry->d_lock);
7072 + && au_dcount(dentry) > 0
7073 + && (!test || test(dentry, arg)))
7074 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7075 + spin_unlock(&dentry->d_lock);
7076 + if (unlikely(err))
7080 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7083 + while (!IS_ROOT(dentry)) {
7084 + dentry = dentry->d_parent; /* rename_lock is locked */
7085 + spin_lock(&dentry->d_lock);
7086 + if (au_dcount(dentry) > 0
7087 + && (!test || test(dentry, arg)))
7088 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7089 + spin_unlock(&dentry->d_lock);
7090 + if (unlikely(err))
7095 + write_sequnlock(&rename_lock);
7099 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7101 + return au_di(dentry) && dentry->d_sb == arg;
7104 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7105 + struct dentry *dentry, int do_include)
7107 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7108 + au_dcsub_dpages_aufs, dentry->d_sb);
7111 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7113 + struct path path[2] = {
7122 + return path_is_under(path + 0, path + 1);
7124 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7125 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7126 +++ linux/fs/aufs/dcsub.h 2022-11-05 23:02:18.962555950 +0100
7128 +/* SPDX-License-Identifier: GPL-2.0 */
7130 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7132 + * This program is free software; you can redistribute it and/or modify
7133 + * it under the terms of the GNU General Public License as published by
7134 + * the Free Software Foundation; either version 2 of the License, or
7135 + * (at your option) any later version.
7137 + * This program is distributed in the hope that it will be useful,
7138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7140 + * GNU General Public License for more details.
7142 + * You should have received a copy of the GNU General Public License
7143 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7147 + * sub-routines for dentry cache
7150 +#ifndef __AUFS_DCSUB_H__
7151 +#define __AUFS_DCSUB_H__
7155 +#include <linux/dcache.h>
7156 +#include <linux/fs.h>
7160 + struct dentry **dentries;
7163 +struct au_dcsub_pages {
7165 + struct au_dpage *dpages;
7168 +/* ---------------------------------------------------------------------- */
7171 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7172 +void au_dpages_free(struct au_dcsub_pages *dpages);
7173 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7174 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7175 + au_dpages_test test, void *arg);
7176 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7177 + int do_include, au_dpages_test test, void *arg);
7178 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7179 + struct dentry *dentry, int do_include);
7180 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7182 +/* ---------------------------------------------------------------------- */
7185 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7186 + * include/linux/dcache.h. Try them (in the future).
7189 +static inline int au_d_hashed_positive(struct dentry *d)
7192 + struct inode *inode = d_inode(d);
7195 + if (unlikely(d_unhashed(d)
7196 + || d_is_negative(d)
7197 + || !inode->i_nlink))
7202 +static inline int au_d_linkable(struct dentry *d)
7205 + struct inode *inode = d_inode(d);
7207 + err = au_d_hashed_positive(d);
7209 + && d_is_positive(d)
7210 + && (inode->i_state & I_LINKABLE))
7215 +static inline int au_d_alive(struct dentry *d)
7218 + struct inode *inode;
7222 + err = au_d_hashed_positive(d);
7224 + inode = d_inode(d);
7225 + if (unlikely(d_unlinked(d)
7226 + || d_is_negative(d)
7227 + || !inode->i_nlink))
7233 +static inline int au_alive_dir(struct dentry *d)
7237 + err = au_d_alive(d);
7238 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7243 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7245 + return a->len == b->len
7246 + && !memcmp(a->name, b->name, a->len);
7251 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7253 + * the type of d_lockref.count became int, but the inlined function d_count()
7254 + * still returns unsigned int.
7255 + * I don't know why. Maybe it is for every d_count() users?
7256 + * Anyway au_dcount() lives on.
7258 +static inline int au_dcount(struct dentry *d)
7260 + return (int)d_count(d);
7263 +#endif /* __KERNEL__ */
7264 +#endif /* __AUFS_DCSUB_H__ */
7265 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7266 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7267 +++ linux/fs/aufs/debug.c 2023-08-28 12:34:39.956636132 +0200
7269 +// SPDX-License-Identifier: GPL-2.0
7271 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7273 + * This program is free software; you can redistribute it and/or modify
7274 + * it under the terms of the GNU General Public License as published by
7275 + * the Free Software Foundation; either version 2 of the License, or
7276 + * (at your option) any later version.
7278 + * This program is distributed in the hope that it will be useful,
7279 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7280 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7281 + * GNU General Public License for more details.
7283 + * You should have received a copy of the GNU General Public License
7284 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7288 + * debug print functions
7291 +#include <linux/iversion.h>
7294 +/* Returns 0, or -errno. arg is in kp->arg. */
7295 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7299 + err = kstrtoint(val, 0, &n);
7309 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7310 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7315 + return sprintf(buffer, "%d", atomic_read(a));
7318 +static const struct kernel_param_ops param_ops_atomic_t = {
7319 + .set = param_atomic_t_set,
7320 + .get = param_atomic_t_get
7321 + /* void (*free)(void *arg) */
7324 +atomic_t aufs_debug = ATOMIC_INIT(0);
7325 +MODULE_PARM_DESC(debug, "debug print");
7326 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7328 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7329 +char *au_plevel = KERN_DEBUG;
7330 +#define dpri(fmt, ...) do { \
7332 + && strcmp(au_plevel, KERN_DEBUG)) \
7333 + || au_debug_test()) \
7334 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7337 +/* ---------------------------------------------------------------------- */
7339 +void au_dpri_whlist(struct au_nhash *whlist)
7341 + unsigned long ul, n;
7342 + struct hlist_head *head;
7343 + struct au_vdir_wh *pos;
7345 + n = whlist->nh_num;
7346 + head = whlist->nh_head;
7347 + for (ul = 0; ul < n; ul++) {
7348 + hlist_for_each_entry(pos, head, wh_hash)
7349 + dpri("b%d, %.*s, %d\n",
7351 + pos->wh_str.len, pos->wh_str.name,
7357 +void au_dpri_vdir(struct au_vdir *vdir)
7360 + union au_vdir_deblk_p p;
7363 + if (!vdir || IS_ERR(vdir)) {
7364 + dpri("err %ld\n", PTR_ERR(vdir));
7368 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7369 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7370 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7371 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7372 + p.deblk = vdir->vd_deblk[ul];
7374 + dpri("[%lu]: %p\n", ul, o);
7378 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7379 + struct dentry *wh)
7384 + if (!inode || IS_ERR(inode)) {
7385 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7389 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7390 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7391 + && sizeof(inode->i_blocks) != sizeof(u64));
7393 + n = (void *)wh->d_name.name;
7394 + l = wh->d_name.len;
7397 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7398 + " acl %p, def_acl %p,"
7399 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7401 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7402 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7403 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7404 + inode->i_acl, inode->i_default_acl,
7405 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7406 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7407 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7408 + inode->i_generation,
7409 + l ? ", wh " : "", l, n);
7413 +void au_dpri_inode(struct inode *inode)
7415 + struct au_iinfo *iinfo;
7416 + struct au_hinode *hi;
7417 + aufs_bindex_t bindex;
7420 + err = do_pri_inode(-1, inode, -1, NULL);
7421 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7424 + iinfo = au_ii(inode);
7425 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7426 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7427 + if (iinfo->ii_btop < 0)
7430 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7431 + hi = au_hinode(iinfo, bindex);
7433 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7437 +void au_dpri_dalias(struct inode *inode)
7441 + spin_lock(&inode->i_lock);
7442 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7443 + au_dpri_dentry(d);
7444 + spin_unlock(&inode->i_lock);
7447 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7449 + struct dentry *wh = NULL;
7451 + struct inode *inode;
7452 + struct au_iinfo *iinfo;
7453 + struct au_hinode *hi;
7455 + if (!dentry || IS_ERR(dentry)) {
7456 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7459 + /* do not call dget_parent() here */
7460 + /* note: access d_xxx without d_lock */
7461 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7462 + bindex, dentry, dentry,
7463 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7464 + au_dcount(dentry), dentry->d_flags,
7465 + d_unhashed(dentry) ? "un" : "");
7468 + if (d_is_positive(dentry))
7469 + inode = d_inode(dentry);
7471 + && au_test_aufs(dentry->d_sb)
7473 + && !au_is_bad_inode(inode)) {
7474 + iinfo = au_ii(inode);
7475 + hi = au_hinode(iinfo, bindex);
7477 + wh = hi->hi_whdentry;
7479 + do_pri_inode(bindex, inode, hn, wh);
7483 +void au_dpri_dentry(struct dentry *dentry)
7485 + struct au_dinfo *dinfo;
7486 + aufs_bindex_t bindex;
7489 + err = do_pri_dentry(-1, dentry);
7490 + if (err || !au_test_aufs(dentry->d_sb))
7493 + dinfo = au_di(dentry);
7496 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7497 + dinfo->di_btop, dinfo->di_bbot,
7498 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7499 + dinfo->di_tmpfile);
7500 + if (dinfo->di_btop < 0)
7502 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7503 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7506 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7510 + if (!file || IS_ERR(file)) {
7511 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7516 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7517 + && au_test_aufs(file->f_path.dentry->d_sb)
7519 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7520 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7521 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7522 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7523 + file->f_version, file->f_pos, a);
7524 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7525 + do_pri_dentry(bindex, file->f_path.dentry);
7529 +void au_dpri_file(struct file *file)
7531 + struct au_finfo *finfo;
7532 + struct au_fidir *fidir;
7533 + struct au_hfile *hfile;
7534 + aufs_bindex_t bindex;
7537 + err = do_pri_file(-1, file);
7539 + || IS_ERR_OR_NULL(file->f_path.dentry)
7540 + || !au_test_aufs(file->f_path.dentry->d_sb))
7543 + finfo = au_fi(file);
7546 + if (finfo->fi_btop < 0)
7548 + fidir = finfo->fi_hdir;
7550 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7552 + for (bindex = finfo->fi_btop;
7553 + bindex >= 0 && bindex <= fidir->fd_bbot;
7555 + hfile = fidir->fd_hfile + bindex;
7556 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7560 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7562 + struct vfsmount *mnt;
7563 + struct super_block *sb;
7565 + if (!br || IS_ERR(br))
7567 + mnt = au_br_mnt(br);
7568 + if (!mnt || IS_ERR(mnt))
7571 + if (!sb || IS_ERR(sb))
7574 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7575 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7577 + bindex, br->br_perm, br->br_id, br->br_wbr,
7578 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7579 + sb->s_flags, sb->s_count,
7580 + atomic_read(&sb->s_active),
7581 + !!au_xino_file(br->br_xino, /*idx*/-1));
7585 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7589 +void au_dpri_sb(struct super_block *sb)
7591 + struct au_sbinfo *sbinfo;
7592 + aufs_bindex_t bindex;
7594 + /* to reduce stack size */
7596 + struct vfsmount mnt;
7597 + struct au_branch fake;
7600 + /* this function can be called from magic sysrq */
7601 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7602 + if (unlikely(!a)) {
7603 + dpri("no memory\n");
7607 + a->mnt.mnt_sb = sb;
7608 + a->fake.br_path.mnt = &a->mnt;
7609 + err = do_pri_br(-1, &a->fake);
7611 + dpri("dev 0x%x\n", sb->s_dev);
7612 + if (err || !au_test_aufs(sb))
7615 + sbinfo = au_sbi(sb);
7618 + dpri("nw %d, gen %u, kobj %d\n",
7619 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7620 + kref_read(&sbinfo->si_kobj.kref));
7621 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7622 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7625 +/* ---------------------------------------------------------------------- */
7627 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7629 + struct inode *h_inode, *inode = d_inode(dentry);
7630 + struct dentry *h_dentry;
7631 + aufs_bindex_t bindex, bbot, bi;
7633 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7636 + bbot = au_dbbot(dentry);
7637 + bi = au_ibbot(inode);
7640 + bindex = au_dbtop(dentry);
7641 + bi = au_ibtop(inode);
7645 + for (; bindex <= bbot; bindex++) {
7646 + h_dentry = au_h_dptr(dentry, bindex);
7649 + h_inode = au_h_iptr(inode, bindex);
7650 + if (unlikely(h_inode != d_inode(h_dentry))) {
7652 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7653 + AuDbgDentry(dentry);
7654 + AuDbgInode(inode);
7656 + if (au_test_fuse(h_inode->i_sb))
7664 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7667 + struct au_dcsub_pages dpages;
7668 + struct au_dpage *dpage;
7669 + struct dentry **dentries;
7671 + err = au_dpages_init(&dpages, GFP_NOFS);
7673 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7675 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7676 + dpage = dpages.dpages + i;
7677 + dentries = dpage->dentries;
7678 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7679 + AuDebugOn(au_digen_test(dentries[j], sigen));
7681 + au_dpages_free(&dpages);
7684 +void au_dbg_verify_kthread(void)
7686 + if (au_wkq_test()) {
7689 + * It may be recursive, but udba=notify between two aufs mounts,
7690 + * where a single ro branch is shared, is not a problem.
7696 +/* ---------------------------------------------------------------------- */
7698 +int __init au_debug_init(void)
7700 + aufs_bindex_t bindex;
7701 + struct au_vdir_destr destr;
7704 + AuDebugOn(bindex >= 0);
7707 + AuDebugOn(destr.len < NAME_MAX);
7709 +#ifdef CONFIG_4KSTACKS
7710 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7715 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7716 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7717 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7719 +/* SPDX-License-Identifier: GPL-2.0 */
7721 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7723 + * This program is free software; you can redistribute it and/or modify
7724 + * it under the terms of the GNU General Public License as published by
7725 + * the Free Software Foundation; either version 2 of the License, or
7726 + * (at your option) any later version.
7728 + * This program is distributed in the hope that it will be useful,
7729 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7730 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7731 + * GNU General Public License for more details.
7733 + * You should have received a copy of the GNU General Public License
7734 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7738 + * debug print functions
7741 +#ifndef __AUFS_DEBUG_H__
7742 +#define __AUFS_DEBUG_H__
7746 +#include <linux/atomic.h>
7747 +#include <linux/module.h>
7748 +#include <linux/kallsyms.h>
7749 +#include <linux/sysrq.h>
7751 +#ifdef CONFIG_AUFS_DEBUG
7752 +#define AuDebugOn(a) BUG_ON(a)
7754 +/* module parameter */
7755 +extern atomic_t aufs_debug;
7756 +static inline void au_debug_on(void)
7758 + atomic_inc(&aufs_debug);
7760 +static inline void au_debug_off(void)
7762 + atomic_dec_if_positive(&aufs_debug);
7765 +static inline int au_debug_test(void)
7767 + return atomic_read(&aufs_debug) > 0;
7770 +#define AuDebugOn(a) do {} while (0)
7771 +AuStubVoid(au_debug_on, void)
7772 +AuStubVoid(au_debug_off, void)
7773 +AuStubInt0(au_debug_test, void)
7774 +#endif /* CONFIG_AUFS_DEBUG */
7776 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7778 +/* ---------------------------------------------------------------------- */
7782 +#define AuDbg(fmt, ...) do { \
7783 + if (au_debug_test()) \
7784 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7786 +#define AuLabel(l) AuDbg(#l "\n")
7787 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7788 +#define AuWarn1(fmt, ...) do { \
7789 + static unsigned char _c; \
7791 + pr_warn(fmt, ##__VA_ARGS__); \
7794 +#define AuErr1(fmt, ...) do { \
7795 + static unsigned char _c; \
7797 + pr_err(fmt, ##__VA_ARGS__); \
7800 +#define AuIOErr1(fmt, ...) do { \
7801 + static unsigned char _c; \
7803 + AuIOErr(fmt, ##__VA_ARGS__); \
7806 +#define AuUnsupportMsg "This operation is not supported." \
7807 + " Please report this application to aufs-users ML."
7808 +#define AuUnsupport(fmt, ...) do { \
7809 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7813 +#define AuTraceErr(e) do { \
7814 + if (unlikely((e) < 0)) \
7815 + AuDbg("err %d\n", (int)(e)); \
7818 +#define AuTraceErrPtr(p) do { \
7820 + AuDbg("err %ld\n", PTR_ERR(p)); \
7823 +/* dirty macros for debug print, use with "%.*s" and caution */
7824 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7826 +/* ---------------------------------------------------------------------- */
7829 +#ifdef CONFIG_AUFS_DEBUG
7830 +extern struct mutex au_dbg_mtx;
7831 +extern char *au_plevel;
7833 +void au_dpri_whlist(struct au_nhash *whlist);
7835 +void au_dpri_vdir(struct au_vdir *vdir);
7837 +void au_dpri_inode(struct inode *inode);
7838 +void au_dpri_dalias(struct inode *inode);
7839 +void au_dpri_dentry(struct dentry *dentry);
7841 +void au_dpri_file(struct file *filp);
7842 +struct super_block;
7843 +void au_dpri_sb(struct super_block *sb);
7845 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7846 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7847 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7848 +void au_dbg_verify_kthread(void);
7850 +int __init au_debug_init(void);
7852 +#define AuDbgWhlist(w) do { \
7853 + mutex_lock(&au_dbg_mtx); \
7855 + au_dpri_whlist(w); \
7856 + mutex_unlock(&au_dbg_mtx); \
7859 +#define AuDbgVdir(v) do { \
7860 + mutex_lock(&au_dbg_mtx); \
7862 + au_dpri_vdir(v); \
7863 + mutex_unlock(&au_dbg_mtx); \
7866 +#define AuDbgInode(i) do { \
7867 + mutex_lock(&au_dbg_mtx); \
7869 + au_dpri_inode(i); \
7870 + mutex_unlock(&au_dbg_mtx); \
7873 +#define AuDbgDAlias(i) do { \
7874 + mutex_lock(&au_dbg_mtx); \
7876 + au_dpri_dalias(i); \
7877 + mutex_unlock(&au_dbg_mtx); \
7880 +#define AuDbgDentry(d) do { \
7881 + mutex_lock(&au_dbg_mtx); \
7883 + au_dpri_dentry(d); \
7884 + mutex_unlock(&au_dbg_mtx); \
7887 +#define AuDbgFile(f) do { \
7888 + mutex_lock(&au_dbg_mtx); \
7890 + au_dpri_file(f); \
7891 + mutex_unlock(&au_dbg_mtx); \
7894 +#define AuDbgSb(sb) do { \
7895 + mutex_lock(&au_dbg_mtx); \
7896 + AuDbg(#sb "\n"); \
7898 + mutex_unlock(&au_dbg_mtx); \
7901 +#define AuDbgSym(addr) do { \
7902 + char sym[KSYM_SYMBOL_LEN]; \
7903 + sprint_symbol(sym, (unsigned long)addr); \
7904 + AuDbg("%s\n", sym); \
7907 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7908 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7909 +AuStubVoid(au_dbg_verify_kthread, void)
7910 +AuStubInt0(__init au_debug_init, void)
7912 +#define AuDbgWhlist(w) do {} while (0)
7913 +#define AuDbgVdir(v) do {} while (0)
7914 +#define AuDbgInode(i) do {} while (0)
7915 +#define AuDbgDAlias(i) do {} while (0)
7916 +#define AuDbgDentry(d) do {} while (0)
7917 +#define AuDbgFile(f) do {} while (0)
7918 +#define AuDbgSb(sb) do {} while (0)
7919 +#define AuDbgSym(addr) do {} while (0)
7920 +#endif /* CONFIG_AUFS_DEBUG */
7922 +/* ---------------------------------------------------------------------- */
7924 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7925 +int __init au_sysrq_init(void);
7926 +void au_sysrq_fin(void);
7928 +#ifdef CONFIG_HW_CONSOLE
7929 +#define au_dbg_blocked() do { \
7931 + handle_sysrq('w'); \
7934 +AuStubVoid(au_dbg_blocked, void)
7938 +AuStubInt0(__init au_sysrq_init, void)
7939 +AuStubVoid(au_sysrq_fin, void)
7940 +AuStubVoid(au_dbg_blocked, void)
7941 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7943 +#endif /* __KERNEL__ */
7944 +#endif /* __AUFS_DEBUG_H__ */
7945 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7946 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7947 +++ linux/fs/aufs/dentry.c 2023-08-28 12:34:39.956636132 +0200
7949 +// SPDX-License-Identifier: GPL-2.0
7951 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7953 + * This program is free software; you can redistribute it and/or modify
7954 + * it under the terms of the GNU General Public License as published by
7955 + * the Free Software Foundation; either version 2 of the License, or
7956 + * (at your option) any later version.
7958 + * This program is distributed in the hope that it will be useful,
7959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7961 + * GNU General Public License for more details.
7963 + * You should have received a copy of the GNU General Public License
7964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7968 + * lookup and dentry operations
7971 +#include <linux/iversion.h>
7975 + * returns positive/negative dentry, NULL or an error.
7976 + * NULL means whiteout-ed or not-found.
7978 +static struct dentry*
7979 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7980 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
7982 + struct dentry *h_dentry;
7983 + struct inode *h_inode;
7984 + struct au_branch *br;
7985 + struct mnt_idmap *h_idmap;
7986 + struct path h_path;
7987 + int wh_found, opq;
7988 + unsigned char wh_able;
7989 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7990 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7994 + br = au_sbr(dentry->d_sb, bindex);
7995 + h_path.dentry = h_parent;
7996 + h_path.mnt = au_br_mnt(br);
7997 + h_idmap = au_br_idmap(br);
7998 + wh_able = !!au_br_whable(br->br_perm);
8000 + wh_found = au_wh_test(h_idmap, &h_path, &args->whname,
8002 + h_dentry = ERR_PTR(wh_found);
8005 + if (unlikely(wh_found < 0))
8008 + /* We found a whiteout */
8009 + /* au_set_dbbot(dentry, bindex); */
8010 + au_set_dbwh(dentry, bindex);
8012 + return NULL; /* success */
8016 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8018 + h_dentry = au_sio_lkup_one(h_idmap, args->name, &h_path);
8019 + if (IS_ERR(h_dentry)) {
8020 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8026 + h_inode = d_inode(h_dentry);
8027 + if (d_is_negative(h_dentry)) {
8030 + } else if (wh_found
8031 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8033 + else if (au_ftest_lkup(args->flags, DIRREN)
8035 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8036 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8037 + (unsigned long long)h_inode->i_ino);
8041 + if (au_dbbot(dentry) <= bindex)
8042 + au_set_dbbot(dentry, bindex);
8043 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8044 + au_set_dbtop(dentry, bindex);
8045 + au_set_h_dptr(dentry, bindex, h_dentry);
8047 + if (!d_is_dir(h_dentry)
8049 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8050 + goto out; /* success */
8052 + h_path.dentry = h_dentry;
8053 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8054 + opq = au_diropq_test(h_idmap, &h_path);
8055 + inode_unlock_shared(h_inode);
8057 + au_set_dbdiropq(dentry, bindex);
8058 + else if (unlikely(opq < 0)) {
8059 + au_set_h_dptr(dentry, bindex, NULL);
8060 + h_dentry = ERR_PTR(opq);
8071 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8073 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8074 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8080 + * returns the number of lower positive dentries,
8081 + * otherwise an error.
8082 + * can be called at unlinking with @type is zero.
8084 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8085 + unsigned int flags)
8087 + int npositive, err;
8088 + aufs_bindex_t bindex, btail, bdiropq;
8089 + unsigned char isdir, dirperm1, dirren;
8090 + struct au_do_lookup_args args = {
8092 + .name = &dentry->d_name
8094 + struct dentry *parent;
8095 + struct super_block *sb;
8097 + sb = dentry->d_sb;
8098 + err = au_test_shwh(sb, args.name);
8099 + if (unlikely(err))
8102 + err = au_wh_name_alloc(&args.whname, args.name);
8103 + if (unlikely(err))
8106 + isdir = !!d_is_dir(dentry);
8107 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8108 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8110 + au_fset_lkup(args.flags, DIRREN);
8113 + parent = dget_parent(dentry);
8114 + btail = au_dbtaildir(parent);
8115 + for (bindex = btop; bindex <= btail; bindex++) {
8116 + struct dentry *h_parent, *h_dentry;
8117 + struct inode *h_inode, *h_dir;
8118 + struct au_branch *br;
8120 + h_dentry = au_h_dptr(dentry, bindex);
8122 + if (d_is_positive(h_dentry))
8126 + h_parent = au_h_dptr(parent, bindex);
8127 + if (!h_parent || !d_is_dir(h_parent))
8131 + /* if the inum matches, then use the prepared name */
8132 + err = au_dr_lkup_name(&args, bindex);
8133 + if (unlikely(err))
8137 + h_dir = d_inode(h_parent);
8138 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8139 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8140 + inode_unlock_shared(h_dir);
8141 + err = PTR_ERR(h_dentry);
8142 + if (IS_ERR(h_dentry))
8145 + au_fclr_lkup(args.flags, ALLOW_NEG);
8147 + au_fset_lkup(args.flags, IGNORE_PERM);
8149 + if (au_dbwh(dentry) == bindex)
8153 + if (d_is_negative(h_dentry))
8155 + h_inode = d_inode(h_dentry);
8158 + args.type = h_inode->i_mode & S_IFMT;
8159 + if (args.type != S_IFDIR)
8162 + /* the type of lower may be different */
8163 + bdiropq = au_dbdiropq(dentry);
8164 + if (bdiropq >= 0 && bdiropq <= bindex)
8167 + br = au_sbr(sb, bindex);
8169 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8170 + /*add_ent*/NULL)) {
8171 + /* prepare next name to lookup */
8172 + err = au_dr_lkup(&args, dentry, bindex);
8173 + if (unlikely(err))
8179 + AuLabel(positive);
8180 + au_update_dbtop(dentry);
8183 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8184 + && au_dbtop(dentry) < 0)) {
8186 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8192 + au_kfree_try_rcu(args.whname.name);
8194 + au_dr_lkup_fin(&args);
8199 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
8200 + struct path *ppath)
8202 + struct dentry *dentry;
8205 + if (!au_test_h_perm_sio(idmap, d_inode(ppath->dentry), MAY_EXEC))
8206 + dentry = vfsub_lkup_one(name, ppath);
8208 + struct vfsub_lkup_one_args args = {
8214 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8215 + if (unlikely(wkq_err))
8216 + dentry = ERR_PTR(wkq_err);
8223 + * lookup @dentry on @bindex which should be negative.
8225 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8228 + struct dentry *parent, *h_dentry;
8229 + struct au_branch *br;
8230 + struct mnt_idmap *h_idmap;
8231 + struct path h_ppath;
8233 + parent = dget_parent(dentry);
8234 + br = au_sbr(dentry->d_sb, bindex);
8235 + h_ppath.dentry = au_h_dptr(parent, bindex);
8236 + h_ppath.mnt = au_br_mnt(br);
8237 + h_idmap = au_br_idmap(br);
8239 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8241 + h_dentry = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
8242 + err = PTR_ERR(h_dentry);
8243 + if (IS_ERR(h_dentry))
8245 + if (unlikely(d_is_positive(h_dentry))) {
8247 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8253 + if (bindex < au_dbtop(dentry))
8254 + au_set_dbtop(dentry, bindex);
8255 + if (au_dbbot(dentry) < bindex)
8256 + au_set_dbbot(dentry, bindex);
8257 + au_set_h_dptr(dentry, bindex, h_dentry);
8264 +/* ---------------------------------------------------------------------- */
8266 +/* subset of struct inode */
8268 + unsigned long i_ino;
8269 + /* unsigned int i_nlink; */
8275 + blkcnt_t i_blocks;
8280 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8282 + ia->i_ino = h_inode->i_ino;
8283 + /* ia->i_nlink = h_inode->i_nlink; */
8284 + ia->i_uid = h_inode->i_uid;
8285 + ia->i_gid = h_inode->i_gid;
8286 + ia->i_version = inode_query_iversion(h_inode);
8288 + ia->i_size = h_inode->i_size;
8289 + ia->i_blocks = h_inode->i_blocks;
8291 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8294 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8296 + return ia->i_ino != h_inode->i_ino
8297 + /* || ia->i_nlink != h_inode->i_nlink */
8298 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8299 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8300 + || !inode_eq_iversion(h_inode, ia->i_version)
8302 + || ia->i_size != h_inode->i_size
8303 + || ia->i_blocks != h_inode->i_blocks
8305 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8308 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8309 + struct au_branch *br)
8312 + struct au_iattr ia;
8313 + struct inode *h_inode;
8314 + struct dentry *h_d;
8315 + struct super_block *h_sb;
8316 + struct path h_ppath;
8319 + memset(&ia, -1, sizeof(ia));
8320 + h_sb = h_dentry->d_sb;
8322 + if (d_is_positive(h_dentry)) {
8323 + h_inode = d_inode(h_dentry);
8324 + au_iattr_save(&ia, h_inode);
8325 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8326 + /* nfs d_revalidate may return 0 for negative dentry */
8327 + /* fuse d_revalidate always return 0 for negative dentry */
8330 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8331 + h_ppath.dentry = h_parent;
8332 + h_ppath.mnt = au_br_mnt(br);
8333 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8334 + err = PTR_ERR(h_d);
8339 + if (unlikely(h_d != h_dentry
8340 + || d_inode(h_d) != h_inode
8341 + || (h_inode && au_iattr_test(&ia, h_inode))))
8342 + err = au_busy_or_stale();
8350 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8351 + struct dentry *h_parent, struct au_branch *br)
8356 + if (udba == AuOpt_UDBA_REVAL
8357 + && !au_test_fs_remote(h_dentry->d_sb)) {
8359 + err = (d_inode(h_dentry->d_parent) != h_dir);
8360 + } else if (udba != AuOpt_UDBA_NONE)
8361 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8366 +/* ---------------------------------------------------------------------- */
8368 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8371 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8372 + struct au_hdentry tmp, *p, *q;
8373 + struct au_dinfo *dinfo;
8374 + struct super_block *sb;
8376 + DiMustWriteLock(dentry);
8378 + sb = dentry->d_sb;
8379 + dinfo = au_di(dentry);
8380 + bbot = dinfo->di_bbot;
8381 + bwh = dinfo->di_bwh;
8382 + bdiropq = dinfo->di_bdiropq;
8383 + bindex = dinfo->di_btop;
8384 + p = au_hdentry(dinfo, bindex);
8385 + for (; bindex <= bbot; bindex++, p++) {
8386 + if (!p->hd_dentry)
8389 + new_bindex = au_br_index(sb, p->hd_id);
8390 + if (new_bindex == bindex)
8393 + if (dinfo->di_bwh == bindex)
8395 + if (dinfo->di_bdiropq == bindex)
8396 + bdiropq = new_bindex;
8397 + if (new_bindex < 0) {
8399 + p->hd_dentry = NULL;
8403 + /* swap two lower dentries, and loop again */
8404 + q = au_hdentry(dinfo, new_bindex);
8408 + if (tmp.hd_dentry) {
8414 + dinfo->di_bwh = -1;
8415 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8416 + dinfo->di_bwh = bwh;
8418 + dinfo->di_bdiropq = -1;
8420 + && bdiropq <= au_sbbot(sb)
8421 + && au_sbr_whable(sb, bdiropq))
8422 + dinfo->di_bdiropq = bdiropq;
8425 + dinfo->di_btop = -1;
8426 + dinfo->di_bbot = -1;
8427 + bbot = au_dbbot(parent);
8429 + p = au_hdentry(dinfo, bindex);
8430 + for (; bindex <= bbot; bindex++, p++)
8431 + if (p->hd_dentry) {
8432 + dinfo->di_btop = bindex;
8436 + if (dinfo->di_btop >= 0) {
8438 + p = au_hdentry(dinfo, bindex);
8439 + for (; bindex >= 0; bindex--, p--)
8440 + if (p->hd_dentry) {
8441 + dinfo->di_bbot = bindex;
8450 +static void au_do_hide(struct dentry *dentry)
8452 + struct inode *inode;
8454 + if (d_really_is_positive(dentry)) {
8455 + inode = d_inode(dentry);
8456 + if (!d_is_dir(dentry)) {
8457 + if (inode->i_nlink && !d_unhashed(dentry))
8458 + drop_nlink(inode);
8460 + clear_nlink(inode);
8461 + /* stop next lookup */
8462 + inode->i_flags |= S_DEAD;
8464 + smp_mb(); /* necessary? */
8469 +static int au_hide_children(struct dentry *parent)
8471 + int err, i, j, ndentry;
8472 + struct au_dcsub_pages dpages;
8473 + struct au_dpage *dpage;
8474 + struct dentry *dentry;
8476 + err = au_dpages_init(&dpages, GFP_NOFS);
8477 + if (unlikely(err))
8479 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8480 + if (unlikely(err))
8483 + /* in reverse order */
8484 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8485 + dpage = dpages.dpages + i;
8486 + ndentry = dpage->ndentry;
8487 + for (j = ndentry - 1; j >= 0; j--) {
8488 + dentry = dpage->dentries[j];
8489 + if (dentry != parent)
8490 + au_do_hide(dentry);
8495 + au_dpages_free(&dpages);
8500 +static void au_hide(struct dentry *dentry)
8504 + AuDbgDentry(dentry);
8505 + if (d_is_dir(dentry)) {
8506 + /* shrink_dcache_parent(dentry); */
8507 + err = au_hide_children(dentry);
8508 + if (unlikely(err))
8509 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8512 + au_do_hide(dentry);
8516 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8518 + * a dirty branch is added
8519 + * - on the top of layers
8520 + * - in the middle of layers
8521 + * - to the bottom of layers
8523 + * on the added branch there exists
8526 + * - a same named entry
8528 + * * negative --> positive
8529 + * * positive --> positive
8530 + * - type is unchanged
8531 + * - type is changed
8533 + * * negative --> negative
8534 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8537 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8538 + struct au_dinfo *tmp)
8541 + aufs_bindex_t bindex, bbot;
8543 + struct dentry *dentry;
8544 + struct inode *inode;
8546 + } orig_h, tmp_h = {
8549 + struct au_hdentry *hd;
8550 + struct inode *inode, *h_inode;
8551 + struct dentry *h_dentry;
8554 + AuDebugOn(dinfo->di_btop < 0);
8556 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8557 + orig_h.inode = NULL;
8558 + if (d_is_positive(orig_h.dentry)) {
8559 + orig_h.inode = d_inode(orig_h.dentry);
8560 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8562 + if (tmp->di_btop >= 0) {
8563 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8564 + if (d_is_positive(tmp_h.dentry)) {
8565 + tmp_h.inode = d_inode(tmp_h.dentry);
8566 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8571 + if (d_really_is_positive(dentry))
8572 + inode = d_inode(dentry);
8573 + if (!orig_h.inode) {
8574 + AuDbg("negative originally\n");
8580 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8581 + AuDebugOn(dinfo->di_bdiropq != -1);
8583 + if (!tmp_h.inode) {
8584 + AuDbg("negative --> negative\n");
8585 + /* should have only one negative lower */
8586 + if (tmp->di_btop >= 0
8587 + && tmp->di_btop < dinfo->di_btop) {
8588 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8589 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8590 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8591 + au_di_cp(dinfo, tmp);
8592 + hd = au_hdentry(tmp, tmp->di_btop);
8593 + au_set_h_dptr(dentry, tmp->di_btop,
8594 + dget(hd->hd_dentry));
8596 + au_dbg_verify_dinode(dentry);
8598 + AuDbg("negative --> positive\n");
8600 + * similar to the behaviour of creating with bypassing
8602 + * unhash it in order to force an error in the
8603 + * succeeding create operation.
8604 + * we should not set S_DEAD here.
8607 + /* au_di_swap(tmp, dinfo); */
8608 + au_dbg_verify_dinode(dentry);
8611 + AuDbg("positive originally\n");
8612 + /* inode may be NULL */
8613 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8614 + if (!tmp_h.inode) {
8615 + AuDbg("positive --> negative\n");
8616 + /* or bypassing aufs */
8618 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8619 + dinfo->di_bwh = tmp->di_bwh;
8621 + err = au_refresh_hinode_self(inode);
8622 + au_dbg_verify_dinode(dentry);
8623 + } else if (orig_h.mode == tmp_h.mode) {
8624 + AuDbg("positive --> positive, same type\n");
8625 + if (!S_ISDIR(orig_h.mode)
8626 + && dinfo->di_btop > tmp->di_btop) {
8628 + * similar to the behaviour of removing and
8633 + err = au_refresh_hinode_self(inode);
8634 + au_dbg_verify_dinode(dentry);
8636 + /* fill empty slots */
8637 + if (dinfo->di_btop > tmp->di_btop)
8638 + dinfo->di_btop = tmp->di_btop;
8639 + if (dinfo->di_bbot < tmp->di_bbot)
8640 + dinfo->di_bbot = tmp->di_bbot;
8641 + dinfo->di_bwh = tmp->di_bwh;
8642 + dinfo->di_bdiropq = tmp->di_bdiropq;
8643 + bbot = dinfo->di_bbot;
8644 + bindex = tmp->di_btop;
8645 + hd = au_hdentry(tmp, bindex);
8646 + for (; bindex <= bbot; bindex++, hd++) {
8647 + if (au_h_dptr(dentry, bindex))
8649 + h_dentry = hd->hd_dentry;
8652 + AuDebugOn(d_is_negative(h_dentry));
8653 + h_inode = d_inode(h_dentry);
8654 + AuDebugOn(orig_h.mode
8655 + != (h_inode->i_mode
8657 + au_set_h_dptr(dentry, bindex,
8661 + err = au_refresh_hinode(inode, dentry);
8662 + au_dbg_verify_dinode(dentry);
8665 + AuDbg("positive --> positive, different type\n");
8666 + /* similar to the behaviour of removing and creating */
8669 + err = au_refresh_hinode_self(inode);
8670 + au_dbg_verify_dinode(dentry);
8678 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8680 + const struct dentry_operations *dop
8681 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8682 + static const unsigned int mask
8683 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8685 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8687 + if (dentry->d_op == dop)
8690 + AuDbg("%pd\n", dentry);
8691 + spin_lock(&dentry->d_lock);
8692 + if (dop == &aufs_dop)
8693 + dentry->d_flags |= mask;
8695 + dentry->d_flags &= ~mask;
8696 + dentry->d_op = dop;
8697 + spin_unlock(&dentry->d_lock);
8700 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8702 + int err, ebrange, nbr;
8703 + unsigned int sigen;
8704 + struct au_dinfo *dinfo, *tmp;
8705 + struct super_block *sb;
8706 + struct inode *inode;
8708 + DiMustWriteLock(dentry);
8709 + AuDebugOn(IS_ROOT(dentry));
8710 + AuDebugOn(d_really_is_negative(parent));
8712 + sb = dentry->d_sb;
8713 + sigen = au_sigen(sb);
8714 + err = au_digen_test(parent, sigen);
8715 + if (unlikely(err))
8718 + nbr = au_sbbot(sb) + 1;
8719 + dinfo = au_di(dentry);
8720 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8721 + if (unlikely(err))
8723 + ebrange = au_dbrange_test(dentry);
8725 + ebrange = au_do_refresh_hdentry(dentry, parent);
8727 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8728 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8729 + if (d_really_is_positive(dentry)) {
8730 + inode = d_inode(dentry);
8731 + err = au_refresh_hinode_self(inode);
8733 + au_dbg_verify_dinode(dentry);
8735 + goto out_dgen; /* success */
8739 + /* temporary dinfo */
8740 + AuDbgDentry(dentry);
8742 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8743 + if (unlikely(!tmp))
8745 + au_di_swap(tmp, dinfo);
8746 + /* returns the number of positive dentries */
8748 + * if current working dir is removed, it returns an error.
8749 + * but the dentry is legal.
8751 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8752 + AuDbgDentry(dentry);
8753 + au_di_swap(tmp, dinfo);
8754 + if (err == -ENOENT)
8757 + /* compare/refresh by dinfo */
8758 + AuDbgDentry(dentry);
8759 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8760 + au_dbg_verify_dinode(dentry);
8763 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8764 + au_rw_write_unlock(&tmp->di_rwsem);
8766 + if (unlikely(err))
8770 + au_update_digen(dentry);
8772 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8773 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8774 + AuDbgDentry(dentry);
8780 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8781 + struct dentry *dentry, aufs_bindex_t bindex)
8786 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8789 + AuDbg("b%d\n", bindex);
8791 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8792 + * due to whiteout and branch permission.
8794 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8795 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8796 + /* it may return tri-state */
8797 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8799 + if (unlikely(valid < 0))
8809 +/* todo: remove this */
8810 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8811 + unsigned int flags, int do_udba, int dirren)
8814 + umode_t mode, h_mode;
8815 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8816 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8817 + struct inode *h_inode, *h_cached_inode;
8818 + struct dentry *h_dentry;
8819 + struct qstr *name, *h_name;
8826 + unhashed = !!d_unhashed(dentry);
8827 + is_root = !!IS_ROOT(dentry);
8828 + name = &dentry->d_name;
8829 + tmpfile = au_di(dentry)->di_tmpfile;
8832 + * Theoretically, REVAL test should be unnecessary in case of
8834 + * But {fs,i}notify doesn't fire some necessary events,
8835 + * IN_ATTRIB for atime/nlink/pageio
8836 + * Let's do REVAL test too.
8838 + if (do_udba && inode) {
8839 + mode = (inode->i_mode & S_IFMT);
8840 + plus = (inode->i_nlink > 0);
8841 + ibs = au_ibtop(inode);
8842 + ibe = au_ibbot(inode);
8845 + btop = au_dbtop(dentry);
8847 + if (inode && S_ISDIR(inode->i_mode))
8848 + btail = au_dbtaildir(dentry);
8849 + for (bindex = btop; bindex <= btail; bindex++) {
8850 + h_dentry = au_h_dptr(dentry, bindex);
8854 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8855 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8856 + spin_lock(&h_dentry->d_lock);
8857 + h_name = &h_dentry->d_name;
8858 + if (unlikely(do_udba
8861 + && (unhashed != !!d_unhashed(h_dentry)
8862 + || (!tmpfile && !dirren
8863 + && !au_qstreq(name, h_name))
8866 + && !(flags & LOOKUP_OPEN)
8867 + && (h_dentry->d_flags
8868 + & DCACHE_NFSFS_RENAMED)))
8872 + h_unhashed = d_unhashed(h_dentry);
8873 + spin_unlock(&h_dentry->d_lock);
8874 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8875 + unhashed, h_unhashed, dentry, h_dentry);
8878 + spin_unlock(&h_dentry->d_lock);
8880 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8881 + if (unlikely(err))
8882 + /* do not goto err, to keep the errno */
8885 + /* todo: plink too? */
8890 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8894 + if (d_is_positive(h_dentry))
8895 + h_inode = d_inode(h_dentry);
8898 + h_cached_inode = h_inode;
8900 + h_mode = (h_inode->i_mode & S_IFMT);
8901 + h_plus = (h_inode->i_nlink > 0);
8903 + if (inode && ibs <= bindex && bindex <= ibe)
8904 + h_cached_inode = au_h_iptr(inode, bindex);
8907 + if (unlikely(plus != h_plus && !tmpfile))
8910 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8912 + && !IS_ROOT(h_dentry)
8913 + && unhashed != d_unhashed(h_dentry)))
8916 + if (unlikely(mode != h_mode
8917 + || h_cached_inode != h_inode))
8930 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8931 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8934 + struct dentry *parent;
8936 + if (!au_digen_test(dentry, sigen))
8939 + parent = dget_parent(dentry);
8940 + di_read_lock_parent(parent, AuLock_IR);
8941 + AuDebugOn(au_digen_test(parent, sigen));
8942 + au_dbg_verify_gen(parent, sigen);
8943 + err = au_refresh_dentry(dentry, parent);
8944 + di_read_unlock(parent, AuLock_IR);
8950 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8953 + struct dentry *d, *parent;
8955 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8956 + return simple_reval_dpath(dentry, sigen);
8958 + /* slow loop, keep it simple and stupid */
8959 + /* cf: au_cpup_dirs() */
8962 + while (au_digen_test(dentry, sigen)) {
8966 + parent = dget_parent(d);
8967 + if (!au_digen_test(parent, sigen))
8973 + di_write_lock_child2(d);
8975 + /* someone might update our dentry while we were sleeping */
8976 + if (au_digen_test(d, sigen)) {
8978 + * todo: consolidate with simple_reval_dpath(),
8979 + * do_refresh() and au_reval_for_attr().
8981 + di_read_lock_parent(parent, AuLock_IR);
8982 + err = au_refresh_dentry(d, parent);
8983 + di_read_unlock(parent, AuLock_IR);
8987 + di_write_unlock(d);
8989 + if (unlikely(err))
8997 + * if valid returns 1, otherwise 0.
8999 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9002 + unsigned int sigen;
9003 + unsigned char do_udba, dirren;
9004 + struct super_block *sb;
9005 + struct inode *inode;
9007 + /* todo: support rcu-walk? */
9008 + if (flags & LOOKUP_RCU)
9012 + if (unlikely(!au_di(dentry)))
9016 + sb = dentry->d_sb;
9019 + * i_mutex of parent dir may be held,
9020 + * but we should not return 'invalid' due to busy.
9022 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9023 + if (unlikely(err)) {
9029 + if (d_really_is_positive(dentry))
9030 + inode = d_inode(dentry);
9031 + if (unlikely(inode && au_is_bad_inode(inode))) {
9036 + if (unlikely(au_dbrange_test(dentry))) {
9042 + sigen = au_sigen(sb);
9043 + if (au_digen_test(dentry, sigen)) {
9044 + AuDebugOn(IS_ROOT(dentry));
9045 + err = au_reval_dpath(dentry, sigen);
9046 + if (unlikely(err)) {
9051 + di_downgrade_lock(dentry, AuLock_IR);
9054 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9056 + && !(inode->i_state && I_LINKABLE)
9057 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9062 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9063 + if (do_udba && inode) {
9064 + aufs_bindex_t btop = au_ibtop(inode);
9065 + struct inode *h_inode;
9068 + h_inode = au_h_iptr(inode, btop);
9069 + if (h_inode && au_test_higen(inode, h_inode)) {
9076 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9077 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9078 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9080 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9086 + di_downgrade_lock(dentry, AuLock_IR);
9088 + aufs_read_unlock(dentry, AuLock_IR);
9093 + AuDbg("%pd invalid, %d\n", dentry, valid);
9099 +static void aufs_d_release(struct dentry *dentry)
9101 + if (au_di(dentry)) {
9102 + au_di_fin(dentry);
9103 + au_hn_di_reinit(dentry);
9107 +const struct dentry_operations aufs_dop = {
9108 + .d_revalidate = aufs_d_revalidate,
9109 + .d_weak_revalidate = aufs_d_revalidate,
9110 + .d_release = aufs_d_release
9113 +/* aufs_dop without d_revalidate */
9114 +const struct dentry_operations aufs_dop_noreval = {
9115 + .d_release = aufs_d_release
9117 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9118 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9119 +++ linux/fs/aufs/dentry.h 2023-08-28 12:34:39.956636132 +0200
9121 +/* SPDX-License-Identifier: GPL-2.0 */
9123 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9125 + * This program is free software; you can redistribute it and/or modify
9126 + * it under the terms of the GNU General Public License as published by
9127 + * the Free Software Foundation; either version 2 of the License, or
9128 + * (at your option) any later version.
9130 + * This program is distributed in the hope that it will be useful,
9131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9133 + * GNU General Public License for more details.
9135 + * You should have received a copy of the GNU General Public License
9136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9140 + * lookup and dentry operations
9143 +#ifndef __AUFS_DENTRY_H__
9144 +#define __AUFS_DENTRY_H__
9148 +#include <linux/dcache.h>
9149 +#include "dirren.h"
9152 +struct au_hdentry {
9153 + struct dentry *hd_dentry;
9154 + aufs_bindex_t hd_id;
9158 + atomic_t di_generation;
9160 + struct au_rwsem di_rwsem;
9161 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9162 + unsigned char di_tmpfile; /* to allow the different name */
9163 + struct au_hdentry *di_hdentry;
9164 + struct file *di_htmpfile;
9165 + struct rcu_head rcu;
9166 +} ____cacheline_aligned_in_smp;
9168 +/* ---------------------------------------------------------------------- */
9170 +/* flags for au_lkup_dentry() */
9171 +#define AuLkup_ALLOW_NEG 1
9172 +#define AuLkup_IGNORE_PERM (1 << 1)
9173 +#define AuLkup_DIRREN (1 << 2)
9174 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9175 +#define au_fset_lkup(flags, name) \
9176 + do { (flags) |= AuLkup_##name; } while (0)
9177 +#define au_fclr_lkup(flags, name) \
9178 + do { (flags) &= ~AuLkup_##name; } while (0)
9180 +#ifndef CONFIG_AUFS_DIRREN
9181 +#undef AuLkup_DIRREN
9182 +#define AuLkup_DIRREN 0
9185 +struct au_do_lookup_args {
9186 + unsigned int flags;
9188 + struct qstr whname, *name;
9189 + struct au_dr_lookup dirren;
9192 +/* ---------------------------------------------------------------------- */
9195 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9197 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
9198 + struct path *ppath);
9199 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9200 + struct dentry *h_parent, struct au_branch *br);
9202 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9203 + unsigned int flags);
9204 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9205 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9206 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9207 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9210 +void au_di_init_once(void *_di);
9211 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9212 +void au_di_free(struct au_dinfo *dinfo);
9213 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9214 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9215 +int au_di_init(struct dentry *dentry);
9216 +void au_di_fin(struct dentry *dentry);
9217 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9219 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9220 +void di_read_unlock(struct dentry *d, int flags);
9221 +void di_downgrade_lock(struct dentry *d, int flags);
9222 +void di_write_lock(struct dentry *d, unsigned int lsc);
9223 +void di_write_unlock(struct dentry *d);
9224 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9225 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9226 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9228 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9229 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9230 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9231 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9233 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9234 + struct dentry *h_dentry);
9235 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9236 +int au_dbrange_test(struct dentry *dentry);
9237 +void au_update_digen(struct dentry *dentry);
9238 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9239 +void au_update_dbtop(struct dentry *dentry);
9240 +void au_update_dbbot(struct dentry *dentry);
9241 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9243 +/* ---------------------------------------------------------------------- */
9245 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9247 + return dentry->d_fsdata;
9250 +/* ---------------------------------------------------------------------- */
9252 +/* lock subclass for dinfo */
9254 + AuLsc_DI_CHILD, /* child first */
9255 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9256 + AuLsc_DI_CHILD3, /* copyup dirs */
9260 + AuLsc_DI_TMP /* temp for replacing dinfo */
9264 + * di_read_lock_child, di_write_lock_child,
9265 + * di_read_lock_child2, di_write_lock_child2,
9266 + * di_read_lock_child3, di_write_lock_child3,
9267 + * di_read_lock_parent, di_write_lock_parent,
9268 + * di_read_lock_parent2, di_write_lock_parent2,
9269 + * di_read_lock_parent3, di_write_lock_parent3,
9271 +#define AuReadLockFunc(name, lsc) \
9272 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9273 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9275 +#define AuWriteLockFunc(name, lsc) \
9276 +static inline void di_write_lock_##name(struct dentry *d) \
9277 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9279 +#define AuRWLockFuncs(name, lsc) \
9280 + AuReadLockFunc(name, lsc) \
9281 + AuWriteLockFunc(name, lsc)
9283 +AuRWLockFuncs(child, CHILD);
9284 +AuRWLockFuncs(child2, CHILD2);
9285 +AuRWLockFuncs(child3, CHILD3);
9286 +AuRWLockFuncs(parent, PARENT);
9287 +AuRWLockFuncs(parent2, PARENT2);
9288 +AuRWLockFuncs(parent3, PARENT3);
9290 +#undef AuReadLockFunc
9291 +#undef AuWriteLockFunc
9292 +#undef AuRWLockFuncs
9294 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9295 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9296 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9298 +/* ---------------------------------------------------------------------- */
9300 +/* todo: memory barrier? */
9301 +static inline unsigned int au_digen(struct dentry *d)
9303 + return atomic_read(&au_di(d)->di_generation);
9306 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9308 + hdentry->hd_dentry = NULL;
9311 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9312 + aufs_bindex_t bindex)
9314 + return di->di_hdentry + bindex;
9317 +static inline void au_hdput(struct au_hdentry *hd)
9320 + dput(hd->hd_dentry);
9323 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9325 + DiMustAnyLock(dentry);
9326 + return au_di(dentry)->di_btop;
9329 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9331 + DiMustAnyLock(dentry);
9332 + return au_di(dentry)->di_bbot;
9335 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9337 + DiMustAnyLock(dentry);
9338 + return au_di(dentry)->di_bwh;
9341 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9343 + DiMustAnyLock(dentry);
9344 + return au_di(dentry)->di_bdiropq;
9347 +/* todo: hard/soft set? */
9348 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9350 + DiMustWriteLock(dentry);
9351 + au_di(dentry)->di_btop = bindex;
9354 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9356 + DiMustWriteLock(dentry);
9357 + au_di(dentry)->di_bbot = bindex;
9360 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9362 + DiMustWriteLock(dentry);
9363 + /* dbwh can be outside of btop - bbot range */
9364 + au_di(dentry)->di_bwh = bindex;
9367 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9369 + DiMustWriteLock(dentry);
9370 + au_di(dentry)->di_bdiropq = bindex;
9373 +/* ---------------------------------------------------------------------- */
9375 +#ifdef CONFIG_AUFS_HNOTIFY
9376 +static inline void au_digen_dec(struct dentry *d)
9378 + atomic_dec(&au_di(d)->di_generation);
9381 +static inline void au_hn_di_reinit(struct dentry *dentry)
9383 + dentry->d_fsdata = NULL;
9386 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9387 +#endif /* CONFIG_AUFS_HNOTIFY */
9389 +#endif /* __KERNEL__ */
9390 +#endif /* __AUFS_DENTRY_H__ */
9391 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9392 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9393 +++ linux/fs/aufs/dinfo.c 2022-12-17 09:21:34.796521861 +0100
9395 +// SPDX-License-Identifier: GPL-2.0
9397 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9399 + * This program is free software; you can redistribute it and/or modify
9400 + * it under the terms of the GNU General Public License as published by
9401 + * the Free Software Foundation; either version 2 of the License, or
9402 + * (at your option) any later version.
9404 + * This program is distributed in the hope that it will be useful,
9405 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9406 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9407 + * GNU General Public License for more details.
9409 + * You should have received a copy of the GNU General Public License
9410 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9414 + * dentry private data
9419 +void au_di_init_once(void *_dinfo)
9421 + struct au_dinfo *dinfo = _dinfo;
9423 + au_rw_init(&dinfo->di_rwsem);
9426 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9428 + struct au_dinfo *dinfo;
9431 + dinfo = au_cache_alloc_dinfo();
9432 + if (unlikely(!dinfo))
9435 + nbr = au_sbbot(sb) + 1;
9438 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9439 + if (dinfo->di_hdentry) {
9440 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9441 + dinfo->di_btop = -1;
9442 + dinfo->di_bbot = -1;
9443 + dinfo->di_bwh = -1;
9444 + dinfo->di_bdiropq = -1;
9445 + dinfo->di_tmpfile = 0;
9446 + for (i = 0; i < nbr; i++)
9447 + dinfo->di_hdentry[i].hd_id = -1;
9448 + dinfo->di_htmpfile = NULL;
9452 + au_cache_free_dinfo(dinfo);
9459 +void au_di_free(struct au_dinfo *dinfo)
9461 + struct au_hdentry *p;
9462 + aufs_bindex_t bbot, bindex;
9464 + /* dentry may not be revalidated */
9465 + bindex = dinfo->di_btop;
9466 + if (bindex >= 0) {
9467 + bbot = dinfo->di_bbot;
9468 + p = au_hdentry(dinfo, bindex);
9469 + while (bindex++ <= bbot)
9472 + au_kfree_try_rcu(dinfo->di_hdentry);
9473 + au_cache_free_dinfo(dinfo);
9476 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9478 + struct au_hdentry *p;
9481 + AuRwMustWriteLock(&a->di_rwsem);
9482 + AuRwMustWriteLock(&b->di_rwsem);
9484 +#define DiSwap(v, name) \
9486 + v = a->di_##name; \
9487 + a->di_##name = b->di_##name; \
9488 + b->di_##name = v; \
9491 + DiSwap(p, hdentry);
9495 + DiSwap(bi, bdiropq);
9501 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9503 + AuRwMustWriteLock(&dst->di_rwsem);
9504 + AuRwMustWriteLock(&src->di_rwsem);
9506 + dst->di_btop = src->di_btop;
9507 + dst->di_bbot = src->di_bbot;
9508 + dst->di_bwh = src->di_bwh;
9509 + dst->di_bdiropq = src->di_bdiropq;
9513 +int au_di_init(struct dentry *dentry)
9516 + struct super_block *sb;
9517 + struct au_dinfo *dinfo;
9520 + sb = dentry->d_sb;
9521 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9523 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9524 + /* smp_mb(); */ /* atomic_set */
9525 + dentry->d_fsdata = dinfo;
9532 +void au_di_fin(struct dentry *dentry)
9534 + struct au_dinfo *dinfo;
9536 + dinfo = au_di(dentry);
9537 + AuRwDestroy(&dinfo->di_rwsem);
9538 + au_di_free(dinfo);
9541 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9544 + struct au_hdentry *hdp;
9546 + AuRwMustWriteLock(&dinfo->di_rwsem);
9549 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9551 + sz = sizeof(*hdp);
9552 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9555 + dinfo->di_hdentry = hdp;
9562 +/* ---------------------------------------------------------------------- */
9564 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9567 + case AuLsc_DI_CHILD:
9568 + ii_write_lock_child(inode);
9570 + case AuLsc_DI_CHILD2:
9571 + ii_write_lock_child2(inode);
9573 + case AuLsc_DI_CHILD3:
9574 + ii_write_lock_child3(inode);
9576 + case AuLsc_DI_PARENT:
9577 + ii_write_lock_parent(inode);
9579 + case AuLsc_DI_PARENT2:
9580 + ii_write_lock_parent2(inode);
9582 + case AuLsc_DI_PARENT3:
9583 + ii_write_lock_parent3(inode);
9590 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9593 + case AuLsc_DI_CHILD:
9594 + ii_read_lock_child(inode);
9596 + case AuLsc_DI_CHILD2:
9597 + ii_read_lock_child2(inode);
9599 + case AuLsc_DI_CHILD3:
9600 + ii_read_lock_child3(inode);
9602 + case AuLsc_DI_PARENT:
9603 + ii_read_lock_parent(inode);
9605 + case AuLsc_DI_PARENT2:
9606 + ii_read_lock_parent2(inode);
9608 + case AuLsc_DI_PARENT3:
9609 + ii_read_lock_parent3(inode);
9616 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9618 + struct inode *inode;
9620 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9621 + if (d_really_is_positive(d)) {
9622 + inode = d_inode(d);
9623 + if (au_ftest_lock(flags, IW))
9624 + do_ii_write_lock(inode, lsc);
9625 + else if (au_ftest_lock(flags, IR))
9626 + do_ii_read_lock(inode, lsc);
9630 +void di_read_unlock(struct dentry *d, int flags)
9632 + struct inode *inode;
9634 + if (d_really_is_positive(d)) {
9635 + inode = d_inode(d);
9636 + if (au_ftest_lock(flags, IW)) {
9637 + au_dbg_verify_dinode(d);
9638 + ii_write_unlock(inode);
9639 + } else if (au_ftest_lock(flags, IR)) {
9640 + au_dbg_verify_dinode(d);
9641 + ii_read_unlock(inode);
9644 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9647 +void di_downgrade_lock(struct dentry *d, int flags)
9649 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9650 + ii_downgrade_lock(d_inode(d));
9651 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9654 +void di_write_lock(struct dentry *d, unsigned int lsc)
9656 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9657 + if (d_really_is_positive(d))
9658 + do_ii_write_lock(d_inode(d), lsc);
9661 +void di_write_unlock(struct dentry *d)
9663 + au_dbg_verify_dinode(d);
9664 + if (d_really_is_positive(d))
9665 + ii_write_unlock(d_inode(d));
9666 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9669 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9671 + AuDebugOn(d1 == d2
9672 + || d_inode(d1) == d_inode(d2)
9673 + || d1->d_sb != d2->d_sb);
9675 + if ((isdir && au_test_subdir(d1, d2))
9677 + di_write_lock_child(d1);
9678 + di_write_lock_child2(d2);
9680 + di_write_lock_child(d2);
9681 + di_write_lock_child2(d1);
9685 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9687 + AuDebugOn(d1 == d2
9688 + || d_inode(d1) == d_inode(d2)
9689 + || d1->d_sb != d2->d_sb);
9691 + if ((isdir && au_test_subdir(d1, d2))
9693 + di_write_lock_parent(d1);
9694 + di_write_lock_parent2(d2);
9696 + di_write_lock_parent(d2);
9697 + di_write_lock_parent2(d1);
9701 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9703 + di_write_unlock(d1);
9704 + if (d_inode(d1) == d_inode(d2))
9705 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9707 + di_write_unlock(d2);
9710 +/* ---------------------------------------------------------------------- */
9712 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9716 + DiMustAnyLock(dentry);
9718 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9720 + AuDebugOn(bindex < 0);
9721 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9722 + AuDebugOn(d && au_dcount(d) <= 0);
9727 + * extended version of au_h_dptr().
9728 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9731 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9733 + struct dentry *h_dentry;
9734 + struct inode *inode, *h_inode;
9736 + AuDebugOn(d_really_is_negative(dentry));
9739 + if (au_dbtop(dentry) <= bindex
9740 + && bindex <= au_dbbot(dentry))
9741 + h_dentry = au_h_dptr(dentry, bindex);
9742 + if (h_dentry && !au_d_linkable(h_dentry)) {
9744 + goto out; /* success */
9747 + inode = d_inode(dentry);
9748 + AuDebugOn(bindex < au_ibtop(inode));
9749 + AuDebugOn(au_ibbot(inode) < bindex);
9750 + h_inode = au_h_iptr(inode, bindex);
9751 + h_dentry = d_find_alias(h_inode);
9753 + if (!IS_ERR(h_dentry)) {
9754 + if (!au_d_linkable(h_dentry))
9755 + goto out; /* success */
9761 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9762 + h_dentry = au_plink_lkup(inode, bindex);
9763 + AuDebugOn(!h_dentry);
9764 + if (!IS_ERR(h_dentry)) {
9765 + if (!au_d_hashed_positive(h_dentry))
9766 + goto out; /* success */
9773 + AuDbgDentry(h_dentry);
9777 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9779 + aufs_bindex_t bbot, bwh;
9781 + bbot = au_dbbot(dentry);
9783 + bwh = au_dbwh(dentry);
9786 + if (0 < bwh && bwh < bbot)
9792 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9794 + aufs_bindex_t bbot, bopq;
9796 + bbot = au_dbtail(dentry);
9798 + bopq = au_dbdiropq(dentry);
9799 + if (0 <= bopq && bopq < bbot)
9805 +/* ---------------------------------------------------------------------- */
9807 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9808 + struct dentry *h_dentry)
9810 + struct au_dinfo *dinfo;
9811 + struct au_hdentry *hd;
9812 + struct au_branch *br;
9814 + DiMustWriteLock(dentry);
9816 + dinfo = au_di(dentry);
9817 + hd = au_hdentry(dinfo, bindex);
9819 + hd->hd_dentry = h_dentry;
9821 + br = au_sbr(dentry->d_sb, bindex);
9822 + hd->hd_id = br->br_id;
9826 +int au_dbrange_test(struct dentry *dentry)
9829 + aufs_bindex_t btop, bbot;
9832 + btop = au_dbtop(dentry);
9833 + bbot = au_dbbot(dentry);
9835 + AuDebugOn(bbot < 0 && btop > bbot);
9838 + AuDebugOn(bbot >= 0);
9844 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9849 + if (unlikely(au_digen(dentry) != sigen
9850 + || au_iigen_test(d_inode(dentry), sigen)))
9856 +void au_update_digen(struct dentry *dentry)
9858 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9859 + /* smp_mb(); */ /* atomic_set */
9862 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9864 + struct au_dinfo *dinfo;
9865 + struct dentry *h_d;
9866 + struct au_hdentry *hdp;
9867 + aufs_bindex_t bindex, bbot;
9869 + DiMustWriteLock(dentry);
9871 + dinfo = au_di(dentry);
9872 + if (!dinfo || dinfo->di_btop < 0)
9875 + if (do_put_zero) {
9876 + bbot = dinfo->di_bbot;
9877 + bindex = dinfo->di_btop;
9878 + hdp = au_hdentry(dinfo, bindex);
9879 + for (; bindex <= bbot; bindex++, hdp++) {
9880 + h_d = hdp->hd_dentry;
9881 + if (h_d && d_is_negative(h_d))
9882 + au_set_h_dptr(dentry, bindex, NULL);
9886 + dinfo->di_btop = 0;
9887 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9888 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9889 + if (hdp->hd_dentry)
9891 + if (dinfo->di_btop > dinfo->di_bbot) {
9892 + dinfo->di_btop = -1;
9893 + dinfo->di_bbot = -1;
9897 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9898 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9899 + if (hdp->hd_dentry)
9901 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9904 +void au_update_dbtop(struct dentry *dentry)
9906 + aufs_bindex_t bindex, bbot;
9907 + struct dentry *h_dentry;
9909 + bbot = au_dbbot(dentry);
9910 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9911 + h_dentry = au_h_dptr(dentry, bindex);
9914 + if (d_is_positive(h_dentry)) {
9915 + au_set_dbtop(dentry, bindex);
9918 + au_set_h_dptr(dentry, bindex, NULL);
9922 +void au_update_dbbot(struct dentry *dentry)
9924 + aufs_bindex_t bindex, btop;
9925 + struct dentry *h_dentry;
9927 + btop = au_dbtop(dentry);
9928 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9929 + h_dentry = au_h_dptr(dentry, bindex);
9932 + if (d_is_positive(h_dentry)) {
9933 + au_set_dbbot(dentry, bindex);
9936 + au_set_h_dptr(dentry, bindex, NULL);
9940 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9942 + aufs_bindex_t bindex, bbot;
9944 + bbot = au_dbbot(dentry);
9945 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9946 + if (au_h_dptr(dentry, bindex) == h_dentry)
9950 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9951 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9952 +++ linux/fs/aufs/dir.c 2023-08-28 12:34:39.956636132 +0200
9954 +// SPDX-License-Identifier: GPL-2.0
9956 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9958 + * This program is free software; you can redistribute it and/or modify
9959 + * it under the terms of the GNU General Public License as published by
9960 + * the Free Software Foundation; either version 2 of the License, or
9961 + * (at your option) any later version.
9963 + * This program is distributed in the hope that it will be useful,
9964 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9966 + * GNU General Public License for more details.
9968 + * You should have received a copy of the GNU General Public License
9969 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9973 + * directory operations
9976 +#include <linux/fs_stack.h>
9977 +#include <linux/iversion.h>
9980 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9982 + unsigned int nlink;
9984 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9986 + nlink = dir->i_nlink;
9987 + nlink += h_dir->i_nlink - 2;
9988 + if (h_dir->i_nlink < 2)
9990 + smp_mb(); /* for i_nlink */
9991 + /* 0 can happen in revaliding */
9992 + set_nlink(dir, nlink);
9995 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9997 + unsigned int nlink;
9999 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10001 + nlink = dir->i_nlink;
10002 + nlink -= h_dir->i_nlink - 2;
10003 + if (h_dir->i_nlink < 2)
10005 + smp_mb(); /* for i_nlink */
10006 + /* nlink == 0 means the branch-fs is broken */
10007 + set_nlink(dir, nlink);
10010 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10013 + aufs_bindex_t bindex, bbot;
10014 + struct file *h_file;
10015 + struct dentry *h_dentry;
10019 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10021 + bbot = au_fbbot_dir(file);
10022 + for (bindex = au_fbtop(file);
10023 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10025 + h_file = au_hf_dir(file, bindex);
10026 + if (h_file && file_inode(h_file))
10027 + sz += vfsub_f_size_read(h_file);
10030 + AuDebugOn(!dentry);
10031 + AuDebugOn(!d_is_dir(dentry));
10033 + bbot = au_dbtaildir(dentry);
10034 + for (bindex = au_dbtop(dentry);
10035 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10037 + h_dentry = au_h_dptr(dentry, bindex);
10038 + if (h_dentry && d_is_positive(h_dentry))
10039 + sz += i_size_read(d_inode(h_dentry));
10042 + if (sz < KMALLOC_MAX_SIZE)
10043 + sz = roundup_pow_of_two(sz);
10044 + if (sz > KMALLOC_MAX_SIZE)
10045 + sz = KMALLOC_MAX_SIZE;
10046 + else if (sz < NAME_MAX) {
10047 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10048 + sz = AUFS_RDBLK_DEF;
10053 +struct au_dir_ts_arg {
10054 + struct dentry *dentry;
10055 + aufs_bindex_t brid;
10058 +static void au_do_dir_ts(void *arg)
10060 + struct au_dir_ts_arg *a = arg;
10061 + struct au_dtime dt;
10062 + struct path h_path;
10063 + struct inode *dir, *h_dir;
10064 + struct super_block *sb;
10065 + struct au_branch *br;
10066 + struct au_hinode *hdir;
10068 + aufs_bindex_t btop, bindex;
10070 + sb = a->dentry->d_sb;
10071 + if (d_really_is_negative(a->dentry))
10073 + /* no dir->i_mutex lock */
10074 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10076 + dir = d_inode(a->dentry);
10077 + btop = au_ibtop(dir);
10078 + bindex = au_br_index(sb, a->brid);
10079 + if (bindex < btop)
10082 + br = au_sbr(sb, bindex);
10083 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10084 + if (!h_path.dentry)
10086 + h_path.mnt = au_br_mnt(br);
10087 + au_dtime_store(&dt, a->dentry, &h_path);
10089 + br = au_sbr(sb, btop);
10090 + if (!au_br_writable(br->br_perm))
10092 + h_path.dentry = au_h_dptr(a->dentry, btop);
10093 + h_path.mnt = au_br_mnt(br);
10094 + err = vfsub_mnt_want_write(h_path.mnt);
10097 + hdir = au_hi(dir, btop);
10098 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10099 + h_dir = au_h_iptr(dir, btop);
10100 + if (h_dir->i_nlink
10101 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10102 + dt.dt_h_path = h_path;
10103 + au_dtime_revert(&dt);
10105 + au_hn_inode_unlock(hdir);
10106 + vfsub_mnt_drop_write(h_path.mnt);
10107 + au_cpup_attr_timesizes(dir);
10110 + aufs_read_unlock(a->dentry, AuLock_DW);
10113 + au_nwt_done(&au_sbi(sb)->si_nowait);
10114 + au_kfree_try_rcu(arg);
10117 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10119 + int perm, wkq_err;
10120 + aufs_bindex_t btop;
10121 + struct au_dir_ts_arg *arg;
10122 + struct dentry *dentry;
10123 + struct super_block *sb;
10127 + dentry = d_find_any_alias(dir);
10128 + AuDebugOn(!dentry);
10129 + sb = dentry->d_sb;
10130 + btop = au_ibtop(dir);
10131 + if (btop == bindex) {
10132 + au_cpup_attr_timesizes(dir);
10136 + perm = au_sbr_perm(sb, btop);
10137 + if (!au_br_writable(perm))
10140 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10144 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10145 + arg->brid = au_sbr_id(sb, bindex);
10146 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10147 + if (unlikely(wkq_err)) {
10148 + pr_err("wkq %d\n", wkq_err);
10150 + au_kfree_try_rcu(arg);
10157 +/* ---------------------------------------------------------------------- */
10159 +static int reopen_dir(struct file *file)
10162 + unsigned int flags;
10163 + aufs_bindex_t bindex, btail, btop;
10164 + struct dentry *dentry, *h_dentry;
10165 + struct file *h_file;
10167 + /* open all lower dirs */
10168 + dentry = file->f_path.dentry;
10169 + btop = au_dbtop(dentry);
10170 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10171 + au_set_h_fptr(file, bindex, NULL);
10172 + au_set_fbtop(file, btop);
10174 + btail = au_dbtaildir(dentry);
10175 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10176 + au_set_h_fptr(file, bindex, NULL);
10177 + au_set_fbbot_dir(file, btail);
10179 + flags = vfsub_file_flags(file);
10180 + for (bindex = btop; bindex <= btail; bindex++) {
10181 + h_dentry = au_h_dptr(dentry, bindex);
10184 + h_file = au_hf_dir(file, bindex);
10188 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10189 + err = PTR_ERR(h_file);
10190 + if (IS_ERR(h_file))
10191 + goto out; /* close all? */
10192 + au_set_h_fptr(file, bindex, h_file);
10194 + au_update_figen(file);
10195 + /* todo: necessary? */
10196 + /* file->f_ra = h_file->f_ra; */
10203 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10206 + aufs_bindex_t bindex, btail;
10207 + struct dentry *dentry, *h_dentry;
10208 + struct vfsmount *mnt;
10210 + FiMustWriteLock(file);
10211 + AuDebugOn(h_file);
10214 + mnt = file->f_path.mnt;
10215 + dentry = file->f_path.dentry;
10216 + file->f_version = inode_query_iversion(d_inode(dentry));
10217 + bindex = au_dbtop(dentry);
10218 + au_set_fbtop(file, bindex);
10219 + btail = au_dbtaildir(dentry);
10220 + au_set_fbbot_dir(file, btail);
10221 + for (; !err && bindex <= btail; bindex++) {
10222 + h_dentry = au_h_dptr(dentry, bindex);
10226 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10227 + if (unlikely(err))
10229 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10230 + if (IS_ERR(h_file)) {
10231 + err = PTR_ERR(h_file);
10234 + au_set_h_fptr(file, bindex, h_file);
10236 + au_update_figen(file);
10237 + /* todo: necessary? */
10238 + /* file->f_ra = h_file->f_ra; */
10240 + return 0; /* success */
10243 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10244 + au_set_h_fptr(file, bindex, NULL);
10245 + au_set_fbtop(file, -1);
10246 + au_set_fbbot_dir(file, -1);
10251 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10252 + struct file *file)
10255 + struct super_block *sb;
10256 + struct au_fidir *fidir;
10259 + sb = file->f_path.dentry->d_sb;
10260 + si_read_lock(sb, AuLock_FLUSH);
10261 + fidir = au_fidir_alloc(sb);
10263 + struct au_do_open_args args = {
10264 + .open = do_open_dir,
10267 + err = au_do_open(file, &args);
10268 + if (unlikely(err))
10269 + au_kfree_rcu(fidir);
10271 + si_read_unlock(sb);
10275 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10276 + struct file *file)
10278 + struct au_vdir *vdir_cache;
10279 + struct au_finfo *finfo;
10280 + struct au_fidir *fidir;
10281 + struct au_hfile *hf;
10282 + aufs_bindex_t bindex, bbot;
10284 + finfo = au_fi(file);
10285 + fidir = finfo->fi_hdir;
10287 + au_hbl_del(&finfo->fi_hlist,
10288 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10289 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10291 + au_vdir_free(vdir_cache);
10293 + bindex = finfo->fi_btop;
10294 + if (bindex >= 0) {
10295 + hf = fidir->fd_hfile + bindex;
10297 + * calls fput() instead of filp_close(),
10298 + * since no dnotify or lock for the lower file.
10300 + bbot = fidir->fd_bbot;
10301 + for (; bindex <= bbot; bindex++, hf++)
10303 + au_hfput(hf, /*execed*/0);
10305 + au_kfree_rcu(fidir);
10306 + finfo->fi_hdir = NULL;
10308 + au_finfo_fin(file);
10312 +/* ---------------------------------------------------------------------- */
10314 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10317 + aufs_bindex_t bindex, bbot;
10318 + struct file *h_file;
10321 + bbot = au_fbbot_dir(file);
10322 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10323 + h_file = au_hf_dir(file, bindex);
10325 + err = vfsub_flush(h_file, id);
10330 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10332 + return au_do_flush(file, id, au_do_flush_dir);
10335 +/* ---------------------------------------------------------------------- */
10337 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10340 + aufs_bindex_t bbot, bindex;
10341 + struct inode *inode;
10342 + struct super_block *sb;
10345 + sb = dentry->d_sb;
10346 + inode = d_inode(dentry);
10347 + IMustLock(inode);
10348 + bbot = au_dbbot(dentry);
10349 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10350 + struct path h_path;
10352 + if (au_test_ro(sb, bindex, inode))
10354 + h_path.dentry = au_h_dptr(dentry, bindex);
10355 + if (!h_path.dentry)
10358 + h_path.mnt = au_sbr_mnt(sb, bindex);
10359 + err = vfsub_fsync(NULL, &h_path, datasync);
10365 +static int au_do_fsync_dir(struct file *file, int datasync)
10368 + aufs_bindex_t bbot, bindex;
10369 + struct file *h_file;
10370 + struct super_block *sb;
10371 + struct inode *inode;
10373 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10374 + if (unlikely(err))
10377 + inode = file_inode(file);
10378 + sb = inode->i_sb;
10379 + bbot = au_fbbot_dir(file);
10380 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10381 + h_file = au_hf_dir(file, bindex);
10382 + if (!h_file || au_test_ro(sb, bindex, inode))
10385 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10393 + * @file may be NULL
10395 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10399 + struct dentry *dentry;
10400 + struct inode *inode;
10401 + struct super_block *sb;
10404 + dentry = file->f_path.dentry;
10405 + inode = d_inode(dentry);
10406 + inode_lock(inode);
10407 + sb = dentry->d_sb;
10408 + si_noflush_read_lock(sb);
10410 + err = au_do_fsync_dir(file, datasync);
10412 + di_write_lock_child(dentry);
10413 + err = au_do_fsync_dir_no_file(dentry, datasync);
10415 + au_cpup_attr_timesizes(inode);
10416 + di_write_unlock(dentry);
10418 + fi_write_unlock(file);
10420 + si_read_unlock(sb);
10421 + inode_unlock(inode);
10425 +/* ---------------------------------------------------------------------- */
10427 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10430 + struct dentry *dentry;
10431 + struct inode *inode, *h_inode;
10432 + struct super_block *sb;
10434 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10436 + dentry = file->f_path.dentry;
10437 + inode = d_inode(dentry);
10438 + IMustLock(inode);
10440 + sb = dentry->d_sb;
10441 + si_read_lock(sb, AuLock_FLUSH);
10442 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10443 + if (unlikely(err))
10445 + err = au_alive_dir(dentry);
10447 + err = au_vdir_init(file);
10448 + di_downgrade_lock(dentry, AuLock_IR);
10449 + if (unlikely(err))
10452 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10453 + if (!au_test_nfsd()) {
10454 + err = au_vdir_fill_de(file, ctx);
10455 + fsstack_copy_attr_atime(inode, h_inode);
10458 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10459 + * encode_fh() and others.
10461 + atomic_inc(&h_inode->i_count);
10462 + di_read_unlock(dentry, AuLock_IR);
10463 + si_read_unlock(sb);
10464 + err = au_vdir_fill_de(file, ctx);
10465 + fsstack_copy_attr_atime(inode, h_inode);
10466 + fi_write_unlock(file);
10474 + di_read_unlock(dentry, AuLock_IR);
10475 + fi_write_unlock(file);
10477 + si_read_unlock(sb);
10481 +/* ---------------------------------------------------------------------- */
10483 +#define AuTestEmpty_WHONLY 1
10484 +#define AuTestEmpty_CALLED (1 << 1)
10485 +#define AuTestEmpty_SHWH (1 << 2)
10486 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10487 +#define au_fset_testempty(flags, name) \
10488 + do { (flags) |= AuTestEmpty_##name; } while (0)
10489 +#define au_fclr_testempty(flags, name) \
10490 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10492 +#ifndef CONFIG_AUFS_SHWH
10493 +#undef AuTestEmpty_SHWH
10494 +#define AuTestEmpty_SHWH 0
10497 +struct test_empty_arg {
10498 + struct dir_context ctx;
10499 + struct au_nhash *whlist;
10500 + unsigned int flags;
10502 + aufs_bindex_t bindex;
10505 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10506 + int namelen, loff_t offset __maybe_unused, u64 ino,
10507 + unsigned int d_type)
10509 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10511 + char *name = (void *)__name;
10514 + au_fset_testempty(arg->flags, CALLED);
10516 + if (name[0] == '.'
10517 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10518 + goto out; /* success */
10520 + if (namelen <= AUFS_WH_PFX_LEN
10521 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10522 + if (au_ftest_testempty(arg->flags, WHONLY)
10523 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10524 + arg->err = -ENOTEMPTY;
10528 + name += AUFS_WH_PFX_LEN;
10529 + namelen -= AUFS_WH_PFX_LEN;
10530 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10531 + arg->err = au_nhash_append_wh
10532 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10533 + au_ftest_testempty(arg->flags, SHWH));
10537 + AuTraceErr(arg->err);
10538 + return !arg->err;
10541 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10544 + struct file *h_file;
10545 + struct au_branch *br;
10547 + h_file = au_h_open(dentry, arg->bindex,
10548 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10549 + /*file*/NULL, /*force_wr*/0);
10550 + err = PTR_ERR(h_file);
10551 + if (IS_ERR(h_file))
10555 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10556 + && !file_inode(h_file)->i_nlink)
10561 + au_fclr_testempty(arg->flags, CALLED);
10563 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10566 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10570 + br = au_sbr(dentry->d_sb, arg->bindex);
10571 + au_lcnt_dec(&br->br_nfiles);
10576 +struct do_test_empty_args {
10578 + struct dentry *dentry;
10579 + struct test_empty_arg *arg;
10582 +static void call_do_test_empty(void *args)
10584 + struct do_test_empty_args *a = args;
10585 + *a->errp = do_test_empty(a->dentry, a->arg);
10588 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10590 + int err, wkq_err;
10591 + struct dentry *h_dentry;
10592 + struct inode *h_inode;
10593 + struct mnt_idmap *h_idmap;
10595 + h_idmap = au_sbr_idmap(dentry->d_sb, arg->bindex);
10596 + h_dentry = au_h_dptr(dentry, arg->bindex);
10597 + h_inode = d_inode(h_dentry);
10598 + /* todo: i_mode changes anytime? */
10599 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10600 + err = au_test_h_perm_sio(h_idmap, h_inode, MAY_EXEC | MAY_READ);
10601 + inode_unlock_shared(h_inode);
10603 + err = do_test_empty(dentry, arg);
10605 + struct do_test_empty_args args = {
10607 + .dentry = dentry,
10610 + unsigned int flags = arg->flags;
10612 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10613 + if (unlikely(wkq_err))
10615 + arg->flags = flags;
10621 +int au_test_empty_lower(struct dentry *dentry)
10624 + unsigned int rdhash;
10625 + aufs_bindex_t bindex, btop, btail;
10626 + struct au_nhash whlist;
10627 + struct test_empty_arg arg = {
10629 + .actor = test_empty_cb
10632 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10634 + SiMustAnyLock(dentry->d_sb);
10636 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10638 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10639 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10640 + if (unlikely(err))
10644 + arg.whlist = &whlist;
10645 + btop = au_dbtop(dentry);
10646 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10647 + au_fset_testempty(arg.flags, SHWH);
10648 + test_empty = do_test_empty;
10649 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10650 + test_empty = sio_test_empty;
10651 + arg.bindex = btop;
10652 + err = test_empty(dentry, &arg);
10653 + if (unlikely(err))
10656 + au_fset_testempty(arg.flags, WHONLY);
10657 + btail = au_dbtaildir(dentry);
10658 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10659 + struct dentry *h_dentry;
10661 + h_dentry = au_h_dptr(dentry, bindex);
10662 + if (h_dentry && d_is_positive(h_dentry)) {
10663 + arg.bindex = bindex;
10664 + err = test_empty(dentry, &arg);
10669 + au_nhash_wh_free(&whlist);
10674 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10677 + struct test_empty_arg arg = {
10679 + .actor = test_empty_cb
10682 + aufs_bindex_t bindex, btail;
10685 + arg.whlist = whlist;
10686 + arg.flags = AuTestEmpty_WHONLY;
10687 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10688 + au_fset_testempty(arg.flags, SHWH);
10689 + btail = au_dbtaildir(dentry);
10690 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10691 + struct dentry *h_dentry;
10693 + h_dentry = au_h_dptr(dentry, bindex);
10694 + if (h_dentry && d_is_positive(h_dentry)) {
10695 + arg.bindex = bindex;
10696 + err = sio_test_empty(dentry, &arg);
10703 +/* ---------------------------------------------------------------------- */
10705 +const struct file_operations aufs_dir_fop = {
10706 + .owner = THIS_MODULE,
10707 + .llseek = default_llseek,
10708 + .read = generic_read_dir,
10709 + .iterate_shared = aufs_iterate_shared,
10710 + .unlocked_ioctl = aufs_ioctl_dir,
10711 +#ifdef CONFIG_COMPAT
10712 + .compat_ioctl = aufs_compat_ioctl_dir,
10714 + .open = aufs_open_dir,
10715 + .release = aufs_release_dir,
10716 + .flush = aufs_flush_dir,
10717 + .fsync = aufs_fsync_dir
10719 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10720 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10721 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10723 +/* SPDX-License-Identifier: GPL-2.0 */
10725 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10727 + * This program is free software; you can redistribute it and/or modify
10728 + * it under the terms of the GNU General Public License as published by
10729 + * the Free Software Foundation; either version 2 of the License, or
10730 + * (at your option) any later version.
10732 + * This program is distributed in the hope that it will be useful,
10733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10735 + * GNU General Public License for more details.
10737 + * You should have received a copy of the GNU General Public License
10738 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10742 + * directory operations
10745 +#ifndef __AUFS_DIR_H__
10746 +#define __AUFS_DIR_H__
10750 +#include <linux/fs.h>
10752 +/* ---------------------------------------------------------------------- */
10754 +/* need to be faster and smaller */
10757 + unsigned int nh_num;
10758 + struct hlist_head *nh_head;
10761 +struct au_vdir_destr {
10762 + unsigned char len;
10763 + unsigned char name[];
10766 +struct au_vdir_dehstr {
10767 + struct hlist_node hash;
10768 + struct au_vdir_destr *str;
10769 + struct rcu_head rcu;
10770 +} ____cacheline_aligned_in_smp;
10772 +struct au_vdir_de {
10774 + unsigned char de_type;
10775 + /* caution: packed */
10776 + struct au_vdir_destr de_str;
10779 +struct au_vdir_wh {
10780 + struct hlist_node wh_hash;
10781 +#ifdef CONFIG_AUFS_SHWH
10783 + aufs_bindex_t wh_bindex;
10784 + unsigned char wh_type;
10786 + aufs_bindex_t wh_bindex;
10788 + /* caution: packed */
10789 + struct au_vdir_destr wh_str;
10792 +union au_vdir_deblk_p {
10793 + unsigned char *deblk;
10794 + struct au_vdir_de *de;
10798 + unsigned char **vd_deblk;
10799 + unsigned long vd_nblk;
10801 + unsigned long ul;
10802 + union au_vdir_deblk_p p;
10806 + unsigned int vd_deblk_sz;
10807 + unsigned long vd_jiffy;
10808 + struct rcu_head rcu;
10809 +} ____cacheline_aligned_in_smp;
10811 +/* ---------------------------------------------------------------------- */
10814 +extern const struct file_operations aufs_dir_fop;
10815 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10816 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10817 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10818 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10819 +int au_test_empty_lower(struct dentry *dentry);
10820 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10823 +unsigned int au_rdhash_est(loff_t sz);
10824 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10825 +void au_nhash_wh_free(struct au_nhash *whlist);
10826 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10828 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10829 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10830 + unsigned int d_type, aufs_bindex_t bindex,
10831 + unsigned char shwh);
10832 +void au_vdir_free(struct au_vdir *vdir);
10833 +int au_vdir_init(struct file *file);
10834 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10837 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10839 +#ifdef CONFIG_AUFS_RDU
10841 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10842 +#ifdef CONFIG_COMPAT
10843 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10844 + unsigned long arg);
10847 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10848 + unsigned int cmd, unsigned long arg)
10849 +#ifdef CONFIG_COMPAT
10850 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10851 + unsigned int cmd, unsigned long arg)
10855 +#endif /* __KERNEL__ */
10856 +#endif /* __AUFS_DIR_H__ */
10857 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10858 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10859 +++ linux/fs/aufs/dirren.c 2022-11-05 23:02:18.962555950 +0100
10861 +// SPDX-License-Identifier: GPL-2.0
10863 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10865 + * This program is free software; you can redistribute it and/or modify
10866 + * it under the terms of the GNU General Public License as published by
10867 + * the Free Software Foundation; either version 2 of the License, or
10868 + * (at your option) any later version.
10870 + * This program is distributed in the hope that it will be useful,
10871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10873 + * GNU General Public License for more details.
10875 + * You should have received a copy of the GNU General Public License
10876 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10880 + * special handling in renaming a directory
10881 + * in order to support looking-up the before-renamed name on the lower readonly
10885 +#include <linux/byteorder/generic.h>
10888 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10892 + idx = au_dr_ihash(ent->dr_h_ino);
10893 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10896 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10899 + struct hlist_bl_head *hbl;
10902 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10903 + hbl = dr->dr_h_ino + i;
10904 + hlist_bl_lock(hbl);
10905 + ret &= hlist_bl_empty(hbl);
10906 + hlist_bl_unlock(hbl);
10912 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10914 + struct au_dr_hino *found, *ent;
10915 + struct hlist_bl_head *hbl;
10916 + struct hlist_bl_node *pos;
10920 + idx = au_dr_ihash(ino);
10921 + hbl = dr->dr_h_ino + idx;
10922 + hlist_bl_lock(hbl);
10923 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10924 + if (ent->dr_h_ino == ino) {
10928 + hlist_bl_unlock(hbl);
10933 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10934 + struct au_dr_hino *add_ent)
10937 + struct hlist_bl_head *hbl;
10938 + struct hlist_bl_node *pos;
10939 + struct au_dr_hino *ent;
10942 + idx = au_dr_ihash(ino);
10943 + hbl = dr->dr_h_ino + idx;
10944 +#if 0 /* debug print */
10946 + struct hlist_bl_node *tmp;
10948 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10949 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10952 + hlist_bl_lock(hbl);
10953 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10954 + if (ent->dr_h_ino == ino) {
10958 + if (!found && add_ent)
10959 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10960 + hlist_bl_unlock(hbl);
10962 + if (!found && add_ent)
10963 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10968 +void au_dr_hino_free(struct au_dr_br *dr)
10971 + struct hlist_bl_head *hbl;
10972 + struct hlist_bl_node *pos, *tmp;
10973 + struct au_dr_hino *ent;
10975 + /* SiMustWriteLock(sb); */
10977 + for (i = 0; i < AuDirren_NHASH; i++) {
10978 + hbl = dr->dr_h_ino + i;
10979 + /* no spinlock since sbinfo must be write-locked */
10980 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10981 + au_kfree_rcu(ent);
10982 + INIT_HLIST_BL_HEAD(hbl);
10986 +/* returns the number of inodes or an error */
10987 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
10988 + struct file *hinofile)
10992 + loff_t pos, oldsize;
10994 + struct inode *hinoinode;
10995 + struct hlist_bl_head *hbl;
10996 + struct hlist_bl_node *n1, *n2;
10997 + struct au_dr_hino *ent;
10999 + SiMustWriteLock(sb);
11000 + AuDebugOn(!au_br_writable(br->br_perm));
11002 + hinoinode = file_inode(hinofile);
11003 + oldsize = i_size_read(hinoinode);
11007 + hbl = br->br_dirren.dr_h_ino;
11008 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11009 + /* no bit-lock since sbinfo must be write-locked */
11010 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11011 + AuDbg("hi%llu, %pD2\n",
11012 + (unsigned long long)ent->dr_h_ino, hinofile);
11013 + u64 = cpu_to_be64(ent->dr_h_ino);
11014 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11015 + if (ssz == sizeof(u64))
11018 + /* write error */
11019 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11026 + /* regardless the error */
11027 + if (pos < oldsize) {
11028 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11036 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11043 + struct au_dr_hino *ent;
11044 + struct inode *hinoinode;
11045 + struct hlist_bl_head *hbl;
11049 + hbl = dr->dr_h_ino;
11050 + hinoinode = file_inode(hinofile);
11051 + sz = i_size_read(hinoinode);
11052 + AuDebugOn(sz % sizeof(u64));
11053 + n = sz / sizeof(u64);
11055 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11056 + if (unlikely(ssz != sizeof(u64))) {
11057 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11064 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11070 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11071 + AuDbg("hi%llu, %pD2\n",
11072 + (unsigned long long)ent->dr_h_ino, hinofile);
11073 + hidx = au_dr_ihash(ent->dr_h_ino);
11074 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11076 + goto out; /* success */
11079 + au_dr_hino_free(dr);
11086 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11087 + * @path is a switch to distinguish load and store.
11089 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11090 + struct au_branch *br, const struct path *path)
11093 + unsigned char load, suspend;
11094 + struct file *hinofile;
11095 + struct au_hinode *hdir;
11096 + struct inode *dir, *delegated;
11097 + struct path hinopath;
11098 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11099 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11101 + AuDebugOn(bindex < 0 && !br);
11102 + AuDebugOn(bindex >= 0 && br);
11107 + br = au_sbr(sb, bindex);
11110 + path = &br->br_path;
11111 + AuDebugOn(!au_br_writable(br->br_perm));
11112 + if (unlikely(!au_br_writable(br->br_perm)))
11118 + dir = d_inode(sb->s_root);
11119 + hdir = au_hinode(au_ii(dir), bindex);
11120 + dir = hdir->hi_inode;
11121 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11123 + dir = d_inode(path->dentry);
11124 + inode_lock_nested(dir, AuLsc_I_CHILD);
11126 + hinopath.mnt = path->mnt;
11127 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11128 + err = PTR_ERR(hinopath.dentry);
11129 + if (IS_ERR(hinopath.dentry))
11133 + flags = O_RDONLY;
11135 + if (d_is_negative(hinopath.dentry))
11136 + goto out_dput; /* success */
11138 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11139 + if (d_is_positive(hinopath.dentry)) {
11140 + delegated = NULL;
11141 + err = vfsub_unlink(dir, &hinopath, &delegated,
11144 + if (unlikely(err))
11145 + pr_err("ignored err %d, %pd2\n",
11146 + err, hinopath.dentry);
11147 + if (unlikely(err == -EWOULDBLOCK))
11152 + } else if (!d_is_positive(hinopath.dentry)) {
11153 + err = vfsub_create(dir, &hinopath, 0600,
11154 + /*want_excl*/false);
11156 + if (unlikely(err))
11159 + flags = O_WRONLY;
11161 + hinofile = vfsub_dentry_open(&hinopath, flags);
11163 + au_hn_inode_unlock(hdir);
11165 + inode_unlock(dir);
11166 + dput(hinopath.dentry);
11167 + AuTraceErrPtr(hinofile);
11168 + if (IS_ERR(hinofile)) {
11169 + err = PTR_ERR(hinofile);
11174 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11176 + err = au_dr_hino_store(sb, br, hinofile);
11181 + dput(hinopath.dentry);
11184 + au_hn_inode_unlock(hdir);
11186 + inode_unlock(dir);
11192 +/* ---------------------------------------------------------------------- */
11194 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11197 + struct kstatfs kstfs;
11199 + struct dentry *dentry;
11200 + struct super_block *sb;
11202 + err = vfs_statfs((void *)path, &kstfs);
11204 + if (unlikely(err))
11207 + /* todo: support for UUID */
11209 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11210 + brid->type = AuBrid_FSID;
11211 + brid->fsid = kstfs.f_fsid;
11213 + dentry = path->dentry;
11214 + sb = dentry->d_sb;
11217 + brid->type = AuBrid_DEV;
11226 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11227 + const struct path *path)
11230 + struct au_dr_br *dr;
11231 + struct hlist_bl_head *hbl;
11233 + dr = &br->br_dirren;
11234 + hbl = dr->dr_h_ino;
11235 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11236 + INIT_HLIST_BL_HEAD(hbl);
11238 + err = au_dr_brid_init(&dr->dr_brid, path);
11239 + if (unlikely(err))
11242 + if (au_opt_test(au_mntflags(sb), DIRREN))
11243 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11250 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11255 + if (au_br_writable(br->br_perm))
11256 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11258 + au_dr_hino_free(&br->br_dirren);
11263 +/* ---------------------------------------------------------------------- */
11265 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11266 + char *buf, size_t sz)
11269 + unsigned int major, minor;
11273 + err = snprintf(p, sz, "%d_", brid->type);
11274 + AuDebugOn(err > sz);
11277 + switch (brid->type) {
11278 + case AuBrid_Unset:
11280 + case AuBrid_UUID:
11281 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11283 + case AuBrid_FSID:
11284 + err = snprintf(p, sz, "%08x-%08x",
11285 + brid->fsid.val[0], brid->fsid.val[1]);
11288 + major = MAJOR(brid->dev);
11289 + minor = MINOR(brid->dev);
11290 + if (major <= 0xff && minor <= 0xff)
11291 + err = snprintf(p, sz, "%02x%02x", major, minor);
11293 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11296 + AuDebugOn(err > sz);
11299 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11300 + AuDebugOn(err > sz);
11307 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11310 + struct dentry *br_dentry;
11311 + struct inode *br_inode;
11313 + br_dentry = au_br_dentry(br);
11314 + br_inode = d_inode(br_dentry);
11315 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11316 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11317 + AuDebugOn(rlen > len);
11322 +/* ---------------------------------------------------------------------- */
11325 + * from the given @h_dentry, construct drinfo at @*fdata.
11326 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11329 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11330 + struct dentry *h_dentry,
11331 + unsigned char *allocated)
11334 + struct au_drinfo_fdata *f, *p;
11335 + struct au_drinfo *drinfo;
11336 + struct inode *h_inode;
11337 + struct qstr *qname;
11341 + h_inode = d_inode(h_dentry);
11342 + qname = &h_dentry->d_name;
11343 + drinfo = &f->drinfo;
11344 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11345 + drinfo->oldnamelen = qname->len;
11346 + if (*allocated < sizeof(*f) + qname->len) {
11347 + v = roundup_pow_of_two(*allocated + qname->len);
11348 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11349 + if (unlikely(!p)) {
11357 + drinfo = &f->drinfo;
11359 + memcpy(drinfo->oldname, qname->name, qname->len);
11360 + AuDbg("i%llu, %.*s\n",
11361 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11362 + drinfo->oldname);
11369 +/* callers have to free the return value */
11370 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11372 + struct au_drinfo *ret, *drinfo;
11373 + struct au_drinfo_fdata fdata;
11378 + ret = ERR_PTR(-EIO);
11380 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11381 + if (unlikely(ssz != sizeof(fdata))) {
11382 + AuIOErr("ssz %zd, %u, %pD2\n",
11383 + ssz, (unsigned int)sizeof(fdata), file);
11387 + fdata.magic = ntohl((__force __be32)fdata.magic);
11388 + switch (fdata.magic) {
11389 + case AUFS_DRINFO_MAGIC_V1:
11392 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11393 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11397 + drinfo = &fdata.drinfo;
11398 + len = drinfo->oldnamelen;
11400 + AuIOErr("broken drinfo %pD2\n", file);
11405 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11406 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11407 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11408 + (unsigned long long)drinfo->ino,
11409 + (unsigned long long)h_ino, file);
11410 + goto out; /* success */
11413 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11414 + if (unlikely(!ret)) {
11415 + ret = ERR_PTR(-ENOMEM);
11416 + AuTraceErrPtr(ret);
11421 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11422 + if (unlikely(ssz != len)) {
11423 + au_kfree_rcu(ret);
11424 + ret = ERR_PTR(-EIO);
11425 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11429 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11435 +/* ---------------------------------------------------------------------- */
11437 +/* in order to be revertible */
11438 +struct au_drinfo_rev_elm {
11440 + struct dentry *info_dentry;
11441 + struct au_drinfo *info_last;
11444 +struct au_drinfo_rev {
11445 + unsigned char already;
11446 + aufs_bindex_t nelm;
11447 + struct au_drinfo_rev_elm elm[];
11450 +/* todo: isn't it too large? */
11451 +struct au_drinfo_store {
11452 + struct path h_ppath;
11453 + struct dentry *h_dentry;
11454 + struct au_drinfo_fdata *fdata;
11455 + char *infoname; /* inside of whname, just after PFX */
11456 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11457 + aufs_bindex_t btgt, btail;
11458 + unsigned char no_sio,
11459 + allocated, /* current size of *fdata */
11460 + infonamelen, /* room size for p */
11461 + whnamelen, /* length of the generated name */
11462 + renameback; /* renamed back */
11465 +/* on rename(2) error, the caller should revert it using @elm */
11466 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11467 + struct au_drinfo_rev_elm *elm)
11472 + struct path infopath = {
11473 + .mnt = w->h_ppath.mnt
11475 + struct inode *h_dir, *h_inode, *delegated;
11476 + struct file *infofile;
11477 + struct qstr *qname;
11480 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11482 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11484 + AuTraceErrPtr(infopath.dentry);
11485 + if (IS_ERR(infopath.dentry)) {
11486 + err = PTR_ERR(infopath.dentry);
11491 + h_dir = d_inode(w->h_ppath.dentry);
11492 + if (elm && d_is_negative(infopath.dentry)) {
11493 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11495 + if (unlikely(err))
11497 + elm->created = 1;
11498 + elm->info_dentry = dget(infopath.dentry);
11501 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11502 + AuTraceErrPtr(infofile);
11503 + if (IS_ERR(infofile)) {
11504 + err = PTR_ERR(infofile);
11508 + h_inode = d_inode(infopath.dentry);
11509 + if (elm && i_size_read(h_inode)) {
11510 + h_inode = d_inode(w->h_dentry);
11511 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11512 + AuTraceErrPtr(elm->info_last);
11513 + if (IS_ERR(elm->info_last)) {
11514 + err = PTR_ERR(elm->info_last);
11515 + elm->info_last = NULL;
11516 + AuDebugOn(elm->info_dentry);
11521 + if (elm && w->renameback) {
11522 + delegated = NULL;
11523 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11525 + if (unlikely(err == -EWOULDBLOCK))
11531 + qname = &w->h_dentry->d_name;
11532 + len = sizeof(*w->fdata) + qname->len;
11534 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11535 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11536 + if (ssz == len) {
11537 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11538 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11539 + goto out_fput; /* success */
11544 + /* the caller should revert it using @elm */
11550 + dput(infopath.dentry);
11556 +struct au_call_drinfo_do_store_args {
11558 + struct au_drinfo_store *w;
11559 + struct au_drinfo_rev_elm *elm;
11562 +static void au_call_drinfo_do_store(void *args)
11564 + struct au_call_drinfo_do_store_args *a = args;
11566 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11569 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11570 + struct au_drinfo_rev_elm *elm)
11572 + int err, wkq_err;
11575 + err = au_drinfo_do_store(w, elm);
11577 + struct au_call_drinfo_do_store_args a = {
11582 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11583 + if (unlikely(wkq_err))
11591 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11592 + aufs_bindex_t btgt)
11596 + memset(w, 0, sizeof(*w));
11597 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11598 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11599 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11600 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11602 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11605 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11606 + if (unlikely(!w->fdata)) {
11610 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11617 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11619 + au_kfree_rcu(w->fdata);
11622 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11623 + struct au_drinfo_store *w)
11625 + struct au_drinfo_rev_elm *elm;
11626 + struct inode *h_dir, *delegated;
11628 + struct path infopath = {
11629 + .mnt = w->h_ppath.mnt
11632 + h_dir = d_inode(w->h_ppath.dentry);
11633 + IMustLock(h_dir);
11637 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11638 + AuDebugOn(elm->created && elm->info_last);
11639 + if (elm->created) {
11641 + delegated = NULL;
11642 + infopath.dentry = elm->info_dentry;
11643 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11646 + if (unlikely(err == -EWOULDBLOCK))
11648 + dput(elm->info_dentry);
11649 + } else if (elm->info_last) {
11651 + w->fdata->drinfo = *elm->info_last;
11652 + memcpy(w->fdata->drinfo.oldname,
11653 + elm->info_last->oldname,
11654 + elm->info_last->oldnamelen);
11655 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11656 + au_kfree_rcu(elm->info_last);
11658 + if (unlikely(err))
11659 + AuIOErr("%d, %s\n", err, w->whname);
11660 + /* go on even if err */
11664 +/* caller has to call au_dr_rename_fin() later */
11665 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11666 + struct qstr *dst_name, void *_rev)
11668 + int err, sz, nelm;
11669 + aufs_bindex_t bindex, btail;
11670 + struct au_drinfo_store work;
11671 + struct au_drinfo_rev *rev, **p;
11672 + struct au_drinfo_rev_elm *elm;
11673 + struct super_block *sb;
11674 + struct au_branch *br;
11675 + struct au_hinode *hdir;
11677 + err = au_drinfo_store_work_init(&work, btgt);
11679 + if (unlikely(err))
11683 + btail = au_dbtaildir(dentry);
11684 + nelm = btail - btgt;
11685 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11686 + rev = kcalloc(1, sz, GFP_NOFS);
11687 + if (unlikely(!rev)) {
11691 + rev->nelm = nelm;
11697 + sb = dentry->d_sb;
11698 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11699 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11700 + hdir = au_hi(d_inode(dentry), btgt);
11701 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11702 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11703 + work.h_dentry = au_h_dptr(dentry, bindex);
11704 + if (!work.h_dentry)
11707 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11708 + &work.allocated);
11710 + if (unlikely(err))
11713 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11714 + br = au_sbr(sb, bindex);
11715 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11716 + work.whnamelen += au_drinfo_name(br, work.infoname,
11717 + work.infonamelen);
11718 + AuDbg("whname %.*s, i%llu, %.*s\n",
11719 + work.whnamelen, work.whname,
11720 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11721 + work.fdata->drinfo.oldnamelen,
11722 + work.fdata->drinfo.oldname);
11724 + err = au_drinfo_store_sio(&work, elm);
11726 + if (unlikely(err))
11729 + if (unlikely(err)) {
11730 + /* revert all drinfo */
11731 + au_drinfo_store_rev(rev, &work);
11732 + au_kfree_try_rcu(rev);
11735 + au_hn_inode_unlock(hdir);
11738 + au_drinfo_store_work_fin(&work);
11743 +/* ---------------------------------------------------------------------- */
11745 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11746 + struct qstr *dst_name, void *_rev)
11748 + int err, already;
11750 + struct super_block *sb;
11751 + struct au_branch *br;
11752 + struct au_dr_br *dr;
11753 + struct dentry *h_dentry;
11754 + struct inode *h_inode;
11755 + struct au_dr_hino *ent;
11756 + struct au_drinfo_rev *rev, **p;
11758 + AuDbg("bindex %d\n", bindex);
11761 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11762 + if (unlikely(!ent))
11766 + br = au_sbr(sb, bindex);
11767 + dr = &br->br_dirren;
11768 + h_dentry = au_h_dptr(src, bindex);
11769 + h_inode = d_inode(h_dentry);
11770 + ino = h_inode->i_ino;
11771 + ent->dr_h_ino = ino;
11772 + already = au_dr_hino_test_add(dr, ino, ent);
11773 + AuDbg("b%d, hi%llu, already %d\n",
11774 + bindex, (unsigned long long)ino, already);
11776 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11781 + rev->already = already;
11782 + goto out; /* success */
11787 + au_dr_hino_del(dr, ent);
11788 + au_kfree_rcu(ent);
11795 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11797 + struct au_drinfo_rev *rev;
11798 + struct au_drinfo_rev_elm *elm;
11803 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11804 + dput(elm->info_dentry);
11805 + au_kfree_rcu(elm->info_last);
11807 + au_kfree_try_rcu(rev);
11810 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11813 + struct au_drinfo_store work;
11814 + struct au_drinfo_rev *rev = _rev;
11815 + struct super_block *sb;
11816 + struct au_branch *br;
11817 + struct inode *h_inode;
11818 + struct au_dr_br *dr;
11819 + struct au_dr_hino *ent;
11821 + err = au_drinfo_store_work_init(&work, btgt);
11822 + if (unlikely(err))
11826 + br = au_sbr(sb, btgt);
11827 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11828 + work.h_ppath.mnt = au_br_mnt(br);
11829 + au_drinfo_store_rev(rev, &work);
11830 + au_drinfo_store_work_fin(&work);
11831 + if (rev->already)
11834 + dr = &br->br_dirren;
11835 + h_inode = d_inode(work.h_ppath.dentry);
11836 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11838 + au_dr_hino_del(dr, ent);
11839 + au_kfree_rcu(ent);
11842 + au_kfree_try_rcu(rev);
11843 + if (unlikely(err))
11844 + pr_err("failed to remove dirren info\n");
11847 +/* ---------------------------------------------------------------------- */
11849 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11850 + char *whname, int whnamelen,
11851 + struct dentry **info_dentry)
11853 + struct au_drinfo *drinfo;
11855 + struct inode *h_dir;
11856 + struct path infopath;
11859 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11861 + *info_dentry = NULL;
11864 + h_dir = d_inode(h_ppath->dentry);
11865 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11866 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11867 + if (IS_ERR(infopath.dentry)) {
11868 + drinfo = (void *)infopath.dentry;
11872 + if (d_is_negative(infopath.dentry))
11873 + goto out_dput; /* success */
11875 + infopath.mnt = h_ppath->mnt;
11876 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11877 + inode_unlock_shared(h_dir);
11880 + drinfo = (void *)f;
11884 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11885 + if (IS_ERR_OR_NULL(drinfo))
11888 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11889 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11894 + dput(infopath.dentry);
11897 + inode_unlock_shared(h_dir);
11898 + AuTraceErrPtr(drinfo);
11902 +struct au_drinfo_do_load_args {
11903 + struct au_drinfo **drinfop;
11904 + struct path *h_ppath;
11907 + struct dentry **info_dentry;
11910 +static void au_call_drinfo_do_load(void *args)
11912 + struct au_drinfo_do_load_args *a = args;
11914 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11918 +struct au_drinfo_load {
11919 + struct path h_ppath;
11920 + struct qstr *qname;
11921 + unsigned char no_sio;
11923 + aufs_bindex_t ninfo;
11924 + struct au_drinfo **drinfo;
11927 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11928 + struct au_branch *br)
11930 + int err, wkq_err, whnamelen, e;
11931 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11932 + = AUFS_WH_DR_INFO_PFX;
11933 + struct au_drinfo *drinfo;
11934 + struct qstr oldname;
11935 + struct inode *h_dir, *delegated;
11936 + struct dentry *info_dentry;
11937 + struct path infopath;
11939 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11940 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11941 + sizeof(whname) - whnamelen);
11943 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11946 + struct au_drinfo_do_load_args args = {
11947 + .drinfop = &drinfo,
11948 + .h_ppath = &w->h_ppath,
11949 + .whname = whname,
11950 + .whnamelen = whnamelen,
11951 + .info_dentry = &info_dentry
11953 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11954 + if (unlikely(wkq_err))
11955 + drinfo = ERR_PTR(wkq_err);
11957 + err = PTR_ERR(drinfo);
11958 + if (IS_ERR_OR_NULL(drinfo))
11962 + oldname.len = drinfo->oldnamelen;
11963 + oldname.name = drinfo->oldname;
11964 + if (au_qstreq(w->qname, &oldname)) {
11965 + /* the name is renamed back */
11966 + au_kfree_rcu(drinfo);
11969 + infopath.dentry = info_dentry;
11970 + infopath.mnt = w->h_ppath.mnt;
11971 + h_dir = d_inode(w->h_ppath.dentry);
11972 + delegated = NULL;
11973 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11974 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11975 + inode_unlock(h_dir);
11977 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
11978 + if (unlikely(e == -EWOULDBLOCK))
11981 + au_kfree_rcu(w->drinfo[bindex]);
11982 + w->drinfo[bindex] = drinfo;
11983 + dput(info_dentry);
11990 +/* ---------------------------------------------------------------------- */
11992 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
11994 + struct au_drinfo **p = drinfo;
11997 + au_kfree_rcu(*drinfo++);
11998 + au_kfree_try_rcu(p);
12001 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12002 + aufs_bindex_t btgt)
12005 + struct au_drinfo_load w;
12006 + aufs_bindex_t bindex, bbot;
12007 + struct au_branch *br;
12008 + struct inode *h_dir;
12009 + struct au_dr_hino *ent;
12010 + struct super_block *sb;
12012 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12013 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12014 + AuLNPair(&lkup->whname), btgt);
12016 + sb = dentry->d_sb;
12017 + bbot = au_sbbot(sb);
12018 + w.ninfo = bbot + 1;
12019 + if (!lkup->dirren.drinfo) {
12020 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12021 + sizeof(*lkup->dirren.drinfo),
12023 + if (unlikely(!lkup->dirren.drinfo)) {
12027 + lkup->dirren.ninfo = w.ninfo;
12029 + w.drinfo = lkup->dirren.drinfo;
12030 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12031 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12032 + AuDebugOn(!w.h_ppath.dentry);
12033 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12034 + w.qname = &dentry->d_name;
12037 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12038 + br = au_sbr(sb, bindex);
12039 + err = au_drinfo_load(&w, bindex, br);
12040 + if (unlikely(err))
12042 + if (w.drinfo[bindex])
12046 + br = au_sbr(sb, btgt);
12047 + h_dir = d_inode(w.h_ppath.dentry);
12048 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12050 + au_dr_hino_del(&br->br_dirren, ent);
12051 + au_kfree_rcu(ent);
12053 + goto out; /* success */
12056 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12057 + lkup->dirren.ninfo = 0;
12058 + lkup->dirren.drinfo = NULL;
12064 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12066 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12069 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12072 + struct au_drinfo *drinfo;
12075 + if (!lkup->dirren.drinfo)
12077 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12078 + drinfo = lkup->dirren.drinfo[btgt];
12082 + au_kfree_try_rcu(lkup->whname.name);
12083 + lkup->whname.name = NULL;
12084 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12085 + lkup->dirren.dr_name.name = drinfo->oldname;
12086 + lkup->name = &lkup->dirren.dr_name;
12087 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12089 + AuDbg("name %.*s, whname %.*s, b%d\n",
12090 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12098 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12102 + struct au_drinfo *drinfo;
12105 + if (!lkup->dirren.drinfo)
12107 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12108 + drinfo = lkup->dirren.drinfo[bindex];
12112 + match = (drinfo->ino == h_ino);
12113 + AuDbg("match %d\n", match);
12119 +/* ---------------------------------------------------------------------- */
12121 +int au_dr_opt_set(struct super_block *sb)
12124 + aufs_bindex_t bindex, bbot;
12125 + struct au_branch *br;
12128 + bbot = au_sbbot(sb);
12129 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12130 + br = au_sbr(sb, bindex);
12131 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12137 +int au_dr_opt_flush(struct super_block *sb)
12140 + aufs_bindex_t bindex, bbot;
12141 + struct au_branch *br;
12144 + bbot = au_sbbot(sb);
12145 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12146 + br = au_sbr(sb, bindex);
12147 + if (au_br_writable(br->br_perm))
12148 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12154 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12157 + aufs_bindex_t bindex, bbot;
12158 + struct au_branch *br;
12162 + err = au_dr_opt_flush(sb);
12163 + if (unlikely(err))
12167 + bbot = au_sbbot(sb);
12168 + for (bindex = 0; bindex <= bbot; bindex++) {
12169 + br = au_sbr(sb, bindex);
12170 + au_dr_hino_free(&br->br_dirren);
12176 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12177 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12178 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12180 +/* SPDX-License-Identifier: GPL-2.0 */
12182 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12184 + * This program is free software; you can redistribute it and/or modify
12185 + * it under the terms of the GNU General Public License as published by
12186 + * the Free Software Foundation; either version 2 of the License, or
12187 + * (at your option) any later version.
12189 + * This program is distributed in the hope that it will be useful,
12190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12192 + * GNU General Public License for more details.
12194 + * You should have received a copy of the GNU General Public License
12195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12199 + * renamed dir info
12202 +#ifndef __AUFS_DIRREN_H__
12203 +#define __AUFS_DIRREN_H__
12207 +#include <linux/dcache.h>
12208 +#include <linux/statfs.h>
12209 +#include <linux/uuid.h>
12212 +#define AuDirren_NHASH 100
12214 +#ifdef CONFIG_AUFS_DIRREN
12215 +enum au_brid_type {
12222 +struct au_dr_brid {
12223 + enum au_brid_type type;
12225 + uuid_t uuid; /* unimplemented yet */
12231 +/* 20 is the max digits length of ulong 64 */
12232 +/* brid-type "_" uuid "_" inum */
12233 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12234 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12236 +struct au_dr_hino {
12237 + struct hlist_bl_node dr_hnode;
12242 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12243 + struct au_dr_brid dr_brid;
12246 +struct au_dr_lookup {
12247 + /* dr_name is pointed by struct au_do_lookup_args.name */
12248 + struct qstr dr_name; /* subset of dr_info */
12249 + aufs_bindex_t ninfo;
12250 + struct au_drinfo **drinfo;
12253 +struct au_dr_hino;
12255 +struct au_dr_br { };
12256 +struct au_dr_lookup { };
12259 +/* ---------------------------------------------------------------------- */
12262 +struct au_do_lookup_args;
12264 +#ifdef CONFIG_AUFS_DIRREN
12265 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12266 + struct au_dr_hino *add_ent);
12267 +void au_dr_hino_free(struct au_dr_br *dr);
12268 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12269 + const struct path *path);
12270 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12271 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12272 + struct qstr *dst_name, void *_rev);
12273 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12274 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12275 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12276 + aufs_bindex_t bindex);
12277 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12278 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12280 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12281 +int au_dr_opt_set(struct super_block *sb);
12282 +int au_dr_opt_flush(struct super_block *sb);
12283 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12285 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12286 + struct au_dr_hino *add_ent);
12287 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12288 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12289 + const struct path *path);
12290 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12291 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12292 + struct qstr *dst_name, void *_rev);
12293 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12294 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12296 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12297 + aufs_bindex_t bindex);
12298 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12299 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12300 + aufs_bindex_t bindex, ino_t h_ino);
12301 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12302 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12303 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12304 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12307 +/* ---------------------------------------------------------------------- */
12309 +#ifdef CONFIG_AUFS_DIRREN
12310 +static inline int au_dr_ihash(ino_t h_ino)
12312 + return h_ino % AuDirren_NHASH;
12315 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12318 +#endif /* __KERNEL__ */
12319 +#endif /* __AUFS_DIRREN_H__ */
12320 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12321 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12322 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12324 +// SPDX-License-Identifier: GPL-2.0
12326 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12328 + * This program is free software; you can redistribute it and/or modify
12329 + * it under the terms of the GNU General Public License as published by
12330 + * the Free Software Foundation; either version 2 of the License, or
12331 + * (at your option) any later version.
12333 + * This program is distributed in the hope that it will be useful,
12334 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12335 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12336 + * GNU General Public License for more details.
12338 + * You should have received a copy of the GNU General Public License
12339 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12343 + * dynamically customizable operations for regular files
12348 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12351 + * How large will these lists be?
12352 + * Usually just a few elements, 20-30 at most for each, I guess.
12354 +static struct hlist_bl_head dynop[AuDyLast];
12356 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12357 + const void *h_op)
12359 + struct au_dykey *key, *tmp;
12360 + struct hlist_bl_node *pos;
12363 + hlist_bl_lock(hbl);
12364 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12365 + if (tmp->dk_op.dy_hop == h_op) {
12366 + if (kref_get_unless_zero(&tmp->dk_kref))
12370 + hlist_bl_unlock(hbl);
12375 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12377 + struct au_dykey **k, *found;
12378 + const void *h_op = key->dk_op.dy_hop;
12382 + k = br->br_dykey;
12383 + for (i = 0; i < AuBrDynOp; i++)
12385 + if (k[i]->dk_op.dy_hop == h_op) {
12392 + spin_lock(&br->br_dykey_lock);
12393 + for (; i < AuBrDynOp; i++)
12395 + if (k[i]->dk_op.dy_hop == h_op) {
12403 + spin_unlock(&br->br_dykey_lock);
12404 + BUG_ON(i == AuBrDynOp); /* expand the array */
12410 +/* kref_get() if @key is already added */
12411 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12413 + struct au_dykey *tmp, *found;
12414 + struct hlist_bl_node *pos;
12415 + const void *h_op = key->dk_op.dy_hop;
12418 + hlist_bl_lock(hbl);
12419 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12420 + if (tmp->dk_op.dy_hop == h_op) {
12421 + if (kref_get_unless_zero(&tmp->dk_kref))
12426 + hlist_bl_add_head(&key->dk_hnode, hbl);
12427 + hlist_bl_unlock(hbl);
12434 +static void dy_free_rcu(struct rcu_head *rcu)
12436 + struct au_dykey *key;
12438 + key = container_of(rcu, struct au_dykey, dk_rcu);
12443 +static void dy_free(struct kref *kref)
12445 + struct au_dykey *key;
12446 + struct hlist_bl_head *hbl;
12448 + key = container_of(kref, struct au_dykey, dk_kref);
12449 + hbl = dynop + key->dk_op.dy_type;
12450 + au_hbl_del(&key->dk_hnode, hbl);
12451 + call_rcu(&key->dk_rcu, dy_free_rcu);
12454 +void au_dy_put(struct au_dykey *key)
12456 + kref_put(&key->dk_kref, dy_free);
12459 +/* ---------------------------------------------------------------------- */
12461 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12463 +#ifdef CONFIG_AUFS_DEBUG
12464 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12465 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12467 +#define DyDbgDeclare(cnt) do {} while (0)
12468 +#define DyDbgInc(cnt) do {} while (0)
12471 +#define DySet(func, dst, src, h_op, h_sb) do { \
12473 + if (h_op->func) { \
12475 + dst.func = src.func; \
12477 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12481 +#define DySetForce(func, dst, src) do { \
12482 + AuDebugOn(!src.func); \
12484 + dst.func = src.func; \
12487 +#define DySetAop(func) \
12488 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12489 +#define DySetAopForce(func) \
12490 + DySetForce(func, dyaop->da_op, aufs_aop)
12492 +static void dy_aop(struct au_dykey *key, const void *h_op,
12493 + struct super_block *h_sb __maybe_unused)
12495 + struct au_dyaop *dyaop = (void *)key;
12496 + const struct address_space_operations *h_aop = h_op;
12497 + DyDbgDeclare(cnt);
12499 + AuDbg("%s\n", au_sbtype(h_sb));
12501 + DySetAop(writepage);
12502 + DySetAopForce(read_folio); /* force */
12503 + DySetAop(writepages);
12504 + DySetAop(dirty_folio);
12505 + DySetAop(invalidate_folio);
12506 + DySetAop(readahead);
12507 + DySetAop(write_begin);
12508 + DySetAop(write_end);
12510 + DySetAop(release_folio);
12511 + DySetAop(free_folio);
12512 + /* this one will be changed according to an aufs mount option */
12513 + DySetAop(direct_IO);
12514 + DySetAop(migrate_folio);
12515 + DySetAop(launder_folio);
12516 + DySetAop(is_partially_uptodate);
12517 + DySetAop(is_dirty_writeback);
12518 + DySetAop(error_remove_page);
12519 + DySetAop(swap_activate);
12520 + DySetAop(swap_deactivate);
12521 + DySetAop(swap_rw);
12523 + DyDbgSize(cnt, *h_aop);
12526 +/* ---------------------------------------------------------------------- */
12528 +static void dy_bug(struct kref *kref)
12533 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12535 + struct au_dykey *key, *old;
12536 + struct hlist_bl_head *hbl;
12539 + void (*set)(struct au_dykey *key, const void *h_op,
12540 + struct super_block *h_sb __maybe_unused);
12542 + static const struct op a[] = {
12544 + .sz = sizeof(struct au_dyaop),
12548 + const struct op *p;
12550 + hbl = dynop + op->dy_type;
12551 + key = dy_gfind_get(hbl, op->dy_hop);
12553 + goto out_add; /* success */
12555 + p = a + op->dy_type;
12556 + key = kzalloc(p->sz, GFP_NOFS);
12557 + if (unlikely(!key)) {
12558 + key = ERR_PTR(-ENOMEM);
12562 + key->dk_op.dy_hop = op->dy_hop;
12563 + kref_init(&key->dk_kref);
12564 + p->set(key, op->dy_hop, au_br_sb(br));
12565 + old = dy_gadd(hbl, key);
12567 + au_kfree_rcu(key);
12572 + old = dy_bradd(br, key);
12574 + /* its ref-count should never be zero here */
12575 + kref_put(&key->dk_kref, dy_bug);
12580 +/* ---------------------------------------------------------------------- */
12582 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12583 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12584 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12585 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12586 + * See the aufs manual in detail.
12588 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12591 + dyaop->da_op.direct_IO = NULL;
12593 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12596 +static struct au_dyaop *dy_aget(struct au_branch *br,
12597 + const struct address_space_operations *h_aop,
12600 + struct au_dyaop *dyaop;
12601 + struct au_dynop op;
12603 + op.dy_type = AuDy_AOP;
12604 + op.dy_haop = h_aop;
12605 + dyaop = (void *)dy_get(&op, br);
12606 + if (IS_ERR(dyaop))
12608 + dy_adx(dyaop, do_dx);
12614 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12615 + struct inode *h_inode)
12618 + struct super_block *sb;
12619 + struct au_branch *br;
12620 + struct au_dyaop *dyaop;
12622 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12623 + IiMustWriteLock(inode);
12625 + sb = inode->i_sb;
12626 + br = au_sbr(sb, bindex);
12627 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12628 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12629 + err = PTR_ERR(dyaop);
12630 + if (IS_ERR(dyaop))
12631 + /* unnecessary to call dy_fput() */
12635 + inode->i_mapping->a_ops = &dyaop->da_op;
12642 + * Is it safe to replace a_ops during the inode/file is in operation?
12643 + * Yes, I hope so.
12645 +int au_dy_irefresh(struct inode *inode)
12648 + aufs_bindex_t btop;
12649 + struct inode *h_inode;
12652 + if (S_ISREG(inode->i_mode)) {
12653 + btop = au_ibtop(inode);
12654 + h_inode = au_h_iptr(inode, btop);
12655 + err = au_dy_iaop(inode, btop, h_inode);
12660 +void au_dy_arefresh(int do_dx)
12662 + struct hlist_bl_head *hbl;
12663 + struct hlist_bl_node *pos;
12664 + struct au_dykey *key;
12666 + hbl = dynop + AuDy_AOP;
12667 + hlist_bl_lock(hbl);
12668 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12669 + dy_adx((void *)key, do_dx);
12670 + hlist_bl_unlock(hbl);
12673 +/* ---------------------------------------------------------------------- */
12675 +void __init au_dy_init(void)
12679 + for (i = 0; i < AuDyLast; i++)
12680 + INIT_HLIST_BL_HEAD(dynop + i);
12683 +void au_dy_fin(void)
12687 + for (i = 0; i < AuDyLast; i++)
12688 + WARN_ON(!hlist_bl_empty(dynop + i));
12690 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12691 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12692 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12694 +/* SPDX-License-Identifier: GPL-2.0 */
12696 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12698 + * This program is free software; you can redistribute it and/or modify
12699 + * it under the terms of the GNU General Public License as published by
12700 + * the Free Software Foundation; either version 2 of the License, or
12701 + * (at your option) any later version.
12703 + * This program is distributed in the hope that it will be useful,
12704 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12705 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12706 + * GNU General Public License for more details.
12708 + * You should have received a copy of the GNU General Public License
12709 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12713 + * dynamically customizable operations (for regular files only)
12716 +#ifndef __AUFS_DYNOP_H__
12717 +#define __AUFS_DYNOP_H__
12721 +#include <linux/fs.h>
12722 +#include <linux/kref.h>
12724 +enum {AuDy_AOP, AuDyLast};
12729 + const void *dy_hop;
12730 + const struct address_space_operations *dy_haop;
12736 + struct hlist_bl_node dk_hnode;
12737 + struct rcu_head dk_rcu;
12739 + struct au_dynop dk_op;
12742 + * during I am in the branch local array, kref is gotten. when the
12743 + * branch is removed, kref is put.
12745 + struct kref dk_kref;
12748 +/* stop unioning since their sizes are very different from each other */
12750 + struct au_dykey da_key;
12751 + struct address_space_operations da_op; /* not const */
12753 +/* make sure that 'struct au_dykey *' can be any type */
12754 +static_assert(!offsetof(struct au_dyaop, da_key));
12756 +/* ---------------------------------------------------------------------- */
12760 +void au_dy_put(struct au_dykey *key);
12761 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12762 + struct inode *h_inode);
12763 +int au_dy_irefresh(struct inode *inode);
12764 +void au_dy_arefresh(int do_dio);
12766 +void __init au_dy_init(void);
12767 +void au_dy_fin(void);
12769 +#endif /* __KERNEL__ */
12770 +#endif /* __AUFS_DYNOP_H__ */
12771 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12772 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12773 +++ linux/fs/aufs/export.c 2022-12-17 09:21:34.796521861 +0100
12775 +// SPDX-License-Identifier: GPL-2.0
12777 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12779 + * This program is free software; you can redistribute it and/or modify
12780 + * it under the terms of the GNU General Public License as published by
12781 + * the Free Software Foundation; either version 2 of the License, or
12782 + * (at your option) any later version.
12784 + * This program is distributed in the hope that it will be useful,
12785 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12786 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12787 + * GNU General Public License for more details.
12789 + * You should have received a copy of the GNU General Public License
12790 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12797 +#include <linux/exportfs.h>
12798 +#include <linux/fs_struct.h>
12799 +#include <linux/nsproxy.h>
12800 +#include <linux/random.h>
12801 +#include <linux/writeback.h>
12805 +#ifdef CONFIG_AUFS_INO_T_64
12813 +static ino_t decode_ino(__u32 *a)
12817 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12819 +#ifdef CONFIG_AUFS_INO_T_64
12825 +static void encode_ino(__u32 *a, ino_t ino)
12831 +#ifdef CONFIG_AUFS_INO_T_64
12836 +/* NFS file handle */
12840 +#ifdef CONFIG_AUFS_INO_T_64
12841 + /* support 64bit inode number */
12854 + Fh_ino = Fh_ino1,
12855 + Fh_dir_ino = Fh_dir_ino1
12858 +static int au_test_anon(struct dentry *dentry)
12860 + /* note: read d_flags without d_lock */
12861 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12864 +int au_test_nfsd(void)
12867 + struct task_struct *tsk = current;
12868 + char comm[sizeof(tsk->comm)];
12871 + if (tsk->flags & PF_KTHREAD) {
12872 + get_task_comm(comm, tsk);
12873 + ret = !strcmp(comm, "nfsd");
12879 +/* ---------------------------------------------------------------------- */
12880 +/* inode generation external table */
12882 +void au_xigen_inc(struct inode *inode)
12887 + struct super_block *sb;
12888 + struct au_sbinfo *sbinfo;
12890 + sb = inode->i_sb;
12891 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12893 + sbinfo = au_sbi(sb);
12894 + pos = inode->i_ino;
12895 + pos *= sizeof(igen);
12896 + igen = inode->i_generation + 1;
12897 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12898 + if (sz == sizeof(igen))
12899 + return; /* success */
12901 + if (unlikely(sz >= 0))
12902 + AuIOErr("xigen error (%zd)\n", sz);
12905 +int au_xigen_new(struct inode *inode)
12910 + struct super_block *sb;
12911 + struct au_sbinfo *sbinfo;
12912 + struct file *file;
12915 + /* todo: dirty, at mount time */
12916 + if (inode->i_ino == AUFS_ROOT_INO)
12918 + sb = inode->i_sb;
12919 + SiMustAnyLock(sb);
12920 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12924 + pos = inode->i_ino;
12925 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12926 + AuIOErr1("too large i%lld\n", pos);
12929 + pos *= sizeof(inode->i_generation);
12932 + sbinfo = au_sbi(sb);
12933 + file = sbinfo->si_xigen;
12936 + if (vfsub_f_size_read(file)
12937 + < pos + sizeof(inode->i_generation)) {
12938 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12939 + sz = xino_fwrite(file, &inode->i_generation,
12940 + sizeof(inode->i_generation), &pos);
12942 + sz = xino_fread(file, &inode->i_generation,
12943 + sizeof(inode->i_generation), &pos);
12944 + if (sz == sizeof(inode->i_generation))
12945 + goto out; /* success */
12948 + if (unlikely(sz >= 0)) {
12950 + AuIOErr("xigen error (%zd)\n", sz);
12957 +int au_xigen_set(struct super_block *sb, struct path *path)
12960 + struct au_sbinfo *sbinfo;
12961 + struct file *file;
12963 + SiMustWriteLock(sb);
12965 + sbinfo = au_sbi(sb);
12966 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12967 + err = PTR_ERR(file);
12968 + if (IS_ERR(file))
12971 + if (sbinfo->si_xigen)
12972 + fput(sbinfo->si_xigen);
12973 + sbinfo->si_xigen = file;
12980 +void au_xigen_clr(struct super_block *sb)
12982 + struct au_sbinfo *sbinfo;
12984 + SiMustWriteLock(sb);
12986 + sbinfo = au_sbi(sb);
12987 + if (sbinfo->si_xigen) {
12988 + fput(sbinfo->si_xigen);
12989 + sbinfo->si_xigen = NULL;
12993 +/* ---------------------------------------------------------------------- */
12995 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
12998 + struct dentry *dentry, *d;
12999 + struct inode *inode;
13000 + unsigned int sigen;
13003 + inode = ilookup(sb, ino);
13007 + dentry = ERR_PTR(-ESTALE);
13008 + sigen = au_sigen(sb);
13009 + if (unlikely(au_is_bad_inode(inode)
13010 + || IS_DEADDIR(inode)
13011 + || sigen != au_iigen(inode, NULL)))
13015 + if (!dir_ino || S_ISDIR(inode->i_mode))
13016 + dentry = d_find_alias(inode);
13018 + spin_lock(&inode->i_lock);
13019 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13020 + spin_lock(&d->d_lock);
13021 + if (!au_test_anon(d)
13022 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13023 + dentry = dget_dlock(d);
13024 + spin_unlock(&d->d_lock);
13027 + spin_unlock(&d->d_lock);
13029 + spin_unlock(&inode->i_lock);
13031 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13032 + /* need to refresh */
13040 + AuTraceErrPtr(dentry);
13044 +/* ---------------------------------------------------------------------- */
13046 +/* todo: dirty? */
13047 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13049 +struct au_compare_mnt_args {
13051 + struct super_block *sb;
13054 + struct vfsmount *mnt;
13057 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13059 + struct au_compare_mnt_args *a = arg;
13061 + if (mnt->mnt_sb != a->sb)
13063 + a->mnt = mntget(mnt);
13067 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13070 + struct path root;
13071 + struct au_compare_mnt_args args = {
13075 + get_fs_root(current->fs, &root);
13077 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13078 + rcu_read_unlock();
13081 + AuDebugOn(!args.mnt);
13085 +struct au_nfsd_si_lock {
13086 + unsigned int sigen;
13087 + aufs_bindex_t bindex, br_id;
13088 + unsigned char force_lock;
13091 +static int si_nfsd_read_lock(struct super_block *sb,
13092 + struct au_nfsd_si_lock *nsi_lock)
13095 + aufs_bindex_t bindex;
13097 + si_read_lock(sb, AuLock_FLUSH);
13099 + /* branch id may be wrapped around */
13101 + bindex = au_br_index(sb, nsi_lock->br_id);
13102 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13103 + goto out; /* success */
13107 + if (!nsi_lock->force_lock)
13108 + si_read_unlock(sb);
13111 + nsi_lock->bindex = bindex;
13115 +struct find_name_by_ino {
13116 + struct dir_context ctx;
13117 + int called, found;
13124 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13125 + loff_t offset, u64 ino, unsigned int d_type)
13127 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13131 + if (a->ino != ino)
13134 + memcpy(a->name, name, namelen);
13135 + a->namelen = namelen;
13140 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13141 + struct au_nfsd_si_lock *nsi_lock)
13143 + struct dentry *dentry, *parent;
13144 + struct file *file;
13145 + struct inode *dir;
13146 + struct find_name_by_ino arg = {
13148 + .actor = find_name_by_ino
13153 + parent = path->dentry;
13155 + si_read_unlock(parent->d_sb);
13156 + file = vfsub_dentry_open(path, au_dir_roflags);
13157 + dentry = (void *)file;
13158 + if (IS_ERR(file))
13161 + dentry = ERR_PTR(-ENOMEM);
13162 + arg.name = (void *)__get_free_page(GFP_NOFS);
13163 + if (unlikely(!arg.name))
13170 + err = vfsub_iterate_dir(file, &arg.ctx);
13171 + } while (!err && !arg.found && arg.called);
13172 + dentry = ERR_PTR(err);
13173 + if (unlikely(err))
13175 + /* instead of ENOENT */
13176 + dentry = ERR_PTR(-ESTALE);
13180 + /* do not call vfsub_lkup_one() */
13181 + dir = d_inode(parent);
13182 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13183 + AuTraceErrPtr(dentry);
13184 + if (IS_ERR(dentry))
13186 + AuDebugOn(au_test_anon(dentry));
13187 + if (unlikely(d_really_is_negative(dentry))) {
13189 + dentry = ERR_PTR(-ENOENT);
13193 + free_page((unsigned long)arg.name);
13197 + if (unlikely(nsi_lock
13198 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13199 + if (!IS_ERR(dentry)) {
13201 + dentry = ERR_PTR(-ESTALE);
13203 + AuTraceErrPtr(dentry);
13207 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13209 + struct au_nfsd_si_lock *nsi_lock)
13211 + struct dentry *dentry;
13212 + struct path path;
13214 + if (dir_ino != AUFS_ROOT_INO) {
13215 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13216 + dentry = path.dentry;
13217 + if (!path.dentry || IS_ERR(path.dentry))
13219 + AuDebugOn(au_test_anon(path.dentry));
13221 + path.dentry = dget(sb->s_root);
13223 + path.mnt = au_mnt_get(sb);
13224 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13228 + AuTraceErrPtr(dentry);
13232 +/* ---------------------------------------------------------------------- */
13234 +static int h_acceptable(void *expv, struct dentry *dentry)
13239 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13240 + char *buf, int len, struct super_block *sb)
13244 + struct path path;
13246 + p = d_path(h_rootpath, buf, len);
13251 + path.mnt = h_rootpath->mnt;
13252 + path.dentry = h_parent;
13253 + p = d_path(&path, buf, len);
13259 + path.mnt = au_mnt_get(sb);
13260 + path.dentry = sb->s_root;
13261 + p = d_path(&path, buf, len - strlen(p));
13262 + mntput(path.mnt);
13266 + p[strlen(p)] = '/';
13269 + AuTraceErrPtr(p);
13274 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13275 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13277 + struct dentry *dentry, *h_parent, *root;
13278 + struct super_block *h_sb;
13279 + char *pathname, *p;
13280 + struct vfsmount *h_mnt;
13281 + struct au_branch *br;
13283 + struct path path;
13285 + br = au_sbr(sb, nsi_lock->bindex);
13286 + h_mnt = au_br_mnt(br);
13287 + h_sb = h_mnt->mnt_sb;
13288 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13290 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13291 + fh_len - Fh_tail, fh[Fh_h_type],
13292 + h_acceptable, /*context*/NULL);
13294 + dentry = h_parent;
13295 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13296 + AuWarn1("%s decode_fh failed, %ld\n",
13297 + au_sbtype(h_sb), PTR_ERR(h_parent));
13301 + if (unlikely(au_test_anon(h_parent))) {
13302 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13303 + au_sbtype(h_sb));
13304 + goto out_h_parent;
13307 + dentry = ERR_PTR(-ENOMEM);
13308 + pathname = (void *)__get_free_page(GFP_NOFS);
13309 + if (unlikely(!pathname))
13310 + goto out_h_parent;
13312 + root = sb->s_root;
13313 + path.mnt = h_mnt;
13314 + di_read_lock_parent(root, !AuLock_IR);
13315 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13316 + di_read_unlock(root, !AuLock_IR);
13317 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13318 + dentry = (void *)p;
13320 + goto out_pathname;
13322 + si_read_unlock(sb);
13323 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13324 + dentry = ERR_PTR(err);
13325 + if (unlikely(err))
13328 + dentry = ERR_PTR(-ENOENT);
13329 + AuDebugOn(au_test_anon(path.dentry));
13330 + if (unlikely(d_really_is_negative(path.dentry)))
13333 + if (ino != d_inode(path.dentry)->i_ino)
13334 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13336 + dentry = dget(path.dentry);
13341 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13342 + if (!IS_ERR(dentry)) {
13344 + dentry = ERR_PTR(-ESTALE);
13347 + free_page((unsigned long)pathname);
13351 + AuTraceErrPtr(dentry);
13355 +/* ---------------------------------------------------------------------- */
13357 +static struct dentry *
13358 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13361 + struct dentry *dentry;
13362 + __u32 *fh = fid->raw;
13363 + struct au_branch *br;
13364 + ino_t ino, dir_ino;
13365 + struct au_nfsd_si_lock nsi_lock = {
13369 + dentry = ERR_PTR(-ESTALE);
13370 + /* it should never happen, but the file handle is unreliable */
13371 + if (unlikely(fh_len < Fh_tail))
13373 + nsi_lock.sigen = fh[Fh_sigen];
13374 + nsi_lock.br_id = fh[Fh_br_id];
13376 + /* branch id may be wrapped around */
13378 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13380 + nsi_lock.force_lock = 1;
13382 + /* is this inode still cached? */
13383 + ino = decode_ino(fh + Fh_ino);
13384 + /* it should never happen */
13385 + if (unlikely(ino == AUFS_ROOT_INO))
13388 + dir_ino = decode_ino(fh + Fh_dir_ino);
13389 + dentry = decode_by_ino(sb, ino, dir_ino);
13390 + if (IS_ERR(dentry))
13395 + /* is the parent dir cached? */
13396 + br = au_sbr(sb, nsi_lock.bindex);
13397 + au_lcnt_inc(&br->br_nfiles);
13398 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13399 + if (IS_ERR(dentry))
13404 + /* lookup path */
13405 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13406 + if (IS_ERR(dentry))
13408 + if (unlikely(!dentry))
13409 + /* todo?: make it ESTALE */
13413 + if (!au_digen_test(dentry, au_sigen(sb))
13414 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13415 + goto out_unlock; /* success */
13418 + dentry = ERR_PTR(-ESTALE);
13421 + au_lcnt_dec(&br->br_nfiles);
13422 + si_read_unlock(sb);
13424 + AuTraceErrPtr(dentry);
13428 +#if 0 /* reserved for future use */
13429 +/* support subtreecheck option */
13430 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13431 + int fh_len, int fh_type)
13433 + struct dentry *parent;
13434 + __u32 *fh = fid->raw;
13437 + dir_ino = decode_ino(fh + Fh_dir_ino);
13438 + parent = decode_by_ino(sb, dir_ino, 0);
13439 + if (IS_ERR(parent))
13442 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13443 + dir_ino, fh, fh_len);
13446 + AuTraceErrPtr(parent);
13451 +/* ---------------------------------------------------------------------- */
13453 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13454 + struct inode *dir)
13457 + aufs_bindex_t bindex;
13458 + struct super_block *sb, *h_sb;
13459 + struct dentry *dentry, *parent, *h_parent;
13460 + struct inode *h_dir;
13461 + struct au_branch *br;
13464 + if (unlikely(*max_len <= Fh_tail)) {
13465 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13469 + err = FILEID_ROOT;
13470 + if (inode->i_ino == AUFS_ROOT_INO) {
13471 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13476 + sb = inode->i_sb;
13477 + err = si_read_lock(sb, AuLock_FLUSH);
13478 + if (unlikely(err))
13481 +#ifdef CONFIG_AUFS_DEBUG
13482 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13483 + AuWarn1("NFS-exporting requires xino\n");
13487 + ii_read_lock_child(inode);
13488 + bindex = au_ibtop(inode);
13490 + dentry = d_find_any_alias(inode);
13491 + if (unlikely(!dentry))
13493 + AuDebugOn(au_test_anon(dentry));
13494 + parent = dget_parent(dentry);
13496 + if (unlikely(!parent))
13498 + if (d_really_is_positive(parent))
13499 + dir = d_inode(parent);
13502 + ii_read_lock_parent(dir);
13503 + h_dir = au_h_iptr(dir, bindex);
13504 + ii_read_unlock(dir);
13505 + if (unlikely(!h_dir))
13507 + h_parent = d_find_any_alias(h_dir);
13508 + if (unlikely(!h_parent))
13509 + goto out_hparent;
13512 + br = au_sbr(sb, bindex);
13513 + h_sb = au_br_sb(br);
13514 + if (unlikely(!h_sb->s_export_op)) {
13515 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13516 + goto out_hparent;
13519 + fh[Fh_br_id] = br->br_id;
13520 + fh[Fh_sigen] = au_sigen(sb);
13521 + encode_ino(fh + Fh_ino, inode->i_ino);
13522 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13523 + fh[Fh_igen] = inode->i_generation;
13525 + *max_len -= Fh_tail;
13526 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13528 + /*connectable or subtreecheck*/0);
13529 + err = fh[Fh_h_type];
13530 + *max_len += Fh_tail;
13531 + /* todo: macros? */
13532 + if (err != FILEID_INVALID)
13535 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13542 + ii_read_unlock(inode);
13543 + si_read_unlock(sb);
13545 + if (unlikely(err < 0))
13546 + err = FILEID_INVALID;
13550 +/* ---------------------------------------------------------------------- */
13552 +static int aufs_commit_metadata(struct inode *inode)
13555 + aufs_bindex_t bindex;
13556 + struct super_block *sb;
13557 + struct inode *h_inode;
13558 + int (*f)(struct inode *inode);
13560 + sb = inode->i_sb;
13561 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13562 + ii_write_lock_child(inode);
13563 + bindex = au_ibtop(inode);
13564 + AuDebugOn(bindex < 0);
13565 + h_inode = au_h_iptr(inode, bindex);
13567 + f = h_inode->i_sb->s_export_op->commit_metadata;
13569 + err = f(h_inode);
13571 + err = sync_inode_metadata(h_inode, /*wait*/1);
13573 + au_cpup_attr_timesizes(inode);
13574 + ii_write_unlock(inode);
13575 + si_read_unlock(sb);
13579 +/* ---------------------------------------------------------------------- */
13581 +static struct export_operations aufs_export_op = {
13582 + .fh_to_dentry = aufs_fh_to_dentry,
13583 + /* .fh_to_parent = aufs_fh_to_parent, */
13584 + .encode_fh = aufs_encode_fh,
13585 + .commit_metadata = aufs_commit_metadata
13588 +void au_export_init(struct super_block *sb)
13590 + struct au_sbinfo *sbinfo;
13593 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13594 + && IS_MODULE(CONFIG_EXPORTFS),
13595 + AUFS_NAME ": unsupported configuration "
13596 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13598 + sb->s_export_op = &aufs_export_op;
13599 + sbinfo = au_sbi(sb);
13600 + sbinfo->si_xigen = NULL;
13601 + get_random_bytes(&u, sizeof(u));
13602 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13603 + atomic_set(&sbinfo->si_xigen_next, u);
13605 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13606 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13607 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13609 +// SPDX-License-Identifier: GPL-2.0
13611 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13613 + * This program is free software; you can redistribute it and/or modify
13614 + * it under the terms of the GNU General Public License as published by
13615 + * the Free Software Foundation; either version 2 of the License, or
13616 + * (at your option) any later version.
13618 + * This program is distributed in the hope that it will be useful,
13619 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13620 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13621 + * GNU General Public License for more details.
13623 + * You should have received a copy of the GNU General Public License
13624 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13628 + * File-based Hierarchy Storage Management
13631 +#include <linux/anon_inodes.h>
13632 +#include <linux/poll.h>
13633 +#include <linux/seq_file.h>
13634 +#include <linux/statfs.h>
13637 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13639 + struct au_sbinfo *sbinfo;
13640 + struct au_fhsm *fhsm;
13642 + SiMustAnyLock(sb);
13644 + sbinfo = au_sbi(sb);
13645 + fhsm = &sbinfo->si_fhsm;
13646 + AuDebugOn(!fhsm);
13647 + return fhsm->fhsm_bottom;
13650 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13652 + struct au_sbinfo *sbinfo;
13653 + struct au_fhsm *fhsm;
13655 + SiMustWriteLock(sb);
13657 + sbinfo = au_sbi(sb);
13658 + fhsm = &sbinfo->si_fhsm;
13659 + AuDebugOn(!fhsm);
13660 + fhsm->fhsm_bottom = bindex;
13663 +/* ---------------------------------------------------------------------- */
13665 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13667 + struct au_br_fhsm *bf;
13669 + bf = br->br_fhsm;
13670 + MtxMustLock(&bf->bf_lock);
13672 + return !bf->bf_readable
13673 + || time_after(jiffies,
13674 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13677 +/* ---------------------------------------------------------------------- */
13679 +static void au_fhsm_notify(struct super_block *sb, int val)
13681 + struct au_sbinfo *sbinfo;
13682 + struct au_fhsm *fhsm;
13684 + SiMustAnyLock(sb);
13686 + sbinfo = au_sbi(sb);
13687 + fhsm = &sbinfo->si_fhsm;
13688 + if (au_fhsm_pid(fhsm)
13689 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13690 + atomic_set(&fhsm->fhsm_readable, val);
13692 + wake_up(&fhsm->fhsm_wqh);
13696 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13697 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13700 + struct au_branch *br;
13701 + struct au_br_fhsm *bf;
13703 + br = au_sbr(sb, bindex);
13704 + AuDebugOn(au_br_rdonly(br));
13705 + bf = br->br_fhsm;
13709 + mutex_lock(&bf->bf_lock);
13711 + MtxMustLock(&bf->bf_lock);
13713 + /* sb->s_root for NFS is unreliable */
13714 + err = au_br_stfs(br, &bf->bf_stfs);
13715 + if (unlikely(err)) {
13716 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13720 + bf->bf_jiffy = jiffies;
13721 + bf->bf_readable = 1;
13723 + au_fhsm_notify(sb, /*val*/1);
13725 + *rstfs = bf->bf_stfs;
13729 + mutex_unlock(&bf->bf_lock);
13730 + au_fhsm_notify(sb, /*val*/1);
13735 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13738 + struct au_sbinfo *sbinfo;
13739 + struct au_fhsm *fhsm;
13740 + struct au_branch *br;
13741 + struct au_br_fhsm *bf;
13743 + AuDbg("b%d, force %d\n", bindex, force);
13744 + SiMustAnyLock(sb);
13746 + sbinfo = au_sbi(sb);
13747 + fhsm = &sbinfo->si_fhsm;
13748 + if (!au_ftest_si(sbinfo, FHSM)
13749 + || fhsm->fhsm_bottom == bindex)
13752 + br = au_sbr(sb, bindex);
13753 + bf = br->br_fhsm;
13755 + mutex_lock(&bf->bf_lock);
13757 + || au_fhsm_pid(fhsm)
13758 + || au_fhsm_test_jiffy(sbinfo, br))
13759 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13761 + mutex_unlock(&bf->bf_lock);
13764 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13766 + aufs_bindex_t bindex, bbot;
13767 + struct au_branch *br;
13769 + /* exclude the bottom */
13770 + bbot = au_fhsm_bottom(sb);
13771 + for (bindex = 0; bindex < bbot; bindex++) {
13772 + br = au_sbr(sb, bindex);
13773 + if (au_br_fhsm(br->br_perm))
13774 + au_fhsm_wrote(sb, bindex, force);
13778 +/* ---------------------------------------------------------------------- */
13780 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13783 + struct au_sbinfo *sbinfo;
13784 + struct au_fhsm *fhsm;
13787 + sbinfo = file->private_data;
13788 + fhsm = &sbinfo->si_fhsm;
13789 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13790 + if (atomic_read(&fhsm->fhsm_readable))
13791 + mask = EPOLLIN /* | EPOLLRDNORM */;
13794 + AuDbg("mask 0x%x\n", mask);
13798 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13799 + struct aufs_stfs *stfs, __s16 brid)
13803 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13805 + err = __put_user(brid, &stbr->brid);
13806 + if (unlikely(err))
13812 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13813 + struct aufs_stbr __user *stbr, size_t count)
13817 + aufs_bindex_t bindex, bbot;
13818 + struct au_branch *br;
13819 + struct au_br_fhsm *bf;
13821 + /* except the bottom branch */
13824 + bbot = au_fhsm_bottom(sb);
13825 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13826 + br = au_sbr(sb, bindex);
13827 + if (!au_br_fhsm(br->br_perm))
13830 + bf = br->br_fhsm;
13831 + mutex_lock(&bf->bf_lock);
13832 + if (bf->bf_readable) {
13834 + if (count >= sizeof(*stbr))
13835 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13838 + bf->bf_readable = 0;
13839 + count -= sizeof(*stbr);
13843 + mutex_unlock(&bf->bf_lock);
13846 + err = sizeof(*stbr) * nstbr;
13851 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13856 + aufs_bindex_t nfhsm, bindex, bbot;
13857 + struct au_sbinfo *sbinfo;
13858 + struct au_fhsm *fhsm;
13859 + struct au_branch *br;
13860 + struct super_block *sb;
13863 + sbinfo = file->private_data;
13864 + fhsm = &sbinfo->si_fhsm;
13866 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13867 + if (!atomic_read(&fhsm->fhsm_readable)) {
13868 + if (vfsub_file_flags(file) & O_NONBLOCK)
13871 + err = wait_event_interruptible_locked_irq
13873 + atomic_read(&fhsm->fhsm_readable));
13875 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13876 + if (unlikely(err))
13879 + /* sb may already be dead */
13880 + au_rw_read_lock(&sbinfo->si_rwsem);
13881 + readable = atomic_read(&fhsm->fhsm_readable);
13882 + if (readable > 0) {
13883 + sb = sbinfo->si_sb;
13885 + /* exclude the bottom branch */
13887 + bbot = au_fhsm_bottom(sb);
13888 + for (bindex = 0; bindex < bbot; bindex++) {
13889 + br = au_sbr(sb, bindex);
13890 + if (au_br_fhsm(br->br_perm))
13894 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13895 + atomic_set(&fhsm->fhsm_readable, 0);
13896 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13900 + au_rw_read_unlock(&sbinfo->si_rwsem);
13908 +static int au_fhsm_release(struct inode *inode, struct file *file)
13910 + struct au_sbinfo *sbinfo;
13911 + struct au_fhsm *fhsm;
13913 + /* sb may already be dead */
13914 + sbinfo = file->private_data;
13915 + fhsm = &sbinfo->si_fhsm;
13916 + spin_lock(&fhsm->fhsm_spin);
13917 + fhsm->fhsm_pid = 0;
13918 + spin_unlock(&fhsm->fhsm_spin);
13919 + kobject_put(&sbinfo->si_kobj);
13924 +static const struct file_operations au_fhsm_fops = {
13925 + .owner = THIS_MODULE,
13926 + .llseek = noop_llseek,
13927 + .read = au_fhsm_read,
13928 + .poll = au_fhsm_poll,
13929 + .release = au_fhsm_release
13932 +int au_fhsm_fd(struct super_block *sb, int oflags)
13935 + struct au_sbinfo *sbinfo;
13936 + struct au_fhsm *fhsm;
13939 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13943 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13947 + sbinfo = au_sbi(sb);
13948 + fhsm = &sbinfo->si_fhsm;
13949 + spin_lock(&fhsm->fhsm_spin);
13950 + if (!fhsm->fhsm_pid)
13951 + fhsm->fhsm_pid = current->pid;
13954 + spin_unlock(&fhsm->fhsm_spin);
13955 + if (unlikely(err))
13958 + oflags |= O_RDONLY;
13959 + /* oflags |= FMODE_NONOTIFY; */
13960 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13962 + if (unlikely(fd < 0))
13965 + /* succeed regardless 'fhsm' status */
13966 + kobject_get(&sbinfo->si_kobj);
13967 + si_noflush_read_lock(sb);
13968 + if (au_ftest_si(sbinfo, FHSM))
13969 + au_fhsm_wrote_all(sb, /*force*/0);
13970 + si_read_unlock(sb);
13971 + goto out; /* success */
13974 + spin_lock(&fhsm->fhsm_spin);
13975 + fhsm->fhsm_pid = 0;
13976 + spin_unlock(&fhsm->fhsm_spin);
13982 +/* ---------------------------------------------------------------------- */
13984 +int au_fhsm_br_alloc(struct au_branch *br)
13989 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
13991 + au_br_fhsm_init(br->br_fhsm);
13998 +/* ---------------------------------------------------------------------- */
14000 +void au_fhsm_fin(struct super_block *sb)
14002 + au_fhsm_notify(sb, /*val*/-1);
14005 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14007 + struct au_fhsm *fhsm;
14009 + fhsm = &sbinfo->si_fhsm;
14010 + spin_lock_init(&fhsm->fhsm_spin);
14011 + init_waitqueue_head(&fhsm->fhsm_wqh);
14012 + atomic_set(&fhsm->fhsm_readable, 0);
14013 + fhsm->fhsm_expire
14014 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14015 + fhsm->fhsm_bottom = -1;
14018 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14020 + sbinfo->si_fhsm.fhsm_expire
14021 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14024 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14028 + if (!au_ftest_si(sbinfo, FHSM))
14031 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14032 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14033 + seq_printf(seq, ",fhsm_sec=%u", u);
14035 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14036 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14037 +++ linux/fs/aufs/file.c 2022-12-17 09:21:34.799855195 +0100
14039 +// SPDX-License-Identifier: GPL-2.0
14041 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14043 + * This program is free software; you can redistribute it and/or modify
14044 + * it under the terms of the GNU General Public License as published by
14045 + * the Free Software Foundation; either version 2 of the License, or
14046 + * (at your option) any later version.
14048 + * This program is distributed in the hope that it will be useful,
14049 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14050 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14051 + * GNU General Public License for more details.
14053 + * You should have received a copy of the GNU General Public License
14054 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14058 + * handling file/dir, and address_space operation
14061 +#ifdef CONFIG_AUFS_DEBUG
14062 +#include <linux/migrate.h>
14064 +#include <linux/pagemap.h>
14067 +/* drop flags for writing */
14068 +unsigned int au_file_roflags(unsigned int flags)
14070 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14071 + flags |= O_RDONLY | O_NOATIME;
14075 +/* common functions to regular file and dir */
14076 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14077 + struct file *file, int force_wr)
14079 + struct file *h_file;
14080 + struct dentry *h_dentry;
14081 + struct inode *h_inode;
14082 + struct super_block *sb;
14083 + struct au_branch *br;
14084 + struct path h_path;
14087 + /* a race condition can happen between open and unlink/rmdir */
14088 + h_file = ERR_PTR(-ENOENT);
14089 + h_dentry = au_h_dptr(dentry, bindex);
14090 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14092 + h_inode = d_inode(h_dentry);
14093 + spin_lock(&h_dentry->d_lock);
14094 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14095 + /* || !d_inode(dentry)->i_nlink */
14097 + spin_unlock(&h_dentry->d_lock);
14098 + if (unlikely(err))
14101 + sb = dentry->d_sb;
14102 + br = au_sbr(sb, bindex);
14103 + err = au_br_test_oflag(flags, br);
14104 + h_file = ERR_PTR(err);
14105 + if (unlikely(err))
14108 + /* drop flags for writing */
14109 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14110 + if (force_wr && !(flags & O_WRONLY))
14112 + flags = au_file_roflags(flags);
14114 + h_file = ERR_PTR(-EROFS);
14115 + flags = au_file_roflags(flags);
14116 + if (unlikely(vfsub_native_ro(h_inode)
14117 + || IS_APPEND(h_inode)))
14119 + flags &= ~O_ACCMODE;
14120 + flags |= O_WRONLY;
14123 + flags &= ~O_CREAT;
14124 + au_lcnt_inc(&br->br_nfiles);
14125 + h_path.dentry = h_dentry;
14126 + h_path.mnt = au_br_mnt(br);
14127 + h_file = vfsub_dentry_open(&h_path, flags);
14128 + if (IS_ERR(h_file))
14131 + if (flags & __FMODE_EXEC) {
14132 + err = deny_write_access(h_file);
14133 + if (unlikely(err)) {
14135 + h_file = ERR_PTR(err);
14139 + fsnotify_open(h_file);
14140 + goto out; /* success */
14143 + au_lcnt_dec(&br->br_nfiles);
14148 +static int au_cmoo(struct dentry *dentry)
14150 + int err, cmoo, matched;
14151 + unsigned int udba;
14152 + struct path h_path;
14153 + struct au_pin pin;
14154 + struct au_cp_generic cpg = {
14155 + .dentry = dentry,
14160 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14162 + struct inode *delegated;
14163 + struct super_block *sb;
14164 + struct au_sbinfo *sbinfo;
14165 + struct au_fhsm *fhsm;
14167 + struct au_branch *br;
14168 + struct dentry *parent;
14169 + struct au_hinode *hdir;
14171 + DiMustWriteLock(dentry);
14172 + IiMustWriteLock(d_inode(dentry));
14175 + if (IS_ROOT(dentry))
14177 + cpg.bsrc = au_dbtop(dentry);
14181 + sb = dentry->d_sb;
14182 + sbinfo = au_sbi(sb);
14183 + fhsm = &sbinfo->si_fhsm;
14184 + pid = au_fhsm_pid(fhsm);
14187 + && (current->pid == pid
14188 + || rcu_dereference(current->real_parent)->pid == pid));
14189 + rcu_read_unlock();
14193 + br = au_sbr(sb, cpg.bsrc);
14194 + cmoo = au_br_cmoo(br->br_perm);
14197 + if (!d_is_reg(dentry))
14198 + cmoo &= AuBrAttr_COO_ALL;
14202 + parent = dget_parent(dentry);
14203 + di_write_lock_parent(parent);
14204 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14206 + if (unlikely(err < 0)) {
14207 + err = 0; /* there is no upper writable branch */
14210 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14212 + /* do not respect the coo attrib for the target branch */
14213 + err = au_cpup_dirs(dentry, cpg.bdst);
14214 + if (unlikely(err))
14217 + di_downgrade_lock(parent, AuLock_IR);
14218 + udba = au_opt_udba(sb);
14219 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14220 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14221 + if (unlikely(err))
14224 + err = au_sio_cpup_simple(&cpg);
14226 + if (unlikely(err))
14228 + if (!(cmoo & AuBrWAttr_MOO))
14229 + goto out_parent; /* success */
14231 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14232 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14233 + if (unlikely(err))
14236 + h_path.mnt = au_br_mnt(br);
14237 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14238 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14239 + delegated = NULL;
14240 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14242 + /* todo: keep h_dentry or not? */
14243 + if (unlikely(err == -EWOULDBLOCK)) {
14244 + pr_warn("cannot retry for NFSv4 delegation"
14245 + " for an internal unlink\n");
14248 + if (unlikely(err)) {
14249 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14253 + goto out_parent; /* success */
14256 + di_downgrade_lock(parent, AuLock_IR);
14258 + di_read_unlock(parent, AuLock_IR);
14265 +int au_do_open(struct file *file, struct au_do_open_args *args)
14267 + int err, aopen = args->aopen;
14268 + struct dentry *dentry;
14269 + struct au_finfo *finfo;
14272 + err = au_finfo_init(file, args->fidir);
14275 + err = au_finfo_init(file, args->fidir);
14278 + if (unlikely(err))
14281 + dentry = file->f_path.dentry;
14282 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14283 + di_write_lock_child(dentry);
14284 + err = au_cmoo(dentry);
14287 + err = args->open(file, vfsub_file_flags(file),
14288 + au_di(dentry)->di_htmpfile);
14289 + di_write_unlock(dentry);
14291 + di_downgrade_lock(dentry, AuLock_IR);
14293 + err = args->open(file, vfsub_file_flags(file),
14296 + di_read_unlock(dentry, AuLock_IR);
14300 + finfo = au_fi(file);
14302 + finfo->fi_file = file;
14303 + au_hbl_add(&finfo->fi_hlist,
14304 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14307 + fi_write_unlock(file);
14310 + fi_write_unlock(file);
14313 + if (unlikely(err)) {
14314 + finfo->fi_hdir = NULL;
14315 + au_finfo_fin(file);
14323 +int au_reopen_nondir(struct file *file)
14326 + aufs_bindex_t btop;
14327 + struct dentry *dentry;
14328 + struct au_branch *br;
14329 + struct file *h_file, *h_file_tmp;
14331 + dentry = file->f_path.dentry;
14332 + btop = au_dbtop(dentry);
14333 + br = au_sbr(dentry->d_sb, btop);
14334 + h_file_tmp = NULL;
14335 + if (au_fbtop(file) == btop) {
14336 + h_file = au_hf_top(file);
14337 + if (file->f_mode == h_file->f_mode)
14338 + return 0; /* success */
14339 + h_file_tmp = h_file;
14340 + get_file(h_file_tmp);
14341 + au_lcnt_inc(&br->br_nfiles);
14342 + au_set_h_fptr(file, btop, NULL);
14344 + AuDebugOn(au_fi(file)->fi_hdir);
14347 + * file exists on both of rw and ro
14348 + * open --> dbtop and fbtop are both 0
14349 + * prepend a branch as rw, "rw" become ro
14351 + * delete the top branch, "rw" becomes rw again
14352 + * --> dbtop is 1, fbtop is still 0
14353 + * write --> fbtop is 0 but dbtop is 1
14355 + /* AuDebugOn(au_fbtop(file) < btop); */
14357 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14358 + file, /*force_wr*/0);
14359 + err = PTR_ERR(h_file);
14360 + if (IS_ERR(h_file)) {
14361 + if (h_file_tmp) {
14363 + au_set_h_fptr(file, btop, h_file_tmp);
14364 + h_file_tmp = NULL;
14366 + goto out; /* todo: close all? */
14370 + au_set_fbtop(file, btop);
14371 + au_set_h_fptr(file, btop, h_file);
14372 + au_update_figen(file);
14373 + /* todo: necessary? */
14374 + /* file->f_ra = h_file->f_ra; */
14377 + if (h_file_tmp) {
14378 + fput(h_file_tmp);
14379 + au_lcnt_dec(&br->br_nfiles);
14384 +/* ---------------------------------------------------------------------- */
14386 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14387 + struct dentry *hi_wh)
14390 + aufs_bindex_t btop;
14391 + struct au_dinfo *dinfo;
14392 + struct dentry *h_dentry;
14393 + struct au_hdentry *hdp;
14395 + dinfo = au_di(file->f_path.dentry);
14396 + AuRwMustWriteLock(&dinfo->di_rwsem);
14398 + btop = dinfo->di_btop;
14399 + dinfo->di_btop = btgt;
14400 + hdp = au_hdentry(dinfo, btgt);
14401 + h_dentry = hdp->hd_dentry;
14402 + hdp->hd_dentry = hi_wh;
14403 + err = au_reopen_nondir(file);
14404 + hdp->hd_dentry = h_dentry;
14405 + dinfo->di_btop = btop;
14410 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14411 + aufs_bindex_t bcpup, struct au_pin *pin)
14414 + struct inode *inode, *h_inode;
14415 + struct dentry *h_dentry, *hi_wh;
14416 + struct au_cp_generic cpg = {
14417 + .dentry = file->f_path.dentry,
14424 + au_update_dbtop(cpg.dentry);
14425 + inode = d_inode(cpg.dentry);
14427 + if (au_dbtop(cpg.dentry) <= bcpup
14428 + && au_dbbot(cpg.dentry) >= bcpup) {
14429 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14430 + if (h_dentry && d_is_positive(h_dentry))
14431 + h_inode = d_inode(h_dentry);
14433 + hi_wh = au_hi_wh(inode, bcpup);
14434 + if (!hi_wh && !h_inode)
14435 + err = au_sio_cpup_wh(&cpg, file);
14437 + /* already copied-up after unlink */
14438 + err = au_reopen_wh(file, bcpup, hi_wh);
14441 + && (inode->i_nlink > 1
14442 + || (inode->i_state & I_LINKABLE))
14443 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14444 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14450 + * prepare the @file for writing.
14452 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14455 + aufs_bindex_t dbtop;
14456 + struct dentry *parent;
14457 + struct inode *inode;
14458 + struct super_block *sb;
14459 + struct file *h_file;
14460 + struct au_cp_generic cpg = {
14461 + .dentry = file->f_path.dentry,
14466 + .flags = AuCpup_DTIME
14469 + sb = cpg.dentry->d_sb;
14470 + inode = d_inode(cpg.dentry);
14471 + cpg.bsrc = au_fbtop(file);
14472 + err = au_test_ro(sb, cpg.bsrc, inode);
14473 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14474 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14479 + /* need to cpup or reopen */
14480 + parent = dget_parent(cpg.dentry);
14481 + di_write_lock_parent(parent);
14482 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14484 + if (unlikely(err < 0))
14488 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14489 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14490 + if (unlikely(err))
14494 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14495 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14496 + if (unlikely(err))
14499 + dbtop = au_dbtop(cpg.dentry);
14500 + if (dbtop <= cpg.bdst)
14501 + cpg.bsrc = cpg.bdst;
14503 + if (dbtop <= cpg.bdst /* just reopen */
14504 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14506 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14507 + if (IS_ERR(h_file))
14508 + err = PTR_ERR(h_file);
14510 + di_downgrade_lock(parent, AuLock_IR);
14511 + if (dbtop > cpg.bdst)
14512 + err = au_sio_cpup_simple(&cpg);
14514 + err = au_reopen_nondir(file);
14515 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14517 + } else { /* copyup as wh and reopen */
14519 + * since writable hfsplus branch is not supported,
14520 + * h_open_pre/post() are unnecessary.
14522 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14523 + di_downgrade_lock(parent, AuLock_IR);
14527 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14528 + goto out_dput; /* success */
14534 + di_downgrade_lock(parent, AuLock_IR);
14536 + di_read_unlock(parent, AuLock_IR);
14543 +/* ---------------------------------------------------------------------- */
14545 +int au_do_flush(struct file *file, fl_owner_t id,
14546 + int (*flush)(struct file *file, fl_owner_t id))
14549 + struct super_block *sb;
14550 + struct inode *inode;
14552 + inode = file_inode(file);
14553 + sb = inode->i_sb;
14554 + si_noflush_read_lock(sb);
14555 + fi_read_lock(file);
14556 + ii_read_lock_child(inode);
14558 + err = flush(file, id);
14559 + au_cpup_attr_timesizes(inode);
14561 + ii_read_unlock(inode);
14562 + fi_read_unlock(file);
14563 + si_read_unlock(sb);
14567 +/* ---------------------------------------------------------------------- */
14569 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14572 + struct au_pin pin;
14573 + struct au_finfo *finfo;
14574 + struct dentry *parent, *hi_wh;
14575 + struct inode *inode;
14576 + struct super_block *sb;
14577 + struct au_cp_generic cpg = {
14578 + .dentry = file->f_path.dentry,
14583 + .flags = AuCpup_DTIME
14586 + FiMustWriteLock(file);
14589 + finfo = au_fi(file);
14590 + sb = cpg.dentry->d_sb;
14591 + inode = d_inode(cpg.dentry);
14592 + cpg.bdst = au_ibtop(inode);
14593 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14596 + parent = dget_parent(cpg.dentry);
14597 + if (au_test_ro(sb, cpg.bdst, inode)) {
14598 + di_read_lock_parent(parent, !AuLock_IR);
14599 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14601 + di_read_unlock(parent, !AuLock_IR);
14602 + if (unlikely(err < 0))
14607 + di_read_lock_parent(parent, AuLock_IR);
14608 + hi_wh = au_hi_wh(inode, cpg.bdst);
14609 + if (!S_ISDIR(inode->i_mode)
14610 + && au_opt_test(au_mntflags(sb), PLINK)
14611 + && au_plink_test(inode)
14612 + && !d_unhashed(cpg.dentry)
14613 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14614 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14615 + if (unlikely(err))
14618 + /* always superio. */
14619 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14620 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14622 + err = au_sio_cpup_simple(&cpg);
14625 + } else if (hi_wh) {
14626 + /* already copied-up after unlink */
14627 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14628 + *need_reopen = 0;
14632 + di_read_unlock(parent, AuLock_IR);
14639 +static void au_do_refresh_dir(struct file *file)
14641 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14642 + struct au_hfile *p, tmp, *q;
14643 + struct au_finfo *finfo;
14644 + struct super_block *sb;
14645 + struct au_fidir *fidir;
14647 + FiMustWriteLock(file);
14649 + sb = file->f_path.dentry->d_sb;
14650 + finfo = au_fi(file);
14651 + fidir = finfo->fi_hdir;
14652 + AuDebugOn(!fidir);
14653 + p = fidir->fd_hfile + finfo->fi_btop;
14654 + brid = p->hf_br->br_id;
14655 + bbot = fidir->fd_bbot;
14656 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14660 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14661 + if (new_bindex == bindex)
14663 + if (new_bindex < 0) {
14664 + au_set_h_fptr(file, bindex, NULL);
14668 + /* swap two lower inode, and loop again */
14669 + q = fidir->fd_hfile + new_bindex;
14673 + if (tmp.hf_file) {
14679 + p = fidir->fd_hfile;
14680 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14681 + bbot = au_sbbot(sb);
14682 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14683 + finfo->fi_btop++, p++)
14684 + if (p->hf_file) {
14685 + if (file_inode(p->hf_file))
14687 + au_hfput(p, /*execed*/0);
14690 + bbot = au_br_index(sb, brid);
14691 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14692 + finfo->fi_btop++, p++)
14694 + au_hfput(p, /*execed*/0);
14695 + bbot = au_sbbot(sb);
14698 + p = fidir->fd_hfile + bbot;
14699 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14700 + fidir->fd_bbot--, p--)
14701 + if (p->hf_file) {
14702 + if (file_inode(p->hf_file))
14704 + au_hfput(p, /*execed*/0);
14706 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14710 + * after branch manipulating, refresh the file.
14712 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14714 + int err, need_reopen, nbr;
14715 + aufs_bindex_t bbot, bindex;
14716 + struct dentry *dentry;
14717 + struct super_block *sb;
14718 + struct au_finfo *finfo;
14719 + struct au_hfile *hfile;
14721 + dentry = file->f_path.dentry;
14722 + sb = dentry->d_sb;
14723 + nbr = au_sbbot(sb) + 1;
14724 + finfo = au_fi(file);
14725 + if (!finfo->fi_hdir) {
14726 + hfile = &finfo->fi_htop;
14727 + AuDebugOn(!hfile->hf_file);
14728 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14729 + AuDebugOn(bindex < 0);
14730 + if (bindex != finfo->fi_btop)
14731 + au_set_fbtop(file, bindex);
14733 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14734 + if (unlikely(err))
14736 + au_do_refresh_dir(file);
14741 + if (!au_test_mmapped(file))
14742 + err = au_file_refresh_by_inode(file, &need_reopen);
14743 + if (finfo->fi_hdir)
14744 + /* harmless if err */
14745 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14746 + if (!err && need_reopen && !d_unlinked(dentry))
14747 + err = reopen(file);
14749 + au_update_figen(file);
14750 + goto out; /* success */
14753 + /* error, close all lower files */
14754 + if (finfo->fi_hdir) {
14755 + bbot = au_fbbot_dir(file);
14756 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14757 + au_set_h_fptr(file, bindex, NULL);
14764 +/* common function to regular file and dir */
14765 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14766 + int wlock, unsigned int fi_lsc)
14769 + unsigned int sigen, figen;
14770 + aufs_bindex_t btop;
14771 + unsigned char pseudo_link;
14772 + struct dentry *dentry;
14773 + struct inode *inode;
14776 + dentry = file->f_path.dentry;
14777 + inode = d_inode(dentry);
14778 + sigen = au_sigen(dentry->d_sb);
14779 + fi_write_lock_nested(file, fi_lsc);
14780 + figen = au_figen(file);
14782 + di_write_lock_child(dentry);
14784 + di_write_lock_child2(dentry);
14785 + btop = au_dbtop(dentry);
14786 + pseudo_link = (btop != au_ibtop(inode));
14787 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14789 + di_downgrade_lock(dentry, AuLock_IR);
14790 + fi_downgrade_lock(file);
14792 + goto out; /* success */
14795 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14796 + if (au_digen_test(dentry, sigen)) {
14797 + err = au_reval_dpath(dentry, sigen);
14798 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14802 + err = refresh_file(file, reopen);
14805 + di_downgrade_lock(dentry, AuLock_IR);
14806 + fi_downgrade_lock(file);
14809 + di_write_unlock(dentry);
14810 + fi_write_unlock(file);
14817 +/* ---------------------------------------------------------------------- */
14819 +/* cf. aufs_nopage() */
14820 +/* for madvise(2) */
14821 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14823 + folio_unlock(folio);
14827 +/* it will never be called, but necessary to support O_DIRECT */
14828 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14829 +{ BUG(); return 0; }
14831 +/* they will never be called. */
14832 +#ifdef CONFIG_AUFS_DEBUG
14833 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14834 + loff_t pos, unsigned len,
14835 + struct page **pagep, void **fsdata)
14836 +{ AuUnsupport(); return 0; }
14837 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14838 + loff_t pos, unsigned len, unsigned copied,
14839 + struct page *page, void *fsdata)
14840 +{ AuUnsupport(); return 0; }
14841 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14842 +{ AuUnsupport(); return 0; }
14844 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14845 +{ AuUnsupport(); return true; }
14846 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14847 +{ AuUnsupport(); }
14848 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14849 +{ AuUnsupport(); return true; }
14850 +#if 0 /* called by memory compaction regardless file */
14851 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14852 + struct folio *src, enum migrate_mode mode)
14853 +{ AuUnsupport(); return 0; }
14855 +static int aufs_launder_folio(struct folio *folio)
14856 +{ AuUnsupport(); return 0; }
14857 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14859 +{ AuUnsupport(); return true; }
14860 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14862 +{ AuUnsupport(); }
14863 +static int aufs_error_remove_page(struct address_space *mapping,
14864 + struct page *page)
14865 +{ AuUnsupport(); return 0; }
14866 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14868 +{ AuUnsupport(); return 0; }
14869 +static void aufs_swap_deactivate(struct file *file)
14870 +{ AuUnsupport(); }
14871 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14872 +{ AuUnsupport(); return 0; }
14873 +#endif /* CONFIG_AUFS_DEBUG */
14875 +const struct address_space_operations aufs_aop = {
14876 + .read_folio = aufs_read_folio,
14877 + .direct_IO = aufs_direct_IO,
14878 +#ifdef CONFIG_AUFS_DEBUG
14879 + .writepage = aufs_writepage,
14880 + /* no writepages, because of writepage */
14881 + .dirty_folio = aufs_dirty_folio,
14882 + /* no readpages, because of readpage */
14883 + .write_begin = aufs_write_begin,
14884 + .write_end = aufs_write_end,
14885 + /* no bmap, no block device */
14886 + .invalidate_folio = aufs_invalidate_folio,
14887 + .release_folio = aufs_release_folio,
14888 + /* is fallback_migrate_page ok? */
14889 + /* .migrate_folio = aufs_migrate_folio, */
14890 + .launder_folio = aufs_launder_folio,
14891 + .is_partially_uptodate = aufs_is_partially_uptodate,
14892 + .is_dirty_writeback = aufs_is_dirty_writeback,
14893 + .error_remove_page = aufs_error_remove_page,
14894 + .swap_activate = aufs_swap_activate,
14895 + .swap_deactivate = aufs_swap_deactivate,
14896 + .swap_rw = aufs_swap_rw
14897 +#endif /* CONFIG_AUFS_DEBUG */
14899 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14900 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14901 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14903 +/* SPDX-License-Identifier: GPL-2.0 */
14905 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14907 + * This program is free software; you can redistribute it and/or modify
14908 + * it under the terms of the GNU General Public License as published by
14909 + * the Free Software Foundation; either version 2 of the License, or
14910 + * (at your option) any later version.
14912 + * This program is distributed in the hope that it will be useful,
14913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14915 + * GNU General Public License for more details.
14917 + * You should have received a copy of the GNU General Public License
14918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14922 + * file operations
14925 +#ifndef __AUFS_FILE_H__
14926 +#define __AUFS_FILE_H__
14930 +#include <linux/file.h>
14931 +#include <linux/fs.h>
14932 +#include <linux/mm_types.h>
14933 +#include <linux/poll.h>
14934 +#include "rwsem.h"
14938 + struct file *hf_file;
14939 + struct au_branch *hf_br;
14944 + aufs_bindex_t fd_bbot;
14945 + aufs_bindex_t fd_nent;
14946 + struct au_vdir *fd_vdir_cache;
14947 + struct au_hfile fd_hfile[];
14950 +static inline int au_fidir_sz(int nent)
14952 + AuDebugOn(nent < 0);
14953 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14957 + atomic_t fi_generation;
14959 + struct au_rwsem fi_rwsem;
14960 + aufs_bindex_t fi_btop;
14962 + /* do not union them */
14963 + struct { /* for non-dir */
14964 + struct au_hfile fi_htop;
14965 + atomic_t fi_mmapped;
14967 + struct au_fidir *fi_hdir; /* for dir only */
14969 + struct hlist_bl_node fi_hlist;
14970 + struct file *fi_file; /* very ugly */
14971 + struct rcu_head rcu;
14972 +} ____cacheline_aligned_in_smp;
14974 +/* ---------------------------------------------------------------------- */
14977 +extern const struct address_space_operations aufs_aop;
14978 +unsigned int au_file_roflags(unsigned int flags);
14979 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14980 + struct file *file, int force_wr);
14981 +struct au_do_open_args {
14983 + int (*open)(struct file *file, int flags,
14984 + struct file *h_file);
14985 + struct au_fidir *fidir;
14986 + struct file *h_file;
14988 +int au_do_open(struct file *file, struct au_do_open_args *args);
14989 +int au_reopen_nondir(struct file *file);
14991 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
14992 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14993 + int wlock, unsigned int fi_lsc);
14994 +int au_do_flush(struct file *file, fl_owner_t id,
14995 + int (*flush)(struct file *file, fl_owner_t id));
14998 +#ifdef CONFIG_AUFS_POLL
14999 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15002 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15004 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15006 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15007 + struct file *h_file);
15009 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15010 + aufs_bindex_t bindex, int force_wr)
15011 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15012 + struct file *h_file);
15016 +extern const struct file_operations aufs_file_fop;
15017 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15018 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15019 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15022 +void au_hfput(struct au_hfile *hf, int execed);
15023 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15024 + struct file *h_file);
15026 +void au_update_figen(struct file *file);
15027 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15028 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15030 +void au_fi_init_once(void *_fi);
15031 +void au_finfo_fin(struct file *file);
15032 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15035 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15036 +#ifdef CONFIG_COMPAT
15037 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15038 + unsigned long arg);
15039 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15040 + unsigned long arg);
15043 +/* ---------------------------------------------------------------------- */
15045 +static inline struct au_finfo *au_fi(struct file *file)
15047 + return file->private_data;
15050 +/* ---------------------------------------------------------------------- */
15052 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15053 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15054 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15055 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15057 +#define fi_read_trylock_nested(f) \
15058 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15059 +#define fi_write_trylock_nested(f) \
15060 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15063 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15064 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15065 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15067 +/* lock subclass for finfo */
15073 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15075 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15078 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15080 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15084 + * fi_read_lock_1, fi_write_lock_1,
15085 + * fi_read_lock_2, fi_write_lock_2
15087 +#define AuReadLockFunc(name) \
15088 +static inline void fi_read_lock_##name(struct file *f) \
15089 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15091 +#define AuWriteLockFunc(name) \
15092 +static inline void fi_write_lock_##name(struct file *f) \
15093 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15095 +#define AuRWLockFuncs(name) \
15096 + AuReadLockFunc(name) \
15097 + AuWriteLockFunc(name)
15102 +#undef AuReadLockFunc
15103 +#undef AuWriteLockFunc
15104 +#undef AuRWLockFuncs
15106 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15107 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15108 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15110 +/* ---------------------------------------------------------------------- */
15112 +/* todo: hard/soft set? */
15113 +static inline aufs_bindex_t au_fbtop(struct file *file)
15115 + FiMustAnyLock(file);
15116 + return au_fi(file)->fi_btop;
15119 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15121 + FiMustAnyLock(file);
15122 + AuDebugOn(!au_fi(file)->fi_hdir);
15123 + return au_fi(file)->fi_hdir->fd_bbot;
15126 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15128 + FiMustAnyLock(file);
15129 + AuDebugOn(!au_fi(file)->fi_hdir);
15130 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15133 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15135 + FiMustWriteLock(file);
15136 + au_fi(file)->fi_btop = bindex;
15139 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15141 + FiMustWriteLock(file);
15142 + AuDebugOn(!au_fi(file)->fi_hdir);
15143 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15146 +static inline void au_set_fvdir_cache(struct file *file,
15147 + struct au_vdir *vdir_cache)
15149 + FiMustWriteLock(file);
15150 + AuDebugOn(!au_fi(file)->fi_hdir);
15151 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15154 +static inline struct file *au_hf_top(struct file *file)
15156 + FiMustAnyLock(file);
15157 + AuDebugOn(au_fi(file)->fi_hdir);
15158 + return au_fi(file)->fi_htop.hf_file;
15161 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15163 + FiMustAnyLock(file);
15164 + AuDebugOn(!au_fi(file)->fi_hdir);
15165 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15168 +/* todo: memory barrier? */
15169 +static inline unsigned int au_figen(struct file *f)
15171 + return atomic_read(&au_fi(f)->fi_generation);
15174 +static inline void au_set_mmapped(struct file *f)
15176 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15178 + pr_warn("fi_mmapped wrapped around\n");
15179 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15183 +static inline void au_unset_mmapped(struct file *f)
15185 + atomic_dec(&au_fi(f)->fi_mmapped);
15188 +static inline int au_test_mmapped(struct file *f)
15190 + return atomic_read(&au_fi(f)->fi_mmapped);
15193 +/* customize vma->vm_file */
15195 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15196 + struct file *file)
15200 + f = vma->vm_file;
15202 + vma->vm_file = file;
15207 +#define AuDbgVmRegion(file, vma) do {} while (0)
15209 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15210 + struct file *file)
15212 + au_do_vm_file_reset(vma, file);
15215 +#define AuDbgVmRegion(file, vma) \
15216 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15218 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15219 + struct file *file)
15223 + au_do_vm_file_reset(vma, file);
15224 + f = vma->vm_region->vm_file;
15226 + vma->vm_region->vm_file = file;
15229 +#endif /* CONFIG_MMU */
15231 +/* handle vma->vm_prfile */
15232 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15233 + struct file *file)
15236 + vma->vm_prfile = file;
15237 +#ifndef CONFIG_MMU
15239 + vma->vm_region->vm_prfile = file;
15243 +#endif /* __KERNEL__ */
15244 +#endif /* __AUFS_FILE_H__ */
15245 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15246 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15247 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15249 +// SPDX-License-Identifier: GPL-2.0
15251 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15253 + * This program is free software; you can redistribute it and/or modify
15254 + * it under the terms of the GNU General Public License as published by
15255 + * the Free Software Foundation; either version 2 of the License, or
15256 + * (at your option) any later version.
15258 + * This program is distributed in the hope that it will be useful,
15259 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15260 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15261 + * GNU General Public License for more details.
15263 + * You should have received a copy of the GNU General Public License
15264 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15268 + * file private data
15273 +void au_hfput(struct au_hfile *hf, int execed)
15276 + allow_write_access(hf->hf_file);
15277 + fput(hf->hf_file);
15278 + hf->hf_file = NULL;
15279 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15280 + hf->hf_br = NULL;
15283 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15285 + struct au_finfo *finfo = au_fi(file);
15286 + struct au_hfile *hf;
15287 + struct au_fidir *fidir;
15289 + fidir = finfo->fi_hdir;
15291 + AuDebugOn(finfo->fi_btop != bindex);
15292 + hf = &finfo->fi_htop;
15294 + hf = fidir->fd_hfile + bindex;
15296 + if (hf && hf->hf_file)
15297 + au_hfput(hf, vfsub_file_execed(file));
15299 + FiMustWriteLock(file);
15300 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15301 + hf->hf_file = val;
15302 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15306 +void au_update_figen(struct file *file)
15308 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15309 + /* smp_mb(); */ /* atomic_set */
15312 +/* ---------------------------------------------------------------------- */
15314 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15316 + struct au_fidir *fidir;
15319 + nbr = au_sbbot(sb) + 1;
15321 + nbr = 2; /* initial allocate for 2 branches */
15322 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15324 + fidir->fd_bbot = -1;
15325 + fidir->fd_nent = nbr;
15331 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15334 + struct au_fidir *fidir, *p;
15336 + AuRwMustWriteLock(&finfo->fi_rwsem);
15337 + fidir = finfo->fi_hdir;
15338 + AuDebugOn(!fidir);
15341 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15342 + GFP_NOFS, may_shrink);
15344 + p->fd_nent = nbr;
15345 + finfo->fi_hdir = p;
15352 +/* ---------------------------------------------------------------------- */
15354 +void au_finfo_fin(struct file *file)
15356 + struct au_finfo *finfo;
15358 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15360 + finfo = au_fi(file);
15361 + AuDebugOn(finfo->fi_hdir);
15362 + AuRwDestroy(&finfo->fi_rwsem);
15363 + au_cache_free_finfo(finfo);
15366 +void au_fi_init_once(void *_finfo)
15368 + struct au_finfo *finfo = _finfo;
15370 + au_rw_init(&finfo->fi_rwsem);
15373 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15376 + struct au_finfo *finfo;
15377 + struct dentry *dentry;
15380 + dentry = file->f_path.dentry;
15381 + finfo = au_cache_alloc_finfo();
15382 + if (unlikely(!finfo))
15386 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15387 + au_rw_write_lock(&finfo->fi_rwsem);
15388 + finfo->fi_btop = -1;
15389 + finfo->fi_hdir = fidir;
15390 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15391 + /* smp_mb(); */ /* atomic_set */
15393 + file->private_data = finfo;
15398 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15399 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15400 +++ linux/fs/aufs/f_op.c 2023-02-20 21:05:51.959693785 +0100
15402 +// SPDX-License-Identifier: GPL-2.0
15404 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15406 + * This program is free software; you can redistribute it and/or modify
15407 + * it under the terms of the GNU General Public License as published by
15408 + * the Free Software Foundation; either version 2 of the License, or
15409 + * (at your option) any later version.
15411 + * This program is distributed in the hope that it will be useful,
15412 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15413 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15414 + * GNU General Public License for more details.
15416 + * You should have received a copy of the GNU General Public License
15417 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15421 + * file and vm operations
15424 +#include <linux/aio.h>
15425 +#include <linux/fs_stack.h>
15426 +#include <linux/mman.h>
15427 +#include <linux/security.h>
15430 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15433 + aufs_bindex_t bindex;
15434 + struct dentry *dentry, *h_dentry;
15435 + struct au_finfo *finfo;
15436 + struct inode *h_inode;
15438 + FiMustWriteLock(file);
15441 + dentry = file->f_path.dentry;
15442 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15443 + finfo = au_fi(file);
15444 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15445 + atomic_set(&finfo->fi_mmapped, 0);
15446 + bindex = au_dbtop(dentry);
15448 + h_dentry = au_h_dptr(dentry, bindex);
15449 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15450 + if (unlikely(err))
15452 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15453 + if (IS_ERR(h_file)) {
15454 + err = PTR_ERR(h_file);
15458 + h_dentry = h_file->f_path.dentry;
15459 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15460 + if (unlikely(err))
15462 + /* br ref is already inc-ed */
15465 + if (flags & __O_TMPFILE) {
15466 + AuDebugOn(!h_file);
15467 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15468 + au_di(dentry)->di_htmpfile = NULL;
15470 + if (!(flags & O_EXCL)) {
15471 + h_inode = file_inode(h_file);
15472 + spin_lock(&h_inode->i_lock);
15473 + h_inode->i_state |= I_LINKABLE;
15474 + spin_unlock(&h_inode->i_lock);
15477 + au_set_fbtop(file, bindex);
15478 + au_set_h_fptr(file, bindex, h_file);
15479 + au_update_figen(file);
15480 + /* todo: necessary? */
15481 + /* file->f_ra = h_file->f_ra; */
15487 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15488 + struct file *file)
15491 + struct super_block *sb;
15492 + struct au_do_open_args args = {
15493 + .open = au_do_open_nondir
15496 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15497 + file, vfsub_file_flags(file), file->f_mode);
15499 + sb = file->f_path.dentry->d_sb;
15500 + si_read_lock(sb, AuLock_FLUSH);
15501 + err = au_do_open(file, &args);
15502 + si_read_unlock(sb);
15506 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15508 + struct au_finfo *finfo;
15509 + aufs_bindex_t bindex;
15511 + finfo = au_fi(file);
15512 + au_hbl_del(&finfo->fi_hlist,
15513 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15514 + bindex = finfo->fi_btop;
15516 + au_set_h_fptr(file, bindex, NULL);
15518 + au_finfo_fin(file);
15522 +/* ---------------------------------------------------------------------- */
15524 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15527 + struct file *h_file;
15530 + h_file = au_hf_top(file);
15532 + err = vfsub_flush(h_file, id);
15536 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15538 + return au_do_flush(file, id, au_do_flush_nondir);
15541 +/* ---------------------------------------------------------------------- */
15543 + * read and write functions acquire [fdi]_rwsem once, but release before
15544 + * mmap_sem. This is because to stop a race condition between mmap(2).
15545 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15546 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15547 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15550 +/* Callers should call au_read_post() or fput() in the end */
15551 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15553 + struct file *h_file;
15556 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15558 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15559 + h_file = au_hf_top(file);
15560 + get_file(h_file);
15562 + fi_read_unlock(file);
15564 + h_file = ERR_PTR(err);
15569 +static void au_read_post(struct inode *inode, struct file *h_file)
15571 + /* update without lock, I don't think it a problem */
15572 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15576 +struct au_write_pre {
15578 + unsigned int lsc;
15582 + aufs_bindex_t btop;
15586 + * return with iinfo is write-locked
15587 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15590 +static struct file *au_write_pre(struct file *file, int do_ready,
15591 + struct au_write_pre *wpre)
15593 + struct file *h_file;
15594 + struct dentry *dentry;
15596 + unsigned int lsc;
15597 + struct au_pin pin;
15602 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15603 + h_file = ERR_PTR(err);
15604 + if (unlikely(err))
15607 + dentry = file->f_path.dentry;
15609 + err = au_ready_to_write(file, -1, &pin);
15610 + if (unlikely(err)) {
15611 + h_file = ERR_PTR(err);
15612 + di_write_unlock(dentry);
15617 + di_downgrade_lock(dentry, /*flags*/0);
15619 + wpre->btop = au_fbtop(file);
15620 + h_file = au_hf_top(file);
15621 + get_file(h_file);
15623 + wpre->blks = file_inode(h_file)->i_blocks;
15626 + di_read_unlock(dentry, /*flags*/0);
15629 + fi_write_unlock(file);
15634 +static void au_write_post(struct inode *inode, struct file *h_file,
15635 + struct au_write_pre *wpre, ssize_t written)
15637 + struct inode *h_inode;
15639 + au_cpup_attr_timesizes(inode);
15640 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15641 + h_inode = file_inode(h_file);
15642 + inode->i_mode = h_inode->i_mode;
15643 + ii_write_unlock(inode);
15644 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15646 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15647 + /*force*/h_inode->i_blocks > wpre->blks);
15652 + * todo: very ugly
15653 + * it locks both of i_mutex and si_rwsem for read in safe.
15654 + * if the plink maintenance mode continues forever (that is the problem),
15655 + * may loop forever.
15657 +static void au_mtx_and_read_lock(struct inode *inode)
15660 + struct super_block *sb = inode->i_sb;
15663 + inode_lock(inode);
15664 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15667 + inode_unlock(inode);
15668 + si_read_lock(sb, AuLock_NOPLMW);
15669 + si_read_unlock(sb);
15673 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15674 + struct iov_iter *iov_iter)
15677 + struct file *file;
15678 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15680 + err = security_file_permission(h_file, rw);
15681 + if (unlikely(err))
15684 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15686 + if (rw == MAY_READ)
15687 + iter = h_file->f_op->read_iter;
15688 + else if (rw == MAY_WRITE)
15689 + iter = h_file->f_op->write_iter;
15691 + file = kio->ki_filp;
15692 + kio->ki_filp = h_file;
15695 + err = iter(kio, iov_iter);
15698 + /* currently there is no such fs */
15700 + kio->ki_filp = file;
15706 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15709 + struct file *file, *h_file;
15710 + struct inode *inode;
15711 + struct super_block *sb;
15713 + file = kio->ki_filp;
15714 + inode = file_inode(file);
15715 + sb = inode->i_sb;
15716 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15718 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15719 + err = PTR_ERR(h_file);
15720 + if (IS_ERR(h_file))
15723 + if (au_test_loopback_kthread()) {
15724 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15725 + if (file->f_mapping != h_file->f_mapping) {
15726 + file->f_mapping = h_file->f_mapping;
15727 + smp_mb(); /* unnecessary? */
15730 + fi_read_unlock(file);
15732 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15733 + /* todo: necessary? */
15734 + /* file->f_ra = h_file->f_ra; */
15735 + au_read_post(inode, h_file);
15738 + si_read_unlock(sb);
15742 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15745 + struct au_write_pre wpre;
15746 + struct inode *inode;
15747 + struct file *file, *h_file;
15749 + file = kio->ki_filp;
15750 + inode = file_inode(file);
15751 + au_mtx_and_read_lock(inode);
15754 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15755 + err = PTR_ERR(h_file);
15756 + if (IS_ERR(h_file))
15759 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15760 + au_write_post(inode, h_file, &wpre, err);
15763 + si_read_unlock(inode->i_sb);
15764 + inode_unlock(inode);
15769 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15770 + * don't have their own .splice_{read,write} implimentations, and they use
15771 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15772 + * simple converters to f_op->iter_read() and ->iter_write().
15773 + * But we keep our own implementations because some non-mainlined FSes may have
15774 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15775 + * away an opportunity to co-work with aufs from them.
15777 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15778 + struct pipe_inode_info *pipe, size_t len,
15779 + unsigned int flags)
15782 + struct file *h_file;
15783 + struct inode *inode;
15784 + struct super_block *sb;
15786 + inode = file_inode(file);
15787 + sb = inode->i_sb;
15788 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15790 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15791 + err = PTR_ERR(h_file);
15792 + if (IS_ERR(h_file))
15795 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15796 + /* todo: necessary? */
15797 + /* file->f_ra = h_file->f_ra; */
15798 + au_read_post(inode, h_file);
15801 + si_read_unlock(sb);
15806 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15807 + size_t len, unsigned int flags)
15810 + struct au_write_pre wpre;
15811 + struct inode *inode;
15812 + struct file *h_file;
15814 + inode = file_inode(file);
15815 + au_mtx_and_read_lock(inode);
15818 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15819 + err = PTR_ERR(h_file);
15820 + if (IS_ERR(h_file))
15823 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15824 + au_write_post(inode, h_file, &wpre, err);
15827 + si_read_unlock(inode->i_sb);
15828 + inode_unlock(inode);
15832 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15836 + struct au_write_pre wpre;
15837 + struct inode *inode;
15838 + struct file *h_file;
15840 + inode = file_inode(file);
15841 + au_mtx_and_read_lock(inode);
15844 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15845 + err = PTR_ERR(h_file);
15846 + if (IS_ERR(h_file))
15850 + err = vfs_fallocate(h_file, mode, offset, len);
15853 + * we don't need to call file_modifed() here since au_write_post()
15854 + * is equivalent and copies-up all timestamps and permission bits.
15856 + au_write_post(inode, h_file, &wpre, /*written*/1);
15859 + si_read_unlock(inode->i_sb);
15860 + inode_unlock(inode);
15864 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15865 + struct file *dst, loff_t dst_pos,
15866 + size_t len, unsigned int flags)
15869 + struct au_write_pre wpre;
15870 + enum { SRC, DST };
15872 + struct inode *inode;
15873 + struct file *h_file;
15874 + struct super_block *h_sb;
15876 +#define a_src a[SRC]
15877 +#define a_dst a[DST]
15880 + a_src.inode = file_inode(src);
15881 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15883 + a_dst.inode = file_inode(dst);
15884 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15887 + au_mtx_and_read_lock(a_dst.inode);
15889 + * in order to match the order in di_write_lock2_{child,parent}(),
15890 + * use f_path.dentry for this comparison.
15892 + if (src->f_path.dentry < dst->f_path.dentry) {
15893 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15894 + err = PTR_ERR(a_src.h_file);
15895 + if (IS_ERR(a_src.h_file))
15898 + wpre.lsc = AuLsc_FI_2;
15899 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15900 + err = PTR_ERR(a_dst.h_file);
15901 + if (IS_ERR(a_dst.h_file)) {
15902 + au_read_post(a_src.inode, a_src.h_file);
15906 + wpre.lsc = AuLsc_FI_1;
15907 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15908 + err = PTR_ERR(a_dst.h_file);
15909 + if (IS_ERR(a_dst.h_file))
15912 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15913 + err = PTR_ERR(a_src.h_file);
15914 + if (IS_ERR(a_src.h_file)) {
15915 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15922 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15923 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15924 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15930 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15931 + dst_pos, len, flags);
15934 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15935 + fi_read_unlock(src);
15936 + au_read_post(a_src.inode, a_src.h_file);
15938 + si_read_unlock(a_dst.inode->i_sb);
15939 + inode_unlock(a_dst.inode);
15946 +/* ---------------------------------------------------------------------- */
15949 + * The locking order around current->mmap_sem.
15950 + * - in most and regular cases
15951 + * file I/O syscall -- aufs_read() or something
15952 + * -- si_rwsem for read -- mmap_sem
15953 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15955 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15956 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15957 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15958 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15959 + * It means that when aufs acquires si_rwsem for write, the process should never
15960 + * acquire mmap_sem.
15962 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15963 + * problem either since any directory is not able to be mmap-ed.
15964 + * The similar scenario is applied to aufs_readlink() too.
15967 +#if 0 /* stop calling security_file_mmap() */
15968 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15969 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15971 +static unsigned long au_arch_prot_conv(unsigned long flags)
15973 + /* currently ppc64 only */
15974 +#ifdef CONFIG_PPC64
15975 + /* cf. linux/arch/powerpc/include/asm/mman.h */
15976 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
15977 + return AuConv_VM_PROT(flags, SAO);
15979 + AuDebugOn(arch_calc_vm_prot_bits(-1));
15984 +static unsigned long au_prot_conv(unsigned long flags)
15986 + return AuConv_VM_PROT(flags, READ)
15987 + | AuConv_VM_PROT(flags, WRITE)
15988 + | AuConv_VM_PROT(flags, EXEC)
15989 + | au_arch_prot_conv(flags);
15992 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
15993 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
15995 +static unsigned long au_flag_conv(unsigned long flags)
15997 + return AuConv_VM_MAP(flags, GROWSDOWN)
15998 + | AuConv_VM_MAP(flags, DENYWRITE)
15999 + | AuConv_VM_MAP(flags, LOCKED);
16003 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16006 + const unsigned char wlock
16007 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16008 + struct super_block *sb;
16009 + struct file *h_file;
16010 + struct inode *inode;
16012 + AuDbgVmRegion(file, vma);
16014 + inode = file_inode(file);
16015 + sb = inode->i_sb;
16017 + si_read_lock(sb, AuLock_NOPLMW);
16019 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16021 + err = PTR_ERR(h_file);
16022 + if (IS_ERR(h_file))
16026 + au_set_mmapped(file);
16027 + au_vm_file_reset(vma, h_file);
16029 + * we cannot call security_mmap_file() here since it may acquire
16030 + * mmap_sem or i_mutex.
16032 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16033 + * au_flag_conv(vma->vm_flags));
16036 + err = call_mmap(h_file, vma);
16038 + au_vm_prfile_set(vma, file);
16039 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16040 + goto out_fput; /* success */
16042 + au_unset_mmapped(file);
16043 + au_vm_file_reset(vma, file);
16047 + ii_write_unlock(inode);
16052 + si_read_unlock(sb);
16058 +/* ---------------------------------------------------------------------- */
16060 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16064 + struct au_write_pre wpre;
16065 + struct inode *inode;
16066 + struct file *h_file;
16068 + err = 0; /* -EBADF; */ /* posix? */
16069 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16072 + inode = file_inode(file);
16073 + au_mtx_and_read_lock(inode);
16076 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16077 + err = PTR_ERR(h_file);
16078 + if (IS_ERR(h_file))
16081 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16082 + au_write_post(inode, h_file, &wpre, /*written*/0);
16085 + si_read_unlock(inode->i_sb);
16086 + inode_unlock(inode);
16091 +static int aufs_fasync(int fd, struct file *file, int flag)
16094 + struct file *h_file;
16095 + struct super_block *sb;
16097 + sb = file->f_path.dentry->d_sb;
16098 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16100 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16101 + err = PTR_ERR(h_file);
16102 + if (IS_ERR(h_file))
16105 + if (h_file->f_op->fasync)
16106 + err = h_file->f_op->fasync(fd, h_file, flag);
16107 + fput(h_file); /* instead of au_read_post() */
16110 + si_read_unlock(sb);
16114 +static int aufs_setfl(struct file *file, unsigned long arg)
16117 + struct file *h_file;
16118 + struct super_block *sb;
16120 + sb = file->f_path.dentry->d_sb;
16121 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16123 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16124 + err = PTR_ERR(h_file);
16125 + if (IS_ERR(h_file))
16128 + /* stop calling h_file->fasync */
16129 + arg |= vfsub_file_flags(file) & FASYNC;
16130 + err = setfl(/*unused fd*/-1, h_file, arg);
16131 + fput(h_file); /* instead of au_read_post() */
16134 + si_read_unlock(sb);
16138 +/* ---------------------------------------------------------------------- */
16140 +/* no one supports this operation, currently */
16141 +#if 0 /* reserved for future use */
16142 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16143 + size_t len, loff_t *pos, int more)
16148 +/* ---------------------------------------------------------------------- */
16150 +const struct file_operations aufs_file_fop = {
16151 + .owner = THIS_MODULE,
16153 + .llseek = default_llseek,
16155 + .read_iter = aufs_read_iter,
16156 + .write_iter = aufs_write_iter,
16158 +#ifdef CONFIG_AUFS_POLL
16159 + .poll = aufs_poll,
16161 + .unlocked_ioctl = aufs_ioctl_nondir,
16162 +#ifdef CONFIG_COMPAT
16163 + .compat_ioctl = aufs_compat_ioctl_nondir,
16165 + .mmap = aufs_mmap,
16166 + .open = aufs_open_nondir,
16167 + .flush = aufs_flush_nondir,
16168 + .release = aufs_release_nondir,
16169 + .fsync = aufs_fsync_nondir,
16170 + .fasync = aufs_fasync,
16171 + /* .sendpage = aufs_sendpage, */
16172 + .setfl = aufs_setfl,
16173 + .splice_write = aufs_splice_write,
16174 + .splice_read = aufs_splice_read,
16175 +#if 0 /* reserved for future use */
16176 + .aio_splice_write = aufs_aio_splice_write,
16177 + .aio_splice_read = aufs_aio_splice_read,
16179 + .fallocate = aufs_fallocate,
16180 + .copy_file_range = aufs_copy_file_range
16182 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16183 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16184 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16186 +// SPDX-License-Identifier: GPL-2.0
16188 + * Copyright (C) 2022 Junjiro R. Okajima
16190 + * This program is free software; you can redistribute it and/or modify
16191 + * it under the terms of the GNU General Public License as published by
16192 + * the Free Software Foundation; either version 2 of the License, or
16193 + * (at your option) any later version.
16195 + * This program is distributed in the hope that it will be useful,
16196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16198 + * GNU General Public License for more details.
16200 + * You should have received a copy of the GNU General Public License
16201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16205 + * fs context, aka new mount api
16208 +#include <linux/fs_context.h>
16211 +struct au_fsctx_opts {
16212 + aufs_bindex_t bindex;
16213 + unsigned char skipped;
16214 + struct au_opt *opt, *opt_tail;
16215 + struct super_block *sb;
16216 + struct au_sbinfo *sbinfo;
16217 + struct au_opts opts;
16220 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16221 +static int cvt_err(int err)
16235 +static int au_fsctx_reconfigure(struct fs_context *fc)
16238 + unsigned int mntflags;
16239 + struct dentry *root;
16240 + struct super_block *sb;
16241 + struct inode *inode;
16242 + struct au_fsctx_opts *a = fc->fs_private;
16244 + AuDbg("fc %p\n", fc);
16248 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16250 + di_write_lock_child(root);
16251 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16252 + aufs_write_unlock(root);
16255 + inode = d_inode(root);
16256 + inode_lock(inode);
16257 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16258 + if (unlikely(err))
16260 + di_write_lock_child(root);
16262 + /* au_opts_remount() may return an error */
16263 + err = au_opts_remount(sb, &a->opts);
16265 + if (au_ftest_opts(a->opts.flags, REFRESH))
16266 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16269 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16270 + mntflags = au_mntflags(sb);
16271 + do_dx = !!au_opt_test(mntflags, DIO);
16272 + au_dy_arefresh(do_dx);
16275 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16276 + aufs_write_unlock(root);
16279 + inode_unlock(inode);
16280 + err = cvt_err(err);
16286 +/* ---------------------------------------------------------------------- */
16288 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16291 + struct au_fsctx_opts *a = fc->fs_private;
16292 + struct au_sbinfo *sbinfo = a->sbinfo;
16293 + struct dentry *root;
16294 + struct inode *inode;
16296 + sbinfo->si_sb = sb;
16297 + sb->s_fs_info = sbinfo;
16298 + kobject_get(&sbinfo->si_kobj);
16300 + __si_write_lock(sb);
16302 + au_sbilist_add(sb);
16304 + /* all timestamps always follow the ones on the branch */
16305 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16306 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16307 + sb->s_op = &aufs_sop;
16308 + sb->s_d_op = &aufs_dop;
16309 + sb->s_magic = AUFS_SUPER_MAGIC;
16310 + sb->s_maxbytes = 0;
16311 + sb->s_stack_depth = 1;
16312 + au_export_init(sb);
16313 + au_xattr_init(sb);
16315 + err = au_alloc_root(sb);
16316 + if (unlikely(err)) {
16317 + si_write_unlock(sb);
16320 + root = sb->s_root;
16321 + inode = d_inode(root);
16322 + ii_write_lock_parent(inode);
16323 + aufs_write_unlock(root);
16325 + /* lock vfs_inode first, then aufs. */
16326 + inode_lock(inode);
16327 + aufs_write_lock(root);
16328 + err = au_opts_mount(sb, &a->opts);
16330 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16331 + sb->s_d_op = &aufs_dop_noreval;
16332 + /* infofc(fc, "%ps", sb->s_d_op); */
16333 + pr_info("%ps\n", sb->s_d_op);
16334 + au_refresh_dop(root, /*force_reval*/0);
16335 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16336 + au_refresh_iop(inode, /*force_getattr*/0);
16338 + aufs_write_unlock(root);
16339 + inode_unlock(inode);
16341 + goto out; /* success */
16344 + sb->s_root = NULL;
16347 + if (unlikely(err))
16348 + kobject_put(&sbinfo->si_kobj);
16350 + err = cvt_err(err);
16355 +static int au_fsctx_get_tree(struct fs_context *fc)
16359 + AuDbg("fc %p\n", fc);
16360 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16366 +/* ---------------------------------------------------------------------- */
16368 +static void au_fsctx_dump(struct au_opts *opts)
16370 +#ifdef CONFIG_AUFS_DEBUG
16371 + /* reduce stack space */
16373 + struct au_opt_add *add;
16374 + struct au_opt_del *del;
16375 + struct au_opt_mod *mod;
16376 + struct au_opt_xino *xino;
16377 + struct au_opt_xino_itrunc *xino_itrunc;
16378 + struct au_opt_wbr_create *create;
16380 + struct au_opt *opt;
16383 + while (opt->type != Opt_tail) {
16384 + switch (opt->type) {
16386 + u.add = &opt->add;
16387 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16388 + u.add->bindex, u.add->pathname, u.add->perm,
16389 + u.add->path.dentry);
16394 + u.del = &opt->del;
16395 + AuDbg("del {%s, %p}\n",
16396 + u.del->pathname, u.del->h_path.dentry);
16401 + u.mod = &opt->mod;
16402 + AuDbg("mod {%s, 0x%x, %p}\n",
16403 + u.mod->path, u.mod->perm, u.mod->h_root);
16406 + u.add = &opt->add;
16407 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16408 + u.add->bindex, u.add->pathname, u.add->perm,
16409 + u.add->path.dentry);
16411 + case Opt_prepend:
16412 + u.add = &opt->add;
16413 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16414 + u.add->bindex, u.add->pathname, u.add->perm,
16415 + u.add->path.dentry);
16419 + AuDbg("dirwh %d\n", opt->dirwh);
16421 + case Opt_rdcache:
16422 + AuDbg("rdcache %d\n", opt->rdcache);
16425 + AuDbg("rdblk %d\n", opt->rdblk);
16428 + AuDbg("rdhash %u\n", opt->rdhash);
16432 + u.xino = &opt->xino;
16433 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16436 +#define au_fsctx_TF(name) \
16437 + case Opt_##name: \
16441 + AuLabel(no##name); \
16444 + /* simple true/false flag */
16445 + au_fsctx_TF(trunc_xino);
16446 + au_fsctx_TF(trunc_xib);
16447 + au_fsctx_TF(dirperm1);
16448 + au_fsctx_TF(plink);
16449 + au_fsctx_TF(shwh);
16450 + au_fsctx_TF(dio);
16451 + au_fsctx_TF(warn_perm);
16452 + au_fsctx_TF(verbose);
16453 + au_fsctx_TF(sum);
16454 + au_fsctx_TF(dirren);
16455 + au_fsctx_TF(acl);
16456 +#undef au_fsctx_TF
16458 + case Opt_trunc_xino_path:
16460 + case Opt_itrunc_xino:
16461 + u.xino_itrunc = &opt->xino_itrunc;
16462 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16468 + case Opt_list_plink:
16469 + AuLabel(list_plink);
16472 + AuDbg("udba %d, %s\n",
16473 + opt->udba, au_optstr_udba(opt->udba));
16475 + case Opt_diropq_a:
16476 + AuLabel(diropq_a);
16478 + case Opt_diropq_w:
16479 + AuLabel(diropq_w);
16484 + case Opt_wbr_create:
16485 + u.create = &opt->wbr_create;
16486 + AuDbg("create %d, %s\n", u.create->wbr_create,
16487 + au_optstr_wbr_create(u.create->wbr_create));
16488 + switch (u.create->wbr_create) {
16489 + case AuWbrCreate_MFSV:
16491 + case AuWbrCreate_PMFSV:
16492 + AuDbg("%d sec\n", u.create->mfs_second);
16494 + case AuWbrCreate_MFSRR:
16496 + case AuWbrCreate_TDMFS:
16497 + AuDbg("%llu watermark\n",
16498 + u.create->mfsrr_watermark);
16500 + case AuWbrCreate_MFSRRV:
16502 + case AuWbrCreate_TDMFSV:
16504 + case AuWbrCreate_PMFSRRV:
16505 + AuDbg("%llu watermark, %d sec\n",
16506 + u.create->mfsrr_watermark,
16507 + u.create->mfs_second);
16511 + case Opt_wbr_copyup:
16512 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16513 + au_optstr_wbr_copyup(opt->wbr_copyup));
16515 + case Opt_fhsm_sec:
16516 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16520 + AuDbg("type %d\n", opt->type);
16528 +/* ---------------------------------------------------------------------- */
16531 + * For conditionally compiled mount options.
16532 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16534 +#define au_ignore_flag(name, action) \
16535 + fsparam_flag(name, action), \
16536 + fsparam_flag("no" name, Opt_ignore_silent)
16538 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16539 + fsparam_string("br", Opt_br),
16541 + /* "add=%d:%s" or "ins=%d:%s" */
16542 + fsparam_string("add", Opt_add),
16543 + fsparam_string("ins", Opt_add),
16544 + fsparam_path("append", Opt_append),
16545 + fsparam_path("prepend", Opt_prepend),
16547 + fsparam_path("del", Opt_del),
16548 + /* fsparam_s32("idel", Opt_idel), */
16549 + fsparam_path("mod", Opt_mod),
16550 + /* fsparam_string("imod", Opt_imod), */
16552 + fsparam_s32("dirwh", Opt_dirwh),
16554 + fsparam_path("xino", Opt_xino),
16555 + fsparam_flag("noxino", Opt_noxino),
16556 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16557 + /* "trunc_xino_v=%d:%d" */
16558 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16559 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16560 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16561 + /* fsparam_path("zxino", Opt_zxino), */
16562 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16564 +#ifdef CONFIG_PROC_FS
16565 + fsparam_flag_no("plink", Opt_plink),
16567 + au_ignore_flag("plink", Opt_ignore),
16570 +#ifdef CONFIG_AUFS_DEBUG
16571 + fsparam_flag("list_plink", Opt_list_plink),
16574 + fsparam_string("udba", Opt_udba),
16576 + fsparam_flag_no("dio", Opt_dio),
16578 +#ifdef CONFIG_AUFS_DIRREN
16579 + fsparam_flag_no("dirren", Opt_dirren),
16581 + au_ignore_flag("dirren", Opt_ignore),
16584 +#ifdef CONFIG_AUFS_FHSM
16585 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16587 + fsparam_s32("fhsm_sec", Opt_ignore),
16590 + /* always | a | whiteouted | w */
16591 + fsparam_string("diropq", Opt_diropq),
16593 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16595 +#ifdef CONFIG_AUFS_SHWH
16596 + fsparam_flag_no("shwh", Opt_shwh),
16598 + au_ignore_flag("shwh", Opt_err),
16601 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16603 + fsparam_flag_no("verbose", Opt_verbose),
16604 + fsparam_flag("v", Opt_verbose),
16605 + fsparam_flag("quiet", Opt_noverbose),
16606 + fsparam_flag("q", Opt_noverbose),
16607 + /* user-space may handle this */
16608 + fsparam_flag("silent", Opt_noverbose),
16610 + fsparam_flag_no("sum", Opt_sum),
16611 + fsparam_flag("wsum", Opt_wsum),
16613 + fsparam_s32("rdcache", Opt_rdcache),
16614 + /* "def" or s32 */
16615 + fsparam_string("rdblk", Opt_rdblk),
16616 + /* "def" or s32 */
16617 + fsparam_string("rdhash", Opt_rdhash),
16619 + fsparam_string("create", Opt_wbr_create),
16620 + fsparam_string("create_policy", Opt_wbr_create),
16621 + fsparam_string("cpup", Opt_wbr_copyup),
16622 + fsparam_string("copyup", Opt_wbr_copyup),
16623 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16625 + /* generic VFS flag */
16626 +#ifdef CONFIG_FS_POSIX_ACL
16627 + fsparam_flag_no("acl", Opt_acl),
16629 + au_ignore_flag("acl", Opt_ignore),
16632 + /* internal use for the scripts */
16633 + fsparam_string("si", Opt_ignore_silent),
16635 + /* obsoleted, keep them temporary */
16636 + fsparam_flag("nodlgt", Opt_ignore_silent),
16637 + fsparam_flag("clean_plink", Opt_ignore),
16638 + fsparam_string("dirs", Opt_br),
16639 + fsparam_u32("debug", Opt_ignore),
16640 + /* "whiteout" or "all" */
16641 + fsparam_string("delete", Opt_ignore),
16642 + fsparam_string("imap", Opt_ignore),
16644 + /* temporary workaround, due to old mount(8)? */
16645 + fsparam_flag("relatime", Opt_ignore_silent),
16650 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16651 + char *brspec, size_t speclen,
16652 + aufs_bindex_t bindex)
16657 + AuDbg("brspec %s\n", brspec);
16661 + speclen = strlen(brspec);
16662 + /* will be freed by au_fsctx_free() */
16663 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16664 + if (unlikely(!p)) {
16665 + errorfc(fc, "failed in %s", brspec);
16668 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16675 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16679 + struct au_fsctx_opts *a = fc->fs_private;
16680 + struct au_opt *opt = a->opt;
16681 + aufs_bindex_t bindex = a->bindex;
16683 + AuDbg("brspec %s\n", brspec);
16686 + while ((p = strsep(&brspec, ":")) && *p) {
16687 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16689 + if (unlikely(err))
16693 + if (unlikely(opt > a->opt_tail)) {
16699 + opt->type = Opt_tail;
16702 + a->bindex = bindex;
16709 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16713 + struct au_fsctx_opts *a = fc->fs_private;
16714 + struct au_opt *opt = a->opt;
16717 + p = strchr(addspec, ':');
16718 + if (unlikely(!p)) {
16719 + errorfc(fc, "bad arg in %s", addspec);
16723 + err = kstrtoint(addspec, 0, &n);
16724 + if (unlikely(err)) {
16725 + errorfc(fc, "bad integer in %s", addspec);
16728 + AuDbg("n %d\n", n);
16729 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16736 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16737 + struct fs_parameter *param)
16742 + /* will be freed by au_fsctx_free() */
16743 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16744 + if (unlikely(!del->pathname))
16746 + AuDbg("del %s\n", del->pathname);
16747 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16748 + if (unlikely(err))
16749 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16756 +#if 0 /* reserved for future use */
16757 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16758 + aufs_bindex_t bindex)
16761 + struct super_block *sb;
16762 + struct dentry *root;
16763 + struct au_fsctx_opts *a = fc->fs_private;
16769 + root = sb->s_root;
16770 + aufs_read_lock(root, AuLock_FLUSH);
16771 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16772 + errorfc(fc, "out of bounds, %d", bindex);
16777 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16778 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16781 + aufs_read_unlock(root, !AuLock_IR);
16787 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16788 + struct fs_parameter *param)
16791 + struct path path;
16795 + /* will be freed by au_fsctx_free() */
16796 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16797 + if (unlikely(!mod->path))
16801 + p = strchr(mod->path, '=');
16802 + if (unlikely(!p)) {
16803 + errorfc(fc, "no permission %s", mod->path);
16808 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16809 + if (unlikely(err)) {
16810 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16814 + mod->perm = au_br_perm_val(p);
16815 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16816 + mod->h_root = dget(path.dentry);
16824 +#if 0 /* reserved for future use */
16825 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16830 + struct super_block *sb;
16831 + struct dentry *root;
16832 + struct au_fsctx_opts *a = fc->fs_private;
16838 + p = strchr(ibrspec, ':');
16839 + if (unlikely(!p)) {
16840 + errorfc(fc, "no index, %s", ibrspec);
16844 + err = kstrtoint(ibrspec, 0, &n);
16845 + if (unlikely(err)) {
16846 + errorfc(fc, "bad integer in %s", ibrspec);
16849 + AuDbg("n %d\n", n);
16851 + root = sb->s_root;
16852 + aufs_read_lock(root, AuLock_FLUSH);
16853 + if (n < 0 || au_sbbot(sb) < n) {
16854 + errorfc(fc, "out of bounds, %d", bindex);
16859 + mod->perm = au_br_perm_val(p);
16860 + AuDbg("mod path %s, perm 0x%x, %s\n",
16861 + mod->path, mod->perm, p);
16862 + mod->h_root = dget(au_h_dptr(root, bindex));
16865 + aufs_read_unlock(root, !AuLock_IR);
16872 +static int au_fsctx_parse_xino(struct fs_context *fc,
16873 + struct au_opt_xino *xino,
16874 + struct fs_parameter *param)
16877 + struct au_fsctx_opts *a = fc->fs_private;
16880 + /* will be freed by au_opts_free() */
16881 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16882 + if (unlikely(!xino->path))
16884 + AuDbg("path %s\n", xino->path);
16886 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16888 + err = PTR_ERR(xino->file);
16889 + if (IS_ERR(xino->file)) {
16890 + xino->file = NULL;
16895 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16897 + errorfc(fc, "%s must be outside", xino->path);
16906 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16907 + struct au_opt_xino_itrunc *xino_itrunc,
16911 + aufs_bindex_t bbot, bindex;
16912 + struct path path;
16913 + struct dentry *root;
16914 + struct au_fsctx_opts *a = fc->fs_private;
16916 + AuDebugOn(!a->sb);
16918 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16919 + if (unlikely(err)) {
16920 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16924 + xino_itrunc->bindex = -1;
16925 + root = a->sb->s_root;
16926 + aufs_read_lock(root, AuLock_FLUSH);
16927 + bbot = au_sbbot(a->sb);
16928 + for (bindex = 0; bindex <= bbot; bindex++) {
16929 + if (au_h_dptr(root, bindex) == path.dentry) {
16930 + xino_itrunc->bindex = bindex;
16934 + aufs_read_unlock(root, !AuLock_IR);
16937 + if (unlikely(xino_itrunc->bindex < 0)) {
16939 + errorfc(fc, "no such branch %s", pathname);
16947 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16948 + struct au_opt_xino_itrunc *xino_itrunc,
16949 + unsigned int bindex)
16952 + aufs_bindex_t bbot;
16953 + struct super_block *sb;
16954 + struct au_fsctx_opts *a = fc->fs_private;
16960 + si_noflush_read_lock(sb);
16961 + bbot = au_sbbot(sb);
16962 + si_read_unlock(sb);
16963 + if (bindex <= bbot)
16964 + xino_itrunc->bindex = bindex;
16967 + errorfc(fc, "out of bounds, %u", bindex);
16974 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
16977 + struct fs_parse_result result;
16978 + struct au_fsctx_opts *a = fc->fs_private;
16979 + struct au_opt *opt = a->opt;
16981 + AuDbg("fc %p, param {key %s, string %s}\n",
16982 + fc, param->key, param->string);
16983 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
16984 + if (unlikely(err < 0))
16987 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
16988 + token, result.negated, result.uint_64);
16994 + err = au_fsctx_parse_br(fc, param->string);
16997 + err = au_fsctx_parse_add(fc, param->string);
17000 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17001 + /*dummy bindex*/1);
17003 + case Opt_prepend:
17004 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17009 + err = au_fsctx_parse_del(fc, &opt->del, param);
17011 +#if 0 /* reserved for future use */
17018 + del->pathname = "(indexed)";
17019 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17024 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17026 +#ifdef IMOD /* reserved for future use */
17033 + u.mod->path = "(indexed)";
17034 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17039 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17041 + case Opt_trunc_xino_path:
17043 + errorfc(fc, "no such branch %s", param->string);
17046 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17050 + case Opt_trunc_xino_v:
17056 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17060 + case Opt_itrunc_xino:
17062 + errorfc(fc, "out of bounds %s", param->string);
17065 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17071 + opt->dirwh = result.int_32;
17074 + case Opt_rdcache:
17075 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17076 + errorfc(fc, "rdcache must be smaller than %d",
17077 + AUFS_RDCACHE_MAX);
17081 + opt->rdcache = result.int_32;
17086 + opt->rdblk = AUFS_RDBLK_DEF;
17087 + if (!strcmp(param->string, "def"))
17090 + err = kstrtoint(param->string, 0, &result.int_32);
17091 + if (unlikely(err)) {
17092 + errorfc(fc, "bad value in %s", param->key);
17096 + if (unlikely(result.int_32 < 0
17097 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17098 + errorfc(fc, "bad value in %s", param->key);
17101 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17102 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17106 + opt->rdblk = result.int_32;
17111 + opt->rdhash = AUFS_RDHASH_DEF;
17112 + if (!strcmp(param->string, "def"))
17115 + err = kstrtoint(param->string, 0, &result.int_32);
17116 + if (unlikely(err)) {
17117 + errorfc(fc, "bad value in %s", param->key);
17120 + /* how about zero? */
17121 + if (result.int_32 < 0
17122 + || result.int_32 * sizeof(struct hlist_head)
17123 + > KMALLOC_MAX_SIZE) {
17125 + errorfc(fc, "bad integer in %s", param->key);
17128 + opt->rdhash = result.int_32;
17133 + * As other options, fs/aufs/opts.c can handle these strings by
17134 + * match_token(). But "diropq=" is deprecated now and will
17135 + * never have other value. So simple strcmp() is enough here.
17137 + if (!strcmp(param->string, "a") ||
17138 + !strcmp(param->string, "always")) {
17140 + opt->type = Opt_diropq_a;
17141 + } else if (!strcmp(param->string, "w") ||
17142 + !strcmp(param->string, "whiteouted")) {
17144 + opt->type = Opt_diropq_w;
17146 + errorfc(fc, "unknown value %s", param->string);
17150 + opt->udba = au_udba_val(param->string);
17151 + if (opt->udba >= 0)
17154 + errorf(fc, "wrong value, %s", param->string);
17157 + case Opt_wbr_create:
17158 + opt->wbr_create.wbr_create
17159 + = au_wbr_create_val(param->string, &opt->wbr_create);
17160 + if (opt->wbr_create.wbr_create >= 0)
17163 + errorf(fc, "wrong value, %s", param->key);
17166 + case Opt_wbr_copyup:
17167 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17168 + if (opt->wbr_copyup >= 0)
17171 + errorfc(fc, "wrong value, %s", param->key);
17174 + case Opt_fhsm_sec:
17175 + if (unlikely(result.int_32 < 0)) {
17176 + errorfc(fc, "bad integer in %s\n", param->key);
17181 + opt->fhsm_second = result.int_32;
17183 + warnfc(fc, "ignored %s %s", param->key, param->string);
17186 + /* simple true/false flag */
17187 +#define au_fsctx_TF(name) \
17188 + case Opt_##name: \
17190 + opt->tf = !result.negated; \
17192 + au_fsctx_TF(trunc_xino);
17193 + au_fsctx_TF(trunc_xib);
17194 + au_fsctx_TF(dirperm1);
17195 + au_fsctx_TF(plink);
17196 + au_fsctx_TF(shwh);
17197 + au_fsctx_TF(dio);
17198 + au_fsctx_TF(warn_perm);
17199 + au_fsctx_TF(verbose);
17200 + au_fsctx_TF(sum);
17201 + au_fsctx_TF(dirren);
17202 + au_fsctx_TF(acl);
17203 +#undef au_fsctx_TF
17205 + case Opt_noverbose:
17207 + opt->type = Opt_verbose;
17213 + case Opt_list_plink:
17220 + warnfc(fc, "ignored %s", param->key);
17222 + case Opt_ignore_silent:
17231 + if (unlikely(err))
17239 + case Opt_noverbose:
17244 + opt->type = token;
17248 + if (unlikely(opt > a->opt_tail)) {
17252 + opt->type = Opt_tail;
17260 + * these options accept both 'name=val' and 'name:val' form.
17261 + * some accept optional '=' in its value.
17262 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17264 +static inline unsigned int is_colonopt(char *str)
17266 +#define do_test(name) \
17267 + if (!strncmp(str, name ":", sizeof(name))) \
17268 + return sizeof(name) - 1
17272 + do_test("append");
17273 + do_test("prepend");
17275 + /* do_test("idel"); */
17277 + /* do_test("imod"); */
17283 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17288 + struct au_fsctx_opts *a = fc->fs_private;
17291 + AuDbg("str %s\n", str);
17293 + u = is_colonopt(str);
17296 + str = strchr(str, ',');
17302 + AuDbg("str %s\n", str);
17304 + err = generic_parse_monolithic(fc, str);
17306 + au_fsctx_dump(&a->opts);
17311 +/* ---------------------------------------------------------------------- */
17313 +static void au_fsctx_opts_free(struct au_opts *opts)
17315 + struct au_opt *opt;
17318 + while (opt->type != Opt_tail) {
17319 + switch (opt->type) {
17324 + case Opt_prepend:
17325 + kfree(opt->add.pathname);
17326 + path_put(&opt->add.path);
17329 + kfree(opt->del.pathname);
17332 + path_put(&opt->del.h_path);
17335 + kfree(opt->mod.path);
17338 + dput(opt->mod.h_root);
17341 + kfree(opt->xino.path);
17342 + fput(opt->xino.file);
17349 +static void au_fsctx_free(struct fs_context *fc)
17351 + struct au_fsctx_opts *a = fc->fs_private;
17353 + /* fs_type=%p, root=%pD */
17354 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17355 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17357 + kobject_put(&a->sbinfo->si_kobj);
17358 + au_fsctx_opts_free(&a->opts);
17359 + free_page((unsigned long)a->opts.opt);
17363 +static const struct fs_context_operations au_fsctx_ops = {
17364 + .free = au_fsctx_free,
17365 + .parse_param = au_fsctx_parse_param,
17366 + .parse_monolithic = au_fsctx_parse_monolithic,
17367 + .get_tree = au_fsctx_get_tree,
17368 + .reconfigure = au_fsctx_reconfigure
17370 + * nfs4 requires ->dup()? No.
17371 + * I don't know what is this ->dup() for.
17375 +int aufs_fsctx_init(struct fs_context *fc)
17378 + struct au_fsctx_opts *a;
17380 + /* fs_type=%p, root=%pD */
17381 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17382 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17384 + /* they will be freed by au_fsctx_free() */
17386 + a = kzalloc(sizeof(*a), GFP_NOFS);
17387 + if (unlikely(!a))
17390 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17391 + if (unlikely(!a->opts.opt))
17393 + a->opt = a->opts.opt;
17394 + a->opt->type = Opt_tail;
17395 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17396 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17397 + a->opts.sb_flags = fc->sb_flags;
17401 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17402 + a->opts.flags = AuOpts_REMOUNT;
17403 + a->sb = fc->root->d_sb;
17404 + a->sbinfo = au_sbi(a->sb);
17405 + kobject_get(&a->sbinfo->si_kobj);
17407 + a->sbinfo = au_si_alloc(a->sb);
17408 + AuDebugOn(!a->sbinfo);
17409 + err = PTR_ERR(a->sbinfo);
17410 + if (IS_ERR(a->sbinfo))
17412 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17416 + fc->fs_private = a;
17417 + fc->ops = &au_fsctx_ops;
17418 + goto out; /* success */
17421 + free_page((unsigned long)a->opts.opt);
17428 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17429 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17430 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17432 +/* SPDX-License-Identifier: GPL-2.0 */
17434 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17436 + * This program is free software; you can redistribute it and/or modify
17437 + * it under the terms of the GNU General Public License as published by
17438 + * the Free Software Foundation; either version 2 of the License, or
17439 + * (at your option) any later version.
17441 + * This program is distributed in the hope that it will be useful,
17442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17444 + * GNU General Public License for more details.
17446 + * You should have received a copy of the GNU General Public License
17447 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17451 + * judging filesystem type
17454 +#ifndef __AUFS_FSTYPE_H__
17455 +#define __AUFS_FSTYPE_H__
17459 +#include <linux/fs.h>
17460 +#include <linux/magic.h>
17461 +#include <linux/nfs_fs.h>
17462 +#include <linux/romfs_fs.h>
17464 +static inline int au_test_aufs(struct super_block *sb)
17466 + return sb->s_magic == AUFS_SUPER_MAGIC;
17469 +static inline const char *au_sbtype(struct super_block *sb)
17471 + return sb->s_type->name;
17474 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17476 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17477 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17483 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17485 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17486 + return sb->s_magic == ROMFS_MAGIC;
17492 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17494 +#if IS_ENABLED(CONFIG_CRAMFS)
17495 + return sb->s_magic == CRAMFS_MAGIC;
17500 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17502 +#if IS_ENABLED(CONFIG_NFS_FS)
17503 + return sb->s_magic == NFS_SUPER_MAGIC;
17509 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17511 +#if IS_ENABLED(CONFIG_FUSE_FS)
17512 + return sb->s_magic == FUSE_SUPER_MAGIC;
17518 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17520 +#if IS_ENABLED(CONFIG_XFS_FS)
17521 + return sb->s_magic == XFS_SB_MAGIC;
17527 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17529 +#ifdef CONFIG_TMPFS
17530 + return sb->s_magic == TMPFS_MAGIC;
17536 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17538 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17539 + return !strcmp(au_sbtype(sb), "ecryptfs");
17545 +static inline int au_test_ramfs(struct super_block *sb)
17547 + return sb->s_magic == RAMFS_MAGIC;
17550 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17552 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17553 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17559 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17561 +#ifdef CONFIG_PROC_FS
17562 + return sb->s_magic == PROC_SUPER_MAGIC;
17568 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17570 +#ifdef CONFIG_SYSFS
17571 + return sb->s_magic == SYSFS_MAGIC;
17577 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17579 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17580 + return sb->s_magic == CONFIGFS_MAGIC;
17586 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17588 +#if IS_ENABLED(CONFIG_MINIX_FS)
17589 + return sb->s_magic == MINIX3_SUPER_MAGIC
17590 + || sb->s_magic == MINIX2_SUPER_MAGIC
17591 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17592 + || sb->s_magic == MINIX_SUPER_MAGIC
17593 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17599 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17601 +#if IS_ENABLED(CONFIG_FAT_FS)
17602 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17608 +static inline int au_test_msdos(struct super_block *sb)
17610 + return au_test_fat(sb);
17613 +static inline int au_test_vfat(struct super_block *sb)
17615 + return au_test_fat(sb);
17618 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17620 +#ifdef CONFIG_SECURITYFS
17621 + return sb->s_magic == SECURITYFS_MAGIC;
17627 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17629 +#if IS_ENABLED(CONFIG_SQUASHFS)
17630 + return sb->s_magic == SQUASHFS_MAGIC;
17636 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17638 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17639 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17645 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17647 +#if IS_ENABLED(CONFIG_XENFS)
17648 + return sb->s_magic == XENFS_SUPER_MAGIC;
17654 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17656 +#ifdef CONFIG_DEBUG_FS
17657 + return sb->s_magic == DEBUGFS_MAGIC;
17663 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17665 +#if IS_ENABLED(CONFIG_NILFS)
17666 + return sb->s_magic == NILFS_SUPER_MAGIC;
17672 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17674 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17675 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17681 +/* ---------------------------------------------------------------------- */
17683 + * they can't be an aufs branch.
17685 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17688 +#ifndef CONFIG_AUFS_BR_RAMFS
17689 + au_test_ramfs(sb) ||
17691 + au_test_procfs(sb)
17692 + || au_test_sysfs(sb)
17693 + || au_test_configfs(sb)
17694 + || au_test_debugfs(sb)
17695 + || au_test_securityfs(sb)
17696 + || au_test_xenfs(sb)
17697 + || au_test_ecryptfs(sb)
17698 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17699 + || au_test_aufs(sb); /* will be supported in next version */
17702 +static inline int au_test_fs_remote(struct super_block *sb)
17704 + return !au_test_tmpfs(sb)
17705 +#ifdef CONFIG_AUFS_BR_RAMFS
17706 + && !au_test_ramfs(sb)
17708 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17711 +/* ---------------------------------------------------------------------- */
17714 + * Note: these functions (below) are created after reading ->getattr() in all
17715 + * filesystems under linux/fs. it means we have to do so in every update...
17719 + * some filesystems require getattr to refresh the inode attributes before
17721 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17722 + * and leave the work for d_revalidate()
17724 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17726 + return au_test_nfs(sb)
17727 + || au_test_fuse(sb)
17728 + /* || au_test_btrfs(sb) */ /* untested */
17733 + * filesystems which don't maintain i_size or i_blocks.
17735 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17737 + return au_test_xfs(sb)
17738 + || au_test_btrfs(sb)
17739 + || au_test_ubifs(sb)
17740 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17741 + /* || au_test_minix(sb) */ /* untested */
17746 + * filesystems which don't store the correct value in some of their inode
17749 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17751 + return au_test_fs_bad_iattr_size(sb)
17752 + || au_test_fat(sb)
17753 + || au_test_msdos(sb)
17754 + || au_test_vfat(sb);
17757 +/* they don't check i_nlink in link(2) */
17758 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17760 + return au_test_tmpfs(sb)
17761 +#ifdef CONFIG_AUFS_BR_RAMFS
17762 + || au_test_ramfs(sb)
17764 + || au_test_ubifs(sb)
17765 + || au_test_hfsplus(sb);
17769 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17771 +static inline int au_test_fs_notime(struct super_block *sb)
17773 + return au_test_nfs(sb)
17774 + || au_test_fuse(sb)
17775 + || au_test_ubifs(sb)
17779 +/* temporary support for i#1 in cramfs */
17780 +static inline int au_test_fs_unique_ino(struct inode *inode)
17782 + if (au_test_cramfs(inode->i_sb))
17783 + return inode->i_ino != 1;
17787 +/* ---------------------------------------------------------------------- */
17790 + * the filesystem where the xino files placed must support i/o after unlink and
17791 + * maintain i_size and i_blocks.
17793 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17795 + return au_test_fs_remote(sb)
17796 + || au_test_fs_bad_iattr_size(sb)
17797 + /* don't want unnecessary work for xino */
17798 + || au_test_aufs(sb)
17799 + || au_test_ecryptfs(sb)
17800 + || au_test_nilfs(sb);
17803 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17805 + return au_test_tmpfs(sb)
17806 + || au_test_ramfs(sb);
17810 + * test if the @sb is real-readonly.
17812 +static inline int au_test_fs_rr(struct super_block *sb)
17814 + return au_test_squashfs(sb)
17815 + || au_test_iso9660(sb)
17816 + || au_test_cramfs(sb)
17817 + || au_test_romfs(sb);
17821 + * test if the @inode is nfs with 'noacl' option
17822 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17824 +static inline int au_test_nfs_noacl(struct inode *inode)
17826 + return au_test_nfs(inode->i_sb)
17827 + /* && IS_POSIXACL(inode) */
17828 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17831 +#endif /* __KERNEL__ */
17832 +#endif /* __AUFS_FSTYPE_H__ */
17833 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17834 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17835 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17837 +/* SPDX-License-Identifier: GPL-2.0 */
17839 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17841 + * This program is free software; you can redistribute it and/or modify
17842 + * it under the terms of the GNU General Public License as published by
17843 + * the Free Software Foundation; either version 2 of the License, or
17844 + * (at your option) any later version.
17846 + * This program is distributed in the hope that it will be useful,
17847 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17848 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17849 + * GNU General Public License for more details.
17851 + * You should have received a copy of the GNU General Public License
17852 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17856 + * helpers for hlist_bl.h
17859 +#ifndef __AUFS_HBL_H__
17860 +#define __AUFS_HBL_H__
17864 +#include <linux/list_bl.h>
17866 +static inline void au_hbl_add(struct hlist_bl_node *node,
17867 + struct hlist_bl_head *hbl)
17869 + hlist_bl_lock(hbl);
17870 + hlist_bl_add_head(node, hbl);
17871 + hlist_bl_unlock(hbl);
17874 +static inline void au_hbl_del(struct hlist_bl_node *node,
17875 + struct hlist_bl_head *hbl)
17877 + hlist_bl_lock(hbl);
17878 + hlist_bl_del(node);
17879 + hlist_bl_unlock(hbl);
17882 +#define au_hbl_for_each(pos, head) \
17883 + for (pos = hlist_bl_first(head); \
17887 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17889 + unsigned long cnt;
17890 + struct hlist_bl_node *pos;
17893 + hlist_bl_lock(hbl);
17894 + au_hbl_for_each(pos, hbl)
17896 + hlist_bl_unlock(hbl);
17900 +#endif /* __KERNEL__ */
17901 +#endif /* __AUFS_HBL_H__ */
17902 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17903 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17904 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17906 +// SPDX-License-Identifier: GPL-2.0
17908 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17910 + * This program is free software; you can redistribute it and/or modify
17911 + * it under the terms of the GNU General Public License as published by
17912 + * the Free Software Foundation; either version 2 of the License, or
17913 + * (at your option) any later version.
17915 + * This program is distributed in the hope that it will be useful,
17916 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17917 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17918 + * GNU General Public License for more details.
17920 + * You should have received a copy of the GNU General Public License
17921 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17925 + * fsnotify for the lower directories
17930 +/* FS_IN_IGNORED is unnecessary */
17931 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17932 + | FS_CREATE | FS_EVENT_ON_CHILD);
17933 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17934 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17936 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17938 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17940 + /* AuDbg("here\n"); */
17941 + au_cache_free_hnotify(hn);
17942 + smp_mb__before_atomic(); /* for atomic64_dec */
17943 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17944 + wake_up(&au_hfsn_wq);
17947 +static int au_hfsn_alloc(struct au_hinode *hinode)
17950 + struct au_hnotify *hn;
17951 + struct super_block *sb;
17952 + struct au_branch *br;
17953 + struct fsnotify_mark *mark;
17954 + aufs_bindex_t bindex;
17956 + hn = hinode->hi_notify;
17957 + sb = hn->hn_aufs_inode->i_sb;
17958 + bindex = au_br_index(sb, hinode->hi_id);
17959 + br = au_sbr(sb, bindex);
17960 + AuDebugOn(!br->br_hfsn);
17962 + mark = &hn->hn_mark;
17963 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17964 + mark->mask = AuHfsnMask;
17966 + * by udba rename or rmdir, aufs assign a new inode to the known
17967 + * h_inode, so specify 1 to allow dups.
17970 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
17976 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
17978 + struct fsnotify_mark *mark;
17979 + unsigned long long ull;
17980 + struct fsnotify_group *group;
17982 + ull = atomic64_inc_return(&au_hfsn_ifree);
17985 + mark = &hn->hn_mark;
17986 + spin_lock(&mark->lock);
17987 + group = mark->group;
17988 + fsnotify_get_group(group);
17989 + spin_unlock(&mark->lock);
17991 + fsnotify_destroy_mark(mark, group);
17992 + fsnotify_put_mark(mark);
17993 + fsnotify_put_group(group);
17996 + /* free hn by myself */
18000 +/* ---------------------------------------------------------------------- */
18002 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18004 + struct fsnotify_mark *mark;
18006 + mark = &hinode->hi_notify->hn_mark;
18007 + spin_lock(&mark->lock);
18009 + AuDebugOn(mark->mask & AuHfsnMask);
18010 + mark->mask |= AuHfsnMask;
18012 + AuDebugOn(!(mark->mask & AuHfsnMask));
18013 + mark->mask &= ~AuHfsnMask;
18015 + spin_unlock(&mark->lock);
18016 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18019 +/* ---------------------------------------------------------------------- */
18021 +/* #define AuDbgHnotify */
18022 +#ifdef AuDbgHnotify
18023 +static char *au_hfsn_name(u32 mask)
18025 +#ifdef CONFIG_AUFS_DEBUG
18026 +#define test_ret(flag) \
18028 + if (mask & flag) \
18031 + test_ret(FS_ACCESS);
18032 + test_ret(FS_MODIFY);
18033 + test_ret(FS_ATTRIB);
18034 + test_ret(FS_CLOSE_WRITE);
18035 + test_ret(FS_CLOSE_NOWRITE);
18036 + test_ret(FS_OPEN);
18037 + test_ret(FS_MOVED_FROM);
18038 + test_ret(FS_MOVED_TO);
18039 + test_ret(FS_CREATE);
18040 + test_ret(FS_DELETE);
18041 + test_ret(FS_DELETE_SELF);
18042 + test_ret(FS_MOVE_SELF);
18043 + test_ret(FS_UNMOUNT);
18044 + test_ret(FS_Q_OVERFLOW);
18045 + test_ret(FS_IN_IGNORED);
18046 + test_ret(FS_ISDIR);
18047 + test_ret(FS_IN_ONESHOT);
18048 + test_ret(FS_EVENT_ON_CHILD);
18057 +/* ---------------------------------------------------------------------- */
18059 +static void au_hfsn_free_group(struct fsnotify_group *group)
18061 + struct au_br_hfsnotify *hfsn = group->private;
18063 + /* AuDbg("here\n"); */
18064 + au_kfree_try_rcu(hfsn);
18067 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18068 + u32 mask, const void *data, int data_type,
18069 + struct inode *dir,
18070 + const struct qstr *file_name, u32 cookie,
18071 + struct fsnotify_iter_info *iter_info)
18074 + struct au_hnotify *hnotify;
18075 + struct inode *h_dir, *h_inode;
18076 + struct fsnotify_mark *inode_mark;
18078 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18079 + || data_type == FSNOTIFY_EVENT_DENTRY));
18082 + /* if FS_UNMOUNT happens, there must be another bug */
18083 + AuDebugOn(mask & FS_UNMOUNT);
18084 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18089 +#ifdef AuDbgHnotify
18091 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18092 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18093 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18094 + h_dir->i_ino, mask, au_hfsn_name(mask),
18095 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18096 + /* WARN_ON(1); */
18101 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18102 + AuDebugOn(!inode_mark);
18103 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18104 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18110 +static struct fsnotify_ops au_hfsn_ops = {
18111 + .handle_event = au_hfsn_handle_event,
18112 + .free_group_priv = au_hfsn_free_group,
18113 + .free_mark = au_hfsn_free_mark
18116 +/* ---------------------------------------------------------------------- */
18118 +static void au_hfsn_fin_br(struct au_branch *br)
18120 + struct au_br_hfsnotify *hfsn;
18122 + hfsn = br->br_hfsn;
18125 + fsnotify_put_group(hfsn->hfsn_group);
18130 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18133 + struct fsnotify_group *group;
18134 + struct au_br_hfsnotify *hfsn;
18137 + br->br_hfsn = NULL;
18138 + if (!au_br_hnotifyable(perm))
18142 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18143 + if (unlikely(!hfsn))
18147 + group = fsnotify_alloc_group(&au_hfsn_ops,
18148 + /*flags - not for userspace*/0);
18149 + if (IS_ERR(group)) {
18150 + err = PTR_ERR(group);
18151 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18155 + group->private = hfsn;
18156 + hfsn->hfsn_group = group;
18157 + br->br_hfsn = hfsn;
18158 + goto out; /* success */
18161 + au_kfree_try_rcu(hfsn);
18166 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18171 + if (!br->br_hfsn)
18172 + err = au_hfsn_init_br(br, perm);
18177 +/* ---------------------------------------------------------------------- */
18179 +static void au_hfsn_fin(void)
18181 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18182 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18185 +const struct au_hnotify_op au_hnotify_op = {
18186 + .ctl = au_hfsn_ctl,
18187 + .alloc = au_hfsn_alloc,
18188 + .free = au_hfsn_free,
18190 + .fin = au_hfsn_fin,
18192 + .reset_br = au_hfsn_reset_br,
18193 + .fin_br = au_hfsn_fin_br,
18194 + .init_br = au_hfsn_init_br
18196 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18197 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18198 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18200 +// SPDX-License-Identifier: GPL-2.0
18202 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18204 + * This program is free software; you can redistribute it and/or modify
18205 + * it under the terms of the GNU General Public License as published by
18206 + * the Free Software Foundation; either version 2 of the License, or
18207 + * (at your option) any later version.
18209 + * This program is distributed in the hope that it will be useful,
18210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18212 + * GNU General Public License for more details.
18214 + * You should have received a copy of the GNU General Public License
18215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18219 + * special support for filesystems which acquires an inode mutex
18220 + * at final closing a file, eg, hfsplus.
18222 + * This trick is very simple and stupid, just to open the file before really
18223 + * necessary open to tell hfsplus that this is not the final closing.
18224 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18225 + * and au_h_open_post() after releasing it.
18230 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18233 + struct file *h_file;
18234 + struct dentry *h_dentry;
18236 + h_dentry = au_h_dptr(dentry, bindex);
18237 + AuDebugOn(!h_dentry);
18238 + AuDebugOn(d_is_negative(h_dentry));
18241 + if (au_test_hfsplus(h_dentry->d_sb)
18242 + && d_is_reg(h_dentry))
18243 + h_file = au_h_open(dentry, bindex,
18244 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18245 + /*file*/NULL, force_wr);
18249 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18250 + struct file *h_file)
18252 + struct au_branch *br;
18256 + br = au_sbr(dentry->d_sb, bindex);
18257 + au_lcnt_dec(&br->br_nfiles);
18260 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18261 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18262 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18264 +// SPDX-License-Identifier: GPL-2.0
18266 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18268 + * This program is free software; you can redistribute it and/or modify
18269 + * it under the terms of the GNU General Public License as published by
18270 + * the Free Software Foundation; either version 2 of the License, or
18271 + * (at your option) any later version.
18273 + * This program is distributed in the hope that it will be useful,
18274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18276 + * GNU General Public License for more details.
18278 + * You should have received a copy of the GNU General Public License
18279 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18283 + * abstraction to notify the direct changes on lower directories
18286 +/* #include <linux/iversion.h> */
18289 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18292 + struct au_hnotify *hn;
18295 + hn = au_cache_alloc_hnotify();
18297 + hn->hn_aufs_inode = inode;
18298 + hinode->hi_notify = hn;
18299 + err = au_hnotify_op.alloc(hinode);
18301 + if (unlikely(err)) {
18302 + hinode->hi_notify = NULL;
18303 + au_cache_free_hnotify(hn);
18305 + * The upper dir was removed by udba, but the same named
18306 + * dir left. In this case, aufs assigns a new inode
18307 + * number and set the monitor again.
18308 + * For the lower dir, the old monitor is still left.
18310 + if (err == -EEXIST)
18319 +void au_hn_free(struct au_hinode *hinode)
18321 + struct au_hnotify *hn;
18323 + hn = hinode->hi_notify;
18325 + hinode->hi_notify = NULL;
18326 + if (au_hnotify_op.free(hinode, hn))
18327 + au_cache_free_hnotify(hn);
18331 +/* ---------------------------------------------------------------------- */
18333 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18335 + if (hinode->hi_notify)
18336 + au_hnotify_op.ctl(hinode, do_set);
18339 +void au_hn_reset(struct inode *inode, unsigned int flags)
18341 + aufs_bindex_t bindex, bbot;
18342 + struct inode *hi;
18343 + struct dentry *iwhdentry;
18345 + bbot = au_ibbot(inode);
18346 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18347 + hi = au_h_iptr(inode, bindex);
18351 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18352 + iwhdentry = au_hi_wh(inode, bindex);
18356 + au_set_h_iptr(inode, bindex, NULL, 0);
18357 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18358 + flags & ~AuHi_XINO);
18361 + /* inode_unlock(hi); */
18365 +/* ---------------------------------------------------------------------- */
18367 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18370 + aufs_bindex_t bindex, bbot, bfound, btop;
18371 + struct inode *h_i;
18374 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18375 + pr_warn("branch root dir was changed\n");
18380 + bbot = au_ibbot(inode);
18381 + btop = au_ibtop(inode);
18382 +#if 0 /* reserved for future use */
18383 + if (bindex == bbot) {
18384 + /* keep this ino in rename case */
18388 + for (bindex = btop; bindex <= bbot; bindex++)
18389 + if (au_h_iptr(inode, bindex) == h_inode) {
18396 + for (bindex = btop; bindex <= bbot; bindex++) {
18397 + h_i = au_h_iptr(inode, bindex);
18401 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18402 + /* ignore this error */
18403 + /* bad action? */
18406 + /* children inode number will be broken */
18413 +static int hn_gen_tree(struct dentry *dentry)
18415 + int err, i, j, ndentry;
18416 + struct au_dcsub_pages dpages;
18417 + struct au_dpage *dpage;
18418 + struct dentry **dentries;
18420 + err = au_dpages_init(&dpages, GFP_NOFS);
18421 + if (unlikely(err))
18423 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18424 + if (unlikely(err))
18427 + for (i = 0; i < dpages.ndpage; i++) {
18428 + dpage = dpages.dpages + i;
18429 + dentries = dpage->dentries;
18430 + ndentry = dpage->ndentry;
18431 + for (j = 0; j < ndentry; j++) {
18432 + struct dentry *d;
18439 + if (d_really_is_positive(d))
18440 + /* todo: reset children xino?
18441 + cached children only? */
18442 + au_iigen_dec(d_inode(d));
18447 + au_dpages_free(&dpages);
18453 + * return 0 if processed.
18455 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18456 + const unsigned int isdir)
18459 + struct dentry *d;
18460 + struct qstr *dname;
18463 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18464 + pr_warn("branch root dir was changed\n");
18470 + AuDebugOn(!name);
18471 + au_iigen_dec(inode);
18472 + spin_lock(&inode->i_lock);
18473 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18474 + spin_lock(&d->d_lock);
18475 + dname = &d->d_name;
18476 + if (dname->len != nlen
18477 + && memcmp(dname->name, name, nlen)) {
18478 + spin_unlock(&d->d_lock);
18483 + spin_unlock(&d->d_lock);
18486 + spin_unlock(&inode->i_lock);
18488 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18489 + d = d_find_any_alias(inode);
18491 + au_iigen_dec(inode);
18495 + spin_lock(&d->d_lock);
18496 + dname = &d->d_name;
18497 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18498 + spin_unlock(&d->d_lock);
18499 + err = hn_gen_tree(d);
18500 + spin_lock(&d->d_lock);
18502 + spin_unlock(&d->d_lock);
18511 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18515 + if (IS_ROOT(dentry)) {
18516 + pr_warn("branch root dir was changed\n");
18522 + au_digen_dec(dentry);
18523 + if (d_really_is_positive(dentry))
18524 + au_iigen_dec(d_inode(dentry));
18526 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18527 + if (d_really_is_positive(dentry))
18528 + err = hn_gen_tree(dentry);
18535 +/* ---------------------------------------------------------------------- */
18537 +/* hnotify job flags */
18538 +#define AuHnJob_XINO0 1
18539 +#define AuHnJob_GEN (1 << 1)
18540 +#define AuHnJob_DIRENT (1 << 2)
18541 +#define AuHnJob_ISDIR (1 << 3)
18542 +#define AuHnJob_TRYXINO0 (1 << 4)
18543 +#define AuHnJob_MNTPNT (1 << 5)
18544 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18545 +#define au_fset_hnjob(flags, name) \
18546 + do { (flags) |= AuHnJob_##name; } while (0)
18547 +#define au_fclr_hnjob(flags, name) \
18548 + do { (flags) &= ~AuHnJob_##name; } while (0)
18556 +struct au_hnotify_args {
18557 + struct inode *h_dir, *dir, *h_child_inode;
18559 + unsigned int flags[AuHnLast];
18560 + unsigned int h_child_nlen;
18561 + char h_child_name[];
18564 +struct hn_job_args {
18565 + unsigned int flags;
18566 + struct inode *inode, *h_inode, *dir, *h_dir;
18567 + struct dentry *dentry;
18572 +static int hn_job(struct hn_job_args *a)
18574 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18578 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18579 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18581 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18584 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18585 + if (!a->h_inode->i_nlink
18586 + && !(a->h_inode->i_state & I_LINKABLE))
18587 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18588 + inode_unlock_shared(a->h_inode);
18591 + /* make the generation obsolete */
18592 + if (au_ftest_hnjob(a->flags, GEN)) {
18595 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18597 + if (e && a->dentry)
18598 + hn_gen_by_name(a->dentry, isdir);
18599 + /* ignore this error */
18602 + /* make dir entries obsolete */
18603 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18604 + struct au_vdir *vdir;
18606 + vdir = au_ivdir(a->inode);
18608 + vdir->vd_jiffy = 0;
18609 + /* IMustLock(a->inode); */
18610 + /* inode_inc_iversion(a->inode); */
18613 + /* can do nothing but warn */
18614 + if (au_ftest_hnjob(a->flags, MNTPNT)
18616 + && d_mountpoint(a->dentry))
18617 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18622 +/* ---------------------------------------------------------------------- */
18624 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18625 + struct inode *dir)
18627 + struct dentry *dentry, *d, *parent;
18628 + struct qstr *dname;
18630 + parent = d_find_any_alias(dir);
18635 + spin_lock(&parent->d_lock);
18636 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18637 + /* AuDbg("%pd\n", d); */
18638 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18639 + dname = &d->d_name;
18640 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18641 + goto cont_unlock;
18645 + goto cont_unlock;
18646 + if (au_dcount(d) > 0) {
18647 + dentry = dget_dlock(d);
18648 + spin_unlock(&d->d_lock);
18653 + spin_unlock(&d->d_lock);
18655 + spin_unlock(&parent->d_lock);
18659 + di_write_lock_child(dentry);
18664 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18665 + aufs_bindex_t bindex, ino_t h_ino)
18667 + struct inode *inode;
18672 + err = au_xino_read(sb, bindex, h_ino, &ino);
18674 + inode = ilookup(sb, ino);
18678 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18679 + pr_warn("wrong root branch\n");
18685 + ii_write_lock_child(inode);
18691 +static void au_hn_bh(void *_args)
18693 + struct au_hnotify_args *a = _args;
18694 + struct super_block *sb;
18695 + aufs_bindex_t bindex, bbot, bfound;
18696 + unsigned char xino, try_iput;
18698 + struct inode *inode;
18700 + struct hn_job_args args;
18701 + struct dentry *dentry;
18702 + struct au_sbinfo *sbinfo;
18704 + AuDebugOn(!_args);
18705 + AuDebugOn(!a->h_dir);
18706 + AuDebugOn(!a->dir);
18707 + AuDebugOn(!a->mask);
18708 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18709 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18710 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18715 + * do not lock a->dir->i_mutex here
18716 + * because of d_revalidate() may cause a deadlock.
18718 + sb = a->dir->i_sb;
18720 + sbinfo = au_sbi(sb);
18721 + AuDebugOn(!sbinfo);
18722 + si_write_lock(sb, AuLock_NOPLMW);
18724 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18725 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18726 + case FS_MOVED_FROM:
18727 + case FS_MOVED_TO:
18728 + AuWarn1("DIRREN with UDBA may not work correctly "
18729 + "for the direct rename(2)\n");
18732 + ii_read_lock_parent(a->dir);
18734 + bbot = au_ibbot(a->dir);
18735 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18736 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18740 + ii_read_unlock(a->dir);
18741 + if (unlikely(bfound < 0))
18744 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18746 + if (a->h_child_inode)
18747 + h_ino = a->h_child_inode->i_ino;
18749 + if (a->h_child_nlen
18750 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18751 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18752 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18755 + if (dentry && d_really_is_positive(dentry))
18756 + inode = d_inode(dentry);
18757 + if (xino && !inode && h_ino
18758 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18759 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18760 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18761 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18765 + args.flags = a->flags[AuHn_CHILD];
18766 + args.dentry = dentry;
18767 + args.inode = inode;
18768 + args.h_inode = a->h_child_inode;
18769 + args.dir = a->dir;
18770 + args.h_dir = a->h_dir;
18771 + args.h_name = a->h_child_name;
18772 + args.h_nlen = a->h_child_nlen;
18773 + err = hn_job(&args);
18775 + if (au_di(dentry))
18776 + di_write_unlock(dentry);
18779 + if (inode && try_iput) {
18780 + ii_write_unlock(inode);
18784 + ii_write_lock_parent(a->dir);
18785 + args.flags = a->flags[AuHn_PARENT];
18786 + args.dentry = NULL;
18787 + args.inode = a->dir;
18788 + args.h_inode = a->h_dir;
18790 + args.h_dir = NULL;
18791 + args.h_name = NULL;
18793 + err = hn_job(&args);
18794 + ii_write_unlock(a->dir);
18797 + iput(a->h_child_inode);
18800 + si_write_unlock(sb);
18801 + au_nwt_done(&sbinfo->si_nowait);
18805 +/* ---------------------------------------------------------------------- */
18807 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18808 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18811 + unsigned int flags[AuHnLast], f;
18812 + unsigned char isdir, isroot, wh;
18813 + struct inode *dir;
18814 + struct au_hnotify_args *args;
18815 + char *p, *h_child_name;
18818 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18819 + dir = igrab(hnotify->hn_aufs_inode);
18823 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18825 + h_child_name = (void *)h_child_qstr->name;
18826 + len = h_child_qstr->len;
18827 + if (h_child_name) {
18828 + if (len > AUFS_WH_PFX_LEN
18829 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18830 + h_child_name += AUFS_WH_PFX_LEN;
18831 + len -= AUFS_WH_PFX_LEN;
18837 + if (h_child_inode)
18838 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18839 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18840 + flags[AuHn_CHILD] = 0;
18842 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18843 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18844 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18845 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18846 + case FS_MOVED_FROM:
18847 + case FS_MOVED_TO:
18848 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18849 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18852 + AuDebugOn(!h_child_name);
18857 + * aufs never be able to get this child inode.
18858 + * revalidation should be in d_revalidate()
18859 + * by checking i_nlink, i_generation or d_unhashed().
18861 + AuDebugOn(!h_child_name);
18862 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18863 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18871 + h_child_inode = NULL;
18874 + /* iput() and kfree() will be called in au_hnotify() */
18875 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18876 + if (unlikely(!args)) {
18877 + AuErr1("no memory\n");
18881 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18882 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18883 + args->mask = mask;
18885 + args->h_dir = igrab(h_dir);
18886 + if (h_child_inode)
18887 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18888 + args->h_child_inode = h_child_inode;
18889 + args->h_child_nlen = len;
18891 + p = (void *)args;
18892 + p += sizeof(*args);
18893 + memcpy(p, h_child_name, len);
18897 + /* NFS fires the event for silly-renamed one from kworker */
18899 + if (!dir->i_nlink
18900 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18902 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18903 + if (unlikely(err)) {
18904 + pr_err("wkq %d\n", err);
18905 + iput(args->h_child_inode);
18906 + iput(args->h_dir);
18908 + au_kfree_rcu(args);
18915 +/* ---------------------------------------------------------------------- */
18917 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18921 + AuDebugOn(!(udba & AuOptMask_UDBA));
18924 + if (au_hnotify_op.reset_br)
18925 + err = au_hnotify_op.reset_br(udba, br, perm);
18930 +int au_hnotify_init_br(struct au_branch *br, int perm)
18935 + if (au_hnotify_op.init_br)
18936 + err = au_hnotify_op.init_br(br, perm);
18941 +void au_hnotify_fin_br(struct au_branch *br)
18943 + if (au_hnotify_op.fin_br)
18944 + au_hnotify_op.fin_br(br);
18947 +static void au_hn_destroy_cache(void)
18949 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18950 + au_cache[AuCache_HNOTIFY] = NULL;
18953 +int __init au_hnotify_init(void)
18958 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18959 + if (au_cache[AuCache_HNOTIFY]) {
18961 + if (au_hnotify_op.init)
18962 + err = au_hnotify_op.init();
18963 + if (unlikely(err))
18964 + au_hn_destroy_cache();
18970 +void au_hnotify_fin(void)
18972 + if (au_hnotify_op.fin)
18973 + au_hnotify_op.fin();
18975 + /* cf. au_cache_fin() */
18976 + if (au_cache[AuCache_HNOTIFY])
18977 + au_hn_destroy_cache();
18979 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
18980 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
18981 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
18983 +// SPDX-License-Identifier: GPL-2.0
18985 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18987 + * This program is free software; you can redistribute it and/or modify
18988 + * it under the terms of the GNU General Public License as published by
18989 + * the Free Software Foundation; either version 2 of the License, or
18990 + * (at your option) any later version.
18992 + * This program is distributed in the hope that it will be useful,
18993 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18994 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18995 + * GNU General Public License for more details.
18997 + * You should have received a copy of the GNU General Public License
18998 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19002 + * inode private data
19007 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19009 + struct inode *h_inode;
19010 + struct au_hinode *hinode;
19012 + IiMustAnyLock(inode);
19014 + hinode = au_hinode(au_ii(inode), bindex);
19015 + h_inode = hinode->hi_inode;
19016 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19020 +/* todo: hard/soft set? */
19021 +void au_hiput(struct au_hinode *hinode)
19023 + au_hn_free(hinode);
19024 + dput(hinode->hi_whdentry);
19025 + iput(hinode->hi_inode);
19028 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19030 + unsigned int flags;
19031 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19034 + if (au_opt_test(mnt_flags, XINO))
19035 + au_fset_hi(flags, XINO);
19036 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19037 + au_fset_hi(flags, HNOTIFY);
19041 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19042 + struct inode *h_inode, unsigned int flags)
19044 + struct au_hinode *hinode;
19045 + struct inode *hi;
19046 + struct au_iinfo *iinfo = au_ii(inode);
19048 + IiMustWriteLock(inode);
19050 + hinode = au_hinode(iinfo, bindex);
19051 + hi = hinode->hi_inode;
19052 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19055 + au_hiput(hinode);
19056 + hinode->hi_inode = h_inode;
19059 + struct super_block *sb = inode->i_sb;
19060 + struct au_branch *br;
19062 + AuDebugOn(inode->i_mode
19063 + && (h_inode->i_mode & S_IFMT)
19064 + != (inode->i_mode & S_IFMT));
19065 + if (bindex == iinfo->ii_btop)
19066 + au_cpup_igen(inode, h_inode);
19067 + br = au_sbr(sb, bindex);
19068 + hinode->hi_id = br->br_id;
19069 + if (au_ftest_hi(flags, XINO)) {
19070 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19072 + if (unlikely(err))
19073 + AuIOErr1("failed au_xino_write() %d\n", err);
19076 + if (au_ftest_hi(flags, HNOTIFY)
19077 + && au_br_hnotifyable(br->br_perm)) {
19078 + err = au_hn_alloc(hinode, inode);
19079 + if (unlikely(err))
19080 + AuIOErr1("au_hn_alloc() %d\n", err);
19085 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19086 + struct dentry *h_wh)
19088 + struct au_hinode *hinode;
19090 + IiMustWriteLock(inode);
19092 + hinode = au_hinode(au_ii(inode), bindex);
19093 + AuDebugOn(hinode->hi_whdentry);
19094 + hinode->hi_whdentry = h_wh;
19097 +void au_update_iigen(struct inode *inode, int half)
19099 + struct au_iinfo *iinfo;
19100 + struct au_iigen *iigen;
19101 + unsigned int sigen;
19103 + sigen = au_sigen(inode->i_sb);
19104 + iinfo = au_ii(inode);
19105 + iigen = &iinfo->ii_generation;
19106 + spin_lock(&iigen->ig_spin);
19107 + iigen->ig_generation = sigen;
19109 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19111 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19112 + spin_unlock(&iigen->ig_spin);
19115 +/* it may be called at remount time, too */
19116 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19118 + struct au_iinfo *iinfo;
19119 + aufs_bindex_t bindex, bbot;
19121 + AuDebugOn(au_is_bad_inode(inode));
19122 + IiMustWriteLock(inode);
19124 + iinfo = au_ii(inode);
19125 + if (do_put_zero && iinfo->ii_btop >= 0) {
19126 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19128 + struct inode *h_i;
19130 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19133 + && !(h_i->i_state & I_LINKABLE))
19134 + au_set_h_iptr(inode, bindex, NULL, 0);
19138 + iinfo->ii_btop = -1;
19139 + iinfo->ii_bbot = -1;
19140 + bbot = au_sbbot(inode->i_sb);
19141 + for (bindex = 0; bindex <= bbot; bindex++)
19142 + if (au_hinode(iinfo, bindex)->hi_inode) {
19143 + iinfo->ii_btop = bindex;
19146 + if (iinfo->ii_btop >= 0)
19147 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19148 + if (au_hinode(iinfo, bindex)->hi_inode) {
19149 + iinfo->ii_bbot = bindex;
19152 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19155 +/* ---------------------------------------------------------------------- */
19157 +void au_icntnr_init_once(void *_c)
19159 + struct au_icntnr *c = _c;
19160 + struct au_iinfo *iinfo = &c->iinfo;
19162 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19163 + au_rw_init(&iinfo->ii_rwsem);
19164 + inode_init_once(&c->vfs_inode);
19167 +void au_hinode_init(struct au_hinode *hinode)
19169 + hinode->hi_inode = NULL;
19170 + hinode->hi_id = -1;
19171 + au_hn_init(hinode);
19172 + hinode->hi_whdentry = NULL;
19175 +int au_iinfo_init(struct inode *inode)
19177 + struct au_iinfo *iinfo;
19178 + struct super_block *sb;
19179 + struct au_hinode *hi;
19182 + sb = inode->i_sb;
19183 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19184 + nbr = au_sbbot(sb) + 1;
19185 + if (unlikely(nbr <= 0))
19187 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19189 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19191 + iinfo->ii_hinode = hi;
19192 + for (i = 0; i < nbr; i++, hi++)
19193 + au_hinode_init(hi);
19195 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19196 + iinfo->ii_btop = -1;
19197 + iinfo->ii_bbot = -1;
19198 + iinfo->ii_vdir = NULL;
19204 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19207 + struct au_hinode *hip;
19209 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19212 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19215 + iinfo->ii_hinode = hip;
19216 + i = iinfo->ii_bbot + 1;
19218 + for (; i < nbr; i++, hip++)
19219 + au_hinode_init(hip);
19226 +void au_iinfo_fin(struct inode *inode)
19228 + struct au_iinfo *iinfo;
19229 + struct au_hinode *hi;
19230 + struct super_block *sb;
19231 + aufs_bindex_t bindex, bbot;
19232 + const unsigned char unlinked = !inode->i_nlink;
19234 + AuDebugOn(au_is_bad_inode(inode));
19236 + sb = inode->i_sb;
19237 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19238 + if (si_pid_test(sb))
19239 + au_xino_delete_inode(inode, unlinked);
19242 + * it is safe to hide the dependency between sbinfo and
19246 + si_noflush_read_lock(sb);
19247 + au_xino_delete_inode(inode, unlinked);
19248 + si_read_unlock(sb);
19252 + iinfo = au_ii(inode);
19253 + if (iinfo->ii_vdir)
19254 + au_vdir_free(iinfo->ii_vdir);
19256 + bindex = iinfo->ii_btop;
19257 + if (bindex >= 0) {
19258 + hi = au_hinode(iinfo, bindex);
19259 + bbot = iinfo->ii_bbot;
19260 + while (bindex++ <= bbot) {
19261 + if (hi->hi_inode)
19266 + au_kfree_rcu(iinfo->ii_hinode);
19267 + AuRwDestroy(&iinfo->ii_rwsem);
19269 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19270 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19271 +++ linux/fs/aufs/inode.c 2023-08-28 12:34:39.956636132 +0200
19273 +// SPDX-License-Identifier: GPL-2.0
19275 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19277 + * This program is free software; you can redistribute it and/or modify
19278 + * it under the terms of the GNU General Public License as published by
19279 + * the Free Software Foundation; either version 2 of the License, or
19280 + * (at your option) any later version.
19282 + * This program is distributed in the hope that it will be useful,
19283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19285 + * GNU General Public License for more details.
19287 + * You should have received a copy of the GNU General Public License
19288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19292 + * inode functions
19295 +#include <linux/iversion.h>
19298 +struct inode *au_igrab(struct inode *inode)
19301 + AuDebugOn(!atomic_read(&inode->i_count));
19307 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19309 + au_cpup_attr_all(inode, /*force*/0);
19310 + au_update_iigen(inode, /*half*/1);
19312 + inode_inc_iversion(inode);
19315 +static int au_ii_refresh(struct inode *inode, int *update)
19319 + aufs_bindex_t bindex, new_bindex;
19320 + struct super_block *sb;
19321 + struct au_iinfo *iinfo;
19322 + struct au_hinode *p, *q, tmp;
19324 + AuDebugOn(au_is_bad_inode(inode));
19325 + IiMustWriteLock(inode);
19328 + sb = inode->i_sb;
19329 + nbr = au_sbbot(sb) + 1;
19330 + type = inode->i_mode & S_IFMT;
19331 + iinfo = au_ii(inode);
19332 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19333 + if (unlikely(err))
19336 + AuDebugOn(iinfo->ii_btop < 0);
19337 + p = au_hinode(iinfo, iinfo->ii_btop);
19338 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19340 + if (!p->hi_inode)
19343 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19344 + new_bindex = au_br_index(sb, p->hi_id);
19345 + if (new_bindex == bindex)
19348 + if (new_bindex < 0) {
19351 + p->hi_inode = NULL;
19355 + if (new_bindex < iinfo->ii_btop)
19356 + iinfo->ii_btop = new_bindex;
19357 + if (iinfo->ii_bbot < new_bindex)
19358 + iinfo->ii_bbot = new_bindex;
19359 + /* swap two lower inode, and loop again */
19360 + q = au_hinode(iinfo, new_bindex);
19364 + if (tmp.hi_inode) {
19369 + au_update_ibrange(inode, /*do_put_zero*/0);
19370 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19371 + e = au_dy_irefresh(inode);
19372 + if (unlikely(e && !err))
19380 +void au_refresh_iop(struct inode *inode, int force_getattr)
19383 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19384 + const struct inode_operations *iop
19385 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19387 + if (inode->i_op == iop)
19390 + switch (inode->i_mode & S_IFMT) {
19392 + type = AuIop_DIR;
19395 + type = AuIop_SYMLINK;
19398 + type = AuIop_OTHER;
19402 + inode->i_op = iop + type;
19403 + /* unnecessary smp_wmb() */
19406 +int au_refresh_hinode_self(struct inode *inode)
19410 + err = au_ii_refresh(inode, &update);
19412 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19418 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19420 + int err, e, update;
19421 + unsigned int flags;
19423 + aufs_bindex_t bindex, bbot;
19424 + unsigned char isdir;
19425 + struct au_hinode *p;
19426 + struct au_iinfo *iinfo;
19428 + err = au_ii_refresh(inode, &update);
19429 + if (unlikely(err))
19433 + iinfo = au_ii(inode);
19434 + p = au_hinode(iinfo, iinfo->ii_btop);
19435 + mode = (inode->i_mode & S_IFMT);
19436 + isdir = S_ISDIR(mode);
19437 + flags = au_hi_flags(inode, isdir);
19438 + bbot = au_dbbot(dentry);
19439 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19440 + struct inode *h_i, *h_inode;
19441 + struct dentry *h_d;
19443 + h_d = au_h_dptr(dentry, bindex);
19444 + if (!h_d || d_is_negative(h_d))
19447 + h_inode = d_inode(h_d);
19448 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19449 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19450 + h_i = au_h_iptr(inode, bindex);
19452 + if (h_i == h_inode)
19458 + if (bindex < iinfo->ii_btop)
19459 + iinfo->ii_btop = bindex;
19460 + if (iinfo->ii_bbot < bindex)
19461 + iinfo->ii_bbot = bindex;
19462 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19465 + au_update_ibrange(inode, /*do_put_zero*/0);
19466 + e = au_dy_irefresh(inode);
19467 + if (unlikely(e && !err))
19470 + au_refresh_hinode_attr(inode, update && isdir);
19477 +static int set_inode(struct inode *inode, struct dentry *dentry)
19480 + unsigned int flags;
19482 + aufs_bindex_t bindex, btop, btail;
19483 + unsigned char isdir;
19484 + struct dentry *h_dentry;
19485 + struct inode *h_inode;
19486 + struct au_iinfo *iinfo;
19487 + const struct inode_operations *iop;
19489 + IiMustWriteLock(inode);
19493 + iop = au_sbi(inode->i_sb)->si_iop_array;
19494 + btop = au_dbtop(dentry);
19495 + h_dentry = au_h_dptr(dentry, btop);
19496 + h_inode = d_inode(h_dentry);
19497 + mode = h_inode->i_mode;
19498 + switch (mode & S_IFMT) {
19500 + btail = au_dbtail(dentry);
19501 + inode->i_op = iop + AuIop_OTHER;
19502 + inode->i_fop = &aufs_file_fop;
19503 + err = au_dy_iaop(inode, btop, h_inode);
19504 + if (unlikely(err))
19509 + btail = au_dbtaildir(dentry);
19510 + inode->i_op = iop + AuIop_DIR;
19511 + inode->i_fop = &aufs_dir_fop;
19514 + btail = au_dbtail(dentry);
19515 + inode->i_op = iop + AuIop_SYMLINK;
19521 + btail = au_dbtail(dentry);
19522 + inode->i_op = iop + AuIop_OTHER;
19523 + init_special_inode(inode, mode, h_inode->i_rdev);
19526 + AuIOErr("Unknown file type 0%o\n", mode);
19531 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19532 + flags = au_hi_flags(inode, isdir);
19533 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19534 + && au_ftest_hi(flags, HNOTIFY)
19535 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19536 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19537 + au_fclr_hi(flags, HNOTIFY);
19538 + iinfo = au_ii(inode);
19539 + iinfo->ii_btop = btop;
19540 + iinfo->ii_bbot = btail;
19541 + for (bindex = btop; bindex <= btail; bindex++) {
19542 + h_dentry = au_h_dptr(dentry, bindex);
19544 + au_set_h_iptr(inode, bindex,
19545 + au_igrab(d_inode(h_dentry)), flags);
19547 + au_cpup_attr_all(inode, /*force*/1);
19549 + * to force calling aufs_get_inode_acl() every time,
19550 + * do not call cache_no_acl() for aufs inode.
19558 + * successful returns with iinfo write_locked
19560 + * zero: success, matched
19561 + * plus: no error, but unmatched
19563 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19566 + unsigned int gen, igflags;
19567 + aufs_bindex_t bindex, bbot;
19568 + struct inode *h_inode, *h_dinode;
19569 + struct dentry *h_dentry;
19572 + * before this function, if aufs got any iinfo lock, it must be only
19573 + * one, the parent dir.
19574 + * it can happen by UDBA and the obsoleted inode number.
19577 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19581 + ii_write_lock_new_child(inode);
19582 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19583 + h_dinode = d_inode(h_dentry);
19584 + bbot = au_ibbot(inode);
19585 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19586 + h_inode = au_h_iptr(inode, bindex);
19587 + if (!h_inode || h_inode != h_dinode)
19591 + gen = au_iigen(inode, &igflags);
19592 + if (gen == au_digen(dentry)
19593 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19596 + /* fully refresh inode using dentry */
19597 + err = au_refresh_hinode(inode, dentry);
19599 + au_update_iigen(inode, /*half*/0);
19603 + if (unlikely(err))
19604 + ii_write_unlock(inode);
19609 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19610 + unsigned int d_type, ino_t *ino)
19613 + const int isnondir = d_type != DT_DIR;
19615 + /* prevent hardlinked inode number from race condition */
19617 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19618 + if (unlikely(err))
19622 + err = au_xino_read(sb, bindex, h_ino, ino);
19623 + if (unlikely(err))
19624 + goto out_xinondir;
19628 + *ino = au_xino_new_ino(sb);
19629 + if (unlikely(!*ino))
19630 + goto out_xinondir;
19631 + err = au_xino_write(sb, bindex, h_ino, *ino);
19632 + if (unlikely(err))
19633 + goto out_xinondir;
19637 + if (isnondir && idx >= 0)
19638 + au_xinondir_leave(sb, bindex, h_ino, idx);
19643 +/* successful returns with iinfo write_locked */
19644 +/* todo: return with unlocked? */
19645 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19647 + struct inode *inode, *h_inode;
19648 + struct dentry *h_dentry;
19649 + struct super_block *sb;
19650 + ino_t h_ino, ino;
19651 + int err, idx, hlinked;
19652 + aufs_bindex_t btop;
19654 + sb = dentry->d_sb;
19655 + btop = au_dbtop(dentry);
19656 + h_dentry = au_h_dptr(dentry, btop);
19657 + h_inode = d_inode(h_dentry);
19658 + h_ino = h_inode->i_ino;
19659 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19663 + * stop 'race'-ing between hardlinks under different
19667 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19668 + inode = ERR_PTR(err);
19669 + if (unlikely(err))
19673 + err = au_xino_read(sb, btop, h_ino, &ino);
19674 + inode = ERR_PTR(err);
19675 + if (unlikely(err))
19676 + goto out_xinondir;
19679 + ino = au_xino_new_ino(sb);
19680 + if (unlikely(!ino)) {
19681 + inode = ERR_PTR(-EIO);
19682 + goto out_xinondir;
19686 + AuDbg("i%lu\n", (unsigned long)ino);
19687 + inode = au_iget_locked(sb, ino);
19688 + err = PTR_ERR(inode);
19689 + if (IS_ERR(inode))
19690 + goto out_xinondir;
19692 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19693 + if (inode->i_state & I_NEW) {
19694 + ii_write_lock_new_child(inode);
19695 + err = set_inode(inode, dentry);
19697 + unlock_new_inode(inode);
19698 + goto out_xinondir; /* success */
19702 + * iget_failed() calls iput(), but we need to call
19703 + * ii_write_unlock() after iget_failed(). so dirty hack for
19706 + atomic_inc(&inode->i_count);
19707 + iget_failed(inode);
19708 + ii_write_unlock(inode);
19709 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19710 + /* ignore this error */
19712 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19714 + * horrible race condition between lookup, readdir and copyup
19715 + * (or something).
19717 + if (hlinked && idx >= 0)
19718 + au_xinondir_leave(sb, btop, h_ino, idx);
19719 + err = reval_inode(inode, dentry);
19720 + if (unlikely(err < 0)) {
19725 + goto out; /* success */
19726 + else if (hlinked && idx >= 0) {
19727 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19728 + if (unlikely(err)) {
19730 + inode = ERR_PTR(err);
19736 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19737 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19738 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19739 + btop, au_sbtype(h_dentry->d_sb), dentry,
19740 + (unsigned long)h_ino, (unsigned long)ino);
19742 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19745 + if (hlinked && idx >= 0)
19746 + au_xinondir_leave(sb, btop, h_ino, idx);
19752 + inode = ERR_PTR(err);
19754 + if (hlinked && idx >= 0)
19755 + au_xinondir_leave(sb, btop, h_ino, idx);
19760 +/* ---------------------------------------------------------------------- */
19762 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19763 + struct inode *inode)
19766 + struct inode *hi;
19768 + err = au_br_rdonly(au_sbr(sb, bindex));
19770 + /* pseudo-link after flushed may happen out of bounds */
19773 + && au_ibtop(inode) <= bindex
19774 + && bindex <= au_ibbot(inode)) {
19776 + * permission check is unnecessary since vfsub routine
19777 + * will be called later
19779 + hi = au_h_iptr(inode, bindex);
19781 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19787 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19790 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19792 + return inode_permission(h_idmap, h_inode, mask);
19795 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19798 + if (au_test_nfs(h_inode->i_sb)
19799 + && (mask & MAY_WRITE)
19800 + && S_ISDIR(h_inode->i_mode))
19801 + mask |= MAY_READ; /* force permission check */
19802 + return au_test_h_perm(h_idmap, h_inode, mask);
19804 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19805 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19806 +++ linux/fs/aufs/inode.h 2023-08-28 12:34:39.956636132 +0200
19808 +/* SPDX-License-Identifier: GPL-2.0 */
19810 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19812 + * This program is free software; you can redistribute it and/or modify
19813 + * it under the terms of the GNU General Public License as published by
19814 + * the Free Software Foundation; either version 2 of the License, or
19815 + * (at your option) any later version.
19817 + * This program is distributed in the hope that it will be useful,
19818 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19820 + * GNU General Public License for more details.
19822 + * You should have received a copy of the GNU General Public License
19823 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19827 + * inode operations
19830 +#ifndef __AUFS_INODE_H__
19831 +#define __AUFS_INODE_H__
19835 +#include <linux/fsnotify.h>
19836 +#include "rwsem.h"
19840 +struct au_hnotify {
19841 +#ifdef CONFIG_AUFS_HNOTIFY
19842 +#ifdef CONFIG_AUFS_HFSNOTIFY
19843 + /* never use fsnotify_add_vfsmount_mark() */
19844 + struct fsnotify_mark hn_mark;
19846 + struct inode *hn_aufs_inode; /* no get/put */
19847 + struct rcu_head rcu;
19849 +} ____cacheline_aligned_in_smp;
19851 +struct au_hinode {
19852 + struct inode *hi_inode;
19853 + aufs_bindex_t hi_id;
19854 +#ifdef CONFIG_AUFS_HNOTIFY
19855 + struct au_hnotify *hi_notify;
19858 + /* reference to the copied-up whiteout with get/put */
19859 + struct dentry *hi_whdentry;
19863 +#define AuIG_HALF_REFRESHED 1
19864 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19865 +#define au_ig_fset(flags, name) \
19866 + do { (flags) |= AuIG_##name; } while (0)
19867 +#define au_ig_fclr(flags, name) \
19868 + do { (flags) &= ~AuIG_##name; } while (0)
19871 + spinlock_t ig_spin;
19872 + __u32 ig_generation, ig_flags;
19877 + struct au_iigen ii_generation;
19878 + struct super_block *ii_hsb1; /* no get/put */
19880 + struct au_rwsem ii_rwsem;
19881 + aufs_bindex_t ii_btop, ii_bbot;
19883 + struct au_hinode *ii_hinode;
19884 + struct au_vdir *ii_vdir;
19887 +struct au_icntnr {
19888 + struct au_iinfo iinfo;
19889 + struct inode vfs_inode;
19890 + struct hlist_bl_node plink;
19891 + struct rcu_head rcu;
19892 +} ____cacheline_aligned_in_smp;
19894 +/* au_pin flags */
19895 +#define AuPin_DI_LOCKED 1
19896 +#define AuPin_MNT_WRITE (1 << 1)
19897 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19898 +#define au_fset_pin(flags, name) \
19899 + do { (flags) |= AuPin_##name; } while (0)
19900 +#define au_fclr_pin(flags, name) \
19901 + do { (flags) &= ~AuPin_##name; } while (0)
19905 + struct dentry *dentry;
19906 + unsigned int udba;
19907 + unsigned char lsc_di, lsc_hi, flags;
19908 + aufs_bindex_t bindex;
19911 + struct dentry *parent;
19912 + struct au_hinode *hdir;
19913 + struct vfsmount *h_mnt;
19915 + /* temporary unlock/relock for copyup */
19916 + struct dentry *h_dentry, *h_parent;
19917 + struct au_branch *br;
19918 + struct task_struct *task;
19921 +void au_pin_hdir_unlock(struct au_pin *p);
19922 +int au_pin_hdir_lock(struct au_pin *p);
19923 +int au_pin_hdir_relock(struct au_pin *p);
19924 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19925 +void au_pin_hdir_release(struct au_pin *p);
19927 +/* ---------------------------------------------------------------------- */
19929 +static inline struct au_iinfo *au_ii(struct inode *inode)
19931 + BUG_ON(is_bad_inode(inode));
19932 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19935 +/* ---------------------------------------------------------------------- */
19938 +struct inode *au_igrab(struct inode *inode);
19939 +void au_refresh_iop(struct inode *inode, int force_getattr);
19940 +int au_refresh_hinode_self(struct inode *inode);
19941 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19942 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19943 + unsigned int d_type, ino_t *ino);
19944 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19945 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19946 + struct inode *inode);
19947 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19949 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19952 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19953 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19955 +#ifdef CONFIG_AUFS_SHWH
19956 + return au_ino(sb, bindex, h_ino, d_type, ino);
19969 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19970 + aufs_iop_nogetattr[AuIop_Last];
19972 +/* au_wr_dir flags */
19973 +#define AuWrDir_ADD_ENTRY 1
19974 +#define AuWrDir_ISDIR (1 << 1)
19975 +#define AuWrDir_TMPFILE (1 << 2)
19976 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
19977 +#define au_fset_wrdir(flags, name) \
19978 + do { (flags) |= AuWrDir_##name; } while (0)
19979 +#define au_fclr_wrdir(flags, name) \
19980 + do { (flags) &= ~AuWrDir_##name; } while (0)
19982 +struct au_wr_dir_args {
19983 + aufs_bindex_t force_btgt;
19984 + unsigned char flags;
19986 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
19987 + struct au_wr_dir_args *args);
19989 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
19990 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
19991 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19992 + unsigned int udba, unsigned char flags);
19993 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19994 + unsigned int udba, unsigned char flags) __must_check;
19995 +int au_do_pin(struct au_pin *pin) __must_check;
19996 +void au_unpin(struct au_pin *pin);
19997 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
19999 +#define AuIcpup_DID_CPUP 1
20000 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20001 +#define au_fset_icpup(flags, name) \
20002 + do { (flags) |= AuIcpup_##name; } while (0)
20003 +#define au_fclr_icpup(flags, name) \
20004 + do { (flags) &= ~AuIcpup_##name; } while (0)
20006 +struct au_icpup_args {
20007 + unsigned char flags;
20008 + unsigned char pin_flags;
20009 + aufs_bindex_t btgt;
20010 + unsigned int udba;
20011 + struct au_pin pin;
20012 + struct path h_path;
20013 + struct inode *h_inode;
20016 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20017 + struct au_icpup_args *a);
20019 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20020 + struct path *h_path, int locked);
20023 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20024 + struct dentry *h_parent, int isdir);
20025 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
20026 + struct dentry *dentry, umode_t mode, dev_t dev);
20027 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
20028 + struct dentry *dentry, const char *symname);
20029 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
20030 + struct dentry *dentry, umode_t mode, bool want_excl);
20031 +struct vfsub_aopen_args;
20032 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20033 + struct vfsub_aopen_args *args);
20034 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
20035 + struct file *file, umode_t mode);
20036 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20037 + struct dentry *dentry);
20038 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
20039 + struct dentry *dentry, umode_t mode);
20042 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20043 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20044 + struct dentry *h_parent, int isdir);
20045 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20046 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20049 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20050 +int aufs_rename(struct mnt_idmap *idmap,
20051 + struct inode *_src_dir, struct dentry *_src_dentry,
20052 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20053 + unsigned int _flags);
20056 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20057 +void au_hiput(struct au_hinode *hinode);
20058 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20059 + struct dentry *h_wh);
20060 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20062 +/* hinode flags */
20063 +#define AuHi_XINO 1
20064 +#define AuHi_HNOTIFY (1 << 1)
20065 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20066 +#define au_fset_hi(flags, name) \
20067 + do { (flags) |= AuHi_##name; } while (0)
20068 +#define au_fclr_hi(flags, name) \
20069 + do { (flags) &= ~AuHi_##name; } while (0)
20071 +#ifndef CONFIG_AUFS_HNOTIFY
20072 +#undef AuHi_HNOTIFY
20073 +#define AuHi_HNOTIFY 0
20076 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20077 + struct inode *h_inode, unsigned int flags);
20079 +void au_update_iigen(struct inode *inode, int half);
20080 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20082 +void au_icntnr_init_once(void *_c);
20083 +void au_hinode_init(struct au_hinode *hinode);
20084 +int au_iinfo_init(struct inode *inode);
20085 +void au_iinfo_fin(struct inode *inode);
20086 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20088 +#ifdef CONFIG_PROC_FS
20090 +int au_plink_maint(struct super_block *sb, int flags);
20092 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20093 +int au_plink_maint_enter(struct super_block *sb);
20094 +#ifdef CONFIG_AUFS_DEBUG
20095 +void au_plink_list(struct super_block *sb);
20097 +AuStubVoid(au_plink_list, struct super_block *sb)
20099 +int au_plink_test(struct inode *inode);
20100 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20101 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20102 + struct dentry *h_dentry);
20103 +void au_plink_put(struct super_block *sb, int verbose);
20104 +void au_plink_clean(struct super_block *sb, int verbose);
20105 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20107 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20108 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20109 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20110 +AuStubVoid(au_plink_list, struct super_block *sb);
20111 +AuStubInt0(au_plink_test, struct inode *inode);
20112 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20113 + struct inode *inode, aufs_bindex_t bindex);
20114 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20115 + struct dentry *h_dentry);
20116 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20117 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20118 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20119 +#endif /* CONFIG_PROC_FS */
20121 +#ifdef CONFIG_AUFS_XATTR
20123 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20124 + unsigned int verbose);
20125 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20126 +void au_xattr_init(struct super_block *sb);
20128 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20129 + int ignore_flags, unsigned int verbose);
20130 +AuStubVoid(au_xattr_init, struct super_block *sb);
20133 +#ifdef CONFIG_FS_POSIX_ACL
20134 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu);
20135 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
20136 + struct dentry *dentry, int type);
20137 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
20138 + struct posix_acl *acl, int type);
20141 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20147 +struct au_sxattr {
20151 + const char *name;
20152 + const void *value;
20157 + struct posix_acl *acl;
20162 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20163 + struct au_sxattr *arg);
20166 +/* ---------------------------------------------------------------------- */
20168 +/* lock subclass for iinfo */
20170 + AuLsc_II_CHILD, /* child first */
20171 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20172 + AuLsc_II_CHILD3, /* copyup dirs */
20173 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20174 + AuLsc_II_PARENT2,
20175 + AuLsc_II_PARENT3, /* copyup dirs */
20176 + AuLsc_II_NEW_CHILD
20180 + * ii_read_lock_child, ii_write_lock_child,
20181 + * ii_read_lock_child2, ii_write_lock_child2,
20182 + * ii_read_lock_child3, ii_write_lock_child3,
20183 + * ii_read_lock_parent, ii_write_lock_parent,
20184 + * ii_read_lock_parent2, ii_write_lock_parent2,
20185 + * ii_read_lock_parent3, ii_write_lock_parent3,
20186 + * ii_read_lock_new_child, ii_write_lock_new_child,
20188 +#define AuReadLockFunc(name, lsc) \
20189 +static inline void ii_read_lock_##name(struct inode *i) \
20191 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20194 +#define AuWriteLockFunc(name, lsc) \
20195 +static inline void ii_write_lock_##name(struct inode *i) \
20197 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20200 +#define AuRWLockFuncs(name, lsc) \
20201 + AuReadLockFunc(name, lsc) \
20202 + AuWriteLockFunc(name, lsc)
20204 +AuRWLockFuncs(child, CHILD);
20205 +AuRWLockFuncs(child2, CHILD2);
20206 +AuRWLockFuncs(child3, CHILD3);
20207 +AuRWLockFuncs(parent, PARENT);
20208 +AuRWLockFuncs(parent2, PARENT2);
20209 +AuRWLockFuncs(parent3, PARENT3);
20210 +AuRWLockFuncs(new_child, NEW_CHILD);
20212 +#undef AuReadLockFunc
20213 +#undef AuWriteLockFunc
20214 +#undef AuRWLockFuncs
20216 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20217 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20218 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20220 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20221 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20222 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20224 +/* ---------------------------------------------------------------------- */
20226 +static inline void au_icntnr_init(struct au_icntnr *c)
20228 +#ifdef CONFIG_AUFS_DEBUG
20229 + c->vfs_inode.i_mode = 0;
20233 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20235 + unsigned int gen;
20236 + struct au_iinfo *iinfo;
20237 + struct au_iigen *iigen;
20239 + iinfo = au_ii(inode);
20240 + iigen = &iinfo->ii_generation;
20241 + spin_lock(&iigen->ig_spin);
20243 + *igflags = iigen->ig_flags;
20244 + gen = iigen->ig_generation;
20245 + spin_unlock(&iigen->ig_spin);
20250 +/* tiny test for inode number */
20251 +/* tmpfs generation is too rough */
20252 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20254 + struct au_iinfo *iinfo;
20256 + iinfo = au_ii(inode);
20257 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20258 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20259 + && iinfo->ii_higen == h_inode->i_generation);
20262 +static inline void au_iigen_dec(struct inode *inode)
20264 + struct au_iinfo *iinfo;
20265 + struct au_iigen *iigen;
20267 + iinfo = au_ii(inode);
20268 + iigen = &iinfo->ii_generation;
20269 + spin_lock(&iigen->ig_spin);
20270 + iigen->ig_generation--;
20271 + spin_unlock(&iigen->ig_spin);
20274 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20279 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20285 +/* ---------------------------------------------------------------------- */
20287 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20288 + aufs_bindex_t bindex)
20290 + return iinfo->ii_hinode + bindex;
20293 +static inline int au_is_bad_inode(struct inode *inode)
20295 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20298 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20299 + aufs_bindex_t bindex)
20301 + IiMustAnyLock(inode);
20302 + return au_hinode(au_ii(inode), bindex)->hi_id;
20305 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20307 + IiMustAnyLock(inode);
20308 + return au_ii(inode)->ii_btop;
20311 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20313 + IiMustAnyLock(inode);
20314 + return au_ii(inode)->ii_bbot;
20317 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20319 + IiMustAnyLock(inode);
20320 + return au_ii(inode)->ii_vdir;
20323 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20325 + IiMustAnyLock(inode);
20326 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20329 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20331 + IiMustWriteLock(inode);
20332 + au_ii(inode)->ii_btop = bindex;
20335 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20337 + IiMustWriteLock(inode);
20338 + au_ii(inode)->ii_bbot = bindex;
20341 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20343 + IiMustWriteLock(inode);
20344 + au_ii(inode)->ii_vdir = vdir;
20347 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20349 + IiMustAnyLock(inode);
20350 + return au_hinode(au_ii(inode), bindex);
20353 +/* ---------------------------------------------------------------------- */
20355 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20358 + return pin->parent;
20362 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20364 + if (pin && pin->hdir)
20365 + return pin->hdir->hi_inode;
20369 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20372 + return pin->hdir;
20376 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20379 + pin->dentry = dentry;
20382 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20383 + unsigned char lflag)
20387 + au_fset_pin(pin->flags, DI_LOCKED);
20389 + au_fclr_pin(pin->flags, DI_LOCKED);
20393 +#if 0 /* reserved */
20394 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20397 + dput(pin->parent);
20398 + pin->parent = dget(parent);
20403 +/* ---------------------------------------------------------------------- */
20406 +#ifdef CONFIG_AUFS_HNOTIFY
20407 +struct au_hnotify_op {
20408 + void (*ctl)(struct au_hinode *hinode, int do_set);
20409 + int (*alloc)(struct au_hinode *hinode);
20412 + * if it returns true, the caller should free hinode->hi_notify,
20413 + * otherwise ->free() frees it.
20415 + int (*free)(struct au_hinode *hinode,
20416 + struct au_hnotify *hn) __must_check;
20418 + void (*fin)(void);
20419 + int (*init)(void);
20421 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20422 + void (*fin_br)(struct au_branch *br);
20423 + int (*init_br)(struct au_branch *br, int perm);
20427 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20428 +void au_hn_free(struct au_hinode *hinode);
20429 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20430 +void au_hn_reset(struct inode *inode, unsigned int flags);
20431 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20432 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20433 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20434 +int au_hnotify_init_br(struct au_branch *br, int perm);
20435 +void au_hnotify_fin_br(struct au_branch *br);
20436 +int __init au_hnotify_init(void);
20437 +void au_hnotify_fin(void);
20440 +extern const struct au_hnotify_op au_hnotify_op;
20443 +void au_hn_init(struct au_hinode *hinode)
20445 + hinode->hi_notify = NULL;
20448 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20450 + return hinode->hi_notify;
20454 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20455 + struct au_hinode *hinode __maybe_unused,
20456 + struct inode *inode __maybe_unused)
20457 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20458 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20459 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20460 + int do_set __maybe_unused)
20461 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20462 + unsigned int flags __maybe_unused)
20463 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20464 + struct au_branch *br __maybe_unused,
20465 + int perm __maybe_unused)
20466 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20467 + int perm __maybe_unused)
20468 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20469 +AuStubInt0(__init au_hnotify_init, void)
20470 +AuStubVoid(au_hnotify_fin, void)
20471 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20472 +#endif /* CONFIG_AUFS_HNOTIFY */
20474 +static inline void au_hn_suspend(struct au_hinode *hdir)
20476 + au_hn_ctl(hdir, /*do_set*/0);
20479 +static inline void au_hn_resume(struct au_hinode *hdir)
20481 + au_hn_ctl(hdir, /*do_set*/1);
20484 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20486 + inode_lock(hdir->hi_inode);
20487 + au_hn_suspend(hdir);
20490 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20491 + unsigned int sc __maybe_unused)
20493 + inode_lock_nested(hdir->hi_inode, sc);
20494 + au_hn_suspend(hdir);
20497 +#if 0 /* unused */
20498 +#include "vfsub.h"
20499 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20502 + inode_lock_shared_nested(hdir->hi_inode, sc);
20503 + au_hn_suspend(hdir);
20507 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20509 + au_hn_resume(hdir);
20510 + inode_unlock(hdir->hi_inode);
20513 +#endif /* __KERNEL__ */
20514 +#endif /* __AUFS_INODE_H__ */
20515 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20516 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20517 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20519 +// SPDX-License-Identifier: GPL-2.0
20521 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20523 + * This program is free software; you can redistribute it and/or modify
20524 + * it under the terms of the GNU General Public License as published by
20525 + * the Free Software Foundation; either version 2 of the License, or
20526 + * (at your option) any later version.
20528 + * This program is distributed in the hope that it will be useful,
20529 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20530 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20531 + * GNU General Public License for more details.
20533 + * You should have received a copy of the GNU General Public License
20534 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20539 + * plink-management and readdir in userspace.
20540 + * assist the pathconf(3) wrapper library.
20542 + * File-based Hierarchical Storage Management.
20545 +#include <linux/compat.h>
20546 +#include <linux/file.h>
20549 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20552 + aufs_bindex_t wbi, bindex, bbot;
20553 + struct file *h_file;
20554 + struct super_block *sb;
20555 + struct dentry *root;
20556 + struct au_branch *br;
20557 + struct aufs_wbr_fd wbrfd = {
20558 + .oflags = au_dir_roflags,
20561 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20562 + | O_NOATIME | O_CLOEXEC;
20564 + AuDebugOn(wbrfd.oflags & ~valid);
20567 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20568 + if (unlikely(err)) {
20574 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20575 + wbrfd.oflags |= au_dir_roflags;
20576 + AuDbg("0%o\n", wbrfd.oflags);
20577 + if (unlikely(wbrfd.oflags & ~valid))
20581 + fd = get_unused_fd_flags(0);
20583 + if (unlikely(fd < 0))
20586 + h_file = ERR_PTR(-EINVAL);
20589 + sb = path->dentry->d_sb;
20590 + root = sb->s_root;
20591 + aufs_read_lock(root, AuLock_IR);
20592 + bbot = au_sbbot(sb);
20593 + if (wbrfd.brid >= 0) {
20594 + wbi = au_br_index(sb, wbrfd.brid);
20595 + if (unlikely(wbi < 0 || wbi > bbot))
20599 + h_file = ERR_PTR(-ENOENT);
20600 + br = au_sbr(sb, wbi);
20601 + if (!au_br_writable(br->br_perm)) {
20605 + bindex = wbi + 1;
20607 + for (; bindex <= bbot; bindex++) {
20608 + br = au_sbr(sb, bindex);
20609 + if (au_br_writable(br->br_perm)) {
20611 + br = au_sbr(sb, wbi);
20616 + AuDbg("wbi %d\n", wbi);
20618 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20622 + aufs_read_unlock(root, AuLock_IR);
20623 + err = PTR_ERR(h_file);
20624 + if (IS_ERR(h_file))
20627 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20628 + fd_install(fd, h_file);
20630 + goto out; /* success */
20633 + put_unused_fd(fd);
20639 +/* ---------------------------------------------------------------------- */
20641 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20644 + struct dentry *dentry;
20647 + case AUFS_CTL_RDU:
20648 + case AUFS_CTL_RDU_INO:
20649 + err = au_rdu_ioctl(file, cmd, arg);
20652 + case AUFS_CTL_WBR_FD:
20653 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20656 + case AUFS_CTL_IBUSY:
20657 + err = au_ibusy_ioctl(file, arg);
20660 + case AUFS_CTL_BRINFO:
20661 + err = au_brinfo_ioctl(file, arg);
20664 + case AUFS_CTL_FHSM_FD:
20665 + dentry = file->f_path.dentry;
20666 + if (IS_ROOT(dentry))
20667 + err = au_fhsm_fd(dentry->d_sb, arg);
20673 + /* do not call the lower */
20674 + AuDbg("0x%x\n", cmd);
20682 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20687 + case AUFS_CTL_MVDOWN:
20688 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20691 + case AUFS_CTL_WBR_FD:
20692 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20696 + /* do not call the lower */
20697 + AuDbg("0x%x\n", cmd);
20705 +#ifdef CONFIG_COMPAT
20706 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20707 + unsigned long arg)
20712 + case AUFS_CTL_RDU:
20713 + case AUFS_CTL_RDU_INO:
20714 + err = au_rdu_compat_ioctl(file, cmd, arg);
20717 + case AUFS_CTL_IBUSY:
20718 + err = au_ibusy_compat_ioctl(file, arg);
20721 + case AUFS_CTL_BRINFO:
20722 + err = au_brinfo_compat_ioctl(file, arg);
20726 + err = aufs_ioctl_dir(file, cmd, arg);
20733 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20734 + unsigned long arg)
20736 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20739 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20740 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20741 +++ linux/fs/aufs/i_op_add.c 2023-08-28 12:34:39.956636132 +0200
20743 +// SPDX-License-Identifier: GPL-2.0
20745 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20747 + * This program is free software; you can redistribute it and/or modify
20748 + * it under the terms of the GNU General Public License as published by
20749 + * the Free Software Foundation; either version 2 of the License, or
20750 + * (at your option) any later version.
20752 + * This program is distributed in the hope that it will be useful,
20753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20755 + * GNU General Public License for more details.
20757 + * You should have received a copy of the GNU General Public License
20758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20762 + * inode operations (add entry)
20765 +#include <linux/iversion.h>
20769 + * final procedure of adding a new entry, except link(2).
20770 + * remove whiteout, instantiate, copyup the parent dir's times and size
20771 + * and update version.
20772 + * if it failed, re-create the removed whiteout.
20774 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20775 + struct dentry *wh_dentry, struct dentry *dentry)
20778 + aufs_bindex_t bwh;
20779 + struct path h_path;
20780 + struct super_block *sb;
20781 + struct inode *inode, *h_dir;
20782 + struct dentry *wh;
20787 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20788 + IMustLock(h_dir);
20789 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20790 + bwh = au_dbwh(dentry);
20791 + h_path.dentry = wh_dentry;
20792 + h_path.mnt = au_sbr_mnt(sb, bindex);
20793 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20795 + if (unlikely(err))
20799 + inode = au_new_inode(dentry, /*must_new*/1);
20800 + if (!IS_ERR(inode)) {
20801 + d_instantiate(dentry, inode);
20802 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20804 + au_dir_ts(dir, bindex);
20805 + inode_inc_iversion(dir);
20806 + au_fhsm_wrote(sb, bindex, /*force*/0);
20807 + return 0; /* success */
20810 + err = PTR_ERR(inode);
20815 + /* dir inode is locked */
20816 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20817 + rerr = PTR_ERR(wh);
20818 + if (IS_ERR(wh)) {
20819 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20820 + dentry, err, rerr);
20829 +static int au_d_may_add(struct dentry *dentry)
20834 + if (unlikely(d_unhashed(dentry)))
20836 + if (unlikely(d_really_is_positive(dentry)))
20842 + * simple tests for the adding inode operations.
20843 + * following the checks in vfs, plus the parent-child relationship.
20845 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20846 + struct dentry *h_parent, int isdir)
20850 + struct dentry *h_dentry;
20851 + struct inode *h_inode;
20853 + err = -ENAMETOOLONG;
20854 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20857 + h_dentry = au_h_dptr(dentry, bindex);
20858 + if (d_really_is_negative(dentry)) {
20860 + if (unlikely(d_is_positive(h_dentry)))
20863 + /* rename(2) case */
20865 + if (unlikely(d_is_negative(h_dentry)))
20867 + h_inode = d_inode(h_dentry);
20868 + if (unlikely(!h_inode->i_nlink))
20871 + h_mode = h_inode->i_mode;
20874 + if (unlikely(S_ISDIR(h_mode)))
20876 + } else if (unlikely(!S_ISDIR(h_mode))) {
20883 + /* expected parent dir is locked */
20884 + if (unlikely(h_parent != h_dentry->d_parent))
20893 + * initial procedure of adding a new entry.
20894 + * prepare writable branch and the parent dir, lock it,
20895 + * and lookup whiteout for the new entry.
20897 +static struct dentry*
20898 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20899 + struct dentry *src_dentry, struct au_pin *pin,
20900 + struct au_wr_dir_args *wr_dir_args)
20902 + struct dentry *wh_dentry, *h_parent;
20903 + struct super_block *sb;
20904 + struct au_branch *br;
20906 + unsigned int udba;
20907 + aufs_bindex_t bcpup;
20909 + AuDbg("%pd\n", dentry);
20911 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20913 + wh_dentry = ERR_PTR(err);
20914 + if (unlikely(err < 0))
20917 + sb = dentry->d_sb;
20918 + udba = au_opt_udba(sb);
20919 + err = au_pin(pin, dentry, bcpup, udba,
20920 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20921 + wh_dentry = ERR_PTR(err);
20922 + if (unlikely(err))
20925 + h_parent = au_pinned_h_parent(pin);
20926 + if (udba != AuOpt_UDBA_NONE
20927 + && au_dbtop(dentry) == bcpup)
20928 + err = au_may_add(dentry, bcpup, h_parent,
20929 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20930 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20931 + err = -ENAMETOOLONG;
20932 + wh_dentry = ERR_PTR(err);
20933 + if (unlikely(err))
20936 + br = au_sbr(sb, bcpup);
20938 + struct path tmp = {
20939 + .dentry = h_parent,
20940 + .mnt = au_br_mnt(br)
20942 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20945 + wh_dentry = NULL;
20946 + if (bcpup != au_dbwh(dentry))
20947 + goto out; /* success */
20950 + * ENAMETOOLONG here means that if we allowed create such name, then it
20951 + * would not be able to removed in the future. So we don't allow such
20952 + * name here and we don't handle ENAMETOOLONG differently here.
20954 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20957 + if (IS_ERR(wh_dentry))
20960 + return wh_dentry;
20963 +/* ---------------------------------------------------------------------- */
20965 +enum { Mknod, Symlink, Creat };
20966 +struct simple_arg {
20973 + struct vfsub_aopen_args *aopen;
20976 + const char *symname;
20985 +static int add_simple(struct inode *dir, struct dentry *dentry,
20986 + struct simple_arg *arg)
20989 + aufs_bindex_t btop;
20990 + unsigned char created;
20991 + const unsigned char try_aopen
20992 + = (arg->type == Creat && arg->u.c.try_aopen);
20993 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
20994 + struct dentry *wh_dentry, *parent;
20995 + struct inode *h_dir;
20996 + struct super_block *sb;
20997 + struct au_branch *br;
20998 + /* to reduce stack size */
21000 + struct au_dtime dt;
21001 + struct au_pin pin;
21002 + struct path h_path;
21003 + struct au_wr_dir_args wr_dir_args;
21006 + AuDbg("%pd\n", dentry);
21010 + a = kmalloc(sizeof(*a), GFP_NOFS);
21011 + if (unlikely(!a))
21013 + a->wr_dir_args.force_btgt = -1;
21014 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21016 + parent = dentry->d_parent; /* dir inode is locked */
21017 + if (!try_aopen) {
21018 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21019 + if (unlikely(err))
21022 + err = au_d_may_add(dentry);
21023 + if (unlikely(err))
21026 + di_write_lock_parent(parent);
21027 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21028 + &a->pin, &a->wr_dir_args);
21029 + err = PTR_ERR(wh_dentry);
21030 + if (IS_ERR(wh_dentry))
21033 + btop = au_dbtop(dentry);
21034 + sb = dentry->d_sb;
21035 + br = au_sbr(sb, btop);
21036 + a->h_path.dentry = au_h_dptr(dentry, btop);
21037 + a->h_path.mnt = au_br_mnt(br);
21038 + h_dir = au_pinned_h_dir(&a->pin);
21039 + switch (arg->type) {
21041 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21042 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21043 + arg->u.c.want_excl);
21045 + if (!err && try_aopen)
21046 + aopen->file->f_mode |= FMODE_CREATED;
21049 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21050 + AuDbg("err %d\n", err);
21051 + AuDbgFile(aopen->file);
21052 + created = err >= 0
21053 + && !!(aopen->file->f_mode & FMODE_CREATED);
21057 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21061 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21068 + if (unlikely(err < 0))
21071 + err = epilog(dir, btop, wh_dentry, dentry);
21073 + goto out_unpin; /* success */
21076 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21077 + /* no delegation since it is just created */
21078 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21081 + AuIOErr("%pd revert failure(%d, %d)\n",
21082 + dentry, err, rerr);
21085 + au_dtime_revert(&a->dt);
21087 + if (try_aopen && h_dir->i_op->atomic_open
21088 + && (aopen->file->f_mode & FMODE_OPENED))
21089 + /* aopen->file is still opened */
21090 + au_lcnt_dec(&aopen->br->br_nfiles);
21093 + au_unpin(&a->pin);
21097 + di_write_unlock(parent);
21099 + if (unlikely(err)) {
21100 + au_update_dbtop(dentry);
21104 + aufs_read_unlock(dentry, AuLock_DW);
21111 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
21112 + struct dentry *dentry, umode_t mode, dev_t dev)
21114 + struct simple_arg arg = {
21121 + return add_simple(dir, dentry, &arg);
21124 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
21125 + struct dentry *dentry, const char *symname)
21127 + struct simple_arg arg = {
21129 + .u.s.symname = symname
21131 + return add_simple(dir, dentry, &arg);
21134 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
21135 + struct dentry *dentry, umode_t mode, bool want_excl)
21137 + struct simple_arg arg = {
21141 + .want_excl = want_excl
21144 + return add_simple(dir, dentry, &arg);
21147 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21148 + struct vfsub_aopen_args *aopen_args)
21150 + struct simple_arg arg = {
21153 + .mode = aopen_args->create_mode,
21154 + .want_excl = aopen_args->open_flag & O_EXCL,
21155 + .try_aopen = true,
21156 + .aopen = aopen_args
21159 + return add_simple(dir, dentry, &arg);
21162 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
21163 + struct file *file, umode_t mode)
21166 + aufs_bindex_t bindex;
21167 + struct path h_ppath;
21168 + struct super_block *sb;
21169 + struct au_branch *br;
21170 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21171 + struct inode *h_dir, *inode;
21172 + struct vfsmount *h_mnt;
21173 + struct mnt_idmap *h_idmap;
21174 + struct file *h_file;
21175 + struct au_wr_dir_args wr_dir_args = {
21176 + .force_btgt = -1,
21177 + .flags = AuWrDir_TMPFILE
21180 + /* copy-up may happen */
21185 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21186 + if (unlikely(err))
21189 + dentry = file->f_path.dentry;
21190 + err = au_di_init(dentry);
21191 + if (unlikely(err))
21195 + parent = d_find_any_alias(dir);
21196 + AuDebugOn(!parent);
21197 + di_write_lock_parent(parent);
21198 + if (unlikely(d_inode(parent) != dir))
21201 + err = au_digen_test(parent, au_sigen(sb));
21202 + if (unlikely(err))
21205 + bindex = au_dbtop(parent);
21206 + au_set_dbtop(dentry, bindex);
21207 + au_set_dbbot(dentry, bindex);
21208 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21210 + if (unlikely(err < 0))
21213 + err = -EOPNOTSUPP;
21214 + h_dir = au_h_iptr(dir, bindex);
21215 + if (unlikely(!h_dir->i_op->tmpfile))
21218 + br = au_sbr(sb, bindex);
21219 + h_mnt = au_br_mnt(br);
21220 + err = vfsub_mnt_want_write(h_mnt);
21221 + if (unlikely(err))
21224 + h_idmap = mnt_idmap(h_mnt);
21225 + h_parent = au_h_dptr(parent, bindex);
21226 + h_ppath.mnt = h_mnt;
21227 + h_ppath.dentry = h_parent;
21228 + h_file = kernel_tmpfile_open(h_idmap, &h_ppath, mode, /*open_flag*/0,
21230 + if (IS_ERR(h_file)) {
21231 + err = PTR_ERR(h_file);
21236 + h_dentry = h_file->f_path.dentry;
21237 + au_set_dbtop(dentry, bindex);
21238 + au_set_dbbot(dentry, bindex);
21239 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21240 + inode = au_new_inode(dentry, /*must_new*/1);
21241 + if (IS_ERR(inode)) {
21242 + err = PTR_ERR(inode);
21243 + au_set_h_dptr(dentry, bindex, NULL);
21244 + au_set_dbtop(dentry, -1);
21245 + au_set_dbbot(dentry, -1);
21249 + if (!inode->i_nlink)
21250 + set_nlink(inode, 1);
21251 + d_tmpfile(file, inode);
21252 + au_di(dentry)->di_tmpfile = 1;
21253 + get_file(h_file);
21254 + au_di(dentry)->di_htmpfile = h_file;
21256 + /* update without i_mutex */
21257 + if (au_ibtop(dir) == au_dbtop(dentry))
21258 + au_cpup_attr_timesizes(dir);
21263 + vfsub_mnt_drop_write(h_mnt);
21265 + di_write_unlock(parent);
21267 + di_write_unlock(dentry);
21272 + au_di(dentry)->di_htmpfile = NULL;
21273 + au_di_fin(dentry);
21274 + dentry->d_fsdata = NULL;
21276 + si_read_unlock(sb);
21277 + if (!err && h_file) {
21279 + err = finish_open_simple(file, err);
21281 + au_lcnt_inc(&br->br_nfiles);
21284 + au_di(dentry)->di_htmpfile = NULL;
21285 + au_di_fin(dentry);
21286 + dentry->d_fsdata = NULL;
21290 + inode_unlock(dir);
21295 +/* ---------------------------------------------------------------------- */
21297 +struct au_link_args {
21298 + aufs_bindex_t bdst, bsrc;
21299 + struct au_pin pin;
21300 + struct path h_path;
21301 + struct dentry *src_parent, *parent;
21304 +static int au_cpup_before_link(struct dentry *src_dentry,
21305 + struct au_link_args *a)
21308 + struct dentry *h_src_dentry;
21309 + struct au_cp_generic cpg = {
21310 + .dentry = src_dentry,
21315 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21318 + di_read_lock_parent(a->src_parent, AuLock_IR);
21319 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21320 + if (unlikely(err))
21323 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21324 + err = au_pin(&a->pin, src_dentry, a->bdst,
21325 + au_opt_udba(src_dentry->d_sb),
21326 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21327 + if (unlikely(err))
21330 + err = au_sio_cpup_simple(&cpg);
21331 + au_unpin(&a->pin);
21334 + di_read_unlock(a->src_parent, AuLock_IR);
21338 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21339 + struct au_link_args *a)
21342 + unsigned char plink;
21343 + aufs_bindex_t bbot;
21344 + struct dentry *h_src_dentry;
21345 + struct inode *h_inode, *inode, *delegated;
21346 + struct super_block *sb;
21347 + struct file *h_file;
21351 + sb = src_dentry->d_sb;
21352 + inode = d_inode(src_dentry);
21353 + if (au_ibtop(inode) <= a->bdst)
21354 + h_inode = au_h_iptr(inode, a->bdst);
21355 + if (!h_inode || !h_inode->i_nlink) {
21356 + /* copyup src_dentry as the name of dentry. */
21357 + bbot = au_dbbot(dentry);
21358 + if (bbot < a->bsrc)
21359 + au_set_dbbot(dentry, a->bsrc);
21360 + au_set_h_dptr(dentry, a->bsrc,
21361 + dget(au_h_dptr(src_dentry, a->bsrc)));
21362 + dget(a->h_path.dentry);
21363 + au_set_h_dptr(dentry, a->bdst, NULL);
21364 + AuDbg("temporary d_inode...\n");
21365 + spin_lock(&dentry->d_lock);
21366 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21367 + spin_unlock(&dentry->d_lock);
21368 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21369 + if (IS_ERR(h_file))
21370 + err = PTR_ERR(h_file);
21372 + struct au_cp_generic cpg = {
21373 + .dentry = dentry,
21378 + .flags = AuCpup_KEEPLINO
21380 + err = au_sio_cpup_simple(&cpg);
21381 + au_h_open_post(dentry, a->bsrc, h_file);
21383 + dput(a->h_path.dentry);
21384 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21386 + au_set_h_dptr(dentry, a->bdst,
21387 + a->h_path.dentry);
21389 + spin_lock(&dentry->d_lock);
21390 + dentry->d_inode = NULL; /* restore */
21391 + spin_unlock(&dentry->d_lock);
21392 + AuDbg("temporary d_inode...done\n");
21393 + au_set_h_dptr(dentry, a->bsrc, NULL);
21394 + au_set_dbbot(dentry, bbot);
21396 + /* the inode of src_dentry already exists on a.bdst branch */
21397 + h_src_dentry = d_find_alias(h_inode);
21398 + if (!h_src_dentry && au_plink_test(inode)) {
21400 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21401 + err = PTR_ERR(h_src_dentry);
21402 + if (IS_ERR(h_src_dentry))
21405 + if (unlikely(d_is_negative(h_src_dentry))) {
21406 + dput(h_src_dentry);
21407 + h_src_dentry = NULL;
21411 + if (h_src_dentry) {
21412 + delegated = NULL;
21413 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21414 + &a->h_path, &delegated);
21415 + if (unlikely(err == -EWOULDBLOCK)) {
21416 + pr_warn("cannot retry for NFSv4 delegation"
21417 + " for an internal link\n");
21420 + dput(h_src_dentry);
21422 + AuIOErr("no dentry found for hi%lu on b%d\n",
21423 + h_inode->i_ino, a->bdst);
21428 + if (!err && !plink)
21429 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21436 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21437 + struct dentry *dentry)
21440 + struct au_dtime dt;
21441 + struct au_link_args *a;
21442 + struct dentry *wh_dentry, *h_src_dentry;
21443 + struct inode *inode, *delegated;
21444 + struct super_block *sb;
21445 + struct au_wr_dir_args wr_dir_args = {
21446 + /* .force_btgt = -1, */
21447 + .flags = AuWrDir_ADD_ENTRY
21451 + inode = d_inode(src_dentry);
21452 + IMustLock(inode);
21455 + a = kzalloc(sizeof(*a), GFP_NOFS);
21456 + if (unlikely(!a))
21459 + a->parent = dentry->d_parent; /* dir inode is locked */
21460 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21461 + AuLock_NOPLM | AuLock_GEN);
21462 + if (unlikely(err))
21464 + err = au_d_linkable(src_dentry);
21465 + if (unlikely(err))
21467 + err = au_d_may_add(dentry);
21468 + if (unlikely(err))
21471 + a->src_parent = dget_parent(src_dentry);
21472 + wr_dir_args.force_btgt = au_ibtop(inode);
21474 + di_write_lock_parent(a->parent);
21475 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21476 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21478 + err = PTR_ERR(wh_dentry);
21479 + if (IS_ERR(wh_dentry))
21483 + sb = dentry->d_sb;
21484 + a->bdst = au_dbtop(dentry);
21485 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21486 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21487 + a->bsrc = au_ibtop(inode);
21488 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21489 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21490 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21491 + if (!h_src_dentry) {
21492 + a->bsrc = au_dbtop(src_dentry);
21493 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21494 + AuDebugOn(!h_src_dentry);
21495 + } else if (IS_ERR(h_src_dentry)) {
21496 + err = PTR_ERR(h_src_dentry);
21501 + * aufs doesn't touch the credential so
21502 + * security_dentry_create_files_as() is unnecessary.
21504 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21505 + if (a->bdst < a->bsrc
21506 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21507 + err = au_cpup_or_link(src_dentry, dentry, a);
21509 + delegated = NULL;
21510 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21511 + &a->h_path, &delegated);
21512 + if (unlikely(err == -EWOULDBLOCK)) {
21513 + pr_warn("cannot retry for NFSv4 delegation"
21514 + " for an internal link\n");
21518 + dput(h_src_dentry);
21521 + * copyup src_dentry to the branch we process,
21522 + * and then link(2) to it.
21524 + dput(h_src_dentry);
21525 + if (a->bdst < a->bsrc
21526 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21527 + au_unpin(&a->pin);
21528 + di_write_unlock(a->parent);
21529 + err = au_cpup_before_link(src_dentry, a);
21530 + di_write_lock_parent(a->parent);
21532 + err = au_pin(&a->pin, dentry, a->bdst,
21534 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21535 + if (unlikely(err))
21539 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21541 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21542 + delegated = NULL;
21543 + err = vfsub_link(h_src_dentry,
21544 + au_pinned_h_dir(&a->pin),
21545 + &a->h_path, &delegated);
21546 + if (unlikely(err == -EWOULDBLOCK)) {
21547 + pr_warn("cannot retry"
21548 + " for NFSv4 delegation"
21549 + " for an internal link\n");
21555 + if (unlikely(err))
21559 + a->h_path.dentry = wh_dentry;
21560 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21562 + if (unlikely(err))
21566 + au_dir_ts(dir, a->bdst);
21567 + inode_inc_iversion(dir);
21568 + inc_nlink(inode);
21569 + inode->i_ctime = dir->i_ctime;
21570 + d_instantiate(dentry, au_igrab(inode));
21571 + if (d_unhashed(a->h_path.dentry))
21572 + /* some filesystem calls d_drop() */
21574 + /* some filesystems consume an inode even hardlink */
21575 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21576 + goto out_unpin; /* success */
21579 + /* no delegation since it is just created */
21580 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21581 + /*delegated*/NULL, /*force*/0);
21582 + if (unlikely(rerr)) {
21583 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21586 + au_dtime_revert(&dt);
21588 + au_unpin(&a->pin);
21592 + di_write_unlock(a->parent);
21593 + dput(a->src_parent);
21595 + if (unlikely(err)) {
21596 + au_update_dbtop(dentry);
21599 + aufs_read_and_write_unlock2(dentry, src_dentry);
21607 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
21608 + struct dentry *dentry, umode_t mode)
21611 + aufs_bindex_t bindex;
21612 + unsigned char diropq;
21613 + struct path h_path;
21614 + struct dentry *wh_dentry, *parent, *opq_dentry;
21615 + struct inode *h_inode;
21616 + struct super_block *sb;
21618 + struct au_pin pin;
21619 + struct au_dtime dt;
21620 + } *a; /* reduce the stack usage */
21621 + struct au_wr_dir_args wr_dir_args = {
21622 + .force_btgt = -1,
21623 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21629 + a = kmalloc(sizeof(*a), GFP_NOFS);
21630 + if (unlikely(!a))
21633 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21634 + if (unlikely(err))
21636 + err = au_d_may_add(dentry);
21637 + if (unlikely(err))
21640 + parent = dentry->d_parent; /* dir inode is locked */
21641 + di_write_lock_parent(parent);
21642 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21643 + &a->pin, &wr_dir_args);
21644 + err = PTR_ERR(wh_dentry);
21645 + if (IS_ERR(wh_dentry))
21648 + sb = dentry->d_sb;
21649 + bindex = au_dbtop(dentry);
21650 + h_path.dentry = au_h_dptr(dentry, bindex);
21651 + h_path.mnt = au_sbr_mnt(sb, bindex);
21652 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21653 + if (unlikely(err))
21656 + /* make the dir opaque */
21658 + h_inode = d_inode(h_path.dentry);
21660 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21661 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21662 + opq_dentry = au_diropq_create(dentry, bindex);
21663 + inode_unlock(h_inode);
21664 + err = PTR_ERR(opq_dentry);
21665 + if (IS_ERR(opq_dentry))
21667 + dput(opq_dentry);
21671 + err = epilog(dir, bindex, wh_dentry, dentry);
21674 + goto out_unpin; /* success */
21679 + AuLabel(revert opq);
21680 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21681 + rerr = au_diropq_remove(dentry, bindex);
21682 + inode_unlock(h_inode);
21684 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21685 + dentry, err, rerr);
21691 + AuLabel(revert dir);
21692 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21694 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21695 + dentry, err, rerr);
21698 + au_dtime_revert(&a->dt);
21700 + au_unpin(&a->pin);
21703 + di_write_unlock(parent);
21705 + if (unlikely(err)) {
21706 + au_update_dbtop(dentry);
21709 + aufs_read_unlock(dentry, AuLock_DW);
21715 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21716 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21717 +++ linux/fs/aufs/i_op.c 2023-08-28 12:34:39.956636132 +0200
21719 +// SPDX-License-Identifier: GPL-2.0
21721 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21723 + * This program is free software; you can redistribute it and/or modify
21724 + * it under the terms of the GNU General Public License as published by
21725 + * the Free Software Foundation; either version 2 of the License, or
21726 + * (at your option) any later version.
21728 + * This program is distributed in the hope that it will be useful,
21729 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21730 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21731 + * GNU General Public License for more details.
21733 + * You should have received a copy of the GNU General Public License
21734 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21738 + * inode operations (except add/del/rename)
21741 +#include <linux/device_cgroup.h>
21742 +#include <linux/filelock.h>
21743 +#include <linux/fs_stack.h>
21744 +#include <linux/iversion.h>
21745 +#include <linux/security.h>
21748 +static int h_permission(struct inode *h_inode, int mask,
21749 + struct path *h_path, int brperm)
21752 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21753 + struct mnt_idmap *h_idmap;
21756 + if (write_mask && IS_IMMUTABLE(h_inode))
21760 + if (((mask & MAY_EXEC)
21761 + && S_ISREG(h_inode->i_mode)
21762 + && (path_noexec(h_path)
21763 + || !(h_inode->i_mode & 0111))))
21767 + * - skip the lower fs test in the case of write to ro branch.
21768 + * - nfs dir permission write check is optimized, but a policy for
21769 + * link/rename requires a real check.
21770 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21771 + * in this case, generic_permission() returns -EOPNOTSUPP.
21773 + h_idmap = mnt_idmap(h_path->mnt);
21774 + if ((write_mask && !au_br_writable(brperm))
21775 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21776 + && write_mask && !(mask & MAY_READ))
21777 + || !h_inode->i_op->permission) {
21778 + /* AuLabel(generic_permission); */
21779 + /* AuDbg("get_inode_acl %ps\n",
21780 + h_inode->i_op->get_inode_acl); */
21781 + err = generic_permission(h_idmap, h_inode, mask);
21782 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21783 + err = h_inode->i_op->permission(h_idmap, h_inode,
21787 + /* AuLabel(h_inode->permission); */
21788 + err = h_inode->i_op->permission(h_idmap, h_inode, mask);
21793 + err = devcgroup_inode_permission(h_inode, mask);
21795 + err = security_inode_permission(h_inode, mask);
21801 +static int aufs_permission(struct mnt_idmap *idmap, struct inode *inode,
21805 + aufs_bindex_t bindex, bbot;
21806 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21807 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21808 + struct inode *h_inode;
21809 + struct super_block *sb;
21810 + struct au_branch *br;
21812 + /* todo: support rcu-walk? */
21813 + if (mask & MAY_NOT_BLOCK)
21816 + sb = inode->i_sb;
21817 + si_read_lock(sb, AuLock_FLUSH);
21818 + ii_read_lock_child(inode);
21819 +#if 0 /* reserved for future use */
21821 + * This test may be rather 'too much' since the test is essentially done
21822 + * in the aufs_lookup(). Theoretically it is possible that the inode
21823 + * generation doesn't match to the superblock's here. But it isn't a
21824 + * big deal I suppose.
21826 + err = au_iigen_test(inode, au_sigen(sb));
21827 + if (unlikely(err))
21833 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21834 + err = au_busy_or_stale();
21835 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21836 + if (unlikely(!h_inode
21837 + || (h_inode->i_mode & S_IFMT)
21838 + != (inode->i_mode & S_IFMT)))
21842 + bindex = au_ibtop(inode);
21843 + br = au_sbr(sb, bindex);
21844 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21847 + && !special_file(h_inode->i_mode)) {
21848 + /* test whether the upper writable branch exists */
21850 + for (; bindex >= 0; bindex--)
21851 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21859 + /* non-write to dir */
21861 + bbot = au_ibbot(inode);
21862 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21863 + h_inode = au_h_iptr(inode, bindex);
21865 + err = au_busy_or_stale();
21866 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21869 + br = au_sbr(sb, bindex);
21870 + err = h_permission(h_inode, mask, &br->br_path,
21876 + ii_read_unlock(inode);
21877 + si_read_unlock(sb);
21881 +/* ---------------------------------------------------------------------- */
21883 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21884 + unsigned int flags)
21886 + struct dentry *ret, *parent;
21887 + struct inode *inode;
21888 + struct super_block *sb;
21889 + int err, npositive;
21893 + /* todo: support rcu-walk? */
21894 + ret = ERR_PTR(-ECHILD);
21895 + if (flags & LOOKUP_RCU)
21898 + ret = ERR_PTR(-ENAMETOOLONG);
21899 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21903 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21904 + ret = ERR_PTR(err);
21905 + if (unlikely(err))
21908 + err = au_di_init(dentry);
21909 + ret = ERR_PTR(err);
21910 + if (unlikely(err))
21914 + npositive = 0; /* suppress a warning */
21915 + parent = dentry->d_parent; /* dir inode is locked */
21916 + di_read_lock_parent(parent, AuLock_IR);
21917 + err = au_alive_dir(parent);
21919 + err = au_digen_test(parent, au_sigen(sb));
21921 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21922 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21923 + AuLkup_ALLOW_NEG);
21926 + di_read_unlock(parent, AuLock_IR);
21927 + ret = ERR_PTR(err);
21928 + if (unlikely(err < 0))
21932 + inode = au_new_inode(dentry, /*must_new*/0);
21933 + if (IS_ERR(inode)) {
21934 + ret = (void *)inode;
21941 + atomic_inc(&inode->i_count);
21942 + ret = d_splice_alias(inode, dentry);
21943 +#if 0 /* reserved for future use */
21944 + if (unlikely(d_need_lookup(dentry))) {
21945 + spin_lock(&dentry->d_lock);
21946 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21947 + spin_unlock(&dentry->d_lock);
21951 + if (!IS_ERR(ret)) {
21953 + if (ret && ret != dentry)
21954 + ii_write_unlock(inode);
21956 + ii_write_unlock(inode);
21963 + di_write_unlock(dentry);
21965 + si_read_unlock(sb);
21970 +/* ---------------------------------------------------------------------- */
21973 + * very dirty and complicated aufs ->atomic_open().
21974 + * aufs_atomic_open()
21975 + * + au_aopen_or_create()
21977 + * + vfsub_atomic_open()
21978 + * + branch fs ->atomic_open()
21979 + * may call the actual 'open' for h_file
21980 + * + inc br_nfiles only if opened
21981 + * + au_aopen_no_open() or au_aopen_do_open()
21983 + * au_aopen_do_open()
21984 + * + finish_open()
21985 + * + au_do_aopen()
21986 + * + au_do_open() the body of all 'open'
21987 + * + au_do_open_nondir()
21988 + * set the passed h_file
21990 + * au_aopen_no_open()
21991 + * + finish_no_open()
21994 +struct aopen_node {
21995 + struct hlist_bl_node hblist;
21996 + struct file *file, *h_file;
21999 +static int au_do_aopen(struct inode *inode, struct file *file)
22001 + struct hlist_bl_head *aopen;
22002 + struct hlist_bl_node *pos;
22003 + struct aopen_node *node;
22004 + struct au_do_open_args args = {
22006 + .open = au_do_open_nondir
22009 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22010 + hlist_bl_lock(aopen);
22011 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22012 + if (node->file == file) {
22013 + args.h_file = node->h_file;
22016 + hlist_bl_unlock(aopen);
22017 + /* AuDebugOn(!args.h_file); */
22019 + return au_do_open(file, &args);
22022 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22023 + struct aopen_node *aopen_node)
22026 + struct hlist_bl_head *aopen;
22029 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22030 + au_hbl_add(&aopen_node->hblist, aopen);
22031 + err = finish_open(file, dentry, au_do_aopen);
22032 + au_hbl_del(&aopen_node->hblist, aopen);
22033 + /* AuDbgFile(file); */
22034 + AuDbg("%pd%s%s\n", dentry,
22035 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22036 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22042 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22048 + err = finish_no_open(file, dentry);
22054 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22055 + struct file *file, unsigned int open_flag,
22056 + umode_t create_mode)
22058 + int err, did_open;
22059 + unsigned int lkup_flags;
22060 + aufs_bindex_t bindex;
22061 + struct super_block *sb;
22062 + struct dentry *parent, *d;
22063 + struct vfsub_aopen_args args = {
22064 + .open_flag = open_flag,
22065 + .create_mode = create_mode
22067 + struct aopen_node aopen_node = {
22072 + AuDbg("open_flag 0%o\n", open_flag);
22073 + AuDbgDentry(dentry);
22076 + if (!au_di(dentry)) {
22077 + lkup_flags = LOOKUP_OPEN;
22078 + if (open_flag & O_CREAT)
22079 + lkup_flags |= LOOKUP_CREATE;
22080 + d = aufs_lookup(dir, dentry, lkup_flags);
22082 + err = PTR_ERR(d);
22087 + * obsoleted dentry found.
22088 + * another error will be returned later.
22094 + AuDbgDentry(dentry);
22097 + if (d_is_positive(dentry)
22098 + || d_unhashed(dentry)
22099 + || d_unlinked(dentry)
22100 + || !(open_flag & O_CREAT)) {
22101 + err = au_aopen_no_open(file, dentry);
22102 + goto out; /* success */
22105 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22106 + if (unlikely(err))
22109 + sb = dentry->d_sb;
22110 + parent = dentry->d_parent; /* dir is locked */
22111 + di_write_lock_parent(parent);
22112 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22113 + if (unlikely(err < 0))
22116 + AuDbgDentry(dentry);
22117 + if (d_is_positive(dentry)) {
22118 + err = au_aopen_no_open(file, dentry);
22119 + goto out_parent; /* success */
22122 + args.file = alloc_empty_file(file->f_flags, current_cred());
22123 + err = PTR_ERR(args.file);
22124 + if (IS_ERR(args.file))
22127 + bindex = au_dbtop(dentry);
22128 + err = au_aopen_or_create(dir, dentry, &args);
22130 + AuDbgFile(args.file);
22131 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22132 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22135 + args.file = NULL;
22137 + di_write_unlock(parent);
22138 + di_write_unlock(dentry);
22139 + if (unlikely(err < 0)) {
22146 + err = au_aopen_no_open(file, dentry);
22148 + aopen_node.h_file = args.file;
22149 + err = au_aopen_do_open(file, dentry, &aopen_node);
22151 + if (unlikely(err < 0)) {
22155 + au_lcnt_dec(&args.br->br_nfiles);
22157 + goto out_sb; /* success */
22160 + di_write_unlock(parent);
22161 + di_write_unlock(dentry);
22163 + si_read_unlock(sb);
22171 +/* ---------------------------------------------------------------------- */
22173 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22174 + const unsigned char add_entry, aufs_bindex_t bcpup,
22175 + aufs_bindex_t btop)
22178 + struct dentry *h_parent;
22179 + struct inode *h_dir;
22182 + IMustLock(d_inode(parent));
22184 + di_write_lock_parent(parent);
22187 + if (!au_h_dptr(parent, bcpup)) {
22188 + if (btop > bcpup)
22189 + err = au_cpup_dirs(dentry, bcpup);
22190 + else if (btop < bcpup)
22191 + err = au_cpdown_dirs(dentry, bcpup);
22195 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22196 + h_parent = au_h_dptr(parent, bcpup);
22197 + h_dir = d_inode(h_parent);
22198 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22199 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22200 + /* todo: no unlock here */
22201 + inode_unlock_shared(h_dir);
22203 + AuDbg("bcpup %d\n", bcpup);
22205 + if (d_really_is_negative(dentry))
22206 + au_set_h_dptr(dentry, btop, NULL);
22207 + au_update_dbrange(dentry, /*do_put_zero*/0);
22212 + di_write_unlock(parent);
22214 + err = bcpup; /* success */
22221 + * decide the branch and the parent dir where we will create a new entry.
22222 + * returns new bindex or an error.
22223 + * copyup the parent dir if needed.
22225 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22226 + struct au_wr_dir_args *args)
22229 + unsigned int flags;
22230 + aufs_bindex_t bcpup, btop, src_btop;
22231 + const unsigned char add_entry
22232 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22233 + | au_ftest_wrdir(args->flags, TMPFILE);
22234 + struct super_block *sb;
22235 + struct dentry *parent;
22236 + struct au_sbinfo *sbinfo;
22238 + sb = dentry->d_sb;
22239 + sbinfo = au_sbi(sb);
22240 + parent = dget_parent(dentry);
22241 + btop = au_dbtop(dentry);
22243 + if (args->force_btgt < 0) {
22244 + if (src_dentry) {
22245 + src_btop = au_dbtop(src_dentry);
22246 + if (src_btop < btop)
22247 + bcpup = src_btop;
22248 + } else if (add_entry) {
22250 + if (au_ftest_wrdir(args->flags, ISDIR))
22251 + au_fset_wbr(flags, DIR);
22252 + err = AuWbrCreate(sbinfo, dentry, flags);
22256 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22258 + err = AuWbrCopyup(sbinfo, dentry);
22260 + if (!IS_ROOT(dentry)) {
22261 + di_read_lock_parent(parent, !AuLock_IR);
22262 + err = AuWbrCopyup(sbinfo, dentry);
22263 + di_read_unlock(parent, !AuLock_IR);
22265 + err = AuWbrCopyup(sbinfo, dentry);
22268 + if (unlikely(err < 0))
22272 + bcpup = args->force_btgt;
22273 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22276 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22278 + if (bcpup == btop)
22279 + goto out; /* success */
22281 + /* copyup the new parent into the branch we process */
22282 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22284 + if (d_really_is_negative(dentry)) {
22285 + au_set_h_dptr(dentry, btop, NULL);
22286 + au_set_dbtop(dentry, bcpup);
22287 + au_set_dbbot(dentry, bcpup);
22289 + AuDebugOn(add_entry
22290 + && !au_ftest_wrdir(args->flags, TMPFILE)
22291 + && !au_h_dptr(dentry, bcpup));
22299 +/* ---------------------------------------------------------------------- */
22301 +void au_pin_hdir_unlock(struct au_pin *p)
22304 + au_hn_inode_unlock(p->hdir);
22307 +int au_pin_hdir_lock(struct au_pin *p)
22315 + /* even if an error happens later, keep this lock */
22316 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22319 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22324 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22325 + p->h_parent, p->br);
22331 +int au_pin_hdir_relock(struct au_pin *p)
22334 + struct inode *h_i;
22335 + struct dentry *h_d[] = {
22340 + err = au_pin_hdir_lock(p);
22341 + if (unlikely(err))
22344 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22347 + if (d_is_positive(h_d[i])) {
22348 + h_i = d_inode(h_d[i]);
22349 + err = !h_i->i_nlink;
22357 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22359 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22362 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22365 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22366 + p->lsc_hi, 0, NULL, _RET_IP_);
22367 + au_pin_hdir_set_owner(p, current);
22371 +void au_pin_hdir_release(struct au_pin *p)
22374 + au_pin_hdir_set_owner(p, p->task);
22375 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22379 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22381 + if (pin && pin->parent)
22382 + return au_h_dptr(pin->parent, pin->bindex);
22386 +void au_unpin(struct au_pin *p)
22389 + au_pin_hdir_unlock(p);
22390 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22391 + vfsub_mnt_drop_write(p->h_mnt);
22395 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22396 + di_read_unlock(p->parent, AuLock_IR);
22397 + iput(p->hdir->hi_inode);
22399 + p->parent = NULL;
22402 + /* do not clear p->task */
22405 +int au_do_pin(struct au_pin *p)
22408 + struct super_block *sb;
22409 + struct inode *h_dir;
22412 + sb = p->dentry->d_sb;
22413 + p->br = au_sbr(sb, p->bindex);
22414 + if (IS_ROOT(p->dentry)) {
22415 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22416 + p->h_mnt = au_br_mnt(p->br);
22417 + err = vfsub_mnt_want_write(p->h_mnt);
22418 + if (unlikely(err)) {
22419 + au_fclr_pin(p->flags, MNT_WRITE);
22426 + p->h_dentry = NULL;
22427 + if (p->bindex <= au_dbbot(p->dentry))
22428 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22430 + p->parent = dget_parent(p->dentry);
22431 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22432 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22435 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22436 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22438 + h_dir = p->hdir->hi_inode;
22442 + * if DI_LOCKED is not set, then p->parent may be different
22443 + * and h_parent can be NULL.
22445 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22447 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22448 + di_read_unlock(p->parent, AuLock_IR);
22450 + p->parent = NULL;
22454 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22455 + p->h_mnt = au_br_mnt(p->br);
22456 + err = vfsub_mnt_want_write(p->h_mnt);
22457 + if (unlikely(err)) {
22458 + au_fclr_pin(p->flags, MNT_WRITE);
22459 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22460 + di_read_unlock(p->parent, AuLock_IR);
22462 + p->parent = NULL;
22468 + err = au_pin_hdir_lock(p);
22470 + goto out; /* success */
22475 + pr_err("err %d\n", err);
22476 + err = au_busy_or_stale();
22481 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22482 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22483 + unsigned int udba, unsigned char flags)
22485 + p->dentry = dentry;
22487 + p->lsc_di = lsc_di;
22488 + p->lsc_hi = lsc_hi;
22489 + p->flags = flags;
22490 + p->bindex = bindex;
22492 + p->parent = NULL;
22496 + p->h_dentry = NULL;
22497 + p->h_parent = NULL;
22499 + p->task = current;
22502 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22503 + unsigned int udba, unsigned char flags)
22505 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22507 + return au_do_pin(pin);
22510 +/* ---------------------------------------------------------------------- */
22513 + * ->setattr() and ->getattr() are called in various cases.
22514 + * chmod, stat: dentry is revalidated.
22515 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22517 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22519 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22520 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22523 + struct dentry *parent;
22526 + if (au_digen_test(dentry, sigen)) {
22527 + parent = dget_parent(dentry);
22528 + di_read_lock_parent(parent, AuLock_IR);
22529 + err = au_refresh_dentry(dentry, parent);
22530 + di_read_unlock(parent, AuLock_IR);
22538 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22539 + struct au_icpup_args *a)
22543 + aufs_bindex_t btop, ibtop;
22544 + struct dentry *hi_wh, *parent;
22545 + struct inode *inode;
22546 + struct au_wr_dir_args wr_dir_args = {
22547 + .force_btgt = -1,
22551 + if (d_is_dir(dentry))
22552 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22553 + /* plink or hi_wh() case */
22554 + btop = au_dbtop(dentry);
22555 + inode = d_inode(dentry);
22556 + ibtop = au_ibtop(inode);
22557 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22558 + wr_dir_args.force_btgt = ibtop;
22559 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22560 + if (unlikely(err < 0))
22564 + au_fset_icpup(a->flags, DID_CPUP);
22567 + a->pin_flags = AuPin_MNT_WRITE;
22569 + if (!IS_ROOT(dentry)) {
22570 + au_fset_pin(a->pin_flags, DI_LOCKED);
22571 + parent = dget_parent(dentry);
22572 + di_write_lock_parent(parent);
22575 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22576 + if (unlikely(err))
22580 + a->h_path.dentry = au_h_dptr(dentry, btop);
22581 + a->h_inode = d_inode(a->h_path.dentry);
22582 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22583 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22584 + if (ia->ia_size < i_size_read(a->h_inode))
22585 + sz = ia->ia_size;
22586 + inode_unlock_shared(a->h_inode);
22590 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22591 + hi_wh = au_hi_wh(inode, a->btgt);
22593 + struct au_cp_generic cpg = {
22594 + .dentry = dentry,
22600 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22601 + if (unlikely(err))
22603 + hi_wh = au_hi_wh(inode, a->btgt);
22604 + /* todo: revalidate hi_wh? */
22609 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22610 + di_downgrade_lock(parent, AuLock_IR);
22614 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22615 + goto out; /* success */
22617 + if (!d_unhashed(dentry)) {
22618 + struct au_cp_generic cpg = {
22619 + .dentry = dentry,
22624 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22626 + err = au_sio_cpup_simple(&cpg);
22628 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22629 + } else if (!hi_wh)
22630 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22632 + a->h_path.dentry = hi_wh; /* do not dget here */
22635 + a->h_inode = d_inode(a->h_path.dentry);
22637 + goto out; /* success */
22638 + au_unpin(&a->pin);
22641 + di_write_unlock(parent);
22646 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22650 +static int aufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
22651 + struct iattr *ia)
22654 + struct inode *inode, *delegated;
22655 + struct super_block *sb;
22656 + struct file *file;
22657 + struct au_icpup_args *a;
22658 + struct mnt_idmap *h_idmap;
22660 + inode = d_inode(dentry);
22661 + IMustLock(inode);
22663 + err = setattr_prepare(idmap, dentry, ia);
22664 + if (unlikely(err))
22668 + a = kzalloc(sizeof(*a), GFP_NOFS);
22669 + if (unlikely(!a))
22672 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22673 + ia->ia_valid &= ~ATTR_MODE;
22676 + sb = dentry->d_sb;
22677 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22678 + if (unlikely(err))
22681 + if (ia->ia_valid & ATTR_FILE) {
22682 + /* currently ftruncate(2) only */
22683 + AuDebugOn(!d_is_reg(dentry));
22684 + file = ia->ia_file;
22685 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22687 + if (unlikely(err))
22689 + ia->ia_file = au_hf_top(file);
22690 + a->udba = AuOpt_UDBA_NONE;
22692 + /* fchmod() doesn't pass ia_file */
22693 + a->udba = au_opt_udba(sb);
22694 + di_write_lock_child(dentry);
22695 + /* no d_unlinked(), to set UDBA_NONE for root */
22696 + if (d_unhashed(dentry))
22697 + a->udba = AuOpt_UDBA_NONE;
22698 + if (a->udba != AuOpt_UDBA_NONE) {
22699 + AuDebugOn(IS_ROOT(dentry));
22700 + err = au_reval_for_attr(dentry, au_sigen(sb));
22701 + if (unlikely(err))
22706 + err = au_pin_and_icpup(dentry, ia, a);
22707 + if (unlikely(err < 0))
22709 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22710 + ia->ia_file = NULL;
22711 + ia->ia_valid &= ~ATTR_FILE;
22714 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22715 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22716 + == (ATTR_MODE | ATTR_CTIME)) {
22717 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22718 + if (unlikely(err))
22720 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22721 + && (ia->ia_valid & ATTR_CTIME)) {
22722 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22723 + if (unlikely(err))
22727 + if (ia->ia_valid & ATTR_SIZE) {
22730 + if (ia->ia_size < i_size_read(inode))
22732 + truncate_setsize(inode, ia->ia_size);
22735 + if (ia->ia_valid & ATTR_FILE)
22737 + inode_unlock(a->h_inode);
22738 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22739 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22741 + delegated = NULL;
22743 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22745 + err = break_deleg_wait(&delegated);
22753 + * regardless aufs 'acl' option setting.
22754 + * why don't all acl-aware fs call this func from their ->setattr()?
22756 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22757 + h_idmap = mnt_idmap(a->h_path.mnt);
22758 + err = vfsub_acl_chmod(h_idmap, a->h_path.dentry, ia->ia_mode);
22761 + au_cpup_attr_changeable(inode);
22764 + inode_unlock(a->h_inode);
22765 + au_unpin(&a->pin);
22766 + if (unlikely(err))
22767 + au_update_dbtop(dentry);
22769 + di_write_unlock(dentry);
22771 + fi_write_unlock(file);
22772 + ia->ia_file = file;
22773 + ia->ia_valid |= ATTR_FILE;
22776 + si_read_unlock(sb);
22784 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22785 +static int au_h_path_to_set_attr(struct dentry *dentry,
22786 + struct au_icpup_args *a, struct path *h_path)
22789 + struct super_block *sb;
22791 + sb = dentry->d_sb;
22792 + a->udba = au_opt_udba(sb);
22793 + /* no d_unlinked(), to set UDBA_NONE for root */
22794 + if (d_unhashed(dentry))
22795 + a->udba = AuOpt_UDBA_NONE;
22796 + if (a->udba != AuOpt_UDBA_NONE) {
22797 + AuDebugOn(IS_ROOT(dentry));
22798 + err = au_reval_for_attr(dentry, au_sigen(sb));
22799 + if (unlikely(err))
22802 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22803 + if (unlikely(err < 0))
22806 + h_path->dentry = a->h_path.dentry;
22807 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22813 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22814 + struct au_sxattr *arg)
22817 + struct path h_path;
22818 + struct super_block *sb;
22819 + struct au_icpup_args *a;
22820 + struct inode *h_inode;
22821 + struct mnt_idmap *h_idmap;
22823 + IMustLock(inode);
22826 + a = kzalloc(sizeof(*a), GFP_NOFS);
22827 + if (unlikely(!a))
22830 + sb = dentry->d_sb;
22831 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22832 + if (unlikely(err))
22835 + h_path.dentry = NULL; /* silence gcc */
22836 + di_write_lock_child(dentry);
22837 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22838 + if (unlikely(err))
22840 + h_idmap = mnt_idmap(h_path.mnt);
22842 + inode_unlock(a->h_inode);
22843 + switch (arg->type) {
22844 + case AU_XATTR_SET:
22845 + AuDebugOn(d_is_negative(h_path.dentry));
22846 + err = vfsub_setxattr(h_idmap, h_path.dentry,
22847 + arg->u.set.name, arg->u.set.value,
22848 + arg->u.set.size, arg->u.set.flags);
22851 + err = -EOPNOTSUPP;
22852 + h_inode = d_inode(h_path.dentry);
22853 + if (h_inode->i_op->set_acl) {
22854 + /* this will call posix_acl_update_mode */
22855 + err = h_inode->i_op->set_acl(h_idmap, h_path.dentry,
22856 + arg->u.acl_set.acl,
22857 + arg->u.acl_set.type);
22862 + au_cpup_attr_timesizes(inode);
22864 + au_unpin(&a->pin);
22865 + if (unlikely(err))
22866 + au_update_dbtop(dentry);
22869 + di_write_unlock(dentry);
22870 + si_read_unlock(sb);
22879 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22880 + unsigned int nlink)
22884 + inode->i_mode = st->mode;
22885 + /* don't i_[ug]id_write() here */
22886 + inode->i_uid = st->uid;
22887 + inode->i_gid = st->gid;
22888 + inode->i_atime = st->atime;
22889 + inode->i_mtime = st->mtime;
22890 + inode->i_ctime = st->ctime;
22892 + au_cpup_attr_nlink(inode, /*force*/0);
22893 + if (S_ISDIR(inode->i_mode)) {
22894 + n = inode->i_nlink;
22897 + smp_mb(); /* for i_nlink */
22898 + /* 0 can happen */
22899 + set_nlink(inode, n);
22902 + spin_lock(&inode->i_lock);
22903 + inode->i_blocks = st->blocks;
22904 + i_size_write(inode, st->size);
22905 + spin_unlock(&inode->i_lock);
22909 + * common routine for aufs_getattr() and au_getxattr().
22910 + * returns zero or negative (an error).
22911 + * @dentry will be read-locked in success.
22913 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22914 + struct path *h_path, int locked)
22917 + unsigned int mnt_flags, sigen;
22918 + unsigned char udba_none;
22919 + aufs_bindex_t bindex;
22920 + struct super_block *sb, *h_sb;
22922 + h_path->mnt = NULL;
22923 + h_path->dentry = NULL;
22926 + sb = dentry->d_sb;
22927 + mnt_flags = au_mntflags(sb);
22928 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22930 + if (unlikely(locked))
22931 + goto body; /* skip locking dinfo */
22933 + /* support fstat(2) */
22934 + if (!d_unlinked(dentry) && !udba_none) {
22935 + sigen = au_sigen(sb);
22936 + err = au_digen_test(dentry, sigen);
22938 + di_read_lock_child(dentry, AuLock_IR);
22939 + err = au_dbrange_test(dentry);
22940 + if (unlikely(err)) {
22941 + di_read_unlock(dentry, AuLock_IR);
22945 + AuDebugOn(IS_ROOT(dentry));
22946 + di_write_lock_child(dentry);
22947 + err = au_dbrange_test(dentry);
22949 + err = au_reval_for_attr(dentry, sigen);
22951 + di_downgrade_lock(dentry, AuLock_IR);
22953 + di_write_unlock(dentry);
22958 + di_read_lock_child(dentry, AuLock_IR);
22962 + inode = d_inode(dentry);
22963 + if (unlikely(!inode))
22966 + bindex = au_ibtop(inode);
22967 + h_path->mnt = au_sbr_mnt(sb, bindex);
22968 + h_sb = h_path->mnt->mnt_sb;
22970 + && !au_test_fs_bad_iattr(h_sb)
22972 + goto out; /* success */
22974 + if (au_dbtop(dentry) == bindex)
22975 + h_path->dentry = au_h_dptr(dentry, bindex);
22976 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
22977 + h_path->dentry = au_plink_lkup(inode, bindex);
22978 + if (IS_ERR(h_path->dentry))
22979 + /* pretending success */
22980 + h_path->dentry = NULL;
22982 + dput(h_path->dentry);
22989 +static int aufs_getattr(struct mnt_idmap *idmap, const struct path *path,
22990 + struct kstat *st, u32 request, unsigned int query)
22993 + unsigned char positive;
22994 + struct path h_path;
22995 + struct dentry *dentry;
22996 + struct inode *inode;
22997 + struct super_block *sb;
22999 + dentry = path->dentry;
23000 + inode = d_inode(dentry);
23001 + sb = dentry->d_sb;
23002 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23003 + if (unlikely(err))
23005 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23007 + if (unlikely(err))
23009 + if (unlikely(!h_path.dentry))
23010 + /* illegally overlapped or something */
23011 + goto out_fill; /* pretending success */
23013 + positive = d_is_positive(h_path.dentry);
23015 + /* no vfsub version */
23016 + err = vfs_getattr(&h_path, st, request, query);
23019 + au_refresh_iattr(inode, st,
23020 + d_inode(h_path.dentry)->i_nlink);
23021 + goto out_fill; /* success */
23027 + generic_fillattr(idmap, inode, st);
23029 + di_read_unlock(dentry, AuLock_IR);
23031 + si_read_unlock(sb);
23037 +/* ---------------------------------------------------------------------- */
23039 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23040 + struct delayed_call *done)
23043 + struct dentry *h_dentry;
23044 + struct inode *h_inode;
23046 + aufs_bindex_t bindex;
23048 + ret = NULL; /* suppress a warning */
23053 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23054 + if (unlikely(err))
23057 + err = au_d_hashed_positive(dentry);
23058 + if (unlikely(err))
23062 + inode = d_inode(dentry);
23063 + bindex = au_ibtop(inode);
23064 + h_inode = au_h_iptr(inode, bindex);
23065 + if (unlikely(!h_inode->i_op->get_link))
23070 + if (au_dbtop(dentry) <= bindex) {
23071 + h_dentry = au_h_dptr(dentry, bindex);
23076 + h_dentry = d_find_any_alias(h_inode);
23077 + if (IS_ERR(h_dentry)) {
23078 + err = PTR_ERR(h_dentry);
23082 + if (unlikely(!h_dentry))
23086 + AuDbg("%ps\n", h_inode->i_op->get_link);
23087 + AuDbgDentry(h_dentry);
23088 + ret = vfs_get_link(h_dentry, done);
23091 + err = PTR_ERR(ret);
23094 + aufs_read_unlock(dentry, AuLock_IR);
23096 + if (unlikely(err))
23097 + ret = ERR_PTR(err);
23098 + AuTraceErrPtr(ret);
23102 +/* ---------------------------------------------------------------------- */
23104 +static int au_is_special(struct inode *inode)
23106 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23109 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
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, ts, 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-08-28 12:34:39.956636132 +0200
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->i_ctime = dir->i_ctime;
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;
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 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23623 + /* todo: this timestamp may be reverted later */
23624 + inode->i_ctime = h_dir->i_ctime;
23625 + goto out_unpin; /* success */
23632 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23639 + au_unpin(&a->pin);
23641 + dput(a->h_path.dentry);
23643 + di_write_unlock(parent);
23645 + aufs_read_unlock(dentry, AuLock_DW);
23652 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23654 + int err, rmdir_later;
23655 + aufs_bindex_t bwh, bindex, btop;
23656 + struct inode *inode;
23657 + struct dentry *parent, *wh_dentry, *h_dentry;
23658 + struct au_whtmp_rmdir *args;
23659 + /* to reduce stack size */
23661 + struct au_dtime dt;
23662 + struct au_pin pin;
23668 + a = kmalloc(sizeof(*a), GFP_NOFS);
23669 + if (unlikely(!a))
23672 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23673 + if (unlikely(err))
23675 + err = au_alive_dir(dentry);
23676 + if (unlikely(err))
23678 + inode = d_inode(dentry);
23679 + IMustLock(inode);
23681 + if (unlikely(!d_is_dir(dentry)))
23682 + goto out_unlock; /* possible? */
23685 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23686 + if (unlikely(!args))
23689 + parent = dentry->d_parent; /* dir inode is locked */
23690 + di_write_lock_parent(parent);
23691 + err = au_test_empty(dentry, &args->whlist);
23692 + if (unlikely(err))
23695 + btop = au_dbtop(dentry);
23696 + bwh = au_dbwh(dentry);
23698 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23700 + err = PTR_ERR(wh_dentry);
23701 + if (IS_ERR(wh_dentry))
23704 + h_dentry = au_h_dptr(dentry, btop);
23707 + if (bindex == btop) {
23708 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23710 + rmdir_later = err;
23714 + /* stop monitoring */
23715 + au_hn_free(au_hi(inode, btop));
23717 + /* dir inode is locked */
23718 + IMustLock(d_inode(wh_dentry->d_parent));
23723 + vfsub_dead_dir(inode);
23724 + au_set_dbdiropq(dentry, -1);
23725 + epilog(dir, dentry, bindex);
23727 + if (rmdir_later) {
23728 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23732 + goto out_unpin; /* success */
23740 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23747 + au_unpin(&a->pin);
23751 + di_write_unlock(parent);
23753 + au_whtmp_rmdir_free(args);
23755 + aufs_read_unlock(dentry, AuLock_DW);
23762 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23763 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23764 +++ linux/fs/aufs/i_op_ren.c 2023-08-28 12:34:39.956636132 +0200
23766 +// SPDX-License-Identifier: GPL-2.0
23768 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23770 + * This program is free software; you can redistribute it and/or modify
23771 + * it under the terms of the GNU General Public License as published by
23772 + * the Free Software Foundation; either version 2 of the License, or
23773 + * (at your option) any later version.
23775 + * This program is distributed in the hope that it will be useful,
23776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23778 + * GNU General Public License for more details.
23780 + * You should have received a copy of the GNU General Public License
23781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23785 + * inode operation (rename entry)
23786 + * todo: this is crazy monster
23789 +#include <linux/iversion.h>
23792 +enum { AuSRC, AuDST, AuSrcDst };
23793 +enum { AuPARENT, AuCHILD, AuParentChild };
23795 +#define AuRen_ISDIR_SRC 1
23796 +#define AuRen_ISDIR_DST (1 << 1)
23797 +#define AuRen_ISSAMEDIR (1 << 2)
23798 +#define AuRen_WHSRC (1 << 3)
23799 +#define AuRen_WHDST (1 << 4)
23800 +#define AuRen_MNT_WRITE (1 << 5)
23801 +#define AuRen_DT_DSTDIR (1 << 6)
23802 +#define AuRen_DIROPQ_SRC (1 << 7)
23803 +#define AuRen_DIROPQ_DST (1 << 8)
23804 +#define AuRen_DIRREN (1 << 9)
23805 +#define AuRen_DROPPED_SRC (1 << 10)
23806 +#define AuRen_DROPPED_DST (1 << 11)
23807 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23808 +#define au_fset_ren(flags, name) \
23809 + do { (flags) |= AuRen_##name; } while (0)
23810 +#define au_fclr_ren(flags, name) \
23811 + do { (flags) &= ~AuRen_##name; } while (0)
23813 +#ifndef CONFIG_AUFS_DIRREN
23814 +#undef AuRen_DIRREN
23815 +#define AuRen_DIRREN 0
23818 +struct au_ren_args {
23820 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23822 + struct inode *dir, *inode;
23823 + struct au_hinode *hdir, *hinode;
23824 + struct au_dtime dt[AuParentChild];
23825 + aufs_bindex_t btop, bdiropq;
23828 +#define src_dentry sd[AuSRC].dentry
23829 +#define src_dir sd[AuSRC].dir
23830 +#define src_inode sd[AuSRC].inode
23831 +#define src_h_dentry sd[AuSRC].h_dentry
23832 +#define src_parent sd[AuSRC].parent
23833 +#define src_h_parent sd[AuSRC].h_parent
23834 +#define src_wh_dentry sd[AuSRC].wh_dentry
23835 +#define src_hdir sd[AuSRC].hdir
23836 +#define src_hinode sd[AuSRC].hinode
23837 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23838 +#define src_dt sd[AuSRC].dt
23839 +#define src_btop sd[AuSRC].btop
23840 +#define src_bdiropq sd[AuSRC].bdiropq
23842 +#define dst_dentry sd[AuDST].dentry
23843 +#define dst_dir sd[AuDST].dir
23844 +#define dst_inode sd[AuDST].inode
23845 +#define dst_h_dentry sd[AuDST].h_dentry
23846 +#define dst_parent sd[AuDST].parent
23847 +#define dst_h_parent sd[AuDST].h_parent
23848 +#define dst_wh_dentry sd[AuDST].wh_dentry
23849 +#define dst_hdir sd[AuDST].hdir
23850 +#define dst_hinode sd[AuDST].hinode
23851 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23852 +#define dst_dt sd[AuDST].dt
23853 +#define dst_btop sd[AuDST].btop
23854 +#define dst_bdiropq sd[AuDST].bdiropq
23856 + struct dentry *h_trap;
23857 + struct au_branch *br;
23858 + struct path h_path;
23859 + struct au_nhash whlist;
23860 + aufs_bindex_t btgt, src_bwh;
23863 + unsigned short auren_flags;
23864 + unsigned char flags; /* syscall parameter */
23865 + unsigned char exchange;
23868 + struct au_whtmp_rmdir *thargs;
23869 + struct dentry *h_dst;
23870 + struct au_hinode *h_root;
23873 +/* ---------------------------------------------------------------------- */
23876 + * functions for reverting.
23877 + * when an error happened in a single rename systemcall, we should revert
23878 + * everything as if nothing happened.
23879 + * we don't need to revert the copied-up/down the parent dir since they are
23883 +#define RevertFailure(fmt, ...) do { \
23884 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23885 + ##__VA_ARGS__, err, rerr); \
23889 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23892 + struct dentry *d;
23893 +#define src_or_dst(member) a->sd[idx].member
23895 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23896 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23897 + rerr = au_diropq_remove(d, a->btgt);
23898 + au_hn_inode_unlock(src_or_dst(hinode));
23899 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23901 + RevertFailure("remove diropq %pd", d);
23903 +#undef src_or_dst_
23906 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23908 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23909 + au_ren_do_rev_diropq(err, a, AuSRC);
23910 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23911 + au_ren_do_rev_diropq(err, a, AuDST);
23914 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23917 + struct inode *delegated;
23918 + struct path h_ppath = {
23919 + .dentry = a->src_h_parent,
23920 + .mnt = a->h_path.mnt
23923 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23924 + rerr = PTR_ERR(a->h_path.dentry);
23925 + if (IS_ERR(a->h_path.dentry)) {
23926 + RevertFailure("lkup one %pd", a->src_dentry);
23930 + delegated = NULL;
23931 + rerr = vfsub_rename(a->dst_h_dir,
23932 + au_h_dptr(a->src_dentry, a->btgt),
23933 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23934 + if (unlikely(rerr == -EWOULDBLOCK)) {
23935 + pr_warn("cannot retry for NFSv4 delegation"
23936 + " for an internal rename\n");
23939 + d_drop(a->h_path.dentry);
23940 + dput(a->h_path.dentry);
23941 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23943 + RevertFailure("rename %pd", a->src_dentry);
23946 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23949 + struct inode *delegated;
23950 + struct path h_ppath = {
23951 + .dentry = a->dst_h_parent,
23952 + .mnt = a->h_path.mnt
23955 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23956 + rerr = PTR_ERR(a->h_path.dentry);
23957 + if (IS_ERR(a->h_path.dentry)) {
23958 + RevertFailure("lkup one %pd", a->dst_dentry);
23961 + if (d_is_positive(a->h_path.dentry)) {
23962 + d_drop(a->h_path.dentry);
23963 + dput(a->h_path.dentry);
23967 + delegated = NULL;
23968 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23969 + &delegated, a->flags);
23970 + if (unlikely(rerr == -EWOULDBLOCK)) {
23971 + pr_warn("cannot retry for NFSv4 delegation"
23972 + " for an internal rename\n");
23975 + d_drop(a->h_path.dentry);
23976 + dput(a->h_path.dentry);
23978 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
23980 + RevertFailure("rename %pd", a->h_dst);
23983 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
23987 + a->h_path.dentry = a->src_wh_dentry;
23988 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
23989 + au_set_dbwh(a->src_dentry, a->src_bwh);
23991 + RevertFailure("unlink %pd", a->src_wh_dentry);
23993 +#undef RevertFailure
23995 +/* ---------------------------------------------------------------------- */
23998 + * when we have to copyup the renaming entry, do it with the rename-target name
23999 + * in order to minimize the cost (the later actual rename is unnecessary).
24000 + * otherwise rename it on the target branch.
24002 +static int au_ren_or_cpup(struct au_ren_args *a)
24005 + struct dentry *d;
24006 + struct inode *delegated;
24008 + d = a->src_dentry;
24009 + if (au_dbtop(d) == a->btgt) {
24010 + a->h_path.dentry = a->dst_h_dentry;
24011 + AuDebugOn(au_dbtop(d) != a->btgt);
24012 + delegated = NULL;
24013 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24014 + a->dst_h_dir, &a->h_path, &delegated,
24016 + if (unlikely(err == -EWOULDBLOCK)) {
24017 + pr_warn("cannot retry for NFSv4 delegation"
24018 + " for an internal rename\n");
24024 + if (!err && a->h_dst)
24025 + /* it will be set to dinfo later */
24031 +/* cf. aufs_rmdir() */
24032 +static int au_ren_del_whtmp(struct au_ren_args *a)
24035 + struct inode *dir;
24037 + dir = a->dst_dir;
24038 + SiMustAnyLock(dir->i_sb);
24039 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24040 + au_sbi(dir->i_sb)->si_dirwh)
24041 + || au_test_fs_remote(a->h_dst->d_sb)) {
24042 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24043 + if (unlikely(err))
24044 + pr_warn("failed removing whtmp dir %pd (%d), "
24045 + "ignored.\n", a->h_dst, err);
24047 + au_nhash_wh_free(&a->thargs->whlist);
24048 + a->thargs->whlist = a->whlist;
24049 + a->whlist.nh_num = 0;
24050 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24052 + a->thargs = NULL;
24058 +/* make it 'opaque' dir. */
24059 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24062 + struct dentry *d, *diropq;
24063 +#define src_or_dst(member) a->sd[idx].member
24066 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24067 + src_or_dst(bdiropq) = au_dbdiropq(d);
24068 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24069 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24070 + diropq = au_diropq_create(d, a->btgt);
24071 + au_hn_inode_unlock(src_or_dst(hinode));
24072 + if (IS_ERR(diropq))
24073 + err = PTR_ERR(diropq);
24077 +#undef src_or_dst_
24081 +static int au_ren_diropq(struct au_ren_args *a)
24084 + unsigned char always;
24085 + struct dentry *d;
24088 + d = a->dst_dentry; /* already renamed on the branch */
24089 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24090 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24091 + && !au_ftest_ren(a->auren_flags, DIRREN)
24092 + && a->btgt != au_dbdiropq(a->src_dentry)
24093 + && (a->dst_wh_dentry
24094 + || a->btgt <= au_dbdiropq(d)
24095 + /* hide the lower to keep xino */
24096 + /* the lowers may not be a dir, but we hide them anyway */
24097 + || a->btgt < au_dbbot(d)
24100 + err = au_ren_do_diropq(a, AuSRC);
24101 + if (unlikely(err))
24103 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24105 + if (!a->exchange)
24106 + goto out; /* success */
24108 + d = a->src_dentry; /* already renamed on the branch */
24109 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24110 + && a->btgt != au_dbdiropq(a->dst_dentry)
24111 + && (a->btgt < au_dbdiropq(d)
24112 + || a->btgt < au_dbbot(d)
24114 + AuDbgDentry(a->src_dentry);
24115 + AuDbgDentry(a->dst_dentry);
24116 + err = au_ren_do_diropq(a, AuDST);
24117 + if (unlikely(err))
24118 + goto out_rev_src;
24119 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24121 + goto out; /* success */
24124 + AuDbg("err %d, reverting src\n", err);
24125 + au_ren_rev_diropq(err, a);
24130 +static int do_rename(struct au_ren_args *a)
24133 + struct dentry *d, *h_d;
24135 + if (!a->exchange) {
24136 + /* prepare workqueue args for asynchronous rmdir */
24137 + h_d = a->dst_h_dentry;
24138 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24139 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24140 + && d_is_positive(h_d)) {
24142 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24144 + if (unlikely(!a->thargs))
24146 + a->h_dst = dget(h_d);
24149 + /* create whiteout for src_dentry */
24150 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24151 + a->src_bwh = au_dbwh(a->src_dentry);
24152 + AuDebugOn(a->src_bwh >= 0);
24153 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24154 + a->src_h_parent);
24155 + err = PTR_ERR(a->src_wh_dentry);
24156 + if (IS_ERR(a->src_wh_dentry))
24160 + /* lookup whiteout for dentry */
24161 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24162 + h_d = au_wh_lkup(a->dst_h_parent,
24163 + &a->dst_dentry->d_name, a->br);
24164 + err = PTR_ERR(h_d);
24167 + if (d_is_negative(h_d))
24170 + a->dst_wh_dentry = h_d;
24173 + /* rename dentry to tmpwh */
24175 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24176 + if (unlikely(err))
24179 + d = a->dst_dentry;
24180 + au_set_h_dptr(d, a->btgt, NULL);
24181 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24182 + if (unlikely(err))
24184 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24188 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24189 +#if 0 /* debugging */
24190 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24191 + && d_is_positive(a->dst_h_dentry)
24192 + && a->src_btop != a->btgt);
24195 + /* rename by vfs_rename or cpup */
24196 + err = au_ren_or_cpup(a);
24197 + if (unlikely(err))
24198 + /* leave the copied-up one */
24201 + /* make dir opaque */
24202 + err = au_ren_diropq(a);
24203 + if (unlikely(err))
24206 + /* update target timestamps */
24207 + if (a->exchange) {
24208 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24209 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24210 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24211 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24213 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24214 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24215 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24216 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24218 + if (!a->exchange) {
24219 + /* remove whiteout for dentry */
24220 + if (a->dst_wh_dentry) {
24221 + a->h_path.dentry = a->dst_wh_dentry;
24222 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24224 + if (unlikely(err))
24228 + /* remove whtmp */
24230 + au_ren_del_whtmp(a); /* ignore this error */
24232 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24235 + goto out_success;
24238 + au_ren_rev_diropq(err, a);
24240 + au_ren_rev_rename(err, a);
24244 + au_ren_rev_whtmp(err, a);
24246 + dput(a->dst_wh_dentry);
24247 + a->dst_wh_dentry = NULL;
24249 + if (a->src_wh_dentry)
24250 + au_ren_rev_whsrc(err, a);
24252 + dput(a->src_wh_dentry);
24253 + dput(a->dst_wh_dentry);
24257 + au_whtmp_rmdir_free(a->thargs);
24258 + a->thargs = NULL;
24264 +/* ---------------------------------------------------------------------- */
24267 + * test if @dentry dir can be rename destination or not.
24268 + * success means, it is a logically empty dir.
24270 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24272 + return au_test_empty(dentry, whlist);
24276 + * test if @a->src_dentry dir can be rename source or not.
24277 + * if it can, return 0.
24279 + * - it is a logically empty dir.
24280 + * - or, it exists on writable branch and has no children including whiteouts
24281 + * on the lower branch unless DIRREN is on.
24283 +static int may_rename_srcdir(struct au_ren_args *a)
24286 + unsigned int rdhash;
24287 + aufs_bindex_t btop, btgt;
24288 + struct dentry *dentry;
24289 + struct super_block *sb;
24290 + struct au_sbinfo *sbinfo;
24292 + dentry = a->src_dentry;
24293 + sb = dentry->d_sb;
24294 + sbinfo = au_sbi(sb);
24295 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24296 + au_fset_ren(a->auren_flags, DIRREN);
24299 + btop = au_dbtop(dentry);
24300 + if (btop != btgt) {
24301 + struct au_nhash whlist;
24303 + SiMustAnyLock(sb);
24304 + rdhash = sbinfo->si_rdhash;
24306 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24308 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24309 + if (unlikely(err))
24311 + err = au_test_empty(dentry, &whlist);
24312 + au_nhash_wh_free(&whlist);
24316 + if (btop == au_dbtaildir(dentry))
24317 + return 0; /* success */
24319 + err = au_test_empty_lower(dentry);
24322 + if (err == -ENOTEMPTY) {
24323 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24326 + AuWarn1("renaming dir who has child(ren) on multiple "
24327 + "branches, is not supported\n");
24334 +/* side effect: sets whlist and h_dentry */
24335 +static int au_ren_may_dir(struct au_ren_args *a)
24338 + unsigned int rdhash;
24339 + struct dentry *d;
24341 + d = a->dst_dentry;
24342 + SiMustAnyLock(d->d_sb);
24345 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24346 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24348 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24349 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24350 + if (unlikely(err))
24353 + if (!a->exchange) {
24354 + au_set_dbtop(d, a->dst_btop);
24355 + err = may_rename_dstdir(d, &a->whlist);
24356 + au_set_dbtop(d, a->btgt);
24358 + err = may_rename_srcdir(a);
24360 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24361 + if (unlikely(err))
24364 + d = a->src_dentry;
24365 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24366 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24367 + err = may_rename_srcdir(a);
24368 + if (unlikely(err)) {
24369 + au_nhash_wh_free(&a->whlist);
24370 + a->whlist.nh_num = 0;
24377 +/* ---------------------------------------------------------------------- */
24380 + * simple tests for rename.
24381 + * following the checks in vfs, plus the parent-child relationship.
24383 +static int au_may_ren(struct au_ren_args *a)
24386 + struct inode *h_inode;
24388 + if (a->src_btop == a->btgt) {
24389 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24390 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24391 + if (unlikely(err))
24394 + if (unlikely(a->src_h_dentry == a->h_trap))
24399 + if (a->dst_btop != a->btgt)
24402 + err = -ENOTEMPTY;
24403 + if (unlikely(a->dst_h_dentry == a->h_trap))
24407 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24408 + if (d_really_is_negative(a->dst_dentry)) {
24409 + if (d_is_negative(a->dst_h_dentry))
24410 + err = au_may_add(a->dst_dentry, a->btgt,
24411 + a->dst_h_parent, isdir);
24413 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24415 + h_inode = d_inode(a->dst_h_dentry);
24416 + if (h_inode->i_nlink)
24417 + err = au_may_del(a->dst_dentry, a->btgt,
24418 + a->dst_h_parent, isdir);
24422 + if (unlikely(err == -ENOENT || err == -EEXIST))
24428 +/* ---------------------------------------------------------------------- */
24433 + * - src_dir and dir by lock_rename()
24434 + * - inode if exists
24437 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24439 + * + di_write_lock2_child()
24440 + * + di_write_lock_child()
24441 + * + ii_write_lock_child()
24442 + * + di_write_lock_child2()
24443 + * + ii_write_lock_child2()
24444 + * + src_parent and parent
24445 + * + di_write_lock_parent()
24446 + * + ii_write_lock_parent()
24447 + * + di_write_lock_parent2()
24448 + * + ii_write_lock_parent2()
24449 + * + lower src_dir and dir by vfsub_lock_rename()
24450 + * + verify the every relationships between child and parent. if any
24451 + * of them failed, unlock all and return -EBUSY.
24453 +static void au_ren_unlock(struct au_ren_args *a)
24455 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24456 + a->dst_h_parent, a->dst_hdir);
24457 + if (au_ftest_ren(a->auren_flags, DIRREN)
24459 + au_hn_inode_unlock(a->h_root);
24460 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24461 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24464 +static int au_ren_lock(struct au_ren_args *a)
24467 + unsigned int udba;
24470 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24471 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24472 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24473 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24475 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24476 + if (unlikely(err))
24478 + au_fset_ren(a->auren_flags, MNT_WRITE);
24479 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24480 + struct dentry *root;
24481 + struct inode *dir;
24484 + * sbinfo is already locked, so this ii_read_lock is
24485 + * unnecessary. but our debugging feature checks it.
24487 + root = a->src_inode->i_sb->s_root;
24488 + if (root != a->src_parent && root != a->dst_parent) {
24489 + dir = d_inode(root);
24490 + ii_read_lock_parent3(dir);
24491 + a->h_root = au_hi(dir, a->btgt);
24492 + ii_read_unlock(dir);
24493 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24496 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24497 + a->dst_h_parent, a->dst_hdir);
24498 + udba = au_opt_udba(a->src_dentry->d_sb);
24499 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24500 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24501 + err = au_busy_or_stale();
24502 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24503 + err = au_h_verify(a->src_h_dentry, udba,
24504 + d_inode(a->src_h_parent), a->src_h_parent,
24506 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24507 + err = au_h_verify(a->dst_h_dentry, udba,
24508 + d_inode(a->dst_h_parent), a->dst_h_parent,
24511 + goto out; /* success */
24513 + err = au_busy_or_stale();
24514 + au_ren_unlock(a);
24520 +/* ---------------------------------------------------------------------- */
24522 +static void au_ren_refresh_dir(struct au_ren_args *a)
24524 + struct inode *dir;
24526 + dir = a->dst_dir;
24527 + inode_inc_iversion(dir);
24528 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24529 + /* is this updating defined in POSIX? */
24530 + au_cpup_attr_timesizes(a->src_inode);
24531 + au_cpup_attr_nlink(dir, /*force*/1);
24533 + au_dir_ts(dir, a->btgt);
24535 + if (a->exchange) {
24536 + dir = a->src_dir;
24537 + inode_inc_iversion(dir);
24538 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24539 + /* is this updating defined in POSIX? */
24540 + au_cpup_attr_timesizes(a->dst_inode);
24541 + au_cpup_attr_nlink(dir, /*force*/1);
24543 + au_dir_ts(dir, a->btgt);
24546 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24549 + dir = a->src_dir;
24550 + inode_inc_iversion(dir);
24551 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24552 + au_cpup_attr_nlink(dir, /*force*/1);
24553 + au_dir_ts(dir, a->btgt);
24556 +static void au_ren_refresh(struct au_ren_args *a)
24558 + aufs_bindex_t bbot, bindex;
24559 + struct dentry *d, *h_d;
24560 + struct inode *i, *h_i;
24561 + struct super_block *sb;
24563 + d = a->dst_dentry;
24566 + /* already dget-ed by au_ren_or_cpup() */
24567 + au_set_h_dptr(d, a->btgt, a->h_dst);
24569 + i = a->dst_inode;
24571 + if (!a->exchange) {
24572 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24573 + vfsub_drop_nlink(i);
24575 + vfsub_dead_dir(i);
24576 + au_cpup_attr_timesizes(i);
24578 + au_update_dbrange(d, /*do_put_zero*/1);
24580 + au_cpup_attr_nlink(i, /*force*/1);
24583 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24584 + au_set_h_dptr(d, bindex, NULL);
24585 + bbot = au_dbbot(d);
24586 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24587 + au_set_h_dptr(d, bindex, NULL);
24588 + au_update_dbrange(d, /*do_put_zero*/0);
24592 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24593 + d_drop(a->src_dentry);
24594 + if (au_ftest_ren(a->auren_flags, DIRREN))
24595 + au_set_dbwh(a->src_dentry, -1);
24599 + d = a->src_dentry;
24600 + au_set_dbwh(d, -1);
24601 + bbot = au_dbbot(d);
24602 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24603 + h_d = au_h_dptr(d, bindex);
24605 + au_set_h_dptr(d, bindex, NULL);
24607 + au_set_dbbot(d, a->btgt);
24610 + i = a->src_inode;
24611 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24612 + return; /* success */
24614 + bbot = au_ibbot(i);
24615 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24616 + h_i = au_h_iptr(i, bindex);
24618 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24619 + /* ignore this error */
24620 + au_set_h_iptr(i, bindex, NULL, 0);
24623 + au_set_ibbot(i, a->btgt);
24626 +/* ---------------------------------------------------------------------- */
24628 +/* mainly for link(2) and rename(2) */
24629 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24631 + aufs_bindex_t bdiropq, bwh;
24632 + struct dentry *parent;
24633 + struct au_branch *br;
24635 + parent = dentry->d_parent;
24636 + IMustLock(d_inode(parent)); /* dir is locked */
24638 + bdiropq = au_dbdiropq(parent);
24639 + bwh = au_dbwh(dentry);
24640 + br = au_sbr(dentry->d_sb, btgt);
24641 + if (au_br_rdonly(br)
24642 + || (0 <= bdiropq && bdiropq < btgt)
24643 + || (0 <= bwh && bwh < btgt))
24646 + AuDbg("btgt %d\n", btgt);
24650 +/* sets src_btop, dst_btop and btgt */
24651 +static int au_ren_wbr(struct au_ren_args *a)
24654 + struct au_wr_dir_args wr_dir_args = {
24655 + /* .force_btgt = -1, */
24656 + .flags = AuWrDir_ADD_ENTRY
24659 + a->src_btop = au_dbtop(a->src_dentry);
24660 + a->dst_btop = au_dbtop(a->dst_dentry);
24661 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24662 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24663 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24664 + wr_dir_args.force_btgt = a->src_btop;
24665 + if (a->dst_inode && a->dst_btop < a->src_btop)
24666 + wr_dir_args.force_btgt = a->dst_btop;
24667 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24668 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24671 + au_update_dbtop(a->dst_dentry);
24676 +static void au_ren_dt(struct au_ren_args *a)
24678 + a->h_path.dentry = a->src_h_parent;
24679 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24680 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24681 + a->h_path.dentry = a->dst_h_parent;
24682 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24685 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24686 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24690 + a->h_path.dentry = a->src_h_dentry;
24691 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24692 + if (d_is_positive(a->dst_h_dentry)) {
24693 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24694 + a->h_path.dentry = a->dst_h_dentry;
24695 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24699 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24701 + struct dentry *h_d;
24702 + struct inode *h_inode;
24704 + au_dtime_revert(a->src_dt + AuPARENT);
24705 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24706 + au_dtime_revert(a->dst_dt + AuPARENT);
24708 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24709 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24710 + h_inode = d_inode(h_d);
24711 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24712 + au_dtime_revert(a->src_dt + AuCHILD);
24713 + inode_unlock(h_inode);
24715 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24716 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24717 + h_inode = d_inode(h_d);
24718 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24719 + au_dtime_revert(a->dst_dt + AuCHILD);
24720 + inode_unlock(h_inode);
24725 +/* ---------------------------------------------------------------------- */
24727 +int aufs_rename(struct mnt_idmap *idmap,
24728 + struct inode *_src_dir, struct dentry *_src_dentry,
24729 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24730 + unsigned int _flags)
24732 + int err, lock_flags;
24734 + /* reduce stack space */
24735 + struct au_ren_args *a;
24736 + struct au_pin pin;
24738 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24739 + IMustLock(_src_dir);
24740 + IMustLock(_dst_dir);
24743 + if (unlikely(_flags & RENAME_WHITEOUT))
24747 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24748 + a = kzalloc(sizeof(*a), GFP_NOFS);
24749 + if (unlikely(!a))
24752 + a->flags = _flags;
24753 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24754 + && RENAME_EXCHANGE > U8_MAX);
24755 + a->exchange = _flags & RENAME_EXCHANGE;
24756 + a->src_dir = _src_dir;
24757 + a->src_dentry = _src_dentry;
24758 + a->src_inode = NULL;
24759 + if (d_really_is_positive(a->src_dentry))
24760 + a->src_inode = d_inode(a->src_dentry);
24761 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24762 + a->dst_dir = _dst_dir;
24763 + a->dst_dentry = _dst_dentry;
24764 + a->dst_inode = NULL;
24765 + if (d_really_is_positive(a->dst_dentry))
24766 + a->dst_inode = d_inode(a->dst_dentry);
24767 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24768 + if (a->dst_inode) {
24770 + * if EXCHANGE && src is non-dir && dst is dir,
24771 + * dst is not locked.
24773 + /* IMustLock(a->dst_inode); */
24774 + au_igrab(a->dst_inode);
24778 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24779 + if (d_is_dir(a->src_dentry)) {
24780 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24781 + if (unlikely(!a->exchange
24782 + && d_really_is_positive(a->dst_dentry)
24783 + && !d_is_dir(a->dst_dentry)))
24785 + lock_flags |= AuLock_DIRS;
24787 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24788 + au_fset_ren(a->auren_flags, ISDIR_DST);
24789 + if (unlikely(!a->exchange
24790 + && d_really_is_positive(a->src_dentry)
24791 + && !d_is_dir(a->src_dentry)))
24793 + lock_flags |= AuLock_DIRS;
24795 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24797 + if (unlikely(err))
24800 + err = au_d_hashed_positive(a->src_dentry);
24801 + if (unlikely(err))
24804 + if (a->dst_inode) {
24806 + * If it is a dir, VFS unhash it before this
24807 + * function. It means we cannot rely upon d_unhashed().
24809 + if (unlikely(!a->dst_inode->i_nlink))
24811 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24812 + err = au_d_hashed_positive(a->dst_dentry);
24813 + if (unlikely(err && !a->exchange))
24815 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24817 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24821 + * is it possible?
24822 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24823 + * there may exist a problem somewhere else.
24826 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24829 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24830 + di_write_lock_parent(a->dst_parent);
24832 + /* which branch we process */
24833 + err = au_ren_wbr(a);
24834 + if (unlikely(err < 0))
24836 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24837 + a->h_path.mnt = au_br_mnt(a->br);
24839 + /* are they available to be renamed */
24840 + err = au_ren_may_dir(a);
24841 + if (unlikely(err))
24842 + goto out_children;
24844 + /* prepare the writable parent dir on the same branch */
24845 + if (a->dst_btop == a->btgt) {
24846 + au_fset_ren(a->auren_flags, WHDST);
24848 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24849 + if (unlikely(err))
24850 + goto out_children;
24854 + if (!a->exchange) {
24855 + if (a->src_dir != a->dst_dir) {
24857 + * this temporary unlock is safe,
24858 + * because both dir->i_mutex are locked.
24860 + di_write_unlock(a->dst_parent);
24861 + di_write_lock_parent(a->src_parent);
24862 + err = au_wr_dir_need_wh(a->src_dentry,
24863 + au_ftest_ren(a->auren_flags,
24866 + di_write_unlock(a->src_parent);
24867 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24869 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24871 + err = au_wr_dir_need_wh(a->src_dentry,
24872 + au_ftest_ren(a->auren_flags,
24876 + if (unlikely(err < 0))
24877 + goto out_children;
24879 + au_fset_ren(a->auren_flags, WHSRC);
24882 + if (a->src_btop != a->btgt) {
24883 + err = au_pin(&pin, a->src_dentry, a->btgt,
24884 + au_opt_udba(a->src_dentry->d_sb),
24885 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24887 + struct au_cp_generic cpg = {
24888 + .dentry = a->src_dentry,
24890 + .bsrc = a->src_btop,
24893 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24895 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24896 + err = au_sio_cpup_simple(&cpg);
24899 + if (unlikely(err))
24900 + goto out_children;
24901 + a->src_btop = a->btgt;
24902 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24903 + if (!a->exchange)
24904 + au_fset_ren(a->auren_flags, WHSRC);
24908 + if (a->exchange && a->dst_inode
24909 + && a->dst_btop != a->btgt) {
24910 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24911 + au_opt_udba(a->dst_dentry->d_sb),
24912 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24914 + struct au_cp_generic cpg = {
24915 + .dentry = a->dst_dentry,
24917 + .bsrc = a->dst_btop,
24920 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24922 + err = au_sio_cpup_simple(&cpg);
24925 + if (unlikely(err))
24926 + goto out_children;
24927 + a->dst_btop = a->btgt;
24928 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24931 + /* lock them all */
24932 + err = au_ren_lock(a);
24933 + if (unlikely(err))
24934 + /* leave the copied-up one */
24935 + goto out_children;
24937 + if (!a->exchange) {
24938 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24939 + err = au_may_ren(a);
24940 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24941 + err = -ENAMETOOLONG;
24942 + if (unlikely(err))
24946 + /* store timestamps to be revertible */
24949 + /* store dirren info */
24950 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24951 + err = au_dr_rename(a->src_dentry, a->btgt,
24952 + &a->dst_dentry->d_name, &rev);
24954 + if (unlikely(err))
24959 + err = do_rename(a);
24960 + if (unlikely(err))
24963 + if (au_ftest_ren(a->auren_flags, DIRREN))
24964 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24966 + /* update dir attributes */
24967 + au_ren_refresh_dir(a);
24969 + /* dput/iput all lower dentries */
24970 + au_ren_refresh(a);
24972 + goto out_hdir; /* success */
24975 + if (au_ftest_ren(a->auren_flags, DIRREN))
24976 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
24978 + au_ren_rev_dt(err, a);
24980 + au_ren_unlock(a);
24982 + au_nhash_wh_free(&a->whlist);
24983 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
24984 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
24985 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
24986 + au_set_dbtop(a->dst_dentry, a->dst_btop);
24990 + if (d_unhashed(a->src_dentry))
24991 + au_fset_ren(a->auren_flags, DROPPED_SRC);
24992 + if (d_unhashed(a->dst_dentry))
24993 + au_fset_ren(a->auren_flags, DROPPED_DST);
24994 + if (!a->exchange)
24995 + d_move(a->src_dentry, a->dst_dentry);
24997 + d_exchange(a->src_dentry, a->dst_dentry);
24998 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
24999 + d_drop(a->dst_dentry);
25001 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
25002 + d_drop(a->src_dentry);
25004 + au_update_dbtop(a->dst_dentry);
25005 + if (!a->dst_inode)
25006 + d_drop(a->dst_dentry);
25008 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25009 + di_write_unlock(a->dst_parent);
25011 + di_write_unlock2(a->src_parent, a->dst_parent);
25013 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25015 + iput(a->dst_inode);
25017 + au_whtmp_rmdir_free(a->thargs);
25023 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25024 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25025 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
25027 +# SPDX-License-Identifier: GPL-2.0
25029 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25031 + Aufs is a stackable unification filesystem such as Unionfs,
25032 + which unifies several directories and provides a merged single
25034 + In the early days, aufs was entirely re-designed and
25035 + re-implemented Unionfs Version 1.x series. Introducing many
25036 + original ideas, approaches and improvements, it becomes totally
25037 + different from Unionfs while keeping the basic features.
25041 + prompt "Maximum number of branches"
25042 + default AUFS_BRANCH_MAX_127
25044 + Specifies the maximum number of branches (or member directories)
25045 + in a single aufs. The larger value consumes more system
25046 + resources and has a minor impact to performance.
25047 +config AUFS_BRANCH_MAX_127
25050 + Specifies the maximum number of branches (or member directories)
25051 + in a single aufs. The larger value consumes more system
25052 + resources and has a minor impact to performance.
25053 +config AUFS_BRANCH_MAX_511
25056 + Specifies the maximum number of branches (or member directories)
25057 + in a single aufs. The larger value consumes more system
25058 + resources and has a minor impact to performance.
25059 +config AUFS_BRANCH_MAX_1023
25062 + Specifies the maximum number of branches (or member directories)
25063 + in a single aufs. The larger value consumes more system
25064 + resources and has a minor impact to performance.
25065 +config AUFS_BRANCH_MAX_32767
25068 + Specifies the maximum number of branches (or member directories)
25069 + in a single aufs. The larger value consumes more system
25070 + resources and has a minor impact to performance.
25073 +config AUFS_SBILIST
25075 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25078 + Automatic configuration for internal use.
25079 + When aufs supports Magic SysRq or /proc, enabled automatically.
25081 +config AUFS_HNOTIFY
25082 + bool "Detect direct branch access (bypassing aufs)"
25084 + If you want to modify files on branches directly, eg. bypassing aufs,
25085 + and want aufs to detect the changes of them fully, then enable this
25086 + option and use 'udba=notify' mount option.
25087 + Currently there is only one available configuration, "fsnotify".
25088 + It will have a negative impact to the performance.
25089 + See detail in aufs.5.
25092 + prompt "method" if AUFS_HNOTIFY
25093 + default AUFS_HFSNOTIFY
25094 +config AUFS_HFSNOTIFY
25099 +config AUFS_EXPORT
25100 + bool "NFS-exportable aufs"
25101 + depends on EXPORTFS
25103 + If you want to export your mounted aufs via NFS, then enable this
25104 + option. There are several requirements for this configuration.
25105 + See detail in aufs.5.
25107 +config AUFS_INO_T_64
25109 + depends on AUFS_EXPORT
25110 + depends on 64BIT && !(ALPHA || S390)
25113 + Automatic configuration for internal use.
25114 + /* typedef unsigned long/int __kernel_ino_t */
25115 + /* alpha and s390x are int */
25118 + bool "support for XATTR/EA (including Security Labels)"
25120 + If your branch fs supports XATTR/EA and you want to make them
25121 + available in aufs too, then enable this opsion and specify the
25122 + branch attributes for EA.
25123 + See detail in aufs.5.
25126 + bool "File-based Hierarchical Storage Management"
25128 + Hierarchical Storage Management (or HSM) is a well-known feature
25129 + in the storage world. Aufs provides this feature as file-based.
25130 + with multiple branches.
25131 + These multiple branches are prioritized, ie. the topmost one
25132 + should be the fastest drive and be used heavily.
25135 + bool "Readdir in userspace"
25137 + Aufs has two methods to provide a merged view for a directory,
25138 + by a user-space library and by kernel-space natively. The latter
25139 + is always enabled but sometimes large and slow.
25140 + If you enable this option, install the library in aufs2-util
25141 + package, and set some environment variables for your readdir(3),
25142 + then the work will be handled in user-space which generally
25143 + shows better performance in most cases.
25144 + See detail in aufs.5.
25146 +config AUFS_DIRREN
25147 + bool "Workaround for rename(2)-ing a directory"
25149 + By default, aufs returns EXDEV error in renameing a dir who has
25150 + his child on the lower branch, since it is a bad idea to issue
25151 + rename(2) internally for every lower branch. But user may not
25152 + accept this behaviour. So here is a workaround to allow such
25153 + rename(2) and store some extra information on the writable
25154 + branch. Obviously this costs high (and I don't like it).
25155 + To use this feature, you need to enable this configuration AND
25156 + to specify the mount option `dirren.'
25157 + See details in aufs.5 and the design documents.
25160 + bool "Show whiteouts"
25162 + If you want to make the whiteouts in aufs visible, then enable
25163 + this option and specify 'shwh' mount option. Although it may
25164 + sounds like philosophy or something, but in technically it
25165 + simply shows the name of whiteout with keeping its behaviour.
25167 +config AUFS_BR_RAMFS
25168 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25170 + If you want to use ramfs as an aufs branch fs, then enable this
25171 + option. Generally tmpfs is recommended.
25172 + Aufs prohibited them to be a branch fs by default, because
25173 + initramfs becomes unusable after switch_root or something
25174 + generally. If you sets initramfs as an aufs branch and boot your
25175 + system by switch_root, you will meet a problem easily since the
25176 + files in initramfs may be inaccessible.
25177 + Unless you are going to use ramfs as an aufs branch fs without
25178 + switch_root or something, leave it N.
25180 +config AUFS_BR_FUSE
25181 + bool "Fuse fs as an aufs branch"
25182 + depends on FUSE_FS
25185 + If you want to use fuse-based userspace filesystem as an aufs
25186 + branch fs, then enable this option.
25187 + It implements the internal poll(2) operation which is
25188 + implemented by fuse only (curretnly).
25193 + Automatic configuration for internal use.
25195 +config AUFS_BR_HFSPLUS
25196 + bool "Hfsplus as an aufs branch"
25197 + depends on HFSPLUS_FS
25200 + If you want to use hfsplus fs as an aufs branch fs, then enable
25201 + this option. This option introduces a small overhead at
25202 + copying-up a file on hfsplus.
25204 +config AUFS_BDEV_LOOP
25206 + depends on BLK_DEV_LOOP
25209 + Automatic configuration for internal use.
25210 + Convert =[ym] into =y.
25213 + bool "Debug aufs"
25215 + Enable this to compile aufs internal debug code.
25216 + It will have a negative impact to the performance.
25218 +config AUFS_MAGIC_SYSRQ
25220 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25223 + Automatic configuration for internal use.
25224 + When aufs supports Magic SysRq, enabled automatically.
25226 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25227 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25228 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25230 +/* SPDX-License-Identifier: GPL-2.0 */
25232 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25234 + * This program is free software; you can redistribute it and/or modify
25235 + * it under the terms of the GNU General Public License as published by
25236 + * the Free Software Foundation; either version 2 of the License, or
25237 + * (at your option) any later version.
25239 + * This program is distributed in the hope that it will be useful,
25240 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25241 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25242 + * GNU General Public License for more details.
25244 + * You should have received a copy of the GNU General Public License
25245 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25249 + * simple long counter wrapper
25252 +#ifndef __AUFS_LCNT_H__
25253 +#define __AUFS_LCNT_H__
25257 +#include "debug.h"
25259 +#define AuLCntATOMIC 1
25260 +#define AuLCntPCPUCNT 2
25262 + * why does percpu_refcount require extra synchronize_rcu()s in
25263 + * au_br_do_free()
25265 +#define AuLCntPCPUREF 3
25267 +/* #define AuLCntChosen AuLCntATOMIC */
25268 +#define AuLCntChosen AuLCntPCPUCNT
25269 +/* #define AuLCntChosen AuLCntPCPUREF */
25271 +#if AuLCntChosen == AuLCntATOMIC
25272 +#include <linux/atomic.h>
25274 +typedef atomic_long_t au_lcnt_t;
25276 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25278 + atomic_long_set(cnt, 0);
25282 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25287 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25288 + int do_sync __maybe_unused)
25293 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25295 + atomic_long_inc(cnt);
25298 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25300 + atomic_long_dec(cnt);
25303 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25305 + return atomic_long_read(cnt);
25309 +#if AuLCntChosen == AuLCntPCPUCNT
25310 +#include <linux/percpu_counter.h>
25312 +typedef struct percpu_counter au_lcnt_t;
25314 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25316 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25319 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25324 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25326 + percpu_counter_destroy(cnt);
25329 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25331 + percpu_counter_inc(cnt);
25334 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25336 + percpu_counter_dec(cnt);
25339 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25343 + n = percpu_counter_sum(cnt);
25345 + if (LONG_MAX != LLONG_MAX
25347 + AuWarn1("%s\n", "wrap-around");
25353 +#if AuLCntChosen == AuLCntPCPUREF
25354 +#include <linux/percpu-refcount.h>
25356 +typedef struct percpu_ref au_lcnt_t;
25358 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25361 + release = percpu_ref_exit;
25362 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25365 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25367 + synchronize_rcu();
25370 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25372 + percpu_ref_kill(cnt);
25374 + au_lcnt_wait_for_fin(cnt);
25377 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25379 + percpu_ref_get(cnt);
25382 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25384 + percpu_ref_put(cnt);
25388 + * avoid calling this func as possible.
25390 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25394 + percpu_ref_switch_to_atomic_sync(cnt);
25395 + l = atomic_long_read(&cnt->count);
25397 + percpu_ref_switch_to_percpu(cnt);
25399 + /* percpu_ref is initialized by 1 instead of 0 */
25404 +#ifdef CONFIG_AUFS_DEBUG
25405 +#define AuLCntZero(val) do { \
25408 + AuDbg("%s = %ld\n", #val, l); \
25411 +#define AuLCntZero(val) do {} while (0)
25414 +#endif /* __KERNEL__ */
25415 +#endif /* __AUFS_LCNT_H__ */
25416 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25417 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25418 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25420 +// SPDX-License-Identifier: GPL-2.0
25422 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25424 + * This program is free software; you can redistribute it and/or modify
25425 + * it under the terms of the GNU General Public License as published by
25426 + * the Free Software Foundation; either version 2 of the License, or
25427 + * (at your option) any later version.
25429 + * This program is distributed in the hope that it will be useful,
25430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25432 + * GNU General Public License for more details.
25434 + * You should have received a copy of the GNU General Public License
25435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25439 + * support for loopback block device as a branch
25444 +/* added into drivers/block/loop.c */
25445 +static struct file *(*backing_file_func)(struct super_block *sb);
25448 + * test if two lower dentries have overlapping branches.
25450 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25452 + struct super_block *h_sb;
25453 + struct file *backing_file;
25455 + if (unlikely(!backing_file_func)) {
25456 + /* don't load "loop" module here */
25457 + backing_file_func = symbol_get(loop_backing_file);
25458 + if (unlikely(!backing_file_func))
25459 + /* "loop" module is not loaded */
25463 + h_sb = h_adding->d_sb;
25464 + backing_file = backing_file_func(h_sb);
25465 + if (!backing_file)
25468 + h_adding = backing_file->f_path.dentry;
25470 + * h_adding can be local NFS.
25471 + * in this case aufs cannot detect the loop.
25473 + if (unlikely(h_adding->d_sb == sb))
25475 + return !!au_test_subdir(h_adding, sb->s_root);
25478 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25479 +int au_test_loopback_kthread(void)
25482 + struct task_struct *tsk = current;
25483 + char c, comm[sizeof(tsk->comm)];
25486 + if (tsk->flags & PF_KTHREAD) {
25487 + get_task_comm(comm, tsk);
25489 + ret = ('0' <= c && c <= '9'
25490 + && !strncmp(comm, "loop", 4));
25496 +/* ---------------------------------------------------------------------- */
25498 +#define au_warn_loopback_step 16
25499 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25500 +static unsigned long *au_warn_loopback_array;
25502 +void au_warn_loopback(struct super_block *h_sb)
25504 + int i, new_nelem;
25505 + unsigned long *a, magic;
25506 + static DEFINE_SPINLOCK(spin);
25508 + magic = h_sb->s_magic;
25509 + spin_lock(&spin);
25510 + a = au_warn_loopback_array;
25511 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25512 + if (a[i] == magic) {
25513 + spin_unlock(&spin);
25517 + /* h_sb is new to us, print it */
25518 + if (i < au_warn_loopback_nelem) {
25523 + /* expand the array */
25524 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25525 + a = au_kzrealloc(au_warn_loopback_array,
25526 + au_warn_loopback_nelem * sizeof(unsigned long),
25527 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25528 + /*may_shrink*/0);
25530 + au_warn_loopback_nelem = new_nelem;
25531 + au_warn_loopback_array = a;
25536 + spin_unlock(&spin);
25537 + AuWarn1("realloc failed, ignored\n");
25541 + spin_unlock(&spin);
25542 + pr_warn("you may want to try another patch for loopback file "
25543 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25546 +int au_loopback_init(void)
25549 + struct super_block *sb __maybe_unused;
25551 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25554 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25555 + sizeof(unsigned long), GFP_NOFS);
25556 + if (unlikely(!au_warn_loopback_array))
25562 +void au_loopback_fin(void)
25564 + if (backing_file_func)
25565 + symbol_put(loop_backing_file);
25566 + au_kfree_try_rcu(au_warn_loopback_array);
25568 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25569 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25570 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25572 +/* SPDX-License-Identifier: GPL-2.0 */
25574 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25576 + * This program is free software; you can redistribute it and/or modify
25577 + * it under the terms of the GNU General Public License as published by
25578 + * the Free Software Foundation; either version 2 of the License, or
25579 + * (at your option) any later version.
25581 + * This program is distributed in the hope that it will be useful,
25582 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25583 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25584 + * GNU General Public License for more details.
25586 + * You should have received a copy of the GNU General Public License
25587 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25591 + * support for loopback mount as a branch
25594 +#ifndef __AUFS_LOOP_H__
25595 +#define __AUFS_LOOP_H__
25600 +struct super_block;
25602 +#ifdef CONFIG_AUFS_BDEV_LOOP
25603 +/* drivers/block/loop.c */
25604 +struct file *loop_backing_file(struct super_block *sb);
25607 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25608 +int au_test_loopback_kthread(void);
25609 +void au_warn_loopback(struct super_block *h_sb);
25611 +int au_loopback_init(void);
25612 +void au_loopback_fin(void);
25614 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25616 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25617 + struct dentry *h_adding)
25618 +AuStubInt0(au_test_loopback_kthread, void)
25619 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25621 +AuStubInt0(au_loopback_init, void)
25622 +AuStubVoid(au_loopback_fin, void)
25623 +#endif /* BLK_DEV_LOOP */
25625 +#endif /* __KERNEL__ */
25626 +#endif /* __AUFS_LOOP_H__ */
25627 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25628 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25629 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25631 +# SPDX-License-Identifier: GPL-2.0
25633 +# defined in ${srctree}/fs/fuse/inode.c
25635 +ifdef CONFIG_FUSE_FS
25636 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25639 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25641 +ifdef CONFIG_XFS_FS
25642 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25645 +# defined in ${srctree}/fs/configfs/mount.c
25647 +ifdef CONFIG_CONFIGFS_FS
25648 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25651 +# defined in ${srctree}/fs/ubifs/ubifs.h
25653 +ifdef CONFIG_UBIFS_FS
25654 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25657 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25659 +ifdef CONFIG_HFSPLUS_FS
25660 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25662 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25663 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25664 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25666 +# SPDX-License-Identifier: GPL-2.0
25668 +include ${src}/magic.mk
25669 +ifeq (${CONFIG_AUFS_FS},m)
25670 +include ${src}/conf.mk
25672 +-include ${src}/priv_def.mk
25674 +# cf. include/linux/kernel.h
25676 +ccflags-y += -DDEBUG
25677 +# sparse requires the full pathname
25679 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25681 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25684 +obj-$(CONFIG_AUFS_FS) += aufs.o
25685 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25686 + wkq.o vfsub.o dcsub.o \
25687 + cpup.o whout.o wbr_policy.o \
25688 + dinfo.o dentry.o \
25690 + finfo.o file.o f_op.o \
25692 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25696 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25697 +aufs-$(CONFIG_SYSFS) += sysfs.o
25698 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25699 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25700 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25701 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25702 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25703 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25704 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25705 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25706 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25707 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25708 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25709 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25710 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25711 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25712 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25713 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25714 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25716 +// SPDX-License-Identifier: GPL-2.0
25718 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25720 + * This program is free software; you can redistribute it and/or modify
25721 + * it under the terms of the GNU General Public License as published by
25722 + * the Free Software Foundation; either version 2 of the License, or
25723 + * (at your option) any later version.
25725 + * This program is distributed in the hope that it will be useful,
25726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25728 + * GNU General Public License for more details.
25730 + * You should have received a copy of the GNU General Public License
25731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25735 + * module global variables and operations
25738 +#include <linux/module.h>
25739 +#include <linux/seq_file.h>
25742 +/* shrinkable realloc */
25743 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25751 +#if 0 /* unused */
25758 + AuDebugOn(!new_sz);
25761 + diff = au_kmidx_sub(sz, new_sz);
25767 + /* expand or SLOB */
25768 + p = krealloc(p, new_sz, gfp);
25769 + else if (new_sz < sz && may_shrink) {
25773 + q = kmalloc(new_sz, gfp);
25776 + memcpy(q, p, new_sz);
25777 + au_kfree_try_rcu(p);
25788 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25791 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25792 + if (p && new_sz > nused)
25793 + memset(p + nused, 0, new_sz - nused);
25797 +/* ---------------------------------------------------------------------- */
25801 +struct kmem_cache *au_cache[AuCache_Last];
25803 +static void au_cache_fin(void)
25808 + * Make sure all delayed rcu free inodes are flushed before we
25813 + /* excluding AuCache_HNOTIFY */
25814 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25815 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25816 + kmem_cache_destroy(au_cache[i]);
25817 + au_cache[i] = NULL;
25821 +static int __init au_cache_init(void)
25823 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25824 + if (au_cache[AuCache_DINFO])
25825 + /* SLAB_DESTROY_BY_RCU */
25826 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25827 + au_icntnr_init_once);
25828 + if (au_cache[AuCache_ICNTNR])
25829 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25830 + au_fi_init_once);
25831 + if (au_cache[AuCache_FINFO])
25832 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25833 + if (au_cache[AuCache_VDIR])
25834 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25835 + if (au_cache[AuCache_DEHSTR])
25842 +/* ---------------------------------------------------------------------- */
25844 +int au_dir_roflags;
25846 +#ifdef CONFIG_AUFS_SBILIST
25848 + * iterate_supers_type() doesn't protect us from
25849 + * remounting (branch management)
25851 +struct hlist_bl_head au_sbilist;
25855 + * functions for module interface.
25857 +MODULE_LICENSE("GPL");
25858 +/* MODULE_LICENSE("GPL v2"); */
25859 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25860 +MODULE_DESCRIPTION(AUFS_NAME
25861 + " -- Advanced multi layered unification filesystem");
25862 +MODULE_VERSION(AUFS_VERSION);
25863 +MODULE_ALIAS_FS(AUFS_NAME);
25865 +/* this module parameter has no meaning when SYSFS is disabled */
25866 +int sysaufs_brs = 1;
25867 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25868 +module_param_named(brs, sysaufs_brs, int, 0444);
25870 +/* this module parameter has no meaning when USER_NS is disabled */
25872 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25873 +module_param_named(allow_userns, au_userns, bool, 0444);
25875 +/* ---------------------------------------------------------------------- */
25877 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25879 +int au_seq_path(struct seq_file *seq, struct path *path)
25883 + err = seq_path(seq, path, au_esc_chars);
25892 +/* ---------------------------------------------------------------------- */
25894 +static int __init aufs_init(void)
25899 + p = au_esc_chars;
25900 + for (i = 1; i <= ' '; i++)
25906 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25908 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25909 + for (i = 0; i < AuIop_Last; i++)
25910 + aufs_iop_nogetattr[i].getattr = NULL;
25912 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25914 + au_sbilist_init();
25915 + sysaufs_brs_init();
25918 + err = sysaufs_init();
25919 + if (unlikely(err))
25921 + err = dbgaufs_init();
25922 + if (unlikely(err))
25923 + goto out_sysaufs;
25924 + err = au_procfs_init();
25925 + if (unlikely(err))
25926 + goto out_dbgaufs;
25927 + err = au_wkq_init();
25928 + if (unlikely(err))
25930 + err = au_loopback_init();
25931 + if (unlikely(err))
25933 + err = au_hnotify_init();
25934 + if (unlikely(err))
25935 + goto out_loopback;
25936 + err = au_sysrq_init();
25937 + if (unlikely(err))
25939 + err = au_cache_init();
25940 + if (unlikely(err))
25943 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25944 + err = register_filesystem(&aufs_fs_type);
25945 + if (unlikely(err))
25948 + /* since we define pr_fmt, call printk directly */
25949 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25950 + goto out; /* success */
25957 + au_hnotify_fin();
25959 + au_loopback_fin();
25973 +static void __exit aufs_exit(void)
25975 + unregister_filesystem(&aufs_fs_type);
25978 + au_hnotify_fin();
25979 + au_loopback_fin();
25987 +module_init(aufs_init);
25988 +module_exit(aufs_exit);
25989 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
25990 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
25991 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
25993 +/* SPDX-License-Identifier: GPL-2.0 */
25995 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25997 + * This program is free software; you can redistribute it and/or modify
25998 + * it under the terms of the GNU General Public License as published by
25999 + * the Free Software Foundation; either version 2 of the License, or
26000 + * (at your option) any later version.
26002 + * This program is distributed in the hope that it will be useful,
26003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26005 + * GNU General Public License for more details.
26007 + * You should have received a copy of the GNU General Public License
26008 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26012 + * module initialization and module-global
26015 +#ifndef __AUFS_MODULE_H__
26016 +#define __AUFS_MODULE_H__
26020 +#include <linux/slab.h>
26021 +#include "debug.h"
26022 +#include "dentry.h"
26025 +#include "inode.h"
26030 +/* module parameters */
26031 +extern int sysaufs_brs;
26032 +extern bool au_userns;
26034 +/* ---------------------------------------------------------------------- */
26036 +extern int au_dir_roflags;
26038 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26039 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26043 + * Comparing the size of the object with sizeof(struct rcu_head)
26044 + * case 1: object is always larger
26045 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26046 + * case 2: object is always smaller
26047 + * --> au_kfree_small()
26048 + * case 3: object can be any size
26049 + * --> au_kfree_try_rcu()
26052 +static inline void au_kfree_do_rcu(const void *p)
26055 + struct rcu_head rcu;
26056 + } *a = (void *)p;
26058 + kfree_rcu(a, rcu);
26061 +#define au_kfree_rcu(_p) do { \
26062 + typeof(_p) p = (_p); \
26063 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26065 + au_kfree_do_rcu(p); \
26068 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26069 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26071 +static inline void au_kfree_try_rcu(const void *p)
26075 + if (au_kfree_sz_test(p))
26076 + au_kfree_do_rcu(p);
26081 +static inline void au_kfree_small(const void *p)
26085 + AuDebugOn(au_kfree_sz_test(p));
26089 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26091 +#ifndef CONFIG_SLOB
26092 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26094 + return -1; /* SLOB is untested */
26098 +int au_seq_path(struct seq_file *seq, struct path *path);
26100 +#ifdef CONFIG_PROC_FS
26102 +int __init au_procfs_init(void);
26103 +void au_procfs_fin(void);
26105 +AuStubInt0(au_procfs_init, void);
26106 +AuStubVoid(au_procfs_fin, void);
26109 +/* ---------------------------------------------------------------------- */
26118 + AuCache_HNOTIFY, /* must be last */
26122 +extern struct kmem_cache *au_cache[AuCache_Last];
26124 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26125 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26126 +#define AuCacheCtor(type, ctor) \
26127 + kmem_cache_create(#type, sizeof(struct type), \
26128 + __alignof__(struct type), AuCacheFlags, ctor)
26130 +#define AuCacheFuncAlloc(name, index) \
26131 + static inline struct au_##name *au_cache_alloc_##name(void) \
26132 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26134 +#define AuCacheFuncs(name, index) \
26135 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26136 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26138 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26139 + { void *p = rcu; \
26140 + p -= offsetof(struct au_##name, rcu); \
26141 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26142 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26143 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26144 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26146 + static inline void au_cache_free_##name(struct au_##name *p) \
26147 + { /* au_cache_free_##name##_norcu(p); */ \
26148 + au_cache_free_##name##_rcu(p); }
26150 +AuCacheFuncs(dinfo, DINFO);
26151 +AuCacheFuncAlloc(dinfo, DINFO);
26153 +AuCacheFuncs(icntnr, ICNTNR);
26154 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26155 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26157 +AuCacheFuncs(finfo, FINFO);
26158 +AuCacheFuncAlloc(finfo, FINFO);
26160 +AuCacheFuncs(vdir, VDIR);
26161 +AuCacheFuncAlloc(vdir, VDIR);
26163 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26164 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26166 +#ifdef CONFIG_AUFS_HNOTIFY
26167 +AuCacheFuncs(hnotify, HNOTIFY);
26168 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26171 +#endif /* __KERNEL__ */
26172 +#endif /* __AUFS_MODULE_H__ */
26173 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26174 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26175 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26177 +// SPDX-License-Identifier: GPL-2.0
26179 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26181 + * This program is free software; you can redistribute it and/or modify
26182 + * it under the terms of the GNU General Public License as published by
26183 + * the Free Software Foundation; either version 2 of the License, or
26184 + * (at your option) any later version.
26186 + * This program is distributed in the hope that it will be useful,
26187 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26188 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26189 + * GNU General Public License for more details.
26191 + * You should have received a copy of the GNU General Public License
26192 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26196 + * move-down, opposite of copy-up
26201 +struct au_mvd_args {
26203 + struct super_block *h_sb;
26204 + struct dentry *h_parent;
26205 + struct au_hinode *hdir;
26206 + struct inode *h_dir, *h_inode;
26207 + struct au_pin pin;
26208 + } info[AUFS_MVDOWN_NARRAY];
26210 + struct aufs_mvdown mvdown;
26211 + struct dentry *dentry, *parent;
26212 + struct inode *inode, *dir;
26213 + struct super_block *sb;
26214 + aufs_bindex_t bopq, bwh, bfound;
26215 + unsigned char rename_lock;
26218 +#define mvd_errno mvdown.au_errno
26219 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26220 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26221 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26222 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26224 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26225 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26226 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26227 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26228 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26229 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26231 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26232 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26233 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26234 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26235 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26236 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26238 +#define AU_MVD_PR(flag, ...) do { \
26240 + pr_err(__VA_ARGS__); \
26243 +static int find_lower_writable(struct au_mvd_args *a)
26245 + struct super_block *sb;
26246 + aufs_bindex_t bindex, bbot;
26247 + struct au_branch *br;
26250 + bindex = a->mvd_bsrc;
26251 + bbot = au_sbbot(sb);
26252 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26253 + for (bindex++; bindex <= bbot; bindex++) {
26254 + br = au_sbr(sb, bindex);
26255 + if (au_br_fhsm(br->br_perm)
26256 + && !sb_rdonly(au_br_sb(br)))
26259 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26260 + for (bindex++; bindex <= bbot; bindex++) {
26261 + br = au_sbr(sb, bindex);
26262 + if (!au_br_rdonly(br))
26266 + for (bindex++; bindex <= bbot; bindex++) {
26267 + br = au_sbr(sb, bindex);
26268 + if (!sb_rdonly(au_br_sb(br))) {
26269 + if (au_br_rdonly(br))
26271 + |= AUFS_MVDOWN_ROLOWER_R;
26279 +/* make the parent dir on bdst */
26280 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26285 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26286 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26287 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26288 + a->mvd_h_dst_parent = NULL;
26289 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26290 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26291 + if (!a->mvd_h_dst_parent) {
26292 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26293 + if (unlikely(err)) {
26294 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26297 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26305 +/* lock them all */
26306 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26309 + struct dentry *h_trap;
26311 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26312 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26313 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26314 + au_opt_udba(a->sb),
26315 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26317 + if (unlikely(err)) {
26318 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26322 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26323 + a->rename_lock = 0;
26324 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26325 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26326 + au_opt_udba(a->sb),
26327 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26328 + err = au_do_pin(&a->mvd_pin_src);
26330 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26331 + if (unlikely(err)) {
26332 + AU_MVD_PR(dmsg, "pin_src failed\n");
26335 + goto out; /* success */
26338 + a->rename_lock = 1;
26339 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26340 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26341 + au_opt_udba(a->sb),
26342 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26344 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26345 + if (unlikely(err)) {
26346 + AU_MVD_PR(dmsg, "pin_src failed\n");
26347 + au_pin_hdir_lock(&a->mvd_pin_dst);
26350 + au_pin_hdir_unlock(&a->mvd_pin_src);
26351 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26352 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26354 + err = (h_trap != a->mvd_h_src_parent);
26356 + err = (h_trap != a->mvd_h_dst_parent);
26358 + BUG_ON(err); /* it should never happen */
26359 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26362 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26363 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26364 + au_pin_hdir_lock(&a->mvd_pin_src);
26365 + au_unpin(&a->mvd_pin_src);
26366 + au_pin_hdir_lock(&a->mvd_pin_dst);
26369 + goto out; /* success */
26372 + au_unpin(&a->mvd_pin_dst);
26378 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26380 + if (!a->rename_lock)
26381 + au_unpin(&a->mvd_pin_src);
26383 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26384 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26385 + au_pin_hdir_lock(&a->mvd_pin_src);
26386 + au_unpin(&a->mvd_pin_src);
26387 + au_pin_hdir_lock(&a->mvd_pin_dst);
26389 + au_unpin(&a->mvd_pin_dst);
26392 +/* copy-down the file */
26393 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26396 + struct au_cp_generic cpg = {
26397 + .dentry = a->dentry,
26398 + .bdst = a->mvd_bdst,
26399 + .bsrc = a->mvd_bsrc,
26401 + .pin = &a->mvd_pin_dst,
26402 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26405 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26406 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26407 + au_fset_cpup(cpg.flags, OVERWRITE);
26408 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26409 + au_fset_cpup(cpg.flags, RWDST);
26410 + err = au_sio_cpdown_simple(&cpg);
26411 + if (unlikely(err))
26412 + AU_MVD_PR(dmsg, "cpdown failed\n");
26419 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26422 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26425 + struct path h_path;
26426 + struct au_branch *br;
26427 + struct inode *delegated;
26429 + br = au_sbr(a->sb, a->mvd_bdst);
26430 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26431 + err = PTR_ERR(h_path.dentry);
26432 + if (IS_ERR(h_path.dentry)) {
26433 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26438 + if (d_is_positive(h_path.dentry)) {
26439 + h_path.mnt = au_br_mnt(br);
26440 + delegated = NULL;
26441 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26442 + &delegated, /*force*/0);
26443 + if (unlikely(err == -EWOULDBLOCK)) {
26444 + pr_warn("cannot retry for NFSv4 delegation"
26445 + " for an internal unlink\n");
26448 + if (unlikely(err))
26449 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26451 + dput(h_path.dentry);
26459 + * unlink the topmost h_dentry
26461 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26464 + struct path h_path;
26465 + struct inode *delegated;
26467 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26468 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26469 + delegated = NULL;
26470 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26471 + if (unlikely(err == -EWOULDBLOCK)) {
26472 + pr_warn("cannot retry for NFSv4 delegation"
26473 + " for an internal unlink\n");
26476 + if (unlikely(err))
26477 + AU_MVD_PR(dmsg, "unlink failed\n");
26483 +/* Since mvdown succeeded, we ignore an error of this function */
26484 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26487 + struct au_branch *br;
26489 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26490 + br = au_sbr(a->sb, a->mvd_bsrc);
26491 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26493 + br = au_sbr(a->sb, a->mvd_bdst);
26494 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26495 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26498 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26500 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26504 + * copy-down the file and unlink the bsrc file.
26505 + * - unlink the bdst whout if exist
26506 + * - copy-down the file (with whtmp name and rename)
26507 + * - unlink the bsrc file
26509 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26513 + err = au_do_mkdir(dmsg, a);
26515 + err = au_do_lock(dmsg, a);
26516 + if (unlikely(err))
26520 + * do not revert the activities we made on bdst since they should be
26521 + * harmless in aufs.
26524 + err = au_do_cpdown(dmsg, a);
26526 + err = au_do_unlink_wh(dmsg, a);
26527 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26528 + err = au_do_unlink(dmsg, a);
26529 + if (unlikely(err))
26532 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26533 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26534 + if (find_lower_writable(a) < 0)
26535 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26537 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26538 + au_do_stfs(dmsg, a);
26540 + /* maintain internal array */
26541 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26542 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26543 + au_set_dbtop(a->dentry, a->mvd_bdst);
26544 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26545 + au_set_ibtop(a->inode, a->mvd_bdst);
26547 + /* hide the lower */
26548 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26549 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26550 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26551 + au_set_ibbot(a->inode, a->mvd_bsrc);
26553 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26554 + au_set_dbbot(a->dentry, a->mvd_bdst);
26555 + if (au_ibbot(a->inode) < a->mvd_bdst)
26556 + au_set_ibbot(a->inode, a->mvd_bdst);
26559 + au_do_unlock(dmsg, a);
26565 +/* ---------------------------------------------------------------------- */
26567 +/* make sure the file is idle */
26568 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26570 + int err, plinked;
26573 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26574 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26575 + && au_dcount(a->dentry) == 1
26576 + && atomic_read(&a->inode->i_count) == 1
26577 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26578 + && (!plinked || !au_plink_test(a->inode))
26579 + && a->inode->i_nlink == 1)
26584 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26585 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26586 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26587 + a->mvd_h_src_inode->i_nlink,
26588 + plinked, plinked ? au_plink_test(a->inode) : 0);
26595 +/* make sure the parent dir is fine */
26596 +static int au_mvd_args_parent(const unsigned char dmsg,
26597 + struct au_mvd_args *a)
26600 + aufs_bindex_t bindex;
26603 + if (unlikely(au_alive_dir(a->parent))) {
26605 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26609 + a->bopq = au_dbdiropq(a->parent);
26610 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26611 + AuDbg("b%d\n", bindex);
26612 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26613 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26615 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26616 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26617 + a->bopq, a->mvd_bdst);
26625 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26626 + struct au_mvd_args *a)
26629 + struct au_dinfo *dinfo, *tmp;
26631 + /* lookup the next lower positive entry */
26633 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26634 + if (unlikely(!tmp))
26639 + dinfo = au_di(a->dentry);
26640 + au_di_cp(tmp, dinfo);
26641 + au_di_swap(tmp, dinfo);
26643 + /* returns the number of positive dentries */
26644 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26645 + /* AuLkup_IGNORE_PERM */ 0);
26647 + a->bwh = au_dbwh(a->dentry);
26648 + else if (err > 0)
26649 + a->bfound = au_dbtop(a->dentry);
26651 + au_di_swap(tmp, dinfo);
26652 + au_rw_write_unlock(&tmp->di_rwsem);
26654 + if (unlikely(err < 0))
26655 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26658 + * here, we have these cases.
26660 + * no positive dentry under bsrc. there are more sub-cases.
26662 + * there no whiteout, we can safely move-down.
26665 + * bsrc < bwh && bwh < bdst
26666 + * there is a whiteout on RO branch. cannot proceed.
26668 + * there is a whiteout on the RW target branch. it should
26671 + * there is a whiteout somewhere unrelated branch.
26672 + * -1 < bfound && bfound <= bsrc
26675 + * found, but it is on RO branch between bsrc and bdst. cannot
26678 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26681 + * found, after we create the file on bdst, it will be hidden.
26684 + AuDebugOn(a->bfound == -1
26686 + && a->bwh <= a->mvd_bsrc);
26687 + AuDebugOn(-1 < a->bfound
26688 + && a->bfound <= a->mvd_bsrc);
26691 + if (a->bfound == -1
26692 + && a->mvd_bsrc < a->bwh
26694 + && a->bwh < a->mvd_bdst) {
26695 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26696 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26697 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26699 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26700 + a->mvd_errno = EAU_MVDOWN_UPPER;
26701 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26702 + a->mvd_bdst, a->bfound);
26706 + err = 0; /* success */
26713 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26718 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26719 + && a->bfound == a->mvd_bdst)
26725 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26728 + struct au_branch *br;
26731 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26735 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26736 + a->mvd_bsrc = au_ibtop(a->inode);
26738 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26739 + if (unlikely(a->mvd_bsrc < 0
26740 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26741 + || au_dbbot(a->dentry) < a->mvd_bsrc
26742 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26743 + || (a->mvd_bsrc < au_ibtop(a->inode)
26744 + || au_ibbot(a->inode) < a->mvd_bsrc
26745 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26746 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26747 + AU_MVD_PR(dmsg, "no upper\n");
26751 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26752 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26753 + AU_MVD_PR(dmsg, "on the bottom\n");
26756 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26757 + br = au_sbr(a->sb, a->mvd_bsrc);
26758 + err = au_br_rdonly(br);
26759 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26760 + if (unlikely(err))
26762 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26763 + || IS_APPEND(a->mvd_h_src_inode))) {
26765 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26771 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26772 + a->mvd_bdst = find_lower_writable(a);
26773 + if (unlikely(a->mvd_bdst < 0)) {
26774 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26775 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26779 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26780 + if (unlikely(a->mvd_bdst < 0
26781 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26782 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26783 + AU_MVD_PR(dmsg, "no lower brid\n");
26788 + err = au_mvd_args_busy(dmsg, a);
26790 + err = au_mvd_args_parent(dmsg, a);
26792 + err = au_mvd_args_intermediate(dmsg, a);
26794 + err = au_mvd_args_exist(dmsg, a);
26796 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26803 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26806 + unsigned char dmsg;
26807 + struct au_mvd_args *args;
26808 + struct inode *inode;
26810 + inode = d_inode(dentry);
26812 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26816 + args = kmalloc(sizeof(*args), GFP_NOFS);
26817 + if (unlikely(!args))
26820 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26822 + /* VERIFY_WRITE */
26823 + err = !access_ok(uarg, sizeof(*uarg));
26824 + if (unlikely(err)) {
26829 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26830 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26831 + args->mvdown.au_errno = 0;
26832 + args->dentry = dentry;
26833 + args->inode = inode;
26834 + args->sb = dentry->d_sb;
26837 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26838 + args->parent = dget_parent(dentry);
26839 + args->dir = d_inode(args->parent);
26840 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26841 + dput(args->parent);
26842 + if (unlikely(args->parent != dentry->d_parent)) {
26843 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26847 + inode_lock_nested(inode, I_MUTEX_CHILD);
26848 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26849 + if (unlikely(err))
26852 + di_write_lock_parent(args->parent);
26853 + err = au_mvd_args(dmsg, args);
26854 + if (unlikely(err))
26857 + err = au_do_mvdown(dmsg, args);
26858 + if (unlikely(err))
26861 + au_cpup_attr_timesizes(args->dir);
26862 + au_cpup_attr_timesizes(inode);
26863 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26864 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26865 + /* au_digen_dec(dentry); */
26868 + di_write_unlock(args->parent);
26869 + aufs_read_unlock(dentry, AuLock_DW);
26871 + inode_unlock(inode);
26873 + inode_unlock(args->dir);
26875 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26878 + au_kfree_rcu(args);
26883 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26884 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26885 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26887 +// SPDX-License-Identifier: GPL-2.0
26889 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26891 + * This program is free software; you can redistribute it and/or modify
26892 + * it under the terms of the GNU General Public License as published by
26893 + * the Free Software Foundation; either version 2 of the License, or
26894 + * (at your option) any later version.
26896 + * This program is distributed in the hope that it will be useful,
26897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26899 + * GNU General Public License for more details.
26901 + * You should have received a copy of the GNU General Public License
26902 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26906 + * mount options/flags
26909 +#include <linux/types.h> /* a distribution requires */
26910 +#include <linux/parser.h>
26913 +/* ---------------------------------------------------------------------- */
26915 +static const char *au_parser_pattern(int val, match_table_t tbl)
26917 + struct match_token *p;
26920 + while (p->pattern) {
26921 + if (p->token == val)
26922 + return p->pattern;
26929 +static const char *au_optstr(int *val, match_table_t tbl)
26931 + struct match_token *p;
26938 + while (p->pattern) {
26940 + && (v & p->token) == p->token) {
26941 + *val &= ~p->token;
26942 + return p->pattern;
26951 +/* ---------------------------------------------------------------------- */
26953 +static match_table_t brperm = {
26954 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26955 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26956 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26960 +static match_table_t brattr = {
26962 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26963 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26964 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26965 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26966 +#ifdef CONFIG_AUFS_FHSM
26967 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26969 +#ifdef CONFIG_AUFS_XATTR
26970 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26971 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26972 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26973 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26974 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26975 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
26978 + /* ro/rr branch */
26979 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
26982 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
26983 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
26988 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
26995 + p = strchr(str, '+');
26998 + v = match_token(str, table, args);
27000 + if (v & AuBrAttr_CMOO_Mask)
27001 + attr &= ~AuBrAttr_CMOO_Mask;
27006 + pr_warn("ignored branch attribute %s\n", str);
27016 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27024 + p = au_optstr(&perm, brattr);
27027 + memcpy(q, p, sz + 1);
27033 + p = au_optstr(&perm, brattr);
27037 + memcpy(q, p, sz + 1);
27043 + return q - str->a;
27046 +int au_br_perm_val(char *perm)
27048 + int val, bad, sz;
27050 + substring_t args[MAX_OPT_ARGS];
27051 + au_br_perm_str_t attr;
27053 + p = strchr(perm, '+');
27056 + val = match_token(perm, brperm, args);
27060 + pr_warn("ignored branch permission %s\n", perm);
27061 + val = AuBrPerm_RO;
27067 + val |= br_attr_val(p + 1, brattr, args);
27070 + switch (val & AuBrPerm_Mask) {
27071 + case AuBrPerm_RO:
27072 + case AuBrPerm_RR:
27073 + bad = val & AuBrWAttr_Mask;
27074 + val &= ~AuBrWAttr_Mask;
27076 + case AuBrPerm_RW:
27077 + bad = val & AuBrRAttr_Mask;
27078 + val &= ~AuBrRAttr_Mask;
27083 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27084 + * does not treat it as an error, just warning.
27085 + * this is a tiny guard for the user operation.
27087 + if (val & AuBrAttr_UNPIN) {
27088 + bad |= AuBrAttr_UNPIN;
27089 + val &= ~AuBrAttr_UNPIN;
27092 + if (unlikely(bad)) {
27093 + sz = au_do_optstr_br_attr(&attr, bad);
27095 + pr_warn("ignored branch attribute %s\n", attr.a);
27102 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27104 + au_br_perm_str_t attr;
27110 + p = au_optstr(&perm, brperm);
27111 + AuDebugOn(!p || !*p);
27113 + memcpy(q, p, sz + 1);
27116 + sz = au_do_optstr_br_attr(&attr, perm);
27119 + memcpy(q, attr.a, sz + 1);
27122 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27125 +/* ---------------------------------------------------------------------- */
27127 +static match_table_t udbalevel = {
27128 + {AuOpt_UDBA_REVAL, "reval"},
27129 + {AuOpt_UDBA_NONE, "none"},
27130 +#ifdef CONFIG_AUFS_HNOTIFY
27131 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27132 +#ifdef CONFIG_AUFS_HFSNOTIFY
27133 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27139 +int au_udba_val(char *str)
27141 + substring_t args[MAX_OPT_ARGS];
27143 + return match_token(str, udbalevel, args);
27146 +const char *au_optstr_udba(int udba)
27148 + return au_parser_pattern(udba, udbalevel);
27151 +/* ---------------------------------------------------------------------- */
27153 +static match_table_t au_wbr_create_policy = {
27154 + {AuWbrCreate_TDP, "tdp"},
27155 + {AuWbrCreate_TDP, "top-down-parent"},
27156 + {AuWbrCreate_RR, "rr"},
27157 + {AuWbrCreate_RR, "round-robin"},
27158 + {AuWbrCreate_MFS, "mfs"},
27159 + {AuWbrCreate_MFS, "most-free-space"},
27160 + {AuWbrCreate_MFSV, "mfs:%d"},
27161 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27163 + /* top-down regardless the parent, and then mfs */
27164 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27165 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27167 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27168 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27169 + {AuWbrCreate_PMFS, "pmfs"},
27170 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27171 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27172 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27177 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27178 + struct au_opt_wbr_create *create)
27181 + unsigned long long ull;
27184 + if (!match_u64(arg, &ull))
27185 + create->mfsrr_watermark = ull;
27187 + pr_err("bad integer in %s\n", str);
27194 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27195 + struct au_opt_wbr_create *create)
27200 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27201 + create->mfs_second = n;
27203 + pr_err("bad integer in %s\n", str);
27210 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27213 + substring_t args[MAX_OPT_ARGS];
27215 + err = match_token(str, au_wbr_create_policy, args);
27216 + create->wbr_create = err;
27218 + case AuWbrCreate_MFSRRV:
27219 + case AuWbrCreate_TDMFSV:
27220 + case AuWbrCreate_PMFSRRV:
27221 + e = au_wbr_mfs_wmark(&args[0], str, create);
27223 + e = au_wbr_mfs_sec(&args[1], str, create);
27227 + case AuWbrCreate_MFSRR:
27228 + case AuWbrCreate_TDMFS:
27229 + case AuWbrCreate_PMFSRR:
27230 + e = au_wbr_mfs_wmark(&args[0], str, create);
27231 + if (unlikely(e)) {
27236 + case AuWbrCreate_MFS:
27237 + case AuWbrCreate_PMFS:
27238 + create->mfs_second = AUFS_MFS_DEF_SEC;
27240 + case AuWbrCreate_MFSV:
27241 + case AuWbrCreate_PMFSV:
27242 + e = au_wbr_mfs_sec(&args[0], str, create);
27251 +const char *au_optstr_wbr_create(int wbr_create)
27253 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27256 +static match_table_t au_wbr_copyup_policy = {
27257 + {AuWbrCopyup_TDP, "tdp"},
27258 + {AuWbrCopyup_TDP, "top-down-parent"},
27259 + {AuWbrCopyup_BUP, "bup"},
27260 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27261 + {AuWbrCopyup_BU, "bu"},
27262 + {AuWbrCopyup_BU, "bottom-up"},
27266 +int au_wbr_copyup_val(char *str)
27268 + substring_t args[MAX_OPT_ARGS];
27270 + return match_token(str, au_wbr_copyup_policy, args);
27273 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27275 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27278 +/* ---------------------------------------------------------------------- */
27280 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27281 + aufs_bindex_t bindex)
27284 + struct au_opt_add *add = &opt->add;
27287 + add->bindex = bindex;
27288 + add->perm = AuBrPerm_RO;
27289 + add->pathname = opt_str;
27290 + p = strchr(opt_str, '=');
27294 + add->perm = au_br_perm_val(p);
27297 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27300 + add->perm = AuBrPerm_RO;
27301 + if (au_test_fs_rr(add->path.dentry->d_sb))
27302 + add->perm = AuBrPerm_RR;
27303 + else if (!bindex && !(sb_flags & SB_RDONLY))
27304 + add->perm = AuBrPerm_RW;
27306 + opt->type = Opt_add;
27309 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27316 +static int au_opt_wbr_create(struct super_block *sb,
27317 + struct au_opt_wbr_create *create)
27320 + struct au_sbinfo *sbinfo;
27322 + SiMustWriteLock(sb);
27324 + err = 1; /* handled */
27325 + sbinfo = au_sbi(sb);
27326 + if (sbinfo->si_wbr_create_ops->fin) {
27327 + err = sbinfo->si_wbr_create_ops->fin(sb);
27332 + sbinfo->si_wbr_create = create->wbr_create;
27333 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27334 + switch (create->wbr_create) {
27335 + case AuWbrCreate_MFSRRV:
27336 + case AuWbrCreate_MFSRR:
27337 + case AuWbrCreate_TDMFS:
27338 + case AuWbrCreate_TDMFSV:
27339 + case AuWbrCreate_PMFSRR:
27340 + case AuWbrCreate_PMFSRRV:
27341 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27343 + case AuWbrCreate_MFS:
27344 + case AuWbrCreate_MFSV:
27345 + case AuWbrCreate_PMFS:
27346 + case AuWbrCreate_PMFSV:
27347 + sbinfo->si_wbr_mfs.mfs_expire
27348 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27352 + if (sbinfo->si_wbr_create_ops->init)
27353 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27360 + * plus: processed without an error
27361 + * zero: unprocessed
27363 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27364 + struct au_opts *opts)
27367 + struct au_sbinfo *sbinfo;
27369 + SiMustWriteLock(sb);
27371 + err = 1; /* handled */
27372 + sbinfo = au_sbi(sb);
27373 + switch (opt->type) {
27375 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27376 + sbinfo->si_mntflags |= opt->udba;
27377 + opts->given_udba |= opt->udba;
27382 + au_opt_set(sbinfo->si_mntflags, PLINK);
27384 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27385 + au_plink_put(sb, /*verbose*/1);
27386 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27389 + case Opt_list_plink:
27390 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27391 + au_plink_list(sb);
27396 + au_opt_set(sbinfo->si_mntflags, DIO);
27397 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27399 + au_opt_clr(sbinfo->si_mntflags, DIO);
27400 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27404 + case Opt_fhsm_sec:
27405 + au_fhsm_set(sbinfo, opt->fhsm_second);
27408 + case Opt_diropq_a:
27409 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27411 + case Opt_diropq_w:
27412 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27415 + case Opt_warn_perm:
27417 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27419 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27422 + case Opt_verbose:
27424 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27426 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27431 + au_opt_set(sbinfo->si_mntflags, SUM);
27433 + au_opt_clr(sbinfo->si_mntflags, SUM);
27434 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27438 + au_opt_clr(sbinfo->si_mntflags, SUM);
27439 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27442 + case Opt_wbr_create:
27443 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27445 + case Opt_wbr_copyup:
27446 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27447 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27451 + sbinfo->si_dirwh = opt->dirwh;
27454 + case Opt_rdcache:
27455 + sbinfo->si_rdcache
27456 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27459 + sbinfo->si_rdblk = opt->rdblk;
27462 + sbinfo->si_rdhash = opt->rdhash;
27467 + au_opt_set(sbinfo->si_mntflags, SHWH);
27469 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27472 + case Opt_dirperm1:
27474 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27476 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27479 + case Opt_trunc_xino:
27481 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27483 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27486 + case Opt_trunc_xino_path:
27487 + case Opt_itrunc_xino:
27488 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27494 + case Opt_trunc_xib:
27496 + au_fset_opts(opts->flags, TRUNC_XIB);
27498 + au_fclr_opts(opts->flags, TRUNC_XIB);
27504 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27505 + err = au_dr_opt_set(sb);
27510 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27512 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27513 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27519 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27525 + sb->s_flags |= SB_POSIXACL;
27527 + sb->s_flags &= ~SB_POSIXACL;
27539 + * returns tri-state.
27540 + * plus: processed without an error
27541 + * zero: unprocessed
27544 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27545 + struct au_opts *opts)
27547 + int err, do_refresh;
27550 + switch (opt->type) {
27552 + opt->add.bindex = au_sbbot(sb) + 1;
27553 + if (opt->add.bindex < 0)
27554 + opt->add.bindex = 0;
27556 + /* Always goto add, not fallthrough */
27557 + case Opt_prepend:
27558 + opt->add.bindex = 0;
27560 + add: /* indented label */
27562 + err = au_br_add(sb, &opt->add,
27563 + au_ftest_opts(opts->flags, REMOUNT));
27566 + au_fset_opts(opts->flags, REFRESH);
27572 + err = au_br_del(sb, &opt->del,
27573 + au_ftest_opts(opts->flags, REMOUNT));
27576 + au_fset_opts(opts->flags, TRUNC_XIB);
27577 + au_fset_opts(opts->flags, REFRESH);
27583 + err = au_br_mod(sb, &opt->mod,
27584 + au_ftest_opts(opts->flags, REMOUNT),
27589 + au_fset_opts(opts->flags, REFRESH);
27596 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27597 + struct au_opt_xino **opt_xino,
27598 + struct au_opts *opts)
27603 + switch (opt->type) {
27605 + err = au_xino_set(sb, &opt->xino,
27606 + !!au_ftest_opts(opts->flags, REMOUNT));
27608 + *opt_xino = &opt->xino;
27612 + *opt_xino = (void *)-1;
27619 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27620 + unsigned int pending)
27623 + aufs_bindex_t bindex, bbot;
27624 + unsigned char do_plink, skip, do_free, can_no_dreval;
27625 + struct au_branch *br;
27626 + struct au_wbr *wbr;
27627 + struct dentry *root, *dentry;
27628 + struct inode *dir, *h_dir;
27629 + struct au_sbinfo *sbinfo;
27630 + struct au_hinode *hdir;
27632 + SiMustAnyLock(sb);
27634 + sbinfo = au_sbi(sb);
27635 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27637 + if (!(sb_flags & SB_RDONLY)) {
27638 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27639 + pr_warn("first branch should be rw\n");
27640 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27641 + pr_warn_once("shwh should be used with ro\n");
27644 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27645 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27646 + pr_warn_once("udba=*notify requires xino\n");
27648 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27649 + pr_warn_once("dirperm1 breaks the protection"
27650 + " by the permission bits on the lower branch\n");
27654 + root = sb->s_root;
27655 + dir = d_inode(root);
27656 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27657 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27659 + bbot = au_sbbot(sb);
27660 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27662 + h_dir = au_h_iptr(dir, bindex);
27663 + br = au_sbr(sb, bindex);
27665 + if ((br->br_perm & AuBrAttr_ICEX)
27666 + && !h_dir->i_op->listxattr)
27667 + br->br_perm &= ~AuBrAttr_ICEX;
27668 +#if 0 /* untested */
27669 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27670 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27671 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27675 + wbr = br->br_wbr;
27677 + wbr_wh_read_lock(wbr);
27679 + if (!au_br_writable(br->br_perm)) {
27682 + || (!wbr->wbr_whbase
27683 + && !wbr->wbr_plink
27684 + && !wbr->wbr_orph));
27685 + } else if (!au_br_wh_linkable(br->br_perm)) {
27686 + /* skip = (!br->br_whbase && !br->br_orph); */
27687 + skip = (!wbr || !wbr->wbr_whbase);
27688 + if (skip && wbr) {
27690 + skip = !!wbr->wbr_plink;
27692 + skip = !wbr->wbr_plink;
27695 + /* skip = (br->br_whbase && br->br_ohph); */
27696 + skip = (wbr && wbr->wbr_whbase);
27699 + skip = !!wbr->wbr_plink;
27701 + skip = !wbr->wbr_plink;
27705 + wbr_wh_read_unlock(wbr);
27707 + if (can_no_dreval) {
27708 + dentry = br->br_path.dentry;
27709 + spin_lock(&dentry->d_lock);
27710 + if (dentry->d_flags &
27711 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27712 + can_no_dreval = 0;
27713 + spin_unlock(&dentry->d_lock);
27716 + if (au_br_fhsm(br->br_perm)) {
27718 + AuDebugOn(!br->br_fhsm);
27724 + hdir = au_hi(dir, bindex);
27725 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27727 + wbr_wh_write_lock(wbr);
27728 + err = au_wh_init(br, sb);
27730 + wbr_wh_write_unlock(wbr);
27731 + au_hn_inode_unlock(hdir);
27733 + if (!err && do_free) {
27734 + au_kfree_rcu(wbr);
27735 + br->br_wbr = NULL;
27739 + if (can_no_dreval)
27740 + au_fset_si(sbinfo, NO_DREVAL);
27742 + au_fclr_si(sbinfo, NO_DREVAL);
27745 + au_fset_si(sbinfo, FHSM);
27746 + for (bindex = bbot; bindex >= 0; bindex--) {
27747 + br = au_sbr(sb, bindex);
27748 + if (au_br_fhsm(br->br_perm)) {
27749 + au_fhsm_set_bottom(sb, bindex);
27754 + au_fclr_si(sbinfo, FHSM);
27755 + au_fhsm_set_bottom(sb, -1);
27761 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27764 + unsigned int tmp;
27765 + aufs_bindex_t bindex, bbot;
27766 + struct au_opt *opt;
27767 + struct au_opt_xino *opt_xino, xino;
27768 + struct au_sbinfo *sbinfo;
27769 + struct au_branch *br;
27770 + struct inode *dir;
27772 + SiMustWriteLock(sb);
27777 + while (err >= 0 && opt->type != Opt_tail)
27778 + err = au_opt_simple(sb, opt++, opts);
27781 + else if (unlikely(err < 0))
27784 + /* disable xino and udba temporary */
27785 + sbinfo = au_sbi(sb);
27786 + tmp = sbinfo->si_mntflags;
27787 + au_opt_clr(sbinfo->si_mntflags, XINO);
27788 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27791 + while (err >= 0 && opt->type != Opt_tail)
27792 + err = au_opt_br(sb, opt++, opts);
27795 + else if (unlikely(err < 0))
27798 + bbot = au_sbbot(sb);
27799 + if (unlikely(bbot < 0)) {
27801 + pr_err("no branches\n");
27805 + if (au_opt_test(tmp, XINO))
27806 + au_opt_set(sbinfo->si_mntflags, XINO);
27808 + while (!err && opt->type != Opt_tail)
27809 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27810 + if (unlikely(err))
27813 + err = au_opts_verify(sb, sb->s_flags, tmp);
27814 + if (unlikely(err))
27817 + /* restore xino */
27818 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27819 + xino.file = au_xino_def(sb);
27820 + err = PTR_ERR(xino.file);
27821 + if (IS_ERR(xino.file))
27824 + err = au_xino_set(sb, &xino, /*remount*/0);
27826 + if (unlikely(err))
27830 + /* restore udba */
27831 + tmp &= AuOptMask_UDBA;
27832 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27833 + sbinfo->si_mntflags |= tmp;
27834 + bbot = au_sbbot(sb);
27835 + for (bindex = 0; bindex <= bbot; bindex++) {
27836 + br = au_sbr(sb, bindex);
27837 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27838 + if (unlikely(err))
27839 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27841 + /* go on even if err */
27843 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27844 + dir = d_inode(sb->s_root);
27845 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27852 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27855 + unsigned char no_dreval;
27856 + struct inode *dir;
27857 + struct au_opt_xino *opt_xino;
27858 + struct au_opt *opt;
27859 + struct au_sbinfo *sbinfo;
27861 + SiMustWriteLock(sb);
27863 + err = au_dr_opt_flush(sb);
27864 + if (unlikely(err))
27866 + au_fset_opts(opts->flags, DR_FLUSHED);
27868 + dir = d_inode(sb->s_root);
27869 + sbinfo = au_sbi(sb);
27872 + while (err >= 0 && opt->type != Opt_tail) {
27873 + err = au_opt_simple(sb, opt, opts);
27875 + err = au_opt_br(sb, opt, opts);
27877 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27883 + /* go on even err */
27885 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27886 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27887 + if (unlikely(rerr && !err))
27890 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27891 + au_fset_opts(opts->flags, REFRESH_IDOP);
27893 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27894 + rerr = au_xib_trunc(sb);
27895 + if (unlikely(rerr && !err))
27899 + /* will be handled by the caller */
27900 + if (!au_ftest_opts(opts->flags, REFRESH)
27901 + && (opts->given_udba
27902 + || au_opt_test(sbinfo->si_mntflags, XINO)
27903 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27905 + au_fset_opts(opts->flags, REFRESH);
27907 + AuDbg("status 0x%x\n", opts->flags);
27913 +/* ---------------------------------------------------------------------- */
27915 +unsigned int au_opt_udba(struct super_block *sb)
27917 + return au_mntflags(sb) & AuOptMask_UDBA;
27919 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27920 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27921 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27923 +/* SPDX-License-Identifier: GPL-2.0 */
27925 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27927 + * This program is free software; you can redistribute it and/or modify
27928 + * it under the terms of the GNU General Public License as published by
27929 + * the Free Software Foundation; either version 2 of the License, or
27930 + * (at your option) any later version.
27932 + * This program is distributed in the hope that it will be useful,
27933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27935 + * GNU General Public License for more details.
27937 + * You should have received a copy of the GNU General Public License
27938 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27942 + * mount options/flags
27945 +#ifndef __AUFS_OPTS_H__
27946 +#define __AUFS_OPTS_H__
27950 +#include <linux/fs_parser.h>
27951 +#include <linux/namei.h>
27952 +#include <linux/path.h>
27956 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27957 + Opt_idel, Opt_imod,
27958 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27959 + Opt_xino, Opt_noxino,
27960 + Opt_trunc_xino, Opt_trunc_xino_v,
27961 + Opt_trunc_xino_path, Opt_itrunc_xino,
27964 + Opt_plink, Opt_list_plink,
27967 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27969 + Opt_wbr_copyup, Opt_wbr_create,
27971 + Opt_verbose, Opt_noverbose,
27972 + Opt_sum, Opt_wsum,
27976 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
27979 +/* ---------------------------------------------------------------------- */
27982 +#define AuOpt_XINO 1 /* external inode number bitmap
27983 + and translation table */
27984 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
27985 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
27986 +#define AuOpt_UDBA_REVAL (1 << 3)
27987 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
27988 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
27989 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
27990 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
27992 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
27993 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
27994 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
27995 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
27996 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
27997 +#define AuOpt_DIO (1 << 14) /* direct io */
27998 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
28000 +#ifndef CONFIG_AUFS_HNOTIFY
28001 +#undef AuOpt_UDBA_HNOTIFY
28002 +#define AuOpt_UDBA_HNOTIFY 0
28004 +#ifndef CONFIG_AUFS_DIRREN
28005 +#undef AuOpt_DIRREN
28006 +#define AuOpt_DIRREN 0
28008 +#ifndef CONFIG_AUFS_SHWH
28010 +#define AuOpt_SHWH 0
28013 +#define AuOpt_Def (AuOpt_XINO \
28014 + | AuOpt_UDBA_REVAL \
28016 + /* | AuOpt_DIRPERM1 */ \
28017 + | AuOpt_WARN_PERM)
28018 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28019 + | AuOpt_UDBA_REVAL \
28020 + | AuOpt_UDBA_HNOTIFY)
28022 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28024 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28025 +#define au_opt_set(flags, name) do { \
28026 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28027 + ((flags) |= AuOpt_##name); \
28029 +#define au_opt_set_udba(flags, name) do { \
28030 + (flags) &= ~AuOptMask_UDBA; \
28031 + ((flags) |= AuOpt_##name); \
28033 +#define au_opt_clr(flags, name) do { \
28034 + ((flags) &= ~AuOpt_##name); \
28037 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28039 +#ifdef CONFIG_PROC_FS
28042 + return mntflags & ~AuOpt_PLINK;
28046 +/* ---------------------------------------------------------------------- */
28048 +/* policies to select one among multiple writable branches */
28050 + AuWbrCreate_TDP, /* top down parent */
28051 + AuWbrCreate_RR, /* round robin */
28052 + AuWbrCreate_MFS, /* most free space */
28053 + AuWbrCreate_MFSV, /* mfs with seconds */
28054 + AuWbrCreate_MFSRR, /* mfs then rr */
28055 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28056 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28057 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28058 + AuWbrCreate_PMFS, /* parent and mfs */
28059 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28060 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28061 + AuWbrCreate_PMFSRRV, /* plus seconds */
28063 + AuWbrCreate_Def = AuWbrCreate_TDP
28067 + AuWbrCopyup_TDP, /* top down parent */
28068 + AuWbrCopyup_BUP, /* bottom up parent */
28069 + AuWbrCopyup_BU, /* bottom up */
28071 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28074 +/* ---------------------------------------------------------------------- */
28078 +struct au_opt_add {
28079 + aufs_bindex_t bindex;
28082 + struct path path;
28085 +struct au_opt_del {
28087 + struct path h_path;
28090 +struct au_opt_mod {
28093 + struct dentry *h_root;
28096 +struct au_opt_xino {
28098 + struct file *file;
28101 +struct au_opt_xino_itrunc {
28102 + aufs_bindex_t bindex;
28105 +struct au_opt_wbr_create {
28108 + unsigned long long mfsrr_watermark;
28114 + struct au_opt_xino xino;
28115 + struct au_opt_xino_itrunc xino_itrunc;
28116 + struct au_opt_add add;
28117 + struct au_opt_del del;
28118 + struct au_opt_mod mod;
28121 + unsigned int rdblk;
28122 + unsigned int rdhash;
28124 + struct au_opt_wbr_create wbr_create;
28126 + unsigned int fhsm_second;
28127 + bool tf; /* generic flag, true or false */
28132 +#define AuOpts_REMOUNT 1
28133 +#define AuOpts_REFRESH (1 << 1)
28134 +#define AuOpts_TRUNC_XIB (1 << 2)
28135 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28136 +#define AuOpts_REFRESH_IDOP (1 << 4)
28137 +#define AuOpts_DR_FLUSHED (1 << 5)
28138 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28139 +#define au_fset_opts(flags, name) \
28140 + do { (flags) |= AuOpts_##name; } while (0)
28141 +#define au_fclr_opts(flags, name) \
28142 + do { (flags) &= ~AuOpts_##name; } while (0)
28144 +#ifndef CONFIG_AUFS_DIRREN
28145 +#undef AuOpts_DR_FLUSHED
28146 +#define AuOpts_DR_FLUSHED 0
28150 + struct au_opt *opt;
28153 + unsigned int given_udba;
28154 + unsigned int flags;
28155 + unsigned long sb_flags;
28158 +/* ---------------------------------------------------------------------- */
28161 +int au_br_perm_val(char *perm);
28162 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28163 +int au_udba_val(char *str);
28164 +const char *au_optstr_udba(int udba);
28165 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28166 +const char *au_optstr_wbr_create(int wbr_create);
28167 +int au_wbr_copyup_val(char *str);
28168 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28170 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28171 + aufs_bindex_t bindex);
28172 +struct super_block;
28173 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28174 + unsigned int pending);
28175 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28176 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28178 +unsigned int au_opt_udba(struct super_block *sb);
28181 +int aufs_fsctx_init(struct fs_context *fc);
28182 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28184 +#endif /* __KERNEL__ */
28185 +#endif /* __AUFS_OPTS_H__ */
28186 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28187 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28188 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28190 +// SPDX-License-Identifier: GPL-2.0
28192 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28194 + * This program is free software; you can redistribute it and/or modify
28195 + * it under the terms of the GNU General Public License as published by
28196 + * the Free Software Foundation; either version 2 of the License, or
28197 + * (at your option) any later version.
28199 + * This program is distributed in the hope that it will be useful,
28200 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28201 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28202 + * GNU General Public License for more details.
28204 + * You should have received a copy of the GNU General Public License
28205 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28215 + * the pseudo-link maintenance mode.
28216 + * during a user process maintains the pseudo-links,
28217 + * prohibit adding a new plink and branch manipulation.
28221 + * For entry functions which will handle plink, and i_mutex is already held
28223 + * They cannot wait and should return an error at once.
28224 + * Callers has to check the error.
28226 + * For entry functions which will handle plink, but i_mutex is not held
28228 + * They can wait the plink maintenance mode to finish.
28230 + * They behave like F_SETLK and F_SETLKW.
28231 + * If the caller never handle plink, then both flags are unnecessary.
28234 +int au_plink_maint(struct super_block *sb, int flags)
28238 + struct task_struct *parent, *prev;
28239 + struct au_sbinfo *sbi;
28241 + SiMustAnyLock(sb);
28244 + if (!au_opt_test(au_mntflags(sb), PLINK))
28247 + sbi = au_sbi(sb);
28248 + pid = sbi->si_plink_maint_pid;
28249 + if (!pid || pid == current->pid)
28252 + /* todo: it highly depends upon /sbin/mount.aufs */
28254 + parent = current;
28258 + parent = rcu_dereference(parent->real_parent);
28259 + if (parent == prev)
28261 + ppid = task_pid_vnr(parent);
28262 + if (pid == ppid) {
28263 + rcu_read_unlock();
28268 + rcu_read_unlock();
28270 + if (au_ftest_lock(flags, NOPLMW)) {
28271 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28272 + /* AuDebugOn(!lockdep_depth(current)); */
28273 + while (sbi->si_plink_maint_pid) {
28274 + si_read_unlock(sb);
28275 + /* gave up wake_up_bit() */
28276 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28278 + if (au_ftest_lock(flags, FLUSH))
28279 + au_nwt_flush(&sbi->si_nowait);
28280 + si_noflush_read_lock(sb);
28282 + } else if (au_ftest_lock(flags, NOPLM)) {
28283 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28291 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28293 + spin_lock(&sbinfo->si_plink_maint_lock);
28294 + sbinfo->si_plink_maint_pid = 0;
28295 + spin_unlock(&sbinfo->si_plink_maint_lock);
28296 + wake_up_all(&sbinfo->si_plink_wq);
28299 +int au_plink_maint_enter(struct super_block *sb)
28302 + struct au_sbinfo *sbinfo;
28305 + sbinfo = au_sbi(sb);
28306 + /* make sure i am the only one in this fs */
28307 + si_write_lock(sb, AuLock_FLUSH);
28308 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28309 + spin_lock(&sbinfo->si_plink_maint_lock);
28310 + if (!sbinfo->si_plink_maint_pid)
28311 + sbinfo->si_plink_maint_pid = current->pid;
28314 + spin_unlock(&sbinfo->si_plink_maint_lock);
28316 + si_write_unlock(sb);
28321 +/* ---------------------------------------------------------------------- */
28323 +#ifdef CONFIG_AUFS_DEBUG
28324 +void au_plink_list(struct super_block *sb)
28327 + struct au_sbinfo *sbinfo;
28328 + struct hlist_bl_head *hbl;
28329 + struct hlist_bl_node *pos;
28330 + struct au_icntnr *icntnr;
28332 + SiMustAnyLock(sb);
28334 + sbinfo = au_sbi(sb);
28335 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28336 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28338 + for (i = 0; i < AuPlink_NHASH; i++) {
28339 + hbl = sbinfo->si_plink + i;
28340 + hlist_bl_lock(hbl);
28341 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28342 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28343 + hlist_bl_unlock(hbl);
28348 +/* is the inode pseudo-linked? */
28349 +int au_plink_test(struct inode *inode)
28352 + struct au_sbinfo *sbinfo;
28353 + struct hlist_bl_head *hbl;
28354 + struct hlist_bl_node *pos;
28355 + struct au_icntnr *icntnr;
28357 + sbinfo = au_sbi(inode->i_sb);
28358 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28359 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28360 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28363 + i = au_plink_hash(inode->i_ino);
28364 + hbl = sbinfo->si_plink + i;
28365 + hlist_bl_lock(hbl);
28366 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28367 + if (&icntnr->vfs_inode == inode) {
28371 + hlist_bl_unlock(hbl);
28375 +/* ---------------------------------------------------------------------- */
28378 + * generate a name for plink.
28379 + * the file will be stored under AUFS_WH_PLINKDIR.
28381 +/* 20 is max digits length of ulong 64 */
28382 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28384 +static int plink_name(char *name, int len, struct inode *inode,
28385 + aufs_bindex_t bindex)
28388 + struct inode *h_inode;
28390 + h_inode = au_h_iptr(inode, bindex);
28391 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28395 +struct au_do_plink_lkup_args {
28396 + struct dentry **errp;
28397 + struct qstr *tgtname;
28398 + struct path *h_ppath;
28401 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28402 + struct path *h_ppath)
28404 + struct dentry *h_dentry;
28405 + struct inode *h_inode;
28407 + h_inode = d_inode(h_ppath->dentry);
28408 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28409 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28410 + inode_unlock_shared(h_inode);
28415 +static void au_call_do_plink_lkup(void *args)
28417 + struct au_do_plink_lkup_args *a = args;
28418 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28421 +/* lookup the plink-ed @inode under the branch at @bindex */
28422 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28424 + struct dentry *h_dentry;
28425 + struct au_branch *br;
28426 + struct path h_ppath;
28428 + char a[PLINK_NAME_LEN];
28429 + struct qstr tgtname = QSTR_INIT(a, 0);
28431 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28433 + br = au_sbr(inode->i_sb, bindex);
28434 + h_ppath.dentry = br->br_wbr->wbr_plink;
28435 + h_ppath.mnt = au_br_mnt(br);
28436 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28438 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28439 + struct au_do_plink_lkup_args args = {
28440 + .errp = &h_dentry,
28441 + .tgtname = &tgtname,
28442 + .h_ppath = &h_ppath
28445 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28446 + if (unlikely(wkq_err))
28447 + h_dentry = ERR_PTR(wkq_err);
28449 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28454 +/* create a pseudo-link */
28455 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28456 + struct dentry *h_dentry)
28459 + struct path h_path;
28460 + struct inode *h_dir, *delegated;
28462 + h_dir = d_inode(h_ppath->dentry);
28463 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28464 + h_path.mnt = h_ppath->mnt;
28466 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28467 + err = PTR_ERR(h_path.dentry);
28468 + if (IS_ERR(h_path.dentry))
28472 + /* wh.plink dir is not monitored */
28473 + /* todo: is it really safe? */
28474 + if (d_is_positive(h_path.dentry)
28475 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28476 + delegated = NULL;
28477 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28478 + if (unlikely(err == -EWOULDBLOCK)) {
28479 + pr_warn("cannot retry for NFSv4 delegation"
28480 + " for an internal unlink\n");
28483 + dput(h_path.dentry);
28484 + h_path.dentry = NULL;
28488 + if (!err && d_is_negative(h_path.dentry)) {
28489 + delegated = NULL;
28490 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28491 + if (unlikely(err == -EWOULDBLOCK)) {
28492 + pr_warn("cannot retry for NFSv4 delegation"
28493 + " for an internal link\n");
28497 + dput(h_path.dentry);
28500 + inode_unlock(h_dir);
28504 +struct do_whplink_args {
28506 + struct qstr *tgt;
28507 + struct path *h_ppath;
28508 + struct dentry *h_dentry;
28511 +static void call_do_whplink(void *args)
28513 + struct do_whplink_args *a = args;
28514 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28517 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28518 + aufs_bindex_t bindex)
28520 + int err, wkq_err;
28521 + struct au_branch *br;
28522 + struct au_wbr *wbr;
28523 + struct path h_ppath;
28524 + char a[PLINK_NAME_LEN];
28525 + struct qstr tgtname = QSTR_INIT(a, 0);
28527 + br = au_sbr(inode->i_sb, bindex);
28528 + wbr = br->br_wbr;
28529 + h_ppath.dentry = wbr->wbr_plink;
28530 + h_ppath.mnt = au_br_mnt(br);
28531 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28533 + /* always superio. */
28534 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28535 + struct do_whplink_args args = {
28538 + .h_ppath = &h_ppath,
28539 + .h_dentry = h_dentry
28541 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28542 + if (unlikely(wkq_err))
28545 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28551 + * create a new pseudo-link for @h_dentry on @bindex.
28552 + * the linked inode is held in aufs @inode.
28554 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28555 + struct dentry *h_dentry)
28557 + struct super_block *sb;
28558 + struct au_sbinfo *sbinfo;
28559 + struct hlist_bl_head *hbl;
28560 + struct hlist_bl_node *pos;
28561 + struct au_icntnr *icntnr;
28562 + int found, err, cnt, i;
28564 + sb = inode->i_sb;
28565 + sbinfo = au_sbi(sb);
28566 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28567 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28569 + found = au_plink_test(inode);
28573 + i = au_plink_hash(inode->i_ino);
28574 + hbl = sbinfo->si_plink + i;
28577 + hlist_bl_lock(hbl);
28578 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28579 + if (&icntnr->vfs_inode == inode) {
28585 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28586 + hlist_bl_add_head(&icntnr->plink, hbl);
28588 + hlist_bl_unlock(hbl);
28590 + cnt = au_hbl_count(hbl);
28591 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28592 + if (cnt > AUFS_PLINK_WARN)
28593 + AuWarn1(msg ", %d\n", cnt);
28595 + err = whplink(h_dentry, inode, bindex);
28596 + if (unlikely(err)) {
28597 + pr_warn("err %d, damaged pseudo link.\n", err);
28598 + au_hbl_del(&icntnr->plink, hbl);
28599 + iput(&icntnr->vfs_inode);
28602 + iput(&icntnr->vfs_inode);
28605 +/* free all plinks */
28606 +void au_plink_put(struct super_block *sb, int verbose)
28609 + struct au_sbinfo *sbinfo;
28610 + struct hlist_bl_head *hbl;
28611 + struct hlist_bl_node *pos, *tmp;
28612 + struct au_icntnr *icntnr;
28614 + SiMustWriteLock(sb);
28616 + sbinfo = au_sbi(sb);
28617 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28618 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28620 + /* no spin_lock since sbinfo is write-locked */
28622 + for (i = 0; i < AuPlink_NHASH; i++) {
28623 + hbl = sbinfo->si_plink + i;
28624 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28625 + pr_warn("pseudo-link is not flushed");
28628 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28629 + iput(&icntnr->vfs_inode);
28630 + INIT_HLIST_BL_HEAD(hbl);
28634 +void au_plink_clean(struct super_block *sb, int verbose)
28636 + struct dentry *root;
28638 + root = sb->s_root;
28639 + aufs_write_lock(root);
28640 + if (au_opt_test(au_mntflags(sb), PLINK))
28641 + au_plink_put(sb, verbose);
28642 + aufs_write_unlock(root);
28645 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28648 + aufs_bindex_t btop, bbot, bindex;
28651 + btop = au_ibtop(inode);
28652 + bbot = au_ibbot(inode);
28654 + for (bindex = btop; bindex <= bbot; bindex++) {
28655 + if (!au_h_iptr(inode, bindex)
28656 + || au_ii_br_id(inode, bindex) != br_id)
28658 + au_set_h_iptr(inode, bindex, NULL, 0);
28663 + for (bindex = btop; bindex <= bbot; bindex++)
28664 + if (au_h_iptr(inode, bindex)) {
28674 +/* free the plinks on a branch specified by @br_id */
28675 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28677 + struct au_sbinfo *sbinfo;
28678 + struct hlist_bl_head *hbl;
28679 + struct hlist_bl_node *pos, *tmp;
28680 + struct au_icntnr *icntnr;
28681 + struct inode *inode;
28684 + SiMustWriteLock(sb);
28686 + sbinfo = au_sbi(sb);
28687 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28688 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28690 + /* no bit_lock since sbinfo is write-locked */
28691 + for (i = 0; i < AuPlink_NHASH; i++) {
28692 + hbl = sbinfo->si_plink + i;
28693 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28694 + inode = au_igrab(&icntnr->vfs_inode);
28695 + ii_write_lock_child(inode);
28696 + do_put = au_plink_do_half_refresh(inode, br_id);
28698 + hlist_bl_del(&icntnr->plink);
28701 + ii_write_unlock(inode);
28706 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28707 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28708 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28710 +// SPDX-License-Identifier: GPL-2.0
28712 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28714 + * This program is free software; you can redistribute it and/or modify
28715 + * it under the terms of the GNU General Public License as published by
28716 + * the Free Software Foundation; either version 2 of the License, or
28717 + * (at your option) any later version.
28719 + * This program is distributed in the hope that it will be useful,
28720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28722 + * GNU General Public License for more details.
28724 + * You should have received a copy of the GNU General Public License
28725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28730 + * There is only one filesystem which implements ->poll operation, currently.
28735 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28738 + struct file *h_file;
28739 + struct super_block *sb;
28741 + /* We should pretend an error happened. */
28742 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28743 + sb = file->f_path.dentry->d_sb;
28744 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28746 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28747 + if (IS_ERR(h_file)) {
28748 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28752 + mask = vfs_poll(h_file, pt);
28753 + fput(h_file); /* instead of au_read_post() */
28756 + si_read_unlock(sb);
28757 + if (mask & EPOLLERR)
28758 + AuDbg("mask 0x%x\n", mask);
28761 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28762 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28763 +++ linux/fs/aufs/posix_acl.c 2023-08-28 12:34:39.959969465 +0200
28765 +// SPDX-License-Identifier: GPL-2.0
28767 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28769 + * This program is free software; you can redistribute it and/or modify
28770 + * it under the terms of the GNU General Public License as published by
28771 + * the Free Software Foundation; either version 2 of the License, or
28772 + * (at your option) any later version.
28774 + * This program is distributed in the hope that it will be useful,
28775 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28776 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28777 + * GNU General Public License for more details.
28779 + * You should have received a copy of the GNU General Public License
28780 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28784 + * posix acl operations
28787 +#include <linux/fs.h>
28790 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu)
28792 + struct posix_acl *acl;
28794 + aufs_bindex_t bindex;
28795 + struct inode *h_inode;
28796 + struct super_block *sb;
28798 + acl = ERR_PTR(-ECHILD);
28803 + sb = inode->i_sb;
28804 + si_read_lock(sb, AuLock_FLUSH);
28805 + ii_read_lock_child(inode);
28806 + if (!(sb->s_flags & SB_POSIXACL))
28809 + bindex = au_ibtop(inode);
28810 + h_inode = au_h_iptr(inode, bindex);
28811 + if (unlikely(!h_inode
28812 + || ((h_inode->i_mode & S_IFMT)
28813 + != (inode->i_mode & S_IFMT)))) {
28814 + err = au_busy_or_stale();
28815 + acl = ERR_PTR(err);
28819 + /* always topmost only */
28820 + acl = get_inode_acl(h_inode, type);
28822 + forget_cached_acl(inode, type);
28824 + set_cached_acl(inode, type, acl);
28827 + ii_read_unlock(inode);
28828 + si_read_unlock(sb);
28831 + AuTraceErrPtr(acl);
28835 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
28836 + struct dentry *dentry, int type)
28838 + struct posix_acl *acl;
28839 + struct inode *inode;
28841 + inode = d_inode(dentry);
28842 + acl = aufs_get_inode_acl(inode, type, /*rcu*/false);
28847 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
28848 + struct posix_acl *acl, int type)
28852 + struct inode *inode;
28853 + struct au_sxattr arg = {
28854 + .type = AU_ACL_SET,
28861 + inode = d_inode(dentry);
28862 + IMustLock(inode);
28864 + ssz = au_sxattr(dentry, inode, &arg);
28865 + /* forget even it if succeeds since the branch might set differently */
28866 + forget_cached_acl(inode, type);
28873 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28874 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28875 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28877 +// SPDX-License-Identifier: GPL-2.0
28879 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28881 + * This program is free software; you can redistribute it and/or modify
28882 + * it under the terms of the GNU General Public License as published by
28883 + * the Free Software Foundation; either version 2 of the License, or
28884 + * (at your option) any later version.
28886 + * This program is distributed in the hope that it will be useful,
28887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28889 + * GNU General Public License for more details.
28891 + * You should have received a copy of the GNU General Public License
28892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28896 + * procfs interfaces
28899 +#include <linux/proc_fs.h>
28902 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28904 + struct au_sbinfo *sbinfo;
28906 + sbinfo = file->private_data;
28908 + au_plink_maint_leave(sbinfo);
28909 + kobject_put(&sbinfo->si_kobj);
28915 +static void au_procfs_plm_write_clean(struct file *file)
28917 + struct au_sbinfo *sbinfo;
28919 + sbinfo = file->private_data;
28921 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28924 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28927 + struct super_block *sb;
28928 + struct au_sbinfo *sbinfo;
28929 + struct hlist_bl_node *pos;
28932 + if (unlikely(file->private_data))
28936 + /* don't use au_sbilist_lock() here */
28937 + hlist_bl_lock(&au_sbilist);
28938 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28939 + if (id == sysaufs_si_id(sbinfo)) {
28940 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28941 + sb = sbinfo->si_sb;
28944 + hlist_bl_unlock(&au_sbilist);
28947 + if (unlikely(!sb))
28950 + err = au_plink_maint_enter(sb);
28952 + /* keep kobject_get() */
28953 + file->private_data = sbinfo;
28955 + kobject_put(&sbinfo->si_kobj);
28961 + * Accept a valid "si=xxxx" only.
28962 + * Once it is accepted successfully, accept "clean" too.
28964 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28965 + size_t count, loff_t *ppos)
28968 + unsigned long id;
28969 + /* last newline is allowed */
28970 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28973 + if (unlikely(!capable(CAP_SYS_ADMIN)))
28977 + if (unlikely(count > sizeof(buf)))
28980 + err = copy_from_user(buf, ubuf, count);
28981 + if (unlikely(err)) {
28988 + if (!strcmp("clean", buf)) {
28989 + au_procfs_plm_write_clean(file);
28990 + goto out_success;
28991 + } else if (unlikely(strncmp("si=", buf, 3)))
28994 + err = kstrtoul(buf + 3, 16, &id);
28995 + if (unlikely(err))
28998 + err = au_procfs_plm_write_si(file, id);
28999 + if (unlikely(err))
29003 + err = count; /* success */
29008 +static const struct proc_ops au_procfs_plm_op = {
29009 + .proc_write = au_procfs_plm_write,
29010 + .proc_release = au_procfs_plm_release
29013 +/* ---------------------------------------------------------------------- */
29015 +static struct proc_dir_entry *au_procfs_dir;
29017 +void au_procfs_fin(void)
29019 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29020 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29023 +int __init au_procfs_init(void)
29026 + struct proc_dir_entry *entry;
29029 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29030 + if (unlikely(!au_procfs_dir))
29033 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29034 + au_procfs_dir, &au_procfs_plm_op);
29035 + if (unlikely(!entry))
29039 + goto out; /* success */
29043 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29047 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29048 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29049 +++ linux/fs/aufs/rdu.c 2022-12-17 09:21:34.799855195 +0100
29051 +// SPDX-License-Identifier: GPL-2.0
29053 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29055 + * This program is free software; you can redistribute it and/or modify
29056 + * it under the terms of the GNU General Public License as published by
29057 + * the Free Software Foundation; either version 2 of the License, or
29058 + * (at your option) any later version.
29060 + * This program is distributed in the hope that it will be useful,
29061 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29062 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29063 + * GNU General Public License for more details.
29065 + * You should have received a copy of the GNU General Public License
29066 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29070 + * readdir in userspace.
29073 +#include <linux/compat.h>
29074 +#include <linux/fs_stack.h>
29075 +#include <linux/security.h>
29078 +/* bits for struct aufs_rdu.flags */
29079 +#define AuRdu_CALLED 1
29080 +#define AuRdu_CONT (1 << 1)
29081 +#define AuRdu_FULL (1 << 2)
29082 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29083 +#define au_fset_rdu(flags, name) \
29084 + do { (flags) |= AuRdu_##name; } while (0)
29085 +#define au_fclr_rdu(flags, name) \
29086 + do { (flags) &= ~AuRdu_##name; } while (0)
29088 +struct au_rdu_arg {
29089 + struct dir_context ctx;
29090 + struct aufs_rdu *rdu;
29091 + union au_rdu_ent_ul ent;
29092 + unsigned long end;
29094 + struct super_block *sb;
29098 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29099 + loff_t offset, u64 h_ino, unsigned int d_type)
29102 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29103 + struct aufs_rdu *rdu = arg->rdu;
29104 + struct au_rdu_ent ent;
29108 + au_fset_rdu(rdu->cookie.flags, CALLED);
29109 + len = au_rdu_len(nlen);
29110 + if (arg->ent.ul + len < arg->end) {
29112 + ent.bindex = rdu->cookie.bindex;
29113 + ent.type = d_type;
29115 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29116 + ent.type = DT_UNKNOWN;
29118 + /* unnecessary to support mmap_sem since this is a dir */
29120 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29122 + if (copy_to_user(arg->ent.e->name, name, nlen))
29124 + /* the terminating NULL */
29125 + if (__put_user(0, arg->ent.e->name + nlen))
29128 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29129 + arg->ent.ul += len;
29133 + au_fset_rdu(rdu->cookie.flags, FULL);
29135 + rdu->tail = arg->ent;
29139 + /* AuTraceErr(err); */
29143 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29147 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29149 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29150 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29152 + if (unlikely(offset != cookie->h_pos))
29158 + au_fclr_rdu(cookie->flags, CALLED);
29160 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29164 + && au_ftest_rdu(cookie->flags, CALLED)
29165 + && !au_ftest_rdu(cookie->flags, FULL));
29166 + cookie->h_pos = h_file->f_pos;
29173 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29176 + aufs_bindex_t bbot;
29177 + struct au_rdu_arg arg = {
29179 + .actor = au_rdu_fill
29182 + struct dentry *dentry;
29183 + struct inode *inode;
29184 + struct file *h_file;
29185 + struct au_rdu_cookie *cookie = &rdu->cookie;
29187 + /* VERIFY_WRITE */
29188 + err = !access_ok(rdu->ent.e, rdu->sz);
29189 + if (unlikely(err)) {
29195 + rdu->tail = rdu->ent;
29198 + arg.ent = rdu->ent;
29199 + arg.end = arg.ent.ul;
29200 + arg.end += rdu->sz;
29203 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29206 + err = security_file_permission(file, MAY_READ);
29208 + if (unlikely(err))
29211 + dentry = file->f_path.dentry;
29212 + inode = d_inode(dentry);
29213 + inode_lock_shared(inode);
29215 + arg.sb = inode->i_sb;
29216 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29217 + if (unlikely(err))
29219 + err = au_alive_dir(dentry);
29220 + if (unlikely(err))
29222 + /* todo: reval? */
29223 + fi_read_lock(file);
29226 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29227 + && cookie->generation != au_figen(file)))
29232 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29234 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29236 + bbot = au_fbtop(file);
29237 + if (cookie->bindex < bbot)
29238 + cookie->bindex = bbot;
29239 + bbot = au_fbbot_dir(file);
29240 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29241 + for (; !err && cookie->bindex <= bbot;
29242 + cookie->bindex++, cookie->h_pos = 0) {
29243 + h_file = au_hf_dir(file, cookie->bindex);
29247 + au_fclr_rdu(cookie->flags, FULL);
29248 + err = au_rdu_do(h_file, &arg);
29250 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29253 + AuDbg("rent %llu\n", rdu->rent);
29255 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29256 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29257 + au_fset_rdu(cookie->flags, CONT);
29258 + cookie->generation = au_figen(file);
29261 + ii_read_lock_child(inode);
29262 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29263 + ii_read_unlock(inode);
29266 + fi_read_unlock(file);
29268 + si_read_unlock(arg.sb);
29270 + inode_unlock_shared(inode);
29276 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29280 + unsigned long long nent;
29281 + union au_rdu_ent_ul *u;
29282 + struct au_rdu_ent ent;
29283 + struct super_block *sb;
29286 + nent = rdu->nent;
29288 + sb = file->f_path.dentry->d_sb;
29289 + si_read_lock(sb, AuLock_FLUSH);
29290 + while (nent-- > 0) {
29291 + /* unnecessary to support mmap_sem since this is a dir */
29292 + err = copy_from_user(&ent, u->e, sizeof(ent));
29294 + /* VERIFY_WRITE */
29295 + err = !access_ok(&u->e->ino, sizeof(ino));
29296 + if (unlikely(err)) {
29302 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29304 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29306 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29308 + if (unlikely(err)) {
29313 + err = __put_user(ino, &u->e->ino);
29314 + if (unlikely(err)) {
29319 + u->ul += au_rdu_len(ent.nlen);
29321 + si_read_unlock(sb);
29326 +/* ---------------------------------------------------------------------- */
29328 +static int au_rdu_verify(struct aufs_rdu *rdu)
29330 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29331 + "%llu, b%d, 0x%x, g%u}\n",
29332 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29334 + rdu->rent, rdu->shwh, rdu->full,
29335 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29336 + rdu->cookie.generation);
29338 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29342 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29346 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29349 + struct aufs_rdu rdu;
29350 + void __user *p = (void __user *)arg;
29352 + err = copy_from_user(&rdu, p, sizeof(rdu));
29353 + if (unlikely(err)) {
29358 + err = au_rdu_verify(&rdu);
29359 + if (unlikely(err))
29363 + case AUFS_CTL_RDU:
29364 + err = au_rdu(file, &rdu);
29365 + if (unlikely(err))
29368 + e = copy_to_user(p, &rdu, sizeof(rdu));
29369 + if (unlikely(e)) {
29374 + case AUFS_CTL_RDU_INO:
29375 + err = au_rdu_ino(file, &rdu);
29379 + /* err = -ENOTTY; */
29388 +#ifdef CONFIG_COMPAT
29389 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29392 + struct aufs_rdu rdu;
29393 + void __user *p = compat_ptr(arg);
29395 + /* todo: get_user()? */
29396 + err = copy_from_user(&rdu, p, sizeof(rdu));
29397 + if (unlikely(err)) {
29402 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29403 + err = au_rdu_verify(&rdu);
29404 + if (unlikely(err))
29408 + case AUFS_CTL_RDU:
29409 + err = au_rdu(file, &rdu);
29410 + if (unlikely(err))
29413 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29414 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29415 + e = copy_to_user(p, &rdu, sizeof(rdu));
29416 + if (unlikely(e)) {
29421 + case AUFS_CTL_RDU_INO:
29422 + err = au_rdu_ino(file, &rdu);
29426 + /* err = -ENOTTY; */
29435 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29436 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29437 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29439 +/* SPDX-License-Identifier: GPL-2.0 */
29441 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29443 + * This program is free software; you can redistribute it and/or modify
29444 + * it under the terms of the GNU General Public License as published by
29445 + * the Free Software Foundation; either version 2 of the License, or
29446 + * (at your option) any later version.
29448 + * This program is distributed in the hope that it will be useful,
29449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29451 + * GNU General Public License for more details.
29453 + * You should have received a copy of the GNU General Public License
29454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29458 + * simple read-write semaphore wrappers
29461 +#ifndef __AUFS_RWSEM_H__
29462 +#define __AUFS_RWSEM_H__
29466 +#include "debug.h"
29468 +/* in the future, the name 'au_rwsem' will be totally gone */
29469 +#define au_rwsem rw_semaphore
29471 +/* to debug easier, do not make them inlined functions */
29472 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29474 +#ifdef CONFIG_LOCKDEP
29475 +/* rwsem_is_locked() is unusable */
29476 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29477 + && !lockdep_recursing(current) \
29479 + && !lockdep_is_held_type(rw, 1))
29480 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29481 + && !lockdep_recursing(current) \
29483 + && !lockdep_is_held_type(rw, 0))
29484 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29485 + && !lockdep_recursing(current) \
29487 + && !lockdep_is_held(rw))
29488 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29489 + && !lockdep_recursing(current) \
29491 + && lockdep_is_held(rw))
29493 +#define AuRwMustReadLock(rw) do {} while (0)
29494 +#define AuRwMustWriteLock(rw) do {} while (0)
29495 +#define AuRwMustAnyLock(rw) do {} while (0)
29496 +#define AuRwDestroy(rw) do {} while (0)
29499 +#define au_rw_init(rw) init_rwsem(rw)
29501 +#define au_rw_init_wlock(rw) do { \
29502 + au_rw_init(rw); \
29503 + down_write(rw); \
29506 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29507 + au_rw_init(rw); \
29508 + down_write_nested(rw, lsc); \
29511 +#define au_rw_read_lock(rw) down_read(rw)
29512 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29513 +#define au_rw_read_unlock(rw) up_read(rw)
29514 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29515 +#define au_rw_write_lock(rw) down_write(rw)
29516 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29517 +#define au_rw_write_unlock(rw) up_write(rw)
29518 +/* why is not _nested version defined? */
29519 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29520 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29522 +#endif /* __KERNEL__ */
29523 +#endif /* __AUFS_RWSEM_H__ */
29524 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29525 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29526 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29528 +// SPDX-License-Identifier: GPL-2.0
29530 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29532 + * This program is free software; you can redistribute it and/or modify
29533 + * it under the terms of the GNU General Public License as published by
29534 + * the Free Software Foundation; either version 2 of the License, or
29535 + * (at your option) any later version.
29537 + * This program is distributed in the hope that it will be useful,
29538 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29539 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29540 + * GNU General Public License for more details.
29542 + * You should have received a copy of the GNU General Public License
29543 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29547 + * superblock private data
29550 +#include <linux/iversion.h>
29554 + * they are necessary regardless sysfs is disabled.
29556 +void au_si_free(struct kobject *kobj)
29559 + struct au_sbinfo *sbinfo;
29560 + char *locked __maybe_unused; /* debug only */
29562 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29563 + for (i = 0; i < AuPlink_NHASH; i++)
29564 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29565 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29567 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29568 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29569 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29570 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29572 + dbgaufs_si_fin(sbinfo);
29573 + au_rw_write_lock(&sbinfo->si_rwsem);
29574 + au_br_free(sbinfo);
29575 + au_rw_write_unlock(&sbinfo->si_rwsem);
29577 + au_kfree_try_rcu(sbinfo->si_branch);
29578 + mutex_destroy(&sbinfo->si_xib_mtx);
29579 + AuRwDestroy(&sbinfo->si_rwsem);
29581 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29582 + /* si_nfiles is waited too */
29583 + au_kfree_rcu(sbinfo);
29586 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29588 + struct au_sbinfo *sbinfo;
29592 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29593 + if (unlikely(!sbinfo))
29596 + /* will be reallocated separately */
29597 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29598 + if (unlikely(!sbinfo->si_branch))
29601 + err = sysaufs_si_init(sbinfo);
29603 + dbgaufs_si_null(sbinfo);
29604 + err = dbgaufs_si_init(sbinfo);
29605 + if (unlikely(err))
29606 + kobject_put(&sbinfo->si_kobj);
29608 + if (unlikely(err))
29611 + au_nwt_init(&sbinfo->si_nowait);
29612 + au_rw_init_wlock(&sbinfo->si_rwsem);
29614 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29615 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29617 + sbinfo->si_bbot = -1;
29618 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29620 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29621 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29622 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29623 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29625 + au_fhsm_init(sbinfo);
29627 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29629 + sbinfo->si_xino_jiffy = jiffies;
29630 + sbinfo->si_xino_expire
29631 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29632 + mutex_init(&sbinfo->si_xib_mtx);
29633 + /* leave si_xib_last_pindex and si_xib_next_bit */
29635 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29637 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29638 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29639 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29640 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29642 + for (i = 0; i < AuPlink_NHASH; i++)
29643 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29644 + init_waitqueue_head(&sbinfo->si_plink_wq);
29645 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29647 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29649 + /* with getattr by default */
29650 + sbinfo->si_iop_array = aufs_iop;
29652 + /* leave other members for sysaufs and si_mnt. */
29653 + sbinfo->si_sb = sb;
29655 + sb->s_fs_info = sbinfo;
29658 + return sbinfo; /* success */
29661 + au_kfree_try_rcu(sbinfo->si_branch);
29663 + au_kfree_rcu(sbinfo);
29665 + return ERR_PTR(err);
29668 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29671 + struct au_branch **brp;
29673 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29676 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29677 + if (unlikely(!sz))
29678 + sz = sizeof(*brp);
29679 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29682 + sbinfo->si_branch = brp;
29689 +/* ---------------------------------------------------------------------- */
29691 +unsigned int au_sigen_inc(struct super_block *sb)
29693 + unsigned int gen;
29694 + struct inode *inode;
29696 + SiMustWriteLock(sb);
29698 + gen = ++au_sbi(sb)->si_generation;
29699 + au_update_digen(sb->s_root);
29700 + inode = d_inode(sb->s_root);
29701 + au_update_iigen(inode, /*half*/0);
29702 + inode_inc_iversion(inode);
29706 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29708 + aufs_bindex_t br_id;
29710 + struct au_sbinfo *sbinfo;
29712 + SiMustWriteLock(sb);
29714 + sbinfo = au_sbi(sb);
29715 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29716 + br_id = ++sbinfo->si_last_br_id;
29717 + AuDebugOn(br_id < 0);
29718 + if (br_id && au_br_index(sb, br_id) < 0)
29725 +/* ---------------------------------------------------------------------- */
29727 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29728 +int si_read_lock(struct super_block *sb, int flags)
29733 + if (au_ftest_lock(flags, FLUSH))
29734 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29736 + si_noflush_read_lock(sb);
29737 + err = au_plink_maint(sb, flags);
29738 + if (unlikely(err))
29739 + si_read_unlock(sb);
29744 +int si_write_lock(struct super_block *sb, int flags)
29748 + if (au_ftest_lock(flags, FLUSH))
29749 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29751 + si_noflush_write_lock(sb);
29752 + err = au_plink_maint(sb, flags);
29753 + if (unlikely(err))
29754 + si_write_unlock(sb);
29759 +/* dentry and super_block lock. call at entry point */
29760 +int aufs_read_lock(struct dentry *dentry, int flags)
29763 + struct super_block *sb;
29765 + sb = dentry->d_sb;
29766 + err = si_read_lock(sb, flags);
29767 + if (unlikely(err))
29770 + if (au_ftest_lock(flags, DW))
29771 + di_write_lock_child(dentry);
29773 + di_read_lock_child(dentry, flags);
29775 + if (au_ftest_lock(flags, GEN)) {
29776 + err = au_digen_test(dentry, au_sigen(sb));
29777 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29778 + AuDebugOn(!err && au_dbrange_test(dentry));
29780 + err = au_dbrange_test(dentry);
29781 + if (unlikely(err))
29782 + aufs_read_unlock(dentry, flags);
29789 +void aufs_read_unlock(struct dentry *dentry, int flags)
29791 + if (au_ftest_lock(flags, DW))
29792 + di_write_unlock(dentry);
29794 + di_read_unlock(dentry, flags);
29795 + si_read_unlock(dentry->d_sb);
29798 +void aufs_write_lock(struct dentry *dentry)
29800 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29801 + di_write_lock_child(dentry);
29804 +void aufs_write_unlock(struct dentry *dentry)
29806 + di_write_unlock(dentry);
29807 + si_write_unlock(dentry->d_sb);
29810 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29813 + unsigned int sigen;
29814 + struct super_block *sb;
29817 + err = si_read_lock(sb, flags);
29818 + if (unlikely(err))
29821 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29823 + if (au_ftest_lock(flags, GEN)) {
29824 + sigen = au_sigen(sb);
29825 + err = au_digen_test(d1, sigen);
29826 + AuDebugOn(!err && au_dbrange_test(d1));
29828 + err = au_digen_test(d2, sigen);
29829 + AuDebugOn(!err && au_dbrange_test(d2));
29831 + if (unlikely(err))
29832 + aufs_read_and_write_unlock2(d1, d2);
29839 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29841 + di_write_unlock2(d1, d2);
29842 + si_read_unlock(d1->d_sb);
29844 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29845 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29846 +++ linux/fs/aufs/super.c 2022-11-05 23:02:18.969222617 +0100
29848 +// SPDX-License-Identifier: GPL-2.0
29850 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29852 + * This program is free software; you can redistribute it and/or modify
29853 + * it under the terms of the GNU General Public License as published by
29854 + * the Free Software Foundation; either version 2 of the License, or
29855 + * (at your option) any later version.
29857 + * This program is distributed in the hope that it will be useful,
29858 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29859 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29860 + * GNU General Public License for more details.
29862 + * You should have received a copy of the GNU General Public License
29863 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29867 + * mount and super_block operations
29870 +#include <linux/iversion.h>
29871 +#include <linux/mm.h>
29872 +#include <linux/seq_file.h>
29873 +#include <linux/statfs.h>
29874 +#include <linux/vmalloc.h>
29878 + * super_operations
29880 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29882 + struct au_icntnr *c;
29884 + c = au_cache_alloc_icntnr(sb);
29886 + au_icntnr_init(c);
29887 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29888 + c->iinfo.ii_hinode = NULL;
29889 + return &c->vfs_inode;
29894 +static void aufs_destroy_inode(struct inode *inode)
29896 + if (!au_is_bad_inode(inode))
29897 + au_iinfo_fin(inode);
29900 +static void aufs_free_inode(struct inode *inode)
29902 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29905 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29907 + struct inode *inode;
29910 + inode = iget_locked(sb, ino);
29911 + if (unlikely(!inode)) {
29912 + inode = ERR_PTR(-ENOMEM);
29915 + if (!(inode->i_state & I_NEW))
29918 + err = au_xigen_new(inode);
29920 + err = au_iinfo_init(inode);
29922 + inode_inc_iversion(inode);
29924 + iget_failed(inode);
29925 + inode = ERR_PTR(err);
29929 + /* never return NULL */
29930 + AuDebugOn(!inode);
29931 + AuTraceErrPtr(inode);
29935 +/* lock free root dinfo */
29936 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29939 + aufs_bindex_t bindex, bbot;
29940 + struct path path;
29941 + struct au_hdentry *hdp;
29942 + struct au_branch *br;
29943 + au_br_perm_str_t perm;
29946 + bbot = au_sbbot(sb);
29948 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29949 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29950 + br = au_sbr(sb, bindex);
29951 + path.mnt = au_br_mnt(br);
29952 + path.dentry = hdp->hd_dentry;
29953 + err = au_seq_path(seq, &path);
29955 + au_optstr_br_perm(&perm, br->br_perm);
29956 + seq_printf(seq, "=%s", perm.a);
29957 + if (bindex != bbot)
29958 + seq_putc(seq, ':');
29961 + if (unlikely(err || seq_has_overflowed(seq)))
29967 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29968 + const char *append)
29973 + while (*pat != ':')
29976 + strcpy(p, append);
29977 + AuDebugOn(strlen(fmt) >= len);
29980 +static void au_show_wbr_create(struct seq_file *m, int v,
29981 + struct au_sbinfo *sbinfo)
29985 + struct au_wbr_mfs *mfs;
29987 + AuRwMustAnyLock(&sbinfo->si_rwsem);
29989 + seq_puts(m, ",create=");
29990 + pat = au_optstr_wbr_create(v);
29991 + mfs = &sbinfo->si_wbr_mfs;
29993 + case AuWbrCreate_TDP:
29994 + case AuWbrCreate_RR:
29995 + case AuWbrCreate_MFS:
29996 + case AuWbrCreate_PMFS:
29997 + seq_puts(m, pat);
29999 + case AuWbrCreate_MFSRR:
30000 + case AuWbrCreate_TDMFS:
30001 + case AuWbrCreate_PMFSRR:
30002 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30003 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30005 + case AuWbrCreate_MFSV:
30006 + case AuWbrCreate_PMFSV:
30007 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30008 + seq_printf(m, fmt,
30009 + jiffies_to_msecs(mfs->mfs_expire)
30012 + case AuWbrCreate_MFSRRV:
30013 + case AuWbrCreate_TDMFSV:
30014 + case AuWbrCreate_PMFSRRV:
30015 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30016 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30017 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30024 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30026 +#ifdef CONFIG_SYSFS
30030 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30031 + aufs_bindex_t bindex, brid;
30032 + struct qstr *name;
30034 + struct dentry *d, *h_root;
30035 + struct au_branch *br;
30037 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30040 + f = au_sbi(sb)->si_xib;
30044 + /* stop printing the default xino path on the first writable branch */
30046 + bindex = au_xi_root(sb, f->f_path.dentry);
30047 + if (bindex >= 0) {
30048 + br = au_sbr_sb(sb, bindex);
30049 + h_root = au_br_dentry(br);
30052 + d = f->f_path.dentry;
30053 + name = &d->d_name;
30054 + /* safe ->d_parent because the file is unlinked */
30055 + if (d->d_parent == h_root
30056 + && name->len == len
30057 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30060 + seq_puts(seq, ",xino=");
30061 + err = au_xino_path(seq, f);
30068 +/* seq_file will re-call me in case of too long string */
30069 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30072 + unsigned int mnt_flags, v;
30073 + struct super_block *sb;
30074 + struct au_sbinfo *sbinfo;
30076 +#define AuBool(name, str) do { \
30077 + v = au_opt_test(mnt_flags, name); \
30078 + if (v != au_opt_test(AuOpt_Def, name)) \
30079 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30082 +#define AuStr(name, str) do { \
30083 + v = mnt_flags & AuOptMask_##name; \
30084 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30085 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30088 +#define AuUInt(name, str, val) do { \
30089 + if (val != AUFS_##name##_DEF) \
30090 + seq_printf(m, "," #str "=%u", val); \
30093 + sb = dentry->d_sb;
30094 + if (sb->s_flags & SB_POSIXACL)
30095 + seq_puts(m, ",acl");
30096 +#if 0 /* reserved for future use */
30097 + if (sb->s_flags & SB_I_VERSION)
30098 + seq_puts(m, ",i_version");
30101 + /* lock free root dinfo */
30102 + si_noflush_read_lock(sb);
30103 + sbinfo = au_sbi(sb);
30104 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30106 + mnt_flags = au_mntflags(sb);
30107 + if (au_opt_test(mnt_flags, XINO)) {
30108 + err = au_show_xino(m, sb);
30109 + if (unlikely(err))
30112 + seq_puts(m, ",noxino");
30114 + AuBool(TRUNC_XINO, trunc_xino);
30115 + AuStr(UDBA, udba);
30116 + AuBool(SHWH, shwh);
30117 + AuBool(PLINK, plink);
30118 + AuBool(DIO, dio);
30119 + AuBool(DIRPERM1, dirperm1);
30121 + v = sbinfo->si_wbr_create;
30122 + if (v != AuWbrCreate_Def)
30123 + au_show_wbr_create(m, v, sbinfo);
30125 + v = sbinfo->si_wbr_copyup;
30126 + if (v != AuWbrCopyup_Def)
30127 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30129 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30130 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30131 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30133 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30135 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30136 + AuUInt(RDCACHE, rdcache, v);
30138 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30139 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30141 + au_fhsm_show(m, sbinfo);
30143 + AuBool(DIRREN, dirren);
30144 + AuBool(SUM, sum);
30145 + /* AuBool(SUM_W, wsum); */
30146 + AuBool(WARN_PERM, warn_perm);
30147 + AuBool(VERBOSE, verbose);
30150 + /* be sure to print "br:" last */
30151 + if (!sysaufs_brs) {
30152 + seq_puts(m, ",br:");
30153 + au_show_brs(m, sb);
30155 + si_read_unlock(sb);
30163 +/* ---------------------------------------------------------------------- */
30165 +/* sum mode which returns the summation for statfs(2) */
30167 +static u64 au_add_till_max(u64 a, u64 b)
30175 + return ULLONG_MAX;
30178 +static u64 au_mul_till_max(u64 a, long mul)
30186 + return ULLONG_MAX;
30189 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30192 + long bsize, factor;
30193 + u64 blocks, bfree, bavail, files, ffree;
30194 + aufs_bindex_t bbot, bindex, i;
30195 + unsigned char shared;
30196 + struct path h_path;
30197 + struct super_block *h_sb;
30200 + bsize = LONG_MAX;
30206 + bbot = au_sbbot(sb);
30207 + for (bindex = 0; bindex <= bbot; bindex++) {
30208 + h_path.mnt = au_sbr_mnt(sb, bindex);
30209 + h_sb = h_path.mnt->mnt_sb;
30211 + for (i = 0; !shared && i < bindex; i++)
30212 + shared = (au_sbr_sb(sb, i) == h_sb);
30216 + /* sb->s_root for NFS is unreliable */
30217 + h_path.dentry = h_path.mnt->mnt_root;
30218 + err = vfs_statfs(&h_path, buf);
30219 + if (unlikely(err))
30222 + if (bsize > buf->f_bsize) {
30224 + * we will reduce bsize, so we have to expand blocks
30225 + * etc. to match them again
30227 + factor = (bsize / buf->f_bsize);
30228 + blocks = au_mul_till_max(blocks, factor);
30229 + bfree = au_mul_till_max(bfree, factor);
30230 + bavail = au_mul_till_max(bavail, factor);
30231 + bsize = buf->f_bsize;
30234 + factor = (buf->f_bsize / bsize);
30235 + blocks = au_add_till_max(blocks,
30236 + au_mul_till_max(buf->f_blocks, factor));
30237 + bfree = au_add_till_max(bfree,
30238 + au_mul_till_max(buf->f_bfree, factor));
30239 + bavail = au_add_till_max(bavail,
30240 + au_mul_till_max(buf->f_bavail, factor));
30241 + files = au_add_till_max(files, buf->f_files);
30242 + ffree = au_add_till_max(ffree, buf->f_ffree);
30245 + buf->f_bsize = bsize;
30246 + buf->f_blocks = blocks;
30247 + buf->f_bfree = bfree;
30248 + buf->f_bavail = bavail;
30249 + buf->f_files = files;
30250 + buf->f_ffree = ffree;
30251 + buf->f_frsize = 0;
30257 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30260 + struct path h_path;
30261 + struct super_block *sb;
30263 + /* lock free root dinfo */
30264 + sb = dentry->d_sb;
30265 + si_noflush_read_lock(sb);
30266 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30267 + /* sb->s_root for NFS is unreliable */
30268 + h_path.mnt = au_sbr_mnt(sb, 0);
30269 + h_path.dentry = h_path.mnt->mnt_root;
30270 + err = vfs_statfs(&h_path, buf);
30272 + err = au_statfs_sum(sb, buf);
30273 + si_read_unlock(sb);
30276 + buf->f_type = AUFS_SUPER_MAGIC;
30277 + buf->f_namelen = AUFS_MAX_NAMELEN;
30278 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30280 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30285 +/* ---------------------------------------------------------------------- */
30287 +static int aufs_sync_fs(struct super_block *sb, int wait)
30290 + aufs_bindex_t bbot, bindex;
30291 + struct au_branch *br;
30292 + struct super_block *h_sb;
30295 + si_noflush_read_lock(sb);
30296 + bbot = au_sbbot(sb);
30297 + for (bindex = 0; bindex <= bbot; bindex++) {
30298 + br = au_sbr(sb, bindex);
30299 + if (!au_br_writable(br->br_perm))
30302 + h_sb = au_sbr_sb(sb, bindex);
30303 + e = vfsub_sync_filesystem(h_sb);
30304 + if (unlikely(e && !err))
30306 + /* go on even if an error happens */
30308 + si_read_unlock(sb);
30313 +/* ---------------------------------------------------------------------- */
30315 +/* final actions when unmounting a file system */
30316 +static void aufs_put_super(struct super_block *sb)
30318 + struct au_sbinfo *sbinfo;
30320 + sbinfo = au_sbi(sb);
30322 + kobject_put(&sbinfo->si_kobj);
30325 +/* ---------------------------------------------------------------------- */
30327 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30328 + struct super_block *sb, void *arg)
30331 + unsigned long long n, sz;
30338 + if (*hint > ULLONG_MAX / sizeof(array)) {
30339 + array = ERR_PTR(-EMFILE);
30340 + pr_err("hint %llu\n", *hint);
30344 + sz = sizeof(array) * *hint;
30345 + array = kzalloc(sz, GFP_NOFS);
30346 + if (unlikely(!array))
30347 + array = vzalloc(sz);
30348 + if (unlikely(!array)) {
30349 + array = ERR_PTR(-ENOMEM);
30353 + n = cb(sb, array, *hint, arg);
30354 + AuDebugOn(n > *hint);
30361 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30362 + unsigned long long max __maybe_unused,
30365 + unsigned long long n;
30366 + struct inode **p, *inode;
30367 + struct list_head *head;
30372 + spin_lock(&sb->s_inode_list_lock);
30373 + list_for_each_entry(inode, head, i_sb_list) {
30374 + if (!au_is_bad_inode(inode)
30375 + && au_ii(inode)->ii_btop >= 0) {
30376 + spin_lock(&inode->i_lock);
30377 + if (atomic_read(&inode->i_count)) {
30381 + AuDebugOn(n > max);
30383 + spin_unlock(&inode->i_lock);
30386 + spin_unlock(&sb->s_inode_list_lock);
30391 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30393 + struct au_sbinfo *sbi;
30395 + sbi = au_sbi(sb);
30396 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30397 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30400 +void au_iarray_free(struct inode **a, unsigned long long max)
30402 + unsigned long long ull;
30404 + for (ull = 0; ull < max; ull++)
30409 +/* ---------------------------------------------------------------------- */
30412 + * refresh dentry and inode at remount time.
30414 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30415 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30416 + struct dentry *parent)
30420 + di_write_lock_child(dentry);
30421 + di_read_lock_parent(parent, AuLock_IR);
30422 + err = au_refresh_dentry(dentry, parent);
30423 + if (!err && dir_flags)
30424 + au_hn_reset(d_inode(dentry), dir_flags);
30425 + di_read_unlock(parent, AuLock_IR);
30426 + di_write_unlock(dentry);
30431 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30432 + struct au_sbinfo *sbinfo,
30433 + const unsigned int dir_flags, unsigned int do_idop)
30436 + struct dentry *parent;
30439 + parent = dget_parent(dentry);
30440 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30441 + if (d_really_is_positive(dentry)) {
30442 + if (!d_is_dir(dentry))
30443 + err = au_do_refresh(dentry, /*dir_flags*/0,
30446 + err = au_do_refresh(dentry, dir_flags, parent);
30447 + if (unlikely(err))
30448 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30451 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30452 + AuDbgDentry(dentry);
30458 + au_refresh_dop(dentry, /*force_reval*/0);
30460 + au_refresh_dop(dentry, /*force_reval*/1);
30466 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30468 + int err, i, j, ndentry, e;
30469 + unsigned int sigen;
30470 + struct au_dcsub_pages dpages;
30471 + struct au_dpage *dpage;
30472 + struct dentry **dentries, *d;
30473 + struct au_sbinfo *sbinfo;
30474 + struct dentry *root = sb->s_root;
30475 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30478 + au_refresh_dop(root, /*force_reval*/0);
30480 + err = au_dpages_init(&dpages, GFP_NOFS);
30481 + if (unlikely(err))
30483 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30484 + if (unlikely(err))
30487 + sigen = au_sigen(sb);
30488 + sbinfo = au_sbi(sb);
30489 + for (i = 0; i < dpages.ndpage; i++) {
30490 + dpage = dpages.dpages + i;
30491 + dentries = dpage->dentries;
30492 + ndentry = dpage->ndentry;
30493 + for (j = 0; j < ndentry; j++) {
30495 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30497 + if (unlikely(e && !err))
30499 + /* go on even err */
30504 + au_dpages_free(&dpages);
30509 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30512 + unsigned int sigen;
30513 + unsigned long long max, ull;
30514 + struct inode *inode, **array;
30516 + array = au_iarray_alloc(sb, &max);
30517 + err = PTR_ERR(array);
30518 + if (IS_ERR(array))
30522 + sigen = au_sigen(sb);
30523 + for (ull = 0; ull < max; ull++) {
30524 + inode = array[ull];
30525 + if (unlikely(!inode))
30529 + ii_write_lock_child(inode);
30530 + if (au_iigen(inode, NULL) != sigen) {
30531 + e = au_refresh_hinode_self(inode);
30532 + if (unlikely(e)) {
30533 + au_refresh_iop(inode, /*force_getattr*/1);
30534 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30537 + /* go on even if err */
30540 + if (!e && do_idop)
30541 + au_refresh_iop(inode, /*force_getattr*/0);
30542 + ii_write_unlock(inode);
30545 + au_iarray_free(array, max);
30551 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30554 + unsigned int udba;
30555 + aufs_bindex_t bindex, bbot;
30556 + struct dentry *root;
30557 + struct inode *inode;
30558 + struct au_branch *br;
30559 + struct au_sbinfo *sbi;
30561 + au_sigen_inc(sb);
30562 + sbi = au_sbi(sb);
30563 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30565 + root = sb->s_root;
30566 + DiMustNoWaiters(root);
30567 + inode = d_inode(root);
30568 + IiMustNoWaiters(inode);
30570 + udba = au_opt_udba(sb);
30571 + bbot = au_sbbot(sb);
30572 + for (bindex = 0; bindex <= bbot; bindex++) {
30573 + br = au_sbr(sb, bindex);
30574 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30575 + if (unlikely(err))
30576 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30578 + /* go on even if err */
30580 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30583 + if (au_ftest_si(sbi, NO_DREVAL)) {
30584 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30585 + sb->s_d_op = &aufs_dop_noreval;
30586 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30587 + sbi->si_iop_array = aufs_iop_nogetattr;
30589 + AuDebugOn(sb->s_d_op == &aufs_dop);
30590 + sb->s_d_op = &aufs_dop;
30591 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30592 + sbi->si_iop_array = aufs_iop;
30594 + pr_info("reset to %ps and %ps\n",
30595 + sb->s_d_op, sbi->si_iop_array);
30598 + di_write_unlock(root);
30599 + err = au_refresh_d(sb, do_idop);
30600 + e = au_refresh_i(sb, do_idop);
30601 + if (unlikely(e && !err))
30603 + /* aufs_write_lock() calls ..._child() */
30604 + di_write_lock_child(root);
30606 + au_cpup_attr_all(inode, /*force*/1);
30608 + if (unlikely(err))
30609 + AuIOErr("refresh failed, ignored, %d\n", err);
30612 +const struct super_operations aufs_sop = {
30613 + .alloc_inode = aufs_alloc_inode,
30614 + .destroy_inode = aufs_destroy_inode,
30615 + .free_inode = aufs_free_inode,
30616 + /* always deleting, no clearing */
30617 + .drop_inode = generic_delete_inode,
30618 + .show_options = aufs_show_options,
30619 + .statfs = aufs_statfs,
30620 + .put_super = aufs_put_super,
30621 + .sync_fs = aufs_sync_fs
30624 +/* ---------------------------------------------------------------------- */
30626 +int au_alloc_root(struct super_block *sb)
30629 + struct inode *inode;
30630 + struct dentry *root;
30633 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30634 + err = PTR_ERR(inode);
30635 + if (IS_ERR(inode))
30638 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30639 + inode->i_fop = &aufs_dir_fop;
30640 + inode->i_mode = S_IFDIR;
30641 + set_nlink(inode, 2);
30642 + unlock_new_inode(inode);
30644 + root = d_make_root(inode);
30645 + if (unlikely(!root))
30647 + err = PTR_ERR(root);
30648 + if (IS_ERR(root))
30651 + err = au_di_init(root);
30653 + sb->s_root = root;
30654 + return 0; /* success */
30662 +/* ---------------------------------------------------------------------- */
30664 +static void aufs_kill_sb(struct super_block *sb)
30666 + struct au_sbinfo *sbinfo;
30667 + struct dentry *root;
30669 + sbinfo = au_sbi(sb);
30673 + au_sbilist_del(sb);
30675 + root = sb->s_root;
30677 + aufs_write_lock(root);
30679 + __si_write_lock(sb);
30682 + if (sbinfo->si_wbr_create_ops->fin)
30683 + sbinfo->si_wbr_create_ops->fin(sb);
30684 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30685 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30686 + au_remount_refresh(sb, /*do_idop*/0);
30688 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30689 + au_plink_put(sb, /*verbose*/1);
30692 + au_dr_opt_flush(sb);
30695 + aufs_write_unlock(root);
30697 + __si_write_unlock(sb);
30699 + sbinfo->si_sb = NULL;
30700 + au_nwt_flush(&sbinfo->si_nowait);
30703 + kill_anon_super(sb);
30706 +struct file_system_type aufs_fs_type = {
30707 + .name = AUFS_FSTYPE,
30708 + /* a race between rename and others */
30709 + .fs_flags = FS_RENAME_DOES_D_MOVE
30711 + /*| FS_ALLOW_IDMAP*/
30713 + .init_fs_context = aufs_fsctx_init,
30714 + .parameters = aufs_fsctx_paramspec,
30715 + .kill_sb = aufs_kill_sb,
30716 + /* no need to __module_get() and module_put(). */
30717 + .owner = THIS_MODULE,
30719 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30720 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30721 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30723 +/* SPDX-License-Identifier: GPL-2.0 */
30725 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30727 + * This program is free software; you can redistribute it and/or modify
30728 + * it under the terms of the GNU General Public License as published by
30729 + * the Free Software Foundation; either version 2 of the License, or
30730 + * (at your option) any later version.
30732 + * This program is distributed in the hope that it will be useful,
30733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30735 + * GNU General Public License for more details.
30737 + * You should have received a copy of the GNU General Public License
30738 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30742 + * super_block operations
30745 +#ifndef __AUFS_SUPER_H__
30746 +#define __AUFS_SUPER_H__
30750 +#include <linux/fs.h>
30751 +#include <linux/kobject.h>
30754 +#include "rwsem.h"
30757 +/* policies to select one among multiple writable branches */
30758 +struct au_wbr_copyup_operations {
30759 + int (*copyup)(struct dentry *dentry);
30762 +#define AuWbr_DIR 1 /* target is a dir */
30763 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30765 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30766 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30767 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30769 +struct au_wbr_create_operations {
30770 + int (*create)(struct dentry *dentry, unsigned int flags);
30771 + int (*init)(struct super_block *sb);
30772 + int (*fin)(struct super_block *sb);
30775 +struct au_wbr_mfs {
30776 + struct mutex mfs_lock; /* protect this structure */
30777 + unsigned long mfs_jiffy;
30778 + unsigned long mfs_expire;
30779 + aufs_bindex_t mfs_bindex;
30781 + unsigned long long mfsrr_bytes;
30782 + unsigned long long mfsrr_watermark;
30785 +#define AuPlink_NHASH 100
30786 +static inline int au_plink_hash(ino_t ino)
30788 + return ino % AuPlink_NHASH;
30791 +/* File-based Hierarchical Storage Management */
30793 +#ifdef CONFIG_AUFS_FHSM
30794 + /* allow only one process who can receive the notification */
30795 + spinlock_t fhsm_spin;
30797 + wait_queue_head_t fhsm_wqh;
30798 + atomic_t fhsm_readable;
30800 + /* these are protected by si_rwsem */
30801 + unsigned long fhsm_expire;
30802 + aufs_bindex_t fhsm_bottom;
30807 +struct au_sbinfo {
30808 + /* nowait tasks in the system-wide workqueue */
30809 + struct au_nowait_tasks si_nowait;
30812 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30813 + * rwsem for au_sbinfo is necessary.
30815 + struct au_rwsem si_rwsem;
30818 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30821 + au_lcnt_t si_ninodes, si_nfiles;
30823 + /* branch management */
30824 + unsigned int si_generation;
30826 + /* see AuSi_ flags */
30827 + unsigned char au_si_status;
30829 + aufs_bindex_t si_bbot;
30831 + /* dirty trick to keep br_id plus */
30832 + unsigned int si_last_br_id :
30833 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30834 + struct au_branch **si_branch;
30836 + /* policy to select a writable branch */
30837 + unsigned char si_wbr_copyup;
30838 + unsigned char si_wbr_create;
30839 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30840 + struct au_wbr_create_operations *si_wbr_create_ops;
30842 + /* round robin */
30843 + atomic_t si_wbr_rr_next;
30845 + /* most free space */
30846 + struct au_wbr_mfs si_wbr_mfs;
30848 + /* File-based Hierarchical Storage Management */
30849 + struct au_fhsm si_fhsm;
30851 + /* mount flags */
30852 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30853 + unsigned int si_mntflags;
30855 + /* external inode number (bitmap and translation table) */
30856 + loff_t si_ximaxent; /* max entries in a xino */
30858 + struct file *si_xib;
30859 + struct mutex si_xib_mtx; /* protect xib members */
30860 + unsigned long *si_xib_buf;
30861 + unsigned long si_xib_last_pindex;
30862 + int si_xib_next_bit;
30864 + unsigned long si_xino_jiffy;
30865 + unsigned long si_xino_expire;
30866 + /* reserved for future use */
30867 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30869 +#ifdef CONFIG_AUFS_EXPORT
30870 + /* i_generation */
30871 + /* todo: make xigen file an array to support many inode numbers */
30872 + struct file *si_xigen;
30873 + atomic_t si_xigen_next;
30876 + /* dirty trick to support atomic_open */
30877 + struct hlist_bl_head si_aopen;
30879 + /* vdir parameters */
30880 + unsigned long si_rdcache; /* max cache time in jiffies */
30881 + unsigned int si_rdblk; /* deblk size */
30882 + unsigned int si_rdhash; /* hash size */
30885 + * If the number of whiteouts are larger than si_dirwh, leave all of
30886 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30887 + * future fsck.aufs or kernel thread will remove them later.
30888 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30890 + unsigned int si_dirwh;
30892 + /* pseudo_link list */
30893 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30894 + wait_queue_head_t si_plink_wq;
30895 + spinlock_t si_plink_maint_lock;
30896 + pid_t si_plink_maint_pid;
30899 + struct hlist_bl_head si_files;
30901 + /* with/without getattr, brother of sb->s_d_op */
30902 + const struct inode_operations *si_iop_array;
30905 + * sysfs and lifetime management.
30906 + * this is not a small structure and it may be a waste of memory in case
30907 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30908 + * but using sysfs is majority.
30910 + struct kobject si_kobj;
30911 +#ifdef CONFIG_DEBUG_FS
30912 + struct dentry *si_dbgaufs;
30913 + struct dentry *si_dbgaufs_plink;
30914 + struct dentry *si_dbgaufs_xib;
30915 +#ifdef CONFIG_AUFS_EXPORT
30916 + struct dentry *si_dbgaufs_xigen;
30920 +#ifdef CONFIG_AUFS_SBILIST
30921 + struct hlist_bl_node si_list;
30924 + /* dirty, necessary for unmounting, sysfs and sysrq */
30925 + struct super_block *si_sb;
30928 +/* sbinfo status flags */
30930 + * set true when refresh_dirs() failed at remount time.
30931 + * then try refreshing dirs at access time again.
30932 + * if it is false, refreshing dirs at access time is unnecessary
30934 +#define AuSi_FAILED_REFRESH_DIR 1
30935 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30936 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30938 +#ifndef CONFIG_AUFS_FHSM
30940 +#define AuSi_FHSM 0
30943 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30944 + unsigned int flag)
30946 + AuRwMustAnyLock(&sbi->si_rwsem);
30947 + return sbi->au_si_status & flag;
30949 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30950 +#define au_fset_si(sbinfo, name) do { \
30951 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30952 + (sbinfo)->au_si_status |= AuSi_##name; \
30954 +#define au_fclr_si(sbinfo, name) do { \
30955 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30956 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30959 +/* ---------------------------------------------------------------------- */
30961 +/* policy to select one among writable branches */
30962 +#define AuWbrCopyup(sbinfo, ...) \
30963 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30964 +#define AuWbrCreate(sbinfo, ...) \
30965 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30967 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30968 +#define AuLock_DW 1 /* write-lock dentry */
30969 +#define AuLock_IR (1 << 1) /* read-lock inode */
30970 +#define AuLock_IW (1 << 2) /* write-lock inode */
30971 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30972 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30973 + /* except RENAME_EXCHANGE */
30974 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30975 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
30976 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
30977 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
30978 +#define au_fset_lock(flags, name) \
30979 + do { (flags) |= AuLock_##name; } while (0)
30980 +#define au_fclr_lock(flags, name) \
30981 + do { (flags) &= ~AuLock_##name; } while (0)
30983 +/* ---------------------------------------------------------------------- */
30986 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
30988 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
30989 + unsigned long long max, void *arg);
30990 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30991 + struct super_block *sb, void *arg);
30992 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
30993 +void au_iarray_free(struct inode **a, unsigned long long max);
30995 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
30996 +extern const struct super_operations aufs_sop;
30997 +int au_alloc_root(struct super_block *sb);
30998 +extern struct file_system_type aufs_fs_type;
31001 +void au_si_free(struct kobject *kobj);
31002 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31003 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31005 +unsigned int au_sigen_inc(struct super_block *sb);
31006 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31008 +int si_read_lock(struct super_block *sb, int flags);
31009 +int si_write_lock(struct super_block *sb, int flags);
31010 +int aufs_read_lock(struct dentry *dentry, int flags);
31011 +void aufs_read_unlock(struct dentry *dentry, int flags);
31012 +void aufs_write_lock(struct dentry *dentry);
31013 +void aufs_write_unlock(struct dentry *dentry);
31014 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31015 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31017 +/* wbr_policy.c */
31018 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31019 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31020 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31021 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31022 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31025 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31027 +#ifdef CONFIG_AUFS_FHSM
31030 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31034 + spin_lock(&fhsm->fhsm_spin);
31035 + pid = fhsm->fhsm_pid;
31036 + spin_unlock(&fhsm->fhsm_spin);
31041 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31042 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31043 +int au_fhsm_fd(struct super_block *sb, int oflags);
31044 +int au_fhsm_br_alloc(struct au_branch *br);
31045 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31046 +void au_fhsm_fin(struct super_block *sb);
31047 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31048 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31049 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31051 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31053 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31054 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31055 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31056 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31057 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31058 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31059 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31060 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31061 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31064 +/* ---------------------------------------------------------------------- */
31066 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31068 + return sb->s_fs_info;
31071 +/* ---------------------------------------------------------------------- */
31073 +#ifdef CONFIG_AUFS_EXPORT
31074 +int au_test_nfsd(void);
31075 +void au_export_init(struct super_block *sb);
31076 +void au_xigen_inc(struct inode *inode);
31077 +int au_xigen_new(struct inode *inode);
31078 +int au_xigen_set(struct super_block *sb, struct path *path);
31079 +void au_xigen_clr(struct super_block *sb);
31081 +static inline int au_busy_or_stale(void)
31083 + if (!au_test_nfsd())
31088 +AuStubInt0(au_test_nfsd, void)
31089 +AuStubVoid(au_export_init, struct super_block *sb)
31090 +AuStubVoid(au_xigen_inc, struct inode *inode)
31091 +AuStubInt0(au_xigen_new, struct inode *inode)
31092 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31093 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31094 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31095 +#endif /* CONFIG_AUFS_EXPORT */
31097 +/* ---------------------------------------------------------------------- */
31099 +#ifdef CONFIG_AUFS_SBILIST
31101 +extern struct hlist_bl_head au_sbilist;
31103 +static inline void au_sbilist_init(void)
31105 + INIT_HLIST_BL_HEAD(&au_sbilist);
31108 +static inline void au_sbilist_add(struct super_block *sb)
31110 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31113 +static inline void au_sbilist_del(struct super_block *sb)
31115 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31118 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31119 +static inline void au_sbilist_lock(void)
31121 + hlist_bl_lock(&au_sbilist);
31124 +static inline void au_sbilist_unlock(void)
31126 + hlist_bl_unlock(&au_sbilist);
31128 +#define AuGFP_SBILIST GFP_ATOMIC
31130 +AuStubVoid(au_sbilist_lock, void)
31131 +AuStubVoid(au_sbilist_unlock, void)
31132 +#define AuGFP_SBILIST GFP_NOFS
31133 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31135 +AuStubVoid(au_sbilist_init, void)
31136 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31137 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31138 +AuStubVoid(au_sbilist_lock, void)
31139 +AuStubVoid(au_sbilist_unlock, void)
31140 +#define AuGFP_SBILIST GFP_NOFS
31143 +/* ---------------------------------------------------------------------- */
31145 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31148 + * This function is a dynamic '__init' function actually,
31149 + * so the tiny check for si_rwsem is unnecessary.
31151 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31152 +#ifdef CONFIG_DEBUG_FS
31153 + sbinfo->si_dbgaufs = NULL;
31154 + sbinfo->si_dbgaufs_plink = NULL;
31155 + sbinfo->si_dbgaufs_xib = NULL;
31156 +#ifdef CONFIG_AUFS_EXPORT
31157 + sbinfo->si_dbgaufs_xigen = NULL;
31162 +/* ---------------------------------------------------------------------- */
31164 +/* current->atomic_flags */
31165 +/* this value should never corrupt the ones defined in linux/sched.h */
31166 +#define PFA_AUFS 0x10
31168 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31169 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31170 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31172 +static inline int si_pid_test(struct super_block *sb)
31174 + return !!task_test_aufs(current);
31177 +static inline void si_pid_clr(struct super_block *sb)
31179 + AuDebugOn(!task_test_aufs(current));
31180 + task_clear_aufs(current);
31183 +static inline void si_pid_set(struct super_block *sb)
31185 + AuDebugOn(task_test_aufs(current));
31186 + task_set_aufs(current);
31189 +/* ---------------------------------------------------------------------- */
31191 +/* lock superblock. mainly for entry point functions */
31192 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31193 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31194 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31195 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31197 +#define __si_read_trylock_nested(sb) \
31198 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31199 +#define __si_write_trylock_nested(sb) \
31200 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31203 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31204 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31205 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31207 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31208 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31209 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31211 +static inline void si_noflush_read_lock(struct super_block *sb)
31213 + __si_read_lock(sb);
31217 +static inline int si_noflush_read_trylock(struct super_block *sb)
31221 + locked = __si_read_trylock(sb);
31227 +static inline void si_noflush_write_lock(struct super_block *sb)
31229 + __si_write_lock(sb);
31233 +static inline int si_noflush_write_trylock(struct super_block *sb)
31237 + locked = __si_write_trylock(sb);
31243 +#if 0 /* reserved */
31244 +static inline int si_read_trylock(struct super_block *sb, int flags)
31246 + if (au_ftest_lock(flags, FLUSH))
31247 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31248 + return si_noflush_read_trylock(sb);
31252 +static inline void si_read_unlock(struct super_block *sb)
31255 + __si_read_unlock(sb);
31258 +#if 0 /* reserved */
31259 +static inline int si_write_trylock(struct super_block *sb, int flags)
31261 + if (au_ftest_lock(flags, FLUSH))
31262 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31263 + return si_noflush_write_trylock(sb);
31267 +static inline void si_write_unlock(struct super_block *sb)
31270 + __si_write_unlock(sb);
31273 +#if 0 /* reserved */
31274 +static inline void si_downgrade_lock(struct super_block *sb)
31276 + __si_downgrade_lock(sb);
31280 +/* ---------------------------------------------------------------------- */
31282 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31284 + SiMustAnyLock(sb);
31285 + return au_sbi(sb)->si_bbot;
31288 +static inline unsigned int au_mntflags(struct super_block *sb)
31290 + SiMustAnyLock(sb);
31291 + return au_sbi(sb)->si_mntflags;
31294 +static inline unsigned int au_sigen(struct super_block *sb)
31296 + SiMustAnyLock(sb);
31297 + return au_sbi(sb)->si_generation;
31300 +static inline struct au_branch *au_sbr(struct super_block *sb,
31301 + aufs_bindex_t bindex)
31303 + SiMustAnyLock(sb);
31304 + return au_sbi(sb)->si_branch[0 + bindex];
31307 +static inline loff_t au_xi_maxent(struct super_block *sb)
31309 + SiMustAnyLock(sb);
31310 + return au_sbi(sb)->si_ximaxent;
31313 +#endif /* __KERNEL__ */
31314 +#endif /* __AUFS_SUPER_H__ */
31315 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31316 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31317 +++ linux/fs/aufs/sysaufs.c 2022-11-05 23:02:18.969222617 +0100
31319 +// SPDX-License-Identifier: GPL-2.0
31321 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31323 + * This program is free software; you can redistribute it and/or modify
31324 + * it under the terms of the GNU General Public License as published by
31325 + * the Free Software Foundation; either version 2 of the License, or
31326 + * (at your option) any later version.
31328 + * This program is distributed in the hope that it will be useful,
31329 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31330 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31331 + * GNU General Public License for more details.
31333 + * You should have received a copy of the GNU General Public License
31334 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31338 + * sysfs interface and lifetime management
31339 + * they are necessary regardless sysfs is disabled.
31342 +#include <linux/random.h>
31345 +unsigned long sysaufs_si_mask;
31346 +struct kset *sysaufs_kset;
31348 +#define AuSiAttr(_name) { \
31349 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31350 + .show = sysaufs_si_##_name, \
31353 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31354 +struct attribute *sysaufs_si_attrs[] = {
31355 + &sysaufs_si_attr_xi_path.attr,
31358 +ATTRIBUTE_GROUPS(sysaufs_si);
31360 +static const struct sysfs_ops au_sbi_ops = {
31361 + .show = sysaufs_si_show
31364 +static struct kobj_type au_sbi_ktype = {
31365 + .release = au_si_free,
31366 + .sysfs_ops = &au_sbi_ops,
31367 + .default_groups = sysaufs_si_groups
31370 +/* ---------------------------------------------------------------------- */
31372 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31376 + sbinfo->si_kobj.kset = sysaufs_kset;
31377 + /* cf. sysaufs_name() */
31378 + err = kobject_init_and_add
31379 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31380 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31385 +void sysaufs_fin(void)
31387 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31388 + kset_unregister(sysaufs_kset);
31391 +int __init sysaufs_init(void)
31396 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31397 + } while (!sysaufs_si_mask);
31400 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31401 + if (unlikely(!sysaufs_kset))
31403 + err = PTR_ERR(sysaufs_kset);
31404 + if (IS_ERR(sysaufs_kset))
31406 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31407 + if (unlikely(err))
31408 + kset_unregister(sysaufs_kset);
31413 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31414 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31415 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31417 +/* SPDX-License-Identifier: GPL-2.0 */
31419 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31421 + * This program is free software; you can redistribute it and/or modify
31422 + * it under the terms of the GNU General Public License as published by
31423 + * the Free Software Foundation; either version 2 of the License, or
31424 + * (at your option) any later version.
31426 + * This program is distributed in the hope that it will be useful,
31427 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31428 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31429 + * GNU General Public License for more details.
31431 + * You should have received a copy of the GNU General Public License
31432 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31436 + * sysfs interface and mount lifetime management
31439 +#ifndef __SYSAUFS_H__
31440 +#define __SYSAUFS_H__
31444 +#include <linux/sysfs.h>
31445 +#include "module.h"
31447 +struct super_block;
31450 +struct sysaufs_si_attr {
31451 + struct attribute attr;
31452 + int (*show)(struct seq_file *seq, struct super_block *sb);
31455 +/* ---------------------------------------------------------------------- */
31458 +extern unsigned long sysaufs_si_mask;
31459 +extern struct kset *sysaufs_kset;
31460 +extern struct attribute *sysaufs_si_attrs[];
31461 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31462 +int __init sysaufs_init(void);
31463 +void sysaufs_fin(void);
31465 +/* ---------------------------------------------------------------------- */
31467 +/* some people doesn't like to show a pointer in kernel */
31468 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31470 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31473 +#define SysaufsSiNamePrefix "si_"
31474 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31475 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31477 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31478 + sysaufs_si_id(sbinfo));
31482 +#ifdef CONFIG_SYSFS
31484 +extern struct attribute_group *sysaufs_attr_group;
31486 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31487 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31489 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31490 +#ifdef CONFIG_COMPAT
31491 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31494 +void sysaufs_br_init(struct au_branch *br);
31495 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31496 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31498 +#define sysaufs_brs_init() do {} while (0)
31501 +#define sysaufs_attr_group NULL
31503 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31504 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31505 + struct attribute *attr, char *buf)
31506 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31507 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31508 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31510 +static inline void sysaufs_brs_init(void)
31515 +#endif /* CONFIG_SYSFS */
31517 +#endif /* __KERNEL__ */
31518 +#endif /* __SYSAUFS_H__ */
31519 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31520 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31521 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31523 +// SPDX-License-Identifier: GPL-2.0
31525 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31527 + * This program is free software; you can redistribute it and/or modify
31528 + * it under the terms of the GNU General Public License as published by
31529 + * the Free Software Foundation; either version 2 of the License, or
31530 + * (at your option) any later version.
31532 + * This program is distributed in the hope that it will be useful,
31533 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31534 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31535 + * GNU General Public License for more details.
31537 + * You should have received a copy of the GNU General Public License
31538 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31542 + * sysfs interface
31545 +#include <linux/compat.h>
31546 +#include <linux/seq_file.h>
31549 +#ifdef CONFIG_AUFS_FS_MODULE
31550 +/* this entry violates the "one line per file" policy of sysfs */
31551 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31555 + static char *conf =
31556 +/* this file is generated at compiling */
31557 +#include "conf.str"
31560 + err = snprintf(buf, PAGE_SIZE, conf);
31561 + if (unlikely(err >= PAGE_SIZE))
31566 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31569 +static struct attribute *au_attr[] = {
31570 +#ifdef CONFIG_AUFS_FS_MODULE
31571 + &au_config_attr.attr,
31573 + NULL, /* need to NULL terminate the list of attributes */
31576 +static struct attribute_group sysaufs_attr_group_body = {
31580 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31582 +/* ---------------------------------------------------------------------- */
31584 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31588 + SiMustAnyLock(sb);
31591 + if (au_opt_test(au_mntflags(sb), XINO)) {
31592 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31593 + seq_putc(seq, '\n');
31599 + * the lifetime of branch is independent from the entry under sysfs.
31600 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31603 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31604 + aufs_bindex_t bindex, int idx)
31607 + struct path path;
31608 + struct dentry *root;
31609 + struct au_branch *br;
31610 + au_br_perm_str_t perm;
31612 + AuDbg("b%d\n", bindex);
31615 + root = sb->s_root;
31616 + di_read_lock_parent(root, !AuLock_IR);
31617 + br = au_sbr(sb, bindex);
31620 + case AuBrSysfs_BR:
31621 + path.mnt = au_br_mnt(br);
31622 + path.dentry = au_h_dptr(root, bindex);
31623 + err = au_seq_path(seq, &path);
31625 + au_optstr_br_perm(&perm, br->br_perm);
31626 + seq_printf(seq, "=%s\n", perm.a);
31629 + case AuBrSysfs_BRID:
31630 + seq_printf(seq, "%d\n", br->br_id);
31633 + di_read_unlock(root, !AuLock_IR);
31634 + if (unlikely(err || seq_has_overflowed(seq)))
31640 +/* ---------------------------------------------------------------------- */
31642 +static struct seq_file *au_seq(char *p, ssize_t len)
31644 + struct seq_file *seq;
31646 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31648 + /* mutex_init(&seq.lock); */
31651 + return seq; /* success */
31654 + seq = ERR_PTR(-ENOMEM);
31658 +#define SysaufsBr_PREFIX "br"
31659 +#define SysaufsBrid_PREFIX "brid"
31661 +/* todo: file size may exceed PAGE_SIZE */
31662 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31668 + aufs_bindex_t bbot;
31669 + struct au_sbinfo *sbinfo;
31670 + struct super_block *sb;
31671 + struct seq_file *seq;
31673 + struct attribute **cattr;
31675 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31676 + sb = sbinfo->si_sb;
31679 + * prevent a race condition between sysfs and aufs.
31680 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31681 + * prohibits maintaining the sysfs entries.
31682 + * hew we acquire read lock after sysfs_get_active_two().
31683 + * on the other hand, the remount process may maintain the sysfs/aufs
31684 + * entries after acquiring write lock.
31685 + * it can cause a deadlock.
31686 + * simply we gave up processing read here.
31689 + if (unlikely(!si_noflush_read_trylock(sb)))
31692 + seq = au_seq(buf, PAGE_SIZE);
31693 + err = PTR_ERR(seq);
31697 + name = (void *)attr->name;
31698 + cattr = sysaufs_si_attrs;
31700 + if (!strcmp(name, (*cattr)->name)) {
31701 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31708 + if (!strncmp(name, SysaufsBrid_PREFIX,
31709 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31710 + idx = AuBrSysfs_BRID;
31711 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31712 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31713 + sizeof(SysaufsBr_PREFIX) - 1)) {
31714 + idx = AuBrSysfs_BR;
31715 + name += sizeof(SysaufsBr_PREFIX) - 1;
31719 + err = kstrtol(name, 10, &l);
31721 + bbot = au_sbbot(sb);
31723 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31730 + err = seq->count;
31731 + /* sysfs limit */
31732 + if (unlikely(err == PAGE_SIZE))
31735 + au_kfree_rcu(seq);
31737 + si_read_unlock(sb);
31742 +/* ---------------------------------------------------------------------- */
31744 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31748 + aufs_bindex_t bindex, bbot;
31751 + struct seq_file *seq;
31752 + struct au_branch *br;
31754 + si_read_lock(sb, AuLock_FLUSH);
31755 + bbot = au_sbbot(sb);
31761 + buf = (void *)__get_free_page(GFP_NOFS);
31762 + if (unlikely(!buf))
31765 + seq = au_seq(buf, PAGE_SIZE);
31766 + err = PTR_ERR(seq);
31770 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31771 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31772 + /* VERIFY_WRITE */
31773 + err = !access_ok(arg, sizeof(*arg));
31774 + if (unlikely(err))
31777 + br = au_sbr(sb, bindex);
31778 + brid = br->br_id;
31779 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31780 + err = __put_user(brid, &arg->id);
31781 + if (unlikely(err))
31784 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31785 + err = __put_user(br->br_perm, &arg->perm);
31786 + if (unlikely(err))
31789 + err = au_seq_path(seq, &br->br_path);
31790 + if (unlikely(err))
31792 + seq_putc(seq, '\0');
31793 + if (!seq_has_overflowed(seq)) {
31794 + err = copy_to_user(arg->path, seq->buf, seq->count);
31796 + if (unlikely(err))
31803 + if (unlikely(err))
31807 + au_kfree_rcu(seq);
31809 + free_page((unsigned long)buf);
31811 + si_read_unlock(sb);
31815 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31817 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31820 +#ifdef CONFIG_COMPAT
31821 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31823 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31827 +/* ---------------------------------------------------------------------- */
31829 +void sysaufs_br_init(struct au_branch *br)
31832 + struct au_brsysfs *br_sysfs;
31833 + struct attribute *attr;
31835 + br_sysfs = br->br_sysfs;
31836 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31837 + attr = &br_sysfs->attr;
31838 + sysfs_attr_init(attr);
31839 + attr->name = br_sysfs->name;
31840 + attr->mode = 0444;
31845 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31847 + struct au_branch *br;
31848 + struct kobject *kobj;
31849 + struct au_brsysfs *br_sysfs;
31851 + aufs_bindex_t bbot;
31853 + if (!sysaufs_brs)
31856 + kobj = &au_sbi(sb)->si_kobj;
31857 + bbot = au_sbbot(sb);
31858 + for (; bindex <= bbot; bindex++) {
31859 + br = au_sbr(sb, bindex);
31860 + br_sysfs = br->br_sysfs;
31861 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31862 + sysfs_remove_file(kobj, &br_sysfs->attr);
31868 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31871 + aufs_bindex_t bbot;
31872 + struct kobject *kobj;
31873 + struct au_branch *br;
31874 + struct au_brsysfs *br_sysfs;
31876 + if (!sysaufs_brs)
31879 + kobj = &au_sbi(sb)->si_kobj;
31880 + bbot = au_sbbot(sb);
31881 + for (; bindex <= bbot; bindex++) {
31882 + br = au_sbr(sb, bindex);
31883 + br_sysfs = br->br_sysfs;
31884 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31885 + SysaufsBr_PREFIX "%d", bindex);
31886 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31887 + SysaufsBrid_PREFIX "%d", bindex);
31888 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31889 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31890 + if (unlikely(err))
31891 + pr_warn("failed %s under sysfs(%d)\n",
31892 + br_sysfs->name, err);
31897 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31898 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31899 +++ linux/fs/aufs/sysrq.c 2022-11-05 23:02:18.969222617 +0100
31901 +// SPDX-License-Identifier: GPL-2.0
31903 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31905 + * This program is free software; you can redistribute it and/or modify
31906 + * it under the terms of the GNU General Public License as published by
31907 + * the Free Software Foundation; either version 2 of the License, or
31908 + * (at your option) any later version.
31910 + * This program is distributed in the hope that it will be useful,
31911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31913 + * GNU General Public License for more details.
31915 + * You should have received a copy of the GNU General Public License
31916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31920 + * magic sysrq handler
31923 +/* #include <linux/sysrq.h> */
31924 +#include <linux/writeback.h>
31927 +/* ---------------------------------------------------------------------- */
31929 +static void sysrq_sb(struct super_block *sb)
31932 + struct au_sbinfo *sbinfo;
31933 + struct file *file;
31934 + struct hlist_bl_head *files;
31935 + struct hlist_bl_node *pos;
31936 + struct au_finfo *finfo;
31939 + plevel = au_plevel;
31940 + au_plevel = KERN_WARNING;
31942 + /* since we define pr_fmt, call printk directly */
31943 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31945 + sbinfo = au_sbi(sb);
31946 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31947 + pr("superblock\n");
31950 +#if 0 /* reserved */
31952 + int err, i, j, ndentry;
31953 + struct au_dcsub_pages dpages;
31954 + struct au_dpage *dpage;
31956 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31957 + if (unlikely(err))
31959 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31961 + for (i = 0; i < dpages.ndpage; i++) {
31962 + dpage = dpages.dpages + i;
31963 + ndentry = dpage->ndentry;
31964 + for (j = 0; j < ndentry; j++)
31965 + au_dpri_dentry(dpage->dentries[j]);
31967 + au_dpages_free(&dpages);
31971 + pr("isolated inode\n");
31972 + spin_lock(&sb->s_inode_list_lock);
31973 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31974 + spin_lock(&i->i_lock);
31975 + if (hlist_empty(&i->i_dentry))
31976 + au_dpri_inode(i);
31977 + spin_unlock(&i->i_lock);
31979 + spin_unlock(&sb->s_inode_list_lock);
31982 + files = &au_sbi(sb)->si_files;
31983 + hlist_bl_lock(files);
31984 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
31987 + file = finfo->fi_file;
31988 + mode = file_inode(file)->i_mode;
31989 + if (!special_file(mode))
31990 + au_dpri_file(file);
31992 + hlist_bl_unlock(files);
31996 + au_plevel = plevel;
31999 +/* ---------------------------------------------------------------------- */
32001 +/* module parameter */
32002 +static char *aufs_sysrq_key = "a";
32003 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32004 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32006 +static void au_sysrq(int key __maybe_unused)
32008 + struct au_sbinfo *sbinfo;
32009 + struct hlist_bl_node *pos;
32012 + au_sbilist_lock();
32013 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32014 + sysrq_sb(sbinfo->si_sb);
32015 + au_sbilist_unlock();
32019 +static struct sysrq_key_op au_sysrq_op = {
32020 + .handler = au_sysrq,
32021 + .help_msg = "Aufs",
32022 + .action_msg = "Aufs",
32023 + .enable_mask = SYSRQ_ENABLE_DUMP
32026 +/* ---------------------------------------------------------------------- */
32028 +int __init au_sysrq_init(void)
32034 + key = *aufs_sysrq_key;
32035 + if ('a' <= key && key <= 'z')
32036 + err = register_sysrq_key(key, &au_sysrq_op);
32037 + if (unlikely(err))
32038 + pr_err("err %d, sysrq=%c\n", err, key);
32042 +void au_sysrq_fin(void)
32046 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32047 + if (unlikely(err))
32048 + pr_err("err %d (ignored)\n", err);
32050 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32051 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32052 +++ linux/fs/aufs/vdir.c 2022-12-17 09:21:34.799855195 +0100
32054 +// SPDX-License-Identifier: GPL-2.0
32056 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32058 + * This program is free software; you can redistribute it and/or modify
32059 + * it under the terms of the GNU General Public License as published by
32060 + * the Free Software Foundation; either version 2 of the License, or
32061 + * (at your option) any later version.
32063 + * This program is distributed in the hope that it will be useful,
32064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32066 + * GNU General Public License for more details.
32068 + * You should have received a copy of the GNU General Public License
32069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32073 + * virtual or vertical directory
32076 +#include <linux/iversion.h>
32079 +static unsigned int calc_size(int nlen)
32081 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32084 +static int set_deblk_end(union au_vdir_deblk_p *p,
32085 + union au_vdir_deblk_p *deblk_end)
32087 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32088 + p->de->de_str.len = 0;
32092 + return -1; /* error */
32095 +/* returns true or false */
32096 +static int is_deblk_end(union au_vdir_deblk_p *p,
32097 + union au_vdir_deblk_p *deblk_end)
32099 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32100 + return !p->de->de_str.len;
32104 +static unsigned char *last_deblk(struct au_vdir *vdir)
32106 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32109 +/* ---------------------------------------------------------------------- */
32111 +/* estimate the appropriate size for name hash table */
32112 +unsigned int au_rdhash_est(loff_t sz)
32120 + if (sz < AUFS_RDHASH_DEF)
32121 + n = AUFS_RDHASH_DEF;
32122 + /* pr_info("n %u\n", n); */
32127 + * the allocated memory has to be freed by
32128 + * au_nhash_wh_free() or au_nhash_de_free().
32130 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32132 + struct hlist_head *head;
32136 + sz = sizeof(*nhash->nh_head) * num_hash;
32137 + head = kmalloc(sz, gfp);
32139 + nhash->nh_num = num_hash;
32140 + nhash->nh_head = head;
32141 + for (u = 0; u < num_hash; u++)
32142 + INIT_HLIST_HEAD(head++);
32143 + return 0; /* success */
32149 +static void nhash_count(struct hlist_head *head)
32151 +#if 0 /* debugging */
32153 + struct hlist_node *pos;
32156 + hlist_for_each(pos, head)
32158 + pr_info("%lu\n", n);
32162 +static void au_nhash_wh_do_free(struct hlist_head *head)
32164 + struct au_vdir_wh *pos;
32165 + struct hlist_node *node;
32167 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32168 + au_kfree_rcu(pos);
32171 +static void au_nhash_de_do_free(struct hlist_head *head)
32173 + struct au_vdir_dehstr *pos;
32174 + struct hlist_node *node;
32176 + hlist_for_each_entry_safe(pos, node, head, hash)
32177 + au_cache_free_vdir_dehstr(pos);
32180 +static void au_nhash_do_free(struct au_nhash *nhash,
32181 + void (*free)(struct hlist_head *head))
32184 + struct hlist_head *head;
32186 + n = nhash->nh_num;
32190 + head = nhash->nh_head;
32191 + while (n-- > 0) {
32192 + nhash_count(head);
32195 + au_kfree_try_rcu(nhash->nh_head);
32198 +void au_nhash_wh_free(struct au_nhash *whlist)
32200 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32203 +static void au_nhash_de_free(struct au_nhash *delist)
32205 + au_nhash_do_free(delist, au_nhash_de_do_free);
32208 +/* ---------------------------------------------------------------------- */
32210 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32214 + unsigned int u, n;
32215 + struct hlist_head *head;
32216 + struct au_vdir_wh *pos;
32219 + n = whlist->nh_num;
32220 + head = whlist->nh_head;
32221 + for (u = 0; u < n; u++, head++)
32222 + hlist_for_each_entry(pos, head, wh_hash)
32223 + if (pos->wh_bindex == btgt && ++num > limit)
32228 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32229 + unsigned char *name,
32230 + unsigned int len)
32233 + /* const unsigned int magic_bit = 12; */
32235 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32242 + /* v = hash_long(v, magic_bit); */
32243 + v %= nhash->nh_num;
32244 + return nhash->nh_head + v;
32247 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32250 + return str->len == nlen && !memcmp(str->name, name, nlen);
32253 +/* returns found or not */
32254 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32256 + struct hlist_head *head;
32257 + struct au_vdir_wh *pos;
32258 + struct au_vdir_destr *str;
32260 + head = au_name_hash(whlist, name, nlen);
32261 + hlist_for_each_entry(pos, head, wh_hash) {
32262 + str = &pos->wh_str;
32263 + AuDbg("%.*s\n", str->len, str->name);
32264 + if (au_nhash_test_name(str, name, nlen))
32270 +/* returns found(true) or not */
32271 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32273 + struct hlist_head *head;
32274 + struct au_vdir_dehstr *pos;
32275 + struct au_vdir_destr *str;
32277 + head = au_name_hash(delist, name, nlen);
32278 + hlist_for_each_entry(pos, head, hash) {
32280 + AuDbg("%.*s\n", str->len, str->name);
32281 + if (au_nhash_test_name(str, name, nlen))
32287 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32288 + unsigned char d_type)
32290 +#ifdef CONFIG_AUFS_SHWH
32291 + wh->wh_ino = ino;
32292 + wh->wh_type = d_type;
32296 +/* ---------------------------------------------------------------------- */
32298 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32299 + unsigned int d_type, aufs_bindex_t bindex,
32300 + unsigned char shwh)
32303 + struct au_vdir_destr *str;
32304 + struct au_vdir_wh *wh;
32306 + AuDbg("%.*s\n", nlen, name);
32307 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32310 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32311 + if (unlikely(!wh))
32315 + wh->wh_bindex = bindex;
32317 + au_shwh_init_wh(wh, ino, d_type);
32318 + str = &wh->wh_str;
32320 + memcpy(str->name, name, nlen);
32321 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32328 +static int append_deblk(struct au_vdir *vdir)
32331 + unsigned long ul;
32332 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32333 + union au_vdir_deblk_p p, deblk_end;
32334 + unsigned char **o;
32337 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32338 + GFP_NOFS, /*may_shrink*/0);
32339 + if (unlikely(!o))
32342 + vdir->vd_deblk = o;
32343 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32345 + ul = vdir->vd_nblk++;
32346 + vdir->vd_deblk[ul] = p.deblk;
32347 + vdir->vd_last.ul = ul;
32348 + vdir->vd_last.p.deblk = p.deblk;
32349 + deblk_end.deblk = p.deblk + deblk_sz;
32350 + err = set_deblk_end(&p, &deblk_end);
32357 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32358 + unsigned int d_type, struct au_nhash *delist)
32362 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32363 + union au_vdir_deblk_p p, *room, deblk_end;
32364 + struct au_vdir_dehstr *dehstr;
32366 + p.deblk = last_deblk(vdir);
32367 + deblk_end.deblk = p.deblk + deblk_sz;
32368 + room = &vdir->vd_last.p;
32369 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32370 + || !is_deblk_end(room, &deblk_end));
32372 + sz = calc_size(nlen);
32373 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32374 + err = append_deblk(vdir);
32375 + if (unlikely(err))
32378 + p.deblk = last_deblk(vdir);
32379 + deblk_end.deblk = p.deblk + deblk_sz;
32381 + AuDebugOn(room->deblk != p.deblk);
32385 + dehstr = au_cache_alloc_vdir_dehstr();
32386 + if (unlikely(!dehstr))
32389 + dehstr->str = &room->de->de_str;
32390 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32391 + room->de->de_ino = ino;
32392 + room->de->de_type = d_type;
32393 + room->de->de_str.len = nlen;
32394 + memcpy(room->de->de_str.name, name, nlen);
32397 + room->deblk += sz;
32398 + if (unlikely(set_deblk_end(room, &deblk_end)))
32399 + err = append_deblk(vdir);
32406 +/* ---------------------------------------------------------------------- */
32408 +void au_vdir_free(struct au_vdir *vdir)
32410 + unsigned char **deblk;
32412 + deblk = vdir->vd_deblk;
32413 + while (vdir->vd_nblk--)
32414 + au_kfree_try_rcu(*deblk++);
32415 + au_kfree_try_rcu(vdir->vd_deblk);
32416 + au_cache_free_vdir(vdir);
32419 +static struct au_vdir *alloc_vdir(struct file *file)
32421 + struct au_vdir *vdir;
32422 + struct super_block *sb;
32425 + sb = file->f_path.dentry->d_sb;
32426 + SiMustAnyLock(sb);
32429 + vdir = au_cache_alloc_vdir();
32430 + if (unlikely(!vdir))
32433 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32434 + if (unlikely(!vdir->vd_deblk))
32437 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32438 + if (!vdir->vd_deblk_sz) {
32439 + /* estimate the appropriate size for deblk */
32440 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32441 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32443 + vdir->vd_nblk = 0;
32444 + vdir->vd_version = 0;
32445 + vdir->vd_jiffy = 0;
32446 + err = append_deblk(vdir);
32448 + return vdir; /* success */
32450 + au_kfree_try_rcu(vdir->vd_deblk);
32453 + au_cache_free_vdir(vdir);
32455 + vdir = ERR_PTR(err);
32459 +static int reinit_vdir(struct au_vdir *vdir)
32462 + union au_vdir_deblk_p p, deblk_end;
32464 + while (vdir->vd_nblk > 1) {
32465 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32466 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32469 + p.deblk = vdir->vd_deblk[0];
32470 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32471 + err = set_deblk_end(&p, &deblk_end);
32472 + /* keep vd_dblk_sz */
32473 + vdir->vd_last.ul = 0;
32474 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32475 + vdir->vd_version = 0;
32476 + vdir->vd_jiffy = 0;
32481 +/* ---------------------------------------------------------------------- */
32483 +#define AuFillVdir_CALLED 1
32484 +#define AuFillVdir_WHABLE (1 << 1)
32485 +#define AuFillVdir_SHWH (1 << 2)
32486 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32487 +#define au_fset_fillvdir(flags, name) \
32488 + do { (flags) |= AuFillVdir_##name; } while (0)
32489 +#define au_fclr_fillvdir(flags, name) \
32490 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32492 +#ifndef CONFIG_AUFS_SHWH
32493 +#undef AuFillVdir_SHWH
32494 +#define AuFillVdir_SHWH 0
32497 +struct fillvdir_arg {
32498 + struct dir_context ctx;
32499 + struct file *file;
32500 + struct au_vdir *vdir;
32501 + struct au_nhash delist;
32502 + struct au_nhash whlist;
32503 + aufs_bindex_t bindex;
32504 + unsigned int flags;
32508 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32509 + loff_t offset __maybe_unused, u64 h_ino,
32510 + unsigned int d_type)
32512 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32513 + char *name = (void *)__name;
32514 + struct super_block *sb;
32516 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32519 + sb = arg->file->f_path.dentry->d_sb;
32520 + au_fset_fillvdir(arg->flags, CALLED);
32522 + if (nlen <= AUFS_WH_PFX_LEN
32523 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32524 + if (test_known(&arg->delist, name, nlen)
32525 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32526 + goto out; /* already exists or whiteouted */
32528 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32530 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32531 + d_type = DT_UNKNOWN;
32532 + arg->err = append_de(arg->vdir, name, nlen, ino,
32533 + d_type, &arg->delist);
32535 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32536 + name += AUFS_WH_PFX_LEN;
32537 + nlen -= AUFS_WH_PFX_LEN;
32538 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32539 + goto out; /* already whiteouted */
32541 + ino = 0; /* just to suppress a warning */
32543 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32546 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32547 + d_type = DT_UNKNOWN;
32548 + arg->err = au_nhash_append_wh
32549 + (&arg->whlist, name, nlen, ino, d_type,
32550 + arg->bindex, shwh);
32556 + arg->vdir->vd_jiffy = jiffies;
32558 + AuTraceErr(arg->err);
32559 + return !arg->err;
32562 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32563 + struct au_nhash *whlist, struct au_nhash *delist)
32565 +#ifdef CONFIG_AUFS_SHWH
32567 + unsigned int nh, u;
32568 + struct hlist_head *head;
32569 + struct au_vdir_wh *pos;
32570 + struct hlist_node *n;
32572 + struct au_vdir_destr *destr;
32574 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32577 + o = p = (void *)__get_free_page(GFP_NOFS);
32578 + if (unlikely(!p))
32582 + nh = whlist->nh_num;
32583 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32584 + p += AUFS_WH_PFX_LEN;
32585 + for (u = 0; u < nh; u++) {
32586 + head = whlist->nh_head + u;
32587 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32588 + destr = &pos->wh_str;
32589 + memcpy(p, destr->name, destr->len);
32590 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32591 + pos->wh_ino, pos->wh_type, delist);
32592 + if (unlikely(err))
32597 + free_page((unsigned long)o);
32607 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32610 + unsigned int rdhash;
32612 + aufs_bindex_t bbot, bindex, btop;
32613 + unsigned char shwh;
32614 + struct file *hf, *file;
32615 + struct super_block *sb;
32617 + file = arg->file;
32618 + sb = file->f_path.dentry->d_sb;
32619 + SiMustAnyLock(sb);
32621 + rdhash = au_sbi(sb)->si_rdhash;
32623 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32624 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32625 + if (unlikely(err))
32627 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32628 + if (unlikely(err))
32634 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32636 + au_fset_fillvdir(arg->flags, SHWH);
32638 + btop = au_fbtop(file);
32639 + bbot = au_fbbot_dir(file);
32640 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32641 + hf = au_hf_dir(file, bindex);
32645 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32647 + if (unlikely(offset))
32650 + arg->bindex = bindex;
32651 + au_fclr_fillvdir(arg->flags, WHABLE);
32653 + || (bindex != bbot
32654 + && au_br_whable(au_sbr_perm(sb, bindex))))
32655 + au_fset_fillvdir(arg->flags, WHABLE);
32658 + au_fclr_fillvdir(arg->flags, CALLED);
32660 + err = vfsub_iterate_dir(hf, &arg->ctx);
32663 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32666 + * dir_relax() may be good for concurrency, but aufs should not
32667 + * use it since it will cause a lockdep problem.
32671 + if (!err && shwh)
32672 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32674 + au_nhash_wh_free(&arg->whlist);
32677 + au_nhash_de_free(&arg->delist);
32682 +static int read_vdir(struct file *file, int may_read)
32685 + unsigned long expire;
32686 + unsigned char do_read;
32687 + struct fillvdir_arg arg = {
32689 + .actor = fillvdir
32692 + struct inode *inode;
32693 + struct au_vdir *vdir, *allocated;
32696 + inode = file_inode(file);
32697 + IMustLock(inode);
32698 + IiMustWriteLock(inode);
32699 + SiMustAnyLock(inode->i_sb);
32701 + allocated = NULL;
32703 + expire = au_sbi(inode->i_sb)->si_rdcache;
32704 + vdir = au_ivdir(inode);
32707 + vdir = alloc_vdir(file);
32708 + err = PTR_ERR(vdir);
32709 + if (IS_ERR(vdir))
32712 + allocated = vdir;
32713 + } else if (may_read
32714 + && (!inode_eq_iversion(inode, vdir->vd_version)
32715 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32717 + err = reinit_vdir(vdir);
32718 + if (unlikely(err))
32723 + return 0; /* success */
32727 + err = au_do_read_vdir(&arg);
32729 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32730 + vdir->vd_version = inode_query_iversion(inode);
32731 + vdir->vd_last.ul = 0;
32732 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32734 + au_set_ivdir(inode, allocated);
32735 + } else if (allocated)
32736 + au_vdir_free(allocated);
32742 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32745 + unsigned long ul, n;
32746 + const unsigned int deblk_sz = src->vd_deblk_sz;
32748 + AuDebugOn(tgt->vd_nblk != 1);
32751 + if (tgt->vd_nblk < src->vd_nblk) {
32752 + unsigned char **p;
32754 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32755 + GFP_NOFS, /*may_shrink*/0);
32756 + if (unlikely(!p))
32758 + tgt->vd_deblk = p;
32761 + if (tgt->vd_deblk_sz != deblk_sz) {
32762 + unsigned char *p;
32764 + tgt->vd_deblk_sz = deblk_sz;
32765 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32766 + /*may_shrink*/1);
32767 + if (unlikely(!p))
32769 + tgt->vd_deblk[0] = p;
32771 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32772 + tgt->vd_version = src->vd_version;
32773 + tgt->vd_jiffy = src->vd_jiffy;
32775 + n = src->vd_nblk;
32776 + for (ul = 1; ul < n; ul++) {
32777 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32779 + if (unlikely(!tgt->vd_deblk[ul]))
32783 + tgt->vd_nblk = n;
32784 + tgt->vd_last.ul = tgt->vd_last.ul;
32785 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32786 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32787 + - src->vd_deblk[src->vd_last.ul];
32789 + return 0; /* success */
32792 + rerr = reinit_vdir(tgt);
32797 +int au_vdir_init(struct file *file)
32800 + struct inode *inode;
32801 + struct au_vdir *vdir_cache, *allocated;
32803 + /* test file->f_pos here instead of ctx->pos */
32804 + err = read_vdir(file, !file->f_pos);
32805 + if (unlikely(err))
32808 + allocated = NULL;
32809 + vdir_cache = au_fvdir_cache(file);
32810 + if (!vdir_cache) {
32811 + vdir_cache = alloc_vdir(file);
32812 + err = PTR_ERR(vdir_cache);
32813 + if (IS_ERR(vdir_cache))
32815 + allocated = vdir_cache;
32816 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32817 + /* test file->f_pos here instead of ctx->pos */
32818 + err = reinit_vdir(vdir_cache);
32819 + if (unlikely(err))
32822 + return 0; /* success */
32824 + inode = file_inode(file);
32825 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32827 + file->f_version = inode_query_iversion(inode);
32829 + au_set_fvdir_cache(file, allocated);
32830 + } else if (allocated)
32831 + au_vdir_free(allocated);
32837 +static loff_t calc_offset(struct au_vdir *vdir)
32840 + union au_vdir_deblk_p p;
32842 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32843 + offset = vdir->vd_last.p.deblk - p.deblk;
32844 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32848 +/* returns true or false */
32849 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32852 + unsigned int deblk_sz;
32853 + unsigned long ul, n;
32855 + union au_vdir_deblk_p p, deblk_end;
32856 + struct au_vdir *vdir_cache;
32859 + vdir_cache = au_fvdir_cache(file);
32860 + offset = calc_offset(vdir_cache);
32861 + AuDbg("offset %lld\n", offset);
32862 + if (ctx->pos == offset)
32865 + vdir_cache->vd_last.ul = 0;
32866 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32871 + deblk_sz = vdir_cache->vd_deblk_sz;
32872 + ul = div64_u64(ctx->pos, deblk_sz);
32873 + AuDbg("ul %lu\n", ul);
32874 + if (ul >= vdir_cache->vd_nblk)
32877 + n = vdir_cache->vd_nblk;
32878 + for (; ul < n; ul++) {
32879 + p.deblk = vdir_cache->vd_deblk[ul];
32880 + deblk_end.deblk = p.deblk + deblk_sz;
32882 + offset *= deblk_sz;
32883 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32886 + l = calc_size(p.de->de_str.len);
32890 + if (!is_deblk_end(&p, &deblk_end)) {
32892 + vdir_cache->vd_last.ul = ul;
32893 + vdir_cache->vd_last.p = p;
32901 + AuDbg("valid %d\n", !valid);
32905 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32907 + unsigned int l, deblk_sz;
32908 + union au_vdir_deblk_p deblk_end;
32909 + struct au_vdir *vdir_cache;
32910 + struct au_vdir_de *de;
32912 + if (!seek_vdir(file, ctx))
32915 + vdir_cache = au_fvdir_cache(file);
32916 + deblk_sz = vdir_cache->vd_deblk_sz;
32918 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32919 + deblk_end.deblk += deblk_sz;
32920 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32921 + de = vdir_cache->vd_last.p.de;
32922 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32923 + de->de_str.len, de->de_str.name, ctx->pos,
32924 + (unsigned long)de->de_ino, de->de_type);
32925 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32926 + de->de_str.len, de->de_ino,
32928 + /* todo: ignore the error caused by udba? */
32929 + /* return err; */
32933 + l = calc_size(de->de_str.len);
32934 + vdir_cache->vd_last.p.deblk += l;
32937 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32938 + vdir_cache->vd_last.ul++;
32939 + vdir_cache->vd_last.p.deblk
32940 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32941 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32950 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32951 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32952 +++ linux/fs/aufs/vfsub.c 2023-08-28 12:34:39.999969465 +0200
32954 +// SPDX-License-Identifier: GPL-2.0
32956 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32958 + * This program is free software; you can redistribute it and/or modify
32959 + * it under the terms of the GNU General Public License as published by
32960 + * the Free Software Foundation; either version 2 of the License, or
32961 + * (at your option) any later version.
32963 + * This program is distributed in the hope that it will be useful,
32964 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32965 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32966 + * GNU General Public License for more details.
32968 + * You should have received a copy of the GNU General Public License
32969 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32973 + * sub-routines for VFS
32976 +#include <linux/mnt_namespace.h>
32977 +#include <linux/nsproxy.h>
32978 +#include <linux/security.h>
32979 +#include <linux/splice.h>
32982 +#ifdef CONFIG_AUFS_BR_FUSE
32983 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32985 + if (!au_test_fuse(h_sb) || !au_userns)
32988 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
32992 +int vfsub_sync_filesystem(struct super_block *h_sb)
32997 + down_read(&h_sb->s_umount);
32998 + err = sync_filesystem(h_sb);
32999 + up_read(&h_sb->s_umount);
33005 +/* ---------------------------------------------------------------------- */
33007 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33011 + struct super_block *h_sb;
33014 + * Always needs h_path->mnt for LSM or FUSE branch.
33016 + AuDebugOn(!h_path->mnt);
33018 + /* for remote fs, leave work for its getattr or d_revalidate */
33019 + /* for bad i_attr fs, handle them in aufs_getattr() */
33020 + /* still some fs may acquire i_mutex. we need to skip them */
33024 + h_sb = h_path->dentry->d_sb;
33025 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33027 + err = vfsub_getattr(h_path, &st);
33032 +/* ---------------------------------------------------------------------- */
33034 +struct file *vfsub_dentry_open(struct path *path, int flags)
33036 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33040 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33042 + struct file *file;
33045 + file = filp_open(path,
33046 + oflags /* | __FMODE_NONOTIFY */,
33049 + if (IS_ERR(file))
33051 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33058 + * Ideally this function should call VFS:do_last() in order to keep all its
33059 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33060 + * structure such as nameidata. This is a second (or third) best approach.
33061 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33063 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33064 + struct vfsub_aopen_args *args)
33067 + struct au_branch *br = args->br;
33068 + struct file *file = args->file;
33069 + /* copied from linux/fs/namei.c:atomic_open() */
33070 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33073 + AuDebugOn(!dir->i_op->atomic_open);
33075 + err = au_br_test_oflag(args->open_flag, br);
33076 + if (unlikely(err))
33079 + au_lcnt_inc(&br->br_nfiles);
33080 + file->f_path.dentry = DENTRY_NOT_SET;
33081 + file->f_path.mnt = au_br_mnt(br);
33082 + AuDbg("%ps\n", dir->i_op->atomic_open);
33083 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33084 + args->create_mode);
33085 + if (unlikely(err < 0)) {
33086 + au_lcnt_dec(&br->br_nfiles);
33090 + /* temporary workaround for nfsv4 branch */
33091 + if (au_test_nfs(dir->i_sb))
33092 + nfs_mark_for_revalidate(dir);
33094 + if (file->f_mode & FMODE_CREATED)
33095 + fsnotify_create(dir, dentry);
33096 + if (!(file->f_mode & FMODE_OPENED)) {
33097 + au_lcnt_dec(&br->br_nfiles);
33101 + /* todo: call VFS:may_open() here */
33102 + /* todo: ima_file_check() too? */
33103 + if (!err && (args->open_flag & __FMODE_EXEC))
33104 + err = deny_write_access(file);
33106 + fsnotify_open(file);
33108 + au_lcnt_dec(&br->br_nfiles);
33109 + /* note that the file is created and still opened */
33115 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33119 + err = kern_path(name, flags, path);
33120 + if (!err && d_is_positive(path->dentry))
33121 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33125 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33126 + struct path *ppath, int len)
33128 + struct path path;
33130 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33131 + if (IS_ERR(path.dentry))
33133 + if (d_is_positive(path.dentry)) {
33134 + path.mnt = ppath->mnt;
33135 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33139 + AuTraceErrPtr(path.dentry);
33140 + return path.dentry;
33143 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33146 + struct path path;
33148 + /* VFS checks it too, but by WARN_ON_ONCE() */
33149 + IMustLock(d_inode(ppath->dentry));
33151 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33152 + if (IS_ERR(path.dentry))
33154 + if (d_is_positive(path.dentry)) {
33155 + path.mnt = ppath->mnt;
33156 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33160 + AuTraceErrPtr(path.dentry);
33161 + return path.dentry;
33164 +void vfsub_call_lkup_one(void *args)
33166 + struct vfsub_lkup_one_args *a = args;
33167 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33170 +/* ---------------------------------------------------------------------- */
33172 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33173 + struct dentry *d2, struct au_hinode *hdir2)
33175 + struct dentry *d;
33178 + d = lock_rename(d1, d2);
33180 + au_hn_suspend(hdir1);
33181 + if (hdir1 != hdir2)
33182 + au_hn_suspend(hdir2);
33187 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33188 + struct dentry *d2, struct au_hinode *hdir2)
33190 + au_hn_resume(hdir1);
33191 + if (hdir1 != hdir2)
33192 + au_hn_resume(hdir2);
33194 + unlock_rename(d1, d2);
33198 +/* ---------------------------------------------------------------------- */
33200 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33203 + struct dentry *d;
33204 + struct mnt_idmap *idmap;
33208 + d = path->dentry;
33209 + path->dentry = d->d_parent;
33210 + err = security_path_mknod(path, d, mode, 0);
33211 + path->dentry = d;
33212 + if (unlikely(err))
33214 + idmap = mnt_idmap(path->mnt);
33217 + err = vfs_create(idmap, dir, path->dentry, mode, want_excl);
33220 + struct path tmp = *path;
33223 + vfsub_update_h_iattr(&tmp, &did);
33225 + tmp.dentry = path->dentry->d_parent;
33226 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33235 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33238 + struct dentry *d;
33239 + struct mnt_idmap *idmap;
33243 + d = path->dentry;
33244 + path->dentry = d->d_parent;
33245 + err = security_path_symlink(path, d, symname);
33246 + path->dentry = d;
33247 + if (unlikely(err))
33249 + idmap = mnt_idmap(path->mnt);
33252 + err = vfs_symlink(idmap, dir, path->dentry, symname);
33255 + struct path tmp = *path;
33258 + vfsub_update_h_iattr(&tmp, &did);
33260 + tmp.dentry = path->dentry->d_parent;
33261 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33270 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33273 + struct dentry *d;
33274 + struct mnt_idmap *idmap;
33278 + d = path->dentry;
33279 + path->dentry = d->d_parent;
33280 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33281 + path->dentry = d;
33282 + if (unlikely(err))
33284 + idmap = mnt_idmap(path->mnt);
33287 + err = vfs_mknod(idmap, dir, path->dentry, mode, dev);
33290 + struct path tmp = *path;
33293 + vfsub_update_h_iattr(&tmp, &did);
33295 + tmp.dentry = path->dentry->d_parent;
33296 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33305 +static int au_test_nlink(struct inode *inode)
33307 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33309 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33310 + || inode->i_nlink < link_max)
33315 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33316 + struct inode **delegated_inode)
33319 + struct dentry *d;
33320 + struct mnt_idmap *idmap;
33324 + err = au_test_nlink(d_inode(src_dentry));
33325 + if (unlikely(err))
33328 + /* we don't call may_linkat() */
33329 + d = path->dentry;
33330 + path->dentry = d->d_parent;
33331 + err = security_path_link(src_dentry, path, d);
33332 + path->dentry = d;
33333 + if (unlikely(err))
33335 + idmap = mnt_idmap(path->mnt);
33338 + err = vfs_link(src_dentry, idmap, dir, path->dentry, delegated_inode);
33341 + struct path tmp = *path;
33344 + /* fuse has different memory inode for the same inumber */
33345 + vfsub_update_h_iattr(&tmp, &did);
33347 + tmp.dentry = path->dentry->d_parent;
33348 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33349 + tmp.dentry = src_dentry;
33350 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33359 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33360 + struct inode *dir, struct path *path,
33361 + struct inode **delegated_inode, unsigned int flags)
33364 + struct renamedata rd;
33365 + struct path tmp = {
33368 + struct dentry *d;
33371 + IMustLock(src_dir);
33373 + d = path->dentry;
33374 + path->dentry = d->d_parent;
33375 + tmp.dentry = src_dentry->d_parent;
33376 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33377 + path->dentry = d;
33378 + if (unlikely(err))
33381 + rd.old_mnt_idmap = mnt_idmap(path->mnt);
33382 + rd.old_dir = src_dir;
33383 + rd.old_dentry = src_dentry;
33384 + rd.new_mnt_idmap = rd.old_mnt_idmap;
33385 + rd.new_dir = dir;
33386 + rd.new_dentry = path->dentry;
33387 + rd.delegated_inode = delegated_inode;
33388 + rd.flags = flags;
33390 + err = vfs_rename(&rd);
33395 + tmp.dentry = d->d_parent;
33396 + vfsub_update_h_iattr(&tmp, &did);
33398 + tmp.dentry = src_dentry;
33399 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33400 + tmp.dentry = src_dentry->d_parent;
33401 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33410 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33413 + struct dentry *d;
33414 + struct mnt_idmap *idmap;
33418 + d = path->dentry;
33419 + path->dentry = d->d_parent;
33420 + err = security_path_mkdir(path, d, mode);
33421 + path->dentry = d;
33422 + if (unlikely(err))
33424 + idmap = mnt_idmap(path->mnt);
33427 + err = vfs_mkdir(idmap, dir, path->dentry, mode);
33430 + struct path tmp = *path;
33433 + vfsub_update_h_iattr(&tmp, &did);
33435 + tmp.dentry = path->dentry->d_parent;
33436 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33445 +int vfsub_rmdir(struct inode *dir, struct path *path)
33448 + struct dentry *d;
33449 + struct mnt_idmap *idmap;
33453 + d = path->dentry;
33454 + path->dentry = d->d_parent;
33455 + err = security_path_rmdir(path, d);
33456 + path->dentry = d;
33457 + if (unlikely(err))
33459 + idmap = mnt_idmap(path->mnt);
33462 + err = vfs_rmdir(idmap, dir, path->dentry);
33465 + struct path tmp = {
33466 + .dentry = path->dentry->d_parent,
33470 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33477 +/* ---------------------------------------------------------------------- */
33479 +/* todo: support mmap_sem? */
33480 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33486 + err = vfs_read(file, ubuf, count, ppos);
33489 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33493 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33499 + err = kernel_read(file, kbuf, count, ppos);
33503 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33507 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33513 + err = vfs_write(file, ubuf, count, ppos);
33516 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33520 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33525 + err = kernel_write(file, kbuf, count, ppos);
33528 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33532 +int vfsub_flush(struct file *file, fl_owner_t id)
33537 + if (file->f_op->flush) {
33538 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33539 + err = file->f_op->flush(file, id);
33542 + err = file->f_op->flush(file, id);
33546 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33552 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33556 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33559 + err = iterate_dir(file, ctx);
33562 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33567 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33568 + struct pipe_inode_info *pipe, size_t len,
33569 + unsigned int flags)
33574 + err = vfs_splice_read(in, ppos, pipe, len, flags);
33576 + file_accessed(in);
33578 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33582 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33583 + loff_t *ppos, size_t len, unsigned int flags)
33588 + err = do_splice_from(pipe, out, ppos, len, flags);
33591 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33595 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33599 + /* file can be NULL */
33601 + err = vfs_fsync(file, datasync);
33605 + AuDebugOn(!file);
33606 + path = &file->f_path;
33608 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33613 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33614 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33615 + struct file *h_file)
33618 + struct inode *h_inode;
33619 + struct super_block *h_sb;
33620 + struct mnt_idmap *h_idmap;
33623 + err = vfsub_truncate(h_path, length);
33627 + h_inode = d_inode(h_path->dentry);
33628 + h_sb = h_inode->i_sb;
33630 + sb_start_write(h_sb);
33632 + err = security_file_truncate(h_file);
33634 + h_idmap = mnt_idmap(h_path->mnt);
33636 + err = do_truncate(h_idmap, h_path->dentry, length, attr,
33641 + sb_end_write(h_sb);
33648 +/* ---------------------------------------------------------------------- */
33650 +struct au_vfsub_mkdir_args {
33652 + struct inode *dir;
33653 + struct path *path;
33657 +static void au_call_vfsub_mkdir(void *args)
33659 + struct au_vfsub_mkdir_args *a = args;
33660 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33663 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33665 + int err, do_sio, wkq_err;
33666 + struct mnt_idmap *idmap;
33668 + idmap = mnt_idmap(path->mnt);
33669 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33672 + err = vfsub_mkdir(dir, path, mode);
33675 + struct au_vfsub_mkdir_args args = {
33681 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33682 + if (unlikely(wkq_err))
33689 +struct au_vfsub_rmdir_args {
33691 + struct inode *dir;
33692 + struct path *path;
33695 +static void au_call_vfsub_rmdir(void *args)
33697 + struct au_vfsub_rmdir_args *a = args;
33698 + *a->errp = vfsub_rmdir(a->dir, a->path);
33701 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33703 + int err, do_sio, wkq_err;
33704 + struct mnt_idmap *idmap;
33706 + idmap = mnt_idmap(path->mnt);
33707 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33710 + err = vfsub_rmdir(dir, path);
33713 + struct au_vfsub_rmdir_args args = {
33718 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33719 + if (unlikely(wkq_err))
33726 +/* ---------------------------------------------------------------------- */
33728 +struct notify_change_args {
33730 + struct path *path;
33731 + struct iattr *ia;
33732 + struct inode **delegated_inode;
33735 +static void call_notify_change(void *args)
33737 + struct notify_change_args *a = args;
33738 + struct inode *h_inode;
33739 + struct mnt_idmap *idmap;
33741 + h_inode = d_inode(a->path->dentry);
33742 + IMustLock(h_inode);
33744 + *a->errp = -EPERM;
33745 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33746 + idmap = mnt_idmap(a->path->mnt);
33748 + *a->errp = notify_change(idmap, a->path->dentry, a->ia,
33749 + a->delegated_inode);
33752 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33754 + AuTraceErr(*a->errp);
33757 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33758 + struct inode **delegated_inode)
33761 + struct notify_change_args args = {
33765 + .delegated_inode = delegated_inode
33768 + call_notify_change(&args);
33773 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33774 + struct inode **delegated_inode)
33776 + int err, wkq_err;
33777 + struct notify_change_args args = {
33781 + .delegated_inode = delegated_inode
33784 + wkq_err = au_wkq_wait(call_notify_change, &args);
33785 + if (unlikely(wkq_err))
33791 +/* ---------------------------------------------------------------------- */
33793 +struct unlink_args {
33795 + struct inode *dir;
33796 + struct path *path;
33797 + struct inode **delegated_inode;
33800 +static void call_unlink(void *args)
33802 + struct unlink_args *a = args;
33803 + struct dentry *d = a->path->dentry;
33804 + struct inode *h_inode;
33805 + struct mnt_idmap *idmap;
33806 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33807 + && au_dcount(d) == 1);
33809 + IMustLock(a->dir);
33811 + a->path->dentry = d->d_parent;
33812 + *a->errp = security_path_unlink(a->path, d);
33813 + a->path->dentry = d;
33814 + if (unlikely(*a->errp))
33817 + if (!stop_sillyrename)
33820 + if (d_is_positive(d)) {
33821 + h_inode = d_inode(d);
33825 + idmap = mnt_idmap(a->path->mnt);
33827 + *a->errp = vfs_unlink(idmap, a->dir, d, a->delegated_inode);
33830 + struct path tmp = {
33831 + .dentry = d->d_parent,
33832 + .mnt = a->path->mnt
33834 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33837 + if (!stop_sillyrename)
33842 + AuTraceErr(*a->errp);
33846 + * @dir: must be locked.
33847 + * @dentry: target dentry.
33849 +int vfsub_unlink(struct inode *dir, struct path *path,
33850 + struct inode **delegated_inode, int force)
33853 + struct unlink_args args = {
33857 + .delegated_inode = delegated_inode
33861 + call_unlink(&args);
33865 + wkq_err = au_wkq_wait(call_unlink, &args);
33866 + if (unlikely(wkq_err))
33872 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33873 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33874 +++ linux/fs/aufs/vfsub.h 2023-08-28 12:34:39.999969465 +0200
33876 +/* SPDX-License-Identifier: GPL-2.0 */
33878 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33880 + * This program is free software; you can redistribute it and/or modify
33881 + * it under the terms of the GNU General Public License as published by
33882 + * the Free Software Foundation; either version 2 of the License, or
33883 + * (at your option) any later version.
33885 + * This program is distributed in the hope that it will be useful,
33886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33888 + * GNU General Public License for more details.
33890 + * You should have received a copy of the GNU General Public License
33891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33895 + * sub-routines for VFS
33898 +#ifndef __AUFS_VFSUB_H__
33899 +#define __AUFS_VFSUB_H__
33903 +#include <linux/fs.h>
33904 +#include <linux/mount.h>
33905 +#include <linux/posix_acl.h>
33906 +#include <linux/xattr.h>
33907 +#include "debug.h"
33909 +/* copied from linux/fs/internal.h */
33910 +/* todo: BAD approach!! */
33911 +extern void __mnt_drop_write(struct vfsmount *);
33912 +extern struct file *alloc_empty_file(int, const struct cred *);
33914 +/* ---------------------------------------------------------------------- */
33916 +/* lock subclass for lower inode */
33917 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33918 +/* reduce? gave up. */
33920 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33921 + AuLsc_I_PARENT, /* lower inode, parent first */
33922 + AuLsc_I_PARENT2, /* copyup dirs */
33923 + AuLsc_I_PARENT3, /* copyup wh */
33929 +/* to debug easier, do not make them inlined functions */
33930 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33931 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33933 +/* ---------------------------------------------------------------------- */
33935 +static inline void vfsub_drop_nlink(struct inode *inode)
33937 + AuDebugOn(!inode->i_nlink);
33938 + drop_nlink(inode);
33941 +static inline void vfsub_dead_dir(struct inode *inode)
33943 + AuDebugOn(!S_ISDIR(inode->i_mode));
33944 + inode->i_flags |= S_DEAD;
33945 + clear_nlink(inode);
33948 +static inline int vfsub_native_ro(struct inode *inode)
33950 + return sb_rdonly(inode->i_sb)
33951 + || IS_RDONLY(inode)
33952 + /* || IS_APPEND(inode) */
33953 + || IS_IMMUTABLE(inode);
33956 +#ifdef CONFIG_AUFS_BR_FUSE
33957 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33959 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33962 +int vfsub_sync_filesystem(struct super_block *h_sb);
33964 +/* ---------------------------------------------------------------------- */
33966 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33967 +struct file *vfsub_dentry_open(struct path *path, int flags);
33968 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33970 +struct vfsub_aopen_args {
33971 + struct file *file;
33972 + unsigned int open_flag;
33973 + umode_t create_mode;
33974 + struct au_branch *br;
33976 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33977 + struct vfsub_aopen_args *args);
33978 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
33980 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33981 + struct path *ppath, int len);
33982 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33985 +struct vfsub_lkup_one_args {
33986 + struct dentry **errp;
33987 + struct qstr *name;
33988 + struct path *ppath;
33991 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
33992 + struct path *ppath)
33994 + return vfsub_lookup_one_len(name->name, ppath, name->len);
33997 +void vfsub_call_lkup_one(void *args);
33999 +/* ---------------------------------------------------------------------- */
34001 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34006 + err = mnt_want_write(mnt);
34011 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34014 + mnt_drop_write(mnt);
34018 +#if 0 /* reserved */
34019 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34022 + mnt_drop_write_file(file);
34027 +/* ---------------------------------------------------------------------- */
34030 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34031 + struct dentry *d2, struct au_hinode *hdir2);
34032 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34033 + struct dentry *d2, struct au_hinode *hdir2);
34035 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34037 +int vfsub_symlink(struct inode *dir, struct path *path,
34038 + const char *symname);
34039 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34040 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34041 + struct path *path, struct inode **delegated_inode);
34042 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34043 + struct inode *hdir, struct path *path,
34044 + struct inode **delegated_inode, unsigned int flags);
34045 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34046 +int vfsub_rmdir(struct inode *dir, struct path *path);
34048 +/* ---------------------------------------------------------------------- */
34050 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34052 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34054 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34056 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34058 +int vfsub_flush(struct file *file, fl_owner_t id);
34059 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34061 +static inline loff_t vfsub_f_size_read(struct file *file)
34063 + return i_size_read(file_inode(file));
34066 +static inline unsigned int vfsub_file_flags(struct file *file)
34068 + unsigned int flags;
34070 + spin_lock(&file->f_lock);
34071 + flags = file->f_flags;
34072 + spin_unlock(&file->f_lock);
34077 +static inline int vfsub_file_execed(struct file *file)
34079 + /* todo: direct access f_flags */
34080 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34083 +#if 0 /* reserved */
34084 +static inline void vfsub_file_accessed(struct file *h_file)
34086 + file_accessed(h_file);
34087 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34091 +#if 0 /* reserved */
34092 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34093 + struct dentry *h_dentry)
34095 + struct path h_path = {
34096 + .dentry = h_dentry,
34099 + touch_atime(&h_path);
34100 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34104 +static inline int vfsub_update_time(struct inode *h_inode,
34105 + struct timespec64 *ts, int flags)
34107 + return inode_update_time(h_inode, ts, flags);
34108 + /* no vfsub_update_h_iattr() since we don't have struct path */
34111 +#ifdef CONFIG_FS_POSIX_ACL
34112 +static inline int vfsub_acl_chmod(struct mnt_idmap *h_idmap,
34113 + struct dentry *h_dentry, umode_t h_mode)
34117 + err = posix_acl_chmod(h_idmap, h_dentry, h_mode);
34118 + if (err == -EOPNOTSUPP)
34123 +AuStubInt0(vfsub_acl_chmod, struct mnt_idmap *h_idmap,
34124 + struct dentry *h_dentry, umode_t h_mode);
34127 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34128 + struct pipe_inode_info *pipe, size_t len,
34129 + unsigned int flags);
34130 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34131 + loff_t *ppos, size_t len, unsigned int flags);
34133 +static inline long vfsub_truncate(struct path *path, loff_t length)
34138 + err = vfs_truncate(path, length);
34143 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34144 + struct file *h_file);
34145 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34148 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34151 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34157 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34163 +/* copy_file_range(2) is a systemcall */
34164 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34165 + struct file *dst, loff_t dst_pos,
34166 + size_t len, unsigned int flags)
34171 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34177 +/* ---------------------------------------------------------------------- */
34179 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34184 + err = vfs_llseek(file, offset, origin);
34189 +/* ---------------------------------------------------------------------- */
34191 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34192 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34193 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34194 + struct inode **delegated_inode);
34195 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34196 + struct inode **delegated_inode);
34197 +int vfsub_unlink(struct inode *dir, struct path *path,
34198 + struct inode **delegated_inode, int force);
34200 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34202 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34205 +/* ---------------------------------------------------------------------- */
34207 +static inline int vfsub_setxattr(struct mnt_idmap *idmap,
34208 + struct dentry *dentry, const char *name,
34209 + const void *value, size_t size, int flags)
34214 + err = vfs_setxattr(idmap, dentry, name, value, size, flags);
34220 +static inline int vfsub_removexattr(struct mnt_idmap *idmap,
34221 + struct dentry *dentry, const char *name)
34226 + err = vfs_removexattr(idmap, dentry, name);
34232 +#ifdef CONFIG_FS_POSIX_ACL
34233 +static inline int vfsub_set_acl(struct mnt_idmap *idmap,
34234 + struct dentry *dentry, const char *name,
34235 + struct posix_acl *acl)
34240 + err = vfs_set_acl(idmap, dentry, name, acl);
34246 +static inline int vfsub_remove_acl(struct mnt_idmap *idmap,
34247 + struct dentry *dentry, const char *name)
34252 + err = vfs_remove_acl(idmap, dentry, name);
34258 +AuStubInt0(vfsub_set_acl, struct mnt_idmap *idmap, struct dentry *dentry,
34259 + const char *name, struct posix_acl *acl);
34260 +AuStubInt0(vfsub_remove_acl, struct mnt_idmap *idmap,
34261 + struct dentry *dentry, const char *name);
34264 +#endif /* __KERNEL__ */
34265 +#endif /* __AUFS_VFSUB_H__ */
34266 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34267 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34268 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34270 +// SPDX-License-Identifier: GPL-2.0
34272 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34274 + * This program is free software; you can redistribute it and/or modify
34275 + * it under the terms of the GNU General Public License as published by
34276 + * the Free Software Foundation; either version 2 of the License, or
34277 + * (at your option) any later version.
34279 + * This program is distributed in the hope that it will be useful,
34280 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34281 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34282 + * GNU General Public License for more details.
34284 + * You should have received a copy of the GNU General Public License
34285 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34289 + * policies for selecting one among multiple writable branches
34292 +#include <linux/statfs.h>
34295 +/* subset of cpup_attr() */
34296 +static noinline_for_stack
34297 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34301 + struct inode *h_isrc;
34303 + h_isrc = d_inode(h_src);
34304 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34305 + ia.ia_mode = h_isrc->i_mode;
34306 + ia.ia_uid = h_isrc->i_uid;
34307 + ia.ia_gid = h_isrc->i_gid;
34308 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34309 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34310 + /* no delegation since it is just created */
34311 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34313 + /* is this nfs only? */
34314 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34315 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34316 + ia.ia_mode = h_isrc->i_mode;
34317 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34323 +#define AuCpdown_PARENT_OPQ 1
34324 +#define AuCpdown_WHED (1 << 1)
34325 +#define AuCpdown_MADE_DIR (1 << 2)
34326 +#define AuCpdown_DIROPQ (1 << 3)
34327 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34328 +#define au_fset_cpdown(flags, name) \
34329 + do { (flags) |= AuCpdown_##name; } while (0)
34330 +#define au_fclr_cpdown(flags, name) \
34331 + do { (flags) &= ~AuCpdown_##name; } while (0)
34333 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34334 + unsigned int *flags)
34337 + struct dentry *opq_dentry;
34339 + opq_dentry = au_diropq_create(dentry, bdst);
34340 + err = PTR_ERR(opq_dentry);
34341 + if (IS_ERR(opq_dentry))
34343 + dput(opq_dentry);
34344 + au_fset_cpdown(*flags, DIROPQ);
34350 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34351 + struct inode *dir, aufs_bindex_t bdst)
34354 + struct path h_path;
34355 + struct au_branch *br;
34357 + br = au_sbr(dentry->d_sb, bdst);
34358 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34359 + err = PTR_ERR(h_path.dentry);
34360 + if (IS_ERR(h_path.dentry))
34364 + if (d_is_positive(h_path.dentry)) {
34365 + h_path.mnt = au_br_mnt(br);
34366 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34369 + dput(h_path.dentry);
34375 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34376 + struct au_pin *pin,
34377 + struct dentry *h_parent, void *arg)
34380 + aufs_bindex_t bopq, btop;
34381 + struct path h_path;
34382 + struct dentry *parent;
34383 + struct inode *h_dir, *h_inode, *inode, *dir;
34384 + unsigned int *flags = arg;
34386 + btop = au_dbtop(dentry);
34387 + /* dentry is di-locked */
34388 + parent = dget_parent(dentry);
34389 + dir = d_inode(parent);
34390 + h_dir = d_inode(h_parent);
34391 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34392 + IMustLock(h_dir);
34394 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34395 + if (unlikely(err < 0))
34397 + h_path.dentry = au_h_dptr(dentry, bdst);
34398 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34399 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34400 + if (unlikely(err))
34402 + au_fset_cpdown(*flags, MADE_DIR);
34404 + bopq = au_dbdiropq(dentry);
34405 + au_fclr_cpdown(*flags, WHED);
34406 + au_fclr_cpdown(*flags, DIROPQ);
34407 + if (au_dbwh(dentry) == bdst)
34408 + au_fset_cpdown(*flags, WHED);
34409 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34410 + au_fset_cpdown(*flags, PARENT_OPQ);
34411 + h_inode = d_inode(h_path.dentry);
34412 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34413 + if (au_ftest_cpdown(*flags, WHED)) {
34414 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34415 + if (unlikely(err)) {
34416 + inode_unlock(h_inode);
34421 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34422 + inode_unlock(h_inode);
34423 + if (unlikely(err))
34426 + if (au_ftest_cpdown(*flags, WHED)) {
34427 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34428 + if (unlikely(err))
34432 + inode = d_inode(dentry);
34433 + if (au_ibbot(inode) < bdst)
34434 + au_set_ibbot(inode, bdst);
34435 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34436 + au_hi_flags(inode, /*isdir*/1));
34437 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34438 + goto out; /* success */
34442 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34443 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34444 + rerr = au_diropq_remove(dentry, bdst);
34445 + inode_unlock(h_inode);
34446 + if (unlikely(rerr)) {
34447 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34448 + dentry, bdst, rerr);
34454 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34455 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34456 + if (unlikely(rerr)) {
34457 + AuIOErr("failed removing %pd b%d (%d)\n",
34458 + dentry, bdst, rerr);
34463 + au_set_h_dptr(dentry, bdst, NULL);
34464 + if (au_dbbot(dentry) == bdst)
34465 + au_update_dbbot(dentry);
34471 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34474 + unsigned int flags;
34477 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34482 +/* ---------------------------------------------------------------------- */
34484 +/* policies for create */
34486 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34488 + int err, i, j, ndentry;
34489 + aufs_bindex_t bopq;
34490 + struct au_dcsub_pages dpages;
34491 + struct au_dpage *dpage;
34492 + struct dentry **dentries, *parent, *d;
34494 + err = au_dpages_init(&dpages, GFP_NOFS);
34495 + if (unlikely(err))
34497 + parent = dget_parent(dentry);
34498 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34499 + if (unlikely(err))
34503 + for (i = 0; i < dpages.ndpage; i++) {
34504 + dpage = dpages.dpages + i;
34505 + dentries = dpage->dentries;
34506 + ndentry = dpage->ndentry;
34507 + for (j = 0; j < ndentry; j++) {
34509 + di_read_lock_parent2(d, !AuLock_IR);
34510 + bopq = au_dbdiropq(d);
34511 + di_read_unlock(d, !AuLock_IR);
34512 + if (bopq >= 0 && bopq < err)
34519 + au_dpages_free(&dpages);
34524 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34526 + for (; bindex >= 0; bindex--)
34527 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34532 +/* top down parent */
34533 +static int au_wbr_create_tdp(struct dentry *dentry,
34534 + unsigned int flags __maybe_unused)
34537 + aufs_bindex_t btop, bindex;
34538 + struct super_block *sb;
34539 + struct dentry *parent, *h_parent;
34541 + sb = dentry->d_sb;
34542 + btop = au_dbtop(dentry);
34544 + if (!au_br_rdonly(au_sbr(sb, btop)))
34548 + parent = dget_parent(dentry);
34549 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34550 + h_parent = au_h_dptr(parent, bindex);
34551 + if (!h_parent || d_is_negative(h_parent))
34554 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34561 + /* bottom up here */
34562 + if (unlikely(err < 0)) {
34563 + err = au_wbr_bu(sb, btop - 1);
34565 + err = au_wbr_nonopq(dentry, err);
34569 + AuDbg("b%d\n", err);
34573 +/* ---------------------------------------------------------------------- */
34575 +/* an exception for the policy other than tdp */
34576 +static int au_wbr_create_exp(struct dentry *dentry)
34579 + aufs_bindex_t bwh, bdiropq;
34580 + struct dentry *parent;
34583 + bwh = au_dbwh(dentry);
34584 + parent = dget_parent(dentry);
34585 + bdiropq = au_dbdiropq(parent);
34587 + if (bdiropq >= 0)
34588 + err = min(bdiropq, bwh);
34591 + AuDbg("%d\n", err);
34592 + } else if (bdiropq >= 0) {
34594 + AuDbg("%d\n", err);
34599 + err = au_wbr_nonopq(dentry, err);
34601 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34604 + AuDbg("%d\n", err);
34608 +/* ---------------------------------------------------------------------- */
34611 +static int au_wbr_create_init_rr(struct super_block *sb)
34615 + err = au_wbr_bu(sb, au_sbbot(sb));
34616 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34619 + AuDbg("b%d\n", err);
34623 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34627 + aufs_bindex_t bindex, bbot;
34628 + struct super_block *sb;
34631 + err = au_wbr_create_exp(dentry);
34635 + sb = dentry->d_sb;
34636 + next = &au_sbi(sb)->si_wbr_rr_next;
34637 + bbot = au_sbbot(sb);
34639 + for (bindex = 0; bindex <= bbot; bindex++) {
34640 + if (!au_ftest_wbr(flags, DIR)) {
34641 + err = atomic_dec_return(next) + 1;
34642 + /* modulo for 0 is meaningless */
34643 + if (unlikely(!err))
34644 + err = atomic_dec_return(next) + 1;
34646 + err = atomic_read(next);
34647 + AuDbg("%d\n", err);
34650 + AuDbg("%d\n", err);
34651 + if (!au_br_rdonly(au_sbr(sb, err)))
34657 + err = au_wbr_nonopq(dentry, err);
34660 + AuDbg("%d\n", err);
34664 +/* ---------------------------------------------------------------------- */
34666 +/* most free space */
34667 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34669 + struct super_block *sb;
34670 + struct au_branch *br;
34671 + struct au_wbr_mfs *mfs;
34672 + struct dentry *h_parent;
34673 + aufs_bindex_t bindex, bbot;
34675 + unsigned long long b, bavail;
34676 + struct path h_path;
34677 + /* reduce the stack usage */
34678 + struct kstatfs *st;
34680 + st = kmalloc(sizeof(*st), GFP_NOFS);
34681 + if (unlikely(!st)) {
34682 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34687 + sb = dentry->d_sb;
34688 + mfs = &au_sbi(sb)->si_wbr_mfs;
34689 + MtxMustLock(&mfs->mfs_lock);
34690 + mfs->mfs_bindex = -EROFS;
34691 + mfs->mfsrr_bytes = 0;
34694 + bbot = au_sbbot(sb);
34696 + bindex = au_dbtop(parent);
34697 + bbot = au_dbtaildir(parent);
34700 + for (; bindex <= bbot; bindex++) {
34702 + h_parent = au_h_dptr(parent, bindex);
34703 + if (!h_parent || d_is_negative(h_parent))
34706 + br = au_sbr(sb, bindex);
34707 + if (au_br_rdonly(br))
34710 + /* sb->s_root for NFS is unreliable */
34711 + h_path.mnt = au_br_mnt(br);
34712 + h_path.dentry = h_path.mnt->mnt_root;
34713 + err = vfs_statfs(&h_path, st);
34714 + if (unlikely(err)) {
34715 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34719 + /* when the available size is equal, select the lower one */
34720 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34721 + || sizeof(b) < sizeof(st->f_bsize));
34722 + b = st->f_bavail * st->f_bsize;
34723 + br->br_wbr->wbr_bytes = b;
34724 + if (b >= bavail) {
34726 + mfs->mfs_bindex = bindex;
34727 + mfs->mfs_jiffy = jiffies;
34731 + mfs->mfsrr_bytes = bavail;
34732 + AuDbg("b%d\n", mfs->mfs_bindex);
34733 + au_kfree_rcu(st);
34736 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34739 + struct dentry *parent;
34740 + struct super_block *sb;
34741 + struct au_wbr_mfs *mfs;
34743 + err = au_wbr_create_exp(dentry);
34747 + sb = dentry->d_sb;
34749 + if (au_ftest_wbr(flags, PARENT))
34750 + parent = dget_parent(dentry);
34751 + mfs = &au_sbi(sb)->si_wbr_mfs;
34752 + mutex_lock(&mfs->mfs_lock);
34753 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34754 + || mfs->mfs_bindex < 0
34755 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34756 + au_mfs(dentry, parent);
34757 + mutex_unlock(&mfs->mfs_lock);
34758 + err = mfs->mfs_bindex;
34762 + err = au_wbr_nonopq(dentry, err);
34765 + AuDbg("b%d\n", err);
34769 +static int au_wbr_create_init_mfs(struct super_block *sb)
34771 + struct au_wbr_mfs *mfs;
34773 + mfs = &au_sbi(sb)->si_wbr_mfs;
34774 + mutex_init(&mfs->mfs_lock);
34775 + mfs->mfs_jiffy = 0;
34776 + mfs->mfs_bindex = -EROFS;
34781 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34783 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34787 +/* ---------------------------------------------------------------------- */
34789 +/* top down regardless parent, and then mfs */
34790 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34791 + unsigned int flags __maybe_unused)
34794 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34795 + unsigned long long watermark;
34796 + struct super_block *sb;
34797 + struct au_wbr_mfs *mfs;
34798 + struct au_branch *br;
34799 + struct dentry *parent;
34801 + sb = dentry->d_sb;
34802 + mfs = &au_sbi(sb)->si_wbr_mfs;
34803 + mutex_lock(&mfs->mfs_lock);
34804 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34805 + || mfs->mfs_bindex < 0)
34806 + au_mfs(dentry, /*parent*/NULL);
34807 + watermark = mfs->mfsrr_watermark;
34808 + bmfs = mfs->mfs_bindex;
34809 + mutex_unlock(&mfs->mfs_lock);
34811 + /* another style of au_wbr_create_exp() */
34812 + bwh = au_dbwh(dentry);
34813 + parent = dget_parent(dentry);
34814 + btail = au_dbtaildir(parent);
34815 + if (bwh >= 0 && bwh < btail)
34818 + err = au_wbr_nonopq(dentry, btail);
34819 + if (unlikely(err < 0))
34823 + for (bindex = 0; bindex <= btail; bindex++) {
34824 + br = au_sbr(sb, bindex);
34825 + if (au_br_rdonly(br))
34827 + if (br->br_wbr->wbr_bytes > watermark) {
34838 + AuDbg("b%d\n", err);
34842 +/* ---------------------------------------------------------------------- */
34844 +/* most free space and then round robin */
34845 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34848 + struct au_wbr_mfs *mfs;
34850 + err = au_wbr_create_mfs(dentry, flags);
34852 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34853 + mutex_lock(&mfs->mfs_lock);
34854 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34855 + err = au_wbr_create_rr(dentry, flags);
34856 + mutex_unlock(&mfs->mfs_lock);
34859 + AuDbg("b%d\n", err);
34863 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34867 + au_wbr_create_init_mfs(sb); /* ignore */
34868 + err = au_wbr_create_init_rr(sb);
34873 +/* ---------------------------------------------------------------------- */
34875 +/* top down parent and most free space */
34876 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34879 + unsigned long long b;
34880 + aufs_bindex_t bindex, btop, bbot;
34881 + struct super_block *sb;
34882 + struct dentry *parent, *h_parent;
34883 + struct au_branch *br;
34885 + err = au_wbr_create_tdp(dentry, flags);
34886 + if (unlikely(err < 0))
34888 + parent = dget_parent(dentry);
34889 + btop = au_dbtop(parent);
34890 + bbot = au_dbtaildir(parent);
34891 + if (btop == bbot)
34892 + goto out_parent; /* success */
34894 + e2 = au_wbr_create_mfs(dentry, flags);
34896 + goto out_parent; /* success */
34898 + /* when the available size is equal, select upper one */
34899 + sb = dentry->d_sb;
34900 + br = au_sbr(sb, err);
34901 + b = br->br_wbr->wbr_bytes;
34902 + AuDbg("b%d, %llu\n", err, b);
34904 + for (bindex = btop; bindex <= bbot; bindex++) {
34905 + h_parent = au_h_dptr(parent, bindex);
34906 + if (!h_parent || d_is_negative(h_parent))
34909 + br = au_sbr(sb, bindex);
34910 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34911 + b = br->br_wbr->wbr_bytes;
34913 + AuDbg("b%d, %llu\n", err, b);
34918 + err = au_wbr_nonopq(dentry, err);
34923 + AuDbg("b%d\n", err);
34927 +/* ---------------------------------------------------------------------- */
34930 + * - top down parent
34931 + * - most free space with parent
34932 + * - most free space round-robin regardless parent
34934 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34937 + unsigned long long watermark;
34938 + struct super_block *sb;
34939 + struct au_branch *br;
34940 + struct au_wbr_mfs *mfs;
34942 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34943 + if (unlikely(err < 0))
34946 + sb = dentry->d_sb;
34947 + br = au_sbr(sb, err);
34948 + mfs = &au_sbi(sb)->si_wbr_mfs;
34949 + mutex_lock(&mfs->mfs_lock);
34950 + watermark = mfs->mfsrr_watermark;
34951 + mutex_unlock(&mfs->mfs_lock);
34952 + if (br->br_wbr->wbr_bytes < watermark)
34953 + /* regardless the parent dir */
34954 + err = au_wbr_create_mfsrr(dentry, flags);
34957 + AuDbg("b%d\n", err);
34961 +/* ---------------------------------------------------------------------- */
34963 +/* policies for copyup */
34965 +/* top down parent */
34966 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34968 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34971 +/* bottom up parent */
34972 +static int au_wbr_copyup_bup(struct dentry *dentry)
34975 + aufs_bindex_t bindex, btop;
34976 + struct dentry *parent, *h_parent;
34977 + struct super_block *sb;
34980 + sb = dentry->d_sb;
34981 + parent = dget_parent(dentry);
34982 + btop = au_dbtop(parent);
34983 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
34984 + h_parent = au_h_dptr(parent, bindex);
34985 + if (!h_parent || d_is_negative(h_parent))
34988 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34995 + /* bottom up here */
34996 + if (unlikely(err < 0))
34997 + err = au_wbr_bu(sb, btop - 1);
34999 + AuDbg("b%d\n", err);
35004 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
35008 + err = au_wbr_bu(dentry->d_sb, btop);
35009 + AuDbg("b%d\n", err);
35011 + err = au_wbr_nonopq(dentry, err);
35013 + AuDbg("b%d\n", err);
35017 +static int au_wbr_copyup_bu(struct dentry *dentry)
35020 + aufs_bindex_t btop;
35022 + btop = au_dbtop(dentry);
35023 + err = au_wbr_do_copyup_bu(dentry, btop);
35027 +/* ---------------------------------------------------------------------- */
35029 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35030 + [AuWbrCopyup_TDP] = {
35031 + .copyup = au_wbr_copyup_tdp
35033 + [AuWbrCopyup_BUP] = {
35034 + .copyup = au_wbr_copyup_bup
35036 + [AuWbrCopyup_BU] = {
35037 + .copyup = au_wbr_copyup_bu
35041 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35042 + [AuWbrCreate_TDP] = {
35043 + .create = au_wbr_create_tdp
35045 + [AuWbrCreate_RR] = {
35046 + .create = au_wbr_create_rr,
35047 + .init = au_wbr_create_init_rr
35049 + [AuWbrCreate_MFS] = {
35050 + .create = au_wbr_create_mfs,
35051 + .init = au_wbr_create_init_mfs,
35052 + .fin = au_wbr_create_fin_mfs
35054 + [AuWbrCreate_MFSV] = {
35055 + .create = au_wbr_create_mfs,
35056 + .init = au_wbr_create_init_mfs,
35057 + .fin = au_wbr_create_fin_mfs
35059 + [AuWbrCreate_MFSRR] = {
35060 + .create = au_wbr_create_mfsrr,
35061 + .init = au_wbr_create_init_mfsrr,
35062 + .fin = au_wbr_create_fin_mfs
35064 + [AuWbrCreate_MFSRRV] = {
35065 + .create = au_wbr_create_mfsrr,
35066 + .init = au_wbr_create_init_mfsrr,
35067 + .fin = au_wbr_create_fin_mfs
35069 + [AuWbrCreate_TDMFS] = {
35070 + .create = au_wbr_create_tdmfs,
35071 + .init = au_wbr_create_init_mfs,
35072 + .fin = au_wbr_create_fin_mfs
35074 + [AuWbrCreate_TDMFSV] = {
35075 + .create = au_wbr_create_tdmfs,
35076 + .init = au_wbr_create_init_mfs,
35077 + .fin = au_wbr_create_fin_mfs
35079 + [AuWbrCreate_PMFS] = {
35080 + .create = au_wbr_create_pmfs,
35081 + .init = au_wbr_create_init_mfs,
35082 + .fin = au_wbr_create_fin_mfs
35084 + [AuWbrCreate_PMFSV] = {
35085 + .create = au_wbr_create_pmfs,
35086 + .init = au_wbr_create_init_mfs,
35087 + .fin = au_wbr_create_fin_mfs
35089 + [AuWbrCreate_PMFSRR] = {
35090 + .create = au_wbr_create_pmfsrr,
35091 + .init = au_wbr_create_init_mfsrr,
35092 + .fin = au_wbr_create_fin_mfs
35094 + [AuWbrCreate_PMFSRRV] = {
35095 + .create = au_wbr_create_pmfsrr,
35096 + .init = au_wbr_create_init_mfsrr,
35097 + .fin = au_wbr_create_fin_mfs
35100 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35101 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35102 +++ linux/fs/aufs/whout.c 2023-08-28 12:34:39.999969465 +0200
35104 +// SPDX-License-Identifier: GPL-2.0
35106 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35108 + * This program is free software; you can redistribute it and/or modify
35109 + * it under the terms of the GNU General Public License as published by
35110 + * the Free Software Foundation; either version 2 of the License, or
35111 + * (at your option) any later version.
35113 + * This program is distributed in the hope that it will be useful,
35114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35116 + * GNU General Public License for more details.
35118 + * You should have received a copy of the GNU General Public License
35119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35123 + * whiteout for logical deletion and opaque directory
35128 +#define WH_MASK 0444
35131 + * If a directory contains this file, then it is opaque. We start with the
35132 + * .wh. flag so that it is blocked by lookup.
35134 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35135 + sizeof(AUFS_WH_DIROPQ) - 1);
35138 + * generate whiteout name, which is NOT terminated by NULL.
35139 + * @name: original d_name.name
35140 + * @len: original d_name.len
35141 + * @wh: whiteout qstr
35142 + * returns zero when succeeds, otherwise error.
35143 + * succeeded value as wh->name should be freed by kfree().
35145 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35149 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35150 + return -ENAMETOOLONG;
35152 + wh->len = name->len + AUFS_WH_PFX_LEN;
35153 + p = kmalloc(wh->len, GFP_NOFS);
35156 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35157 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35164 +/* ---------------------------------------------------------------------- */
35167 + * test if the @wh_name exists under @h_ppath.
35168 + * @try_sio specifies the necessary of super-io.
35170 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
35171 + struct qstr *wh_name, int try_sio)
35174 + struct dentry *wh_dentry;
35177 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35179 + wh_dentry = au_sio_lkup_one(h_idmap, wh_name, h_ppath);
35180 + err = PTR_ERR(wh_dentry);
35181 + if (IS_ERR(wh_dentry)) {
35182 + if (err == -ENAMETOOLONG)
35188 + if (d_is_negative(wh_dentry))
35189 + goto out_wh; /* success */
35192 + if (d_is_reg(wh_dentry))
35193 + goto out_wh; /* success */
35196 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35197 + wh_dentry, d_inode(wh_dentry)->i_mode);
35206 + * test if the @h_path->dentry sets opaque or not.
35208 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path)
35211 + struct inode *h_dir;
35213 + h_dir = d_inode(h_path->dentry);
35214 + err = au_wh_test(h_idmap, h_path, &diropq_name,
35215 + au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC));
35220 + * returns a negative dentry whose name is unique and temporary.
35222 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35223 + struct qstr *prefix)
35225 + struct dentry *dentry;
35227 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35229 + /* strict atomic_t is unnecessary here */
35230 + static unsigned short cnt;
35232 + struct path h_ppath;
35233 + struct mnt_idmap *h_idmap;
35235 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35238 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35239 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35240 + dentry = ERR_PTR(-ENAMETOOLONG);
35241 + if (unlikely(qs.len > NAME_MAX))
35243 + dentry = ERR_PTR(-ENOMEM);
35244 + name = kmalloc(qs.len + 1, GFP_NOFS);
35245 + if (unlikely(!name))
35249 + /* doubly whiteout-ed */
35250 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35251 + p = name + AUFS_WH_PFX_LEN * 2;
35252 + memcpy(p, prefix->name, prefix->len);
35253 + p += prefix->len;
35255 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35257 + h_ppath.dentry = h_parent;
35258 + h_ppath.mnt = au_br_mnt(br);
35259 + h_idmap = au_br_idmap(br);
35261 + for (i = 0; i < 3; i++) {
35262 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35263 + dentry = au_sio_lkup_one(h_idmap, &qs, &h_ppath);
35264 + if (IS_ERR(dentry) || d_is_negative(dentry))
35268 + /* pr_warn("could not get random name\n"); */
35269 + dentry = ERR_PTR(-EEXIST);
35270 + AuDbg("%.*s\n", AuLNPair(&qs));
35274 + if (name != defname)
35275 + au_kfree_try_rcu(name);
35277 + AuTraceErrPtr(dentry);
35282 + * rename the @h_dentry on @br to the whiteouted temporary name.
35284 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35287 + struct path h_path = {
35288 + .mnt = au_br_mnt(br)
35290 + struct inode *h_dir, *delegated;
35291 + struct dentry *h_parent;
35293 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35294 + h_dir = d_inode(h_parent);
35295 + IMustLock(h_dir);
35297 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35298 + err = PTR_ERR(h_path.dentry);
35299 + if (IS_ERR(h_path.dentry))
35302 + /* under the same dir, no need to lock_rename() */
35303 + delegated = NULL;
35304 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35307 + if (unlikely(err == -EWOULDBLOCK)) {
35308 + pr_warn("cannot retry for NFSv4 delegation"
35309 + " for an internal rename\n");
35312 + dput(h_path.dentry);
35319 +/* ---------------------------------------------------------------------- */
35321 + * functions for removing a whiteout
35324 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35327 + struct inode *delegated;
35330 + * forces superio when the dir has a sticky bit.
35331 + * this may be a violation of unix fs semantics.
35333 + force = (h_dir->i_mode & S_ISVTX)
35334 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35335 + delegated = NULL;
35336 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35337 + if (unlikely(err == -EWOULDBLOCK)) {
35338 + pr_warn("cannot retry for NFSv4 delegation"
35339 + " for an internal unlink\n");
35345 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35346 + struct dentry *dentry)
35350 + err = do_unlink_wh(h_dir, h_path);
35351 + if (!err && dentry)
35352 + au_set_dbwh(dentry, -1);
35357 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35360 + struct path h_path;
35363 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35364 + if (IS_ERR(h_path.dentry))
35365 + err = PTR_ERR(h_path.dentry);
35367 + if (d_is_reg(h_path.dentry)) {
35368 + h_path.mnt = h_ppath->mnt;
35369 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35371 + dput(h_path.dentry);
35377 +/* ---------------------------------------------------------------------- */
35379 + * initialize/clean whiteout for a branch
35382 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35386 + struct inode *delegated;
35388 + if (d_is_negative(whpath->dentry))
35392 + err = vfsub_rmdir(h_dir, whpath);
35394 + delegated = NULL;
35395 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35396 + if (unlikely(err == -EWOULDBLOCK)) {
35397 + pr_warn("cannot retry for NFSv4 delegation"
35398 + " for an internal unlink\n");
35402 + if (unlikely(err))
35403 + pr_warn("failed removing %pd (%d), ignored.\n",
35404 + whpath->dentry, err);
35407 +static int test_linkable(struct dentry *h_root)
35409 + struct inode *h_dir = d_inode(h_root);
35411 + if (h_dir->i_op->link)
35414 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35415 + h_root, au_sbtype(h_root->d_sb));
35416 + return -ENOSYS; /* the branch doesn't have its ->link() */
35419 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35420 +static int au_whdir(struct inode *h_dir, struct path *path)
35425 + if (d_is_negative(path->dentry)) {
35428 + if (au_test_nfs(path->dentry->d_sb))
35430 + err = vfsub_mkdir(h_dir, path, mode);
35431 + } else if (d_is_dir(path->dentry))
35434 + pr_err("unknown %pd exists\n", path->dentry);
35439 +struct au_wh_base {
35440 + const struct qstr *name;
35441 + struct dentry *dentry;
35444 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35445 + struct path *h_path)
35447 + h_path->dentry = base[AuBrWh_BASE].dentry;
35448 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35449 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35450 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35451 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35452 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35456 + * returns tri-state,
35457 + * minus: error, caller should print the message
35459 + * plus: error, caller should NOT print the message
35461 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35462 + int do_plink, struct au_wh_base base[],
35463 + struct path *h_path)
35466 + struct inode *h_dir;
35468 + h_dir = d_inode(h_root);
35469 + h_path->dentry = base[AuBrWh_BASE].dentry;
35470 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35471 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35473 + err = test_linkable(h_root);
35474 + if (unlikely(err)) {
35479 + err = au_whdir(h_dir, h_path);
35480 + if (unlikely(err))
35482 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35484 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35485 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35486 + err = au_whdir(h_dir, h_path);
35487 + if (unlikely(err))
35489 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35496 + * for the moment, aufs supports the branch filesystem which does not support
35497 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35498 + * copyup failed. finally, such filesystem will not be used as the writable
35501 + * returns tri-state, see above.
35503 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35504 + int do_plink, struct au_wh_base base[],
35505 + struct path *h_path)
35508 + struct inode *h_dir;
35510 + WbrWhMustWriteLock(wbr);
35512 + err = test_linkable(h_root);
35513 + if (unlikely(err)) {
35519 + * todo: should this create be done in /sbin/mount.aufs helper?
35522 + h_dir = d_inode(h_root);
35523 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35524 + h_path->dentry = base[AuBrWh_BASE].dentry;
35525 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35526 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35529 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35530 + if (unlikely(err))
35533 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35535 + err = au_whdir(h_dir, h_path);
35536 + if (unlikely(err))
35538 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35540 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35541 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35543 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35544 + err = au_whdir(h_dir, h_path);
35545 + if (unlikely(err))
35547 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35554 + * initialize the whiteout base file/dir for @br.
35556 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35559 + const unsigned char do_plink
35560 + = !!au_opt_test(au_mntflags(sb), PLINK);
35561 + struct inode *h_dir;
35562 + struct path path = br->br_path;
35563 + struct dentry *h_root = path.dentry;
35564 + struct au_wbr *wbr = br->br_wbr;
35565 + static const struct qstr base_name[] = {
35566 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35567 + sizeof(AUFS_BASE_NAME) - 1),
35568 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35569 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35570 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35571 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35573 + struct au_wh_base base[] = {
35574 + [AuBrWh_BASE] = {
35575 + .name = base_name + AuBrWh_BASE,
35578 + [AuBrWh_PLINK] = {
35579 + .name = base_name + AuBrWh_PLINK,
35582 + [AuBrWh_ORPH] = {
35583 + .name = base_name + AuBrWh_ORPH,
35589 + WbrWhMustWriteLock(wbr);
35591 + for (i = 0; i < AuBrWh_Last; i++) {
35592 + /* doubly whiteouted */
35593 + struct dentry *d;
35595 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35596 + err = PTR_ERR(d);
35600 + base[i].dentry = d;
35602 + && wbr->wbr_wh[i]
35603 + && wbr->wbr_wh[i] != base[i].dentry);
35607 + for (i = 0; i < AuBrWh_Last; i++) {
35608 + dput(wbr->wbr_wh[i]);
35609 + wbr->wbr_wh[i] = NULL;
35613 + if (!au_br_writable(br->br_perm)) {
35614 + h_dir = d_inode(h_root);
35615 + au_wh_init_ro(h_dir, base, &path);
35616 + } else if (!au_br_wh_linkable(br->br_perm)) {
35617 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35623 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35629 + goto out; /* success */
35632 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35633 + err, h_root, au_sbtype(h_root->d_sb));
35635 + for (i = 0; i < AuBrWh_Last; i++)
35636 + dput(base[i].dentry);
35640 +/* ---------------------------------------------------------------------- */
35642 + * whiteouts are all hard-linked usually.
35643 + * when its link count reaches a ceiling, we create a new whiteout base
35644 + * asynchronously.
35647 +struct reinit_br_wh {
35648 + struct super_block *sb;
35649 + struct au_branch *br;
35652 +static void reinit_br_wh(void *arg)
35655 + aufs_bindex_t bindex;
35656 + struct path h_path;
35657 + struct reinit_br_wh *a = arg;
35658 + struct au_wbr *wbr;
35659 + struct inode *dir, *delegated;
35660 + struct dentry *h_root;
35661 + struct au_hinode *hdir;
35664 + wbr = a->br->br_wbr;
35665 + /* big aufs lock */
35666 + si_noflush_write_lock(a->sb);
35667 + if (!au_br_writable(a->br->br_perm))
35669 + bindex = au_br_index(a->sb, a->br->br_id);
35670 + if (unlikely(bindex < 0))
35673 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35674 + dir = d_inode(a->sb->s_root);
35675 + hdir = au_hi(dir, bindex);
35676 + h_root = au_h_dptr(a->sb->s_root, bindex);
35677 + AuDebugOn(h_root != au_br_dentry(a->br));
35679 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35680 + wbr_wh_write_lock(wbr);
35681 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35684 + h_path.dentry = wbr->wbr_whbase;
35685 + h_path.mnt = au_br_mnt(a->br);
35686 + delegated = NULL;
35687 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35689 + if (unlikely(err == -EWOULDBLOCK)) {
35690 + pr_warn("cannot retry for NFSv4 delegation"
35691 + " for an internal unlink\n");
35695 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35698 + dput(wbr->wbr_whbase);
35699 + wbr->wbr_whbase = NULL;
35701 + err = au_wh_init(a->br, a->sb);
35702 + wbr_wh_write_unlock(wbr);
35703 + au_hn_inode_unlock(hdir);
35704 + di_read_unlock(a->sb->s_root, AuLock_IR);
35706 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35710 + atomic_dec(&wbr->wbr_wh_running);
35711 + au_lcnt_dec(&a->br->br_count);
35712 + si_write_unlock(a->sb);
35713 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35715 + if (unlikely(err))
35716 + AuIOErr("err %d\n", err);
35719 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35721 + int do_dec, wkq_err;
35722 + struct reinit_br_wh *arg;
35725 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35728 + /* ignore ENOMEM */
35729 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35732 + * dec(wh_running), kfree(arg) and dec(br_count)
35733 + * in reinit function
35737 + au_lcnt_inc(&br->br_count);
35738 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35739 + if (unlikely(wkq_err)) {
35740 + atomic_dec(&br->br_wbr->wbr_wh_running);
35741 + au_lcnt_dec(&br->br_count);
35742 + au_kfree_rcu(arg);
35749 + atomic_dec(&br->br_wbr->wbr_wh_running);
35752 +/* ---------------------------------------------------------------------- */
35755 + * create the whiteout @wh.
35757 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35758 + struct dentry *wh)
35761 + struct path h_path = {
35764 + struct au_branch *br;
35765 + struct au_wbr *wbr;
35766 + struct dentry *h_parent;
35767 + struct inode *h_dir, *delegated;
35769 + h_parent = wh->d_parent; /* dir inode is locked */
35770 + h_dir = d_inode(h_parent);
35771 + IMustLock(h_dir);
35773 + br = au_sbr(sb, bindex);
35774 + h_path.mnt = au_br_mnt(br);
35775 + wbr = br->br_wbr;
35776 + wbr_wh_read_lock(wbr);
35777 + if (wbr->wbr_whbase) {
35778 + delegated = NULL;
35779 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35780 + if (unlikely(err == -EWOULDBLOCK)) {
35781 + pr_warn("cannot retry for NFSv4 delegation"
35782 + " for an internal link\n");
35785 + if (!err || err != -EMLINK)
35788 + /* link count full. re-initialize br_whbase. */
35789 + kick_reinit_br_wh(sb, br);
35792 + /* return this error in this context */
35793 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35795 + au_fhsm_wrote(sb, bindex, /*force*/0);
35798 + wbr_wh_read_unlock(wbr);
35802 +/* ---------------------------------------------------------------------- */
35805 + * create or remove the diropq.
35807 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35808 + unsigned int flags)
35810 + struct dentry *opq_dentry;
35811 + struct super_block *sb;
35812 + struct au_branch *br;
35813 + struct path h_path;
35816 + sb = dentry->d_sb;
35817 + br = au_sbr(sb, bindex);
35818 + h_path.dentry = au_h_dptr(dentry, bindex);
35819 + h_path.mnt = au_br_mnt(br);
35820 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35821 + if (IS_ERR(opq_dentry))
35824 + if (au_ftest_diropq(flags, CREATE)) {
35825 + err = link_or_create_wh(sb, bindex, opq_dentry);
35827 + au_set_dbdiropq(dentry, bindex);
35828 + goto out; /* success */
35831 + h_path.dentry = opq_dentry;
35832 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35834 + au_set_dbdiropq(dentry, -1);
35836 + dput(opq_dentry);
35837 + opq_dentry = ERR_PTR(err);
35840 + return opq_dentry;
35843 +struct do_diropq_args {
35844 + struct dentry **errp;
35845 + struct dentry *dentry;
35846 + aufs_bindex_t bindex;
35847 + unsigned int flags;
35850 +static void call_do_diropq(void *args)
35852 + struct do_diropq_args *a = args;
35853 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35856 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35857 + unsigned int flags)
35859 + struct dentry *diropq, *h_dentry;
35860 + struct mnt_idmap *h_idmap;
35862 + h_idmap = au_sbr_idmap(dentry->d_sb, bindex);
35863 + h_dentry = au_h_dptr(dentry, bindex);
35864 + if (!au_test_h_perm_sio(h_idmap, d_inode(h_dentry),
35865 + MAY_EXEC | MAY_WRITE))
35866 + diropq = do_diropq(dentry, bindex, flags);
35869 + struct do_diropq_args args = {
35871 + .dentry = dentry,
35872 + .bindex = bindex,
35876 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35877 + if (unlikely(wkq_err))
35878 + diropq = ERR_PTR(wkq_err);
35884 +/* ---------------------------------------------------------------------- */
35887 + * lookup whiteout dentry.
35888 + * @h_parent: lower parent dentry which must exist and be locked
35889 + * @base_name: name of dentry which will be whiteouted
35890 + * returns dentry for whiteout.
35892 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35893 + struct au_branch *br)
35896 + struct qstr wh_name;
35897 + struct dentry *wh_dentry;
35898 + struct path h_path;
35900 + err = au_wh_name_alloc(&wh_name, base_name);
35901 + wh_dentry = ERR_PTR(err);
35903 + h_path.dentry = h_parent;
35904 + h_path.mnt = au_br_mnt(br);
35905 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35906 + au_kfree_try_rcu(wh_name.name);
35908 + return wh_dentry;
35912 + * link/create a whiteout for @dentry on @bindex.
35914 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35915 + struct dentry *h_parent)
35917 + struct dentry *wh_dentry;
35918 + struct super_block *sb;
35921 + sb = dentry->d_sb;
35922 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35923 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35924 + err = link_or_create_wh(sb, bindex, wh_dentry);
35926 + au_set_dbwh(dentry, bindex);
35927 + au_fhsm_wrote(sb, bindex, /*force*/0);
35930 + wh_dentry = ERR_PTR(err);
35934 + return wh_dentry;
35937 +/* ---------------------------------------------------------------------- */
35939 +/* Delete all whiteouts in this directory on branch bindex. */
35940 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35941 + aufs_bindex_t bindex)
35944 + unsigned long ul, n;
35945 + struct qstr wh_name;
35947 + struct hlist_head *head;
35948 + struct au_vdir_wh *pos;
35949 + struct au_vdir_destr *str;
35952 + p = (void *)__get_free_page(GFP_NOFS);
35953 + wh_name.name = p;
35954 + if (unlikely(!wh_name.name))
35958 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35959 + p += AUFS_WH_PFX_LEN;
35960 + n = whlist->nh_num;
35961 + head = whlist->nh_head;
35962 + for (ul = 0; !err && ul < n; ul++, head++) {
35963 + hlist_for_each_entry(pos, head, wh_hash) {
35964 + if (pos->wh_bindex != bindex)
35967 + str = &pos->wh_str;
35968 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35969 + memcpy(p, str->name, str->len);
35970 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35971 + err = unlink_wh_name(h_path, &wh_name);
35976 + AuIOErr("whiteout name too long %.*s\n",
35977 + str->len, str->name);
35982 + free_page((unsigned long)wh_name.name);
35988 +struct del_wh_children_args {
35990 + struct path *h_path;
35991 + struct au_nhash *whlist;
35992 + aufs_bindex_t bindex;
35995 +static void call_del_wh_children(void *args)
35997 + struct del_wh_children_args *a = args;
35998 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
36001 +/* ---------------------------------------------------------------------- */
36003 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
36005 + struct au_whtmp_rmdir *whtmp;
36007 + unsigned int rdhash;
36009 + SiMustAnyLock(sb);
36011 + whtmp = kzalloc(sizeof(*whtmp), gfp);
36012 + if (unlikely(!whtmp)) {
36013 + whtmp = ERR_PTR(-ENOMEM);
36017 + /* no estimation for dir size */
36018 + rdhash = au_sbi(sb)->si_rdhash;
36020 + rdhash = AUFS_RDHASH_DEF;
36021 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
36022 + if (unlikely(err)) {
36023 + au_kfree_rcu(whtmp);
36024 + whtmp = ERR_PTR(err);
36031 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36034 + au_lcnt_dec(&whtmp->br->br_count);
36035 + dput(whtmp->wh_dentry);
36036 + iput(whtmp->dir);
36037 + au_nhash_wh_free(&whtmp->whlist);
36038 + au_kfree_rcu(whtmp);
36042 + * rmdir the whiteouted temporary named dir @h_dentry.
36043 + * @whlist: whiteouted children.
36045 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36046 + struct dentry *wh_dentry, struct au_nhash *whlist)
36049 + unsigned int h_nlink;
36050 + struct path wh_path;
36051 + struct inode *wh_inode, *h_dir;
36052 + struct au_branch *br;
36053 + struct mnt_idmap *h_idmap;
36055 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36056 + IMustLock(h_dir);
36058 + br = au_sbr(dir->i_sb, bindex);
36059 + wh_path.dentry = wh_dentry;
36060 + wh_path.mnt = au_br_mnt(br);
36061 + h_idmap = au_br_idmap(br);
36062 + wh_inode = d_inode(wh_dentry);
36063 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36066 + * someone else might change some whiteouts while we were sleeping.
36067 + * it means this whlist may have an obsoleted entry.
36069 + if (!au_test_h_perm_sio(h_idmap, wh_inode, MAY_EXEC | MAY_WRITE))
36070 + err = del_wh_children(&wh_path, whlist, bindex);
36073 + struct del_wh_children_args args = {
36075 + .h_path = &wh_path,
36076 + .whlist = whlist,
36080 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36081 + if (unlikely(wkq_err))
36084 + inode_unlock(wh_inode);
36087 + h_nlink = h_dir->i_nlink;
36088 + err = vfsub_rmdir(h_dir, &wh_path);
36089 + /* some fs doesn't change the parent nlink in some cases */
36090 + h_nlink -= h_dir->i_nlink;
36094 + if (au_ibtop(dir) == bindex) {
36095 + /* todo: dir->i_mutex is necessary */
36096 + au_cpup_attr_timesizes(dir);
36098 + vfsub_drop_nlink(dir);
36100 + return 0; /* success */
36103 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36107 +static void call_rmdir_whtmp(void *args)
36110 + aufs_bindex_t bindex;
36111 + struct au_whtmp_rmdir *a = args;
36112 + struct super_block *sb;
36113 + struct dentry *h_parent;
36114 + struct inode *h_dir;
36115 + struct au_hinode *hdir;
36117 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36118 + /* inode_lock(a->dir); */
36120 + sb = a->dir->i_sb;
36121 + si_read_lock(sb, !AuLock_FLUSH);
36122 + if (!au_br_writable(a->br->br_perm))
36124 + bindex = au_br_index(sb, a->br->br_id);
36125 + if (unlikely(bindex < 0))
36129 + ii_write_lock_parent(a->dir);
36130 + h_parent = dget_parent(a->wh_dentry);
36131 + h_dir = d_inode(h_parent);
36132 + hdir = au_hi(a->dir, bindex);
36133 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36134 + if (unlikely(err))
36136 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36137 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36140 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36141 + au_hn_inode_unlock(hdir);
36142 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36146 + ii_write_unlock(a->dir);
36148 + /* inode_unlock(a->dir); */
36149 + au_whtmp_rmdir_free(a);
36150 + si_read_unlock(sb);
36151 + au_nwt_done(&au_sbi(sb)->si_nowait);
36152 + if (unlikely(err))
36153 + AuIOErr("err %d\n", err);
36156 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36157 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36160 + struct super_block *sb;
36164 + /* all post-process will be done in do_rmdir_whtmp(). */
36166 + args->dir = au_igrab(dir);
36167 + args->br = au_sbr(sb, bindex);
36168 + au_lcnt_inc(&args->br->br_count);
36169 + args->wh_dentry = dget(wh_dentry);
36170 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36171 + if (unlikely(wkq_err)) {
36172 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36173 + au_whtmp_rmdir_free(args);
36176 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36177 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36178 +++ linux/fs/aufs/whout.h 2023-08-28 12:34:39.999969465 +0200
36180 +/* SPDX-License-Identifier: GPL-2.0 */
36182 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36184 + * This program is free software; you can redistribute it and/or modify
36185 + * it under the terms of the GNU General Public License as published by
36186 + * the Free Software Foundation; either version 2 of the License, or
36187 + * (at your option) any later version.
36189 + * This program is distributed in the hope that it will be useful,
36190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36192 + * GNU General Public License for more details.
36194 + * You should have received a copy of the GNU General Public License
36195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36199 + * whiteout for logical deletion and opaque directory
36202 +#ifndef __AUFS_WHOUT_H__
36203 +#define __AUFS_WHOUT_H__
36210 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36211 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
36212 + struct qstr *wh_name, int try_sio);
36213 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path);
36215 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36216 + struct qstr *prefix);
36217 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36218 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36219 + struct dentry *dentry);
36220 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36222 +/* diropq flags */
36223 +#define AuDiropq_CREATE 1
36224 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36225 +#define au_fset_diropq(flags, name) \
36226 + do { (flags) |= AuDiropq_##name; } while (0)
36227 +#define au_fclr_diropq(flags, name) \
36228 + do { (flags) &= ~AuDiropq_##name; } while (0)
36230 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36231 + unsigned int flags);
36232 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36233 + struct au_branch *br);
36234 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36235 + struct dentry *h_parent);
36237 +/* real rmdir for the whiteout-ed dir */
36238 +struct au_whtmp_rmdir {
36239 + struct inode *dir;
36240 + struct au_branch *br;
36241 + struct dentry *wh_dentry;
36242 + struct au_nhash whlist;
36245 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36246 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36247 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36248 + struct dentry *wh_dentry, struct au_nhash *whlist);
36249 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36250 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36252 +/* ---------------------------------------------------------------------- */
36254 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36255 + aufs_bindex_t bindex)
36257 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36260 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36262 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36265 +#endif /* __KERNEL__ */
36266 +#endif /* __AUFS_WHOUT_H__ */
36267 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36268 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36269 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36271 +// SPDX-License-Identifier: GPL-2.0
36273 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36275 + * This program is free software; you can redistribute it and/or modify
36276 + * it under the terms of the GNU General Public License as published by
36277 + * the Free Software Foundation; either version 2 of the License, or
36278 + * (at your option) any later version.
36280 + * This program is distributed in the hope that it will be useful,
36281 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36282 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36283 + * GNU General Public License for more details.
36285 + * You should have received a copy of the GNU General Public License
36286 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36290 + * workqueue for asynchronous/super-io operations
36291 + * todo: try new credential scheme
36294 +#include <linux/module.h>
36297 +/* internal workqueue named AUFS_WKQ_NAME */
36299 +static struct workqueue_struct *au_wkq;
36301 +struct au_wkinfo {
36302 + struct work_struct wk;
36303 + struct kobject *kobj;
36305 + unsigned int flags; /* see wkq.h */
36307 + au_wkq_func_t func;
36310 +#ifdef CONFIG_LOCKDEP
36312 + struct held_lock **hlock;
36315 + struct completion *comp;
36318 +/* ---------------------------------------------------------------------- */
36320 + * Aufs passes some operations to the workqueue such as the internal copyup.
36321 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36322 + * job run by workqueue depends upon the locks acquired in the other task.
36323 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36324 + * information too. And the job in the workqueue restores the info in order to
36325 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36326 + * correctly and expectedly.
36329 +#ifndef CONFIG_LOCKDEP
36330 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36331 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36332 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36333 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36334 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36336 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36338 + wkinfo->hlock = NULL;
36339 + wkinfo->dont_check = 0;
36346 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36348 + static DEFINE_SPINLOCK(spin);
36351 + struct lock_class_key *key;
36353 + { .name = "&sbinfo->si_rwsem" },
36354 + { .name = "&finfo->fi_rwsem" },
36355 + { .name = "&dinfo->di_rwsem" },
36356 + { .name = "&iinfo->ii_rwsem" }
36361 + /* lockless read from 'set.' see below */
36362 + if (set == ARRAY_SIZE(a)) {
36363 + for (i = 0; i < ARRAY_SIZE(a); i++)
36364 + if (a[i].key == key)
36369 + spin_lock(&spin);
36371 + for (i = 0; i < ARRAY_SIZE(a); i++)
36372 + if (a[i].key == key) {
36373 + spin_unlock(&spin);
36376 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36378 + if (unlikely(a[i].key == key)) { /* rare but possible */
36379 + spin_unlock(&spin);
36384 + if (strstr(a[i].name, name)) {
36386 + * the order of these three lines is important for the
36387 + * lockless read above.
36390 + spin_unlock(&spin);
36392 + /* AuDbg("%d, %s\n", set, name); */
36396 + spin_unlock(&spin);
36405 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36408 + struct task_struct *curr;
36409 + struct held_lock **hl, *held_locks, *p;
36413 + wkinfo->dont_check = lockdep_recursing(curr);
36414 + if (wkinfo->dont_check)
36416 + n = curr->lockdep_depth;
36421 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36422 + if (unlikely(!wkinfo->hlock))
36426 +#if 0 /* left for debugging */
36427 + if (0 && au_debug_test())
36428 + lockdep_print_held_locks(curr);
36430 + held_locks = curr->held_locks;
36431 + hl = wkinfo->hlock;
36433 + p = held_locks++;
36434 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36443 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36445 + au_kfree_try_rcu(wkinfo->hlock);
36448 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36450 + struct held_lock *p, **hl = wkinfo->hlock;
36453 + if (wkinfo->dont_check)
36457 + while ((p = *hl++)) { /* assignment */
36458 + subclass = lockdep_hlock_class(p)->subclass;
36459 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36461 + rwsem_acquire_read(p->instance, subclass, 0,
36462 + /*p->acquire_ip*/_RET_IP_);
36464 + rwsem_acquire(p->instance, subclass, 0,
36465 + /*p->acquire_ip*/_RET_IP_);
36469 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36471 + struct held_lock *p, **hl = wkinfo->hlock;
36473 + if (wkinfo->dont_check)
36477 + while ((p = *hl++)) /* assignment */
36478 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36482 +static void wkq_func(struct work_struct *wk)
36484 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36486 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36487 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36489 + au_wkq_lockdep_pre(wkinfo);
36490 + wkinfo->func(wkinfo->args);
36491 + au_wkq_lockdep_post(wkinfo);
36492 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36493 + complete(wkinfo->comp);
36495 + kobject_put(wkinfo->kobj);
36496 + module_put(THIS_MODULE); /* todo: ?? */
36497 + au_kfree_rcu(wkinfo);
36502 + * Since struct completion is large, try allocating it dynamically.
36504 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36506 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36508 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36510 + init_completion(*comp);
36511 + wkinfo->comp = *comp;
36517 +static void au_wkq_comp_free(struct completion *comp)
36519 + au_kfree_rcu(comp);
36522 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36524 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36525 + if (au_wkq_test()) {
36526 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36527 + " due to a dead dir by UDBA,"
36528 + " or async xino write?\n");
36529 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36532 + au_dbg_verify_kthread();
36534 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36535 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36536 + queue_work(au_wkq, &wkinfo->wk);
36538 + INIT_WORK(&wkinfo->wk, wkq_func);
36539 + schedule_work(&wkinfo->wk);
36544 + * Be careful. It is easy to make deadlock happen.
36545 + * processA: lock, wkq and wait
36546 + * processB: wkq and wait, lock in wkq
36549 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36552 + AuWkqCompDeclare(comp);
36553 + struct au_wkinfo wkinfo = {
36559 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36560 + if (unlikely(err))
36562 + err = au_wkq_lockdep_alloc(&wkinfo);
36563 + if (unlikely(err))
36566 + au_wkq_run(&wkinfo);
36567 + /* no timeout, no interrupt */
36568 + wait_for_completion(wkinfo.comp);
36570 + au_wkq_lockdep_free(&wkinfo);
36573 + au_wkq_comp_free(comp);
36575 + destroy_work_on_stack(&wkinfo.wk);
36580 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36581 + * problem in a concurrent umounting.
36583 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36584 + unsigned int flags)
36587 + struct au_wkinfo *wkinfo;
36589 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36592 + * wkq_func() must free this wkinfo.
36593 + * it highly depends upon the implementation of workqueue.
36596 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36598 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36599 + wkinfo->flags = flags & ~AuWkq_WAIT;
36600 + wkinfo->func = func;
36601 + wkinfo->args = args;
36602 + wkinfo->comp = NULL;
36603 + au_wkq_lockdep_init(wkinfo);
36604 + kobject_get(wkinfo->kobj);
36605 + __module_get(THIS_MODULE); /* todo: ?? */
36607 + au_wkq_run(wkinfo);
36610 + au_nwt_done(&au_sbi(sb)->si_nowait);
36616 +/* ---------------------------------------------------------------------- */
36618 +void au_nwt_init(struct au_nowait_tasks *nwt)
36620 + atomic_set(&nwt->nw_len, 0);
36621 + /* smp_mb(); */ /* atomic_set */
36622 + init_waitqueue_head(&nwt->nw_wq);
36625 +void au_wkq_fin(void)
36627 + destroy_workqueue(au_wkq);
36630 +int __init au_wkq_init(void)
36635 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36636 + if (IS_ERR(au_wkq))
36637 + err = PTR_ERR(au_wkq);
36638 + else if (!au_wkq)
36643 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36644 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36645 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36647 +/* SPDX-License-Identifier: GPL-2.0 */
36649 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36651 + * This program is free software; you can redistribute it and/or modify
36652 + * it under the terms of the GNU General Public License as published by
36653 + * the Free Software Foundation; either version 2 of the License, or
36654 + * (at your option) any later version.
36656 + * This program is distributed in the hope that it will be useful,
36657 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36658 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36659 + * GNU General Public License for more details.
36661 + * You should have received a copy of the GNU General Public License
36662 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36666 + * workqueue for asynchronous/super-io operations
36667 + * todo: try new credentials management scheme
36670 +#ifndef __AUFS_WKQ_H__
36671 +#define __AUFS_WKQ_H__
36675 +#include <linux/wait.h>
36677 +struct super_block;
36679 +/* ---------------------------------------------------------------------- */
36682 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36684 +struct au_nowait_tasks {
36686 + wait_queue_head_t nw_wq;
36689 +/* ---------------------------------------------------------------------- */
36691 +typedef void (*au_wkq_func_t)(void *args);
36694 +#define AuWkq_WAIT 1
36695 +#define AuWkq_NEST (1 << 1)
36696 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36697 +#define au_fset_wkq(flags, name) \
36698 + do { (flags) |= AuWkq_##name; } while (0)
36699 +#define au_fclr_wkq(flags, name) \
36700 + do { (flags) &= ~AuWkq_##name; } while (0)
36703 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36704 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36705 + unsigned int flags);
36706 +void au_nwt_init(struct au_nowait_tasks *nwt);
36707 +int __init au_wkq_init(void);
36708 +void au_wkq_fin(void);
36710 +/* ---------------------------------------------------------------------- */
36712 +static inline int au_wkq_test(void)
36714 + return current->flags & PF_WQ_WORKER;
36717 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36719 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36722 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36724 + if (atomic_dec_and_test(&nwt->nw_len))
36725 + wake_up_all(&nwt->nw_wq);
36728 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36730 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36734 +#endif /* __KERNEL__ */
36735 +#endif /* __AUFS_WKQ_H__ */
36736 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36737 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36738 +++ linux/fs/aufs/xattr.c 2023-08-28 12:34:39.999969465 +0200
36740 +// SPDX-License-Identifier: GPL-2.0
36742 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36744 + * This program is free software; you can redistribute it and/or modify
36745 + * it under the terms of the GNU General Public License as published by
36746 + * the Free Software Foundation; either version 2 of the License, or
36747 + * (at your option) any later version.
36749 + * This program is distributed in the hope that it will be useful,
36750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36752 + * GNU General Public License for more details.
36754 + * You should have received a copy of the GNU General Public License
36755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36759 + * handling xattr functions
36762 +#include <linux/fs.h>
36763 +#include <linux/xattr.h>
36766 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36768 + if (!ignore_flags)
36776 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36781 +#define cmp(brattr, prefix) do { \
36782 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36783 + XATTR_##prefix##_PREFIX_LEN)) { \
36784 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36790 + cmp(SEC, SECURITY);
36791 + cmp(SYS, SYSTEM);
36792 + cmp(TR, TRUSTED);
36796 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36803 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36805 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36806 + char *name, char **buf, unsigned int ignore_flags,
36807 + unsigned int verbose)
36811 + struct inode *h_idst;
36812 + struct dentry *h_dst_dentry, *h_src_dentry;
36813 + struct mnt_idmap *h_dst_idmap, *h_src_idmap;
36814 + struct posix_acl *acl;
36816 + is_acl = !!is_posix_acl_xattr(name);
36817 + h_src_idmap = mnt_idmap(h_src->mnt);
36818 + h_src_dentry = h_src->dentry;
36820 + acl = vfs_get_acl(h_src_idmap, h_src_dentry, name);
36822 + if (unlikely(IS_ERR(acl))) {
36823 + err = PTR_ERR(acl);
36824 + if (err == -ENODATA)
36826 + else if (err == -EOPNOTSUPP
36827 + && au_test_nfs_noacl(d_inode(h_src_dentry)))
36829 + else if (verbose || au_debug_test())
36830 + pr_err("%s, err %d\n", name, err);
36834 + ssz = vfs_getxattr_alloc(h_src_idmap, h_src_dentry, name, buf,
36836 + if (unlikely(ssz <= 0)) {
36838 + if (err == -ENODATA)
36840 + else if (err == -EOPNOTSUPP
36841 + && (ignore_flags & au_xattr_out_of_list))
36843 + else if (err && (verbose || au_debug_test()))
36844 + pr_err("%s, err %d\n", name, err);
36849 + /* unlock it temporary */
36850 + h_dst_idmap = mnt_idmap(h_dst->mnt);
36851 + h_dst_dentry = h_dst->dentry;
36852 + h_idst = d_inode(h_dst_dentry);
36853 + inode_unlock(h_idst);
36855 + err = vfsub_set_acl(h_dst_idmap, h_dst_dentry, name, acl);
36856 + posix_acl_release(acl);
36858 + err = vfsub_setxattr(h_dst_idmap, h_dst_dentry, name, *buf,
36859 + ssz, /*flags*/0);
36860 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36861 + if (unlikely(err)) {
36862 + if (verbose || au_debug_test())
36863 + pr_err("%s, err %d\n", name, err);
36864 + err = au_xattr_ignore(err, name, ignore_flags);
36871 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36872 + unsigned int verbose)
36874 + int err, unlocked;
36876 + struct dentry *h_dst_dentry, *h_src_dentry;
36877 + struct inode *h_isrc, *h_idst;
36878 + char *value, *p, *o, *e;
36880 + /* try stopping to update the source inode while we are referencing */
36881 + /* there should not be the parent-child relationship between them */
36882 + h_dst_dentry = h_dst->dentry;
36883 + h_idst = d_inode(h_dst_dentry);
36884 + h_src_dentry = h_src->dentry;
36885 + h_isrc = d_inode(h_src_dentry);
36886 + inode_unlock(h_idst);
36887 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36888 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36891 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36892 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36894 + if (unlikely(err < 0)) {
36896 + if (err == -ENODATA
36897 + || err == -EOPNOTSUPP)
36898 + err = 0; /* ignore */
36907 + p = kmalloc(ssz, GFP_NOFS);
36909 + if (unlikely(!p))
36911 + err = vfs_listxattr(h_src_dentry, p, ssz);
36913 + inode_unlock_shared(h_isrc);
36915 + AuDbg("err %d, ssz %zd\n", err, ssz);
36916 + if (unlikely(err < 0))
36922 + ignore_flags |= au_xattr_out_of_list;
36923 + while (!err && p < e) {
36924 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36926 + p += strlen(p) + 1;
36928 + au_kfree_try_rcu(value);
36931 + au_kfree_try_rcu(o);
36934 + inode_unlock_shared(h_isrc);
36939 +/* ---------------------------------------------------------------------- */
36941 +static int au_smack_reentering(struct super_block *sb)
36943 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36945 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36946 + * i_op->getxattr(). ouch.
36948 + return si_pid_test(sb);
36959 +struct au_lgxattr {
36967 + const char *name;
36974 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36975 + struct au_lgxattr *arg)
36979 + struct path h_path;
36980 + struct super_block *sb;
36982 + sb = dentry->d_sb;
36983 + reenter = au_smack_reentering(sb);
36985 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
36986 + if (unlikely(err))
36989 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
36990 + if (unlikely(err))
36992 + if (unlikely(!h_path.dentry))
36993 + /* illegally overlapped or something */
36994 + goto out_di; /* pretending success */
36996 + /* always topmost entry only */
36997 + switch (arg->type) {
36998 + case AU_XATTR_LIST:
36999 + err = vfs_listxattr(h_path.dentry,
37000 + arg->u.list.list, arg->u.list.size);
37002 + case AU_XATTR_GET:
37003 + AuDebugOn(d_is_negative(h_path.dentry));
37004 + err = vfs_getxattr(mnt_idmap(h_path.mnt), h_path.dentry,
37005 + arg->u.get.name, arg->u.get.value,
37006 + arg->u.get.size);
37012 + di_read_unlock(dentry, AuLock_IR);
37015 + si_read_unlock(sb);
37021 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37023 + struct au_lgxattr arg = {
37024 + .type = AU_XATTR_LIST,
37031 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37034 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37035 + const char *name, void *value, size_t size)
37037 + struct au_lgxattr arg = {
37038 + .type = AU_XATTR_GET,
37046 + return au_lgxattr(dentry, inode, &arg);
37049 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37050 + const char *name, const void *value, size_t size,
37053 + struct au_sxattr arg = {
37054 + .type = AU_XATTR_SET,
37063 + return au_sxattr(dentry, inode, &arg);
37066 +/* ---------------------------------------------------------------------- */
37068 +static int au_xattr_get(const struct xattr_handler *handler,
37069 + struct dentry *dentry, struct inode *inode,
37070 + const char *name, void *buffer, size_t size)
37072 + return au_getxattr(dentry, inode, name, buffer, size);
37075 +static int au_xattr_set(const struct xattr_handler *handler,
37076 + struct mnt_idmap *idmap,
37077 + struct dentry *dentry, struct inode *inode,
37078 + const char *name, const void *value, size_t size,
37081 + return au_setxattr(dentry, inode, name, value, size, flags);
37084 +static const struct xattr_handler au_xattr_handler = {
37087 + .get = au_xattr_get,
37088 + .set = au_xattr_set
37091 +static const struct xattr_handler *au_xattr_handlers[] = {
37092 + &au_xattr_handler, /* must be last */
37096 +void au_xattr_init(struct super_block *sb)
37098 + sb->s_xattr = au_xattr_handlers;
37100 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37101 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37102 +++ linux/fs/aufs/xino.c 2023-08-28 12:34:39.999969465 +0200
37104 +// SPDX-License-Identifier: GPL-2.0
37106 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37108 + * This program is free software; you can redistribute it and/or modify
37109 + * it under the terms of the GNU General Public License as published by
37110 + * the Free Software Foundation; either version 2 of the License, or
37111 + * (at your option) any later version.
37113 + * This program is distributed in the hope that it will be useful,
37114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37116 + * GNU General Public License for more details.
37118 + * You should have received a copy of the GNU General Public License
37119 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37123 + * external inode number translation table and bitmap
37125 + * things to consider
37127 + * + au_xino object
37128 + * + XINO files (xino, xib, xigen)
37129 + * + dynamic debugfs entries (xiN)
37130 + * + static debugfs entries (xib, xigen)
37131 + * + static sysfs entry (xi_path)
37132 + * - several entry points to handle them.
37133 + * + mount(2) without xino option (default)
37134 + * + mount(2) with xino option
37135 + * + mount(2) with noxino option
37137 + * + remount with add/del branches
37138 + * + remount with xino/noxino options
37141 +#include <linux/seq_file.h>
37142 +#include <linux/statfs.h>
37145 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37146 + aufs_bindex_t bbot,
37147 + struct super_block *h_sb)
37149 + /* todo: try binary-search if the branches are many */
37150 + for (; btop <= bbot; btop++)
37151 + if (h_sb == au_sbr_sb(sb, btop))
37157 + * find another branch who is on the same filesystem of the specified
37158 + * branch{@btgt}. search until @bbot.
37160 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37161 + aufs_bindex_t bbot)
37163 + aufs_bindex_t bindex;
37164 + struct super_block *tgt_sb;
37166 + tgt_sb = au_sbr_sb(sb, btgt);
37167 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37169 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37174 +/* ---------------------------------------------------------------------- */
37177 + * stop unnecessary notify events at creating xino files
37180 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37182 + aufs_bindex_t bfound, bindex, bbot;
37183 + struct dentry *parent;
37184 + struct au_branch *br;
37187 + parent = dentry->d_parent; /* safe d_parent access */
37188 + bbot = au_sbbot(sb);
37189 + for (bindex = 0; bindex <= bbot; bindex++) {
37190 + br = au_sbr(sb, bindex);
37191 + if (au_br_dentry(br) == parent) {
37197 + AuDbg("bfound b%d\n", bfound);
37201 +struct au_xino_lock_dir {
37202 + struct au_hinode *hdir;
37203 + struct dentry *parent;
37204 + struct inode *dir;
37207 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37208 + unsigned int lsc)
37210 + struct dentry *parent;
37211 + struct inode *dir;
37213 + parent = dget_parent(dentry);
37214 + dir = d_inode(parent);
37215 + inode_lock_nested(dir, lsc);
37216 +#if 0 /* it should not happen */
37217 + spin_lock(&dentry->d_lock);
37218 + if (unlikely(dentry->d_parent != parent)) {
37219 + spin_unlock(&dentry->d_lock);
37220 + inode_unlock(dir);
37225 + spin_unlock(&dentry->d_lock);
37232 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37233 + struct au_xino_lock_dir *ldir)
37235 + aufs_bindex_t bindex;
37237 + ldir->hdir = NULL;
37238 + bindex = au_xi_root(sb, xipath->dentry);
37239 + if (bindex >= 0) {
37240 + /* rw branch root */
37241 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37242 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37245 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37247 + ldir->dir = d_inode(ldir->parent);
37251 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37254 + au_hn_inode_unlock(ldir->hdir);
37256 + inode_unlock(ldir->dir);
37257 + dput(ldir->parent);
37261 +/* ---------------------------------------------------------------------- */
37264 + * create and set a new xino file
37266 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37269 + struct file *file;
37270 + struct dentry *h_parent, *d;
37271 + struct inode *h_dir, *inode;
37273 + static DEFINE_MUTEX(mtx);
37276 + * at mount-time, and the xino file is the default path,
37277 + * hnotify is disabled so we have no notify events to ignore.
37278 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37281 + mutex_lock(&mtx);
37282 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37283 + /* | __FMODE_NONOTIFY */,
37285 + if (IS_ERR(file)) {
37287 + mutex_unlock(&mtx);
37289 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37293 + /* keep file count */
37295 + d = file->f_path.dentry;
37296 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37298 + mutex_unlock(&mtx);
37299 + /* mnt_want_write() is unnecessary here */
37300 + h_dir = d_inode(h_parent);
37301 + inode = file_inode(file);
37302 + /* no delegation since it is just created */
37303 + if (inode->i_nlink)
37304 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37306 + inode_unlock(h_dir);
37308 + if (unlikely(err)) {
37310 + pr_err("unlink %s(%d)\n", fpath, err);
37315 + if (unlikely(sb && sb == d->d_sb)) {
37317 + pr_err("%s must be outside\n", fpath);
37320 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37322 + pr_err("xino doesn't support %s(%s)\n",
37323 + fpath, au_sbtype(d->d_sb));
37326 + return file; /* success */
37330 + file = ERR_PTR(err);
37335 + * create a new xinofile at the same place/path as @base.
37337 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37338 + struct file *copy_src)
37340 + struct file *file;
37341 + struct dentry *dentry;
37342 + struct inode *dir, *delegated;
37343 + struct qstr *name;
37344 + struct path ppath, path;
37345 + int err, do_unlock;
37346 + struct au_xino_lock_dir ldir;
37349 + au_xino_lock_dir(sb, base, &ldir);
37350 + dentry = base->dentry;
37351 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37352 + ppath.mnt = base->mnt;
37353 + dir = d_inode(ppath.dentry);
37356 + name = &dentry->d_name;
37357 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37358 + if (IS_ERR(path.dentry)) {
37359 + file = (void *)path.dentry;
37360 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37364 + /* no need to mnt_want_write() since we call dentry_open() later */
37365 + err = vfs_create(mnt_idmap(base->mnt), dir, path.dentry, 0666, NULL);
37366 + if (unlikely(err)) {
37367 + file = ERR_PTR(err);
37368 + pr_err("%pd create err %d\n", dentry, err);
37372 + path.mnt = base->mnt;
37373 + file = vfsub_dentry_open(&path,
37374 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37375 + /* | __FMODE_NONOTIFY */);
37376 + if (IS_ERR(file)) {
37377 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37381 + delegated = NULL;
37382 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37383 + au_xino_unlock_dir(&ldir);
37385 + if (unlikely(err == -EWOULDBLOCK)) {
37386 + pr_warn("cannot retry for NFSv4 delegation"
37387 + " for an internal unlink\n");
37390 + if (unlikely(err)) {
37391 + pr_err("%pd unlink err %d\n", dentry, err);
37396 + /* no one can touch copy_src xino */
37397 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37398 + if (unlikely(err)) {
37399 + pr_err("%pd copy err %d\n", dentry, err);
37403 + goto out_dput; /* success */
37407 + file = ERR_PTR(err);
37409 + dput(path.dentry);
37412 + au_xino_unlock_dir(&ldir);
37416 +struct file *au_xino_file1(struct au_xino *xi)
37418 + struct file *file;
37419 + unsigned int u, nfile;
37422 + nfile = xi->xi_nfile;
37423 + for (u = 0; u < nfile; u++) {
37424 + file = xi->xi_file[u];
37432 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37443 + if (idx < xi->xi_nfile) {
37444 + f = xi->xi_file[idx];
37448 + p = au_kzrealloc(xi->xi_file,
37449 + sizeof(*xi->xi_file) * xi->xi_nfile,
37450 + sizeof(*xi->xi_file) * (idx + 1),
37451 + GFP_NOFS, /*may_shrink*/0);
37453 + MtxMustLock(&xi->xi_mtx);
37455 + xi->xi_nfile = idx + 1;
37463 + xi->xi_file[idx] = file;
37470 + * if @xinew->xi is not set, then create new xigen file.
37472 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37474 + struct file *file;
37477 + SiMustAnyLock(sb);
37479 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37480 + if (IS_ERR(file)) {
37481 + err = PTR_ERR(file);
37482 + pr_err("%s[%d], err %d\n",
37483 + xinew->xi ? "xino" : "xigen",
37484 + xinew->idx, err);
37489 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37492 + /* todo: make xigen file an array */
37493 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37496 + if (unlikely(err))
37497 + file = ERR_PTR(err);
37503 +/* ---------------------------------------------------------------------- */
37506 + * truncate xino files
37508 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37509 + int idx, struct kstatfs *st)
37513 + struct file *file, *new_xino;
37514 + struct au_xi_new xinew = {
37519 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37520 + file = au_xino_file(xinew.xi, idx);
37524 + xinew.base = &file->f_path;
37525 + err = vfs_statfs(xinew.base, st);
37526 + if (unlikely(err)) {
37527 + AuErr1("statfs err %d, ignored\n", err);
37532 + blocks = file_inode(file)->i_blocks;
37533 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37534 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37536 + xinew.copy_src = file;
37537 + new_xino = au_xi_new(sb, &xinew);
37538 + if (IS_ERR(new_xino)) {
37539 + err = PTR_ERR(new_xino);
37540 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37544 + err = vfs_statfs(&new_xino->f_path, st);
37546 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37547 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37548 + st->f_bfree, st->f_blocks);
37550 + AuErr1("statfs err %d, ignored\n", err);
37558 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37561 + unsigned long jiffy;
37562 + aufs_bindex_t bbot;
37563 + struct kstatfs *st;
37564 + struct au_branch *br;
37565 + struct au_xino *xi;
37568 + st = kmalloc(sizeof(*st), GFP_NOFS);
37569 + if (unlikely(!st))
37573 + bbot = au_sbbot(sb);
37574 + if (unlikely(bindex < 0 || bbot < bindex))
37579 + br = au_sbr(sb, bindex);
37580 + xi = br->br_xino;
37581 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37582 + err = au_xino_do_trunc(sb, bindex, i, st);
37584 + au_sbi(sb)->si_xino_jiffy = jiffy;
37587 + au_kfree_rcu(st);
37592 +struct xino_do_trunc_args {
37593 + struct super_block *sb;
37594 + struct au_branch *br;
37598 +static void xino_do_trunc(void *_args)
37600 + struct xino_do_trunc_args *args = _args;
37601 + struct super_block *sb;
37602 + struct au_branch *br;
37603 + struct inode *dir;
37605 + aufs_bindex_t bindex;
37609 + dir = d_inode(sb->s_root);
37613 + si_noflush_write_lock(sb);
37614 + ii_read_lock_parent(dir);
37615 + bindex = au_br_index(sb, br->br_id);
37616 + err = au_xino_trunc(sb, bindex, idx);
37617 + ii_read_unlock(dir);
37618 + if (unlikely(err))
37619 + pr_warn("err b%d, (%d)\n", bindex, err);
37620 + atomic_dec(&br->br_xino->xi_truncating);
37621 + au_lcnt_dec(&br->br_count);
37622 + si_write_unlock(sb);
37623 + au_nwt_done(&au_sbi(sb)->si_nowait);
37624 + au_kfree_rcu(args);
37628 + * returns the index in the xi_file array whose corresponding file is necessary
37629 + * to truncate, or -1 which means no need to truncate.
37631 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37635 + struct kstatfs st;
37636 + struct au_sbinfo *sbinfo;
37637 + struct au_xino *xi;
37638 + struct file *file;
37640 + /* todo: si_xino_expire and the ratio should be customizable */
37641 + sbinfo = au_sbi(sb);
37642 + if (time_before(jiffies,
37643 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37646 + /* truncation border */
37647 + xi = br->br_xino;
37648 + for (u = 0; u < xi->xi_nfile; u++) {
37649 + file = au_xino_file(xi, u);
37653 + err = vfs_statfs(&file->f_path, &st);
37654 + if (unlikely(err)) {
37655 + AuErr1("statfs err %d, ignored\n", err);
37658 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37659 + >= AUFS_XINO_DEF_TRUNC)
37666 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37669 + struct xino_do_trunc_args *args;
37672 + idx = xino_trunc_test(sb, br);
37676 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37679 + /* lock and kfree() will be called in trunc_xino() */
37680 + args = kmalloc(sizeof(*args), GFP_NOFS);
37681 + if (unlikely(!args)) {
37682 + AuErr1("no memory\n");
37686 + au_lcnt_inc(&br->br_count);
37690 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37692 + return; /* success */
37694 + pr_err("wkq %d\n", wkq_err);
37695 + au_lcnt_dec(&br->br_count);
37696 + au_kfree_rcu(args);
37699 + atomic_dec(&br->br_xino->xi_truncating);
37702 +/* ---------------------------------------------------------------------- */
37704 +struct au_xi_calc {
37709 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37710 + struct au_xi_calc *calc)
37714 + maxent = au_xi_maxent(sb);
37715 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37716 + calc->pos *= sizeof(ino_t);
37719 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37720 + struct au_xi_calc *calc)
37723 + struct file *file;
37724 + struct au_xino *xi = br->br_xino;
37725 + struct au_xi_new xinew = {
37729 + SiMustAnyLock(sb);
37735 + mutex_lock(&xi->xi_mtx);
37736 + file = au_xino_file(xi, calc->idx);
37740 + file = au_xino_file(xi, /*idx*/-1);
37741 + AuDebugOn(!file);
37742 + xinew.idx = calc->idx;
37743 + xinew.base = &file->f_path;
37744 + /* xinew.copy_src = NULL; */
37745 + file = au_xi_new(sb, &xinew);
37746 + if (IS_ERR(file))
37747 + err = PTR_ERR(file);
37750 + mutex_unlock(&xi->xi_mtx);
37755 +struct au_xino_do_new_async_args {
37756 + struct super_block *sb;
37757 + struct au_branch *br;
37758 + struct au_xi_calc calc;
37762 +struct au_xi_writing {
37763 + struct hlist_bl_node node;
37764 + ino_t h_ino, ino;
37767 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37770 +static void au_xino_call_do_new_async(void *args)
37772 + struct au_xino_do_new_async_args *a = args;
37773 + struct au_branch *br;
37774 + struct super_block *sb;
37775 + struct au_sbinfo *sbi;
37776 + struct inode *root;
37777 + struct file *file;
37778 + struct au_xi_writing *del, *p;
37779 + struct hlist_bl_head *hbl;
37780 + struct hlist_bl_node *pos;
37785 + sbi = au_sbi(sb);
37786 + si_noflush_read_lock(sb);
37787 + root = d_inode(sb->s_root);
37788 + ii_read_lock_child(root);
37789 + err = au_xino_do_new_async(sb, br, &a->calc);
37790 + if (unlikely(err)) {
37791 + AuIOErr("err %d\n", err);
37795 + file = au_xino_file(br->br_xino, a->calc.idx);
37796 + AuDebugOn(!file);
37797 + err = au_xino_do_write(file, &a->calc, a->ino);
37798 + if (unlikely(err)) {
37799 + AuIOErr("err %d\n", err);
37804 + hbl = &br->br_xino->xi_writing;
37805 + hlist_bl_lock(hbl);
37806 + au_hbl_for_each(pos, hbl) {
37807 + p = container_of(pos, struct au_xi_writing, node);
37808 + if (p->ino == a->ino) {
37810 + hlist_bl_del(&p->node);
37814 + hlist_bl_unlock(hbl);
37815 + au_kfree_rcu(del);
37818 + au_lcnt_dec(&br->br_count);
37819 + ii_read_unlock(root);
37820 + si_read_unlock(sb);
37821 + au_nwt_done(&sbi->si_nowait);
37826 + * create a new xino file asynchronously
37828 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37829 + struct au_xi_calc *calc, ino_t ino)
37832 + struct au_xino_do_new_async_args *arg;
37835 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37836 + if (unlikely(!arg))
37841 + arg->calc = *calc;
37843 + au_lcnt_inc(&br->br_count);
37844 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37845 + if (unlikely(err)) {
37846 + pr_err("wkq %d\n", err);
37847 + au_lcnt_dec(&br->br_count);
37848 + au_kfree_rcu(arg);
37856 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37857 + * at the position of @h_ino.
37859 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37864 + struct au_xi_calc calc;
37865 + struct au_sbinfo *sbinfo;
37866 + struct file *file;
37867 + struct au_xino *xi;
37868 + struct hlist_bl_head *hbl;
37869 + struct hlist_bl_node *pos;
37870 + struct au_xi_writing *p;
37873 + if (!au_opt_test(au_mntflags(sb), XINO))
37874 + return 0; /* no xino */
37877 + au_xi_calc(sb, h_ino, &calc);
37878 + xi = au_sbr(sb, bindex)->br_xino;
37879 + file = au_xino_file(xi, calc.idx);
37881 + hbl = &xi->xi_writing;
37882 + hlist_bl_lock(hbl);
37883 + au_hbl_for_each(pos, hbl) {
37884 + p = container_of(pos, struct au_xi_writing, node);
37885 + if (p->h_ino == h_ino) {
37886 + AuDbg("hi%llu, i%llu, found\n",
37887 + (u64)p->h_ino, (u64)p->ino);
37892 + hlist_bl_unlock(hbl);
37894 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37895 + return 0; /* no xino */
37897 + sbinfo = au_sbi(sb);
37898 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37899 + if (sz == sizeof(*ino))
37900 + return 0; /* success */
37903 + if (unlikely(sz >= 0)) {
37905 + AuIOErr("xino read error (%zd)\n", sz);
37910 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37915 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37916 + if (sz == sizeof(ino))
37917 + return 0; /* success */
37919 + AuIOErr("write failed (%zd)\n", sz);
37924 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37925 + * at the position of @h_ino.
37926 + * even if @ino is zero, it is written to the xinofile and means no entry.
37927 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37928 + * try truncating it.
37930 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37934 + unsigned int mnt_flags;
37935 + struct au_xi_calc calc;
37936 + struct file *file;
37937 + struct au_branch *br;
37938 + struct au_xino *xi;
37939 + struct au_xi_writing *p;
37941 + SiMustAnyLock(sb);
37943 + mnt_flags = au_mntflags(sb);
37944 + if (!au_opt_test(mnt_flags, XINO))
37947 + au_xi_calc(sb, h_ino, &calc);
37948 + br = au_sbr(sb, bindex);
37949 + xi = br->br_xino;
37950 + file = au_xino_file(xi, calc.idx);
37952 + /* store the inum pair into the list */
37953 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37954 + p->h_ino = h_ino;
37956 + au_hbl_add(&p->node, &xi->xi_writing);
37958 + /* create and write a new xino file asynchronously */
37959 + err = au_xino_new_async(sb, br, &calc, ino);
37961 + return 0; /* success */
37965 + err = au_xino_do_write(file, &calc, ino);
37967 + br = au_sbr(sb, bindex);
37968 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37969 + && au_test_fs_trunc_xino(au_br_sb(br)))
37970 + xino_try_trunc(sb, br);
37971 + return 0; /* success */
37975 + AuIOErr("write failed (%d)\n", err);
37979 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
37982 +/* todo: unnecessary to support mmap_sem since kernel-space? */
37983 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
37987 + const int prevent_endless = 10;
37991 + err = vfsub_read_k(file, kbuf, size, pos);
37992 + if (err == -EINTR
37993 + && !au_wkq_test()
37994 + && fatal_signal_pending(current)) {
37995 + err = xino_fread_wkq(file, kbuf, size, pos);
37996 + BUG_ON(err == -EINTR);
37998 + } while (i++ < prevent_endless
37999 + && (err == -EAGAIN || err == -EINTR));
38001 +#if 0 /* reserved for future use */
38003 + fsnotify_access(file->f_path.dentry);
38009 +struct xino_fread_args {
38011 + struct file *file;
38017 +static void call_xino_fread(void *args)
38019 + struct xino_fread_args *a = args;
38020 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38023 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38028 + struct xino_fread_args args = {
38036 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38037 + if (unlikely(wkq_err))
38043 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38046 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38051 + const int prevent_endless = 10;
38055 + err = vfsub_write_k(file, kbuf, size, pos);
38056 + if (err == -EINTR
38057 + && !au_wkq_test()
38058 + && fatal_signal_pending(current)) {
38059 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38060 + BUG_ON(err == -EINTR);
38062 + } while (i++ < prevent_endless
38063 + && (err == -EAGAIN || err == -EINTR));
38065 +#if 0 /* reserved for future use */
38067 + fsnotify_modify(file->f_path.dentry);
38073 +struct do_xino_fwrite_args {
38075 + struct file *file;
38081 +static void call_do_xino_fwrite(void *args)
38083 + struct do_xino_fwrite_args *a = args;
38084 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38087 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38092 + struct do_xino_fwrite_args args = {
38101 + * it breaks RLIMIT_FSIZE and normal user's limit,
38102 + * users should care about quota and real 'filesystem full.'
38104 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38105 + if (unlikely(wkq_err))
38111 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38115 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38117 + err = do_xino_fwrite(file, buf, size, pos);
38121 + err = xino_fwrite_wkq(file, buf, size, pos);
38128 +/* ---------------------------------------------------------------------- */
38131 + * inode number bitmap
38133 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38134 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38138 + AuDebugOn(bit < 0 || page_bits <= bit);
38139 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38143 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38145 + AuDebugOn(ino < AUFS_FIRST_INO);
38146 + ino -= AUFS_FIRST_INO;
38147 + *pindex = ino / page_bits;
38148 + *bit = ino % page_bits;
38151 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38156 + struct au_sbinfo *sbinfo;
38157 + struct file *xib;
38158 + unsigned long *p;
38160 + sbinfo = au_sbi(sb);
38161 + MtxMustLock(&sbinfo->si_xib_mtx);
38162 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38163 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38165 + if (pindex == sbinfo->si_xib_last_pindex)
38168 + xib = sbinfo->si_xib;
38169 + p = sbinfo->si_xib_buf;
38170 + pos = sbinfo->si_xib_last_pindex;
38171 + pos *= PAGE_SIZE;
38172 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38173 + if (unlikely(sz != PAGE_SIZE))
38177 + pos *= PAGE_SIZE;
38178 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38179 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38181 + memset(p, 0, PAGE_SIZE);
38182 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38184 + if (sz == PAGE_SIZE) {
38185 + sbinfo->si_xib_last_pindex = pindex;
38186 + return 0; /* success */
38190 + AuIOErr1("write failed (%zd)\n", sz);
38197 +static void au_xib_clear_bit(struct inode *inode)
38200 + unsigned long pindex;
38201 + struct super_block *sb;
38202 + struct au_sbinfo *sbinfo;
38204 + AuDebugOn(inode->i_nlink);
38206 + sb = inode->i_sb;
38207 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38208 + AuDebugOn(page_bits <= bit);
38209 + sbinfo = au_sbi(sb);
38210 + mutex_lock(&sbinfo->si_xib_mtx);
38211 + err = xib_pindex(sb, pindex);
38213 + clear_bit(bit, sbinfo->si_xib_buf);
38214 + sbinfo->si_xib_next_bit = bit;
38216 + mutex_unlock(&sbinfo->si_xib_mtx);
38219 +/* ---------------------------------------------------------------------- */
38222 + * truncate a xino bitmap file
38226 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38230 + unsigned long pindex;
38231 + loff_t pos, pend;
38232 + struct au_sbinfo *sbinfo;
38234 + unsigned long *p;
38237 + sbinfo = au_sbi(sb);
38238 + MtxMustLock(&sbinfo->si_xib_mtx);
38239 + p = sbinfo->si_xib_buf;
38240 + pend = vfsub_f_size_read(file);
38242 + while (pos < pend) {
38243 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38245 + if (unlikely(sz <= 0))
38249 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38250 + if (unlikely(*ino < AUFS_FIRST_INO))
38253 + xib_calc_bit(*ino, &pindex, &bit);
38254 + AuDebugOn(page_bits <= bit);
38255 + err = xib_pindex(sb, pindex);
38267 +static int xib_restore(struct super_block *sb)
38270 + unsigned int nfile;
38271 + aufs_bindex_t bindex, bbot;
38273 + struct au_branch *br;
38274 + struct au_xino *xi;
38275 + struct file *file;
38278 + page = (void *)__get_free_page(GFP_NOFS);
38279 + if (unlikely(!page))
38283 + bbot = au_sbbot(sb);
38284 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38285 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38286 + br = au_sbr(sb, bindex);
38287 + xi = br->br_xino;
38288 + nfile = xi->xi_nfile;
38289 + for (i = 0; i < nfile; i++) {
38290 + file = au_xino_file(xi, i);
38292 + err = do_xib_restore(sb, file, page);
38295 + AuDbg("skip shared b%d\n", bindex);
38296 + free_page((unsigned long)page);
38302 +int au_xib_trunc(struct super_block *sb)
38307 + struct au_sbinfo *sbinfo;
38308 + unsigned long *p;
38309 + struct file *file;
38311 + SiMustWriteLock(sb);
38314 + sbinfo = au_sbi(sb);
38315 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38318 + file = sbinfo->si_xib;
38319 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38322 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38323 + err = PTR_ERR(file);
38324 + if (IS_ERR(file))
38326 + fput(sbinfo->si_xib);
38327 + sbinfo->si_xib = file;
38329 + p = sbinfo->si_xib_buf;
38330 + memset(p, 0, PAGE_SIZE);
38332 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38333 + if (unlikely(sz != PAGE_SIZE)) {
38335 + AuIOErr("err %d\n", err);
38341 + mutex_lock(&sbinfo->si_xib_mtx);
38342 + /* mnt_want_write() is unnecessary here */
38343 + err = xib_restore(sb);
38344 + mutex_unlock(&sbinfo->si_xib_mtx);
38350 +/* ---------------------------------------------------------------------- */
38352 +struct au_xino *au_xino_alloc(unsigned int nfile)
38354 + struct au_xino *xi;
38356 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38357 + if (unlikely(!xi))
38359 + xi->xi_nfile = nfile;
38360 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38361 + if (unlikely(!xi->xi_file))
38364 + xi->xi_nondir.total = 8; /* initial size */
38365 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38367 + if (unlikely(!xi->xi_nondir.array))
38370 + spin_lock_init(&xi->xi_nondir.spin);
38371 + init_waitqueue_head(&xi->xi_nondir.wqh);
38372 + mutex_init(&xi->xi_mtx);
38373 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38374 + atomic_set(&xi->xi_truncating, 0);
38375 + kref_init(&xi->xi_kref);
38376 + goto out; /* success */
38379 + au_kfree_try_rcu(xi->xi_file);
38381 + au_kfree_rcu(xi);
38387 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38390 + struct au_xino *xi;
38393 + xi = au_xino_alloc(idx + 1);
38394 + if (unlikely(!xi)) {
38401 + xi->xi_file[idx] = file;
38402 + AuDebugOn(br->br_xino);
38403 + br->br_xino = xi;
38409 +static void au_xino_release(struct kref *kref)
38411 + struct au_xino *xi;
38413 + unsigned long ul;
38414 + struct hlist_bl_head *hbl;
38415 + struct hlist_bl_node *pos, *n;
38416 + struct au_xi_writing *p;
38418 + xi = container_of(kref, struct au_xino, xi_kref);
38419 + for (i = 0; i < xi->xi_nfile; i++)
38420 + if (xi->xi_file[i])
38421 + fput(xi->xi_file[i]);
38422 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38423 + AuDebugOn(xi->xi_nondir.array[i]);
38424 + mutex_destroy(&xi->xi_mtx);
38425 + hbl = &xi->xi_writing;
38426 + ul = au_hbl_count(hbl);
38427 + if (unlikely(ul)) {
38428 + pr_warn("xi_writing %lu\n", ul);
38429 + hlist_bl_lock(hbl);
38430 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38431 + hlist_bl_del(&p->node);
38432 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38435 + hlist_bl_unlock(hbl);
38437 + au_kfree_try_rcu(xi->xi_file);
38438 + au_kfree_try_rcu(xi->xi_nondir.array);
38439 + au_kfree_rcu(xi);
38442 +int au_xino_put(struct au_branch *br)
38445 + struct au_xino *xi;
38448 + xi = br->br_xino;
38450 + br->br_xino = NULL;
38451 + ret = kref_put(&xi->xi_kref, au_xino_release);
38457 +/* ---------------------------------------------------------------------- */
38460 + * xino mount option handlers
38464 +static void xino_clear_xib(struct super_block *sb)
38466 + struct au_sbinfo *sbinfo;
38468 + SiMustWriteLock(sb);
38470 + sbinfo = au_sbi(sb);
38471 + if (sbinfo->si_xib)
38472 + fput(sbinfo->si_xib);
38473 + sbinfo->si_xib = NULL;
38474 + if (sbinfo->si_xib_buf)
38475 + free_page((unsigned long)sbinfo->si_xib_buf);
38476 + sbinfo->si_xib_buf = NULL;
38479 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38483 + struct au_sbinfo *sbinfo;
38484 + struct file *file;
38485 + struct super_block *xi_sb;
38487 + SiMustWriteLock(sb);
38489 + sbinfo = au_sbi(sb);
38490 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38491 + err = PTR_ERR(file);
38492 + if (IS_ERR(file))
38494 + if (sbinfo->si_xib)
38495 + fput(sbinfo->si_xib);
38496 + sbinfo->si_xib = file;
38497 + xi_sb = file_inode(file)->i_sb;
38498 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38499 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38501 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38502 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38505 + sbinfo->si_ximaxent /= sizeof(ino_t);
38508 + if (!sbinfo->si_xib_buf)
38509 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38510 + if (unlikely(!sbinfo->si_xib_buf))
38513 + sbinfo->si_xib_last_pindex = 0;
38514 + sbinfo->si_xib_next_bit = 0;
38515 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38517 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38518 + if (unlikely(err != PAGE_SIZE))
38522 + goto out; /* success */
38525 + if (sbinfo->si_xib_buf)
38526 + free_page((unsigned long)sbinfo->si_xib_buf);
38527 + sbinfo->si_xib_buf = NULL;
38531 + fput(sbinfo->si_xib);
38532 + sbinfo->si_xib = NULL;
38538 +/* xino for each branch */
38539 +static void xino_clear_br(struct super_block *sb)
38541 + aufs_bindex_t bindex, bbot;
38542 + struct au_branch *br;
38544 + bbot = au_sbbot(sb);
38545 + for (bindex = 0; bindex <= bbot; bindex++) {
38546 + br = au_sbr(sb, bindex);
38552 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38553 + aufs_bindex_t bshared)
38555 + struct au_branch *brshared;
38557 + brshared = au_sbr(sb, bshared);
38558 + AuDebugOn(!brshared->br_xino);
38559 + AuDebugOn(!brshared->br_xino->xi_file);
38560 + if (br->br_xino != brshared->br_xino) {
38561 + au_xino_get(brshared);
38563 + br->br_xino = brshared->br_xino;
38567 +struct au_xino_do_set_br {
38568 + struct au_branch *br;
38570 + aufs_bindex_t bshared;
38573 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38574 + struct au_xino_do_set_br *args)
38577 + struct au_xi_calc calc;
38578 + struct file *file;
38579 + struct au_branch *br;
38580 + struct au_xi_new xinew = {
38585 + xinew.xi = br->br_xino;
38586 + au_xi_calc(sb, args->h_ino, &calc);
38587 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38588 + if (args->bshared >= 0)
38589 + /* shared xino */
38590 + au_xino_set_br_shared(sb, br, args->bshared);
38591 + else if (!xinew.xi) {
38593 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38594 + if (unlikely(err))
38598 + /* force re-creating */
38599 + xinew.xi = br->br_xino;
38600 + xinew.idx = calc.idx;
38601 + mutex_lock(&xinew.xi->xi_mtx);
38602 + file = au_xi_new(sb, &xinew);
38603 + mutex_unlock(&xinew.xi->xi_mtx);
38604 + err = PTR_ERR(file);
38605 + if (IS_ERR(file))
38607 + AuDebugOn(!file);
38609 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38610 + if (unlikely(err))
38618 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38621 + aufs_bindex_t bindex, bbot;
38622 + struct au_xino_do_set_br args;
38623 + struct inode *inode;
38625 + SiMustWriteLock(sb);
38627 + bbot = au_sbbot(sb);
38628 + inode = d_inode(sb->s_root);
38629 + for (bindex = 0; bindex <= bbot; bindex++) {
38630 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38631 + args.br = au_sbr(sb, bindex);
38632 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38633 + err = au_xino_do_set_br(sb, path, &args);
38634 + if (unlikely(err))
38642 +void au_xino_clr(struct super_block *sb)
38644 + struct au_sbinfo *sbinfo;
38646 + au_xigen_clr(sb);
38647 + xino_clear_xib(sb);
38648 + xino_clear_br(sb);
38649 + dbgaufs_brs_del(sb, 0);
38650 + sbinfo = au_sbi(sb);
38651 + /* lvalue, do not call au_mntflags() */
38652 + au_opt_clr(sbinfo->si_mntflags, XINO);
38655 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38658 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38659 + struct qstr *dname, *cur_name;
38660 + struct file *cur_xino;
38661 + struct au_sbinfo *sbinfo;
38662 + struct path *path, *cur_path;
38664 + SiMustWriteLock(sb);
38667 + sbinfo = au_sbi(sb);
38668 + path = &xiopt->file->f_path;
38669 + dentry = path->dentry;
38670 + parent = dget_parent(dentry);
38673 + cur_xino = sbinfo->si_xib;
38675 + cur_path = &cur_xino->f_path;
38676 + cur_dentry = cur_path->dentry;
38677 + cur_parent = dget_parent(cur_dentry);
38678 + cur_name = &cur_dentry->d_name;
38679 + dname = &dentry->d_name;
38680 + skip = (cur_parent == parent
38681 + && au_qstreq(dname, cur_name));
38682 + dput(cur_parent);
38688 + au_opt_set(sbinfo->si_mntflags, XINO);
38689 + err = au_xino_set_xib(sb, path);
38690 + /* si_x{read,write} are set */
38692 + err = au_xigen_set(sb, path);
38694 + err = au_xino_set_br(sb, path);
38696 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38697 + goto out; /* success */
38701 + AuIOErr("failed setting xino(%d).\n", err);
38710 + * create a xinofile at the default place/path.
38712 +struct file *au_xino_def(struct super_block *sb)
38714 + struct file *file;
38716 + struct au_branch *br;
38717 + struct super_block *h_sb;
38718 + struct path path;
38719 + aufs_bindex_t bbot, bindex, bwr;
38722 + bbot = au_sbbot(sb);
38724 + for (bindex = 0; bindex <= bbot; bindex++) {
38725 + br = au_sbr(sb, bindex);
38726 + if (au_br_writable(br->br_perm)
38727 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38734 + file = ERR_PTR(-ENOMEM);
38735 + page = (void *)__get_free_page(GFP_NOFS);
38736 + if (unlikely(!page))
38738 + path.mnt = au_br_mnt(br);
38739 + path.dentry = au_h_dptr(sb->s_root, bwr);
38740 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38741 + file = (void *)p;
38742 + if (!IS_ERR(p)) {
38743 + strcat(p, "/" AUFS_XINO_FNAME);
38744 + AuDbg("%s\n", p);
38745 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38747 + free_page((unsigned long)page);
38749 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38751 + if (IS_ERR(file))
38753 + h_sb = file->f_path.dentry->d_sb;
38754 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38755 + pr_err("xino doesn't support %s(%s)\n",
38756 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38758 + file = ERR_PTR(-EINVAL);
38766 +/* ---------------------------------------------------------------------- */
38769 + * initialize the xinofile for the specified branch @br
38770 + * at the place/path where @base_file indicates.
38771 + * test whether another branch is on the same filesystem or not,
38772 + * if found then share the xinofile with another branch.
38774 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38775 + struct path *base)
38778 + struct au_xino_do_set_br args = {
38783 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38785 + err = au_xino_do_set_br(sb, base, &args);
38786 + if (unlikely(err))
38792 +/* ---------------------------------------------------------------------- */
38795 + * get an unused inode number from bitmap
38797 +ino_t au_xino_new_ino(struct super_block *sb)
38800 + unsigned long *p, pindex, ul, pend;
38801 + struct au_sbinfo *sbinfo;
38802 + struct file *file;
38803 + int free_bit, err;
38805 + if (!au_opt_test(au_mntflags(sb), XINO))
38806 + return iunique(sb, AUFS_FIRST_INO);
38808 + sbinfo = au_sbi(sb);
38809 + mutex_lock(&sbinfo->si_xib_mtx);
38810 + p = sbinfo->si_xib_buf;
38811 + free_bit = sbinfo->si_xib_next_bit;
38812 + if (free_bit < page_bits && !test_bit(free_bit, p))
38813 + goto out; /* success */
38814 + free_bit = find_first_zero_bit(p, page_bits);
38815 + if (free_bit < page_bits)
38816 + goto out; /* success */
38818 + pindex = sbinfo->si_xib_last_pindex;
38819 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38820 + err = xib_pindex(sb, ul);
38821 + if (unlikely(err))
38823 + free_bit = find_first_zero_bit(p, page_bits);
38824 + if (free_bit < page_bits)
38825 + goto out; /* success */
38828 + file = sbinfo->si_xib;
38829 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38830 + for (ul = pindex + 1; ul <= pend; ul++) {
38831 + err = xib_pindex(sb, ul);
38832 + if (unlikely(err))
38834 + free_bit = find_first_zero_bit(p, page_bits);
38835 + if (free_bit < page_bits)
38836 + goto out; /* success */
38841 + set_bit(free_bit, p);
38842 + sbinfo->si_xib_next_bit = free_bit + 1;
38843 + pindex = sbinfo->si_xib_last_pindex;
38844 + mutex_unlock(&sbinfo->si_xib_mtx);
38845 + ino = xib_calc_ino(pindex, free_bit);
38846 + AuDbg("i%lu\n", (unsigned long)ino);
38849 + mutex_unlock(&sbinfo->si_xib_mtx);
38854 +/* for s_op->delete_inode() */
38855 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38858 + unsigned int mnt_flags;
38859 + aufs_bindex_t bindex, bbot, bi;
38860 + unsigned char try_trunc;
38861 + struct au_iinfo *iinfo;
38862 + struct super_block *sb;
38863 + struct au_hinode *hi;
38864 + struct inode *h_inode;
38865 + struct au_branch *br;
38866 + struct au_xi_calc calc;
38867 + struct file *file;
38869 + AuDebugOn(au_is_bad_inode(inode));
38871 + sb = inode->i_sb;
38872 + mnt_flags = au_mntflags(sb);
38873 + if (!au_opt_test(mnt_flags, XINO)
38874 + || inode->i_ino == AUFS_ROOT_INO)
38878 + au_xigen_inc(inode);
38879 + au_xib_clear_bit(inode);
38882 + iinfo = au_ii(inode);
38883 + bindex = iinfo->ii_btop;
38887 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38888 + hi = au_hinode(iinfo, bindex);
38889 + bbot = iinfo->ii_bbot;
38890 + for (; bindex <= bbot; bindex++, hi++) {
38891 + h_inode = hi->hi_inode;
38893 + || (!unlinked && h_inode->i_nlink))
38896 + /* inode may not be revalidated */
38897 + bi = au_br_index(sb, hi->hi_id);
38901 + br = au_sbr(sb, bi);
38902 + au_xi_calc(sb, h_inode->i_ino, &calc);
38903 + file = au_xino_file(br->br_xino, calc.idx);
38904 + if (IS_ERR_OR_NULL(file))
38907 + err = au_xino_do_write(file, &calc, /*ino*/0);
38908 + if (!err && try_trunc
38909 + && au_test_fs_trunc_xino(au_br_sb(br)))
38910 + xino_try_trunc(sb, br);
38914 +/* ---------------------------------------------------------------------- */
38916 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38918 + int found, total, i;
38921 + total = xi->xi_nondir.total;
38922 + for (i = 0; i < total; i++) {
38923 + if (xi->xi_nondir.array[i] != h_ino)
38932 +static int au_xinondir_expand(struct au_xino *xi)
38937 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38940 + sz = xi->xi_nondir.total * sizeof(ino_t);
38941 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38943 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38944 + /*may_shrink*/0);
38946 + xi->xi_nondir.array = p;
38947 + xi->xi_nondir.total <<= 1;
38948 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38956 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38957 + ino_t h_ino, int idx)
38959 + struct au_xino *xi;
38961 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38962 + xi = au_sbr(sb, bindex)->br_xino;
38963 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38965 + spin_lock(&xi->xi_nondir.spin);
38966 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38967 + xi->xi_nondir.array[idx] = 0;
38968 + spin_unlock(&xi->xi_nondir.spin);
38969 + wake_up_all(&xi->xi_nondir.wqh);
38972 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38975 + int err, found, empty;
38976 + struct au_xino *xi;
38980 + if (!au_opt_test(au_mntflags(sb), XINO))
38981 + goto out; /* no xino */
38983 + xi = au_sbr(sb, bindex)->br_xino;
38986 + spin_lock(&xi->xi_nondir.spin);
38987 + found = au_xinondir_find(xi, h_ino);
38988 + if (found == -1) {
38989 + empty = au_xinondir_find(xi, /*h_ino*/0);
38990 + if (empty == -1) {
38991 + empty = xi->xi_nondir.total;
38992 + err = au_xinondir_expand(xi);
38993 + if (unlikely(err))
38996 + xi->xi_nondir.array[empty] = h_ino;
38999 + spin_unlock(&xi->xi_nondir.spin);
39000 + wait_event(xi->xi_nondir.wqh,
39001 + xi->xi_nondir.array[found] != h_ino);
39006 + spin_unlock(&xi->xi_nondir.spin);
39011 +/* ---------------------------------------------------------------------- */
39013 +int au_xino_path(struct seq_file *seq, struct file *file)
39017 + err = au_seq_path(seq, &file->f_path);
39018 + if (unlikely(err))
39021 +#define Deleted "\\040(deleted)"
39022 + seq->count -= sizeof(Deleted) - 1;
39023 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39024 + sizeof(Deleted) - 1));
39030 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39031 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39032 +++ linux/include/uapi/linux/aufs_type.h 2023-08-28 12:34:41.669969465 +0200
39034 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39036 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39038 + * This program is free software; you can redistribute it and/or modify
39039 + * it under the terms of the GNU General Public License as published by
39040 + * the Free Software Foundation; either version 2 of the License, or
39041 + * (at your option) any later version.
39043 + * This program is distributed in the hope that it will be useful,
39044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39046 + * GNU General Public License for more details.
39048 + * You should have received a copy of the GNU General Public License
39049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39052 +#ifndef __AUFS_TYPE_H__
39053 +#define __AUFS_TYPE_H__
39055 +#define AUFS_NAME "aufs"
39059 + * define it before including all other headers.
39060 + * sched.h may use pr_* macros before defining "current", so define the
39061 + * no-current version first, and re-define later.
39063 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39064 +#include <linux/sched.h>
39066 +#define pr_fmt(fmt) \
39067 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39068 + (int)sizeof(current->comm), current->comm, current->pid
39069 +#include <linux/limits.h>
39071 +#include <stdint.h>
39072 +#include <sys/types.h>
39073 +#include <limits.h>
39074 +#endif /* __KERNEL__ */
39076 +#define AUFS_VERSION "6.x-rcN-20230828"
39078 +/* todo? move this to linux-2.6.19/include/magic.h */
39079 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39081 +/* ---------------------------------------------------------------------- */
39084 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39085 +typedef int8_t aufs_bindex_t;
39086 +#define AUFS_BRANCH_MAX 127
39088 +typedef int16_t aufs_bindex_t;
39089 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39090 +#define AUFS_BRANCH_MAX 511
39091 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39092 +#define AUFS_BRANCH_MAX 1023
39093 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39094 +#define AUFS_BRANCH_MAX 32767
39098 +#ifndef AUFS_BRANCH_MAX
39099 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39101 +#endif /* __KERNEL__ */
39103 +/* ---------------------------------------------------------------------- */
39105 +#define AUFS_FSTYPE AUFS_NAME
39107 +#define AUFS_ROOT_INO 2
39108 +#define AUFS_FIRST_INO 11
39110 +#define AUFS_WH_PFX ".wh."
39111 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39112 +#define AUFS_WH_TMP_LEN 4
39113 +/* a limit for rmdir/rename a dir and copyup */
39114 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39115 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39117 + - AUFS_WH_TMP_LEN) /* hex */
39118 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39119 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39120 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39121 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39122 +#define AUFS_DIRWH_DEF 3
39123 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39124 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39125 +#define AUFS_RDBLK_DEF 512 /* bytes */
39126 +#define AUFS_RDHASH_DEF 32
39127 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39128 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39129 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39130 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39131 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39133 +/* pseudo-link maintenace under /proc */
39134 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39135 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39136 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39138 +/* dirren, renamed dir */
39139 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39140 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39141 +/* whiteouted doubly */
39142 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39143 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39145 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39146 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39148 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39149 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39150 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39152 +/* doubly whiteouted */
39153 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39154 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39155 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39157 +/* branch permissions and attributes */
39158 +#define AUFS_BRPERM_RW "rw"
39159 +#define AUFS_BRPERM_RO "ro"
39160 +#define AUFS_BRPERM_RR "rr"
39161 +#define AUFS_BRATTR_COO_REG "coo_reg"
39162 +#define AUFS_BRATTR_COO_ALL "coo_all"
39163 +#define AUFS_BRATTR_FHSM "fhsm"
39164 +#define AUFS_BRATTR_UNPIN "unpin"
39165 +#define AUFS_BRATTR_ICEX "icex"
39166 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39167 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39168 +#define AUFS_BRATTR_ICEX_TR "icextr"
39169 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39170 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39171 +#define AUFS_BRRATTR_WH "wh"
39172 +#define AUFS_BRWATTR_NLWH "nolwh"
39173 +#define AUFS_BRWATTR_MOO "moo"
39175 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39176 +#define AuBrPerm_RO (1 << 1) /* readonly */
39177 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39178 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39180 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39181 +#define AuBrAttr_COO_ALL (1 << 4)
39182 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39184 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39185 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39186 + branch. meaningless since
39187 + linux-3.18-rc1 */
39189 +/* ignore error in copying XATTR */
39190 +#define AuBrAttr_ICEX_SEC (1 << 7)
39191 +#define AuBrAttr_ICEX_SYS (1 << 8)
39192 +#define AuBrAttr_ICEX_TR (1 << 9)
39193 +#define AuBrAttr_ICEX_USR (1 << 10)
39194 +#define AuBrAttr_ICEX_OTH (1 << 11)
39195 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39196 + | AuBrAttr_ICEX_SYS \
39197 + | AuBrAttr_ICEX_TR \
39198 + | AuBrAttr_ICEX_USR \
39199 + | AuBrAttr_ICEX_OTH)
39201 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39202 +#define AuBrRAttr_Mask AuBrRAttr_WH
39204 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39205 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39206 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39208 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39210 +/* #warning test userspace */
39212 +#ifndef CONFIG_AUFS_FHSM
39213 +#undef AuBrAttr_FHSM
39214 +#define AuBrAttr_FHSM 0
39216 +#ifndef CONFIG_AUFS_XATTR
39217 +#undef AuBrAttr_ICEX
39218 +#define AuBrAttr_ICEX 0
39219 +#undef AuBrAttr_ICEX_SEC
39220 +#define AuBrAttr_ICEX_SEC 0
39221 +#undef AuBrAttr_ICEX_SYS
39222 +#define AuBrAttr_ICEX_SYS 0
39223 +#undef AuBrAttr_ICEX_TR
39224 +#define AuBrAttr_ICEX_TR 0
39225 +#undef AuBrAttr_ICEX_USR
39226 +#define AuBrAttr_ICEX_USR 0
39227 +#undef AuBrAttr_ICEX_OTH
39228 +#define AuBrAttr_ICEX_OTH 0
39232 +/* the longest combination */
39233 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39234 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39235 + "+" AUFS_BRATTR_COO_REG \
39236 + "+" AUFS_BRATTR_FHSM \
39237 + "+" AUFS_BRATTR_UNPIN \
39238 + "+" AUFS_BRATTR_ICEX_SEC \
39239 + "+" AUFS_BRATTR_ICEX_SYS \
39240 + "+" AUFS_BRATTR_ICEX_USR \
39241 + "+" AUFS_BRATTR_ICEX_OTH \
39242 + "+" AUFS_BRWATTR_NLWH)
39245 + char a[AuBrPermStrSz];
39246 +} au_br_perm_str_t;
39248 +static inline int au_br_writable(int brperm)
39250 + return brperm & AuBrPerm_RW;
39253 +static inline int au_br_whable(int brperm)
39255 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39258 +static inline int au_br_wh_linkable(int brperm)
39260 + return !(brperm & AuBrWAttr_NoLinkWH);
39263 +static inline int au_br_cmoo(int brperm)
39265 + return brperm & AuBrAttr_CMOO_Mask;
39268 +static inline int au_br_fhsm(int brperm)
39270 + return brperm & AuBrAttr_FHSM;
39273 +/* ---------------------------------------------------------------------- */
39277 + /* readdir in userspace */
39281 + AuCtl_WBR_FD, /* pathconf wrapper */
39282 + AuCtl_IBUSY, /* busy inode */
39283 + AuCtl_MVDOWN, /* move-down */
39284 + AuCtl_BR, /* info about branches */
39285 + AuCtl_FHSM_FD /* connection for fhsm */
39288 +/* borrowed from linux/include/linux/kernel.h */
39290 +#ifdef _GNU_SOURCE
39291 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39293 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39295 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39298 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39300 +#define __aligned(x) __attribute__((aligned(x)))
39305 +#define __packed __attribute__((packed))
39309 +struct au_rdu_cookie {
39314 + uint32_t generation;
39317 +struct au_rdu_ent {
39326 +static inline int au_rdu_len(int nlen)
39328 + /* include the terminating NULL */
39329 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39330 + sizeof(uint64_t));
39333 +union au_rdu_ent_ul {
39334 + struct au_rdu_ent __user *e;
39346 + uint64_t sz; /* AuCtl_RDU */
39347 + uint64_t nent; /* AuCtl_RDU_INO */
39349 + union au_rdu_ent_ul ent;
39350 + uint16_t verify[AufsCtlRduV_End];
39352 + /* input/output */
39356 + union au_rdu_ent_ul tail;
39357 + /* number of entries which were added in a single call */
39362 + struct au_rdu_cookie cookie;
39365 +/* ---------------------------------------------------------------------- */
39367 +/* dirren. the branch is identified by the filename who contains this */
39368 +struct au_drinfo {
39371 + uint8_t oldnamelen;
39372 + uint64_t _padding;
39374 + uint8_t oldname[];
39377 +struct au_drinfo_fdata {
39379 + struct au_drinfo drinfo;
39382 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39384 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39386 +/* ---------------------------------------------------------------------- */
39388 +struct aufs_wbr_fd {
39393 +/* ---------------------------------------------------------------------- */
39395 +struct aufs_ibusy {
39396 + uint64_t ino, h_ino;
39400 +/* ---------------------------------------------------------------------- */
39402 +/* error code for move-down */
39403 +/* the actual message strings are implemented in aufs-util.git */
39405 + EAU_MVDOWN_OPAQUE = 1,
39406 + EAU_MVDOWN_WHITEOUT,
39407 + EAU_MVDOWN_UPPER,
39408 + EAU_MVDOWN_BOTTOM,
39409 + EAU_MVDOWN_NOUPPER,
39410 + EAU_MVDOWN_NOLOWERBR,
39414 +/* flags for move-down */
39415 +#define AUFS_MVDOWN_DMSG 1
39416 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39417 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39418 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39419 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39420 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39421 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39422 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39423 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39424 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39425 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39426 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39427 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39429 +/* index for move-down */
39431 + AUFS_MVDOWN_UPPER,
39432 + AUFS_MVDOWN_LOWER,
39433 + AUFS_MVDOWN_NARRAY
39437 + * additional info of move-down
39438 + * number of free blocks and inodes.
39439 + * subset of struct kstatfs, but smaller and always 64bit.
39441 +struct aufs_stfs {
39442 + uint64_t f_blocks;
39443 + uint64_t f_bavail;
39444 + uint64_t f_files;
39445 + uint64_t f_ffree;
39448 +struct aufs_stbr {
39449 + int16_t brid; /* optional input */
39450 + int16_t bindex; /* output */
39451 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39454 +struct aufs_mvdown {
39455 + uint32_t flags; /* input/output */
39456 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39457 + int8_t au_errno; /* output */
39460 +/* ---------------------------------------------------------------------- */
39462 +union aufs_brinfo {
39463 + /* PATH_MAX may differ between kernel-space and user-space */
39464 + char _spacer[4096];
39472 +/* ---------------------------------------------------------------------- */
39474 +#define AuCtlType 'A'
39475 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39476 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39477 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39478 + struct aufs_wbr_fd)
39479 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39480 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39481 + struct aufs_mvdown)
39482 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39483 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39485 +#endif /* __AUFS_TYPE_H__ */
39486 SPDX-License-Identifier: GPL-2.0
39487 aufs6.x-rcN loopback patch
39489 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39490 index 131294601819..56016fc9c9d8 100644
39491 --- a/drivers/block/loop.c
39492 +++ b/drivers/block/loop.c
39493 @@ -54,7 +54,7 @@ struct loop_device {
39495 char lo_file_name[LO_NAME_SIZE];
39497 - struct file * lo_backing_file;
39498 + struct file *lo_backing_file, *lo_backing_virt_file;
39499 struct block_device *lo_device;
39501 gfp_t old_gfp_mask;
39502 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39506 +static struct file *loop_real_file(struct file *file)
39508 + struct file *f = NULL;
39510 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39511 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39515 static void loop_reread_partitions(struct loop_device *lo)
39518 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39520 struct file *file = fget(arg);
39521 struct file *old_file;
39522 + struct file *f, *virt_file = NULL, *old_virt_file;
39526 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39527 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39530 + f = loop_real_file(file);
39532 + virt_file = file;
39537 error = loop_validate_file(file, bdev);
39541 old_file = lo->lo_backing_file;
39542 + old_virt_file = lo->lo_backing_virt_file;
39546 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39547 blk_mq_freeze_queue(lo->lo_queue);
39548 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39549 lo->lo_backing_file = file;
39550 + lo->lo_backing_virt_file = virt_file;
39551 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39552 mapping_set_gfp_mask(file->f_mapping,
39553 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39554 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39558 + if (old_virt_file)
39559 + fput(old_virt_file);
39561 loop_reread_partitions(lo);
39563 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39564 loop_global_unlock(lo, is_loop);
39572 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39573 const struct loop_config *config)
39575 struct file *file = fget(config->fd);
39576 + struct file *f, *virt_file = NULL;
39577 struct inode *inode;
39578 struct address_space *mapping;
39580 @@ -1028,6 +1052,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39581 /* This is safe, since we have a reference from open(). */
39582 __module_get(THIS_MODULE);
39584 + f = loop_real_file(file);
39586 + virt_file = file;
39592 * If we don't hold exclusive handle for the device, upgrade to it
39593 * here to avoid changing device under exclusive owner.
39594 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39595 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39596 lo->lo_device = bdev;
39597 lo->lo_backing_file = file;
39598 + lo->lo_backing_virt_file = virt_file;
39599 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39600 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39602 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39603 bd_abort_claiming(bdev, loop_configure);
39608 /* This is safe: open() is still holding a reference. */
39609 module_put(THIS_MODULE);
39611 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39612 static void __loop_clr_fd(struct loop_device *lo, bool release)
39615 + struct file *virt_filp = lo->lo_backing_virt_file;
39616 gfp_t gfp = lo->old_gfp_mask;
39618 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39619 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39620 spin_lock_irq(&lo->lo_lock);
39621 filp = lo->lo_backing_file;
39622 lo->lo_backing_file = NULL;
39623 + lo->lo_backing_virt_file = NULL;
39624 spin_unlock_irq(&lo->lo_lock);
39626 lo->lo_device = NULL;
39627 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39628 * fput can take open_mutex which is usually taken before lo_mutex.
39635 static int loop_clr_fd(struct loop_device *lo)
39636 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39637 index 1ed300047a41..ea63191d6473 100644
39638 --- a/fs/aufs/f_op.c
39639 +++ b/fs/aufs/f_op.c
39640 @@ -309,7 +309,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39641 if (IS_ERR(h_file))
39644 - if (au_test_loopback_kthread()) {
39645 + if (0 && au_test_loopback_kthread()) {
39646 au_warn_loopback(h_file->f_path.dentry->d_sb);
39647 if (file->f_mapping != h_file->f_mapping) {
39648 file->f_mapping = h_file->f_mapping;
39649 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39650 index 58043e31e5f3..e2bfae6f9d59 100644
39651 --- a/fs/aufs/loop.c
39652 +++ b/fs/aufs/loop.c
39653 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39654 symbol_put(loop_backing_file);
39655 au_kfree_try_rcu(au_warn_loopback_array);
39658 +/* ---------------------------------------------------------------------- */
39660 +/* support the loopback block device insude aufs */
39662 +struct file *aufs_real_loop(struct file *file)
39666 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39667 + fi_read_lock(file);
39668 + f = au_hf_top(file);
39669 + fi_read_unlock(file);
39673 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39674 index 03d4908a6c03..34d356e181d5 100644
39675 --- a/fs/aufs/loop.h
39676 +++ b/fs/aufs/loop.h
39677 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39679 int au_loopback_init(void);
39680 void au_loopback_fin(void);
39682 +struct file *aufs_real_loop(struct file *file);
39684 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39686 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39688 AuStubInt0(au_loopback_init, void)
39689 AuStubVoid(au_loopback_fin, void)
39691 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39692 #endif /* BLK_DEV_LOOP */
39694 #endif /* __KERNEL__ */
39695 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39696 index 81922d4faf54..c8a62c267d72 100644
39697 --- a/fs/aufs/super.c
39698 +++ b/fs/aufs/super.c
39699 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39700 .show_options = aufs_show_options,
39701 .statfs = aufs_statfs,
39702 .put_super = aufs_put_super,
39703 - .sync_fs = aufs_sync_fs
39704 + .sync_fs = aufs_sync_fs,
39705 +#ifdef CONFIG_AUFS_BDEV_LOOP
39706 + .real_loop = aufs_real_loop
39710 /* ---------------------------------------------------------------------- */
39711 diff --git a/include/linux/fs.h b/include/linux/fs.h
39712 index 1e3054e5367d..2a780fcbdc75 100644
39713 --- a/include/linux/fs.h
39714 +++ b/include/linux/fs.h
39715 @@ -1934,6 +1934,10 @@ struct super_operations {
39716 long (*free_cached_objects)(struct super_block *,
39717 struct shrink_control *);
39718 void (*shutdown)(struct super_block *sb);
39719 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39721 + struct file *(*real_loop)(struct file *);