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
49 AUXILIARY DISPLAY DRIVERS
50 M: Miguel Ojeda <ojeda@kernel.org>
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 @@ -876,9 +876,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
150 * Attempt to initiate a splice from a file to a pipe.
152 -static long do_splice_to(struct file *in, loff_t *ppos,
153 - struct pipe_inode_info *pipe, size_t len,
154 - unsigned int flags)
155 +long do_splice_to(struct file *in, loff_t *ppos,
156 + struct pipe_inode_info *pipe, size_t len,
157 + unsigned int flags)
159 unsigned int p_space;
161 diff --git a/include/linux/fs.h b/include/linux/fs.h
162 index 21a981680856..1e3054e5367d 100644
163 --- a/include/linux/fs.h
164 +++ b/include/linux/fs.h
165 @@ -1066,6 +1066,7 @@ extern void fasync_free(struct fasync_struct *);
166 /* can be called from interrupts */
167 extern void kill_fasync(struct fasync_struct **, int, int);
169 +extern int setfl(int fd, struct file *filp, unsigned long arg);
170 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
171 extern int f_setown(struct file *filp, unsigned long arg, int force);
172 extern void f_delown(struct file *filp);
173 @@ -1793,6 +1794,7 @@ struct file_operations {
174 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
175 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
176 int (*check_flags)(int);
177 + int (*setfl)(struct file *, unsigned long);
178 int (*flock) (struct file *, int, struct file_lock *);
179 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
180 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
181 diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
182 index b32256e9e944..16bd7230f44b 100644
183 --- a/include/linux/lockdep.h
184 +++ b/include/linux/lockdep.h
185 @@ -249,6 +249,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock,
186 return lock->key == key;
189 +struct lock_class *lockdep_hlock_class(struct held_lock *hlock);
194 diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
195 index 8f882f5881e8..6b9808f09843 100644
196 --- a/include/linux/mnt_namespace.h
197 +++ b/include/linux/mnt_namespace.h
198 @@ -7,12 +7,15 @@ struct mnt_namespace;
200 struct user_namespace;
204 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *,
205 struct user_namespace *, struct fs_struct *);
206 extern void put_mnt_ns(struct mnt_namespace *ns);
207 extern struct ns_common *from_mnt_ns(struct mnt_namespace *);
209 +extern int is_current_mnt_ns(struct vfsmount *mnt);
211 extern const struct file_operations proc_mounts_operations;
212 extern const struct file_operations proc_mountinfo_operations;
213 extern const struct file_operations proc_mountstats_operations;
214 diff --git a/include/linux/splice.h b/include/linux/splice.h
215 index a55179fd60fc..8e21c53cf883 100644
216 --- a/include/linux/splice.h
217 +++ b/include/linux/splice.h
218 @@ -93,4 +93,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
220 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
221 extern const struct pipe_buf_operations default_pipe_buf_ops;
223 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
224 + loff_t *ppos, size_t len, unsigned int flags);
225 +extern long do_splice_to(struct file *in, loff_t *ppos,
226 + struct pipe_inode_info *pipe, size_t len,
227 + unsigned int flags);
229 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
230 index dcd1d5bfc1e0..85d1f7e0bc07 100644
231 --- a/kernel/locking/lockdep.c
232 +++ b/kernel/locking/lockdep.c
233 @@ -218,7 +218,7 @@ unsigned long max_lock_class_idx;
234 struct lock_class lock_classes[MAX_LOCKDEP_KEYS];
235 DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS);
237 -static inline struct lock_class *hlock_class(struct held_lock *hlock)
238 +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
240 unsigned int class_idx = hlock->class_idx;
242 @@ -239,6 +239,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock)
244 return lock_classes + class_idx;
246 +#define hlock_class(hlock) lockdep_hlock_class(hlock)
248 #ifdef CONFIG_LOCK_STAT
249 static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats);
250 SPDX-License-Identifier: GPL-2.0
251 aufs6.x-rcN mmap patch
253 diff --git a/fs/proc/base.c b/fs/proc/base.c
254 index 05452c3b9872..6b92a8430130 100644
257 @@ -2218,7 +2218,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
259 vma = find_exact_vma(mm, vm_start, vm_end);
260 if (vma && vma->vm_file) {
261 - *path = vma->vm_file->f_path;
262 + *path = vma_pr_or_file(vma)->f_path;
266 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
267 index 4d3493579458..42edd9a42c78 100644
268 --- a/fs/proc/nommu.c
269 +++ b/fs/proc/nommu.c
270 @@ -39,7 +39,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
271 file = region->vm_file;
274 - struct inode *inode = file_inode(region->vm_file);
275 + struct inode *inode;
277 + file = vmr_pr_or_file(region);
278 + inode = file_inode(file);
279 dev = inode->i_sb->s_dev;
282 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
283 index 420510f6a545..edfc0941806a 100644
284 --- a/fs/proc/task_mmu.c
285 +++ b/fs/proc/task_mmu.c
286 @@ -285,7 +285,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
287 const char *name = NULL;
290 - struct inode *inode = file_inode(vma->vm_file);
291 + struct inode *inode;
293 + file = vma_pr_or_file(vma);
294 + inode = file_inode(file);
295 dev = inode->i_sb->s_dev;
297 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
298 @@ -1943,7 +1946,7 @@ static int show_numa_map(struct seq_file *m, void *v)
299 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
300 struct vm_area_struct *vma = v;
301 struct numa_maps *md = &numa_priv->md;
302 - struct file *file = vma->vm_file;
303 + struct file *file = vma_pr_or_file(vma);
304 struct mm_struct *mm = vma->vm_mm;
305 struct mempolicy *pol;
307 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
308 index 0ec35072a8e5..f0f0a03eb2b5 100644
309 --- a/fs/proc/task_nommu.c
310 +++ b/fs/proc/task_nommu.c
311 @@ -150,7 +150,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
315 - struct inode *inode = file_inode(vma->vm_file);
316 + struct inode *inode;
318 + file = vma_pr_or_file(vma);
319 + inode = file_inode(file);
320 dev = inode->i_sb->s_dev;
322 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
323 diff --git a/include/linux/mm.h b/include/linux/mm.h
324 index 27ce77080c79..5f07b972242d 100644
325 --- a/include/linux/mm.h
326 +++ b/include/linux/mm.h
327 @@ -2353,6 +2353,43 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping,
328 unmap_mapping_range(mapping, holebegin, holelen, 0);
331 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
332 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
333 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
335 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
336 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
338 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
340 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
342 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
343 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
346 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
347 +extern void vmr_do_fput(struct vm_region *, const char[], int);
349 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
351 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
352 +#endif /* !CONFIG_MMU */
356 +#define vma_file_update_time(vma) file_update_time((vma)->vm_file)
357 +#define vma_pr_or_file(vma) (vma)->vm_file
358 +#define vma_get_file(vma) get_file((vma)->vm_file)
359 +#define vma_fput(vma) fput((vma)->vm_file)
362 +#define vmr_pr_or_file(region) (region)->vm_file
363 +#define vmr_fput(region) fput((region)->vm_file)
364 +#endif /* !CONFIG_MMU */
366 +#endif /* CONFIG_AUFS_FS */
368 extern int access_process_vm(struct task_struct *tsk, unsigned long addr,
369 void *buf, int len, unsigned int gup_flags);
370 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
371 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
372 index 306a3d1a0fa6..56374f0eb825 100644
373 --- a/include/linux/mm_types.h
374 +++ b/include/linux/mm_types.h
375 @@ -449,6 +449,9 @@ struct vm_region {
376 unsigned long vm_top; /* region allocated to here */
377 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
378 struct file *vm_file; /* the backing file or NULL */
379 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
380 + struct file *vm_prfile; /* the virtual backing file or NULL */
383 int vm_usage; /* region usage count (access under nommu_region_sem) */
384 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
385 @@ -548,6 +551,9 @@ struct vm_area_struct {
386 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
388 struct file * vm_file; /* File we map to (can be NULL). */
389 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
390 + struct file *vm_prfile; /* shadow of vm_file */
392 void * vm_private_data; /* was vm_pte (shared mem) */
394 #ifdef CONFIG_ANON_VMA_NAME
395 diff --git a/kernel/fork.c b/kernel/fork.c
396 index ed4e01daccaa..e945a1639283 100644
399 @@ -733,7 +733,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
401 struct address_space *mapping = file->f_mapping;
405 i_mmap_lock_write(mapping);
406 if (tmp->vm_flags & VM_SHARED)
407 mapping_allow_writable(mapping);
408 diff --git a/mm/Makefile b/mm/Makefile
409 index e29afc890cde..c467601299d4 100644
412 @@ -137,3 +137,4 @@ obj-$(CONFIG_IO_MAPPING) += io-mapping.o
413 obj-$(CONFIG_HAVE_BOOTMEM_INFO_NODE) += bootmem_info.o
414 obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o
415 obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o
417 diff --git a/mm/filemap.c b/mm/filemap.c
418 index b4c9bd368b7e..ec4f4e5c1a92 100644
421 @@ -3564,7 +3564,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf)
422 vm_fault_t ret = VM_FAULT_LOCKED;
424 sb_start_pagefault(mapping->host->i_sb);
425 - file_update_time(vmf->vma->vm_file);
426 + vma_file_update_time(vmf->vma);
428 if (folio->mapping != mapping) {
430 diff --git a/mm/mmap.c b/mm/mmap.c
431 index 13678edaa22c..3b5dd8a8d627 100644
434 @@ -140,7 +140,7 @@ static void remove_vma(struct vm_area_struct *vma, bool unreachable)
435 if (vma->vm_ops && vma->vm_ops->close)
436 vma->vm_ops->close(vma);
438 - fput(vma->vm_file);
440 mpol_put(vma_policy(vma));
443 @@ -607,7 +607,7 @@ static inline void vma_complete(struct vma_prepare *vp,
445 uprobe_munmap(vp->remove, vp->remove->vm_start,
450 if (vp->remove->anon_vma)
451 anon_vma_merge(vp->vma, vp->remove);
452 @@ -2269,7 +2269,7 @@ int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
456 - get_file(new->vm_file);
459 if (new->vm_ops && new->vm_ops->open)
460 new->vm_ops->open(new);
461 @@ -2679,7 +2679,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
462 * and cause general protection fault
465 - fput(vma->vm_file);
469 /* Update vm_flags to pick up the change. */
470 @@ -2774,7 +2774,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
472 if (file || vma->vm_file) {
474 - fput(vma->vm_file);
478 /* Undo any partial mapping done by a device driver. */
479 @@ -2843,6 +2843,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
480 unsigned long populate = 0;
481 unsigned long ret = -EINVAL;
483 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
484 + struct file *prfile;
487 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/mm/remap_file_pages.rst.\n",
488 current->comm, current->pid);
489 @@ -2901,10 +2904,34 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
490 if (vma->vm_flags & VM_LOCKED)
493 +#if 1 /* IS_ENABLED(CONFIG_AUFS_FS) */
495 + file = vma->vm_file;
496 + prfile = vma->vm_prfile;
497 + ret = do_mmap(vma->vm_file, start, size,
498 + prot, flags, pgoff, &populate, NULL);
499 + if (!IS_ERR_VALUE(ret) && file && prfile) {
500 + struct vm_area_struct *new_vma;
502 + new_vma = find_vma(mm, ret);
503 + if (!new_vma->vm_prfile)
504 + new_vma->vm_prfile = prfile;
509 + * two fput()s instead of vma_fput(vma),
510 + * coz vma may not be available anymore.
516 file = get_file(vma->vm_file);
517 ret = do_mmap(vma->vm_file, start, size,
518 prot, flags, pgoff, &populate, NULL);
520 +#endif /* CONFIG_AUFS_FS */
522 mmap_write_unlock(mm);
524 @@ -3250,7 +3277,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
525 if (anon_vma_clone(new_vma, vma))
526 goto out_free_mempol;
527 if (new_vma->vm_file)
528 - get_file(new_vma->vm_file);
529 + vma_get_file(new_vma);
530 if (new_vma->vm_ops && new_vma->vm_ops->open)
531 new_vma->vm_ops->open(new_vma);
532 vma_start_write(new_vma);
533 @@ -3266,7 +3293,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
534 new_vma->vm_ops->close(new_vma);
536 if (new_vma->vm_file)
537 - fput(new_vma->vm_file);
540 unlink_anon_vmas(new_vma);
542 diff --git a/mm/nommu.c b/mm/nommu.c
543 index f670d9979a26..94d41bc45915 100644
546 @@ -523,7 +523,7 @@ static void __put_nommu_region(struct vm_region *region)
547 up_write(&nommu_region_sem);
550 - fput(region->vm_file);
553 /* IO memory and memory shared directly out of the pagecache
554 * from ramfs/tmpfs mustn't be released here */
555 @@ -602,7 +602,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
556 if (vma->vm_ops && vma->vm_ops->close)
557 vma->vm_ops->close(vma);
559 - fput(vma->vm_file);
561 put_nommu_region(vma->vm_region);
564 @@ -1124,7 +1124,7 @@ unsigned long do_mmap(struct file *file,
565 goto error_just_free;
568 - fput(region->vm_file);
570 kmem_cache_free(vm_region_jar, region);
573 @@ -1206,10 +1206,10 @@ unsigned long do_mmap(struct file *file,
577 - fput(region->vm_file);
579 kmem_cache_free(vm_region_jar, region);
581 - fput(vma->vm_file);
586 diff --git a/mm/prfile.c b/mm/prfile.c
588 index 000000000000..8f820a235364
592 +// SPDX-License-Identifier: GPL-2.0
594 + * Mainly for aufs which mmap(2) different file and wants to print different
595 + * path in /proc/PID/maps.
596 + * Call these functions via macros defined in linux/mm.h.
598 + * See Documentation/filesystems/aufs/design/06mmap.txt
600 + * Copyright (c) 2014-2022 Junjro R. Okajima
601 + * Copyright (c) 2014 Ian Campbell
604 +#include <linux/mm.h>
605 +#include <linux/file.h>
606 +#include <linux/fs.h>
608 +/* #define PRFILE_TRACE */
609 +static inline void prfile_trace(struct file *f, struct file *pr,
610 + const char func[], int line, const char func2[])
614 + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f);
618 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
621 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
623 + prfile_trace(f, pr, func, line, __func__);
624 + file_update_time(f);
626 + file_update_time(pr);
629 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
635 + return (f && pr) ? pr : f;
638 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
648 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
650 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
652 + prfile_trace(f, pr, func, line, __func__);
659 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
662 + struct file *f = region->vm_file, *pr = region->vm_prfile;
664 + prfile_trace(f, pr, func, line, __func__);
665 + return (f && pr) ? pr : f;
668 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
670 + struct file *f = region->vm_file, *pr = region->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
677 +#endif /* !CONFIG_MMU */
678 SPDX-License-Identifier: GPL-2.0
679 aufs6.x-rcN standalone patch
681 diff --git a/fs/dcache.c b/fs/dcache.c
682 index 519321f32f95..267e0c65914a 100644
685 @@ -1450,6 +1450,7 @@ void d_walk(struct dentry *parent, void *data,
689 +EXPORT_SYMBOL_GPL(d_walk);
692 struct vfsmount *mnt;
693 @@ -3052,6 +3053,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
695 write_sequnlock(&rename_lock);
697 +EXPORT_SYMBOL_GPL(d_exchange);
700 * d_ancestor - search for an ancestor
701 diff --git a/fs/exec.c b/fs/exec.c
702 index a466e797c8e2..c60353b5214f 100644
705 @@ -112,6 +112,7 @@ bool path_noexec(const struct path *path)
706 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
707 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
709 +EXPORT_SYMBOL_GPL(path_noexec);
713 diff --git a/fs/fcntl.c b/fs/fcntl.c
714 index 9ea58b7bb580..99fef189bcd6 100644
717 @@ -87,6 +87,7 @@ int setfl(int fd, struct file *filp, unsigned long arg)
721 +EXPORT_SYMBOL_GPL(setfl);
723 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
725 diff --git a/fs/file_table.c b/fs/file_table.c
726 index 372653b92617..69128fe39b6d 100644
727 --- a/fs/file_table.c
728 +++ b/fs/file_table.c
729 @@ -199,6 +199,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred)
731 return ERR_PTR(-ENFILE);
733 +EXPORT_SYMBOL_GPL(alloc_empty_file);
736 * Variant of alloc_empty_file() that doesn't check and modify nr_files.
737 diff --git a/fs/namespace.c b/fs/namespace.c
738 index ebb7b4b057ea..6ee47677de2f 100644
741 @@ -457,6 +457,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
742 mnt_dec_writers(real_mount(mnt));
745 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
748 * mnt_drop_write - give up write access to a mount
749 @@ -854,6 +855,7 @@ int is_current_mnt_ns(struct vfsmount *mnt)
751 return check_mnt(real_mount(mnt));
753 +EXPORT_SYMBOL_GPL(is_current_mnt_ns);
756 * vfsmount lock must be held for write
757 @@ -2062,6 +2064,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
761 +EXPORT_SYMBOL_GPL(iterate_mounts);
763 static void lock_mnt_tree(struct mount *mnt)
765 diff --git a/fs/notify/group.c b/fs/notify/group.c
766 index 1de6631a3925..3008eb37a18d 100644
767 --- a/fs/notify/group.c
768 +++ b/fs/notify/group.c
769 @@ -100,6 +100,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
771 refcount_inc(&group->refcnt);
773 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
776 * Drop a reference to a group. Free it if it's through.
777 diff --git a/fs/open.c b/fs/open.c
778 index 4478adcc4f3a..5a984ff90580 100644
781 @@ -67,6 +67,7 @@ int do_truncate(struct mnt_idmap *idmap, struct dentry *dentry,
782 inode_unlock(dentry->d_inode);
785 +EXPORT_SYMBOL_GPL(do_truncate);
787 long vfs_truncate(const struct path *path, loff_t length)
789 diff --git a/fs/read_write.c b/fs/read_write.c
790 index a21ba3be7dbe..ec40061176b3 100644
791 --- a/fs/read_write.c
792 +++ b/fs/read_write.c
793 @@ -477,6 +477,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
797 +EXPORT_SYMBOL_GPL(vfs_read);
799 static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
801 @@ -592,6 +593,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
802 file_end_write(file);
805 +EXPORT_SYMBOL_GPL(vfs_write);
807 /* file_ppos returns &file->f_pos or NULL if file is stream */
808 static inline loff_t *file_ppos(struct file *file)
809 diff --git a/fs/splice.c b/fs/splice.c
810 index 97a66df75d4c..19c8d35f5ebd 100644
813 @@ -872,6 +872,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
814 return warn_unsupported(out, "write");
815 return out->f_op->splice_write(pipe, out, ppos, len, flags);
817 +EXPORT_SYMBOL_GPL(do_splice_from);
820 * Attempt to initiate a splice from a file to a pipe.
821 @@ -901,6 +902,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
822 return warn_unsupported(in, "read");
823 return in->f_op->splice_read(in, ppos, pipe, len, flags);
825 +EXPORT_SYMBOL_GPL(do_splice_to);
828 * splice_direct_to_actor - splices data directly between two non-pipes
829 diff --git a/fs/xattr.c b/fs/xattr.c
830 index fcf67d80d7f9..174dfb9285fb 100644
833 @@ -406,6 +406,7 @@ vfs_getxattr_alloc(struct mnt_idmap *idmap, struct dentry *dentry,
834 *xattr_value = value;
837 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
840 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
841 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
842 index 85d1f7e0bc07..5e20504eed24 100644
843 --- a/kernel/locking/lockdep.c
844 +++ b/kernel/locking/lockdep.c
845 @@ -239,6 +239,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock)
847 return lock_classes + class_idx;
849 +EXPORT_SYMBOL_GPL(lockdep_hlock_class);
850 #define hlock_class(hlock) lockdep_hlock_class(hlock)
852 #ifdef CONFIG_LOCK_STAT
853 diff --git a/kernel/task_work.c b/kernel/task_work.c
854 index 065e1ef8fc8d..c623c6f0c645 100644
855 --- a/kernel/task_work.c
856 +++ b/kernel/task_work.c
857 @@ -182,3 +182,4 @@ void task_work_run(void)
861 +EXPORT_SYMBOL_GPL(task_work_run);
862 diff --git a/security/security.c b/security/security.c
863 index d5ff7ff45b77..5cca1f5774ef 100644
864 --- a/security/security.c
865 +++ b/security/security.c
866 @@ -1711,6 +1711,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
868 return call_int_hook(path_rmdir, 0, dir, dentry);
870 +EXPORT_SYMBOL_GPL(security_path_rmdir);
873 * security_path_unlink() - Check if removing a hard link is allowed
874 @@ -1746,6 +1747,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
876 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
878 +EXPORT_SYMBOL_GPL(security_path_symlink);
881 * security_path_link - Check if creating a hard link is allowed
882 @@ -1764,6 +1766,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
884 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
886 +EXPORT_SYMBOL_GPL(security_path_link);
889 * security_path_rename() - Check if renaming a file is allowed
890 @@ -1825,6 +1828,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
892 return call_int_hook(path_chmod, 0, path, mode);
894 +EXPORT_SYMBOL_GPL(security_path_chmod);
897 * security_path_chown() - Check if changing the file's owner/group is allowed
898 @@ -1842,6 +1846,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
900 return call_int_hook(path_chown, 0, path, uid, gid);
902 +EXPORT_SYMBOL_GPL(security_path_chown);
905 * security_path_chroot() - Check if changing the root directory is allowed
906 @@ -2071,6 +2076,7 @@ int security_inode_permission(struct inode *inode, int mask)
908 return call_int_hook(inode_permission, 0, inode, mask);
910 +EXPORT_SYMBOL_GPL(security_inode_permission);
913 * security_inode_setattr() - Check if setting file attributes is allowed
914 @@ -2549,6 +2555,7 @@ int security_file_permission(struct file *file, int mask)
916 return fsnotify_perm(file, mask);
918 +EXPORT_SYMBOL_GPL(security_file_permission);
921 * security_file_alloc() - Allocate and init a file's LSM blob
922 @@ -2815,6 +2822,7 @@ int security_file_truncate(struct file *file)
924 return call_int_hook(file_truncate, 0, file);
926 +EXPORT_SYMBOL_GPL(security_file_truncate);
929 * security_task_alloc() - Allocate a task's LSM blob
930 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
931 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
932 +++ linux/Documentation/ABI/testing/debugfs-aufs 2022-11-05 23:02:18.955889283 +0100
934 +What: /debug/aufs/si_<id>/
936 +Contact: J. R. Okajima <hooanon05g@gmail.com>
938 + Under /debug/aufs, a directory named si_<id> is created
939 + per aufs mount, where <id> is a unique id generated
942 +What: /debug/aufs/si_<id>/plink
944 +Contact: J. R. Okajima <hooanon05g@gmail.com>
946 + It has three lines and shows the information about the
947 + pseudo-link. The first line is a single number
948 + representing a number of buckets. The second line is a
949 + number of pseudo-links per buckets (separated by a
950 + blank). The last line is a single number representing a
951 + total number of psedo-links.
952 + When the aufs mount option 'noplink' is specified, it
953 + will show "1\n0\n0\n".
955 +What: /debug/aufs/si_<id>/xib
957 +Contact: J. R. Okajima <hooanon05g@gmail.com>
959 + It shows the consumed blocks by xib (External Inode Number
960 + Bitmap), its block size and file size.
961 + When the aufs mount option 'noxino' is specified, it
962 + will be empty. About XINO files, see the aufs manual.
964 +What: /debug/aufs/si_<id>/xi<branch-index>
966 +Contact: J. R. Okajima <hooanon05g@gmail.com>
968 + It shows the consumed blocks by xino (External Inode Number
969 + Translation Table), its link count, block size and file
971 + Due to the file size limit, there may exist multiple
972 + xino files per branch. In this case, "-N" is added to
973 + the filename and it corresponds to the index of the
974 + internal xino array. "-0" is omitted.
975 + When the aufs mount option 'noxino' is specified, Those
976 + entries won't exist. About XINO files, see the aufs
979 +What: /debug/aufs/si_<id>/xigen
981 +Contact: J. R. Okajima <hooanon05g@gmail.com>
983 + It shows the consumed blocks by xigen (External Inode
984 + Generation Table), its block size and file size.
985 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
987 + When the aufs mount option 'noxino' is specified, it
988 + will be empty. About XINO files, see the aufs manual.
989 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
990 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
991 +++ linux/Documentation/ABI/testing/sysfs-aufs 2022-11-05 23:02:18.955889283 +0100
993 +What: /sys/fs/aufs/si_<id>/
995 +Contact: J. R. Okajima <hooanon05g@gmail.com>
997 + Under /sys/fs/aufs, a directory named si_<id> is created
998 + per aufs mount, where <id> is a unique id generated
1001 +What: /sys/fs/aufs/si_<id>/br<idx>
1003 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1005 + It shows the abolute path of a member directory (which
1006 + is called branch) in aufs, and its permission.
1008 +What: /sys/fs/aufs/si_<id>/brid<idx>
1010 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1012 + It shows the id of a member directory (which is called
1015 +What: /sys/fs/aufs/si_<id>/xi_path
1017 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1019 + It shows the abolute path of XINO (External Inode Number
1020 + Bitmap, Translation Table and Generation Table) file
1021 + even if it is the default path.
1022 + When the aufs mount option 'noxino' is specified, it
1023 + will be empty. About XINO files, see the aufs manual.
1024 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1025 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1026 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2022-11-05 23:02:18.955889283 +0100
1029 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1031 +# This program is free software; you can redistribute it and/or modify
1032 +# it under the terms of the GNU General Public License as published by
1033 +# the Free Software Foundation; either version 2 of the License, or
1034 +# (at your option) any later version.
1036 +# This program is distributed in the hope that it will be useful,
1037 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1038 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1039 +# GNU General Public License for more details.
1041 +# You should have received a copy of the GNU General Public License
1042 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1045 +----------------------------------------
1047 +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s]
1048 +1. abbrev. for "advanced multi-layered unification filesystem".
1049 +2. abbrev. for "another unionfs".
1050 +3. abbrev. for "auf das" in German which means "on the" in English.
1051 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1052 + But "Filesystem aufs Filesystem" is hard to understand.
1053 +4. abbrev. for "African Urban Fashion Show".
1055 +AUFS is a filesystem with features:
1056 +- multi layered stackable unification filesystem, the member directory
1057 + is called as a branch.
1058 +- branch permission and attribute, 'readonly', 'real-readonly',
1059 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1061 +- internal "file copy-on-write".
1062 +- logical deletion, whiteout.
1063 +- dynamic branch manipulation, adding, deleting and changing permission.
1064 +- allow bypassing aufs, user's direct branch access.
1065 +- external inode number translation table and bitmap which maintains the
1066 + persistent aufs inode number.
1067 +- seekable directory, including NFS readdir.
1068 +- file mapping, mmap and sharing pages.
1069 +- pseudo-link, hardlink over branches.
1070 +- loopback mounted filesystem as a branch.
1071 +- several policies to select one among multiple writable branches.
1072 +- revert a single systemcall when an error occurs in aufs.
1076 +Multi Layered Stackable Unification Filesystem
1077 +----------------------------------------------------------------------
1078 +Most people already knows what it is.
1079 +It is a filesystem which unifies several directories and provides a
1080 +merged single directory. When users access a file, the access will be
1081 +passed/re-directed/converted (sorry, I am not sure which English word is
1082 +correct) to the real file on the member filesystem. The member
1083 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1084 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1085 +readonly branch is handled by creating 'whiteout' on the upper writable
1088 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1089 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1090 +different approaches to implement the merged-view.
1091 +The former tries putting it into VFS, and the latter implements as a
1092 +separate filesystem.
1093 +(If I misunderstand about these implementations, please let me know and
1094 +I shall correct it. Because it is a long time ago when I read their
1095 +source files last time).
1097 +UnionMount's approach will be able to small, but may be hard to share
1098 +branches between several UnionMount since the whiteout in it is
1099 +implemented in the inode on branch filesystem and always
1100 +shared. According to Bharata's post, readdir does not seems to be
1102 +There are several missing features known in this implementations such as
1103 +- for users, the inode number may change silently. eg. copy-up.
1104 +- link(2) may break by copy-up.
1105 +- read(2) may get an obsoleted filedata (fstat(2) too).
1106 +- fcntl(F_SETLK) may be broken by copy-up.
1107 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1110 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1111 +merged into mainline. This is another implementation of UnionMount as a
1112 +separated filesystem. All the limitations and known problems which
1113 +UnionMount are equally inherited to "overlay" filesystem.
1115 +Unionfs has a longer history. When I started implementing a stackable
1116 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1117 +inode, dentry and file objects and they have an array pointing lower
1118 +same kind objects. After contributing many patches for Unionfs, I
1119 +re-started my project AUFS (Jun 2006).
1121 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1122 +implemented my own ideas, approaches and enhancements and it became
1123 +totally different one.
1125 +Comparing DM snapshot and fs based implementation
1126 +- the number of bytes to be copied between devices is much smaller.
1127 +- the type of filesystem must be one and only.
1128 +- the fs must be writable, no readonly fs, even for the lower original
1129 + device. so the compression fs will not be usable. but if we use
1130 + loopback mount, we may address this issue.
1132 + mount /cdrom/squashfs.img /sq
1133 + losetup /sq/ext2.img
1134 + losetup /somewhere/cow
1135 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1136 +- it will be difficult (or needs more operations) to extract the
1137 + difference between the original device and COW.
1138 +- DM snapshot-merge may help a lot when users try merging. in the
1139 + fs-layer union, users will use rsync(1).
1141 +You may want to read my old paper "Filesystems in LiveCD"
1142 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1145 +Several characters/aspects/persona of aufs
1146 +----------------------------------------------------------------------
1148 +Aufs has several characters, aspects or persona.
1149 +1. a filesystem, callee of VFS helper
1150 +2. sub-VFS, caller of VFS helper for branches
1151 +3. a virtual filesystem which maintains persistent inode number
1152 +4. reader/writer of files on branches such like an application
1154 +1. Callee of VFS Helper
1155 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1156 +unlink(2) from an application reaches sys_unlink() kernel function and
1157 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1158 +calls filesystem specific unlink operation. Actually aufs implements the
1159 +unlink operation but it behaves like a redirector.
1161 +2. Caller of VFS Helper for Branches
1162 +aufs_unlink() passes the unlink request to the branch filesystem as if
1163 +it were called from VFS. So the called unlink operation of the branch
1164 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1165 +every necessary pre/post operation for the branch filesystem.
1166 +- acquire the lock for the parent dir on a branch
1167 +- lookup in a branch
1168 +- revalidate dentry on a branch
1169 +- mnt_want_write() for a branch
1170 +- vfs_unlink() for a branch
1171 +- mnt_drop_write() for a branch
1172 +- release the lock on a branch
1174 +3. Persistent Inode Number
1175 +One of the most important issue for a filesystem is to maintain inode
1176 +numbers. This is particularly important to support exporting a
1177 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1178 +backend block device for its own. But some storage is necessary to
1179 +keep and maintain the inode numbers. It may be a large space and may not
1180 +suit to keep in memory. Aufs rents some space from its first writable
1181 +branch filesystem (by default) and creates file(s) on it. These files
1182 +are created by aufs internally and removed soon (currently) keeping
1184 +Note: Because these files are removed, they are totally gone after
1185 + unmounting aufs. It means the inode numbers are not persistent
1186 + across unmount or reboot. I have a plan to make them really
1187 + persistent which will be important for aufs on NFS server.
1189 +4. Read/Write Files Internally (copy-on-write)
1190 +Because a branch can be readonly, when you write a file on it, aufs will
1191 +"copy-up" it to the upper writable branch internally. And then write the
1192 +originally requested thing to the file. Generally kernel doesn't
1193 +open/read/write file actively. In aufs, even a single write may cause a
1194 +internal "file copy". This behaviour is very similar to cp(1) command.
1196 +Some people may think it is better to pass such work to user space
1197 +helper, instead of doing in kernel space. Actually I am still thinking
1198 +about it. But currently I have implemented it in kernel space.
1199 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1200 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1201 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2022-11-05 23:02:18.955889283 +0100
1204 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1206 +# This program is free software; you can redistribute it and/or modify
1207 +# it under the terms of the GNU General Public License as published by
1208 +# the Free Software Foundation; either version 2 of the License, or
1209 +# (at your option) any later version.
1211 +# This program is distributed in the hope that it will be useful,
1212 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1213 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1214 +# GNU General Public License for more details.
1216 +# You should have received a copy of the GNU General Public License
1217 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1219 +Basic Aufs Internal Structure
1221 +Superblock/Inode/Dentry/File Objects
1222 +----------------------------------------------------------------------
1223 +As like an ordinary filesystem, aufs has its own
1224 +superblock/inode/dentry/file objects. All these objects have a
1225 +dynamically allocated array and store the same kind of pointers to the
1226 +lower filesystem, branch.
1227 +For example, when you build a union with one readwrite branch and one
1228 +readonly, mounted /au, /rw and /ro respectively.
1230 +- /ro/fileA exists but /rw/fileA
1232 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1233 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1234 +- [0] = NULL (because /rw/fileA doesn't exist)
1237 +This style of an array is essentially same to the aufs
1238 +superblock/inode/dentry/file objects.
1240 +Because aufs supports manipulating branches, ie. add/delete/change
1241 +branches dynamically, these objects has its own generation. When
1242 +branches are changed, the generation in aufs superblock is
1243 +incremented. And a generation in other object are compared when it is
1244 +accessed. When a generation in other objects are obsoleted, aufs
1245 +refreshes the internal array.
1249 +----------------------------------------------------------------------
1250 +Additionally aufs superblock has some data for policies to select one
1251 +among multiple writable branches, XIB files, pseudo-links and kobject.
1252 +See below in detail.
1253 +About the policies which supports copy-down a directory, see
1254 +wbr_policy.txt too.
1257 +Branch and XINO(External Inode Number Translation Table)
1258 +----------------------------------------------------------------------
1259 +Every branch has its own xino (external inode number translation table)
1260 +file. The xino file is created and unlinked by aufs internally. When two
1261 +members of a union exist on the same filesystem, they share the single
1263 +The struct of a xino file is simple, just a sequence of aufs inode
1264 +numbers which is indexed by the lower inode number.
1265 +In the above sample, assume the inode number of /ro/fileA is i111 and
1266 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1267 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1269 +When the inode numbers are not contiguous, the xino file will be sparse
1270 +which has a hole in it and doesn't consume as much disk space as it
1271 +might appear. If your branch filesystem consumes disk space for such
1272 +holes, then you should specify 'xino=' option at mounting aufs.
1274 +Aufs has a mount option to free the disk blocks for such holes in XINO
1275 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1276 +meet a problem of disk shortage due to XINO files, then you should try
1277 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1278 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1279 +the holes in XINO files.
1281 +Also a writable branch has three kinds of "whiteout bases". All these
1282 +are existed when the branch is joined to aufs, and their names are
1283 +whiteout-ed doubly, so that users will never see their names in aufs
1285 +1. a regular file which will be hardlinked to all whiteouts.
1286 +2. a directory to store a pseudo-link.
1287 +3. a directory to store an "orphan"-ed file temporary.
1290 + When you remove a file on a readonly branch, aufs handles it as a
1291 + logical deletion and creates a whiteout on the upper writable branch
1292 + as a hardlink of this file in order not to consume inode on the
1295 + See below, Pseudo-link.
1297 + When "fileC" exists on the lower readonly branch only and it is
1298 + opened and removed with its parent dir, and then user writes
1299 + something into it, then aufs copies-up fileC to this
1300 + directory. Because there is no other dir to store fileC. After
1301 + creating a file under this dir, the file is unlinked.
1303 +Because aufs supports manipulating branches, ie. add/delete/change
1304 +dynamically, a branch has its own id. When the branch order changes,
1305 +aufs finds the new index by searching the branch id.
1309 +----------------------------------------------------------------------
1310 +Assume "fileA" exists on the lower readonly branch only and it is
1311 +hardlinked to "fileB" on the branch. When you write something to fileA,
1312 +aufs copies-up it to the upper writable branch. Additionally aufs
1313 +creates a hardlink under the Pseudo-link Directory of the writable
1314 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1315 +simple list. If fileB is read after unlinking fileA, aufs returns
1316 +filedata from the pseudo-link instead of the lower readonly
1317 +branch. Because the pseudo-link is based upon the inode, to keep the
1318 +inode number by xino (see above) is essentially necessary.
1320 +All the hardlinks under the Pseudo-link Directory of the writable branch
1321 +should be restored in a proper location later. Aufs provides a utility
1322 +to do this. The userspace helpers executed at remounting and unmounting
1324 +During this utility is running, it puts aufs into the pseudo-link
1325 +maintenance mode. In this mode, only the process which began the
1326 +maintenance mode (and its child processes) is allowed to operate in
1327 +aufs. Some other processes which are not related to the pseudo-link will
1328 +be allowed to run too, but the rest have to return an error or wait
1329 +until the maintenance mode ends. If a process already acquires an inode
1330 +mutex (in VFS), it has to return an error.
1333 +XIB(external inode number bitmap)
1334 +----------------------------------------------------------------------
1335 +Addition to the xino file per a branch, aufs has an external inode number
1336 +bitmap in a superblock object. It is also an internal file such like a
1338 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1340 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1342 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1343 +reduce the number of consumed disk blocks for these files.
1346 +Virtual or Vertical Dir, and Readdir in Userspace
1347 +----------------------------------------------------------------------
1348 +In order to support multiple layers (branches), aufs readdir operation
1349 +constructs a virtual dir block on memory. For readdir, aufs calls
1350 +vfs_readdir() internally for each dir on branches, merges their entries
1351 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1352 +object. So the file object has its entry list until it is closed. The
1353 +entry list will be updated when the file position is zero and becomes
1354 +obsoleted. This decision is made in aufs automatically.
1356 +The dynamically allocated memory block for the name of entries has a
1357 +unit of 512 bytes (by default) and stores the names contiguously (no
1358 +padding). Another block for each entry is handled by kmem_cache too.
1359 +During building dir blocks, aufs creates hash list and judging whether
1360 +the entry is whiteouted by its upper branch or already listed.
1361 +The merged result is cached in the corresponding inode object and
1362 +maintained by a customizable life-time option.
1364 +Some people may call it can be a security hole or invite DoS attack
1365 +since the opened and once readdir-ed dir (file object) holds its entry
1366 +list and becomes a pressure for system memory. But I'd say it is similar
1367 +to files under /proc or /sys. The virtual files in them also holds a
1368 +memory page (generally) while they are opened. When an idea to reduce
1369 +memory for them is introduced, it will be applied to aufs too.
1370 +For those who really hate this situation, I've developed readdir(3)
1371 +library which operates this merging in userspace. You just need to set
1372 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1373 +kernel space for readdir(3).
1377 +----------------------------------------------------------------------
1378 +Aufs sometimes requires privilege access to a branch. For instance,
1379 +in copy-up/down operation. When a user process is going to make changes
1380 +to a file which exists in the lower readonly branch only, and the mode
1381 +of one of ancestor directories may not be writable by a user
1382 +process. Here aufs copy-up the file with its ancestors and they may
1383 +require privilege to set its owner/group/mode/etc.
1384 +This is a typical case of a application character of aufs (see
1387 +Aufs uses workqueue synchronously for this case. It creates its own
1388 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1389 +passes the request to call mkdir or write (for example), and wait for
1390 +its completion. This approach solves a problem of a signal handler
1392 +If aufs didn't adopt the workqueue and changed the privilege of the
1393 +process, then the process may receive the unexpected SIGXFSZ or other
1396 +Also aufs uses the system global workqueue ("events" kernel thread) too
1397 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1398 +whiteout base and etc. This is unrelated to a privilege.
1399 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1400 +superblock at the beginning, at the same time waits for the completion
1401 +of all queued asynchronous tasks.
1405 +----------------------------------------------------------------------
1406 +The whiteout in aufs is very similar to Unionfs's. That is represented
1407 +by its filename. UnionMount takes an approach of a file mode, but I am
1408 +afraid several utilities (find(1) or something) will have to support it.
1410 +Basically the whiteout represents "logical deletion" which stops aufs to
1411 +lookup further, but also it represents "dir is opaque" which also stop
1414 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1415 +In order to make several functions in a single systemcall to be
1416 +revertible, aufs adopts an approach to rename a directory to a temporary
1417 +unique whiteouted name.
1418 +For example, in rename(2) dir where the target dir already existed, aufs
1419 +renames the target dir to a temporary unique whiteouted name before the
1420 +actual rename on a branch, and then handles other actions (make it opaque,
1421 +update the attributes, etc). If an error happens in these actions, aufs
1422 +simply renames the whiteouted name back and returns an error. If all are
1423 +succeeded, aufs registers a function to remove the whiteouted unique
1424 +temporary name completely and asynchronously to the system global
1429 +----------------------------------------------------------------------
1430 +It is a well-known feature or concept.
1431 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1432 +internally and makes change to the new file on the upper writable branch.
1433 +When the trigger systemcall does not update the timestamps of the parent
1434 +dir, aufs reverts it after copy-up.
1437 +Move-down (aufs3.9 and later)
1438 +----------------------------------------------------------------------
1439 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1440 +the lower readonly branch to the upper writable branch when a user
1441 +changes something about the file.
1442 +"Move-down" is an opposite action of copy-up. Basically this action is
1443 +ran manually instead of automatically and internally.
1444 +For desgin and implementation, aufs has to consider these issues.
1445 +- whiteout for the file may exist on the lower branch.
1446 +- ancestor directories may not exist on the lower branch.
1447 +- diropq for the ancestor directories may exist on the upper branch.
1448 +- free space on the lower branch will reduce.
1449 +- another access to the file may happen during moving-down, including
1450 + UDBA (see "Revalidate Dentry and UDBA").
1451 +- the file should not be hard-linked nor pseudo-linked. they should be
1452 + handled by auplink utility later.
1454 +Sometimes users want to move-down a file from the upper writable branch
1455 +to the lower readonly or writable branch. For instance,
1456 +- the free space of the upper writable branch is going to run out.
1457 +- create a new intermediate branch between the upper and lower branch.
1460 +For this purpose, use "aumvdown" command in aufs-util.git.
1461 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1462 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1463 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2022-11-05 23:02:18.955889283 +0100
1466 +# Copyright (C) 2015-2022 Junjiro R. Okajima
1468 +# This program is free software; you can redistribute it and/or modify
1469 +# it under the terms of the GNU General Public License as published by
1470 +# the Free Software Foundation; either version 2 of the License, or
1471 +# (at your option) any later version.
1473 +# This program is distributed in the hope that it will be useful,
1474 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1475 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1476 +# GNU General Public License for more details.
1478 +# You should have received a copy of the GNU General Public License
1479 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1481 +Support for a branch who has its ->atomic_open()
1482 +----------------------------------------------------------------------
1483 +The filesystems who implement its ->atomic_open() are not majority. For
1484 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1485 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1486 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1487 +sure whether all filesystems who have ->atomic_open() behave like this,
1488 +but NFSv4 surely returns the error.
1490 +In order to support ->atomic_open() for aufs, there are a few
1493 +A. Introduce aufs_atomic_open()
1494 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1496 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1497 + an aufs user Pip Cet's approach
1498 + - calls aufs_create(), VFS finish_open() and notify_change().
1499 + - pass fake-mode to finish_open(), and then correct the mode by
1501 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1502 + - no aufs_atomic_open().
1503 + - aufs_lookup() registers the TID to an aufs internal object.
1504 + - aufs_create() does nothing when the matching TID is registered, but
1505 + registers the mode.
1506 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1507 + TID is registered.
1508 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1510 + - no aufs_atomic_open().
1511 + - aufs_create() registers the TID to an internal object. this info
1512 + represents "this process created this file just now."
1513 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1514 + registered TID and re-try open() with superuser's credential.
1516 +Pros and cons for each approach.
1519 + - straightforward but highly depends upon VFS internal.
1520 + - the atomic behavaiour is kept.
1521 + - some of parameters such as nameidata are hard to reproduce for
1525 + - easy to implement.
1526 + - the atomic behavaiour is lost.
1528 + - the atomic behavaiour is kept.
1529 + - dirty and tricky.
1530 + - VFS checks whether the file is created correctly after calling
1531 + ->create(), which means this approach doesn't work.
1533 + - easy to implement.
1534 + - the atomic behavaiour is lost.
1535 + - to open a file with superuser's credential and give it to a user
1536 + process is a bad idea, since the file object keeps the credential
1537 + in it. It may affect LSM or something. This approach doesn't work
1540 +The approach A is ideal, but it hard to implement. So here is a
1541 +variation of A, which is to be implemented.
1543 +A-1. Introduce aufs_atomic_open()
1544 + - calls branch fs ->atomic_open() if exists. otherwise calls
1545 + vfs_create() and finish_open().
1546 + - the demerit is that the several checks after branch fs
1547 + ->atomic_open() are lost. in the ordinary case, the checks are
1548 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1549 + be implemented in aufs, but not all I am afraid.
1550 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1551 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1552 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2022-11-05 23:02:18.959222617 +0100
1555 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1557 +# This program is free software; you can redistribute it and/or modify
1558 +# it under the terms of the GNU General Public License as published by
1559 +# the Free Software Foundation; either version 2 of the License, or
1560 +# (at your option) any later version.
1562 +# This program is distributed in the hope that it will be useful,
1563 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1564 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1565 +# GNU General Public License for more details.
1567 +# You should have received a copy of the GNU General Public License
1568 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1571 +----------------------------------------------------------------------
1572 +Since aufs has a character of sub-VFS (see Introduction), it operates
1573 +lookup for branches as VFS does. It may be a heavy work. But almost all
1574 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1575 +directly connected to its parent. Digging down the directory hierarchy
1576 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1579 +When a branch is a remote filesystem, aufs basically relies upon its
1580 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1582 +For d_revalidate, aufs implements three levels of revalidate tests. See
1583 +"Revalidate Dentry and UDBA" in detail.
1586 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1587 +----------------------------------------------------------------------
1588 +Let's try case study.
1589 +- aufs has two branches, upper readwrite and lower readonly.
1591 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1592 +- user invoked "chmod a+rx /au/dirA"
1593 +- the internal copy-up is activated and "/rw/dirA" is created and its
1594 + permission bits are set to world readable.
1595 +- then "/au/dirA" becomes world readable?
1597 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1598 +or it may be a natively readonly filesystem. If aufs respects the lower
1599 +branch, it should not respond readdir request from other users. But user
1600 +allowed it by chmod. Should really aufs rejects showing the entries
1603 +To be honest, I don't have a good solution for this case. So aufs
1604 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1606 +When dirperm1 is specified, aufs checks only the highest one for the
1607 +directory permission, and shows the entries. Otherwise, as usual, checks
1608 +every dir existing on all branches and rejects the request.
1610 +As a side effect, dirperm1 option improves the performance of aufs
1611 +because the number of permission check is reduced when the number of
1615 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1616 +----------------------------------------------------------------------
1617 +Generally VFS helpers re-validate a dentry as a part of lookup.
1618 +0. digging down the directory hierarchy.
1619 +1. lock the parent dir by its i_mutex.
1620 +2. lookup the final (child) entry.
1622 +4. call the actual operation (create, unlink, etc.)
1623 +5. unlock the parent dir
1625 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1626 +called. Actually aufs implements it and checks the dentry on a branch is
1628 +But it is not enough. Because aufs has to release the lock for the
1629 +parent dir on a branch at the end of ->lookup() (step 2) and
1630 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1632 +If the file on a branch is changed directly, eg. bypassing aufs, after
1633 +aufs released the lock, then the subsequent operation may cause
1634 +something unpleasant result.
1636 +This situation is a result of VFS architecture, ->lookup() and
1637 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1638 +design from VFS's point of view. It is just not suitable for sub-VFS
1641 +Aufs supports such case by three level of revalidation which is
1642 +selectable by user.
1643 +1. Simple Revalidate
1644 + Addition to the native flow in VFS's, confirm the child-parent
1645 + relationship on the branch just after locking the parent dir on the
1646 + branch in the "actual operation" (step 4). When this validation
1647 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1648 + checks the validation of the dentry on branches.
1649 +2. Monitor Changes Internally by Inotify/Fsnotify
1650 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1651 + the dentry on the branch, and returns EBUSY if it finds different
1653 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1654 + during it is in cache. When the event is notified, aufs registers a
1655 + function to kernel 'events' thread by schedule_work(). And the
1656 + function sets some special status to the cached aufs dentry and inode
1657 + private data. If they are not cached, then aufs has nothing to
1658 + do. When the same file is accessed through aufs (step 0-3) later,
1659 + aufs will detect the status and refresh all necessary data.
1660 + In this mode, aufs has to ignore the event which is fired by aufs
1662 +3. No Extra Validation
1663 + This is the simplest test and doesn't add any additional revalidation
1664 + test, and skip the revalidation in step 4. It is useful and improves
1665 + aufs performance when system surely hide the aufs branches from user,
1666 + by over-mounting something (or another method).
1667 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1668 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1669 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2022-11-05 23:02:18.959222617 +0100
1672 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1674 +# This program is free software; you can redistribute it and/or modify
1675 +# it under the terms of the GNU General Public License as published by
1676 +# the Free Software Foundation; either version 2 of the License, or
1677 +# (at your option) any later version.
1679 +# This program is distributed in the hope that it will be useful,
1680 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1681 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1682 +# GNU General Public License for more details.
1684 +# You should have received a copy of the GNU General Public License
1685 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1687 +Branch Manipulation
1689 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1690 +and changing its permission/attribute, there are a lot of works to do.
1694 +----------------------------------------------------------------------
1695 +o Confirm the adding dir exists outside of aufs, including loopback
1696 + mount, and its various attributes.
1697 +o Initialize the xino file and whiteout bases if necessary.
1700 +o Check the owner/group/mode of the directory
1701 + When the owner/group/mode of the adding directory differs from the
1702 + existing branch, aufs issues a warning because it may impose a
1704 + For example, when a upper writable branch has a world writable empty
1705 + top directory, a malicious user can create any files on the writable
1706 + branch directly, like copy-up and modify manually. If something like
1707 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1708 + writable branch, and the writable branch is world-writable, then a
1709 + malicious guy may create /etc/passwd on the writable branch directly
1710 + and the infected file will be valid in aufs.
1711 + I am afraid it can be a security issue, but aufs can do nothing except
1712 + producing a warning.
1716 +----------------------------------------------------------------------
1717 +o Confirm the deleting branch is not busy
1718 + To be general, there is one merit to adopt "remount" interface to
1719 + manipulate branches. It is to discard caches. At deleting a branch,
1720 + aufs checks the still cached (and connected) dentries and inodes. If
1721 + there are any, then they are all in-use. An inode without its
1722 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1724 + For the cached one, aufs checks whether the same named entry exists on
1726 + If the cached one is a directory, because aufs provides a merged view
1727 + to users, as long as one dir is left on any branch aufs can show the
1728 + dir to users. In this case, the branch can be removed from aufs.
1729 + Otherwise aufs rejects deleting the branch.
1731 + If any file on the deleting branch is opened by aufs, then aufs
1735 +Modify the Permission of a Branch
1736 +----------------------------------------------------------------------
1737 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1740 +o rw --> ro: Confirm the modifying branch is not busy
1741 + Aufs rejects the request if any of these conditions are true.
1742 + - a file on the branch is mmap-ed.
1743 + - a regular file on the branch is opened for write and there is no
1744 + same named entry on the upper branch.
1745 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1746 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1747 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2022-11-05 23:02:18.959222617 +0100
1750 +# Copyright (C) 2005-2022 Junjiro R. Okajima
1752 +# This program is free software; you can redistribute it and/or modify
1753 +# it under the terms of the GNU General Public License as published by
1754 +# the Free Software Foundation; either version 2 of the License, or
1755 +# (at your option) any later version.
1757 +# This program is distributed in the hope that it will be useful,
1758 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1759 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1760 +# GNU General Public License for more details.
1762 +# You should have received a copy of the GNU General Public License
1763 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1765 +Policies to Select One among Multiple Writable Branches
1766 +----------------------------------------------------------------------
1767 +When the number of writable branch is more than one, aufs has to decide
1768 +the target branch for file creation or copy-up. By default, the highest
1769 +writable branch which has the parent (or ancestor) dir of the target
1770 +file is chosen (top-down-parent policy).
1771 +By user's request, aufs implements some other policies to select the
1772 +writable branch, for file creation several policies, round-robin,
1773 +most-free-space, and other policies. For copy-up, top-down-parent,
1774 +bottom-up-parent, bottom-up and others.
1776 +As expected, the round-robin policy selects the branch in circular. When
1777 +you have two writable branches and creates 10 new files, 5 files will be
1778 +created for each branch. mkdir(2) systemcall is an exception. When you
1779 +create 10 new directories, all will be created on the same branch.
1780 +And the most-free-space policy selects the one which has most free
1781 +space among the writable branches. The amount of free space will be
1782 +checked by aufs internally, and users can specify its time interval.
1784 +The policies for copy-up is more simple,
1785 +top-down-parent is equivalent to the same named on in create policy,
1786 +bottom-up-parent selects the writable branch where the parent dir
1787 +exists and the nearest upper one from the copyup-source,
1788 +bottom-up selects the nearest upper writable branch from the
1789 +copyup-source, regardless the existence of the parent dir.
1791 +There are some rules or exceptions to apply these policies.
1792 +- If there is a readonly branch above the policy-selected branch and
1793 + the parent dir is marked as opaque (a variation of whiteout), or the
1794 + target (creating) file is whiteout-ed on the upper readonly branch,
1795 + then the result of the policy is ignored and the target file will be
1796 + created on the nearest upper writable branch than the readonly branch.
1797 +- If there is a writable branch above the policy-selected branch and
1798 + the parent dir is marked as opaque or the target file is whiteouted
1799 + on the branch, then the result of the policy is ignored and the target
1800 + file will be created on the highest one among the upper writable
1801 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1803 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1804 + They try selecting the branch where the source exists as possible
1805 + since copyup a large file will take long time. If it can't be,
1806 + ie. the branch where the source exists is readonly, then they will
1807 + follow the copyup policy.
1808 +- There is an exception for rename(2) when the target exists.
1809 + If the rename target exists, aufs compares the index of the branches
1810 + where the source and the target exists and selects the higher
1811 + one. If the selected branch is readonly, then aufs follows the
1813 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot
1814 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100
1815 +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2022-11-05 23:02:18.959222617 +0100
1818 +// to view this graph, run dot(1) command in GRAPHVIZ.
1820 +// This program is free software; you can redistribute it and/or modify
1821 +// it under the terms of the GNU General Public License as published by
1822 +// the Free Software Foundation; either version 2 of the License, or
1823 +// (at your option) any later version.
1825 +// This program is distributed in the hope that it will be useful,
1826 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
1827 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1828 +// GNU General Public License for more details.
1830 +// You should have received a copy of the GNU General Public License
1831 +// along with this program. If not, see <http://www.gnu.org/licenses/>.
1835 +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"];
1839 +aufs_rename -> whinfo [label="store/remove"];
1842 +inode_list [label="h_inum list in branch\ncache"];
1845 +whinode [label="h_inum list file"];
1848 +brmgmt [label="br_add/del/mod/umount"];
1850 +brmgmt -> inode_list [label="create/remove"];
1851 +brmgmt -> whinode [label="load/store"];
1853 +inode_list -> whinode [style=dashed,dir=both];
1855 +aufs_rename -> inode_list [label="add/del"];
1857 +aufs_lookup -> inode_list [label="search"];
1859 +aufs_lookup -> whinfo [label="load/remove"];
1861 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt
1862 --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100
1863 +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2022-11-05 23:02:18.959222617 +0100
1866 +# Copyright (C) 2017-2022 Junjiro R. Okajima
1868 +# This program is free software; you can redistribute it and/or modify
1869 +# it under the terms of the GNU General Public License as published by
1870 +# the Free Software Foundation; either version 2 of the License, or
1871 +# (at your option) any later version.
1873 +# This program is distributed in the hope that it will be useful,
1874 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1875 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1876 +# GNU General Public License for more details.
1878 +# You should have received a copy of the GNU General Public License
1879 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1881 +Special handling for renaming a directory (DIRREN)
1882 +----------------------------------------------------------------------
1883 +First, let's assume we have a simple usecase.
1887 +- /ro/dirA and /ro/dirA/file exist too
1888 +- there is no dirB on both branches
1889 +- a user issues rename("dirA", "dirB")
1891 +Now, what should aufs behave against this rename(2)?
1892 +There are a few possible cases.
1895 + since dirA exists on a readonly branch which cannot be renamed.
1897 + it is possible to copy-up dirA (only the dir itself), but the child
1898 + entries ("file" in this case) should not be. it must be a bad
1899 + approach to copy-up recursively.
1900 +C. returns a success.
1901 + even the branch /ro is readonly, aufs tries renaming it. Obviously it
1902 + is a violation of aufs' policy.
1903 +D. construct an extra information which indicates that /ro/dirA should
1904 + be handled as the name of dirB.
1905 + overlayfs has a similar feature called REDIRECT.
1907 +Until now, aufs implements the case B only which returns EXDEV, and
1908 +expects the userspace application behaves like mv(1) which tries
1909 +issueing rename(2) recursively.
1911 +A new aufs feature called DIRREN is introduced which implements the case
1912 +D. There are several "extra information" added.
1914 +1. detailed info per renamed directory
1915 + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id>
1916 +2. the inode-number list of directories on a branch
1917 + path: /rw/dirB/$AUFS_WH_DR_BRHINO
1919 +The filename of "detailed info per directory" represents the lower
1920 +branch, and its format is
1921 +- a type of the branch id
1923 + + uuid (not implemented yet)
1926 +- the inode-number of the branch root dir
1928 +And it contains these info in a single regular file.
1930 +- branch's inode-number of the logically renamed dir
1931 +- the name of the before-renamed dir
1933 +The "detailed info per directory" file is created in aufs rename(2), and
1934 +loaded in any lookup.
1935 +The info is considered in lookup for the matching case only. Here
1936 +"matching" means that the root of branch (in the info filename) is same
1937 +to the current looking-up branch. After looking-up the before-renamed
1938 +name, the inode-number is compared. And the matched dentry is used.
1940 +The "inode-number list of directories" is a regular file which contains
1941 +simply the inode-numbers on the branch. The file is created or updated
1942 +in removing the branch, and loaded in adding the branch. Its lifetime is
1943 +equal to the branch.
1944 +The list is referred in lookup, and when the current target inode is
1945 +found in the list, the aufs tries loading the "detailed info per
1946 +directory" and get the changed and valid name of the dir.
1948 +Theoretically these "extra informaiton" may be able to be put into XATTR
1949 +in the dir inode. But aufs doesn't choose this way because
1950 +1. XATTR may not be supported by the branch (or its configuration)
1951 +2. XATTR may have its size limit.
1952 +3. XATTR may be less easy to convert than a regular file, when the
1953 + format of the info is changed in the future.
1954 +At the same time, I agree that the regular file approach is much slower
1955 +than XATTR approach. So, in the future, aufs may take the XATTR or other
1958 +This DIRREN feature is enabled by aufs configuration, and is activated
1959 +by a new mount option.
1961 +For the more complicated case, there is a work with UDBA option, which
1962 +is to dected the direct access to the branches (by-passing aufs) and to
1963 +maintain the cashes in aufs. Since a single cached aufs dentry may
1964 +contains two names, before- and after-rename, the name comparision in
1965 +UDBA handler may not work correctly. In this case, the behaviour will be
1966 +equivalen to udba=reval case.
1967 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1968 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1969 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2022-11-05 23:02:18.959222617 +0100
1972 +# Copyright (C) 2011-2022 Junjiro R. Okajima
1974 +# This program is free software; you can redistribute it and/or modify
1975 +# it under the terms of the GNU General Public License as published by
1976 +# the Free Software Foundation; either version 2 of the License, or
1977 +# (at your option) any later version.
1979 +# This program is distributed in the hope that it will be useful,
1980 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1981 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1982 +# GNU General Public License for more details.
1984 +# You should have received a copy of the GNU General Public License
1985 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1987 +File-based Hierarchical Storage Management (FHSM)
1988 +----------------------------------------------------------------------
1989 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1990 +storage world. Aufs provides this feature as file-based with multiple
1991 +writable branches, based upon the principle of "Colder, the Lower".
1992 +Here the word "colder" means that the less used files, and "lower" means
1993 +that the position in the order of the stacked branches vertically.
1994 +These multiple writable branches are prioritized, ie. the topmost one
1995 +should be the fastest drive and be used heavily.
1997 +o Characters in aufs FHSM story
1998 +- aufs itself and a new branch attribute.
1999 +- a new ioctl interface to move-down and to establish a connection with
2000 + the daemon ("move-down" is a converse of "copy-up").
2001 +- userspace tool and daemon.
2003 +The userspace daemon establishes a connection with aufs and waits for
2004 +the notification. The notified information is very similar to struct
2005 +statfs containing the number of consumed blocks and inodes.
2006 +When the consumed blocks/inodes of a branch exceeds the user-specified
2007 +upper watermark, the daemon activates its move-down process until the
2008 +consumed blocks/inodes reaches the user-specified lower watermark.
2010 +The actual move-down is done by aufs based upon the request from
2011 +user-space since we need to maintain the inode number and the internal
2012 +pointer arrays in aufs.
2014 +Currently aufs FHSM handles the regular files only. Additionally they
2015 +must not be hard-linked nor pseudo-linked.
2018 +o Cowork of aufs and the user-space daemon
2019 + During the userspace daemon established the connection, aufs sends a
2020 + small notification to it whenever aufs writes something into the
2021 + writable branch. But it may cost high since aufs issues statfs(2)
2022 + internally. So user can specify a new option to cache the
2023 + info. Actually the notification is controlled by these factors.
2024 + + the specified cache time.
2025 + + classified as "force" by aufs internally.
2026 + Until the specified time expires, aufs doesn't send the info
2027 + except the forced cases. When aufs decide forcing, the info is always
2028 + notified to userspace.
2029 + For example, the number of free inodes is generally large enough and
2030 + the shortage of it happens rarely. So aufs doesn't force the
2031 + notification when creating a new file, directory and others. This is
2032 + the typical case which aufs doesn't force.
2033 + When aufs writes the actual filedata and the files consumes any of new
2034 + blocks, the aufs forces notifying.
2037 +o Interfaces in aufs
2038 +- New branch attribute.
2040 + Specifies that the branch is managed by FHSM feature. In other word,
2041 + participant in the FHSM.
2042 + When nofhsm is set to the branch, it will not be the source/target
2043 + branch of the move-down operation. This attribute is set
2044 + independently from coo and moo attributes, and if you want full
2045 + FHSM, you should specify them as well.
2046 +- New mount option.
2048 + Specifies a second to suppress many less important info to be
2051 + + AUFS_CTL_FHSM_FD
2052 + create a new file descriptor which userspace can read the notification
2053 + (a subset of struct statfs) from aufs.
2054 +- Module parameter 'brs'
2055 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2057 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2058 + When there are two or more branches with fhsm attributes,
2059 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2060 + terminates it. As a result of remounting and branch-manipulation, the
2061 + number of branches with fhsm attribute can be one. In this case,
2062 + /sbin/mount.aufs will terminate the user-space daemon.
2065 +Finally the operation is done as these steps in kernel-space.
2067 + + no one else is using the file.
2068 + + the file is not hard-linked.
2069 + + the file is not pseudo-linked.
2070 + + the file is a regular file.
2071 + + the parent dir is not opaqued.
2072 +- find the target writable branch.
2073 +- make sure the file is not whiteout-ed by the upper (than the target)
2075 +- make the parent dir on the target branch.
2076 +- mutex lock the inode on the branch.
2077 +- unlink the whiteout on the target branch (if exists).
2078 +- lookup and create the whiteout-ed temporary name on the target branch.
2079 +- copy the file as the whiteout-ed temporary name on the target branch.
2080 +- rename the whiteout-ed temporary name to the original name.
2081 +- unlink the file on the source branch.
2082 +- maintain the internal pointer array and the external inode number
2084 +- maintain the timestamps and other attributes of the parent dir and the
2087 +And of course, in every step, an error may happen. So the operation
2088 +should restore the original file state after an error happens.
2089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2090 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2091 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2022-11-05 23:02:18.959222617 +0100
2094 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2096 +# This program is free software; you can redistribute it and/or modify
2097 +# it under the terms of the GNU General Public License as published by
2098 +# the Free Software Foundation; either version 2 of the License, or
2099 +# (at your option) any later version.
2101 +# This program is distributed in the hope that it will be useful,
2102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2104 +# GNU General Public License for more details.
2106 +# You should have received a copy of the GNU General Public License
2107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2109 +mmap(2) -- File Memory Mapping
2110 +----------------------------------------------------------------------
2111 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2112 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2114 +This approach is simple and good, but there is one problem.
2115 +Under /proc, several entries show the mmapped files by its path (with
2116 +device and inode number), and the printed path will be the path on the
2117 +branch fs's instead of virtual aufs's.
2118 +This is not a problem in most cases, but some utilities lsof(1) (and its
2119 +user) may expect the path on aufs.
2121 +To address this issue, aufs adds a new member called vm_prfile in struct
2122 +vm_area_struct (and struct vm_region). The original vm_file points to
2123 +the file on the branch fs in order to handle everything correctly as
2124 +usual. The new vm_prfile points to a virtual file in aufs, and the
2125 +show-functions in procfs refers to vm_prfile if it is set.
2126 +Also we need to maintain several other places where touching vm_file
2128 +- fork()/clone() copies vma and the reference count of vm_file is
2130 +- merging vma maintains the ref count too.
2132 +This is not a good approach. It just fakes the printed path. But it
2133 +leaves all behaviour around f_mapping unchanged. This is surely an
2135 +Actually aufs had adopted another complicated approach which calls
2136 +generic_file_mmap() and handles struct vm_operations_struct. In this
2137 +approach, aufs met a hard problem and I could not solve it without
2138 +switching the approach.
2140 +There may be one more another approach which is
2141 +- bind-mount the branch-root onto the aufs-root internally
2142 +- grab the new vfsmount (ie. struct mount)
2143 +- lazy-umount the branch-root internally
2144 +- in open(2) the aufs-file, open the branch-file with the hidden
2145 + vfsmount (instead of the original branch's vfsmount)
2146 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2147 + but it may be possible from userspace by the mount helper.
2149 +Adding the internal hidden vfsmount and using it in opening a file, the
2150 +file path under /proc will be printed correctly. This approach looks
2151 +smarter, but is not possible I am afraid.
2152 +- aufs-root may be bind-mount later. when it happens, another hidden
2153 + vfsmount will be required.
2154 +- it is hard to get the chance to bind-mount and lazy-umount
2155 + + in kernel-space, FS can have vfsmount in open(2) via
2156 + file->f_path, and aufs can know its vfsmount. But several locks are
2157 + already acquired, and if aufs tries to bind-mount and lazy-umount
2158 + here, then it may cause a deadlock.
2159 + + in user-space, bind-mount doesn't invoke the mount helper.
2160 +- since /proc shows dev and ino, aufs has to give vma these info. it
2161 + means a new member vm_prinode will be necessary. this is essentially
2162 + equivalent to vm_prfile described above.
2164 +I have to give up this "looks-smater" approach.
2165 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2166 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2167 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2022-11-05 23:02:18.959222617 +0100
2170 +# Copyright (C) 2014-2022 Junjiro R. Okajima
2172 +# This program is free software; you can redistribute it and/or modify
2173 +# it under the terms of the GNU General Public License as published by
2174 +# the Free Software Foundation; either version 2 of the License, or
2175 +# (at your option) any later version.
2177 +# This program is distributed in the hope that it will be useful,
2178 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2179 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2180 +# GNU General Public License for more details.
2182 +# You should have received a copy of the GNU General Public License
2183 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2185 +Listing XATTR/EA and getting the value
2186 +----------------------------------------------------------------------
2187 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2188 +shows the values from the topmost existing file. This behaviour is good
2189 +for the non-dir entries since the bahaviour exactly matches the shown
2190 +information. But for the directories, aufs considers all the same named
2191 +entries on the lower branches. Which means, if one of the lower entry
2192 +rejects readdir call, then aufs returns an error even if the topmost
2193 +entry allows it. This behaviour is necessary to respect the branch fs's
2194 +security, but can make users confused since the user-visible standard
2195 +attributes don't match the behaviour.
2196 +To address this issue, aufs has a mount option called dirperm1 which
2197 +checks the permission for the topmost entry only, and ignores the lower
2198 +entry's permission.
2200 +A similar issue can happen around XATTR.
2201 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2202 +always set. Otherwise these very unpleasant situation would happen.
2203 +- listxattr(2) may return the duplicated entries.
2204 +- users may not be able to remove or reset the XATTR forever,
2207 +XATTR/EA support in the internal (copy,move)-(up,down)
2208 +----------------------------------------------------------------------
2209 +Generally the extended attributes of inode are categorized as these.
2210 +- "security" for LSM and capability.
2211 +- "system" for posix ACL, 'acl' mount option is required for the branch
2213 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2214 +- "user" for userspace, 'user_xattr' mount option is required for the
2215 + branch fs generally.
2217 +Moreover there are some other categories. Aufs handles these rather
2218 +unpopular categories as the ordinary ones, ie. there is no special
2219 +condition nor exception.
2221 +In copy-up, the support for XATTR on the dst branch may differ from the
2222 +src branch. In this case, the copy-up operation will get an error and
2223 +the original user operation which triggered the copy-up will fail. It
2224 +can happen that even all copy-up will fail.
2225 +When both of src and dst branches support XATTR and if an error occurs
2226 +during copying XATTR, then the copy-up should fail obviously. That is a
2227 +good reason and aufs should return an error to userspace. But when only
2228 +the src branch support that XATTR, aufs should not return an error.
2229 +For example, the src branch supports ACL but the dst branch doesn't
2230 +because the dst branch may natively un-support it or temporary
2231 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2232 +may NOT return an error even if the XATTR is not supported. It is
2233 +totally up to the branch fs.
2235 +Anyway when the aufs internal copy-up gets an error from the dst branch
2236 +fs, then aufs tries removing the just copied entry and returns the error
2237 +to the userspace. The worst case of this situation will be all copy-up
2240 +For the copy-up operation, there two basic approaches.
2241 +- copy the specified XATTR only (by category above), and return the
2242 + error unconditionally if it happens.
2243 +- copy all XATTR, and ignore the error on the specified category only.
2245 +In order to support XATTR and to implement the correct behaviour, aufs
2246 +chooses the latter approach and introduces some new branch attributes,
2247 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2248 +They correspond to the XATTR namespaces (see above). Additionally, to be
2249 +convenient, "icex" is also provided which means all "icex*" attributes
2250 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2252 +The meaning of these attributes is to ignore the error from setting
2253 +XATTR on that branch.
2254 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2255 +error from the dst branch according to the specified attributes.
2257 +Some XATTR may have its default value. The default value may come from
2258 +the parent dir or the environment. If the default value is set at the
2259 +file creating-time, it will be overwritten by copy-up.
2260 +Some contradiction may happen I am afraid.
2261 +Do we need another attribute to stop copying XATTR? I am unsure. For
2262 +now, aufs implements the branch attributes to ignore the error.
2263 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2264 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2265 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2022-11-05 23:02:18.959222617 +0100
2268 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2270 +# This program is free software; you can redistribute it and/or modify
2271 +# it under the terms of the GNU General Public License as published by
2272 +# the Free Software Foundation; either version 2 of the License, or
2273 +# (at your option) any later version.
2275 +# This program is distributed in the hope that it will be useful,
2276 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2277 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2278 +# GNU General Public License for more details.
2280 +# You should have received a copy of the GNU General Public License
2281 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2283 +Export Aufs via NFS
2284 +----------------------------------------------------------------------
2285 +Here is an approach.
2286 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2288 +- iget_locked(): initialize aufs inode generation for a new inode, and
2289 + store it in xigen file.
2290 +- destroy_inode(): increment aufs inode generation and store it in xigen
2291 + file. it is necessary even if it is not unlinked, because any data of
2292 + inode may be changed by UDBA.
2293 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2294 + build file handle by
2295 + + branch id (4 bytes)
2296 + + superblock generation (4 bytes)
2297 + + inode number (4 or 8 bytes)
2298 + + parent dir inode number (4 or 8 bytes)
2299 + + inode generation (4 bytes))
2300 + + return value of exportfs_encode_fh() for the parent on a branch (4
2302 + + file handle for a branch (by exportfs_encode_fh())
2304 + + find the index of a branch from its id in handle, and check it is
2305 + still exist in aufs.
2306 + + 1st level: get the inode number from handle and search it in cache.
2307 + + 2nd level: if not found in cache, get the parent inode number from
2308 + the handle and search it in cache. and then open the found parent
2309 + dir, find the matching inode number by vfs_readdir() and get its
2310 + name, and call lookup_one_len() for the target dentry.
2311 + + 3rd level: if the parent dir is not cached, call
2312 + exportfs_decode_fh() for a branch and get the parent on a branch,
2313 + build a pathname of it, convert it a pathname in aufs, call
2314 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2316 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2317 + for every branch, but not itself. to get this, (currently) aufs
2318 + searches in current->nsproxy->mnt_ns list. it may not be a good
2319 + idea, but I didn't get other approach.
2320 + + test the generation of the gotten inode.
2321 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2322 + convert it into ESTALE for NFSD.
2323 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2324 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2325 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2326 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2327 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2022-11-05 23:02:18.959222617 +0100
2330 +# Copyright (C) 2005-2022 Junjiro R. Okajima
2332 +# This program is free software; you can redistribute it and/or modify
2333 +# it under the terms of the GNU General Public License as published by
2334 +# the Free Software Foundation; either version 2 of the License, or
2335 +# (at your option) any later version.
2337 +# This program is distributed in the hope that it will be useful,
2338 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2339 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2340 +# GNU General Public License for more details.
2342 +# You should have received a copy of the GNU General Public License
2343 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2345 +Show Whiteout Mode (shwh)
2346 +----------------------------------------------------------------------
2347 +Generally aufs hides the name of whiteouts. But in some cases, to show
2348 +them is very useful for users. For instance, creating a new middle layer
2349 +(branch) by merging existing layers.
2351 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2352 +When you have three branches,
2353 +- Bottom: 'system', squashfs (underlying base system), read-only
2354 +- Middle: 'mods', squashfs, read-only
2355 +- Top: 'overlay', ram (tmpfs), read-write
2357 +The top layer is loaded at boot time and saved at shutdown, to preserve
2358 +the changes made to the system during the session.
2359 +When larger changes have been made, or smaller changes have accumulated,
2360 +the size of the saved top layer data grows. At this point, it would be
2361 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2362 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2363 +restoring save and load speed.
2365 +This merging is simplified by the use of another aufs mount, of just the
2366 +two overlay branches using the 'shwh' option.
2367 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2368 + aufs /livesys/merge_union
2370 +A merged view of these two branches is then available at
2371 +/livesys/merge_union, and the new feature is that the whiteouts are
2373 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2374 +writing to all branches. Also the default mode for all branches is 'ro'.
2375 +It is now possible to save the combined contents of the two overlay
2376 +branches to a new squashfs, e.g.:
2377 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2379 +This new squashfs archive can be stored on the boot device and the
2380 +initramfs will use it to replace the old one at the next boot.
2381 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2382 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2383 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2022-11-05 23:02:18.959222617 +0100
2386 +# Copyright (C) 2010-2022 Junjiro R. Okajima
2388 +# This program is free software; you can redistribute it and/or modify
2389 +# it under the terms of the GNU General Public License as published by
2390 +# the Free Software Foundation; either version 2 of the License, or
2391 +# (at your option) any later version.
2393 +# This program is distributed in the hope that it will be useful,
2394 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2395 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2396 +# GNU General Public License for more details.
2398 +# You should have received a copy of the GNU General Public License
2399 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2401 +Dynamically customizable FS operations
2402 +----------------------------------------------------------------------
2403 +Generally FS operations (struct inode_operations, struct
2404 +address_space_operations, struct file_operations, etc.) are defined as
2405 +"static const", but it never means that FS have only one set of
2406 +operation. Some FS have multiple sets of them. For instance, ext2 has
2407 +three sets, one for XIP, for NOBH, and for normal.
2408 +Since aufs overrides and redirects these operations, sometimes aufs has
2409 +to change its behaviour according to the branch FS type. More importantly
2410 +VFS acts differently if a function (member in the struct) is set or
2411 +not. It means aufs should have several sets of operations and select one
2412 +among them according to the branch FS definition.
2414 +In order to solve this problem and not to affect the behaviour of VFS,
2415 +aufs defines these operations dynamically. For instance, aufs defines
2416 +dummy direct_IO function for struct address_space_operations, but it may
2417 +not be set to the address_space_operations actually. When the branch FS
2418 +doesn't have it, aufs doesn't set it to its address_space_operations
2419 +while the function definition itself is still alive. So the behaviour
2420 +itself will not change, and it will return an error when direct_IO is
2423 +The lifetime of these dynamically generated operation object is
2424 +maintained by aufs branch object. When the branch is removed from aufs,
2425 +the reference counter of the object is decremented. When it reaches
2426 +zero, the dynamically generated operation object will be freed.
2428 +This approach is designed to support AIO (io_submit), Direct I/O and
2430 +Currently this approach is applied to address_space_operations for
2431 +regular files only.
2432 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2433 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2434 +++ linux/Documentation/filesystems/aufs/README 2023-08-28 12:34:41.669969465 +0200
2437 +Aufs6 -- advanced multi layered unification filesystem version 6.x
2443 +----------------------------------------
2444 +In the early days, aufs was entirely re-designed and re-implemented
2445 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2446 +improvements and implementations, it became totally different from
2447 +Unionfs while keeping the basic features.
2448 +Later, Unionfs Version 2.x series began taking some of the same
2449 +approaches to aufs1's.
2450 +Unionfs was being developed by Professor Erez Zadok at Stony Brook
2451 +University and his team.
2453 +Aufs6 supports linux-v6.0 and later, try aufs6.0 branch in
2454 +aufs-linux.git or aufs-standalone.git.
2455 +If you want older kernel version support,
2456 +- for linux-v5.x series, try aufs-linux.git or aufs-standalone.git
2457 +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git
2458 +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git
2459 +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git
2460 + or aufs1 from CVS on SourceForge.
2462 +Note: the name of aufs5-linux.git and aufs5-standalone.git on github
2463 + were changed. Now they are aufs-linux.git and
2464 + aufs-standalone.git and they contain aufs5 and later branches.
2466 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2467 + According to Christoph Hellwig, linux rejects all union-type
2468 + filesystems but UnionMount.
2469 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2471 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2472 + UnionMount, and he pointed out an issue around a directory mutex
2473 + lock and aufs addressed it. But it is still unsure whether aufs will
2474 + be merged (or any other union solution).
2475 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2479 +----------------------------------------
2480 +- unite several directories into a single virtual filesystem. The member
2481 + directory is called as a branch.
2482 +- you can specify the permission flags to the branch, which are 'readonly',
2483 + 'readwrite' and 'whiteout-able.'
2484 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2485 + readonly branch are modifiable logically.
2486 +- dynamic branch manipulation, add, del.
2489 +Also there are many enhancements in aufs, such as:
2490 +- test only the highest one for the directory permission (dirperm1)
2491 +- copyup on open (coo=)
2492 +- 'move' policy for copy-up between two writable branches, after
2493 + checking free space.
2495 +- readdir(3) in userspace.
2496 +- keep inode number by external inode number table
2497 +- keep the timestamps of file/dir in internal copyup operation
2498 +- seekable directory, supporting NFS readdir.
2499 +- whiteout is hardlinked in order to reduce the consumption of inodes
2501 +- do not copyup, nor create a whiteout when it is unnecessary
2502 +- revert a single systemcall when an error occurs in aufs
2503 +- remount interface instead of ioctl
2504 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2505 +- loopback mounted filesystem as a branch
2506 +- kernel thread for removing the dir who has a plenty of whiteouts
2507 +- support copyup sparse file (a file which has a 'hole' in it)
2508 +- default permission flags for branches
2509 +- selectable permission flags for ro branch, whether whiteout can
2512 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2513 +- support multiple writable branches, some policies to select one
2514 + among multiple writable branches.
2515 +- a new semantics for link(2) and rename(2) to support multiple
2516 + writable branches.
2517 +- no glibc changes are required.
2518 +- pseudo hardlink (hardlink over branches)
2519 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2520 + including NFS or remote filesystem branch.
2521 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2524 +Currently these features are dropped temporary from aufs6.
2525 +See design/08plan.txt in detail.
2526 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2528 +- statistics of aufs thread (/sys/fs/aufs/stat)
2530 +Features or just an idea in the future (see also design/*.txt),
2531 +- reorder the branch index without del/re-add.
2532 +- permanent xino files for NFSD
2533 +- an option for refreshing the opened files after add/del branches
2534 +- light version, without branch manipulation. (unnecessary?)
2535 +- copyup in userspace
2536 +- inotify in userspace
2541 +----------------------------------------
2542 +There are three GIT trees for aufs6, aufs-linux.git,
2543 +aufs-standalone.git, and aufs-util.git.
2544 +While the aufs-util is always necessary, you need either of aufs-linux
2545 +or aufs-standalone.
2547 +The aufs-linux tree includes the whole linux mainline GIT tree,
2548 +git://git.kernel.org/.../torvalds/linux.git.
2549 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2550 +build aufs6 as an external kernel module.
2551 +Several extra patches are not included in this tree. Only
2552 +aufs-standalone tree contains them. They are described in the later
2553 +section "Configuration and Compilation."
2555 +On the other hand, the aufs-standalone tree has only aufs source files
2556 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2557 +But you need to apply all aufs patches manually.
2559 +You will find GIT branches whose name is in form of "aufs6.x" where "x"
2560 +represents the linux kernel version, "linux-6.x". For instance,
2561 +"aufs6.0" is for linux-6.0. For latest "linux-6.x-rcN", use
2562 +"aufs6.x-rcN" branch.
2565 +$ git clone --reference /your/linux/git/tree \
2566 + git://github.com/sfjro/aufs-linux.git aufs-linux.git
2567 +- if you don't have linux GIT tree, then remove "--reference ..."
2568 +$ cd aufs-linux.git
2569 +$ git checkout origin/aufs6.0
2571 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2572 +leave the patch-work to GIT.
2573 +$ cd /your/linux/git/tree
2574 +$ git remote add aufs git://github.com/sfjro/aufs-linux.git
2576 +$ git checkout -b my6.0 v6.0
2577 +$ (add your local change...)
2578 +$ git pull aufs aufs6.0
2579 +- now you have v6.0 + your_changes + aufs6.0 in you my6.0 branch.
2580 +- you may need to solve some conflicts between your_changes and
2581 + aufs6.0. in this case, git-rerere is recommended so that you can
2582 + solve the similar conflicts automatically when you upgrade to 6.1 or
2583 + later in the future.
2585 +o aufs-standalone tree
2586 +$ git clone git://github.com/sfjro/aufs-standalone.git aufs-standalone.git
2587 +$ cd aufs-standalone.git
2588 +$ git checkout origin/aufs6.0
2591 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2592 +- note that the public aufs-util.git is on SourceForge instead of
2595 +$ git checkout origin/aufs6.0
2597 +Note: The 6.x-rcN branch is to be used with `rc' kernel versions ONLY.
2598 +The minor version number, 'x' in '6.x', of aufs may not always
2599 +follow the minor version number of the kernel.
2600 +Because changes in the kernel that cause the use of a new
2601 +minor version number do not always require changes to aufs-util.
2603 +Since aufs-util has its own minor version number, you may not be
2604 +able to find a GIT branch in aufs-util for your kernel's
2605 +exact minor version number.
2606 +In this case, you should git-checkout the branch for the
2607 +nearest lower number.
2609 +For (an unreleased) example:
2610 +If you are using "linux-6.10" and the "aufs6.10" branch
2611 +does not exist in aufs-util repository, then "aufs6.9", "aufs6.8"
2612 +or something numerically smaller is the branch for your kernel.
2614 +Also you can view all branches by
2618 +3. Configuration and Compilation
2619 +----------------------------------------
2620 +Make sure you have git-checkout'ed the correct branch.
2622 +For aufs-linux tree,
2623 +- enable CONFIG_AUFS_FS.
2624 +- set other aufs configurations if necessary.
2625 +- for aufs5.13 and later
2626 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2627 + also a caller of VFS functions for branch filesystems, subclassing of
2628 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2629 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2630 + need to customize some LOCKDEP numbers. Here are what I use on my
2632 + CONFIG_LOCKDEP_BITS=21
2633 + CONFIG_LOCKDEP_CHAINS_BITS=21
2634 + CONFIG_LOCKDEP_STACK_TRACE_BITS=24
2635 + Also you will need to expand some constant values in LOCKDEP. Refer
2636 + to lockdep-debug.patch in aufs-standalone.git.
2638 +For aufs-standalone tree,
2639 +There are several ways to build.
2642 +- apply ./aufs6-kbuild.patch to your kernel source files.
2643 +- apply ./aufs6-base.patch too.
2644 +- apply ./aufs6-mmap.patch too.
2645 +- apply ./aufs6-standalone.patch too, if you have a plan to set
2646 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs-standalone.patch.
2647 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2648 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2649 +- enable CONFIG_AUFS_FS, you can select either
2651 +- and build your kernel as usual.
2652 +- install the built kernel.
2653 +- install the header files too by "make headers_install" to the
2654 + directory where you specify. By default, it is $PWD/usr.
2655 + "make help" shows a brief note for headers_install.
2656 +- and reboot your system.
2659 +- module only (CONFIG_AUFS_FS=m).
2660 +- apply ./aufs6-base.patch to your kernel source files.
2661 +- apply ./aufs6-mmap.patch too.
2662 +- apply ./aufs6-standalone.patch too.
2663 +- build your kernel, don't forget "make headers_install", and reboot.
2664 +- edit ./config.mk and set other aufs configurations if necessary.
2665 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2666 + every aufs configurations.
2667 +- build the module by simple "make".
2668 +- you can specify ${KDIR} make variable which points to your kernel
2670 +- install the files
2671 + + run "make install" to install the aufs module, or copy the built
2672 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2673 + + run "make install_headers" (instead of headers_install) to install
2674 + the modified aufs header file (you can specify DESTDIR which is
2675 + available in aufs standalone version's Makefile only), or copy
2676 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2677 + you like manually. By default, the target directory is $PWD/usr.
2678 +- no need to apply aufs6-kbuild.patch, nor copying source files to your
2679 + kernel source tree.
2681 +Note: The header file aufs_type.h is necessary to build aufs-util
2682 + as well as "make headers_install" in the kernel source tree.
2683 + headers_install is subject to be forgotten, but it is essentially
2684 + necessary, not only for building aufs-util.
2685 + You may not meet problems without headers_install in some older
2689 +- read README in aufs-util, build and install it
2690 +- note that your distribution may contain an obsoleted version of
2691 + aufs_type.h in /usr/include/linux or something. When you build aufs
2692 + utilities, make sure that your compiler refers the correct aufs header
2693 + file which is built by "make headers_install."
2694 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2695 + then run "make install_ulib" too. And refer to the aufs manual in
2698 +There several other patches in aufs-standalone.git. They are all
2699 +optional. When you meet some problems, they will help you.
2700 +- aufs6-loopback.patch
2701 + Supports a nested loopback mount in a branch-fs. This patch is
2702 + unnecessary until aufs produces a message like "you may want to try
2703 + another patch for loopback file".
2705 + Modifies a system global kernel internal function get_next_ino() in
2706 + order to stop assigning 0 for an inode-number. Not directly related to
2707 + aufs, but recommended generally.
2709 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2710 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2711 + duplication of inode number, which is important for backup tools and
2712 + other utilities. When you find aufs XINO files for tmpfs branch
2713 + growing too much, try this patch.
2714 +- lockdep-debug.patch
2715 + Similar to some kernel configurations for LOCKDEP (see the top of
2716 + this section), you will need expand some constants in LOCKDEP for
2717 + aufs if you enable CONFIG_LOCKDEP.
2721 +----------------------------------------
2722 +At first, make sure aufs-util are installed, and please read the aufs
2723 +manual, aufs.5 in aufs-util.git tree.
2727 +$ mkdir /tmp/rw /tmp/aufs
2728 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2730 +Here is another example. The result is equivalent.
2731 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2733 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2734 +# mount -o remount,append:${HOME} /tmp/aufs
2736 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2737 +you modify a file under /tmp/aufs, the one on your home directory is
2738 +not affected, instead the same named file will be newly created under
2739 +/tmp/rw. And all of your modification to a file will be applied to
2740 +the one under /tmp/rw. This is called the file based Copy on Write
2742 +Aufs mount options are described in aufs.5.
2743 +If you run chroot or something and make your aufs as a root directory,
2744 +then you need to customize the shutdown script. See the aufs manual in
2747 +Additionally, there are some sample usages of aufs which are a
2748 +diskless system with network booting, and LiveCD over NFS.
2749 +See sample dir in CVS tree on SourceForge.
2753 +----------------------------------------
2754 +When you have any problems or strange behaviour in aufs, please let me
2756 +- /proc/mounts (instead of the output of mount(8))
2757 +- /sys/module/aufs/*
2758 +- /sys/fs/aufs/* (if you have them)
2759 +- /debug/aufs/* (if you have them)
2760 +- linux kernel version
2761 + if your kernel is not plain, for example modified by distributor,
2762 + the url where i can download its source is necessary too.
2763 +- aufs version which was printed at loading the module or booting the
2764 + system, instead of the date you downloaded.
2765 +- configuration (define/undefine CONFIG_AUFS_xxx)
2766 +- kernel configuration or /proc/config.gz (if you have it)
2767 +- LSM (linux security module, if you are using)
2768 +- behaviour which you think to be incorrect
2769 +- actual operation, reproducible one is better
2770 +- mailto: aufs-users at lists.sourceforge.net
2772 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2773 +and Feature Requests) on SourceForge. Please join and write to
2777 +6. Acknowledgements
2778 +----------------------------------------
2779 +Thanks to everyone who have tried and are using aufs, whoever
2780 +have reported a bug or any feedback.
2782 +Especially donators:
2783 +Tomas Matejicek(slax.org) made a donation (much more than once).
2784 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2785 + scripts) is making "doubling" donations.
2786 + Unfortunately I cannot list all of the donators, but I really
2788 + It ends Aug 2010, but the ordinary donation URL is still available.
2789 + <http://sourceforge.net/donate/index.php?group_id=167503>
2790 +Dai Itasaka made a donation (2007/8).
2791 +Chuck Smith made a donation (2008/4, 10 and 12).
2792 +Henk Schoneveld made a donation (2008/9).
2793 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2794 +Francois Dupoux made a donation (2008/11).
2795 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2796 + aufs2 GIT tree (2009/2).
2797 +William Grant made a donation (2009/3).
2798 +Patrick Lane made a donation (2009/4).
2799 +The Mail Archive (mail-archive.com) made donations (2009/5).
2800 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2801 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2802 +Pavel Pronskiy made a donation (2011/2).
2803 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2804 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2805 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2807 +Sam Liddicott made a donation (2011/9).
2808 +Era Scarecrow made a donation (2013/4).
2809 +Bor Ratajc made a donation (2013/4).
2810 +Alessandro Gorreta made a donation (2013/4).
2811 +POIRETTE Marc made a donation (2013/4).
2812 +Alessandro Gorreta made a donation (2013/4).
2813 +lauri kasvandik made a donation (2013/5).
2814 +"pemasu from Finland" made a donation (2013/7).
2815 +The Parted Magic Project made a donation (2013/9 and 11).
2816 +Pavel Barta made a donation (2013/10).
2817 +Nikolay Pertsev made a donation (2014/5).
2818 +James B made a donation (2014/7, 2015/7, and 2021/12).
2819 +Stefano Di Biase made a donation (2014/8).
2820 +Daniel Epellei made a donation (2015/1).
2821 +OmegaPhil made a donation (2016/1, 2018/4).
2822 +Tomasz Szewczyk made a donation (2016/4).
2823 +James Burry made a donation (2016/12).
2824 +Carsten Rose made a donation (2018/9).
2825 +Porteus Kiosk made a donation (2018/10).
2826 +huronOS team: Enya Quetzalli made donations (2022/5, 2023/5 and 8).
2827 +Vasily Mikhaylichenko made a donation (2023/5).
2829 +Thank you very much.
2830 +Donations are always, including future donations, very important and
2831 +helpful for me to keep on developing aufs.
2835 +----------------------------------------
2836 +If you are an experienced user, no explanation is needed. Aufs is
2837 +just a linux filesystem.
2842 +# Local variables: ;
2845 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2846 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2847 +++ linux/fs/aufs/aufs.h 2022-11-05 23:02:18.959222617 +0100
2849 +/* SPDX-License-Identifier: GPL-2.0 */
2851 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2853 + * This program is free software; you can redistribute it and/or modify
2854 + * it under the terms of the GNU General Public License as published by
2855 + * the Free Software Foundation; either version 2 of the License, or
2856 + * (at your option) any later version.
2858 + * This program is distributed in the hope that it will be useful,
2859 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2860 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2861 + * GNU General Public License for more details.
2863 + * You should have received a copy of the GNU General Public License
2864 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2868 + * all header files
2876 +#define AuStub(type, name, body, ...) \
2877 + static inline type name(__VA_ARGS__) { body; }
2879 +#define AuStubVoid(name, ...) \
2880 + AuStub(void, name, , __VA_ARGS__)
2881 +#define AuStubInt0(name, ...) \
2882 + AuStub(int, name, return 0, __VA_ARGS__)
2886 +#include "branch.h"
2889 +#include "dbgaufs.h"
2890 +#include "dentry.h"
2892 +#include "dirren.h"
2895 +#include "fstype.h"
2900 +#include "module.h"
2904 +#include "sysaufs.h"
2909 +#endif /* __KERNEL__ */
2910 +#endif /* __AUFS_H__ */
2911 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2912 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2913 +++ linux/fs/aufs/branch.c 2022-11-05 23:02:18.959222617 +0100
2915 +// SPDX-License-Identifier: GPL-2.0
2917 + * Copyright (C) 2005-2022 Junjiro R. Okajima
2919 + * This program is free software; you can redistribute it and/or modify
2920 + * it under the terms of the GNU General Public License as published by
2921 + * the Free Software Foundation; either version 2 of the License, or
2922 + * (at your option) any later version.
2924 + * This program is distributed in the hope that it will be useful,
2925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2927 + * GNU General Public License for more details.
2929 + * You should have received a copy of the GNU General Public License
2930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2934 + * branch management
2937 +#include <linux/compat.h>
2938 +#include <linux/statfs.h>
2942 + * free a single branch
2944 +static void au_br_do_free(struct au_branch *br)
2947 + struct au_wbr *wbr;
2948 + struct au_dykey **key;
2950 + au_hnotify_fin_br(br);
2951 + /* always, regardless the mount option */
2952 + au_dr_hino_free(&br->br_dirren);
2955 + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0));
2956 + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0);
2957 + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0));
2958 + au_lcnt_fin(&br->br_count, /*do_sync*/0);
2962 + for (i = 0; i < AuBrWh_Last; i++)
2963 + dput(wbr->wbr_wh[i]);
2964 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2965 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2968 + if (br->br_fhsm) {
2969 + au_br_fhsm_fin(br->br_fhsm);
2970 + au_kfree_try_rcu(br->br_fhsm);
2973 + key = br->br_dykey;
2974 + for (i = 0; i < AuBrDynOp; i++, key++)
2980 + /* recursive lock, s_umount of branch's */
2981 + /* synchronize_rcu(); */ /* why? */
2983 + path_put(&br->br_path);
2985 + au_kfree_rcu(wbr);
2986 + au_lcnt_wait_for_fin(&br->br_nfiles);
2987 + au_lcnt_wait_for_fin(&br->br_count);
2988 + /* I don't know why, but percpu_refcount requires this */
2989 + /* synchronize_rcu(); */
2994 + * frees all branches
2996 +void au_br_free(struct au_sbinfo *sbinfo)
2998 + aufs_bindex_t bmax;
2999 + struct au_branch **br;
3001 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3003 + bmax = sbinfo->si_bbot + 1;
3004 + br = sbinfo->si_branch;
3006 + au_br_do_free(*br++);
3010 + * find the index of a branch which is specified by @br_id.
3012 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
3014 + aufs_bindex_t bindex, bbot;
3016 + bbot = au_sbbot(sb);
3017 + for (bindex = 0; bindex <= bbot; bindex++)
3018 + if (au_sbr_id(sb, bindex) == br_id)
3023 +/* ---------------------------------------------------------------------- */
3029 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
3030 + struct dentry *h_root)
3032 + if (unlikely(h_adding == h_root
3033 + || au_test_loopback_overlap(sb, h_adding)))
3035 + if (h_adding->d_sb != h_root->d_sb)
3037 + return au_test_subdir(h_adding, h_root)
3038 + || au_test_subdir(h_root, h_adding);
3042 + * returns a newly allocated branch. @new_nbranch is a number of branches
3043 + * after adding a branch.
3045 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3048 + struct au_branch *add_branch;
3049 + struct dentry *root;
3050 + struct inode *inode;
3054 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3055 + if (unlikely(!add_branch))
3057 + add_branch->br_xino = au_xino_alloc(/*nfile*/1);
3058 + if (unlikely(!add_branch->br_xino))
3060 + err = au_hnotify_init_br(add_branch, perm);
3061 + if (unlikely(err))
3064 + if (au_br_writable(perm)) {
3065 + /* may be freed separately at changing the branch permission */
3066 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3068 + if (unlikely(!add_branch->br_wbr))
3072 + if (au_br_fhsm(perm)) {
3073 + err = au_fhsm_br_alloc(add_branch);
3074 + if (unlikely(err))
3078 + root = sb->s_root;
3079 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3081 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3083 + inode = d_inode(root);
3084 + err = au_hinode_realloc(au_ii(inode), new_nbranch,
3088 + return add_branch; /* success */
3091 + au_kfree_rcu(add_branch->br_wbr);
3093 + au_hnotify_fin_br(add_branch);
3095 + au_xino_put(add_branch);
3097 + au_kfree_rcu(add_branch);
3099 + return ERR_PTR(err);
3103 + * test if the branch permission is legal or not.
3105 +static int test_br(struct inode *inode, int brperm, char *path)
3109 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3114 + pr_err("write permission for readonly mount or inode, %s\n", path);
3122 + * 0: success, the caller will add it
3123 + * plus: success, it is already unified, the caller should ignore it
3126 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3129 + aufs_bindex_t bbot, bindex;
3130 + struct dentry *root, *h_dentry;
3131 + struct inode *inode, *h_inode;
3133 + root = sb->s_root;
3134 + bbot = au_sbbot(sb);
3135 + if (unlikely(bbot >= 0
3136 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3140 + pr_err("%s duplicated\n", add->pathname);
3145 + err = -ENOSPC; /* -E2BIG; */
3146 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3147 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3148 + pr_err("number of branches exceeded %s\n", add->pathname);
3153 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3154 + pr_err("bad index %d\n", add->bindex);
3158 + inode = d_inode(add->path.dentry);
3160 + if (unlikely(!inode->i_nlink)) {
3161 + pr_err("no existence %s\n", add->pathname);
3166 + if (unlikely(inode->i_sb == sb)) {
3167 + pr_err("%s must be outside\n", add->pathname);
3171 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3172 + pr_err("unsupported filesystem, %s (%s)\n",
3173 + add->pathname, au_sbtype(inode->i_sb));
3177 + if (unlikely(inode->i_sb->s_stack_depth)) {
3178 + pr_err("already stacked, %s (%s)\n",
3179 + add->pathname, au_sbtype(inode->i_sb));
3183 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3184 + if (unlikely(err))
3188 + return 0; /* success */
3191 + for (bindex = 0; bindex <= bbot; bindex++)
3192 + if (unlikely(test_overlap(sb, add->path.dentry,
3193 + au_h_dptr(root, bindex)))) {
3194 + pr_err("%s is overlapped\n", add->pathname);
3199 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3200 + h_dentry = au_h_dptr(root, 0);
3201 + h_inode = d_inode(h_dentry);
3202 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3203 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3204 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3205 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3207 + i_uid_read(inode), i_gid_read(inode),
3208 + (inode->i_mode & S_IALLUGO),
3209 + i_uid_read(h_inode), i_gid_read(h_inode),
3210 + (h_inode->i_mode & S_IALLUGO));
3218 + * initialize or clean the whiteouts for an adding branch
3220 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3223 + int err, old_perm;
3224 + aufs_bindex_t bindex;
3225 + struct inode *h_inode;
3226 + struct au_wbr *wbr;
3227 + struct au_hinode *hdir;
3228 + struct dentry *h_dentry;
3230 + err = vfsub_mnt_want_write(au_br_mnt(br));
3231 + if (unlikely(err))
3235 + old_perm = br->br_perm;
3236 + br->br_perm = new_perm;
3239 + bindex = au_br_index(sb, br->br_id);
3240 + if (0 <= bindex) {
3241 + hdir = au_hi(d_inode(sb->s_root), bindex);
3242 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3244 + h_dentry = au_br_dentry(br);
3245 + h_inode = d_inode(h_dentry);
3246 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3249 + err = au_wh_init(br, sb);
3251 + wbr_wh_write_lock(wbr);
3252 + err = au_wh_init(br, sb);
3253 + wbr_wh_write_unlock(wbr);
3256 + au_hn_inode_unlock(hdir);
3258 + inode_unlock(h_inode);
3259 + vfsub_mnt_drop_write(au_br_mnt(br));
3260 + br->br_perm = old_perm;
3262 + if (!err && wbr && !au_br_writable(new_perm)) {
3263 + au_kfree_rcu(wbr);
3264 + br->br_wbr = NULL;
3271 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3275 + struct kstatfs kst;
3276 + struct au_wbr *wbr;
3279 + au_rw_init(&wbr->wbr_wh_rwsem);
3280 + atomic_set(&wbr->wbr_wh_running, 0);
3283 + * a limit for rmdir/rename a dir
3284 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3286 + err = vfs_statfs(&br->br_path, &kst);
3287 + if (unlikely(err))
3290 + if (kst.f_namelen >= NAME_MAX)
3291 + err = au_br_init_wh(sb, br, perm);
3293 + pr_err("%pd(%s), unsupported namelen %ld\n",
3295 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3301 +/* initialize a new branch */
3302 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3303 + struct au_opt_add *add)
3306 + struct au_branch *brbase;
3308 + struct inode *h_inode;
3311 + br->br_perm = add->perm;
3312 + br->br_path = add->path; /* set first, path_get() later */
3313 + spin_lock_init(&br->br_dykey_lock);
3314 + au_lcnt_init(&br->br_nfiles, /*release*/NULL);
3315 + au_lcnt_init(&br->br_count, /*release*/NULL);
3316 + br->br_id = au_new_br_id(sb);
3317 + AuDebugOn(br->br_id < 0);
3319 + /* always, regardless the given option */
3320 + err = au_dr_br_init(sb, br, &add->path);
3321 + if (unlikely(err))
3324 + if (au_br_writable(add->perm)) {
3325 + err = au_wbr_init(br, sb, add->perm);
3326 + if (unlikely(err))
3330 + if (au_opt_test(au_mntflags(sb), XINO)) {
3331 + brbase = au_sbr(sb, 0);
3332 + xf = au_xino_file(brbase->br_xino, /*idx*/-1);
3334 + h_inode = d_inode(add->path.dentry);
3335 + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path);
3336 + if (unlikely(err)) {
3337 + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1));
3342 + sysaufs_br_init(br);
3343 + path_get(&br->br_path);
3344 + goto out; /* success */
3347 + memset(&br->br_path, 0, sizeof(br->br_path));
3352 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3353 + struct au_branch *br, aufs_bindex_t bbot,
3354 + aufs_bindex_t amount)
3356 + struct au_branch **brp;
3358 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3360 + brp = sbinfo->si_branch + bindex;
3361 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3363 + sbinfo->si_bbot++;
3364 + if (unlikely(bbot < 0))
3365 + sbinfo->si_bbot = 0;
3368 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3369 + aufs_bindex_t bbot, aufs_bindex_t amount)
3371 + struct au_hdentry *hdp;
3373 + AuRwMustWriteLock(&dinfo->di_rwsem);
3375 + hdp = au_hdentry(dinfo, bindex);
3376 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3377 + au_h_dentry_init(hdp);
3379 + if (unlikely(bbot < 0))
3380 + dinfo->di_btop = 0;
3383 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3384 + aufs_bindex_t bbot, aufs_bindex_t amount)
3386 + struct au_hinode *hip;
3388 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3390 + hip = au_hinode(iinfo, bindex);
3391 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3392 + au_hinode_init(hip);
3394 + if (unlikely(bbot < 0))
3395 + iinfo->ii_btop = 0;
3398 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3399 + aufs_bindex_t bindex)
3401 + struct dentry *root, *h_dentry;
3402 + struct inode *root_inode, *h_inode;
3403 + aufs_bindex_t bbot, amount;
3405 + root = sb->s_root;
3406 + root_inode = d_inode(root);
3407 + bbot = au_sbbot(sb);
3408 + amount = bbot + 1 - bindex;
3409 + h_dentry = au_br_dentry(br);
3410 + au_sbilist_lock();
3411 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3412 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3413 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3414 + au_set_h_dptr(root, bindex, dget(h_dentry));
3415 + h_inode = d_inode(h_dentry);
3416 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3417 + au_sbilist_unlock();
3420 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3423 + aufs_bindex_t bbot, add_bindex;
3424 + struct dentry *root, *h_dentry;
3425 + struct inode *root_inode;
3426 + struct au_branch *add_branch;
3428 + root = sb->s_root;
3429 + root_inode = d_inode(root);
3430 + IMustLock(root_inode);
3431 + IiMustWriteLock(root_inode);
3432 + err = test_add(sb, add, remount);
3433 + if (unlikely(err < 0))
3437 + goto out; /* success */
3440 + bbot = au_sbbot(sb);
3441 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3442 + err = PTR_ERR(add_branch);
3443 + if (IS_ERR(add_branch))
3446 + err = au_br_init(add_branch, sb, add);
3447 + if (unlikely(err)) {
3448 + au_br_do_free(add_branch);
3452 + add_bindex = add->bindex;
3453 + sysaufs_brs_del(sb, add_bindex); /* remove successors */
3454 + au_br_do_add(sb, add_branch, add_bindex);
3455 + sysaufs_brs_add(sb, add_bindex); /* append successors */
3456 + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */
3458 + h_dentry = add->path.dentry;
3459 + if (!add_bindex) {
3460 + au_cpup_attr_all(root_inode, /*force*/1);
3461 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3463 + au_add_nlink(root_inode, d_inode(h_dentry));
3469 +/* ---------------------------------------------------------------------- */
3471 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3472 + unsigned long long max __maybe_unused,
3475 + unsigned long long n;
3476 + struct file **p, *f;
3477 + struct hlist_bl_head *files;
3478 + struct hlist_bl_node *pos;
3479 + struct au_finfo *finfo;
3483 + files = &au_sbi(sb)->si_files;
3484 + hlist_bl_lock(files);
3485 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
3486 + f = finfo->fi_file;
3488 + && !special_file(file_inode(f)->i_mode)) {
3492 + AuDebugOn(n > max);
3495 + hlist_bl_unlock(files);
3500 +static struct file **au_farray_alloc(struct super_block *sb,
3501 + unsigned long long *max)
3503 + struct au_sbinfo *sbi;
3506 + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1);
3507 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3510 +static void au_farray_free(struct file **a, unsigned long long max)
3512 + unsigned long long ull;
3514 + for (ull = 0; ull < max; ull++)
3520 +/* ---------------------------------------------------------------------- */
3526 +/* to show the line number, do not make it inlined function */
3527 +#define AuVerbose(do_info, fmt, ...) do { \
3529 + pr_info(fmt, ##__VA_ARGS__); \
3532 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3533 + aufs_bindex_t bbot)
3535 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3538 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3539 + aufs_bindex_t bbot)
3541 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3545 + * test if the branch is deletable or not.
3547 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3548 + unsigned int sigen, const unsigned int verbose)
3550 + int err, i, j, ndentry;
3551 + aufs_bindex_t btop, bbot;
3552 + struct au_dcsub_pages dpages;
3553 + struct au_dpage *dpage;
3556 + err = au_dpages_init(&dpages, GFP_NOFS);
3557 + if (unlikely(err))
3559 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3560 + if (unlikely(err))
3563 + for (i = 0; !err && i < dpages.ndpage; i++) {
3564 + dpage = dpages.dpages + i;
3565 + ndentry = dpage->ndentry;
3566 + for (j = 0; !err && j < ndentry; j++) {
3567 + d = dpage->dentries[j];
3568 + AuDebugOn(au_dcount(d) <= 0);
3569 + if (!au_digen_test(d, sigen)) {
3570 + di_read_lock_child(d, AuLock_IR);
3571 + if (unlikely(au_dbrange_test(d))) {
3572 + di_read_unlock(d, AuLock_IR);
3576 + di_write_lock_child(d);
3577 + if (unlikely(au_dbrange_test(d))) {
3578 + di_write_unlock(d);
3581 + err = au_reval_dpath(d, sigen);
3583 + di_downgrade_lock(d, AuLock_IR);
3585 + di_write_unlock(d);
3590 + /* AuDbgDentry(d); */
3591 + btop = au_dbtop(d);
3592 + bbot = au_dbbot(d);
3593 + if (btop <= bindex
3595 + && au_h_dptr(d, bindex)
3596 + && au_test_dbusy(d, btop, bbot)) {
3598 + AuVerbose(verbose, "busy %pd\n", d);
3601 + di_read_unlock(d, AuLock_IR);
3606 + au_dpages_free(&dpages);
3611 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3612 + unsigned int sigen, const unsigned int verbose)
3615 + unsigned long long max, ull;
3616 + struct inode *i, **array;
3617 + aufs_bindex_t btop, bbot;
3619 + array = au_iarray_alloc(sb, &max);
3620 + err = PTR_ERR(array);
3621 + if (IS_ERR(array))
3625 + AuDbg("b%d\n", bindex);
3626 + for (ull = 0; !err && ull < max; ull++) {
3630 + if (i->i_ino == AUFS_ROOT_INO)
3633 + /* AuDbgInode(i); */
3634 + if (au_iigen(i, NULL) == sigen)
3635 + ii_read_lock_child(i);
3637 + ii_write_lock_child(i);
3638 + err = au_refresh_hinode_self(i);
3641 + ii_downgrade_lock(i);
3643 + ii_write_unlock(i);
3648 + btop = au_ibtop(i);
3649 + bbot = au_ibbot(i);
3650 + if (btop <= bindex
3652 + && au_h_iptr(i, bindex)
3653 + && au_test_ibusy(i, btop, bbot)) {
3655 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3658 + ii_read_unlock(i);
3660 + au_iarray_free(array, max);
3666 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3667 + const unsigned int verbose)
3670 + unsigned int sigen;
3672 + sigen = au_sigen(root->d_sb);
3673 + DiMustNoWaiters(root);
3674 + IiMustNoWaiters(d_inode(root));
3675 + di_write_unlock(root);
3676 + err = test_dentry_busy(root, bindex, sigen, verbose);
3678 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3679 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3684 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3685 + struct file **to_free, int *idx)
3688 + unsigned char matched, root;
3689 + aufs_bindex_t bindex, bbot;
3690 + struct au_fidir *fidir;
3691 + struct au_hfile *hfile;
3694 + root = IS_ROOT(file->f_path.dentry);
3697 + to_free[*idx] = file;
3703 + fidir = au_fi(file)->fi_hdir;
3704 + AuDebugOn(!fidir);
3705 + bbot = au_fbbot_dir(file);
3706 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3707 + hfile = fidir->fd_hfile + bindex;
3708 + if (!hfile->hf_file)
3711 + if (hfile->hf_br->br_id == br_id) {
3723 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3724 + struct file **to_free, int opened)
3727 + unsigned long long ull, max;
3728 + aufs_bindex_t btop;
3729 + struct file *file, **array;
3730 + struct dentry *root;
3731 + struct au_hfile *hfile;
3733 + array = au_farray_alloc(sb, &max);
3734 + err = PTR_ERR(array);
3735 + if (IS_ERR(array))
3740 + root = sb->s_root;
3741 + di_write_unlock(root);
3742 + for (ull = 0; ull < max; ull++) {
3743 + file = array[ull];
3744 + if (unlikely(!file))
3747 + /* AuDbg("%pD\n", file); */
3748 + fi_read_lock(file);
3749 + btop = au_fbtop(file);
3750 + if (!d_is_dir(file->f_path.dentry)) {
3751 + hfile = &au_fi(file)->fi_htop;
3752 + if (hfile->hf_br->br_id == br_id)
3755 + err = test_dir_busy(file, br_id, to_free, &idx);
3756 + fi_read_unlock(file);
3757 + if (unlikely(err))
3760 + di_write_lock_child(root);
3761 + au_farray_free(array, max);
3762 + AuDebugOn(idx > opened);
3768 +static void br_del_file(struct file **to_free, unsigned long long opened,
3769 + aufs_bindex_t br_id)
3771 + unsigned long long ull;
3772 + aufs_bindex_t bindex, btop, bbot, bfound;
3773 + struct file *file;
3774 + struct au_fidir *fidir;
3775 + struct au_hfile *hfile;
3777 + for (ull = 0; ull < opened; ull++) {
3778 + file = to_free[ull];
3779 + if (unlikely(!file))
3782 + /* AuDbg("%pD\n", file); */
3783 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3785 + fidir = au_fi(file)->fi_hdir;
3786 + AuDebugOn(!fidir);
3787 + fi_write_lock(file);
3788 + btop = au_fbtop(file);
3789 + bbot = au_fbbot_dir(file);
3790 + for (bindex = btop; bindex <= bbot; bindex++) {
3791 + hfile = fidir->fd_hfile + bindex;
3792 + if (!hfile->hf_file)
3795 + if (hfile->hf_br->br_id == br_id) {
3800 + AuDebugOn(bfound < 0);
3801 + au_set_h_fptr(file, bfound, NULL);
3802 + if (bfound == btop) {
3803 + for (btop++; btop <= bbot; btop++)
3804 + if (au_hf_dir(file, btop)) {
3805 + au_set_fbtop(file, btop);
3809 + fi_write_unlock(file);
3813 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3814 + const aufs_bindex_t bindex,
3815 + const aufs_bindex_t bbot)
3817 + struct au_branch **brp, **p;
3819 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3821 + brp = sbinfo->si_branch + bindex;
3822 + if (bindex < bbot)
3823 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3824 + sbinfo->si_branch[0 + bbot] = NULL;
3825 + sbinfo->si_bbot--;
3827 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3830 + sbinfo->si_branch = p;
3831 + /* harmless error */
3834 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3835 + const aufs_bindex_t bbot)
3837 + struct au_hdentry *hdp, *p;
3839 + AuRwMustWriteLock(&dinfo->di_rwsem);
3841 + hdp = au_hdentry(dinfo, bindex);
3842 + if (bindex < bbot)
3843 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3844 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3847 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3850 + dinfo->di_hdentry = p;
3851 + /* harmless error */
3854 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3855 + const aufs_bindex_t bbot)
3857 + struct au_hinode *hip, *p;
3859 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3861 + hip = au_hinode(iinfo, bindex);
3862 + if (bindex < bbot)
3863 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3864 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3867 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3870 + iinfo->ii_hinode = p;
3871 + /* harmless error */
3874 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3875 + struct au_branch *br)
3877 + aufs_bindex_t bbot;
3878 + struct au_sbinfo *sbinfo;
3879 + struct dentry *root, *h_root;
3880 + struct inode *inode, *h_inode;
3881 + struct au_hinode *hinode;
3883 + SiMustWriteLock(sb);
3885 + root = sb->s_root;
3886 + inode = d_inode(root);
3887 + sbinfo = au_sbi(sb);
3888 + bbot = sbinfo->si_bbot;
3890 + h_root = au_h_dptr(root, bindex);
3891 + hinode = au_hi(inode, bindex);
3892 + h_inode = au_igrab(hinode->hi_inode);
3895 + au_sbilist_lock();
3896 + au_br_do_del_brp(sbinfo, bindex, bbot);
3897 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3898 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3899 + au_sbilist_unlock();
3901 + /* ignore an error */
3902 + au_dr_br_fin(sb, br); /* always, regardless the mount option */
3906 + au_br_do_free(br);
3909 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3910 + unsigned long long max, void *arg)
3915 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3918 + unsigned long long opened;
3919 + unsigned int mnt_flags;
3920 + aufs_bindex_t bindex, bbot, br_id;
3921 + unsigned char do_wh, verbose;
3922 + struct au_branch *br;
3923 + struct au_wbr *wbr;
3924 + struct dentry *root;
3925 + struct file **to_free;
3930 + root = sb->s_root;
3931 + bindex = au_find_dbindex(root, del->h_path.dentry);
3934 + goto out; /* success */
3936 + pr_err("%s no such branch\n", del->pathname);
3939 + AuDbg("bindex b%d\n", bindex);
3942 + mnt_flags = au_mntflags(sb);
3943 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3944 + bbot = au_sbbot(sb);
3945 + if (unlikely(!bbot)) {
3946 + AuVerbose(verbose, "no more branches left\n");
3950 + br = au_sbr(sb, bindex);
3951 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3952 + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) {
3953 + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry);
3957 + br_id = br->br_id;
3958 + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1);
3959 + if (unlikely(opened)) {
3960 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3961 + err = PTR_ERR(to_free);
3962 + if (IS_ERR(to_free))
3965 + err = test_file_busy(sb, br_id, to_free, opened);
3966 + if (unlikely(err)) {
3967 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3973 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3975 + /* instead of WbrWhMustWriteLock(wbr) */
3976 + SiMustWriteLock(sb);
3977 + for (i = 0; i < AuBrWh_Last; i++) {
3978 + dput(wbr->wbr_wh[i]);
3979 + wbr->wbr_wh[i] = NULL;
3983 + err = test_children_busy(root, bindex, verbose);
3984 + if (unlikely(err)) {
3993 + * now we confirmed the branch is deletable.
3994 + * let's free the remaining opened dirs on the branch.
3996 + di_write_unlock(root);
3997 + br_del_file(to_free, opened, br_id);
3998 + di_write_lock_child(root);
4001 + sysaufs_brs_del(sb, bindex); /* remove successors */
4002 + dbgaufs_xino_del(br); /* remove one */
4003 + au_br_do_del(sb, bindex, br);
4004 + sysaufs_brs_add(sb, bindex); /* append successors */
4005 + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */
4008 + au_cpup_attr_all(d_inode(root), /*force*/1);
4009 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
4011 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
4012 + if (au_opt_test(mnt_flags, PLINK))
4013 + au_plink_half_refresh(sb, br_id);
4015 + goto out; /* success */
4019 + rerr = au_br_init_wh(sb, br, br->br_perm);
4021 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
4022 + del->pathname, rerr);
4025 + au_farray_free(to_free, opened);
4029 +/* ---------------------------------------------------------------------- */
4031 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
4034 + aufs_bindex_t btop, bbot;
4035 + struct aufs_ibusy ibusy;
4036 + struct inode *inode, *h_inode;
4039 + if (unlikely(!capable(CAP_SYS_ADMIN)))
4042 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
4044 + /* VERIFY_WRITE */
4045 + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino));
4046 + if (unlikely(err)) {
4053 + si_read_lock(sb, AuLock_FLUSH);
4054 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4058 + ibusy.h_ino = 0; /* invalid */
4059 + inode = ilookup(sb, ibusy.ino);
4061 + || inode->i_ino == AUFS_ROOT_INO
4062 + || au_is_bad_inode(inode))
4065 + ii_read_lock_child(inode);
4066 + btop = au_ibtop(inode);
4067 + bbot = au_ibbot(inode);
4068 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4069 + h_inode = au_h_iptr(inode, ibusy.bindex);
4070 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4071 + ibusy.h_ino = h_inode->i_ino;
4073 + ii_read_unlock(inode);
4077 + si_read_unlock(sb);
4079 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4080 + if (unlikely(err)) {
4089 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4091 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4094 +#ifdef CONFIG_COMPAT
4095 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4097 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4101 +/* ---------------------------------------------------------------------- */
4104 + * change a branch permission
4107 +static void au_warn_ima(void)
4110 + /* since it doesn't support mark_files_ro() */
4111 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4115 +static int do_need_sigen_inc(int a, int b)
4117 + return au_br_whable(a) && !au_br_whable(b);
4120 +static int need_sigen_inc(int old, int new)
4122 + return do_need_sigen_inc(old, new)
4123 + || do_need_sigen_inc(new, old);
4126 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4129 + unsigned int mnt_flags;
4130 + unsigned long long ull, max;
4131 + aufs_bindex_t br_id;
4132 + unsigned char verbose, writer;
4133 + struct file *file, *hf, **array;
4134 + struct au_hfile *hfile;
4135 + struct inode *h_inode;
4137 + mnt_flags = au_mntflags(sb);
4138 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4140 + array = au_farray_alloc(sb, &max);
4141 + err = PTR_ERR(array);
4142 + if (IS_ERR(array))
4146 + br_id = au_sbr_id(sb, bindex);
4147 + for (ull = 0; ull < max; ull++) {
4148 + file = array[ull];
4149 + if (unlikely(!file))
4152 + /* AuDbg("%pD\n", file); */
4153 + fi_read_lock(file);
4154 + if (unlikely(au_test_mmapped(file))) {
4156 + AuVerbose(verbose, "mmapped %pD\n", file);
4158 + FiMustNoWaiters(file);
4159 + fi_read_unlock(file);
4163 + hfile = &au_fi(file)->fi_htop;
4164 + hf = hfile->hf_file;
4165 + if (!d_is_reg(file->f_path.dentry)
4166 + || !(file->f_mode & FMODE_WRITE)
4167 + || hfile->hf_br->br_id != br_id
4168 + || !(hf->f_mode & FMODE_WRITE))
4169 + array[ull] = NULL;
4175 + FiMustNoWaiters(file);
4176 + fi_read_unlock(file);
4184 + for (ull = 0; ull < max; ull++) {
4185 + file = array[ull];
4189 + /* todo: already flushed? */
4191 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4192 + * approach which resets f_mode and calls mnt_drop_write() and
4193 + * file_release_write() for each file, because the branch
4194 + * attribute in aufs world is totally different from the native
4197 + /* fi_read_lock(file); */
4198 + hfile = &au_fi(file)->fi_htop;
4199 + hf = hfile->hf_file;
4200 + /* fi_read_unlock(file); */
4201 + spin_lock(&hf->f_lock);
4202 + writer = !!(hf->f_mode & FMODE_WRITER);
4203 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4204 + spin_unlock(&hf->f_lock);
4206 + h_inode = file_inode(hf);
4207 + if (hf->f_mode & FMODE_READ)
4208 + i_readcount_inc(h_inode);
4209 + put_write_access(h_inode);
4210 + __mnt_drop_write(hf->f_path.mnt);
4215 + au_farray_free(array, max);
4221 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4225 + aufs_bindex_t bindex;
4226 + struct dentry *root;
4227 + struct au_branch *br;
4228 + struct au_br_fhsm *bf;
4230 + root = sb->s_root;
4231 + bindex = au_find_dbindex(root, mod->h_root);
4234 + return 0; /* success */
4236 + pr_err("%s no such branch\n", mod->path);
4239 + AuDbg("bindex b%d\n", bindex);
4241 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4242 + if (unlikely(err))
4245 + br = au_sbr(sb, bindex);
4246 + AuDebugOn(mod->h_root != au_br_dentry(br));
4247 + if (br->br_perm == mod->perm)
4248 + return 0; /* success */
4250 + /* pre-allocate for non-fhsm --> fhsm */
4252 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4253 + err = au_fhsm_br_alloc(br);
4254 + if (unlikely(err))
4257 + br->br_fhsm = NULL;
4260 + if (au_br_writable(br->br_perm)) {
4261 + /* remove whiteout base */
4262 + err = au_br_init_wh(sb, br, mod->perm);
4263 + if (unlikely(err))
4266 + if (!au_br_writable(mod->perm)) {
4267 + /* rw --> ro, file might be mmapped */
4268 + DiMustNoWaiters(root);
4269 + IiMustNoWaiters(d_inode(root));
4270 + di_write_unlock(root);
4271 + err = au_br_mod_files_ro(sb, bindex);
4272 + /* aufs_write_lock() calls ..._child() */
4273 + di_write_lock_child(root);
4275 + if (unlikely(err)) {
4277 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4280 + rerr = au_wbr_init(br, sb, br->br_perm);
4281 + if (unlikely(rerr)) {
4282 + AuIOErr("nested error %d (%d)\n",
4284 + br->br_perm = mod->perm;
4288 + } else if (au_br_writable(mod->perm)) {
4291 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4293 + err = au_wbr_init(br, sb, mod->perm);
4294 + if (unlikely(err)) {
4295 + au_kfree_rcu(br->br_wbr);
4296 + br->br_wbr = NULL;
4300 + if (unlikely(err))
4303 + if (au_br_fhsm(br->br_perm)) {
4304 + if (!au_br_fhsm(mod->perm)) {
4305 + /* fhsm --> non-fhsm */
4306 + au_br_fhsm_fin(br->br_fhsm);
4307 + au_kfree_rcu(br->br_fhsm);
4308 + br->br_fhsm = NULL;
4310 + } else if (au_br_fhsm(mod->perm))
4311 + /* non-fhsm --> fhsm */
4314 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4315 + br->br_perm = mod->perm;
4316 + goto out; /* success */
4319 + au_kfree_try_rcu(bf);
4325 +/* ---------------------------------------------------------------------- */
4327 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4330 + struct kstatfs kstfs;
4332 + err = vfs_statfs(&br->br_path, &kstfs);
4334 + stfs->f_blocks = kstfs.f_blocks;
4335 + stfs->f_bavail = kstfs.f_bavail;
4336 + stfs->f_files = kstfs.f_files;
4337 + stfs->f_ffree = kstfs.f_ffree;
4342 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4343 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4344 +++ linux/fs/aufs/branch.h 2023-08-28 12:34:39.956636132 +0200
4346 +/* SPDX-License-Identifier: GPL-2.0 */
4348 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4350 + * This program is free software; you can redistribute it and/or modify
4351 + * it under the terms of the GNU General Public License as published by
4352 + * the Free Software Foundation; either version 2 of the License, or
4353 + * (at your option) any later version.
4355 + * This program is distributed in the hope that it will be useful,
4356 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4357 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4358 + * GNU General Public License for more details.
4360 + * You should have received a copy of the GNU General Public License
4361 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4365 + * branch filesystems and xino for them
4368 +#ifndef __AUFS_BRANCH_H__
4369 +#define __AUFS_BRANCH_H__
4373 +#include <linux/mount.h>
4374 +#include "dirren.h"
4380 +/* ---------------------------------------------------------------------- */
4384 + struct file **xi_file;
4385 + unsigned int xi_nfile;
4391 + /* reserved for future use */
4392 + /* unsigned long *bitmap; */
4393 + wait_queue_head_t wqh;
4396 + struct mutex xi_mtx; /* protects xi_file array */
4397 + struct hlist_bl_head xi_writing;
4399 + atomic_t xi_truncating;
4401 + struct kref xi_kref;
4404 +/* File-based Hierarchical Storage Management */
4405 +struct au_br_fhsm {
4406 +#ifdef CONFIG_AUFS_FHSM
4407 + struct mutex bf_lock;
4408 + unsigned long bf_jiffy;
4409 + struct aufs_stfs bf_stfs;
4414 +/* members for writable branch only */
4415 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4417 + struct au_rwsem wbr_wh_rwsem;
4418 + struct dentry *wbr_wh[AuBrWh_Last];
4419 + atomic_t wbr_wh_running;
4420 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4421 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4422 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4425 + unsigned long long wbr_bytes;
4428 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4429 +#define AuBrDynOp (AuDyLast * 4)
4431 +#ifdef CONFIG_AUFS_HFSNOTIFY
4432 +/* support for asynchronous destruction */
4433 +struct au_br_hfsnotify {
4434 + struct fsnotify_group *hfsn_group;
4438 +/* sysfs entries */
4439 +struct au_brsysfs {
4441 + struct attribute attr;
4450 +/* protected by superblock rwsem */
4452 + struct au_xino *br_xino;
4454 + aufs_bindex_t br_id;
4457 + struct path br_path;
4458 + spinlock_t br_dykey_lock;
4459 + struct au_dykey *br_dykey[AuBrDynOp];
4460 + au_lcnt_t br_nfiles; /* opened files */
4461 + au_lcnt_t br_count; /* in-use for other */
4463 + struct au_wbr *br_wbr;
4464 + struct au_br_fhsm *br_fhsm;
4466 +#ifdef CONFIG_AUFS_HFSNOTIFY
4467 + struct au_br_hfsnotify *br_hfsn;
4470 +#ifdef CONFIG_SYSFS
4471 + /* entries under sysfs per mount-point */
4472 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4475 +#ifdef CONFIG_DEBUG_FS
4476 + struct dentry *br_dbgaufs; /* xino */
4479 + struct au_dr_br br_dirren;
4482 +/* ---------------------------------------------------------------------- */
4484 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4486 + return br->br_path.mnt;
4489 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4491 + return br->br_path.dentry;
4494 +static inline struct mnt_idmap *au_br_idmap(struct au_branch *br)
4496 + return mnt_idmap(br->br_path.mnt);
4499 +static inline struct super_block *au_br_sb(struct au_branch *br)
4501 + return au_br_mnt(br)->mnt_sb;
4504 +static inline int au_br_rdonly(struct au_branch *br)
4506 + return (sb_rdonly(au_br_sb(br))
4507 + || !au_br_writable(br->br_perm))
4511 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4513 +#ifdef CONFIG_AUFS_HNOTIFY
4514 + return !(brperm & AuBrPerm_RR);
4520 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4522 + int err, exec_flag;
4525 + exec_flag = oflag & __FMODE_EXEC;
4526 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4532 +static inline void au_xino_get(struct au_branch *br)
4534 + struct au_xino *xi;
4538 + kref_get(&xi->xi_kref);
4541 +static inline int au_xino_count(struct au_branch *br)
4544 + struct au_xino *xi;
4549 + v = kref_read(&xi->xi_kref);
4554 +/* ---------------------------------------------------------------------- */
4558 +void au_br_free(struct au_sbinfo *sinfo);
4559 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4561 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4563 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4564 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4565 +#ifdef CONFIG_COMPAT
4566 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4569 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4572 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4575 +static const loff_t au_loff_max = LLONG_MAX;
4577 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry);
4578 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
4580 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
4581 + struct file *copy_src);
4583 + struct au_xino *xi; /* switch between xino and xigen */
4585 + struct path *base;
4586 + struct file *copy_src;
4588 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew);
4590 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4592 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4594 +ssize_t xino_fread(struct file *file, void *buf, size_t size, loff_t *pos);
4595 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos);
4597 +int au_xib_trunc(struct super_block *sb);
4598 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin);
4600 +struct au_xino *au_xino_alloc(unsigned int nfile);
4601 +int au_xino_put(struct au_branch *br);
4602 +struct file *au_xino_file1(struct au_xino *xi);
4604 +struct au_opt_xino;
4605 +void au_xino_clr(struct super_block *sb);
4606 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount);
4607 +struct file *au_xino_def(struct super_block *sb);
4608 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4609 + struct path *base);
4611 +ino_t au_xino_new_ino(struct super_block *sb);
4612 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4614 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
4615 + ino_t h_ino, int idx);
4616 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4619 +int au_xino_path(struct seq_file *seq, struct file *file);
4621 +/* ---------------------------------------------------------------------- */
4623 +/* @idx is signed to accept -1 meaning the first file */
4624 +static inline struct file *au_xino_file(struct au_xino *xi, int idx)
4626 + struct file *file;
4633 + if (idx < xi->xi_nfile)
4634 + file = xi->xi_file[idx];
4636 + file = au_xino_file1(xi);
4642 +/* ---------------------------------------------------------------------- */
4644 +/* Superblock to branch */
4646 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4648 + return au_sbr(sb, bindex)->br_id;
4652 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4654 + return au_br_mnt(au_sbr(sb, bindex));
4658 +struct mnt_idmap *au_sbr_idmap(struct super_block *sb, aufs_bindex_t bindex)
4660 + return au_br_idmap(au_sbr(sb, bindex));
4664 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4666 + return au_br_sb(au_sbr(sb, bindex));
4669 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4671 + return au_sbr(sb, bindex)->br_perm;
4674 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4676 + return au_br_whable(au_sbr_perm(sb, bindex));
4679 +/* ---------------------------------------------------------------------- */
4681 +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem)
4682 +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem)
4683 +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem)
4684 +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem)
4686 +#define wbr_wh_read_trylock_nested(wbr) \
4687 + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem)
4688 +#define wbr_wh_write_trylock_nested(wbr) \
4689 + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem)
4692 +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem)
4693 +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem)
4694 +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem)
4696 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem)
4697 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem)
4698 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem)
4700 +/* ---------------------------------------------------------------------- */
4702 +#ifdef CONFIG_AUFS_FHSM
4703 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4705 + mutex_init(&brfhsm->bf_lock);
4706 + brfhsm->bf_jiffy = 0;
4707 + brfhsm->bf_readable = 0;
4710 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4712 + mutex_destroy(&brfhsm->bf_lock);
4715 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4716 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4719 +#endif /* __KERNEL__ */
4720 +#endif /* __AUFS_BRANCH_H__ */
4721 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4722 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4723 +++ linux/fs/aufs/conf.mk 2022-11-05 23:02:18.959222617 +0100
4725 +# SPDX-License-Identifier: GPL-2.0
4727 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4731 +AuConfStr += ${1}=${${1}}
4735 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4737 + HNOTIFY HFSNOTIFY \
4749 +$(foreach i, ${AuConfAll}, \
4750 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4752 +AuConfName = ${obj}/conf.str
4753 +${AuConfName}.tmp: FORCE
4754 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4755 +${AuConfName}: ${AuConfName}.tmp
4756 + @diff -q $< $@ > /dev/null 2>&1 || { \
4757 + echo ' GEN ' $@; \
4761 +clean-files += ${AuConfName} ${AuConfName}.tmp
4762 +${obj}/sysfs.o: ${AuConfName}
4764 +-include ${srctree}/${src}/conf_priv.mk
4765 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4766 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4767 +++ linux/fs/aufs/cpup.c 2023-08-28 12:34:39.956636132 +0200
4769 +// SPDX-License-Identifier: GPL-2.0
4771 + * Copyright (C) 2005-2022 Junjiro R. Okajima
4773 + * This program is free software; you can redistribute it and/or modify
4774 + * it under the terms of the GNU General Public License as published by
4775 + * the Free Software Foundation; either version 2 of the License, or
4776 + * (at your option) any later version.
4778 + * This program is distributed in the hope that it will be useful,
4779 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4780 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4781 + * GNU General Public License for more details.
4783 + * You should have received a copy of the GNU General Public License
4784 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4788 + * copy-up functions, see wbr_policy.c for copy-down
4791 +#include <linux/fs_stack.h>
4792 +#include <linux/mm.h>
4793 +#include <linux/task_work.h>
4796 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4798 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4799 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4801 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4803 + dst->i_flags |= iflags & ~mask;
4804 + if (au_test_fs_notime(dst->i_sb))
4805 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4808 +void au_cpup_attr_timesizes(struct inode *inode)
4810 + struct inode *h_inode;
4812 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4813 + fsstack_copy_attr_times(inode, h_inode);
4814 + fsstack_copy_inode_size(inode, h_inode);
4817 +void au_cpup_attr_nlink(struct inode *inode, int force)
4819 + struct inode *h_inode;
4820 + struct super_block *sb;
4821 + aufs_bindex_t bindex, bbot;
4824 + bindex = au_ibtop(inode);
4825 + h_inode = au_h_iptr(inode, bindex);
4827 + && !S_ISDIR(h_inode->i_mode)
4828 + && au_opt_test(au_mntflags(sb), PLINK)
4829 + && au_plink_test(inode))
4833 + * 0 can happen in revalidating.
4834 + * h_inode->i_mutex may not be held here, but it is harmless since once
4835 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4837 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4838 + * the incorrect link count.
4840 + set_nlink(inode, h_inode->i_nlink);
4843 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4844 + * it may includes whplink directory.
4846 + if (S_ISDIR(h_inode->i_mode)) {
4847 + bbot = au_ibbot(inode);
4848 + for (bindex++; bindex <= bbot; bindex++) {
4849 + h_inode = au_h_iptr(inode, bindex);
4851 + au_add_nlink(inode, h_inode);
4856 +void au_cpup_attr_changeable(struct inode *inode)
4858 + struct inode *h_inode;
4860 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4861 + inode->i_mode = h_inode->i_mode;
4862 + inode->i_uid = h_inode->i_uid;
4863 + inode->i_gid = h_inode->i_gid;
4864 + au_cpup_attr_timesizes(inode);
4865 + au_cpup_attr_flags(inode, h_inode->i_flags);
4868 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4870 + struct au_iinfo *iinfo = au_ii(inode);
4872 + IiMustWriteLock(inode);
4874 + iinfo->ii_higen = h_inode->i_generation;
4875 + iinfo->ii_hsb1 = h_inode->i_sb;
4878 +void au_cpup_attr_all(struct inode *inode, int force)
4880 + struct inode *h_inode;
4882 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4883 + au_cpup_attr_changeable(inode);
4884 + if (inode->i_nlink > 0)
4885 + au_cpup_attr_nlink(inode, force);
4886 + inode->i_rdev = h_inode->i_rdev;
4887 + inode->i_blkbits = h_inode->i_blkbits;
4888 + au_cpup_igen(inode, h_inode);
4891 +/* ---------------------------------------------------------------------- */
4893 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4895 +/* keep the timestamps of the parent dir when cpup */
4896 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4897 + struct path *h_path)
4899 + struct inode *h_inode;
4901 + dt->dt_dentry = dentry;
4902 + dt->dt_h_path = *h_path;
4903 + h_inode = d_inode(h_path->dentry);
4904 + dt->dt_atime = h_inode->i_atime;
4905 + dt->dt_mtime = h_inode->i_mtime;
4909 +void au_dtime_revert(struct au_dtime *dt)
4911 + struct iattr attr;
4914 + attr.ia_atime = dt->dt_atime;
4915 + attr.ia_mtime = dt->dt_mtime;
4916 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4917 + | ATTR_ATIME | ATTR_ATIME_SET;
4919 + /* no delegation since this is a directory */
4920 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4921 + if (unlikely(err))
4922 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4925 +/* ---------------------------------------------------------------------- */
4927 +/* internal use only */
4928 +struct au_cpup_reg_attr {
4931 + unsigned int iflags; /* inode->i_flags */
4934 +static noinline_for_stack
4935 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct path *h_src,
4936 + struct au_cpup_reg_attr *h_src_attr)
4938 + int err, sbits, icex;
4939 + unsigned int mnt_flags;
4940 + unsigned char verbose;
4942 + struct path h_path;
4943 + struct inode *h_isrc, *h_idst;
4944 + struct kstat *h_st;
4945 + struct au_branch *br;
4947 + br = au_sbr(dst->d_sb, bindex);
4948 + h_path.mnt = au_br_mnt(br);
4949 + h_path.dentry = au_h_dptr(dst, bindex);
4950 + h_idst = d_inode(h_path.dentry);
4951 + h_isrc = d_inode(h_src->dentry);
4952 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4953 + | ATTR_ATIME | ATTR_MTIME
4954 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4955 + if (h_src_attr && h_src_attr->valid) {
4956 + h_st = &h_src_attr->st;
4957 + ia.ia_uid = h_st->uid;
4958 + ia.ia_gid = h_st->gid;
4959 + ia.ia_atime = h_st->atime;
4960 + ia.ia_mtime = h_st->mtime;
4961 + if (h_idst->i_mode != h_st->mode
4962 + && !S_ISLNK(h_idst->i_mode)) {
4963 + ia.ia_valid |= ATTR_MODE;
4964 + ia.ia_mode = h_st->mode;
4966 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4967 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4969 + ia.ia_uid = h_isrc->i_uid;
4970 + ia.ia_gid = h_isrc->i_gid;
4971 + ia.ia_atime = h_isrc->i_atime;
4972 + ia.ia_mtime = h_isrc->i_mtime;
4973 + if (h_idst->i_mode != h_isrc->i_mode
4974 + && !S_ISLNK(h_idst->i_mode)) {
4975 + ia.ia_valid |= ATTR_MODE;
4976 + ia.ia_mode = h_isrc->i_mode;
4978 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4979 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4981 + /* no delegation since it is just created */
4982 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4984 + /* is this nfs only? */
4985 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4986 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4987 + ia.ia_mode = h_isrc->i_mode;
4988 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4991 + icex = br->br_perm & AuBrAttr_ICEX;
4993 + mnt_flags = au_mntflags(dst->d_sb);
4994 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4995 + err = au_cpup_xattr(&h_path, h_src, icex, verbose);
5001 +/* ---------------------------------------------------------------------- */
5003 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
5004 + char *buf, unsigned long blksize)
5007 + size_t sz, rbytes, wbytes;
5008 + unsigned char all_zero;
5010 + struct inode *h_inode;
5011 + /* reduce stack usage */
5014 + zp = page_address(ZERO_PAGE(0));
5015 + if (unlikely(!zp))
5016 + return -ENOMEM; /* possible? */
5021 + AuDbg("len %lld\n", len);
5023 + if (len < blksize)
5027 + /* todo: signal_pending? */
5028 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
5029 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
5032 + if (unlikely(err < 0))
5036 + if (len >= rbytes && rbytes == blksize)
5037 + all_zero = !memcmp(buf, zp, rbytes);
5044 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
5046 + /* todo: signal_pending? */
5047 + if (unlikely(err == -EAGAIN || err == -EINTR))
5049 + if (unlikely(err < 0))
5054 + if (unlikely(err < 0))
5060 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
5062 + if (unlikely(res < 0))
5069 + /* the last block may be a hole */
5070 + if (!err && all_zero) {
5071 + AuLabel(last hole);
5074 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
5075 + /* nfs requires this step to make last hole */
5076 + /* is this only nfs? */
5078 + /* todo: signal_pending? */
5079 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
5080 + } while (err == -EAGAIN || err == -EINTR);
5087 + ia->ia_size = dst->f_pos;
5088 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
5089 + ia->ia_file = dst;
5090 + h_inode = file_inode(dst);
5091 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
5092 + /* no delegation since it is just created */
5093 + err = vfsub_notify_change(&dst->f_path, ia,
5094 + /*delegated*/NULL);
5095 + inode_unlock(h_inode);
5102 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
5105 + unsigned long blksize;
5106 + unsigned char do_kfree;
5108 + struct super_block *h_sb;
5111 + h_sb = file_inode(dst)->i_sb;
5112 + blksize = h_sb->s_blocksize;
5113 + if (!blksize || PAGE_SIZE < blksize)
5114 + blksize = PAGE_SIZE;
5115 + AuDbg("blksize %lu\n", blksize);
5116 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
5118 + buf = kmalloc(blksize, GFP_NOFS);
5120 + buf = (void *)__get_free_page(GFP_NOFS);
5121 + if (unlikely(!buf))
5124 + if (len > (1 << 22))
5125 + AuDbg("copying a large file %lld\n", (long long)len);
5129 + err = au_do_copy_file(dst, src, len, buf, blksize);
5131 + AuDebugOn(!au_kfree_do_sz_test(blksize));
5132 + au_kfree_do_rcu(buf);
5134 + free_page((unsigned long)buf);
5140 +static int au_do_copy(struct file *dst, struct file *src, loff_t len)
5143 + struct super_block *h_src_sb;
5144 + struct inode *h_src_inode;
5146 + h_src_inode = file_inode(src);
5147 + h_src_sb = h_src_inode->i_sb;
5149 + /* XFS acquires inode_lock */
5150 + if (!au_test_xfs(h_src_sb))
5151 + err = au_copy_file(dst, src, len);
5153 + inode_unlock_shared(h_src_inode);
5154 + err = au_copy_file(dst, src, len);
5155 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5161 +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len)
5165 + struct super_block *h_src_sb;
5166 + struct inode *h_src_inode;
5168 + h_src_inode = file_inode(src);
5169 + h_src_sb = h_src_inode->i_sb;
5170 + if (h_src_sb != file_inode(dst)->i_sb
5171 + || !dst->f_op->remap_file_range) {
5172 + err = au_do_copy(dst, src, len);
5176 + if (!au_test_nfs(h_src_sb)) {
5177 + inode_unlock_shared(h_src_inode);
5178 + lo = vfsub_clone_file_range(src, dst, len);
5179 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5181 + lo = vfsub_clone_file_range(src, dst, len);
5184 + goto out; /* success */
5185 + } else if (lo >= 0)
5186 + /* todo: possible? */
5187 + /* paritially succeeded */
5188 + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len);
5189 + else if (lo != -EOPNOTSUPP) {
5190 + /* older XFS has a condition in cloning */
5195 + /* the backend fs on NFS may not support cloning */
5196 + err = au_do_copy(dst, src, len);
5204 + * to support a sparse file which is opened with O_APPEND,
5205 + * we need to close the file.
5207 +static int au_cp_regular(struct au_cp_generic *cpg)
5210 + enum { SRC, DST };
5212 + aufs_bindex_t bindex;
5213 + unsigned int flags;
5214 + struct dentry *dentry;
5216 + struct file *file;
5219 + .bindex = cpg->bsrc,
5220 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5223 + .bindex = cpg->bdst,
5224 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5225 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5228 + struct au_branch *br;
5229 + struct super_block *sb, *h_src_sb;
5230 + struct inode *h_src_inode;
5231 + struct task_struct *tsk = current;
5233 + /* bsrc branch can be ro/rw. */
5234 + sb = cpg->dentry->d_sb;
5236 + for (i = 0; i < 2; i++, f++) {
5237 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5238 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5239 + /*file*/NULL, f->force_wr);
5240 + if (IS_ERR(f->file)) {
5241 + err = PTR_ERR(f->file);
5249 + /* try stopping to update while we copyup */
5250 + h_src_inode = d_inode(file[SRC].dentry);
5251 + h_src_sb = h_src_inode->i_sb;
5252 + if (!au_test_nfs(h_src_sb))
5253 + IMustLock(h_src_inode);
5254 + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len);
5256 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5257 + if (tsk->flags & PF_KTHREAD)
5258 + __fput_sync(file[DST].file);
5260 + /* it happened actually */
5261 + fput(file[DST].file);
5264 + * we have to call both since we don't know which place the file
5268 + flush_delayed_fput();
5270 + br = au_sbr(sb, file[DST].bindex);
5271 + au_lcnt_dec(&br->br_nfiles);
5274 + fput(file[SRC].file);
5275 + br = au_sbr(sb, file[SRC].bindex);
5276 + au_lcnt_dec(&br->br_nfiles);
5281 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5282 + struct au_cpup_reg_attr *h_src_attr)
5286 + struct path h_path;
5287 + struct inode *h_src_inode, *h_dst_inode;
5290 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5291 + l = i_size_read(h_src_inode);
5292 + if (cpg->len == -1 || l < cpg->len)
5295 + /* try stopping to update while we are referencing */
5296 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5297 + au_pin_hdir_unlock(cpg->pin);
5299 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5300 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5301 + h_src_attr->iflags = h_src_inode->i_flags;
5302 + if (!au_test_nfs(h_src_inode->i_sb))
5303 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5305 + inode_unlock_shared(h_src_inode);
5306 + err = vfsub_getattr(&h_path, &h_src_attr->st);
5307 + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD);
5309 + if (unlikely(err)) {
5310 + inode_unlock_shared(h_src_inode);
5313 + h_src_attr->valid = 1;
5314 + if (!au_test_nfs(h_src_inode->i_sb)) {
5315 + err = au_cp_regular(cpg);
5316 + inode_unlock_shared(h_src_inode);
5318 + inode_unlock_shared(h_src_inode);
5319 + err = au_cp_regular(cpg);
5321 + rerr = au_pin_hdir_relock(cpg->pin);
5325 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5326 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5327 + h_dst_inode = d_inode(h_path.dentry);
5328 + spin_lock(&h_dst_inode->i_lock);
5329 + h_dst_inode->i_state |= I_LINKABLE;
5330 + spin_unlock(&h_dst_inode->i_lock);
5337 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5338 + struct inode *h_dir)
5341 + DEFINE_DELAYED_CALL(done);
5344 + sym = vfs_get_link(h_src, &done);
5345 + err = PTR_ERR(sym);
5349 + err = vfsub_symlink(h_dir, h_path, sym);
5352 + do_delayed_call(&done);
5357 + * regardless 'acl' option, reset all ACL.
5358 + * All ACL will be copied up later from the original entry on the lower branch.
5360 +static int au_reset_acl(struct path *h_path, umode_t mode)
5363 + struct dentry *h_dentry;
5364 + /* struct inode *h_inode; */
5365 + struct mnt_idmap *h_idmap;
5367 + h_idmap = mnt_idmap(h_path->mnt);
5368 + h_dentry = h_path->dentry;
5369 + /* h_inode = d_inode(h_dentry); */
5370 + /* forget_all_cached_acls(h_inode)); */
5371 + err = vfsub_remove_acl(h_idmap, h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5373 + if (err == -EOPNOTSUPP)
5376 + err = vfsub_acl_chmod(h_idmap, h_dentry, mode);
5382 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5383 + struct inode *h_dir, struct path *h_path)
5386 + struct inode *dir, *inode;
5387 + struct mnt_idmap *h_idmap;
5389 + h_idmap = mnt_idmap(h_path->mnt);
5390 + err = vfsub_remove_acl(h_idmap, h_path->dentry,
5391 + XATTR_NAME_POSIX_ACL_DEFAULT);
5393 + if (err == -EOPNOTSUPP)
5395 + if (unlikely(err))
5399 + * strange behaviour from the users view,
5400 + * particularly setattr case
5402 + dir = d_inode(dst_parent);
5403 + if (au_ibtop(dir) == cpg->bdst)
5404 + au_cpup_attr_nlink(dir, /*force*/1);
5405 + inode = d_inode(cpg->dentry);
5406 + au_cpup_attr_nlink(inode, /*force*/1);
5412 +static noinline_for_stack
5413 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5414 + struct au_cpup_reg_attr *h_src_attr)
5418 + unsigned int mnt_flags;
5419 + unsigned char isdir, isreg, force;
5420 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5421 + struct au_dtime dt;
5422 + struct path h_path;
5423 + struct dentry *h_src, *h_dst, *h_parent;
5424 + struct inode *h_inode, *h_dir;
5425 + struct super_block *sb;
5427 + /* bsrc branch can be ro/rw. */
5428 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5429 + h_inode = d_inode(h_src);
5430 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5432 + /* try stopping to be referenced while we are creating */
5433 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5434 + if (au_ftest_cpup(cpg->flags, RENAME))
5435 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5436 + AUFS_WH_PFX_LEN));
5437 + h_parent = h_dst->d_parent; /* dir inode is locked */
5438 + h_dir = d_inode(h_parent);
5440 + AuDebugOn(h_parent != h_dst->d_parent);
5442 + sb = cpg->dentry->d_sb;
5443 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5445 + h_path.dentry = h_parent;
5446 + au_dtime_store(&dt, dst_parent, &h_path);
5448 + h_path.dentry = h_dst;
5452 + mode = h_inode->i_mode;
5453 + switch (mode & S_IFMT) {
5456 + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true);
5458 + err = au_do_cpup_regular(cpg, h_src_attr);
5462 + err = vfsub_mkdir(h_dir, &h_path, mode);
5464 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5467 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5471 + AuDebugOn(!capable(CAP_MKNOD));
5475 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5478 + AuIOErr("Unknown inode type 0%o\n", mode);
5482 + err = au_reset_acl(&h_path, mode);
5484 + mnt_flags = au_mntflags(sb);
5485 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5487 + && au_opt_test(mnt_flags, XINO)
5488 + && (h_inode->i_nlink == 1
5489 + || (h_inode->i_state & I_LINKABLE))
5490 + /* todo: unnecessary? */
5491 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5492 + && cpg->bdst < cpg->bsrc
5493 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5494 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5495 + /* ignore this error */
5500 + force = !!cpg->len;
5501 + if (cpg->len == -1)
5502 + force = !!i_size_read(h_inode);
5504 + au_fhsm_wrote(sb, cpg->bdst, force);
5508 + au_dtime_revert(&dt);
5512 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5515 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5516 + struct path h_ppath;
5517 + struct inode *h_dir;
5518 + aufs_bindex_t bdst;
5520 + dentry = cpg->dentry;
5522 + h_ppath.mnt = au_sbr_mnt(dentry->d_sb, bdst);
5523 + h_dentry = au_h_dptr(dentry, bdst);
5524 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5526 + au_set_h_dptr(dentry, bdst, NULL);
5527 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5529 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5530 + au_set_h_dptr(dentry, bdst, h_dentry);
5533 + parent = dget_parent(dentry);
5534 + h_ppath.dentry = au_h_dptr(parent, bdst);
5536 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, &h_ppath);
5537 + if (IS_ERR(h_path->dentry))
5538 + err = PTR_ERR(h_path->dentry);
5540 + if (unlikely(err))
5543 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5544 + h_dir = d_inode(h_parent);
5546 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5547 + /* no delegation since it is just created */
5548 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5550 + dput(h_path->dentry);
5557 + * copyup the @dentry from @bsrc to @bdst.
5558 + * the caller must set the both of lower dentries.
5559 + * @len is for truncating when it is -1 copyup the entire file.
5560 + * in link/rename cases, @dst_parent may be different from the real one.
5561 + * basic->bsrc can be larger than basic->bdst.
5562 + * aufs doesn't touch the credential so
5563 + * security_inode_copy_up{,_xattr}() are unnecessary.
5565 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5568 + aufs_bindex_t old_ibtop;
5569 + unsigned char isdir, plink;
5570 + struct dentry *h_src, *h_dst, *h_parent;
5571 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5572 + struct super_block *sb;
5573 + struct au_branch *br;
5574 + struct path h_src_path;
5575 + /* to reduce stack size */
5577 + struct au_dtime dt;
5578 + struct path h_path;
5579 + struct au_cpup_reg_attr h_src_attr;
5583 + a = kmalloc(sizeof(*a), GFP_NOFS);
5586 + a->h_src_attr.valid = 0;
5588 + sb = cpg->dentry->d_sb;
5589 + br = au_sbr(sb, cpg->bdst);
5590 + a->h_path.mnt = au_br_mnt(br);
5591 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5592 + h_parent = h_dst->d_parent; /* dir inode is locked */
5593 + h_dir = d_inode(h_parent);
5596 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5597 + inode = d_inode(cpg->dentry);
5600 + dst_parent = dget_parent(cpg->dentry);
5604 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5605 + dst_inode = au_h_iptr(inode, cpg->bdst);
5607 + if (unlikely(!plink)) {
5609 + AuIOErr("hi%lu(i%lu) exists on b%d "
5610 + "but plink is disabled\n",
5611 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5615 + if (dst_inode->i_nlink) {
5616 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5618 + h_src = au_plink_lkup(inode, cpg->bdst);
5619 + err = PTR_ERR(h_src);
5620 + if (IS_ERR(h_src))
5622 + if (unlikely(d_is_negative(h_src))) {
5624 + AuIOErr("i%lu exists on b%d "
5625 + "but not pseudo-linked\n",
5626 + inode->i_ino, cpg->bdst);
5632 + a->h_path.dentry = h_parent;
5633 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5636 + a->h_path.dentry = h_dst;
5638 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5639 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5640 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5642 + au_dtime_revert(&a->dt);
5643 + if (unlikely(err == -EWOULDBLOCK)) {
5644 + pr_warn("cannot retry for NFSv4 delegation"
5645 + " for an internal link\n");
5651 + /* todo: cpup_wh_file? */
5653 + au_update_ibrange(inode, /*do_put_zero*/1);
5656 + isdir = S_ISDIR(inode->i_mode);
5657 + old_ibtop = au_ibtop(inode);
5658 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5659 + if (unlikely(err))
5661 + dst_inode = d_inode(h_dst);
5662 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5663 + /* todo: necessary? */
5664 + /* au_pin_hdir_unlock(cpg->pin); */
5666 + h_src_path.dentry = h_src;
5667 + h_src_path.mnt = au_sbr_mnt(sb, cpg->bsrc);
5668 + err = cpup_iattr(cpg->dentry, cpg->bdst, &h_src_path, &a->h_src_attr);
5669 + if (unlikely(err)) {
5670 + /* todo: necessary? */
5671 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5672 + inode_unlock(dst_inode);
5676 + if (cpg->bdst < old_ibtop) {
5677 + if (S_ISREG(inode->i_mode)) {
5678 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5679 + if (unlikely(err)) {
5680 + /* ignore an error */
5681 + /* au_pin_hdir_relock(cpg->pin); */
5682 + inode_unlock(dst_inode);
5686 + au_set_ibtop(inode, cpg->bdst);
5688 + au_set_ibbot(inode, cpg->bdst);
5689 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5690 + au_hi_flags(inode, isdir));
5692 + /* todo: necessary? */
5693 + /* err = au_pin_hdir_relock(cpg->pin); */
5694 + inode_unlock(dst_inode);
5695 + if (unlikely(err))
5698 + src_inode = d_inode(h_src);
5700 + && (src_inode->i_nlink > 1
5701 + || src_inode->i_state & I_LINKABLE)
5703 + au_plink_append(inode, cpg->bdst, h_dst);
5705 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5706 + a->h_path.dentry = h_dst;
5707 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5710 + goto out_parent; /* success */
5714 + a->h_path.dentry = h_parent;
5715 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5716 + a->h_path.dentry = h_dst;
5718 + if (d_is_positive(h_dst)) {
5720 + /* no delegation since it is just created */
5721 + rerr = vfsub_unlink(h_dir, &a->h_path,
5722 + /*delegated*/NULL, /*force*/0);
5724 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5726 + au_dtime_revert(&a->dt);
5728 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5738 +#if 0 /* reserved */
5739 +struct au_cpup_single_args {
5741 + struct au_cp_generic *cpg;
5742 + struct dentry *dst_parent;
5745 +static void au_call_cpup_single(void *args)
5747 + struct au_cpup_single_args *a = args;
5749 + au_pin_hdir_acquire_nest(a->cpg->pin);
5750 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5751 + au_pin_hdir_release(a->cpg->pin);
5756 + * prevent SIGXFSZ in copy-up.
5757 + * testing CAP_MKNOD is for generic fs,
5758 + * but CAP_FSETID is for xfs only, currently.
5760 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5763 + struct super_block *sb;
5764 + struct inode *h_dir;
5767 + sb = au_pinned_parent(pin)->d_sb;
5768 + if (!au_wkq_test()
5769 + && (!au_sbi(sb)->si_plink_maint_pid
5770 + || au_plink_maint(sb, AuLock_NOPLM))) {
5771 + switch (mode & S_IFMT) {
5773 + /* no condition about RLIMIT_FSIZE and the file size */
5778 + do_sio = !capable(CAP_MKNOD);
5782 + do_sio = ((mode & (S_ISUID | S_ISGID))
5783 + && !capable(CAP_FSETID));
5784 + /* this workaround may be removed in the future */
5786 + h_dir = au_pinned_h_dir(pin);
5787 + do_sio = h_dir->i_mode & S_ISVTX;
5794 +#if 0 /* reserved */
5795 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5798 + struct dentry *h_dentry;
5800 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5801 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5802 + err = au_cpup_single(cpg, dst_parent);
5804 + struct au_cpup_single_args args = {
5807 + .dst_parent = dst_parent
5809 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5810 + if (unlikely(wkq_err))
5819 + * copyup the @dentry from the first active lower branch to @bdst,
5820 + * using au_cpup_single().
5822 +static int au_cpup_simple(struct au_cp_generic *cpg)
5825 + unsigned int flags_orig;
5826 + struct dentry *dentry;
5828 + AuDebugOn(cpg->bsrc < 0);
5830 + dentry = cpg->dentry;
5831 + DiMustWriteLock(dentry);
5833 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5835 + flags_orig = cpg->flags;
5836 + au_fset_cpup(cpg->flags, RENAME);
5837 + err = au_cpup_single(cpg, NULL);
5838 + cpg->flags = flags_orig;
5840 + return 0; /* success */
5843 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5844 + au_set_dbtop(dentry, cpg->bsrc);
5850 +struct au_cpup_simple_args {
5852 + struct au_cp_generic *cpg;
5855 +static void au_call_cpup_simple(void *args)
5857 + struct au_cpup_simple_args *a = args;
5859 + au_pin_hdir_acquire_nest(a->cpg->pin);
5860 + *a->errp = au_cpup_simple(a->cpg);
5861 + au_pin_hdir_release(a->cpg->pin);
5864 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5867 + struct dentry *dentry, *parent;
5868 + struct file *h_file;
5869 + struct inode *h_dir;
5870 + struct mnt_idmap *h_idmap;
5872 + dentry = cpg->dentry;
5874 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5875 + AuDebugOn(cpg->bsrc < 0);
5876 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5877 + err = PTR_ERR(h_file);
5878 + if (IS_ERR(h_file))
5882 + parent = dget_parent(dentry);
5883 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5884 + h_idmap = au_sbr_idmap(dentry->d_sb, cpg->bdst);
5885 + if (!au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC | MAY_WRITE)
5886 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5887 + err = au_cpup_simple(cpg);
5889 + struct au_cpup_simple_args args = {
5893 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5894 + if (unlikely(wkq_err))
5900 + au_h_open_post(dentry, cpg->bsrc, h_file);
5906 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5908 + aufs_bindex_t bsrc, bbot;
5909 + struct dentry *dentry, *h_dentry;
5911 + if (cpg->bsrc < 0) {
5912 + dentry = cpg->dentry;
5913 + bbot = au_dbbot(dentry);
5914 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5915 + h_dentry = au_h_dptr(dentry, bsrc);
5917 + AuDebugOn(d_is_negative(h_dentry));
5921 + AuDebugOn(bsrc > bbot);
5924 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5925 + return au_do_sio_cpup_simple(cpg);
5928 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5930 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5931 + return au_do_sio_cpup_simple(cpg);
5934 +/* ---------------------------------------------------------------------- */
5937 + * copyup the deleted file for writing.
5939 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5940 + struct file *file)
5943 + unsigned int flags_orig;
5944 + aufs_bindex_t bsrc_orig;
5945 + struct au_dinfo *dinfo;
5947 + struct au_hdentry *hd;
5948 + struct dentry *h_dentry;
5951 + dinfo = au_di(cpg->dentry);
5952 + AuRwMustWriteLock(&dinfo->di_rwsem);
5954 + bsrc_orig = cpg->bsrc;
5955 + cpg->bsrc = dinfo->di_btop;
5956 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5957 + hdst.h_dentry = hdst.hd->hd_dentry;
5958 + hdst.hd->hd_dentry = wh_dentry;
5959 + dinfo->di_btop = cpg->bdst;
5961 + hsrc.h_dentry = NULL;
5963 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5964 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5965 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5967 + flags_orig = cpg->flags;
5968 + cpg->flags = !AuCpup_DTIME;
5969 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5970 + cpg->flags = flags_orig;
5973 + err = au_reopen_nondir(file);
5974 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5976 + hdst.hd->hd_dentry = hdst.h_dentry;
5977 + dinfo->di_btop = cpg->bsrc;
5978 + cpg->bsrc = bsrc_orig;
5983 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5986 + aufs_bindex_t bdst;
5987 + struct au_dtime dt;
5988 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5989 + struct au_branch *br;
5990 + struct path h_path;
5992 + dentry = cpg->dentry;
5994 + br = au_sbr(dentry->d_sb, bdst);
5995 + parent = dget_parent(dentry);
5996 + h_parent = au_h_dptr(parent, bdst);
5997 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5998 + err = PTR_ERR(wh_dentry);
5999 + if (IS_ERR(wh_dentry))
6002 + h_path.dentry = h_parent;
6003 + h_path.mnt = au_br_mnt(br);
6004 + au_dtime_store(&dt, parent, &h_path);
6005 + err = au_do_cpup_wh(cpg, wh_dentry, file);
6006 + if (unlikely(err))
6010 + h_path.dentry = wh_dentry;
6011 + if (!d_is_dir(wh_dentry)) {
6012 + /* no delegation since it is just created */
6013 + err = vfsub_unlink(d_inode(h_parent), &h_path,
6014 + /*delegated*/NULL, /*force*/0);
6016 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
6017 + if (unlikely(err)) {
6018 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
6022 + au_dtime_revert(&dt);
6023 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
6032 +struct au_cpup_wh_args {
6034 + struct au_cp_generic *cpg;
6035 + struct file *file;
6038 +static void au_call_cpup_wh(void *args)
6040 + struct au_cpup_wh_args *a = args;
6042 + au_pin_hdir_acquire_nest(a->cpg->pin);
6043 + *a->errp = au_cpup_wh(a->cpg, a->file);
6044 + au_pin_hdir_release(a->cpg->pin);
6047 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
6050 + aufs_bindex_t bdst;
6051 + struct dentry *dentry, *parent, *h_orph, *h_parent;
6052 + struct inode *dir, *h_dir, *h_tmpdir;
6053 + struct au_wbr *wbr;
6054 + struct au_pin wh_pin, *pin_orig;
6055 + struct mnt_idmap *h_idmap;
6057 + dentry = cpg->dentry;
6059 + parent = dget_parent(dentry);
6060 + dir = d_inode(parent);
6063 + h_dir = au_igrab(au_h_iptr(dir, bdst));
6066 + if (!h_dir->i_nlink) {
6067 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
6068 + h_orph = wbr->wbr_orph;
6070 + h_parent = dget(au_h_dptr(parent, bdst));
6071 + au_set_h_dptr(parent, bdst, dget(h_orph));
6072 + h_tmpdir = d_inode(h_orph);
6073 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
6075 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
6076 + /* todo: au_h_open_pre()? */
6078 + pin_orig = cpg->pin;
6079 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
6080 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
6081 + cpg->pin = &wh_pin;
6084 + h_idmap = au_sbr_idmap(dentry->d_sb, bdst);
6085 + if (!au_test_h_perm_sio(h_idmap, h_tmpdir, MAY_EXEC | MAY_WRITE)
6086 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
6087 + err = au_cpup_wh(cpg, file);
6089 + struct au_cpup_wh_args args = {
6094 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
6095 + if (unlikely(wkq_err))
6100 + inode_unlock(h_tmpdir);
6101 + /* todo: au_h_open_post()? */
6102 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
6103 + au_set_h_dptr(parent, bdst, h_parent);
6104 + AuDebugOn(!pin_orig);
6105 + cpg->pin = pin_orig;
6113 +/* ---------------------------------------------------------------------- */
6116 + * generic routine for both of copy-up and copy-down.
6118 +/* cf. revalidate function in file.c */
6119 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6120 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6121 + struct au_pin *pin,
6122 + struct dentry *h_parent, void *arg),
6126 + struct au_pin pin;
6127 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
6130 + parent = dget_parent(dentry);
6131 + if (IS_ROOT(parent))
6134 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
6135 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
6137 + /* do not use au_dpage */
6138 + real_parent = parent;
6141 + parent = dget_parent(dentry);
6142 + h_parent = au_h_dptr(parent, bdst);
6144 + goto out; /* success */
6146 + /* find top dir which is necessary to cpup */
6150 + parent = dget_parent(d);
6151 + di_read_lock_parent3(parent, !AuLock_IR);
6152 + h_parent = au_h_dptr(parent, bdst);
6153 + di_read_unlock(parent, !AuLock_IR);
6154 + } while (!h_parent);
6156 + if (d != real_parent)
6157 + di_write_lock_child3(d);
6159 + /* somebody else might create while we were sleeping */
6160 + h_dentry = au_h_dptr(d, bdst);
6161 + if (!h_dentry || d_is_negative(h_dentry)) {
6163 + au_update_dbtop(d);
6165 + au_pin_set_dentry(&pin, d);
6166 + err = au_do_pin(&pin);
6168 + err = cp(d, bdst, &pin, h_parent, arg);
6173 + if (d != real_parent)
6174 + di_write_unlock(d);
6175 + if (unlikely(err))
6184 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6185 + struct au_pin *pin,
6186 + struct dentry *h_parent __maybe_unused,
6187 + void *arg __maybe_unused)
6189 + struct au_cp_generic cpg = {
6195 + .flags = AuCpup_DTIME
6197 + return au_sio_cpup_simple(&cpg);
6200 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6202 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6205 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6208 + struct dentry *parent;
6209 + struct inode *dir;
6211 + parent = dget_parent(dentry);
6212 + dir = d_inode(parent);
6214 + if (au_h_iptr(dir, bdst))
6217 + di_read_unlock(parent, AuLock_IR);
6218 + di_write_lock_parent(parent);
6219 + /* someone else might change our inode while we were sleeping */
6220 + if (!au_h_iptr(dir, bdst))
6221 + err = au_cpup_dirs(dentry, bdst);
6222 + di_downgrade_lock(parent, AuLock_IR);
6228 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6229 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6230 +++ linux/fs/aufs/cpup.h 2022-11-05 23:02:18.962555950 +0100
6232 +/* SPDX-License-Identifier: GPL-2.0 */
6234 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6236 + * This program is free software; you can redistribute it and/or modify
6237 + * it under the terms of the GNU General Public License as published by
6238 + * the Free Software Foundation; either version 2 of the License, or
6239 + * (at your option) any later version.
6241 + * This program is distributed in the hope that it will be useful,
6242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6244 + * GNU General Public License for more details.
6246 + * You should have received a copy of the GNU General Public License
6247 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6251 + * copy-up/down functions
6254 +#ifndef __AUFS_CPUP_H__
6255 +#define __AUFS_CPUP_H__
6259 +#include <linux/path.h>
6265 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6266 +void au_cpup_attr_timesizes(struct inode *inode);
6267 +void au_cpup_attr_nlink(struct inode *inode, int force);
6268 +void au_cpup_attr_changeable(struct inode *inode);
6269 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6270 +void au_cpup_attr_all(struct inode *inode, int force);
6272 +/* ---------------------------------------------------------------------- */
6274 +struct au_cp_generic {
6275 + struct dentry *dentry;
6276 + aufs_bindex_t bdst, bsrc;
6278 + struct au_pin *pin;
6279 + unsigned int flags;
6283 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6284 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6286 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6287 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6289 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6291 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6292 + the branch is marked as RO */
6294 +#ifndef CONFIG_AUFS_BR_HFSPLUS
6295 +#undef AuCpup_HOPEN
6296 +#define AuCpup_HOPEN 0
6299 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6300 +#define au_fset_cpup(flags, name) \
6301 + do { (flags) |= AuCpup_##name; } while (0)
6302 +#define au_fclr_cpup(flags, name) \
6303 + do { (flags) &= ~AuCpup_##name; } while (0)
6305 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6306 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6307 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6308 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6310 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6311 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6312 + struct au_pin *pin,
6313 + struct dentry *h_parent, void *arg),
6315 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6316 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6318 +/* ---------------------------------------------------------------------- */
6320 +/* keep timestamps when copyup */
6322 + struct dentry *dt_dentry;
6323 + struct path dt_h_path;
6324 + struct timespec64 dt_atime, dt_mtime;
6326 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6327 + struct path *h_path);
6328 +void au_dtime_revert(struct au_dtime *dt);
6330 +#endif /* __KERNEL__ */
6331 +#endif /* __AUFS_CPUP_H__ */
6332 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6333 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6334 +++ linux/fs/aufs/dbgaufs.c 2022-11-05 23:02:18.962555950 +0100
6336 +// SPDX-License-Identifier: GPL-2.0
6338 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6340 + * This program is free software; you can redistribute it and/or modify
6341 + * it under the terms of the GNU General Public License as published by
6342 + * the Free Software Foundation; either version 2 of the License, or
6343 + * (at your option) any later version.
6345 + * This program is distributed in the hope that it will be useful,
6346 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6347 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6348 + * GNU General Public License for more details.
6350 + * You should have received a copy of the GNU General Public License
6351 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6355 + * debugfs interface
6358 +#include <linux/debugfs.h>
6361 +#ifndef CONFIG_SYSFS
6362 +#error DEBUG_FS depends upon SYSFS
6365 +static struct dentry *dbgaufs;
6366 +static const mode_t dbgaufs_mode = 0444;
6368 +/* 20 is max digits length of ulong 64 */
6369 +struct dbgaufs_arg {
6375 + * common function for all XINO files
6377 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6378 + struct file *file)
6382 + p = file->private_data;
6384 + /* this is struct dbgaufs_arg */
6385 + AuDebugOn(!au_kfree_sz_test(p));
6386 + au_kfree_do_rcu(p);
6391 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt,
6396 + struct dbgaufs_arg *p;
6399 + p = kmalloc(sizeof(*p), GFP_NOFS);
6405 + file->private_data = p;
6409 + err = vfsub_getattr(&xf->f_path, &st);
6413 + (p->a, sizeof(p->a), "%d, %llux%u %lld\n",
6414 + cnt, st.blocks, st.blksize,
6415 + (long long)st.size);
6417 + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n",
6418 + st.blocks, st.blksize,
6419 + (long long)st.size);
6420 + AuDebugOn(p->n >= sizeof(p->a));
6422 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6430 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6431 + size_t count, loff_t *ppos)
6433 + struct dbgaufs_arg *p;
6435 + p = file->private_data;
6436 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6439 +/* ---------------------------------------------------------------------- */
6441 +struct dbgaufs_plink_arg {
6446 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6447 + struct file *file)
6449 + free_page((unsigned long)file->private_data);
6453 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6455 + int err, i, limit;
6456 + unsigned long n, sum;
6457 + struct dbgaufs_plink_arg *p;
6458 + struct au_sbinfo *sbinfo;
6459 + struct super_block *sb;
6460 + struct hlist_bl_head *hbl;
6463 + p = (void *)get_zeroed_page(GFP_NOFS);
6468 + sbinfo = inode->i_private;
6469 + sb = sbinfo->si_sb;
6470 + si_noflush_read_lock(sb);
6471 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6472 + limit = PAGE_SIZE - sizeof(p->n);
6474 + /* the number of buckets */
6475 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6480 + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH;
6482 + n = au_hbl_count(hbl);
6485 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6488 + if (unlikely(limit <= 0))
6491 + p->a[p->n - 1] = '\n';
6493 + /* the sum of plinks */
6494 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6497 + if (unlikely(limit <= 0))
6500 +#define str "1\n0\n0\n"
6501 + p->n = sizeof(str) - 1;
6502 + strcpy(p->a, str);
6505 + si_read_unlock(sb);
6508 + file->private_data = p;
6509 + goto out; /* success */
6512 + free_page((unsigned long)p);
6517 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6518 + size_t count, loff_t *ppos)
6520 + struct dbgaufs_plink_arg *p;
6522 + p = file->private_data;
6523 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6526 +static const struct file_operations dbgaufs_plink_fop = {
6527 + .owner = THIS_MODULE,
6528 + .open = dbgaufs_plink_open,
6529 + .release = dbgaufs_plink_release,
6530 + .read = dbgaufs_plink_read
6533 +/* ---------------------------------------------------------------------- */
6535 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6538 + struct au_sbinfo *sbinfo;
6539 + struct super_block *sb;
6541 + sbinfo = inode->i_private;
6542 + sb = sbinfo->si_sb;
6543 + si_noflush_read_lock(sb);
6544 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0);
6545 + si_read_unlock(sb);
6549 +static const struct file_operations dbgaufs_xib_fop = {
6550 + .owner = THIS_MODULE,
6551 + .open = dbgaufs_xib_open,
6552 + .release = dbgaufs_xi_release,
6553 + .read = dbgaufs_xi_read
6556 +/* ---------------------------------------------------------------------- */
6558 +#define DbgaufsXi_PREFIX "xi"
6560 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6564 + aufs_bindex_t bindex;
6565 + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8];
6566 + struct au_sbinfo *sbinfo;
6567 + struct super_block *sb;
6568 + struct au_xino *xi;
6570 + struct qstr *name;
6571 + struct au_branch *br;
6574 + name = &file->f_path.dentry->d_name;
6575 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6576 + || memcmp(name->name, DbgaufsXi_PREFIX,
6577 + sizeof(DbgaufsXi_PREFIX) - 1)))
6580 + AuDebugOn(name->len >= sizeof(a));
6581 + memcpy(a, name->name, name->len);
6582 + a[name->len] = '\0';
6583 + p = strchr(a, '-');
6586 + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6587 + if (unlikely(err))
6592 + err = kstrtol(p + 1, 10, &l);
6593 + if (unlikely(err))
6599 + sbinfo = inode->i_private;
6600 + sb = sbinfo->si_sb;
6601 + si_noflush_read_lock(sb);
6602 + if (unlikely(bindex < 0 || bindex > au_sbbot(sb)))
6604 + br = au_sbr(sb, bindex);
6606 + if (unlikely(idx >= xi->xi_nfile))
6608 + xf = au_xino_file(xi, idx);
6610 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1,
6611 + au_xino_count(br));
6614 + si_read_unlock(sb);
6620 +static const struct file_operations dbgaufs_xino_fop = {
6621 + .owner = THIS_MODULE,
6622 + .open = dbgaufs_xino_open,
6623 + .release = dbgaufs_xi_release,
6624 + .read = dbgaufs_xi_read
6627 +void dbgaufs_xino_del(struct au_branch *br)
6629 + struct dentry *dbgaufs;
6631 + dbgaufs = br->br_dbgaufs;
6635 + br->br_dbgaufs = NULL;
6636 + /* debugfs acquires the parent i_mutex */
6638 + debugfs_remove(dbgaufs);
6642 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6644 + aufs_bindex_t bbot;
6645 + struct au_branch *br;
6647 + if (!au_sbi(sb)->si_dbgaufs)
6650 + bbot = au_sbbot(sb);
6651 + for (; bindex <= bbot; bindex++) {
6652 + br = au_sbr(sb, bindex);
6653 + dbgaufs_xino_del(br);
6657 +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex,
6658 + unsigned int idx, struct dentry *parent,
6659 + struct au_sbinfo *sbinfo)
6661 + struct au_branch *br;
6663 + /* "xi" bindex(5) "-" idx(2) NULL */
6664 + char name[sizeof(DbgaufsXi_PREFIX) + 8];
6667 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6669 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u",
6671 + br = au_sbr(sb, bindex);
6672 + if (br->br_dbgaufs) {
6673 + struct qstr qstr = QSTR_INIT(name, strlen(name));
6675 + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) {
6676 + /* debugfs acquires the parent i_mutex */
6678 + d = debugfs_rename(parent, br->br_dbgaufs, parent,
6682 + pr_warn("failed renaming %pd/%s, ignored.\n",
6687 + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6688 + sbinfo, &dbgaufs_xino_fop);
6690 + if (unlikely(!br->br_dbgaufs))
6691 + pr_warn("failed creating %pd/%s, ignored.\n",
6696 +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex,
6697 + struct dentry *parent, struct au_sbinfo *sbinfo)
6699 + struct au_branch *br;
6700 + struct au_xino *xi;
6703 + br = au_sbr(sb, bindex);
6705 + for (u = 0; u < xi->xi_nfile; u++)
6706 + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo);
6709 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown)
6711 + struct au_sbinfo *sbinfo;
6712 + struct dentry *parent;
6713 + aufs_bindex_t bbot;
6715 + if (!au_opt_test(au_mntflags(sb), XINO))
6718 + sbinfo = au_sbi(sb);
6719 + parent = sbinfo->si_dbgaufs;
6723 + bbot = au_sbbot(sb);
6725 + for (; bindex <= bbot; bindex++)
6726 + dbgaufs_br_add(sb, bindex, parent, sbinfo);
6728 + for (; bbot >= bindex; bbot--)
6729 + dbgaufs_br_add(sb, bbot, parent, sbinfo);
6732 +/* ---------------------------------------------------------------------- */
6734 +#ifdef CONFIG_AUFS_EXPORT
6735 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6738 + struct au_sbinfo *sbinfo;
6739 + struct super_block *sb;
6741 + sbinfo = inode->i_private;
6742 + sb = sbinfo->si_sb;
6743 + si_noflush_read_lock(sb);
6744 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0);
6745 + si_read_unlock(sb);
6749 +static const struct file_operations dbgaufs_xigen_fop = {
6750 + .owner = THIS_MODULE,
6751 + .open = dbgaufs_xigen_open,
6752 + .release = dbgaufs_xi_release,
6753 + .read = dbgaufs_xi_read
6756 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6761 + * This function is a dynamic '__init' function actually,
6762 + * so the tiny check for si_rwsem is unnecessary.
6764 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6767 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6768 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6769 + &dbgaufs_xigen_fop);
6770 + if (sbinfo->si_dbgaufs_xigen)
6776 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6780 +#endif /* CONFIG_AUFS_EXPORT */
6782 +/* ---------------------------------------------------------------------- */
6784 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6787 + * This function is a dynamic '__fin' function actually,
6788 + * so the tiny check for si_rwsem is unnecessary.
6790 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6792 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6793 + sbinfo->si_dbgaufs = NULL;
6796 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6799 + char name[SysaufsSiNameLen];
6802 + * This function is a dynamic '__init' function actually,
6803 + * so the tiny check for si_rwsem is unnecessary.
6805 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6809 + AuErr1("/debug/aufs is uninitialized\n");
6814 + sysaufs_name(sbinfo, name);
6815 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6816 + if (unlikely(!sbinfo->si_dbgaufs))
6819 + /* regardless plink/noplink option */
6820 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6821 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6822 + &dbgaufs_plink_fop);
6823 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6826 + /* regardless xino/noxino option */
6827 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6828 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6829 + &dbgaufs_xib_fop);
6830 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6833 + err = dbgaufs_xigen_init(sbinfo);
6835 + goto out; /* success */
6838 + dbgaufs_si_fin(sbinfo);
6840 + if (unlikely(err))
6841 + pr_err("debugfs/aufs failed\n");
6845 +/* ---------------------------------------------------------------------- */
6847 +void dbgaufs_fin(void)
6849 + debugfs_remove(dbgaufs);
6852 +int __init dbgaufs_init(void)
6857 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6862 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6863 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6864 +++ linux/fs/aufs/dbgaufs.h 2022-11-05 23:02:18.962555950 +0100
6866 +/* SPDX-License-Identifier: GPL-2.0 */
6868 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6870 + * This program is free software; you can redistribute it and/or modify
6871 + * it under the terms of the GNU General Public License as published by
6872 + * the Free Software Foundation; either version 2 of the License, or
6873 + * (at your option) any later version.
6875 + * This program is distributed in the hope that it will be useful,
6876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6878 + * GNU General Public License for more details.
6880 + * You should have received a copy of the GNU General Public License
6881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6885 + * debugfs interface
6888 +#ifndef __DBGAUFS_H__
6889 +#define __DBGAUFS_H__
6893 +struct super_block;
6897 +#ifdef CONFIG_DEBUG_FS
6899 +void dbgaufs_xino_del(struct au_branch *br);
6900 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6901 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown);
6902 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6903 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6904 +void dbgaufs_fin(void);
6905 +int __init dbgaufs_init(void);
6907 +AuStubVoid(dbgaufs_xino_del, struct au_branch *br)
6908 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6909 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex,
6911 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6912 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6913 +AuStubVoid(dbgaufs_fin, void)
6914 +AuStubInt0(__init dbgaufs_init, void)
6915 +#endif /* CONFIG_DEBUG_FS */
6917 +#endif /* __KERNEL__ */
6918 +#endif /* __DBGAUFS_H__ */
6919 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6920 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6921 +++ linux/fs/aufs/dcsub.c 2022-11-05 23:02:18.962555950 +0100
6923 +// SPDX-License-Identifier: GPL-2.0
6925 + * Copyright (C) 2005-2022 Junjiro R. Okajima
6927 + * This program is free software; you can redistribute it and/or modify
6928 + * it under the terms of the GNU General Public License as published by
6929 + * the Free Software Foundation; either version 2 of the License, or
6930 + * (at your option) any later version.
6932 + * This program is distributed in the hope that it will be useful,
6933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6935 + * GNU General Public License for more details.
6937 + * You should have received a copy of the GNU General Public License
6938 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6942 + * sub-routines for dentry cache
6947 +static void au_dpage_free(struct au_dpage *dpage)
6950 + struct dentry **p;
6952 + p = dpage->dentries;
6953 + for (i = 0; i < dpage->ndentry; i++)
6955 + free_page((unsigned long)dpage->dentries);
6958 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6964 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6965 + if (unlikely(!dpages->dpages))
6968 + p = (void *)__get_free_page(gfp);
6972 + dpages->dpages[0].ndentry = 0;
6973 + dpages->dpages[0].dentries = p;
6974 + dpages->ndpage = 1;
6975 + return 0; /* success */
6978 + au_kfree_try_rcu(dpages->dpages);
6983 +void au_dpages_free(struct au_dcsub_pages *dpages)
6986 + struct au_dpage *p;
6988 + p = dpages->dpages;
6989 + for (i = 0; i < dpages->ndpage; i++)
6990 + au_dpage_free(p++);
6991 + au_kfree_try_rcu(dpages->dpages);
6994 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6995 + struct dentry *dentry, gfp_t gfp)
6998 + struct au_dpage *dpage;
7001 + dpage = dpages->dpages + dpages->ndpage - 1;
7002 + sz = PAGE_SIZE / sizeof(dentry);
7003 + if (unlikely(dpage->ndentry >= sz)) {
7004 + AuLabel(new dpage);
7006 + sz = dpages->ndpage * sizeof(*dpages->dpages);
7007 + p = au_kzrealloc(dpages->dpages, sz,
7008 + sz + sizeof(*dpages->dpages), gfp,
7013 + dpages->dpages = p;
7014 + dpage = dpages->dpages + dpages->ndpage;
7015 + p = (void *)__get_free_page(gfp);
7019 + dpage->ndentry = 0;
7020 + dpage->dentries = p;
7024 + AuDebugOn(au_dcount(dentry) <= 0);
7025 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
7026 + return 0; /* success */
7032 +/* todo: BAD approach */
7033 +/* copied from linux/fs/dcache.c */
7041 +extern void d_walk(struct dentry *parent, void *data,
7042 + enum d_walk_ret (*enter)(void *, struct dentry *));
7044 +struct ac_dpages_arg {
7046 + struct au_dcsub_pages *dpages;
7047 + struct super_block *sb;
7048 + au_dpages_test test;
7052 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
7054 + enum d_walk_ret ret;
7055 + struct ac_dpages_arg *arg = _arg;
7057 + ret = D_WALK_CONTINUE;
7058 + if (dentry->d_sb == arg->sb
7059 + && !IS_ROOT(dentry)
7060 + && au_dcount(dentry) > 0
7062 + && (!arg->test || arg->test(dentry, arg->arg))) {
7063 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
7064 + if (unlikely(arg->err))
7065 + ret = D_WALK_QUIT;
7071 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7072 + au_dpages_test test, void *arg)
7074 + struct ac_dpages_arg args = {
7082 + d_walk(root, &args, au_call_dpages_append);
7087 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7088 + int do_include, au_dpages_test test, void *arg)
7093 + write_seqlock(&rename_lock);
7094 + spin_lock(&dentry->d_lock);
7096 + && au_dcount(dentry) > 0
7097 + && (!test || test(dentry, arg)))
7098 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7099 + spin_unlock(&dentry->d_lock);
7100 + if (unlikely(err))
7104 + * RCU for vfsmount is unnecessary since this is a traverse in a single
7107 + while (!IS_ROOT(dentry)) {
7108 + dentry = dentry->d_parent; /* rename_lock is locked */
7109 + spin_lock(&dentry->d_lock);
7110 + if (au_dcount(dentry) > 0
7111 + && (!test || test(dentry, arg)))
7112 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
7113 + spin_unlock(&dentry->d_lock);
7114 + if (unlikely(err))
7119 + write_sequnlock(&rename_lock);
7123 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
7125 + return au_di(dentry) && dentry->d_sb == arg;
7128 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7129 + struct dentry *dentry, int do_include)
7131 + return au_dcsub_pages_rev(dpages, dentry, do_include,
7132 + au_dcsub_dpages_aufs, dentry->d_sb);
7135 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
7137 + struct path path[2] = {
7146 + return path_is_under(path + 0, path + 1);
7148 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
7149 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
7150 +++ linux/fs/aufs/dcsub.h 2022-11-05 23:02:18.962555950 +0100
7152 +/* SPDX-License-Identifier: GPL-2.0 */
7154 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7156 + * This program is free software; you can redistribute it and/or modify
7157 + * it under the terms of the GNU General Public License as published by
7158 + * the Free Software Foundation; either version 2 of the License, or
7159 + * (at your option) any later version.
7161 + * This program is distributed in the hope that it will be useful,
7162 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7163 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7164 + * GNU General Public License for more details.
7166 + * You should have received a copy of the GNU General Public License
7167 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7171 + * sub-routines for dentry cache
7174 +#ifndef __AUFS_DCSUB_H__
7175 +#define __AUFS_DCSUB_H__
7179 +#include <linux/dcache.h>
7180 +#include <linux/fs.h>
7184 + struct dentry **dentries;
7187 +struct au_dcsub_pages {
7189 + struct au_dpage *dpages;
7192 +/* ---------------------------------------------------------------------- */
7195 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
7196 +void au_dpages_free(struct au_dcsub_pages *dpages);
7197 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
7198 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
7199 + au_dpages_test test, void *arg);
7200 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
7201 + int do_include, au_dpages_test test, void *arg);
7202 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
7203 + struct dentry *dentry, int do_include);
7204 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
7206 +/* ---------------------------------------------------------------------- */
7209 + * todo: in linux-3.13, several similar (but faster) helpers are added to
7210 + * include/linux/dcache.h. Try them (in the future).
7213 +static inline int au_d_hashed_positive(struct dentry *d)
7216 + struct inode *inode = d_inode(d);
7219 + if (unlikely(d_unhashed(d)
7220 + || d_is_negative(d)
7221 + || !inode->i_nlink))
7226 +static inline int au_d_linkable(struct dentry *d)
7229 + struct inode *inode = d_inode(d);
7231 + err = au_d_hashed_positive(d);
7233 + && d_is_positive(d)
7234 + && (inode->i_state & I_LINKABLE))
7239 +static inline int au_d_alive(struct dentry *d)
7242 + struct inode *inode;
7246 + err = au_d_hashed_positive(d);
7248 + inode = d_inode(d);
7249 + if (unlikely(d_unlinked(d)
7250 + || d_is_negative(d)
7251 + || !inode->i_nlink))
7257 +static inline int au_alive_dir(struct dentry *d)
7261 + err = au_d_alive(d);
7262 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
7267 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
7269 + return a->len == b->len
7270 + && !memcmp(a->name, b->name, a->len);
7275 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
7277 + * the type of d_lockref.count became int, but the inlined function d_count()
7278 + * still returns unsigned int.
7279 + * I don't know why. Maybe it is for every d_count() users?
7280 + * Anyway au_dcount() lives on.
7282 +static inline int au_dcount(struct dentry *d)
7284 + return (int)d_count(d);
7287 +#endif /* __KERNEL__ */
7288 +#endif /* __AUFS_DCSUB_H__ */
7289 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7290 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7291 +++ linux/fs/aufs/debug.c 2023-08-28 12:34:39.956636132 +0200
7293 +// SPDX-License-Identifier: GPL-2.0
7295 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7297 + * This program is free software; you can redistribute it and/or modify
7298 + * it under the terms of the GNU General Public License as published by
7299 + * the Free Software Foundation; either version 2 of the License, or
7300 + * (at your option) any later version.
7302 + * This program is distributed in the hope that it will be useful,
7303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7305 + * GNU General Public License for more details.
7307 + * You should have received a copy of the GNU General Public License
7308 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7312 + * debug print functions
7315 +#include <linux/iversion.h>
7318 +/* Returns 0, or -errno. arg is in kp->arg. */
7319 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7323 + err = kstrtoint(val, 0, &n);
7333 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7334 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7339 + return sprintf(buffer, "%d", atomic_read(a));
7342 +static const struct kernel_param_ops param_ops_atomic_t = {
7343 + .set = param_atomic_t_set,
7344 + .get = param_atomic_t_get
7345 + /* void (*free)(void *arg) */
7348 +atomic_t aufs_debug = ATOMIC_INIT(0);
7349 +MODULE_PARM_DESC(debug, "debug print");
7350 +module_param_named(debug, aufs_debug, atomic_t, 0664);
7352 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7353 +char *au_plevel = KERN_DEBUG;
7354 +#define dpri(fmt, ...) do { \
7356 + && strcmp(au_plevel, KERN_DEBUG)) \
7357 + || au_debug_test()) \
7358 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7361 +/* ---------------------------------------------------------------------- */
7363 +void au_dpri_whlist(struct au_nhash *whlist)
7365 + unsigned long ul, n;
7366 + struct hlist_head *head;
7367 + struct au_vdir_wh *pos;
7369 + n = whlist->nh_num;
7370 + head = whlist->nh_head;
7371 + for (ul = 0; ul < n; ul++) {
7372 + hlist_for_each_entry(pos, head, wh_hash)
7373 + dpri("b%d, %.*s, %d\n",
7375 + pos->wh_str.len, pos->wh_str.name,
7381 +void au_dpri_vdir(struct au_vdir *vdir)
7384 + union au_vdir_deblk_p p;
7387 + if (!vdir || IS_ERR(vdir)) {
7388 + dpri("err %ld\n", PTR_ERR(vdir));
7392 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n",
7393 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7394 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7395 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7396 + p.deblk = vdir->vd_deblk[ul];
7398 + dpri("[%lu]: %p\n", ul, o);
7402 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7403 + struct dentry *wh)
7408 + if (!inode || IS_ERR(inode)) {
7409 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7413 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7414 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7415 + && sizeof(inode->i_blocks) != sizeof(u64));
7417 + n = (void *)wh->d_name.name;
7418 + l = wh->d_name.len;
7421 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7422 + " acl %p, def_acl %p,"
7423 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7425 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7426 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7427 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7428 + inode->i_acl, inode->i_default_acl,
7429 + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff,
7430 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7431 + inode->i_state, inode->i_flags, inode_peek_iversion(inode),
7432 + inode->i_generation,
7433 + l ? ", wh " : "", l, n);
7437 +void au_dpri_inode(struct inode *inode)
7439 + struct au_iinfo *iinfo;
7440 + struct au_hinode *hi;
7441 + aufs_bindex_t bindex;
7444 + err = do_pri_inode(-1, inode, -1, NULL);
7445 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7448 + iinfo = au_ii(inode);
7449 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7450 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7451 + if (iinfo->ii_btop < 0)
7454 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7455 + hi = au_hinode(iinfo, bindex);
7457 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7461 +void au_dpri_dalias(struct inode *inode)
7465 + spin_lock(&inode->i_lock);
7466 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7467 + au_dpri_dentry(d);
7468 + spin_unlock(&inode->i_lock);
7471 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7473 + struct dentry *wh = NULL;
7475 + struct inode *inode;
7476 + struct au_iinfo *iinfo;
7477 + struct au_hinode *hi;
7479 + if (!dentry || IS_ERR(dentry)) {
7480 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7483 + /* do not call dget_parent() here */
7484 + /* note: access d_xxx without d_lock */
7485 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7486 + bindex, dentry, dentry,
7487 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7488 + au_dcount(dentry), dentry->d_flags,
7489 + d_unhashed(dentry) ? "un" : "");
7492 + if (d_is_positive(dentry))
7493 + inode = d_inode(dentry);
7495 + && au_test_aufs(dentry->d_sb)
7497 + && !au_is_bad_inode(inode)) {
7498 + iinfo = au_ii(inode);
7499 + hi = au_hinode(iinfo, bindex);
7501 + wh = hi->hi_whdentry;
7503 + do_pri_inode(bindex, inode, hn, wh);
7507 +void au_dpri_dentry(struct dentry *dentry)
7509 + struct au_dinfo *dinfo;
7510 + aufs_bindex_t bindex;
7513 + err = do_pri_dentry(-1, dentry);
7514 + if (err || !au_test_aufs(dentry->d_sb))
7517 + dinfo = au_di(dentry);
7520 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7521 + dinfo->di_btop, dinfo->di_bbot,
7522 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7523 + dinfo->di_tmpfile);
7524 + if (dinfo->di_btop < 0)
7526 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7527 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7530 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7534 + if (!file || IS_ERR(file)) {
7535 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7540 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7541 + && au_test_aufs(file->f_path.dentry->d_sb)
7543 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7544 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7545 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7546 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7547 + file->f_version, file->f_pos, a);
7548 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7549 + do_pri_dentry(bindex, file->f_path.dentry);
7553 +void au_dpri_file(struct file *file)
7555 + struct au_finfo *finfo;
7556 + struct au_fidir *fidir;
7557 + struct au_hfile *hfile;
7558 + aufs_bindex_t bindex;
7561 + err = do_pri_file(-1, file);
7563 + || IS_ERR_OR_NULL(file->f_path.dentry)
7564 + || !au_test_aufs(file->f_path.dentry->d_sb))
7567 + finfo = au_fi(file);
7570 + if (finfo->fi_btop < 0)
7572 + fidir = finfo->fi_hdir;
7574 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7576 + for (bindex = finfo->fi_btop;
7577 + bindex >= 0 && bindex <= fidir->fd_bbot;
7579 + hfile = fidir->fd_hfile + bindex;
7580 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7584 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7586 + struct vfsmount *mnt;
7587 + struct super_block *sb;
7589 + if (!br || IS_ERR(br))
7591 + mnt = au_br_mnt(br);
7592 + if (!mnt || IS_ERR(mnt))
7595 + if (!sb || IS_ERR(sb))
7598 + dpri("s%d: {perm 0x%x, id %d, wbr %p}, "
7599 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7601 + bindex, br->br_perm, br->br_id, br->br_wbr,
7602 + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7603 + sb->s_flags, sb->s_count,
7604 + atomic_read(&sb->s_active),
7605 + !!au_xino_file(br->br_xino, /*idx*/-1));
7609 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7613 +void au_dpri_sb(struct super_block *sb)
7615 + struct au_sbinfo *sbinfo;
7616 + aufs_bindex_t bindex;
7618 + /* to reduce stack size */
7620 + struct vfsmount mnt;
7621 + struct au_branch fake;
7624 + /* this function can be called from magic sysrq */
7625 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7626 + if (unlikely(!a)) {
7627 + dpri("no memory\n");
7631 + a->mnt.mnt_sb = sb;
7632 + a->fake.br_path.mnt = &a->mnt;
7633 + err = do_pri_br(-1, &a->fake);
7635 + dpri("dev 0x%x\n", sb->s_dev);
7636 + if (err || !au_test_aufs(sb))
7639 + sbinfo = au_sbi(sb);
7642 + dpri("nw %d, gen %u, kobj %d\n",
7643 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7644 + kref_read(&sbinfo->si_kobj.kref));
7645 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7646 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7649 +/* ---------------------------------------------------------------------- */
7651 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7653 + struct inode *h_inode, *inode = d_inode(dentry);
7654 + struct dentry *h_dentry;
7655 + aufs_bindex_t bindex, bbot, bi;
7657 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7660 + bbot = au_dbbot(dentry);
7661 + bi = au_ibbot(inode);
7664 + bindex = au_dbtop(dentry);
7665 + bi = au_ibtop(inode);
7669 + for (; bindex <= bbot; bindex++) {
7670 + h_dentry = au_h_dptr(dentry, bindex);
7673 + h_inode = au_h_iptr(inode, bindex);
7674 + if (unlikely(h_inode != d_inode(h_dentry))) {
7676 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7677 + AuDbgDentry(dentry);
7678 + AuDbgInode(inode);
7680 + if (au_test_fuse(h_inode->i_sb))
7688 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7691 + struct au_dcsub_pages dpages;
7692 + struct au_dpage *dpage;
7693 + struct dentry **dentries;
7695 + err = au_dpages_init(&dpages, GFP_NOFS);
7697 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7699 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7700 + dpage = dpages.dpages + i;
7701 + dentries = dpage->dentries;
7702 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7703 + AuDebugOn(au_digen_test(dentries[j], sigen));
7705 + au_dpages_free(&dpages);
7708 +void au_dbg_verify_kthread(void)
7710 + if (au_wkq_test()) {
7713 + * It may be recursive, but udba=notify between two aufs mounts,
7714 + * where a single ro branch is shared, is not a problem.
7720 +/* ---------------------------------------------------------------------- */
7722 +int __init au_debug_init(void)
7724 + aufs_bindex_t bindex;
7725 + struct au_vdir_destr destr;
7728 + AuDebugOn(bindex >= 0);
7731 + AuDebugOn(destr.len < NAME_MAX);
7733 +#ifdef CONFIG_4KSTACKS
7734 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7739 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7740 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7741 +++ linux/fs/aufs/debug.h 2022-11-05 23:02:18.962555950 +0100
7743 +/* SPDX-License-Identifier: GPL-2.0 */
7745 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7747 + * This program is free software; you can redistribute it and/or modify
7748 + * it under the terms of the GNU General Public License as published by
7749 + * the Free Software Foundation; either version 2 of the License, or
7750 + * (at your option) any later version.
7752 + * This program is distributed in the hope that it will be useful,
7753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7755 + * GNU General Public License for more details.
7757 + * You should have received a copy of the GNU General Public License
7758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7762 + * debug print functions
7765 +#ifndef __AUFS_DEBUG_H__
7766 +#define __AUFS_DEBUG_H__
7770 +#include <linux/atomic.h>
7771 +#include <linux/module.h>
7772 +#include <linux/kallsyms.h>
7773 +#include <linux/sysrq.h>
7775 +#ifdef CONFIG_AUFS_DEBUG
7776 +#define AuDebugOn(a) BUG_ON(a)
7778 +/* module parameter */
7779 +extern atomic_t aufs_debug;
7780 +static inline void au_debug_on(void)
7782 + atomic_inc(&aufs_debug);
7784 +static inline void au_debug_off(void)
7786 + atomic_dec_if_positive(&aufs_debug);
7789 +static inline int au_debug_test(void)
7791 + return atomic_read(&aufs_debug) > 0;
7794 +#define AuDebugOn(a) do {} while (0)
7795 +AuStubVoid(au_debug_on, void)
7796 +AuStubVoid(au_debug_off, void)
7797 +AuStubInt0(au_debug_test, void)
7798 +#endif /* CONFIG_AUFS_DEBUG */
7800 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7802 +/* ---------------------------------------------------------------------- */
7806 +#define AuDbg(fmt, ...) do { \
7807 + if (au_debug_test()) \
7808 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7810 +#define AuLabel(l) AuDbg(#l "\n")
7811 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7812 +#define AuWarn1(fmt, ...) do { \
7813 + static unsigned char _c; \
7815 + pr_warn(fmt, ##__VA_ARGS__); \
7818 +#define AuErr1(fmt, ...) do { \
7819 + static unsigned char _c; \
7821 + pr_err(fmt, ##__VA_ARGS__); \
7824 +#define AuIOErr1(fmt, ...) do { \
7825 + static unsigned char _c; \
7827 + AuIOErr(fmt, ##__VA_ARGS__); \
7830 +#define AuUnsupportMsg "This operation is not supported." \
7831 + " Please report this application to aufs-users ML."
7832 +#define AuUnsupport(fmt, ...) do { \
7833 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7837 +#define AuTraceErr(e) do { \
7838 + if (unlikely((e) < 0)) \
7839 + AuDbg("err %d\n", (int)(e)); \
7842 +#define AuTraceErrPtr(p) do { \
7844 + AuDbg("err %ld\n", PTR_ERR(p)); \
7847 +/* dirty macros for debug print, use with "%.*s" and caution */
7848 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7850 +/* ---------------------------------------------------------------------- */
7853 +#ifdef CONFIG_AUFS_DEBUG
7854 +extern struct mutex au_dbg_mtx;
7855 +extern char *au_plevel;
7857 +void au_dpri_whlist(struct au_nhash *whlist);
7859 +void au_dpri_vdir(struct au_vdir *vdir);
7861 +void au_dpri_inode(struct inode *inode);
7862 +void au_dpri_dalias(struct inode *inode);
7863 +void au_dpri_dentry(struct dentry *dentry);
7865 +void au_dpri_file(struct file *filp);
7866 +struct super_block;
7867 +void au_dpri_sb(struct super_block *sb);
7869 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7870 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7871 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7872 +void au_dbg_verify_kthread(void);
7874 +int __init au_debug_init(void);
7876 +#define AuDbgWhlist(w) do { \
7877 + mutex_lock(&au_dbg_mtx); \
7879 + au_dpri_whlist(w); \
7880 + mutex_unlock(&au_dbg_mtx); \
7883 +#define AuDbgVdir(v) do { \
7884 + mutex_lock(&au_dbg_mtx); \
7886 + au_dpri_vdir(v); \
7887 + mutex_unlock(&au_dbg_mtx); \
7890 +#define AuDbgInode(i) do { \
7891 + mutex_lock(&au_dbg_mtx); \
7893 + au_dpri_inode(i); \
7894 + mutex_unlock(&au_dbg_mtx); \
7897 +#define AuDbgDAlias(i) do { \
7898 + mutex_lock(&au_dbg_mtx); \
7900 + au_dpri_dalias(i); \
7901 + mutex_unlock(&au_dbg_mtx); \
7904 +#define AuDbgDentry(d) do { \
7905 + mutex_lock(&au_dbg_mtx); \
7907 + au_dpri_dentry(d); \
7908 + mutex_unlock(&au_dbg_mtx); \
7911 +#define AuDbgFile(f) do { \
7912 + mutex_lock(&au_dbg_mtx); \
7914 + au_dpri_file(f); \
7915 + mutex_unlock(&au_dbg_mtx); \
7918 +#define AuDbgSb(sb) do { \
7919 + mutex_lock(&au_dbg_mtx); \
7920 + AuDbg(#sb "\n"); \
7922 + mutex_unlock(&au_dbg_mtx); \
7925 +#define AuDbgSym(addr) do { \
7926 + char sym[KSYM_SYMBOL_LEN]; \
7927 + sprint_symbol(sym, (unsigned long)addr); \
7928 + AuDbg("%s\n", sym); \
7931 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7932 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7933 +AuStubVoid(au_dbg_verify_kthread, void)
7934 +AuStubInt0(__init au_debug_init, void)
7936 +#define AuDbgWhlist(w) do {} while (0)
7937 +#define AuDbgVdir(v) do {} while (0)
7938 +#define AuDbgInode(i) do {} while (0)
7939 +#define AuDbgDAlias(i) do {} while (0)
7940 +#define AuDbgDentry(d) do {} while (0)
7941 +#define AuDbgFile(f) do {} while (0)
7942 +#define AuDbgSb(sb) do {} while (0)
7943 +#define AuDbgSym(addr) do {} while (0)
7944 +#endif /* CONFIG_AUFS_DEBUG */
7946 +/* ---------------------------------------------------------------------- */
7948 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7949 +int __init au_sysrq_init(void);
7950 +void au_sysrq_fin(void);
7952 +#ifdef CONFIG_HW_CONSOLE
7953 +#define au_dbg_blocked() do { \
7955 + handle_sysrq('w'); \
7958 +AuStubVoid(au_dbg_blocked, void)
7962 +AuStubInt0(__init au_sysrq_init, void)
7963 +AuStubVoid(au_sysrq_fin, void)
7964 +AuStubVoid(au_dbg_blocked, void)
7965 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7967 +#endif /* __KERNEL__ */
7968 +#endif /* __AUFS_DEBUG_H__ */
7969 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7970 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7971 +++ linux/fs/aufs/dentry.c 2023-08-28 12:34:39.956636132 +0200
7973 +// SPDX-License-Identifier: GPL-2.0
7975 + * Copyright (C) 2005-2022 Junjiro R. Okajima
7977 + * This program is free software; you can redistribute it and/or modify
7978 + * it under the terms of the GNU General Public License as published by
7979 + * the Free Software Foundation; either version 2 of the License, or
7980 + * (at your option) any later version.
7982 + * This program is distributed in the hope that it will be useful,
7983 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7984 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7985 + * GNU General Public License for more details.
7987 + * You should have received a copy of the GNU General Public License
7988 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7992 + * lookup and dentry operations
7995 +#include <linux/iversion.h>
7999 + * returns positive/negative dentry, NULL or an error.
8000 + * NULL means whiteout-ed or not-found.
8002 +static struct dentry*
8003 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
8004 + aufs_bindex_t bindex, struct au_do_lookup_args *args)
8006 + struct dentry *h_dentry;
8007 + struct inode *h_inode;
8008 + struct au_branch *br;
8009 + struct mnt_idmap *h_idmap;
8010 + struct path h_path;
8011 + int wh_found, opq;
8012 + unsigned char wh_able;
8013 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
8014 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
8018 + br = au_sbr(dentry->d_sb, bindex);
8019 + h_path.dentry = h_parent;
8020 + h_path.mnt = au_br_mnt(br);
8021 + h_idmap = au_br_idmap(br);
8022 + wh_able = !!au_br_whable(br->br_perm);
8024 + wh_found = au_wh_test(h_idmap, &h_path, &args->whname,
8026 + h_dentry = ERR_PTR(wh_found);
8029 + if (unlikely(wh_found < 0))
8032 + /* We found a whiteout */
8033 + /* au_set_dbbot(dentry, bindex); */
8034 + au_set_dbwh(dentry, bindex);
8036 + return NULL; /* success */
8040 + h_dentry = vfsub_lkup_one(args->name, &h_path);
8042 + h_dentry = au_sio_lkup_one(h_idmap, args->name, &h_path);
8043 + if (IS_ERR(h_dentry)) {
8044 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
8050 + h_inode = d_inode(h_dentry);
8051 + if (d_is_negative(h_dentry)) {
8054 + } else if (wh_found
8055 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
8057 + else if (au_ftest_lkup(args->flags, DIRREN)
8059 + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) {
8060 + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry,
8061 + (unsigned long long)h_inode->i_ino);
8065 + if (au_dbbot(dentry) <= bindex)
8066 + au_set_dbbot(dentry, bindex);
8067 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
8068 + au_set_dbtop(dentry, bindex);
8069 + au_set_h_dptr(dentry, bindex, h_dentry);
8071 + if (!d_is_dir(h_dentry)
8073 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
8074 + goto out; /* success */
8076 + h_path.dentry = h_dentry;
8077 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
8078 + opq = au_diropq_test(h_idmap, &h_path);
8079 + inode_unlock_shared(h_inode);
8081 + au_set_dbdiropq(dentry, bindex);
8082 + else if (unlikely(opq < 0)) {
8083 + au_set_h_dptr(dentry, bindex, NULL);
8084 + h_dentry = ERR_PTR(opq);
8095 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
8097 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
8098 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
8104 + * returns the number of lower positive dentries,
8105 + * otherwise an error.
8106 + * can be called at unlinking with @type is zero.
8108 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8109 + unsigned int flags)
8111 + int npositive, err;
8112 + aufs_bindex_t bindex, btail, bdiropq;
8113 + unsigned char isdir, dirperm1, dirren;
8114 + struct au_do_lookup_args args = {
8116 + .name = &dentry->d_name
8118 + struct dentry *parent;
8119 + struct super_block *sb;
8121 + sb = dentry->d_sb;
8122 + err = au_test_shwh(sb, args.name);
8123 + if (unlikely(err))
8126 + err = au_wh_name_alloc(&args.whname, args.name);
8127 + if (unlikely(err))
8130 + isdir = !!d_is_dir(dentry);
8131 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
8132 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
8134 + au_fset_lkup(args.flags, DIRREN);
8137 + parent = dget_parent(dentry);
8138 + btail = au_dbtaildir(parent);
8139 + for (bindex = btop; bindex <= btail; bindex++) {
8140 + struct dentry *h_parent, *h_dentry;
8141 + struct inode *h_inode, *h_dir;
8142 + struct au_branch *br;
8144 + h_dentry = au_h_dptr(dentry, bindex);
8146 + if (d_is_positive(h_dentry))
8150 + h_parent = au_h_dptr(parent, bindex);
8151 + if (!h_parent || !d_is_dir(h_parent))
8155 + /* if the inum matches, then use the prepared name */
8156 + err = au_dr_lkup_name(&args, bindex);
8157 + if (unlikely(err))
8161 + h_dir = d_inode(h_parent);
8162 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
8163 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args);
8164 + inode_unlock_shared(h_dir);
8165 + err = PTR_ERR(h_dentry);
8166 + if (IS_ERR(h_dentry))
8169 + au_fclr_lkup(args.flags, ALLOW_NEG);
8171 + au_fset_lkup(args.flags, IGNORE_PERM);
8173 + if (au_dbwh(dentry) == bindex)
8177 + if (d_is_negative(h_dentry))
8179 + h_inode = d_inode(h_dentry);
8182 + args.type = h_inode->i_mode & S_IFMT;
8183 + if (args.type != S_IFDIR)
8186 + /* the type of lower may be different */
8187 + bdiropq = au_dbdiropq(dentry);
8188 + if (bdiropq >= 0 && bdiropq <= bindex)
8191 + br = au_sbr(sb, bindex);
8193 + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino,
8194 + /*add_ent*/NULL)) {
8195 + /* prepare next name to lookup */
8196 + err = au_dr_lkup(&args, dentry, bindex);
8197 + if (unlikely(err))
8203 + AuLabel(positive);
8204 + au_update_dbtop(dentry);
8207 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
8208 + && au_dbtop(dentry) < 0)) {
8210 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
8216 + au_kfree_try_rcu(args.whname.name);
8218 + au_dr_lkup_fin(&args);
8223 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
8224 + struct path *ppath)
8226 + struct dentry *dentry;
8229 + if (!au_test_h_perm_sio(idmap, d_inode(ppath->dentry), MAY_EXEC))
8230 + dentry = vfsub_lkup_one(name, ppath);
8232 + struct vfsub_lkup_one_args args = {
8238 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
8239 + if (unlikely(wkq_err))
8240 + dentry = ERR_PTR(wkq_err);
8247 + * lookup @dentry on @bindex which should be negative.
8249 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
8252 + struct dentry *parent, *h_dentry;
8253 + struct au_branch *br;
8254 + struct mnt_idmap *h_idmap;
8255 + struct path h_ppath;
8257 + parent = dget_parent(dentry);
8258 + br = au_sbr(dentry->d_sb, bindex);
8259 + h_ppath.dentry = au_h_dptr(parent, bindex);
8260 + h_ppath.mnt = au_br_mnt(br);
8261 + h_idmap = au_br_idmap(br);
8263 + h_dentry = au_whtmp_lkup(h_ppath.dentry, br, &dentry->d_name);
8265 + h_dentry = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
8266 + err = PTR_ERR(h_dentry);
8267 + if (IS_ERR(h_dentry))
8269 + if (unlikely(d_is_positive(h_dentry))) {
8271 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
8277 + if (bindex < au_dbtop(dentry))
8278 + au_set_dbtop(dentry, bindex);
8279 + if (au_dbbot(dentry) < bindex)
8280 + au_set_dbbot(dentry, bindex);
8281 + au_set_h_dptr(dentry, bindex, h_dentry);
8288 +/* ---------------------------------------------------------------------- */
8290 +/* subset of struct inode */
8292 + unsigned long i_ino;
8293 + /* unsigned int i_nlink; */
8299 + blkcnt_t i_blocks;
8304 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
8306 + ia->i_ino = h_inode->i_ino;
8307 + /* ia->i_nlink = h_inode->i_nlink; */
8308 + ia->i_uid = h_inode->i_uid;
8309 + ia->i_gid = h_inode->i_gid;
8310 + ia->i_version = inode_query_iversion(h_inode);
8312 + ia->i_size = h_inode->i_size;
8313 + ia->i_blocks = h_inode->i_blocks;
8315 + ia->i_mode = (h_inode->i_mode & S_IFMT);
8318 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
8320 + return ia->i_ino != h_inode->i_ino
8321 + /* || ia->i_nlink != h_inode->i_nlink */
8322 + || !uid_eq(ia->i_uid, h_inode->i_uid)
8323 + || !gid_eq(ia->i_gid, h_inode->i_gid)
8324 + || !inode_eq_iversion(h_inode, ia->i_version)
8326 + || ia->i_size != h_inode->i_size
8327 + || ia->i_blocks != h_inode->i_blocks
8329 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8332 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8333 + struct au_branch *br)
8336 + struct au_iattr ia;
8337 + struct inode *h_inode;
8338 + struct dentry *h_d;
8339 + struct super_block *h_sb;
8340 + struct path h_ppath;
8343 + memset(&ia, -1, sizeof(ia));
8344 + h_sb = h_dentry->d_sb;
8346 + if (d_is_positive(h_dentry)) {
8347 + h_inode = d_inode(h_dentry);
8348 + au_iattr_save(&ia, h_inode);
8349 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8350 + /* nfs d_revalidate may return 0 for negative dentry */
8351 + /* fuse d_revalidate always return 0 for negative dentry */
8354 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8355 + h_ppath.dentry = h_parent;
8356 + h_ppath.mnt = au_br_mnt(br);
8357 + h_d = vfsub_lkup_one(&h_dentry->d_name, &h_ppath);
8358 + err = PTR_ERR(h_d);
8363 + if (unlikely(h_d != h_dentry
8364 + || d_inode(h_d) != h_inode
8365 + || (h_inode && au_iattr_test(&ia, h_inode))))
8366 + err = au_busy_or_stale();
8374 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8375 + struct dentry *h_parent, struct au_branch *br)
8380 + if (udba == AuOpt_UDBA_REVAL
8381 + && !au_test_fs_remote(h_dentry->d_sb)) {
8383 + err = (d_inode(h_dentry->d_parent) != h_dir);
8384 + } else if (udba != AuOpt_UDBA_NONE)
8385 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8390 +/* ---------------------------------------------------------------------- */
8392 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8395 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8396 + struct au_hdentry tmp, *p, *q;
8397 + struct au_dinfo *dinfo;
8398 + struct super_block *sb;
8400 + DiMustWriteLock(dentry);
8402 + sb = dentry->d_sb;
8403 + dinfo = au_di(dentry);
8404 + bbot = dinfo->di_bbot;
8405 + bwh = dinfo->di_bwh;
8406 + bdiropq = dinfo->di_bdiropq;
8407 + bindex = dinfo->di_btop;
8408 + p = au_hdentry(dinfo, bindex);
8409 + for (; bindex <= bbot; bindex++, p++) {
8410 + if (!p->hd_dentry)
8413 + new_bindex = au_br_index(sb, p->hd_id);
8414 + if (new_bindex == bindex)
8417 + if (dinfo->di_bwh == bindex)
8419 + if (dinfo->di_bdiropq == bindex)
8420 + bdiropq = new_bindex;
8421 + if (new_bindex < 0) {
8423 + p->hd_dentry = NULL;
8427 + /* swap two lower dentries, and loop again */
8428 + q = au_hdentry(dinfo, new_bindex);
8432 + if (tmp.hd_dentry) {
8438 + dinfo->di_bwh = -1;
8439 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8440 + dinfo->di_bwh = bwh;
8442 + dinfo->di_bdiropq = -1;
8444 + && bdiropq <= au_sbbot(sb)
8445 + && au_sbr_whable(sb, bdiropq))
8446 + dinfo->di_bdiropq = bdiropq;
8449 + dinfo->di_btop = -1;
8450 + dinfo->di_bbot = -1;
8451 + bbot = au_dbbot(parent);
8453 + p = au_hdentry(dinfo, bindex);
8454 + for (; bindex <= bbot; bindex++, p++)
8455 + if (p->hd_dentry) {
8456 + dinfo->di_btop = bindex;
8460 + if (dinfo->di_btop >= 0) {
8462 + p = au_hdentry(dinfo, bindex);
8463 + for (; bindex >= 0; bindex--, p--)
8464 + if (p->hd_dentry) {
8465 + dinfo->di_bbot = bindex;
8474 +static void au_do_hide(struct dentry *dentry)
8476 + struct inode *inode;
8478 + if (d_really_is_positive(dentry)) {
8479 + inode = d_inode(dentry);
8480 + if (!d_is_dir(dentry)) {
8481 + if (inode->i_nlink && !d_unhashed(dentry))
8482 + drop_nlink(inode);
8484 + clear_nlink(inode);
8485 + /* stop next lookup */
8486 + inode->i_flags |= S_DEAD;
8488 + smp_mb(); /* necessary? */
8493 +static int au_hide_children(struct dentry *parent)
8495 + int err, i, j, ndentry;
8496 + struct au_dcsub_pages dpages;
8497 + struct au_dpage *dpage;
8498 + struct dentry *dentry;
8500 + err = au_dpages_init(&dpages, GFP_NOFS);
8501 + if (unlikely(err))
8503 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8504 + if (unlikely(err))
8507 + /* in reverse order */
8508 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8509 + dpage = dpages.dpages + i;
8510 + ndentry = dpage->ndentry;
8511 + for (j = ndentry - 1; j >= 0; j--) {
8512 + dentry = dpage->dentries[j];
8513 + if (dentry != parent)
8514 + au_do_hide(dentry);
8519 + au_dpages_free(&dpages);
8524 +static void au_hide(struct dentry *dentry)
8528 + AuDbgDentry(dentry);
8529 + if (d_is_dir(dentry)) {
8530 + /* shrink_dcache_parent(dentry); */
8531 + err = au_hide_children(dentry);
8532 + if (unlikely(err))
8533 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8536 + au_do_hide(dentry);
8540 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8542 + * a dirty branch is added
8543 + * - on the top of layers
8544 + * - in the middle of layers
8545 + * - to the bottom of layers
8547 + * on the added branch there exists
8550 + * - a same named entry
8552 + * * negative --> positive
8553 + * * positive --> positive
8554 + * - type is unchanged
8555 + * - type is changed
8557 + * * negative --> negative
8558 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8561 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8562 + struct au_dinfo *tmp)
8565 + aufs_bindex_t bindex, bbot;
8567 + struct dentry *dentry;
8568 + struct inode *inode;
8570 + } orig_h, tmp_h = {
8573 + struct au_hdentry *hd;
8574 + struct inode *inode, *h_inode;
8575 + struct dentry *h_dentry;
8578 + AuDebugOn(dinfo->di_btop < 0);
8580 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8581 + orig_h.inode = NULL;
8582 + if (d_is_positive(orig_h.dentry)) {
8583 + orig_h.inode = d_inode(orig_h.dentry);
8584 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8586 + if (tmp->di_btop >= 0) {
8587 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8588 + if (d_is_positive(tmp_h.dentry)) {
8589 + tmp_h.inode = d_inode(tmp_h.dentry);
8590 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8595 + if (d_really_is_positive(dentry))
8596 + inode = d_inode(dentry);
8597 + if (!orig_h.inode) {
8598 + AuDbg("negative originally\n");
8604 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8605 + AuDebugOn(dinfo->di_bdiropq != -1);
8607 + if (!tmp_h.inode) {
8608 + AuDbg("negative --> negative\n");
8609 + /* should have only one negative lower */
8610 + if (tmp->di_btop >= 0
8611 + && tmp->di_btop < dinfo->di_btop) {
8612 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8613 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8614 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8615 + au_di_cp(dinfo, tmp);
8616 + hd = au_hdentry(tmp, tmp->di_btop);
8617 + au_set_h_dptr(dentry, tmp->di_btop,
8618 + dget(hd->hd_dentry));
8620 + au_dbg_verify_dinode(dentry);
8622 + AuDbg("negative --> positive\n");
8624 + * similar to the behaviour of creating with bypassing
8626 + * unhash it in order to force an error in the
8627 + * succeeding create operation.
8628 + * we should not set S_DEAD here.
8631 + /* au_di_swap(tmp, dinfo); */
8632 + au_dbg_verify_dinode(dentry);
8635 + AuDbg("positive originally\n");
8636 + /* inode may be NULL */
8637 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8638 + if (!tmp_h.inode) {
8639 + AuDbg("positive --> negative\n");
8640 + /* or bypassing aufs */
8642 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8643 + dinfo->di_bwh = tmp->di_bwh;
8645 + err = au_refresh_hinode_self(inode);
8646 + au_dbg_verify_dinode(dentry);
8647 + } else if (orig_h.mode == tmp_h.mode) {
8648 + AuDbg("positive --> positive, same type\n");
8649 + if (!S_ISDIR(orig_h.mode)
8650 + && dinfo->di_btop > tmp->di_btop) {
8652 + * similar to the behaviour of removing and
8657 + err = au_refresh_hinode_self(inode);
8658 + au_dbg_verify_dinode(dentry);
8660 + /* fill empty slots */
8661 + if (dinfo->di_btop > tmp->di_btop)
8662 + dinfo->di_btop = tmp->di_btop;
8663 + if (dinfo->di_bbot < tmp->di_bbot)
8664 + dinfo->di_bbot = tmp->di_bbot;
8665 + dinfo->di_bwh = tmp->di_bwh;
8666 + dinfo->di_bdiropq = tmp->di_bdiropq;
8667 + bbot = dinfo->di_bbot;
8668 + bindex = tmp->di_btop;
8669 + hd = au_hdentry(tmp, bindex);
8670 + for (; bindex <= bbot; bindex++, hd++) {
8671 + if (au_h_dptr(dentry, bindex))
8673 + h_dentry = hd->hd_dentry;
8676 + AuDebugOn(d_is_negative(h_dentry));
8677 + h_inode = d_inode(h_dentry);
8678 + AuDebugOn(orig_h.mode
8679 + != (h_inode->i_mode
8681 + au_set_h_dptr(dentry, bindex,
8685 + err = au_refresh_hinode(inode, dentry);
8686 + au_dbg_verify_dinode(dentry);
8689 + AuDbg("positive --> positive, different type\n");
8690 + /* similar to the behaviour of removing and creating */
8693 + err = au_refresh_hinode_self(inode);
8694 + au_dbg_verify_dinode(dentry);
8702 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8704 + const struct dentry_operations *dop
8705 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8706 + static const unsigned int mask
8707 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8709 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8711 + if (dentry->d_op == dop)
8714 + AuDbg("%pd\n", dentry);
8715 + spin_lock(&dentry->d_lock);
8716 + if (dop == &aufs_dop)
8717 + dentry->d_flags |= mask;
8719 + dentry->d_flags &= ~mask;
8720 + dentry->d_op = dop;
8721 + spin_unlock(&dentry->d_lock);
8724 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8726 + int err, ebrange, nbr;
8727 + unsigned int sigen;
8728 + struct au_dinfo *dinfo, *tmp;
8729 + struct super_block *sb;
8730 + struct inode *inode;
8732 + DiMustWriteLock(dentry);
8733 + AuDebugOn(IS_ROOT(dentry));
8734 + AuDebugOn(d_really_is_negative(parent));
8736 + sb = dentry->d_sb;
8737 + sigen = au_sigen(sb);
8738 + err = au_digen_test(parent, sigen);
8739 + if (unlikely(err))
8742 + nbr = au_sbbot(sb) + 1;
8743 + dinfo = au_di(dentry);
8744 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8745 + if (unlikely(err))
8747 + ebrange = au_dbrange_test(dentry);
8749 + ebrange = au_do_refresh_hdentry(dentry, parent);
8751 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8752 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8753 + if (d_really_is_positive(dentry)) {
8754 + inode = d_inode(dentry);
8755 + err = au_refresh_hinode_self(inode);
8757 + au_dbg_verify_dinode(dentry);
8759 + goto out_dgen; /* success */
8763 + /* temporary dinfo */
8764 + AuDbgDentry(dentry);
8766 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8767 + if (unlikely(!tmp))
8769 + au_di_swap(tmp, dinfo);
8770 + /* returns the number of positive dentries */
8772 + * if current working dir is removed, it returns an error.
8773 + * but the dentry is legal.
8775 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8776 + AuDbgDentry(dentry);
8777 + au_di_swap(tmp, dinfo);
8778 + if (err == -ENOENT)
8781 + /* compare/refresh by dinfo */
8782 + AuDbgDentry(dentry);
8783 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8784 + au_dbg_verify_dinode(dentry);
8787 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8788 + au_rw_write_unlock(&tmp->di_rwsem);
8790 + if (unlikely(err))
8794 + au_update_digen(dentry);
8796 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8797 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8798 + AuDbgDentry(dentry);
8804 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8805 + struct dentry *dentry, aufs_bindex_t bindex)
8810 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8813 + AuDbg("b%d\n", bindex);
8815 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8816 + * due to whiteout and branch permission.
8818 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8819 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8820 + /* it may return tri-state */
8821 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8823 + if (unlikely(valid < 0))
8833 +/* todo: remove this */
8834 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8835 + unsigned int flags, int do_udba, int dirren)
8838 + umode_t mode, h_mode;
8839 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8840 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8841 + struct inode *h_inode, *h_cached_inode;
8842 + struct dentry *h_dentry;
8843 + struct qstr *name, *h_name;
8850 + unhashed = !!d_unhashed(dentry);
8851 + is_root = !!IS_ROOT(dentry);
8852 + name = &dentry->d_name;
8853 + tmpfile = au_di(dentry)->di_tmpfile;
8856 + * Theoretically, REVAL test should be unnecessary in case of
8858 + * But {fs,i}notify doesn't fire some necessary events,
8859 + * IN_ATTRIB for atime/nlink/pageio
8860 + * Let's do REVAL test too.
8862 + if (do_udba && inode) {
8863 + mode = (inode->i_mode & S_IFMT);
8864 + plus = (inode->i_nlink > 0);
8865 + ibs = au_ibtop(inode);
8866 + ibe = au_ibbot(inode);
8869 + btop = au_dbtop(dentry);
8871 + if (inode && S_ISDIR(inode->i_mode))
8872 + btail = au_dbtaildir(dentry);
8873 + for (bindex = btop; bindex <= btail; bindex++) {
8874 + h_dentry = au_h_dptr(dentry, bindex);
8878 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8879 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8880 + spin_lock(&h_dentry->d_lock);
8881 + h_name = &h_dentry->d_name;
8882 + if (unlikely(do_udba
8885 + && (unhashed != !!d_unhashed(h_dentry)
8886 + || (!tmpfile && !dirren
8887 + && !au_qstreq(name, h_name))
8890 + && !(flags & LOOKUP_OPEN)
8891 + && (h_dentry->d_flags
8892 + & DCACHE_NFSFS_RENAMED)))
8896 + h_unhashed = d_unhashed(h_dentry);
8897 + spin_unlock(&h_dentry->d_lock);
8898 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8899 + unhashed, h_unhashed, dentry, h_dentry);
8902 + spin_unlock(&h_dentry->d_lock);
8904 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8905 + if (unlikely(err))
8906 + /* do not goto err, to keep the errno */
8909 + /* todo: plink too? */
8914 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8918 + if (d_is_positive(h_dentry))
8919 + h_inode = d_inode(h_dentry);
8922 + h_cached_inode = h_inode;
8924 + h_mode = (h_inode->i_mode & S_IFMT);
8925 + h_plus = (h_inode->i_nlink > 0);
8927 + if (inode && ibs <= bindex && bindex <= ibe)
8928 + h_cached_inode = au_h_iptr(inode, bindex);
8931 + if (unlikely(plus != h_plus && !tmpfile))
8934 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8936 + && !IS_ROOT(h_dentry)
8937 + && unhashed != d_unhashed(h_dentry)))
8940 + if (unlikely(mode != h_mode
8941 + || h_cached_inode != h_inode))
8954 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8955 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8958 + struct dentry *parent;
8960 + if (!au_digen_test(dentry, sigen))
8963 + parent = dget_parent(dentry);
8964 + di_read_lock_parent(parent, AuLock_IR);
8965 + AuDebugOn(au_digen_test(parent, sigen));
8966 + au_dbg_verify_gen(parent, sigen);
8967 + err = au_refresh_dentry(dentry, parent);
8968 + di_read_unlock(parent, AuLock_IR);
8974 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8977 + struct dentry *d, *parent;
8979 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8980 + return simple_reval_dpath(dentry, sigen);
8982 + /* slow loop, keep it simple and stupid */
8983 + /* cf: au_cpup_dirs() */
8986 + while (au_digen_test(dentry, sigen)) {
8990 + parent = dget_parent(d);
8991 + if (!au_digen_test(parent, sigen))
8997 + di_write_lock_child2(d);
8999 + /* someone might update our dentry while we were sleeping */
9000 + if (au_digen_test(d, sigen)) {
9002 + * todo: consolidate with simple_reval_dpath(),
9003 + * do_refresh() and au_reval_for_attr().
9005 + di_read_lock_parent(parent, AuLock_IR);
9006 + err = au_refresh_dentry(d, parent);
9007 + di_read_unlock(parent, AuLock_IR);
9011 + di_write_unlock(d);
9013 + if (unlikely(err))
9021 + * if valid returns 1, otherwise 0.
9023 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
9026 + unsigned int sigen;
9027 + unsigned char do_udba, dirren;
9028 + struct super_block *sb;
9029 + struct inode *inode;
9031 + /* todo: support rcu-walk? */
9032 + if (flags & LOOKUP_RCU)
9036 + if (unlikely(!au_di(dentry)))
9040 + sb = dentry->d_sb;
9043 + * i_mutex of parent dir may be held,
9044 + * but we should not return 'invalid' due to busy.
9046 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
9047 + if (unlikely(err)) {
9053 + if (d_really_is_positive(dentry))
9054 + inode = d_inode(dentry);
9055 + if (unlikely(inode && au_is_bad_inode(inode))) {
9060 + if (unlikely(au_dbrange_test(dentry))) {
9066 + sigen = au_sigen(sb);
9067 + if (au_digen_test(dentry, sigen)) {
9068 + AuDebugOn(IS_ROOT(dentry));
9069 + err = au_reval_dpath(dentry, sigen);
9070 + if (unlikely(err)) {
9075 + di_downgrade_lock(dentry, AuLock_IR);
9078 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
9080 + && !(inode->i_state && I_LINKABLE)
9081 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
9086 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
9087 + if (do_udba && inode) {
9088 + aufs_bindex_t btop = au_ibtop(inode);
9089 + struct inode *h_inode;
9092 + h_inode = au_h_iptr(inode, btop);
9093 + if (h_inode && au_test_higen(inode, h_inode)) {
9100 + dirren = !!au_opt_test(au_mntflags(sb), DIRREN);
9101 + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren);
9102 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
9104 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
9110 + di_downgrade_lock(dentry, AuLock_IR);
9112 + aufs_read_unlock(dentry, AuLock_IR);
9117 + AuDbg("%pd invalid, %d\n", dentry, valid);
9123 +static void aufs_d_release(struct dentry *dentry)
9125 + if (au_di(dentry)) {
9126 + au_di_fin(dentry);
9127 + au_hn_di_reinit(dentry);
9131 +const struct dentry_operations aufs_dop = {
9132 + .d_revalidate = aufs_d_revalidate,
9133 + .d_weak_revalidate = aufs_d_revalidate,
9134 + .d_release = aufs_d_release
9137 +/* aufs_dop without d_revalidate */
9138 +const struct dentry_operations aufs_dop_noreval = {
9139 + .d_release = aufs_d_release
9141 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
9142 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
9143 +++ linux/fs/aufs/dentry.h 2023-08-28 12:34:39.956636132 +0200
9145 +/* SPDX-License-Identifier: GPL-2.0 */
9147 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9149 + * This program is free software; you can redistribute it and/or modify
9150 + * it under the terms of the GNU General Public License as published by
9151 + * the Free Software Foundation; either version 2 of the License, or
9152 + * (at your option) any later version.
9154 + * This program is distributed in the hope that it will be useful,
9155 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9156 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9157 + * GNU General Public License for more details.
9159 + * You should have received a copy of the GNU General Public License
9160 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9164 + * lookup and dentry operations
9167 +#ifndef __AUFS_DENTRY_H__
9168 +#define __AUFS_DENTRY_H__
9172 +#include <linux/dcache.h>
9173 +#include "dirren.h"
9176 +struct au_hdentry {
9177 + struct dentry *hd_dentry;
9178 + aufs_bindex_t hd_id;
9182 + atomic_t di_generation;
9184 + struct au_rwsem di_rwsem;
9185 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
9186 + unsigned char di_tmpfile; /* to allow the different name */
9187 + struct au_hdentry *di_hdentry;
9188 + struct file *di_htmpfile;
9189 + struct rcu_head rcu;
9190 +} ____cacheline_aligned_in_smp;
9192 +/* ---------------------------------------------------------------------- */
9194 +/* flags for au_lkup_dentry() */
9195 +#define AuLkup_ALLOW_NEG 1
9196 +#define AuLkup_IGNORE_PERM (1 << 1)
9197 +#define AuLkup_DIRREN (1 << 2)
9198 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
9199 +#define au_fset_lkup(flags, name) \
9200 + do { (flags) |= AuLkup_##name; } while (0)
9201 +#define au_fclr_lkup(flags, name) \
9202 + do { (flags) &= ~AuLkup_##name; } while (0)
9204 +#ifndef CONFIG_AUFS_DIRREN
9205 +#undef AuLkup_DIRREN
9206 +#define AuLkup_DIRREN 0
9209 +struct au_do_lookup_args {
9210 + unsigned int flags;
9212 + struct qstr whname, *name;
9213 + struct au_dr_lookup dirren;
9216 +/* ---------------------------------------------------------------------- */
9219 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
9221 +struct dentry *au_sio_lkup_one(struct mnt_idmap *idmap, struct qstr *name,
9222 + struct path *ppath);
9223 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
9224 + struct dentry *h_parent, struct au_branch *br);
9226 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
9227 + unsigned int flags);
9228 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
9229 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
9230 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
9231 +void au_refresh_dop(struct dentry *dentry, int force_reval);
9234 +void au_di_init_once(void *_di);
9235 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
9236 +void au_di_free(struct au_dinfo *dinfo);
9237 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
9238 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
9239 +int au_di_init(struct dentry *dentry);
9240 +void au_di_fin(struct dentry *dentry);
9241 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
9243 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
9244 +void di_read_unlock(struct dentry *d, int flags);
9245 +void di_downgrade_lock(struct dentry *d, int flags);
9246 +void di_write_lock(struct dentry *d, unsigned int lsc);
9247 +void di_write_unlock(struct dentry *d);
9248 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
9249 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
9250 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
9252 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
9253 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
9254 +aufs_bindex_t au_dbtail(struct dentry *dentry);
9255 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
9257 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9258 + struct dentry *h_dentry);
9259 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
9260 +int au_dbrange_test(struct dentry *dentry);
9261 +void au_update_digen(struct dentry *dentry);
9262 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
9263 +void au_update_dbtop(struct dentry *dentry);
9264 +void au_update_dbbot(struct dentry *dentry);
9265 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
9267 +/* ---------------------------------------------------------------------- */
9269 +static inline struct au_dinfo *au_di(struct dentry *dentry)
9271 + return dentry->d_fsdata;
9274 +/* ---------------------------------------------------------------------- */
9276 +/* lock subclass for dinfo */
9278 + AuLsc_DI_CHILD, /* child first */
9279 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
9280 + AuLsc_DI_CHILD3, /* copyup dirs */
9284 + AuLsc_DI_TMP /* temp for replacing dinfo */
9288 + * di_read_lock_child, di_write_lock_child,
9289 + * di_read_lock_child2, di_write_lock_child2,
9290 + * di_read_lock_child3, di_write_lock_child3,
9291 + * di_read_lock_parent, di_write_lock_parent,
9292 + * di_read_lock_parent2, di_write_lock_parent2,
9293 + * di_read_lock_parent3, di_write_lock_parent3,
9295 +#define AuReadLockFunc(name, lsc) \
9296 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
9297 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
9299 +#define AuWriteLockFunc(name, lsc) \
9300 +static inline void di_write_lock_##name(struct dentry *d) \
9301 +{ di_write_lock(d, AuLsc_DI_##lsc); }
9303 +#define AuRWLockFuncs(name, lsc) \
9304 + AuReadLockFunc(name, lsc) \
9305 + AuWriteLockFunc(name, lsc)
9307 +AuRWLockFuncs(child, CHILD);
9308 +AuRWLockFuncs(child2, CHILD2);
9309 +AuRWLockFuncs(child3, CHILD3);
9310 +AuRWLockFuncs(parent, PARENT);
9311 +AuRWLockFuncs(parent2, PARENT2);
9312 +AuRWLockFuncs(parent3, PARENT3);
9314 +#undef AuReadLockFunc
9315 +#undef AuWriteLockFunc
9316 +#undef AuRWLockFuncs
9318 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
9319 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
9320 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
9322 +/* ---------------------------------------------------------------------- */
9324 +/* todo: memory barrier? */
9325 +static inline unsigned int au_digen(struct dentry *d)
9327 + return atomic_read(&au_di(d)->di_generation);
9330 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
9332 + hdentry->hd_dentry = NULL;
9335 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
9336 + aufs_bindex_t bindex)
9338 + return di->di_hdentry + bindex;
9341 +static inline void au_hdput(struct au_hdentry *hd)
9344 + dput(hd->hd_dentry);
9347 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9349 + DiMustAnyLock(dentry);
9350 + return au_di(dentry)->di_btop;
9353 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9355 + DiMustAnyLock(dentry);
9356 + return au_di(dentry)->di_bbot;
9359 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9361 + DiMustAnyLock(dentry);
9362 + return au_di(dentry)->di_bwh;
9365 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9367 + DiMustAnyLock(dentry);
9368 + return au_di(dentry)->di_bdiropq;
9371 +/* todo: hard/soft set? */
9372 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9374 + DiMustWriteLock(dentry);
9375 + au_di(dentry)->di_btop = bindex;
9378 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9380 + DiMustWriteLock(dentry);
9381 + au_di(dentry)->di_bbot = bindex;
9384 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9386 + DiMustWriteLock(dentry);
9387 + /* dbwh can be outside of btop - bbot range */
9388 + au_di(dentry)->di_bwh = bindex;
9391 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9393 + DiMustWriteLock(dentry);
9394 + au_di(dentry)->di_bdiropq = bindex;
9397 +/* ---------------------------------------------------------------------- */
9399 +#ifdef CONFIG_AUFS_HNOTIFY
9400 +static inline void au_digen_dec(struct dentry *d)
9402 + atomic_dec(&au_di(d)->di_generation);
9405 +static inline void au_hn_di_reinit(struct dentry *dentry)
9407 + dentry->d_fsdata = NULL;
9410 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9411 +#endif /* CONFIG_AUFS_HNOTIFY */
9413 +#endif /* __KERNEL__ */
9414 +#endif /* __AUFS_DENTRY_H__ */
9415 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9416 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9417 +++ linux/fs/aufs/dinfo.c 2022-12-17 09:21:34.796521861 +0100
9419 +// SPDX-License-Identifier: GPL-2.0
9421 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9423 + * This program is free software; you can redistribute it and/or modify
9424 + * it under the terms of the GNU General Public License as published by
9425 + * the Free Software Foundation; either version 2 of the License, or
9426 + * (at your option) any later version.
9428 + * This program is distributed in the hope that it will be useful,
9429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9431 + * GNU General Public License for more details.
9433 + * You should have received a copy of the GNU General Public License
9434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9438 + * dentry private data
9443 +void au_di_init_once(void *_dinfo)
9445 + struct au_dinfo *dinfo = _dinfo;
9447 + au_rw_init(&dinfo->di_rwsem);
9450 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9452 + struct au_dinfo *dinfo;
9455 + dinfo = au_cache_alloc_dinfo();
9456 + if (unlikely(!dinfo))
9459 + nbr = au_sbbot(sb) + 1;
9462 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9463 + if (dinfo->di_hdentry) {
9464 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9465 + dinfo->di_btop = -1;
9466 + dinfo->di_bbot = -1;
9467 + dinfo->di_bwh = -1;
9468 + dinfo->di_bdiropq = -1;
9469 + dinfo->di_tmpfile = 0;
9470 + for (i = 0; i < nbr; i++)
9471 + dinfo->di_hdentry[i].hd_id = -1;
9472 + dinfo->di_htmpfile = NULL;
9476 + au_cache_free_dinfo(dinfo);
9483 +void au_di_free(struct au_dinfo *dinfo)
9485 + struct au_hdentry *p;
9486 + aufs_bindex_t bbot, bindex;
9488 + /* dentry may not be revalidated */
9489 + bindex = dinfo->di_btop;
9490 + if (bindex >= 0) {
9491 + bbot = dinfo->di_bbot;
9492 + p = au_hdentry(dinfo, bindex);
9493 + while (bindex++ <= bbot)
9496 + au_kfree_try_rcu(dinfo->di_hdentry);
9497 + au_cache_free_dinfo(dinfo);
9500 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9502 + struct au_hdentry *p;
9505 + AuRwMustWriteLock(&a->di_rwsem);
9506 + AuRwMustWriteLock(&b->di_rwsem);
9508 +#define DiSwap(v, name) \
9510 + v = a->di_##name; \
9511 + a->di_##name = b->di_##name; \
9512 + b->di_##name = v; \
9515 + DiSwap(p, hdentry);
9519 + DiSwap(bi, bdiropq);
9525 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9527 + AuRwMustWriteLock(&dst->di_rwsem);
9528 + AuRwMustWriteLock(&src->di_rwsem);
9530 + dst->di_btop = src->di_btop;
9531 + dst->di_bbot = src->di_bbot;
9532 + dst->di_bwh = src->di_bwh;
9533 + dst->di_bdiropq = src->di_bdiropq;
9537 +int au_di_init(struct dentry *dentry)
9540 + struct super_block *sb;
9541 + struct au_dinfo *dinfo;
9544 + sb = dentry->d_sb;
9545 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9547 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9548 + /* smp_mb(); */ /* atomic_set */
9549 + dentry->d_fsdata = dinfo;
9556 +void au_di_fin(struct dentry *dentry)
9558 + struct au_dinfo *dinfo;
9560 + dinfo = au_di(dentry);
9561 + AuRwDestroy(&dinfo->di_rwsem);
9562 + au_di_free(dinfo);
9565 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9568 + struct au_hdentry *hdp;
9570 + AuRwMustWriteLock(&dinfo->di_rwsem);
9573 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9575 + sz = sizeof(*hdp);
9576 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9579 + dinfo->di_hdentry = hdp;
9586 +/* ---------------------------------------------------------------------- */
9588 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9591 + case AuLsc_DI_CHILD:
9592 + ii_write_lock_child(inode);
9594 + case AuLsc_DI_CHILD2:
9595 + ii_write_lock_child2(inode);
9597 + case AuLsc_DI_CHILD3:
9598 + ii_write_lock_child3(inode);
9600 + case AuLsc_DI_PARENT:
9601 + ii_write_lock_parent(inode);
9603 + case AuLsc_DI_PARENT2:
9604 + ii_write_lock_parent2(inode);
9606 + case AuLsc_DI_PARENT3:
9607 + ii_write_lock_parent3(inode);
9614 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9617 + case AuLsc_DI_CHILD:
9618 + ii_read_lock_child(inode);
9620 + case AuLsc_DI_CHILD2:
9621 + ii_read_lock_child2(inode);
9623 + case AuLsc_DI_CHILD3:
9624 + ii_read_lock_child3(inode);
9626 + case AuLsc_DI_PARENT:
9627 + ii_read_lock_parent(inode);
9629 + case AuLsc_DI_PARENT2:
9630 + ii_read_lock_parent2(inode);
9632 + case AuLsc_DI_PARENT3:
9633 + ii_read_lock_parent3(inode);
9640 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9642 + struct inode *inode;
9644 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9645 + if (d_really_is_positive(d)) {
9646 + inode = d_inode(d);
9647 + if (au_ftest_lock(flags, IW))
9648 + do_ii_write_lock(inode, lsc);
9649 + else if (au_ftest_lock(flags, IR))
9650 + do_ii_read_lock(inode, lsc);
9654 +void di_read_unlock(struct dentry *d, int flags)
9656 + struct inode *inode;
9658 + if (d_really_is_positive(d)) {
9659 + inode = d_inode(d);
9660 + if (au_ftest_lock(flags, IW)) {
9661 + au_dbg_verify_dinode(d);
9662 + ii_write_unlock(inode);
9663 + } else if (au_ftest_lock(flags, IR)) {
9664 + au_dbg_verify_dinode(d);
9665 + ii_read_unlock(inode);
9668 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9671 +void di_downgrade_lock(struct dentry *d, int flags)
9673 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9674 + ii_downgrade_lock(d_inode(d));
9675 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9678 +void di_write_lock(struct dentry *d, unsigned int lsc)
9680 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9681 + if (d_really_is_positive(d))
9682 + do_ii_write_lock(d_inode(d), lsc);
9685 +void di_write_unlock(struct dentry *d)
9687 + au_dbg_verify_dinode(d);
9688 + if (d_really_is_positive(d))
9689 + ii_write_unlock(d_inode(d));
9690 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9693 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9695 + AuDebugOn(d1 == d2
9696 + || d_inode(d1) == d_inode(d2)
9697 + || d1->d_sb != d2->d_sb);
9699 + if ((isdir && au_test_subdir(d1, d2))
9701 + di_write_lock_child(d1);
9702 + di_write_lock_child2(d2);
9704 + di_write_lock_child(d2);
9705 + di_write_lock_child2(d1);
9709 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9711 + AuDebugOn(d1 == d2
9712 + || d_inode(d1) == d_inode(d2)
9713 + || d1->d_sb != d2->d_sb);
9715 + if ((isdir && au_test_subdir(d1, d2))
9717 + di_write_lock_parent(d1);
9718 + di_write_lock_parent2(d2);
9720 + di_write_lock_parent(d2);
9721 + di_write_lock_parent2(d1);
9725 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9727 + di_write_unlock(d1);
9728 + if (d_inode(d1) == d_inode(d2))
9729 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9731 + di_write_unlock(d2);
9734 +/* ---------------------------------------------------------------------- */
9736 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9740 + DiMustAnyLock(dentry);
9742 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9744 + AuDebugOn(bindex < 0);
9745 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9746 + AuDebugOn(d && au_dcount(d) <= 0);
9751 + * extended version of au_h_dptr().
9752 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9755 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9757 + struct dentry *h_dentry;
9758 + struct inode *inode, *h_inode;
9760 + AuDebugOn(d_really_is_negative(dentry));
9763 + if (au_dbtop(dentry) <= bindex
9764 + && bindex <= au_dbbot(dentry))
9765 + h_dentry = au_h_dptr(dentry, bindex);
9766 + if (h_dentry && !au_d_linkable(h_dentry)) {
9768 + goto out; /* success */
9771 + inode = d_inode(dentry);
9772 + AuDebugOn(bindex < au_ibtop(inode));
9773 + AuDebugOn(au_ibbot(inode) < bindex);
9774 + h_inode = au_h_iptr(inode, bindex);
9775 + h_dentry = d_find_alias(h_inode);
9777 + if (!IS_ERR(h_dentry)) {
9778 + if (!au_d_linkable(h_dentry))
9779 + goto out; /* success */
9785 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9786 + h_dentry = au_plink_lkup(inode, bindex);
9787 + AuDebugOn(!h_dentry);
9788 + if (!IS_ERR(h_dentry)) {
9789 + if (!au_d_hashed_positive(h_dentry))
9790 + goto out; /* success */
9797 + AuDbgDentry(h_dentry);
9801 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9803 + aufs_bindex_t bbot, bwh;
9805 + bbot = au_dbbot(dentry);
9807 + bwh = au_dbwh(dentry);
9810 + if (0 < bwh && bwh < bbot)
9816 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9818 + aufs_bindex_t bbot, bopq;
9820 + bbot = au_dbtail(dentry);
9822 + bopq = au_dbdiropq(dentry);
9823 + if (0 <= bopq && bopq < bbot)
9829 +/* ---------------------------------------------------------------------- */
9831 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9832 + struct dentry *h_dentry)
9834 + struct au_dinfo *dinfo;
9835 + struct au_hdentry *hd;
9836 + struct au_branch *br;
9838 + DiMustWriteLock(dentry);
9840 + dinfo = au_di(dentry);
9841 + hd = au_hdentry(dinfo, bindex);
9843 + hd->hd_dentry = h_dentry;
9845 + br = au_sbr(dentry->d_sb, bindex);
9846 + hd->hd_id = br->br_id;
9850 +int au_dbrange_test(struct dentry *dentry)
9853 + aufs_bindex_t btop, bbot;
9856 + btop = au_dbtop(dentry);
9857 + bbot = au_dbbot(dentry);
9859 + AuDebugOn(bbot < 0 && btop > bbot);
9862 + AuDebugOn(bbot >= 0);
9868 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9873 + if (unlikely(au_digen(dentry) != sigen
9874 + || au_iigen_test(d_inode(dentry), sigen)))
9880 +void au_update_digen(struct dentry *dentry)
9882 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9883 + /* smp_mb(); */ /* atomic_set */
9886 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9888 + struct au_dinfo *dinfo;
9889 + struct dentry *h_d;
9890 + struct au_hdentry *hdp;
9891 + aufs_bindex_t bindex, bbot;
9893 + DiMustWriteLock(dentry);
9895 + dinfo = au_di(dentry);
9896 + if (!dinfo || dinfo->di_btop < 0)
9899 + if (do_put_zero) {
9900 + bbot = dinfo->di_bbot;
9901 + bindex = dinfo->di_btop;
9902 + hdp = au_hdentry(dinfo, bindex);
9903 + for (; bindex <= bbot; bindex++, hdp++) {
9904 + h_d = hdp->hd_dentry;
9905 + if (h_d && d_is_negative(h_d))
9906 + au_set_h_dptr(dentry, bindex, NULL);
9910 + dinfo->di_btop = 0;
9911 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9912 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9913 + if (hdp->hd_dentry)
9915 + if (dinfo->di_btop > dinfo->di_bbot) {
9916 + dinfo->di_btop = -1;
9917 + dinfo->di_bbot = -1;
9921 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9922 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9923 + if (hdp->hd_dentry)
9925 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9928 +void au_update_dbtop(struct dentry *dentry)
9930 + aufs_bindex_t bindex, bbot;
9931 + struct dentry *h_dentry;
9933 + bbot = au_dbbot(dentry);
9934 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9935 + h_dentry = au_h_dptr(dentry, bindex);
9938 + if (d_is_positive(h_dentry)) {
9939 + au_set_dbtop(dentry, bindex);
9942 + au_set_h_dptr(dentry, bindex, NULL);
9946 +void au_update_dbbot(struct dentry *dentry)
9948 + aufs_bindex_t bindex, btop;
9949 + struct dentry *h_dentry;
9951 + btop = au_dbtop(dentry);
9952 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9953 + h_dentry = au_h_dptr(dentry, bindex);
9956 + if (d_is_positive(h_dentry)) {
9957 + au_set_dbbot(dentry, bindex);
9960 + au_set_h_dptr(dentry, bindex, NULL);
9964 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9966 + aufs_bindex_t bindex, bbot;
9968 + bbot = au_dbbot(dentry);
9969 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9970 + if (au_h_dptr(dentry, bindex) == h_dentry)
9974 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9975 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9976 +++ linux/fs/aufs/dir.c 2023-08-28 12:34:39.956636132 +0200
9978 +// SPDX-License-Identifier: GPL-2.0
9980 + * Copyright (C) 2005-2022 Junjiro R. Okajima
9982 + * This program is free software; you can redistribute it and/or modify
9983 + * it under the terms of the GNU General Public License as published by
9984 + * the Free Software Foundation; either version 2 of the License, or
9985 + * (at your option) any later version.
9987 + * This program is distributed in the hope that it will be useful,
9988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9990 + * GNU General Public License for more details.
9992 + * You should have received a copy of the GNU General Public License
9993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9997 + * directory operations
10000 +#include <linux/fs_stack.h>
10001 +#include <linux/iversion.h>
10004 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
10006 + unsigned int nlink;
10008 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10010 + nlink = dir->i_nlink;
10011 + nlink += h_dir->i_nlink - 2;
10012 + if (h_dir->i_nlink < 2)
10014 + smp_mb(); /* for i_nlink */
10015 + /* 0 can happen in revaliding */
10016 + set_nlink(dir, nlink);
10019 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
10021 + unsigned int nlink;
10023 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
10025 + nlink = dir->i_nlink;
10026 + nlink -= h_dir->i_nlink - 2;
10027 + if (h_dir->i_nlink < 2)
10029 + smp_mb(); /* for i_nlink */
10030 + /* nlink == 0 means the branch-fs is broken */
10031 + set_nlink(dir, nlink);
10034 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
10037 + aufs_bindex_t bindex, bbot;
10038 + struct file *h_file;
10039 + struct dentry *h_dentry;
10043 + AuDebugOn(!d_is_dir(file->f_path.dentry));
10045 + bbot = au_fbbot_dir(file);
10046 + for (bindex = au_fbtop(file);
10047 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10049 + h_file = au_hf_dir(file, bindex);
10050 + if (h_file && file_inode(h_file))
10051 + sz += vfsub_f_size_read(h_file);
10054 + AuDebugOn(!dentry);
10055 + AuDebugOn(!d_is_dir(dentry));
10057 + bbot = au_dbtaildir(dentry);
10058 + for (bindex = au_dbtop(dentry);
10059 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
10061 + h_dentry = au_h_dptr(dentry, bindex);
10062 + if (h_dentry && d_is_positive(h_dentry))
10063 + sz += i_size_read(d_inode(h_dentry));
10066 + if (sz < KMALLOC_MAX_SIZE)
10067 + sz = roundup_pow_of_two(sz);
10068 + if (sz > KMALLOC_MAX_SIZE)
10069 + sz = KMALLOC_MAX_SIZE;
10070 + else if (sz < NAME_MAX) {
10071 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
10072 + sz = AUFS_RDBLK_DEF;
10077 +struct au_dir_ts_arg {
10078 + struct dentry *dentry;
10079 + aufs_bindex_t brid;
10082 +static void au_do_dir_ts(void *arg)
10084 + struct au_dir_ts_arg *a = arg;
10085 + struct au_dtime dt;
10086 + struct path h_path;
10087 + struct inode *dir, *h_dir;
10088 + struct super_block *sb;
10089 + struct au_branch *br;
10090 + struct au_hinode *hdir;
10092 + aufs_bindex_t btop, bindex;
10094 + sb = a->dentry->d_sb;
10095 + if (d_really_is_negative(a->dentry))
10097 + /* no dir->i_mutex lock */
10098 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
10100 + dir = d_inode(a->dentry);
10101 + btop = au_ibtop(dir);
10102 + bindex = au_br_index(sb, a->brid);
10103 + if (bindex < btop)
10106 + br = au_sbr(sb, bindex);
10107 + h_path.dentry = au_h_dptr(a->dentry, bindex);
10108 + if (!h_path.dentry)
10110 + h_path.mnt = au_br_mnt(br);
10111 + au_dtime_store(&dt, a->dentry, &h_path);
10113 + br = au_sbr(sb, btop);
10114 + if (!au_br_writable(br->br_perm))
10116 + h_path.dentry = au_h_dptr(a->dentry, btop);
10117 + h_path.mnt = au_br_mnt(br);
10118 + err = vfsub_mnt_want_write(h_path.mnt);
10121 + hdir = au_hi(dir, btop);
10122 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
10123 + h_dir = au_h_iptr(dir, btop);
10124 + if (h_dir->i_nlink
10125 + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
10126 + dt.dt_h_path = h_path;
10127 + au_dtime_revert(&dt);
10129 + au_hn_inode_unlock(hdir);
10130 + vfsub_mnt_drop_write(h_path.mnt);
10131 + au_cpup_attr_timesizes(dir);
10134 + aufs_read_unlock(a->dentry, AuLock_DW);
10137 + au_nwt_done(&au_sbi(sb)->si_nowait);
10138 + au_kfree_try_rcu(arg);
10141 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
10143 + int perm, wkq_err;
10144 + aufs_bindex_t btop;
10145 + struct au_dir_ts_arg *arg;
10146 + struct dentry *dentry;
10147 + struct super_block *sb;
10151 + dentry = d_find_any_alias(dir);
10152 + AuDebugOn(!dentry);
10153 + sb = dentry->d_sb;
10154 + btop = au_ibtop(dir);
10155 + if (btop == bindex) {
10156 + au_cpup_attr_timesizes(dir);
10160 + perm = au_sbr_perm(sb, btop);
10161 + if (!au_br_writable(perm))
10164 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
10168 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
10169 + arg->brid = au_sbr_id(sb, bindex);
10170 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
10171 + if (unlikely(wkq_err)) {
10172 + pr_err("wkq %d\n", wkq_err);
10174 + au_kfree_try_rcu(arg);
10181 +/* ---------------------------------------------------------------------- */
10183 +static int reopen_dir(struct file *file)
10186 + unsigned int flags;
10187 + aufs_bindex_t bindex, btail, btop;
10188 + struct dentry *dentry, *h_dentry;
10189 + struct file *h_file;
10191 + /* open all lower dirs */
10192 + dentry = file->f_path.dentry;
10193 + btop = au_dbtop(dentry);
10194 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
10195 + au_set_h_fptr(file, bindex, NULL);
10196 + au_set_fbtop(file, btop);
10198 + btail = au_dbtaildir(dentry);
10199 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
10200 + au_set_h_fptr(file, bindex, NULL);
10201 + au_set_fbbot_dir(file, btail);
10203 + flags = vfsub_file_flags(file);
10204 + for (bindex = btop; bindex <= btail; bindex++) {
10205 + h_dentry = au_h_dptr(dentry, bindex);
10208 + h_file = au_hf_dir(file, bindex);
10212 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10213 + err = PTR_ERR(h_file);
10214 + if (IS_ERR(h_file))
10215 + goto out; /* close all? */
10216 + au_set_h_fptr(file, bindex, h_file);
10218 + au_update_figen(file);
10219 + /* todo: necessary? */
10220 + /* file->f_ra = h_file->f_ra; */
10227 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
10230 + aufs_bindex_t bindex, btail;
10231 + struct dentry *dentry, *h_dentry;
10232 + struct vfsmount *mnt;
10234 + FiMustWriteLock(file);
10235 + AuDebugOn(h_file);
10238 + mnt = file->f_path.mnt;
10239 + dentry = file->f_path.dentry;
10240 + file->f_version = inode_query_iversion(d_inode(dentry));
10241 + bindex = au_dbtop(dentry);
10242 + au_set_fbtop(file, bindex);
10243 + btail = au_dbtaildir(dentry);
10244 + au_set_fbbot_dir(file, btail);
10245 + for (; !err && bindex <= btail; bindex++) {
10246 + h_dentry = au_h_dptr(dentry, bindex);
10250 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
10251 + if (unlikely(err))
10253 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
10254 + if (IS_ERR(h_file)) {
10255 + err = PTR_ERR(h_file);
10258 + au_set_h_fptr(file, bindex, h_file);
10260 + au_update_figen(file);
10261 + /* todo: necessary? */
10262 + /* file->f_ra = h_file->f_ra; */
10264 + return 0; /* success */
10267 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
10268 + au_set_h_fptr(file, bindex, NULL);
10269 + au_set_fbtop(file, -1);
10270 + au_set_fbbot_dir(file, -1);
10275 +static int aufs_open_dir(struct inode *inode __maybe_unused,
10276 + struct file *file)
10279 + struct super_block *sb;
10280 + struct au_fidir *fidir;
10283 + sb = file->f_path.dentry->d_sb;
10284 + si_read_lock(sb, AuLock_FLUSH);
10285 + fidir = au_fidir_alloc(sb);
10287 + struct au_do_open_args args = {
10288 + .open = do_open_dir,
10291 + err = au_do_open(file, &args);
10292 + if (unlikely(err))
10293 + au_kfree_rcu(fidir);
10295 + si_read_unlock(sb);
10299 +static int aufs_release_dir(struct inode *inode __maybe_unused,
10300 + struct file *file)
10302 + struct au_vdir *vdir_cache;
10303 + struct au_finfo *finfo;
10304 + struct au_fidir *fidir;
10305 + struct au_hfile *hf;
10306 + aufs_bindex_t bindex, bbot;
10308 + finfo = au_fi(file);
10309 + fidir = finfo->fi_hdir;
10311 + au_hbl_del(&finfo->fi_hlist,
10312 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
10313 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
10315 + au_vdir_free(vdir_cache);
10317 + bindex = finfo->fi_btop;
10318 + if (bindex >= 0) {
10319 + hf = fidir->fd_hfile + bindex;
10321 + * calls fput() instead of filp_close(),
10322 + * since no dnotify or lock for the lower file.
10324 + bbot = fidir->fd_bbot;
10325 + for (; bindex <= bbot; bindex++, hf++)
10327 + au_hfput(hf, /*execed*/0);
10329 + au_kfree_rcu(fidir);
10330 + finfo->fi_hdir = NULL;
10332 + au_finfo_fin(file);
10336 +/* ---------------------------------------------------------------------- */
10338 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
10341 + aufs_bindex_t bindex, bbot;
10342 + struct file *h_file;
10345 + bbot = au_fbbot_dir(file);
10346 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10347 + h_file = au_hf_dir(file, bindex);
10349 + err = vfsub_flush(h_file, id);
10354 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10356 + return au_do_flush(file, id, au_do_flush_dir);
10359 +/* ---------------------------------------------------------------------- */
10361 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10364 + aufs_bindex_t bbot, bindex;
10365 + struct inode *inode;
10366 + struct super_block *sb;
10369 + sb = dentry->d_sb;
10370 + inode = d_inode(dentry);
10371 + IMustLock(inode);
10372 + bbot = au_dbbot(dentry);
10373 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10374 + struct path h_path;
10376 + if (au_test_ro(sb, bindex, inode))
10378 + h_path.dentry = au_h_dptr(dentry, bindex);
10379 + if (!h_path.dentry)
10382 + h_path.mnt = au_sbr_mnt(sb, bindex);
10383 + err = vfsub_fsync(NULL, &h_path, datasync);
10389 +static int au_do_fsync_dir(struct file *file, int datasync)
10392 + aufs_bindex_t bbot, bindex;
10393 + struct file *h_file;
10394 + struct super_block *sb;
10395 + struct inode *inode;
10397 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10398 + if (unlikely(err))
10401 + inode = file_inode(file);
10402 + sb = inode->i_sb;
10403 + bbot = au_fbbot_dir(file);
10404 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10405 + h_file = au_hf_dir(file, bindex);
10406 + if (!h_file || au_test_ro(sb, bindex, inode))
10409 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10417 + * @file may be NULL
10419 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10423 + struct dentry *dentry;
10424 + struct inode *inode;
10425 + struct super_block *sb;
10428 + dentry = file->f_path.dentry;
10429 + inode = d_inode(dentry);
10430 + inode_lock(inode);
10431 + sb = dentry->d_sb;
10432 + si_noflush_read_lock(sb);
10434 + err = au_do_fsync_dir(file, datasync);
10436 + di_write_lock_child(dentry);
10437 + err = au_do_fsync_dir_no_file(dentry, datasync);
10439 + au_cpup_attr_timesizes(inode);
10440 + di_write_unlock(dentry);
10442 + fi_write_unlock(file);
10444 + si_read_unlock(sb);
10445 + inode_unlock(inode);
10449 +/* ---------------------------------------------------------------------- */
10451 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10454 + struct dentry *dentry;
10455 + struct inode *inode, *h_inode;
10456 + struct super_block *sb;
10458 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
10460 + dentry = file->f_path.dentry;
10461 + inode = d_inode(dentry);
10462 + IMustLock(inode);
10464 + sb = dentry->d_sb;
10465 + si_read_lock(sb, AuLock_FLUSH);
10466 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0);
10467 + if (unlikely(err))
10469 + err = au_alive_dir(dentry);
10471 + err = au_vdir_init(file);
10472 + di_downgrade_lock(dentry, AuLock_IR);
10473 + if (unlikely(err))
10476 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10477 + if (!au_test_nfsd()) {
10478 + err = au_vdir_fill_de(file, ctx);
10479 + fsstack_copy_attr_atime(inode, h_inode);
10482 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10483 + * encode_fh() and others.
10485 + atomic_inc(&h_inode->i_count);
10486 + di_read_unlock(dentry, AuLock_IR);
10487 + si_read_unlock(sb);
10488 + err = au_vdir_fill_de(file, ctx);
10489 + fsstack_copy_attr_atime(inode, h_inode);
10490 + fi_write_unlock(file);
10498 + di_read_unlock(dentry, AuLock_IR);
10499 + fi_write_unlock(file);
10501 + si_read_unlock(sb);
10505 +/* ---------------------------------------------------------------------- */
10507 +#define AuTestEmpty_WHONLY 1
10508 +#define AuTestEmpty_CALLED (1 << 1)
10509 +#define AuTestEmpty_SHWH (1 << 2)
10510 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10511 +#define au_fset_testempty(flags, name) \
10512 + do { (flags) |= AuTestEmpty_##name; } while (0)
10513 +#define au_fclr_testempty(flags, name) \
10514 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10516 +#ifndef CONFIG_AUFS_SHWH
10517 +#undef AuTestEmpty_SHWH
10518 +#define AuTestEmpty_SHWH 0
10521 +struct test_empty_arg {
10522 + struct dir_context ctx;
10523 + struct au_nhash *whlist;
10524 + unsigned int flags;
10526 + aufs_bindex_t bindex;
10529 +static bool test_empty_cb(struct dir_context *ctx, const char *__name,
10530 + int namelen, loff_t offset __maybe_unused, u64 ino,
10531 + unsigned int d_type)
10533 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10535 + char *name = (void *)__name;
10538 + au_fset_testempty(arg->flags, CALLED);
10540 + if (name[0] == '.'
10541 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10542 + goto out; /* success */
10544 + if (namelen <= AUFS_WH_PFX_LEN
10545 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10546 + if (au_ftest_testempty(arg->flags, WHONLY)
10547 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10548 + arg->err = -ENOTEMPTY;
10552 + name += AUFS_WH_PFX_LEN;
10553 + namelen -= AUFS_WH_PFX_LEN;
10554 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10555 + arg->err = au_nhash_append_wh
10556 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10557 + au_ftest_testempty(arg->flags, SHWH));
10561 + AuTraceErr(arg->err);
10562 + return !arg->err;
10565 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10568 + struct file *h_file;
10569 + struct au_branch *br;
10571 + h_file = au_h_open(dentry, arg->bindex,
10572 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10573 + /*file*/NULL, /*force_wr*/0);
10574 + err = PTR_ERR(h_file);
10575 + if (IS_ERR(h_file))
10579 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10580 + && !file_inode(h_file)->i_nlink)
10585 + au_fclr_testempty(arg->flags, CALLED);
10587 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10590 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10594 + br = au_sbr(dentry->d_sb, arg->bindex);
10595 + au_lcnt_dec(&br->br_nfiles);
10600 +struct do_test_empty_args {
10602 + struct dentry *dentry;
10603 + struct test_empty_arg *arg;
10606 +static void call_do_test_empty(void *args)
10608 + struct do_test_empty_args *a = args;
10609 + *a->errp = do_test_empty(a->dentry, a->arg);
10612 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10614 + int err, wkq_err;
10615 + struct dentry *h_dentry;
10616 + struct inode *h_inode;
10617 + struct mnt_idmap *h_idmap;
10619 + h_idmap = au_sbr_idmap(dentry->d_sb, arg->bindex);
10620 + h_dentry = au_h_dptr(dentry, arg->bindex);
10621 + h_inode = d_inode(h_dentry);
10622 + /* todo: i_mode changes anytime? */
10623 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD);
10624 + err = au_test_h_perm_sio(h_idmap, h_inode, MAY_EXEC | MAY_READ);
10625 + inode_unlock_shared(h_inode);
10627 + err = do_test_empty(dentry, arg);
10629 + struct do_test_empty_args args = {
10631 + .dentry = dentry,
10634 + unsigned int flags = arg->flags;
10636 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10637 + if (unlikely(wkq_err))
10639 + arg->flags = flags;
10645 +int au_test_empty_lower(struct dentry *dentry)
10648 + unsigned int rdhash;
10649 + aufs_bindex_t bindex, btop, btail;
10650 + struct au_nhash whlist;
10651 + struct test_empty_arg arg = {
10653 + .actor = test_empty_cb
10656 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10658 + SiMustAnyLock(dentry->d_sb);
10660 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10662 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10663 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10664 + if (unlikely(err))
10668 + arg.whlist = &whlist;
10669 + btop = au_dbtop(dentry);
10670 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10671 + au_fset_testempty(arg.flags, SHWH);
10672 + test_empty = do_test_empty;
10673 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10674 + test_empty = sio_test_empty;
10675 + arg.bindex = btop;
10676 + err = test_empty(dentry, &arg);
10677 + if (unlikely(err))
10680 + au_fset_testempty(arg.flags, WHONLY);
10681 + btail = au_dbtaildir(dentry);
10682 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10683 + struct dentry *h_dentry;
10685 + h_dentry = au_h_dptr(dentry, bindex);
10686 + if (h_dentry && d_is_positive(h_dentry)) {
10687 + arg.bindex = bindex;
10688 + err = test_empty(dentry, &arg);
10693 + au_nhash_wh_free(&whlist);
10698 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10701 + struct test_empty_arg arg = {
10703 + .actor = test_empty_cb
10706 + aufs_bindex_t bindex, btail;
10709 + arg.whlist = whlist;
10710 + arg.flags = AuTestEmpty_WHONLY;
10711 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10712 + au_fset_testempty(arg.flags, SHWH);
10713 + btail = au_dbtaildir(dentry);
10714 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10715 + struct dentry *h_dentry;
10717 + h_dentry = au_h_dptr(dentry, bindex);
10718 + if (h_dentry && d_is_positive(h_dentry)) {
10719 + arg.bindex = bindex;
10720 + err = sio_test_empty(dentry, &arg);
10727 +/* ---------------------------------------------------------------------- */
10729 +const struct file_operations aufs_dir_fop = {
10730 + .owner = THIS_MODULE,
10731 + .llseek = default_llseek,
10732 + .read = generic_read_dir,
10733 + .iterate_shared = aufs_iterate_shared,
10734 + .unlocked_ioctl = aufs_ioctl_dir,
10735 +#ifdef CONFIG_COMPAT
10736 + .compat_ioctl = aufs_compat_ioctl_dir,
10738 + .open = aufs_open_dir,
10739 + .release = aufs_release_dir,
10740 + .flush = aufs_flush_dir,
10741 + .fsync = aufs_fsync_dir
10743 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10744 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10745 +++ linux/fs/aufs/dir.h 2022-11-05 23:02:18.962555950 +0100
10747 +/* SPDX-License-Identifier: GPL-2.0 */
10749 + * Copyright (C) 2005-2022 Junjiro R. Okajima
10751 + * This program is free software; you can redistribute it and/or modify
10752 + * it under the terms of the GNU General Public License as published by
10753 + * the Free Software Foundation; either version 2 of the License, or
10754 + * (at your option) any later version.
10756 + * This program is distributed in the hope that it will be useful,
10757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10759 + * GNU General Public License for more details.
10761 + * You should have received a copy of the GNU General Public License
10762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10766 + * directory operations
10769 +#ifndef __AUFS_DIR_H__
10770 +#define __AUFS_DIR_H__
10774 +#include <linux/fs.h>
10776 +/* ---------------------------------------------------------------------- */
10778 +/* need to be faster and smaller */
10781 + unsigned int nh_num;
10782 + struct hlist_head *nh_head;
10785 +struct au_vdir_destr {
10786 + unsigned char len;
10787 + unsigned char name[];
10790 +struct au_vdir_dehstr {
10791 + struct hlist_node hash;
10792 + struct au_vdir_destr *str;
10793 + struct rcu_head rcu;
10794 +} ____cacheline_aligned_in_smp;
10796 +struct au_vdir_de {
10798 + unsigned char de_type;
10799 + /* caution: packed */
10800 + struct au_vdir_destr de_str;
10803 +struct au_vdir_wh {
10804 + struct hlist_node wh_hash;
10805 +#ifdef CONFIG_AUFS_SHWH
10807 + aufs_bindex_t wh_bindex;
10808 + unsigned char wh_type;
10810 + aufs_bindex_t wh_bindex;
10812 + /* caution: packed */
10813 + struct au_vdir_destr wh_str;
10816 +union au_vdir_deblk_p {
10817 + unsigned char *deblk;
10818 + struct au_vdir_de *de;
10822 + unsigned char **vd_deblk;
10823 + unsigned long vd_nblk;
10825 + unsigned long ul;
10826 + union au_vdir_deblk_p p;
10830 + unsigned int vd_deblk_sz;
10831 + unsigned long vd_jiffy;
10832 + struct rcu_head rcu;
10833 +} ____cacheline_aligned_in_smp;
10835 +/* ---------------------------------------------------------------------- */
10838 +extern const struct file_operations aufs_dir_fop;
10839 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10840 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10841 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10842 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10843 +int au_test_empty_lower(struct dentry *dentry);
10844 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10847 +unsigned int au_rdhash_est(loff_t sz);
10848 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10849 +void au_nhash_wh_free(struct au_nhash *whlist);
10850 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10852 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10853 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10854 + unsigned int d_type, aufs_bindex_t bindex,
10855 + unsigned char shwh);
10856 +void au_vdir_free(struct au_vdir *vdir);
10857 +int au_vdir_init(struct file *file);
10858 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10861 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10863 +#ifdef CONFIG_AUFS_RDU
10865 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10866 +#ifdef CONFIG_COMPAT
10867 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10868 + unsigned long arg);
10871 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10872 + unsigned int cmd, unsigned long arg)
10873 +#ifdef CONFIG_COMPAT
10874 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10875 + unsigned int cmd, unsigned long arg)
10879 +#endif /* __KERNEL__ */
10880 +#endif /* __AUFS_DIR_H__ */
10881 diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c
10882 --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100
10883 +++ linux/fs/aufs/dirren.c 2022-11-05 23:02:18.962555950 +0100
10885 +// SPDX-License-Identifier: GPL-2.0
10887 + * Copyright (C) 2017-2022 Junjiro R. Okajima
10889 + * This program is free software; you can redistribute it and/or modify
10890 + * it under the terms of the GNU General Public License as published by
10891 + * the Free Software Foundation; either version 2 of the License, or
10892 + * (at your option) any later version.
10894 + * This program is distributed in the hope that it will be useful,
10895 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10896 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10897 + * GNU General Public License for more details.
10899 + * You should have received a copy of the GNU General Public License
10900 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10904 + * special handling in renaming a directory
10905 + * in order to support looking-up the before-renamed name on the lower readonly
10909 +#include <linux/byteorder/generic.h>
10912 +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent)
10916 + idx = au_dr_ihash(ent->dr_h_ino);
10917 + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx);
10920 +static int au_dr_hino_test_empty(struct au_dr_br *dr)
10923 + struct hlist_bl_head *hbl;
10926 + for (i = 0; ret && i < AuDirren_NHASH; i++) {
10927 + hbl = dr->dr_h_ino + i;
10928 + hlist_bl_lock(hbl);
10929 + ret &= hlist_bl_empty(hbl);
10930 + hlist_bl_unlock(hbl);
10936 +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino)
10938 + struct au_dr_hino *found, *ent;
10939 + struct hlist_bl_head *hbl;
10940 + struct hlist_bl_node *pos;
10944 + idx = au_dr_ihash(ino);
10945 + hbl = dr->dr_h_ino + idx;
10946 + hlist_bl_lock(hbl);
10947 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10948 + if (ent->dr_h_ino == ino) {
10952 + hlist_bl_unlock(hbl);
10957 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino,
10958 + struct au_dr_hino *add_ent)
10961 + struct hlist_bl_head *hbl;
10962 + struct hlist_bl_node *pos;
10963 + struct au_dr_hino *ent;
10966 + idx = au_dr_ihash(ino);
10967 + hbl = dr->dr_h_ino + idx;
10968 +#if 0 /* debug print */
10970 + struct hlist_bl_node *tmp;
10972 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
10973 + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino);
10976 + hlist_bl_lock(hbl);
10977 + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode)
10978 + if (ent->dr_h_ino == ino) {
10982 + if (!found && add_ent)
10983 + hlist_bl_add_head(&add_ent->dr_hnode, hbl);
10984 + hlist_bl_unlock(hbl);
10986 + if (!found && add_ent)
10987 + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino);
10992 +void au_dr_hino_free(struct au_dr_br *dr)
10995 + struct hlist_bl_head *hbl;
10996 + struct hlist_bl_node *pos, *tmp;
10997 + struct au_dr_hino *ent;
10999 + /* SiMustWriteLock(sb); */
11001 + for (i = 0; i < AuDirren_NHASH; i++) {
11002 + hbl = dr->dr_h_ino + i;
11003 + /* no spinlock since sbinfo must be write-locked */
11004 + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode)
11005 + au_kfree_rcu(ent);
11006 + INIT_HLIST_BL_HEAD(hbl);
11010 +/* returns the number of inodes or an error */
11011 +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br,
11012 + struct file *hinofile)
11016 + loff_t pos, oldsize;
11018 + struct inode *hinoinode;
11019 + struct hlist_bl_head *hbl;
11020 + struct hlist_bl_node *n1, *n2;
11021 + struct au_dr_hino *ent;
11023 + SiMustWriteLock(sb);
11024 + AuDebugOn(!au_br_writable(br->br_perm));
11026 + hinoinode = file_inode(hinofile);
11027 + oldsize = i_size_read(hinoinode);
11031 + hbl = br->br_dirren.dr_h_ino;
11032 + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) {
11033 + /* no bit-lock since sbinfo must be write-locked */
11034 + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) {
11035 + AuDbg("hi%llu, %pD2\n",
11036 + (unsigned long long)ent->dr_h_ino, hinofile);
11037 + u64 = cpu_to_be64(ent->dr_h_ino);
11038 + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos);
11039 + if (ssz == sizeof(u64))
11042 + /* write error */
11043 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11050 + /* regardless the error */
11051 + if (pos < oldsize) {
11052 + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile);
11060 +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile)
11067 + struct au_dr_hino *ent;
11068 + struct inode *hinoinode;
11069 + struct hlist_bl_head *hbl;
11073 + hbl = dr->dr_h_ino;
11074 + hinoinode = file_inode(hinofile);
11075 + sz = i_size_read(hinoinode);
11076 + AuDebugOn(sz % sizeof(u64));
11077 + n = sz / sizeof(u64);
11079 + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos);
11080 + if (unlikely(ssz != sizeof(u64))) {
11081 + pr_err("ssz %zd, %pD2\n", ssz, hinofile);
11088 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11094 + ent->dr_h_ino = be64_to_cpu((__force __be64)u64);
11095 + AuDbg("hi%llu, %pD2\n",
11096 + (unsigned long long)ent->dr_h_ino, hinofile);
11097 + hidx = au_dr_ihash(ent->dr_h_ino);
11098 + au_hbl_add(&ent->dr_hnode, hbl + hidx);
11100 + goto out; /* success */
11103 + au_dr_hino_free(dr);
11110 + * @bindex/@br is a switch to distinguish whether suspending hnotify or not.
11111 + * @path is a switch to distinguish load and store.
11113 +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex,
11114 + struct au_branch *br, const struct path *path)
11117 + unsigned char load, suspend;
11118 + struct file *hinofile;
11119 + struct au_hinode *hdir;
11120 + struct inode *dir, *delegated;
11121 + struct path hinopath;
11122 + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO,
11123 + sizeof(AUFS_WH_DR_BRHINO) - 1);
11125 + AuDebugOn(bindex < 0 && !br);
11126 + AuDebugOn(bindex >= 0 && br);
11131 + br = au_sbr(sb, bindex);
11134 + path = &br->br_path;
11135 + AuDebugOn(!au_br_writable(br->br_perm));
11136 + if (unlikely(!au_br_writable(br->br_perm)))
11142 + dir = d_inode(sb->s_root);
11143 + hdir = au_hinode(au_ii(dir), bindex);
11144 + dir = hdir->hi_inode;
11145 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11147 + dir = d_inode(path->dentry);
11148 + inode_lock_nested(dir, AuLsc_I_CHILD);
11150 + hinopath.mnt = path->mnt;
11151 + hinopath.dentry = vfsub_lkup_one(&hinoname, (struct path *)path);
11152 + err = PTR_ERR(hinopath.dentry);
11153 + if (IS_ERR(hinopath.dentry))
11157 + flags = O_RDONLY;
11159 + if (d_is_negative(hinopath.dentry))
11160 + goto out_dput; /* success */
11162 + if (au_dr_hino_test_empty(&br->br_dirren)) {
11163 + if (d_is_positive(hinopath.dentry)) {
11164 + delegated = NULL;
11165 + err = vfsub_unlink(dir, &hinopath, &delegated,
11168 + if (unlikely(err))
11169 + pr_err("ignored err %d, %pd2\n",
11170 + err, hinopath.dentry);
11171 + if (unlikely(err == -EWOULDBLOCK))
11176 + } else if (!d_is_positive(hinopath.dentry)) {
11177 + err = vfsub_create(dir, &hinopath, 0600,
11178 + /*want_excl*/false);
11180 + if (unlikely(err))
11183 + flags = O_WRONLY;
11185 + hinofile = vfsub_dentry_open(&hinopath, flags);
11187 + au_hn_inode_unlock(hdir);
11189 + inode_unlock(dir);
11190 + dput(hinopath.dentry);
11191 + AuTraceErrPtr(hinofile);
11192 + if (IS_ERR(hinofile)) {
11193 + err = PTR_ERR(hinofile);
11198 + err = au_dr_hino_load(&br->br_dirren, hinofile);
11200 + err = au_dr_hino_store(sb, br, hinofile);
11205 + dput(hinopath.dentry);
11208 + au_hn_inode_unlock(hdir);
11210 + inode_unlock(dir);
11216 +/* ---------------------------------------------------------------------- */
11218 +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path)
11221 + struct kstatfs kstfs;
11223 + struct dentry *dentry;
11224 + struct super_block *sb;
11226 + err = vfs_statfs((void *)path, &kstfs);
11228 + if (unlikely(err))
11231 + /* todo: support for UUID */
11233 + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) {
11234 + brid->type = AuBrid_FSID;
11235 + brid->fsid = kstfs.f_fsid;
11237 + dentry = path->dentry;
11238 + sb = dentry->d_sb;
11241 + brid->type = AuBrid_DEV;
11250 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
11251 + const struct path *path)
11254 + struct au_dr_br *dr;
11255 + struct hlist_bl_head *hbl;
11257 + dr = &br->br_dirren;
11258 + hbl = dr->dr_h_ino;
11259 + for (i = 0; i < AuDirren_NHASH; i++, hbl++)
11260 + INIT_HLIST_BL_HEAD(hbl);
11262 + err = au_dr_brid_init(&dr->dr_brid, path);
11263 + if (unlikely(err))
11266 + if (au_opt_test(au_mntflags(sb), DIRREN))
11267 + err = au_dr_hino(sb, /*bindex*/-1, br, path);
11274 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br)
11279 + if (au_br_writable(br->br_perm))
11280 + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL);
11282 + au_dr_hino_free(&br->br_dirren);
11287 +/* ---------------------------------------------------------------------- */
11289 +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode,
11290 + char *buf, size_t sz)
11293 + unsigned int major, minor;
11297 + err = snprintf(p, sz, "%d_", brid->type);
11298 + AuDebugOn(err > sz);
11301 + switch (brid->type) {
11302 + case AuBrid_Unset:
11304 + case AuBrid_UUID:
11305 + err = snprintf(p, sz, "%pU", brid->uuid.b);
11307 + case AuBrid_FSID:
11308 + err = snprintf(p, sz, "%08x-%08x",
11309 + brid->fsid.val[0], brid->fsid.val[1]);
11312 + major = MAJOR(brid->dev);
11313 + minor = MINOR(brid->dev);
11314 + if (major <= 0xff && minor <= 0xff)
11315 + err = snprintf(p, sz, "%02x%02x", major, minor);
11317 + err = snprintf(p, sz, "%03x:%05x", major, minor);
11320 + AuDebugOn(err > sz);
11323 + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino);
11324 + AuDebugOn(err > sz);
11331 +static int au_drinfo_name(struct au_branch *br, char *name, int len)
11334 + struct dentry *br_dentry;
11335 + struct inode *br_inode;
11337 + br_dentry = au_br_dentry(br);
11338 + br_inode = d_inode(br_dentry);
11339 + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len);
11340 + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ);
11341 + AuDebugOn(rlen > len);
11346 +/* ---------------------------------------------------------------------- */
11349 + * from the given @h_dentry, construct drinfo at @*fdata.
11350 + * when the size of @*fdata is not enough, reallocate and return new @fdata and
11353 +static int au_drinfo_construct(struct au_drinfo_fdata **fdata,
11354 + struct dentry *h_dentry,
11355 + unsigned char *allocated)
11358 + struct au_drinfo_fdata *f, *p;
11359 + struct au_drinfo *drinfo;
11360 + struct inode *h_inode;
11361 + struct qstr *qname;
11365 + h_inode = d_inode(h_dentry);
11366 + qname = &h_dentry->d_name;
11367 + drinfo = &f->drinfo;
11368 + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino);
11369 + drinfo->oldnamelen = qname->len;
11370 + if (*allocated < sizeof(*f) + qname->len) {
11371 + v = roundup_pow_of_two(*allocated + qname->len);
11372 + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0);
11373 + if (unlikely(!p)) {
11381 + drinfo = &f->drinfo;
11383 + memcpy(drinfo->oldname, qname->name, qname->len);
11384 + AuDbg("i%llu, %.*s\n",
11385 + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen,
11386 + drinfo->oldname);
11393 +/* callers have to free the return value */
11394 +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino)
11396 + struct au_drinfo *ret, *drinfo;
11397 + struct au_drinfo_fdata fdata;
11402 + ret = ERR_PTR(-EIO);
11404 + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos);
11405 + if (unlikely(ssz != sizeof(fdata))) {
11406 + AuIOErr("ssz %zd, %u, %pD2\n",
11407 + ssz, (unsigned int)sizeof(fdata), file);
11411 + fdata.magic = ntohl((__force __be32)fdata.magic);
11412 + switch (fdata.magic) {
11413 + case AUFS_DRINFO_MAGIC_V1:
11416 + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n",
11417 + fdata.magic, AUFS_DRINFO_MAGIC_V1, file);
11421 + drinfo = &fdata.drinfo;
11422 + len = drinfo->oldnamelen;
11424 + AuIOErr("broken drinfo %pD2\n", file);
11429 + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino);
11430 + if (unlikely(h_ino && drinfo->ino != h_ino)) {
11431 + AuDbg("ignored i%llu, i%llu, %pD2\n",
11432 + (unsigned long long)drinfo->ino,
11433 + (unsigned long long)h_ino, file);
11434 + goto out; /* success */
11437 + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS);
11438 + if (unlikely(!ret)) {
11439 + ret = ERR_PTR(-ENOMEM);
11440 + AuTraceErrPtr(ret);
11445 + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos);
11446 + if (unlikely(ssz != len)) {
11447 + au_kfree_rcu(ret);
11448 + ret = ERR_PTR(-EIO);
11449 + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file);
11453 + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname);
11459 +/* ---------------------------------------------------------------------- */
11461 +/* in order to be revertible */
11462 +struct au_drinfo_rev_elm {
11464 + struct dentry *info_dentry;
11465 + struct au_drinfo *info_last;
11468 +struct au_drinfo_rev {
11469 + unsigned char already;
11470 + aufs_bindex_t nelm;
11471 + struct au_drinfo_rev_elm elm[];
11474 +/* todo: isn't it too large? */
11475 +struct au_drinfo_store {
11476 + struct path h_ppath;
11477 + struct dentry *h_dentry;
11478 + struct au_drinfo_fdata *fdata;
11479 + char *infoname; /* inside of whname, just after PFX */
11480 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ];
11481 + aufs_bindex_t btgt, btail;
11482 + unsigned char no_sio,
11483 + allocated, /* current size of *fdata */
11484 + infonamelen, /* room size for p */
11485 + whnamelen, /* length of the generated name */
11486 + renameback; /* renamed back */
11489 +/* on rename(2) error, the caller should revert it using @elm */
11490 +static int au_drinfo_do_store(struct au_drinfo_store *w,
11491 + struct au_drinfo_rev_elm *elm)
11496 + struct path infopath = {
11497 + .mnt = w->h_ppath.mnt
11499 + struct inode *h_dir, *h_inode, *delegated;
11500 + struct file *infofile;
11501 + struct qstr *qname;
11504 + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm)));
11506 + infopath.dentry = vfsub_lookup_one_len(w->whname, &w->h_ppath,
11508 + AuTraceErrPtr(infopath.dentry);
11509 + if (IS_ERR(infopath.dentry)) {
11510 + err = PTR_ERR(infopath.dentry);
11515 + h_dir = d_inode(w->h_ppath.dentry);
11516 + if (elm && d_is_negative(infopath.dentry)) {
11517 + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true);
11519 + if (unlikely(err))
11521 + elm->created = 1;
11522 + elm->info_dentry = dget(infopath.dentry);
11525 + infofile = vfsub_dentry_open(&infopath, O_RDWR);
11526 + AuTraceErrPtr(infofile);
11527 + if (IS_ERR(infofile)) {
11528 + err = PTR_ERR(infofile);
11532 + h_inode = d_inode(infopath.dentry);
11533 + if (elm && i_size_read(h_inode)) {
11534 + h_inode = d_inode(w->h_dentry);
11535 + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino);
11536 + AuTraceErrPtr(elm->info_last);
11537 + if (IS_ERR(elm->info_last)) {
11538 + err = PTR_ERR(elm->info_last);
11539 + elm->info_last = NULL;
11540 + AuDebugOn(elm->info_dentry);
11545 + if (elm && w->renameback) {
11546 + delegated = NULL;
11547 + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0);
11549 + if (unlikely(err == -EWOULDBLOCK))
11555 + qname = &w->h_dentry->d_name;
11556 + len = sizeof(*w->fdata) + qname->len;
11558 + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen;
11559 + ssz = vfsub_write_k(infofile, w->fdata, len, &pos);
11560 + if (ssz == len) {
11561 + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino,
11562 + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname);
11563 + goto out_fput; /* success */
11568 + /* the caller should revert it using @elm */
11574 + dput(infopath.dentry);
11580 +struct au_call_drinfo_do_store_args {
11582 + struct au_drinfo_store *w;
11583 + struct au_drinfo_rev_elm *elm;
11586 +static void au_call_drinfo_do_store(void *args)
11588 + struct au_call_drinfo_do_store_args *a = args;
11590 + *a->errp = au_drinfo_do_store(a->w, a->elm);
11593 +static int au_drinfo_store_sio(struct au_drinfo_store *w,
11594 + struct au_drinfo_rev_elm *elm)
11596 + int err, wkq_err;
11599 + err = au_drinfo_do_store(w, elm);
11601 + struct au_call_drinfo_do_store_args a = {
11606 + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a);
11607 + if (unlikely(wkq_err))
11615 +static int au_drinfo_store_work_init(struct au_drinfo_store *w,
11616 + aufs_bindex_t btgt)
11620 + memset(w, 0, sizeof(*w));
11621 + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40);
11622 + strcpy(w->whname, AUFS_WH_DR_INFO_PFX);
11623 + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11624 + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX);
11626 + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
11629 + w->fdata = kcalloc(1, w->allocated, GFP_NOFS);
11630 + if (unlikely(!w->fdata)) {
11634 + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1);
11641 +static void au_drinfo_store_work_fin(struct au_drinfo_store *w)
11643 + au_kfree_rcu(w->fdata);
11646 +static void au_drinfo_store_rev(struct au_drinfo_rev *rev,
11647 + struct au_drinfo_store *w)
11649 + struct au_drinfo_rev_elm *elm;
11650 + struct inode *h_dir, *delegated;
11652 + struct path infopath = {
11653 + .mnt = w->h_ppath.mnt
11656 + h_dir = d_inode(w->h_ppath.dentry);
11657 + IMustLock(h_dir);
11661 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11662 + AuDebugOn(elm->created && elm->info_last);
11663 + if (elm->created) {
11665 + delegated = NULL;
11666 + infopath.dentry = elm->info_dentry;
11667 + err = vfsub_unlink(h_dir, &infopath, &delegated,
11670 + if (unlikely(err == -EWOULDBLOCK))
11672 + dput(elm->info_dentry);
11673 + } else if (elm->info_last) {
11675 + w->fdata->drinfo = *elm->info_last;
11676 + memcpy(w->fdata->drinfo.oldname,
11677 + elm->info_last->oldname,
11678 + elm->info_last->oldnamelen);
11679 + err = au_drinfo_store_sio(w, /*elm*/NULL);
11680 + au_kfree_rcu(elm->info_last);
11682 + if (unlikely(err))
11683 + AuIOErr("%d, %s\n", err, w->whname);
11684 + /* go on even if err */
11688 +/* caller has to call au_dr_rename_fin() later */
11689 +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt,
11690 + struct qstr *dst_name, void *_rev)
11692 + int err, sz, nelm;
11693 + aufs_bindex_t bindex, btail;
11694 + struct au_drinfo_store work;
11695 + struct au_drinfo_rev *rev, **p;
11696 + struct au_drinfo_rev_elm *elm;
11697 + struct super_block *sb;
11698 + struct au_branch *br;
11699 + struct au_hinode *hdir;
11701 + err = au_drinfo_store_work_init(&work, btgt);
11703 + if (unlikely(err))
11707 + btail = au_dbtaildir(dentry);
11708 + nelm = btail - btgt;
11709 + sz = sizeof(*rev) + sizeof(*elm) * nelm;
11710 + rev = kcalloc(1, sz, GFP_NOFS);
11711 + if (unlikely(!rev)) {
11715 + rev->nelm = nelm;
11721 + sb = dentry->d_sb;
11722 + work.h_ppath.dentry = au_h_dptr(dentry, btgt);
11723 + work.h_ppath.mnt = au_sbr_mnt(sb, btgt);
11724 + hdir = au_hi(d_inode(dentry), btgt);
11725 + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD);
11726 + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) {
11727 + work.h_dentry = au_h_dptr(dentry, bindex);
11728 + if (!work.h_dentry)
11731 + err = au_drinfo_construct(&work.fdata, work.h_dentry,
11732 + &work.allocated);
11734 + if (unlikely(err))
11737 + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name);
11738 + br = au_sbr(sb, bindex);
11739 + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11740 + work.whnamelen += au_drinfo_name(br, work.infoname,
11741 + work.infonamelen);
11742 + AuDbg("whname %.*s, i%llu, %.*s\n",
11743 + work.whnamelen, work.whname,
11744 + be64_to_cpu((__force __be64)work.fdata->drinfo.ino),
11745 + work.fdata->drinfo.oldnamelen,
11746 + work.fdata->drinfo.oldname);
11748 + err = au_drinfo_store_sio(&work, elm);
11750 + if (unlikely(err))
11753 + if (unlikely(err)) {
11754 + /* revert all drinfo */
11755 + au_drinfo_store_rev(rev, &work);
11756 + au_kfree_try_rcu(rev);
11759 + au_hn_inode_unlock(hdir);
11762 + au_drinfo_store_work_fin(&work);
11767 +/* ---------------------------------------------------------------------- */
11769 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
11770 + struct qstr *dst_name, void *_rev)
11772 + int err, already;
11774 + struct super_block *sb;
11775 + struct au_branch *br;
11776 + struct au_dr_br *dr;
11777 + struct dentry *h_dentry;
11778 + struct inode *h_inode;
11779 + struct au_dr_hino *ent;
11780 + struct au_drinfo_rev *rev, **p;
11782 + AuDbg("bindex %d\n", bindex);
11785 + ent = kmalloc(sizeof(*ent), GFP_NOFS);
11786 + if (unlikely(!ent))
11790 + br = au_sbr(sb, bindex);
11791 + dr = &br->br_dirren;
11792 + h_dentry = au_h_dptr(src, bindex);
11793 + h_inode = d_inode(h_dentry);
11794 + ino = h_inode->i_ino;
11795 + ent->dr_h_ino = ino;
11796 + already = au_dr_hino_test_add(dr, ino, ent);
11797 + AuDbg("b%d, hi%llu, already %d\n",
11798 + bindex, (unsigned long long)ino, already);
11800 + err = au_drinfo_store(src, bindex, dst_name, _rev);
11805 + rev->already = already;
11806 + goto out; /* success */
11811 + au_dr_hino_del(dr, ent);
11812 + au_kfree_rcu(ent);
11819 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11821 + struct au_drinfo_rev *rev;
11822 + struct au_drinfo_rev_elm *elm;
11827 + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) {
11828 + dput(elm->info_dentry);
11829 + au_kfree_rcu(elm->info_last);
11831 + au_kfree_try_rcu(rev);
11834 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev)
11837 + struct au_drinfo_store work;
11838 + struct au_drinfo_rev *rev = _rev;
11839 + struct super_block *sb;
11840 + struct au_branch *br;
11841 + struct inode *h_inode;
11842 + struct au_dr_br *dr;
11843 + struct au_dr_hino *ent;
11845 + err = au_drinfo_store_work_init(&work, btgt);
11846 + if (unlikely(err))
11850 + br = au_sbr(sb, btgt);
11851 + work.h_ppath.dentry = au_h_dptr(src, btgt);
11852 + work.h_ppath.mnt = au_br_mnt(br);
11853 + au_drinfo_store_rev(rev, &work);
11854 + au_drinfo_store_work_fin(&work);
11855 + if (rev->already)
11858 + dr = &br->br_dirren;
11859 + h_inode = d_inode(work.h_ppath.dentry);
11860 + ent = au_dr_hino_find(dr, h_inode->i_ino);
11862 + au_dr_hino_del(dr, ent);
11863 + au_kfree_rcu(ent);
11866 + au_kfree_try_rcu(rev);
11867 + if (unlikely(err))
11868 + pr_err("failed to remove dirren info\n");
11871 +/* ---------------------------------------------------------------------- */
11873 +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath,
11874 + char *whname, int whnamelen,
11875 + struct dentry **info_dentry)
11877 + struct au_drinfo *drinfo;
11879 + struct inode *h_dir;
11880 + struct path infopath;
11883 + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname);
11885 + *info_dentry = NULL;
11888 + h_dir = d_inode(h_ppath->dentry);
11889 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
11890 + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath, whnamelen);
11891 + if (IS_ERR(infopath.dentry)) {
11892 + drinfo = (void *)infopath.dentry;
11896 + if (d_is_negative(infopath.dentry))
11897 + goto out_dput; /* success */
11899 + infopath.mnt = h_ppath->mnt;
11900 + f = vfsub_dentry_open(&infopath, O_RDONLY);
11901 + inode_unlock_shared(h_dir);
11904 + drinfo = (void *)f;
11908 + drinfo = au_drinfo_read_k(f, /*h_ino*/0);
11909 + if (IS_ERR_OR_NULL(drinfo))
11912 + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname);
11913 + *info_dentry = dget(infopath.dentry); /* keep it alive */
11918 + dput(infopath.dentry);
11921 + inode_unlock_shared(h_dir);
11922 + AuTraceErrPtr(drinfo);
11926 +struct au_drinfo_do_load_args {
11927 + struct au_drinfo **drinfop;
11928 + struct path *h_ppath;
11931 + struct dentry **info_dentry;
11934 +static void au_call_drinfo_do_load(void *args)
11936 + struct au_drinfo_do_load_args *a = args;
11938 + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen,
11942 +struct au_drinfo_load {
11943 + struct path h_ppath;
11944 + struct qstr *qname;
11945 + unsigned char no_sio;
11947 + aufs_bindex_t ninfo;
11948 + struct au_drinfo **drinfo;
11951 +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex,
11952 + struct au_branch *br)
11954 + int err, wkq_err, whnamelen, e;
11955 + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]
11956 + = AUFS_WH_DR_INFO_PFX;
11957 + struct au_drinfo *drinfo;
11958 + struct qstr oldname;
11959 + struct inode *h_dir, *delegated;
11960 + struct dentry *info_dentry;
11961 + struct path infopath;
11963 + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1;
11964 + whnamelen += au_drinfo_name(br, whname + whnamelen,
11965 + sizeof(whname) - whnamelen);
11967 + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen,
11970 + struct au_drinfo_do_load_args args = {
11971 + .drinfop = &drinfo,
11972 + .h_ppath = &w->h_ppath,
11973 + .whname = whname,
11974 + .whnamelen = whnamelen,
11975 + .info_dentry = &info_dentry
11977 + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args);
11978 + if (unlikely(wkq_err))
11979 + drinfo = ERR_PTR(wkq_err);
11981 + err = PTR_ERR(drinfo);
11982 + if (IS_ERR_OR_NULL(drinfo))
11986 + oldname.len = drinfo->oldnamelen;
11987 + oldname.name = drinfo->oldname;
11988 + if (au_qstreq(w->qname, &oldname)) {
11989 + /* the name is renamed back */
11990 + au_kfree_rcu(drinfo);
11993 + infopath.dentry = info_dentry;
11994 + infopath.mnt = w->h_ppath.mnt;
11995 + h_dir = d_inode(w->h_ppath.dentry);
11996 + delegated = NULL;
11997 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
11998 + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio);
11999 + inode_unlock(h_dir);
12001 + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry);
12002 + if (unlikely(e == -EWOULDBLOCK))
12005 + au_kfree_rcu(w->drinfo[bindex]);
12006 + w->drinfo[bindex] = drinfo;
12007 + dput(info_dentry);
12014 +/* ---------------------------------------------------------------------- */
12016 +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n)
12018 + struct au_drinfo **p = drinfo;
12021 + au_kfree_rcu(*drinfo++);
12022 + au_kfree_try_rcu(p);
12025 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12026 + aufs_bindex_t btgt)
12029 + struct au_drinfo_load w;
12030 + aufs_bindex_t bindex, bbot;
12031 + struct au_branch *br;
12032 + struct inode *h_dir;
12033 + struct au_dr_hino *ent;
12034 + struct super_block *sb;
12036 + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n",
12037 + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name),
12038 + AuLNPair(&lkup->whname), btgt);
12040 + sb = dentry->d_sb;
12041 + bbot = au_sbbot(sb);
12042 + w.ninfo = bbot + 1;
12043 + if (!lkup->dirren.drinfo) {
12044 + lkup->dirren.drinfo = kcalloc(w.ninfo,
12045 + sizeof(*lkup->dirren.drinfo),
12047 + if (unlikely(!lkup->dirren.drinfo)) {
12051 + lkup->dirren.ninfo = w.ninfo;
12053 + w.drinfo = lkup->dirren.drinfo;
12054 + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID);
12055 + w.h_ppath.dentry = au_h_dptr(dentry, btgt);
12056 + AuDebugOn(!w.h_ppath.dentry);
12057 + w.h_ppath.mnt = au_sbr_mnt(sb, btgt);
12058 + w.qname = &dentry->d_name;
12061 + for (bindex = btgt + 1; bindex <= bbot; bindex++) {
12062 + br = au_sbr(sb, bindex);
12063 + err = au_drinfo_load(&w, bindex, br);
12064 + if (unlikely(err))
12066 + if (w.drinfo[bindex])
12070 + br = au_sbr(sb, btgt);
12071 + h_dir = d_inode(w.h_ppath.dentry);
12072 + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino);
12074 + au_dr_hino_del(&br->br_dirren, ent);
12075 + au_kfree_rcu(ent);
12077 + goto out; /* success */
12080 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12081 + lkup->dirren.ninfo = 0;
12082 + lkup->dirren.drinfo = NULL;
12088 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup)
12090 + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo);
12093 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt)
12096 + struct au_drinfo *drinfo;
12099 + if (!lkup->dirren.drinfo)
12101 + AuDebugOn(lkup->dirren.ninfo <= btgt);
12102 + drinfo = lkup->dirren.drinfo[btgt];
12106 + au_kfree_try_rcu(lkup->whname.name);
12107 + lkup->whname.name = NULL;
12108 + lkup->dirren.dr_name.len = drinfo->oldnamelen;
12109 + lkup->dirren.dr_name.name = drinfo->oldname;
12110 + lkup->name = &lkup->dirren.dr_name;
12111 + err = au_wh_name_alloc(&lkup->whname, lkup->name);
12113 + AuDbg("name %.*s, whname %.*s, b%d\n",
12114 + AuLNPair(lkup->name), AuLNPair(&lkup->whname),
12122 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12126 + struct au_drinfo *drinfo;
12129 + if (!lkup->dirren.drinfo)
12131 + AuDebugOn(lkup->dirren.ninfo <= bindex);
12132 + drinfo = lkup->dirren.drinfo[bindex];
12136 + match = (drinfo->ino == h_ino);
12137 + AuDbg("match %d\n", match);
12143 +/* ---------------------------------------------------------------------- */
12145 +int au_dr_opt_set(struct super_block *sb)
12148 + aufs_bindex_t bindex, bbot;
12149 + struct au_branch *br;
12152 + bbot = au_sbbot(sb);
12153 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12154 + br = au_sbr(sb, bindex);
12155 + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path);
12161 +int au_dr_opt_flush(struct super_block *sb)
12164 + aufs_bindex_t bindex, bbot;
12165 + struct au_branch *br;
12168 + bbot = au_sbbot(sb);
12169 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
12170 + br = au_sbr(sb, bindex);
12171 + if (au_br_writable(br->br_perm))
12172 + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL);
12178 +int au_dr_opt_clr(struct super_block *sb, int no_flush)
12181 + aufs_bindex_t bindex, bbot;
12182 + struct au_branch *br;
12186 + err = au_dr_opt_flush(sb);
12187 + if (unlikely(err))
12191 + bbot = au_sbbot(sb);
12192 + for (bindex = 0; bindex <= bbot; bindex++) {
12193 + br = au_sbr(sb, bindex);
12194 + au_dr_hino_free(&br->br_dirren);
12200 diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h
12201 --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100
12202 +++ linux/fs/aufs/dirren.h 2022-11-05 23:02:18.962555950 +0100
12204 +/* SPDX-License-Identifier: GPL-2.0 */
12206 + * Copyright (C) 2017-2022 Junjiro R. Okajima
12208 + * This program is free software; you can redistribute it and/or modify
12209 + * it under the terms of the GNU General Public License as published by
12210 + * the Free Software Foundation; either version 2 of the License, or
12211 + * (at your option) any later version.
12213 + * This program is distributed in the hope that it will be useful,
12214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12216 + * GNU General Public License for more details.
12218 + * You should have received a copy of the GNU General Public License
12219 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12223 + * renamed dir info
12226 +#ifndef __AUFS_DIRREN_H__
12227 +#define __AUFS_DIRREN_H__
12231 +#include <linux/dcache.h>
12232 +#include <linux/statfs.h>
12233 +#include <linux/uuid.h>
12236 +#define AuDirren_NHASH 100
12238 +#ifdef CONFIG_AUFS_DIRREN
12239 +enum au_brid_type {
12246 +struct au_dr_brid {
12247 + enum au_brid_type type;
12249 + uuid_t uuid; /* unimplemented yet */
12255 +/* 20 is the max digits length of ulong 64 */
12256 +/* brid-type "_" uuid "_" inum */
12257 +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20)
12258 +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20)
12260 +struct au_dr_hino {
12261 + struct hlist_bl_node dr_hnode;
12266 + struct hlist_bl_head dr_h_ino[AuDirren_NHASH];
12267 + struct au_dr_brid dr_brid;
12270 +struct au_dr_lookup {
12271 + /* dr_name is pointed by struct au_do_lookup_args.name */
12272 + struct qstr dr_name; /* subset of dr_info */
12273 + aufs_bindex_t ninfo;
12274 + struct au_drinfo **drinfo;
12277 +struct au_dr_hino;
12279 +struct au_dr_br { };
12280 +struct au_dr_lookup { };
12283 +/* ---------------------------------------------------------------------- */
12286 +struct au_do_lookup_args;
12288 +#ifdef CONFIG_AUFS_DIRREN
12289 +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino,
12290 + struct au_dr_hino *add_ent);
12291 +void au_dr_hino_free(struct au_dr_br *dr);
12292 +int au_dr_br_init(struct super_block *sb, struct au_branch *br,
12293 + const struct path *path);
12294 +int au_dr_br_fin(struct super_block *sb, struct au_branch *br);
12295 +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex,
12296 + struct qstr *dst_name, void *_rev);
12297 +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev);
12298 +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev);
12299 +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry,
12300 + aufs_bindex_t bindex);
12301 +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12302 +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex,
12304 +void au_dr_lkup_fin(struct au_do_lookup_args *lkup);
12305 +int au_dr_opt_set(struct super_block *sb);
12306 +int au_dr_opt_flush(struct super_block *sb);
12307 +int au_dr_opt_clr(struct super_block *sb, int no_flush);
12309 +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino,
12310 + struct au_dr_hino *add_ent);
12311 +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr);
12312 +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br,
12313 + const struct path *path);
12314 +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br);
12315 +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex,
12316 + struct qstr *dst_name, void *_rev);
12317 +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev);
12318 +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex,
12320 +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry,
12321 + aufs_bindex_t bindex);
12322 +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt);
12323 +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup,
12324 + aufs_bindex_t bindex, ino_t h_ino);
12325 +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup);
12326 +AuStubInt0(au_dr_opt_set, struct super_block *sb);
12327 +AuStubInt0(au_dr_opt_flush, struct super_block *sb);
12328 +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush);
12331 +/* ---------------------------------------------------------------------- */
12333 +#ifdef CONFIG_AUFS_DIRREN
12334 +static inline int au_dr_ihash(ino_t h_ino)
12336 + return h_ino % AuDirren_NHASH;
12339 +AuStubInt0(au_dr_ihash, ino_t h_ino);
12342 +#endif /* __KERNEL__ */
12343 +#endif /* __AUFS_DIRREN_H__ */
12344 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
12345 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
12346 +++ linux/fs/aufs/dynop.c 2022-11-05 23:02:18.962555950 +0100
12348 +// SPDX-License-Identifier: GPL-2.0
12350 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12352 + * This program is free software; you can redistribute it and/or modify
12353 + * it under the terms of the GNU General Public License as published by
12354 + * the Free Software Foundation; either version 2 of the License, or
12355 + * (at your option) any later version.
12357 + * This program is distributed in the hope that it will be useful,
12358 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12359 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12360 + * GNU General Public License for more details.
12362 + * You should have received a copy of the GNU General Public License
12363 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12367 + * dynamically customizable operations for regular files
12372 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
12375 + * How large will these lists be?
12376 + * Usually just a few elements, 20-30 at most for each, I guess.
12378 +static struct hlist_bl_head dynop[AuDyLast];
12380 +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl,
12381 + const void *h_op)
12383 + struct au_dykey *key, *tmp;
12384 + struct hlist_bl_node *pos;
12387 + hlist_bl_lock(hbl);
12388 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12389 + if (tmp->dk_op.dy_hop == h_op) {
12390 + if (kref_get_unless_zero(&tmp->dk_kref))
12394 + hlist_bl_unlock(hbl);
12399 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
12401 + struct au_dykey **k, *found;
12402 + const void *h_op = key->dk_op.dy_hop;
12406 + k = br->br_dykey;
12407 + for (i = 0; i < AuBrDynOp; i++)
12409 + if (k[i]->dk_op.dy_hop == h_op) {
12416 + spin_lock(&br->br_dykey_lock);
12417 + for (; i < AuBrDynOp; i++)
12419 + if (k[i]->dk_op.dy_hop == h_op) {
12427 + spin_unlock(&br->br_dykey_lock);
12428 + BUG_ON(i == AuBrDynOp); /* expand the array */
12434 +/* kref_get() if @key is already added */
12435 +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key)
12437 + struct au_dykey *tmp, *found;
12438 + struct hlist_bl_node *pos;
12439 + const void *h_op = key->dk_op.dy_hop;
12442 + hlist_bl_lock(hbl);
12443 + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode)
12444 + if (tmp->dk_op.dy_hop == h_op) {
12445 + if (kref_get_unless_zero(&tmp->dk_kref))
12450 + hlist_bl_add_head(&key->dk_hnode, hbl);
12451 + hlist_bl_unlock(hbl);
12458 +static void dy_free_rcu(struct rcu_head *rcu)
12460 + struct au_dykey *key;
12462 + key = container_of(rcu, struct au_dykey, dk_rcu);
12467 +static void dy_free(struct kref *kref)
12469 + struct au_dykey *key;
12470 + struct hlist_bl_head *hbl;
12472 + key = container_of(kref, struct au_dykey, dk_kref);
12473 + hbl = dynop + key->dk_op.dy_type;
12474 + au_hbl_del(&key->dk_hnode, hbl);
12475 + call_rcu(&key->dk_rcu, dy_free_rcu);
12478 +void au_dy_put(struct au_dykey *key)
12480 + kref_put(&key->dk_kref, dy_free);
12483 +/* ---------------------------------------------------------------------- */
12485 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
12487 +#ifdef CONFIG_AUFS_DEBUG
12488 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
12489 +#define DyDbgInc(cnt) do { cnt++; } while (0)
12491 +#define DyDbgDeclare(cnt) do {} while (0)
12492 +#define DyDbgInc(cnt) do {} while (0)
12495 +#define DySet(func, dst, src, h_op, h_sb) do { \
12497 + if (h_op->func) { \
12499 + dst.func = src.func; \
12501 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
12505 +#define DySetForce(func, dst, src) do { \
12506 + AuDebugOn(!src.func); \
12508 + dst.func = src.func; \
12511 +#define DySetAop(func) \
12512 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
12513 +#define DySetAopForce(func) \
12514 + DySetForce(func, dyaop->da_op, aufs_aop)
12516 +static void dy_aop(struct au_dykey *key, const void *h_op,
12517 + struct super_block *h_sb __maybe_unused)
12519 + struct au_dyaop *dyaop = (void *)key;
12520 + const struct address_space_operations *h_aop = h_op;
12521 + DyDbgDeclare(cnt);
12523 + AuDbg("%s\n", au_sbtype(h_sb));
12525 + DySetAop(writepage);
12526 + DySetAopForce(read_folio); /* force */
12527 + DySetAop(writepages);
12528 + DySetAop(dirty_folio);
12529 + DySetAop(invalidate_folio);
12530 + DySetAop(readahead);
12531 + DySetAop(write_begin);
12532 + DySetAop(write_end);
12534 + DySetAop(release_folio);
12535 + DySetAop(free_folio);
12536 + /* this one will be changed according to an aufs mount option */
12537 + DySetAop(direct_IO);
12538 + DySetAop(migrate_folio);
12539 + DySetAop(launder_folio);
12540 + DySetAop(is_partially_uptodate);
12541 + DySetAop(is_dirty_writeback);
12542 + DySetAop(error_remove_page);
12543 + DySetAop(swap_activate);
12544 + DySetAop(swap_deactivate);
12545 + DySetAop(swap_rw);
12547 + DyDbgSize(cnt, *h_aop);
12550 +/* ---------------------------------------------------------------------- */
12552 +static void dy_bug(struct kref *kref)
12557 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
12559 + struct au_dykey *key, *old;
12560 + struct hlist_bl_head *hbl;
12563 + void (*set)(struct au_dykey *key, const void *h_op,
12564 + struct super_block *h_sb __maybe_unused);
12566 + static const struct op a[] = {
12568 + .sz = sizeof(struct au_dyaop),
12572 + const struct op *p;
12574 + hbl = dynop + op->dy_type;
12575 + key = dy_gfind_get(hbl, op->dy_hop);
12577 + goto out_add; /* success */
12579 + p = a + op->dy_type;
12580 + key = kzalloc(p->sz, GFP_NOFS);
12581 + if (unlikely(!key)) {
12582 + key = ERR_PTR(-ENOMEM);
12586 + key->dk_op.dy_hop = op->dy_hop;
12587 + kref_init(&key->dk_kref);
12588 + p->set(key, op->dy_hop, au_br_sb(br));
12589 + old = dy_gadd(hbl, key);
12591 + au_kfree_rcu(key);
12596 + old = dy_bradd(br, key);
12598 + /* its ref-count should never be zero here */
12599 + kref_put(&key->dk_kref, dy_bug);
12604 +/* ---------------------------------------------------------------------- */
12606 + * Aufs prohibits O_DIRECT by default even if the branch supports it.
12607 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
12608 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
12609 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
12610 + * See the aufs manual in detail.
12612 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
12615 + dyaop->da_op.direct_IO = NULL;
12617 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
12620 +static struct au_dyaop *dy_aget(struct au_branch *br,
12621 + const struct address_space_operations *h_aop,
12624 + struct au_dyaop *dyaop;
12625 + struct au_dynop op;
12627 + op.dy_type = AuDy_AOP;
12628 + op.dy_haop = h_aop;
12629 + dyaop = (void *)dy_get(&op, br);
12630 + if (IS_ERR(dyaop))
12632 + dy_adx(dyaop, do_dx);
12638 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12639 + struct inode *h_inode)
12642 + struct super_block *sb;
12643 + struct au_branch *br;
12644 + struct au_dyaop *dyaop;
12646 + AuDebugOn(!S_ISREG(h_inode->i_mode));
12647 + IiMustWriteLock(inode);
12649 + sb = inode->i_sb;
12650 + br = au_sbr(sb, bindex);
12651 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
12652 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
12653 + err = PTR_ERR(dyaop);
12654 + if (IS_ERR(dyaop))
12655 + /* unnecessary to call dy_fput() */
12659 + inode->i_mapping->a_ops = &dyaop->da_op;
12666 + * Is it safe to replace a_ops during the inode/file is in operation?
12667 + * Yes, I hope so.
12669 +int au_dy_irefresh(struct inode *inode)
12672 + aufs_bindex_t btop;
12673 + struct inode *h_inode;
12676 + if (S_ISREG(inode->i_mode)) {
12677 + btop = au_ibtop(inode);
12678 + h_inode = au_h_iptr(inode, btop);
12679 + err = au_dy_iaop(inode, btop, h_inode);
12684 +void au_dy_arefresh(int do_dx)
12686 + struct hlist_bl_head *hbl;
12687 + struct hlist_bl_node *pos;
12688 + struct au_dykey *key;
12690 + hbl = dynop + AuDy_AOP;
12691 + hlist_bl_lock(hbl);
12692 + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode)
12693 + dy_adx((void *)key, do_dx);
12694 + hlist_bl_unlock(hbl);
12697 +/* ---------------------------------------------------------------------- */
12699 +void __init au_dy_init(void)
12703 + for (i = 0; i < AuDyLast; i++)
12704 + INIT_HLIST_BL_HEAD(dynop + i);
12707 +void au_dy_fin(void)
12711 + for (i = 0; i < AuDyLast; i++)
12712 + WARN_ON(!hlist_bl_empty(dynop + i));
12714 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
12715 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
12716 +++ linux/fs/aufs/dynop.h 2022-11-05 23:02:18.962555950 +0100
12718 +/* SPDX-License-Identifier: GPL-2.0 */
12720 + * Copyright (C) 2010-2022 Junjiro R. Okajima
12722 + * This program is free software; you can redistribute it and/or modify
12723 + * it under the terms of the GNU General Public License as published by
12724 + * the Free Software Foundation; either version 2 of the License, or
12725 + * (at your option) any later version.
12727 + * This program is distributed in the hope that it will be useful,
12728 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12729 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12730 + * GNU General Public License for more details.
12732 + * You should have received a copy of the GNU General Public License
12733 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12737 + * dynamically customizable operations (for regular files only)
12740 +#ifndef __AUFS_DYNOP_H__
12741 +#define __AUFS_DYNOP_H__
12745 +#include <linux/fs.h>
12746 +#include <linux/kref.h>
12748 +enum {AuDy_AOP, AuDyLast};
12753 + const void *dy_hop;
12754 + const struct address_space_operations *dy_haop;
12760 + struct hlist_bl_node dk_hnode;
12761 + struct rcu_head dk_rcu;
12763 + struct au_dynop dk_op;
12766 + * during I am in the branch local array, kref is gotten. when the
12767 + * branch is removed, kref is put.
12769 + struct kref dk_kref;
12772 +/* stop unioning since their sizes are very different from each other */
12774 + struct au_dykey da_key;
12775 + struct address_space_operations da_op; /* not const */
12777 +/* make sure that 'struct au_dykey *' can be any type */
12778 +static_assert(!offsetof(struct au_dyaop, da_key));
12780 +/* ---------------------------------------------------------------------- */
12784 +void au_dy_put(struct au_dykey *key);
12785 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
12786 + struct inode *h_inode);
12787 +int au_dy_irefresh(struct inode *inode);
12788 +void au_dy_arefresh(int do_dio);
12790 +void __init au_dy_init(void);
12791 +void au_dy_fin(void);
12793 +#endif /* __KERNEL__ */
12794 +#endif /* __AUFS_DYNOP_H__ */
12795 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
12796 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
12797 +++ linux/fs/aufs/export.c 2022-12-17 09:21:34.796521861 +0100
12799 +// SPDX-License-Identifier: GPL-2.0
12801 + * Copyright (C) 2005-2022 Junjiro R. Okajima
12803 + * This program is free software; you can redistribute it and/or modify
12804 + * it under the terms of the GNU General Public License as published by
12805 + * the Free Software Foundation; either version 2 of the License, or
12806 + * (at your option) any later version.
12808 + * This program is distributed in the hope that it will be useful,
12809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12811 + * GNU General Public License for more details.
12813 + * You should have received a copy of the GNU General Public License
12814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12821 +#include <linux/exportfs.h>
12822 +#include <linux/fs_struct.h>
12823 +#include <linux/nsproxy.h>
12824 +#include <linux/random.h>
12825 +#include <linux/writeback.h>
12829 +#ifdef CONFIG_AUFS_INO_T_64
12837 +static ino_t decode_ino(__u32 *a)
12841 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
12843 +#ifdef CONFIG_AUFS_INO_T_64
12849 +static void encode_ino(__u32 *a, ino_t ino)
12855 +#ifdef CONFIG_AUFS_INO_T_64
12860 +/* NFS file handle */
12864 +#ifdef CONFIG_AUFS_INO_T_64
12865 + /* support 64bit inode number */
12878 + Fh_ino = Fh_ino1,
12879 + Fh_dir_ino = Fh_dir_ino1
12882 +static int au_test_anon(struct dentry *dentry)
12884 + /* note: read d_flags without d_lock */
12885 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
12888 +int au_test_nfsd(void)
12891 + struct task_struct *tsk = current;
12892 + char comm[sizeof(tsk->comm)];
12895 + if (tsk->flags & PF_KTHREAD) {
12896 + get_task_comm(comm, tsk);
12897 + ret = !strcmp(comm, "nfsd");
12903 +/* ---------------------------------------------------------------------- */
12904 +/* inode generation external table */
12906 +void au_xigen_inc(struct inode *inode)
12911 + struct super_block *sb;
12912 + struct au_sbinfo *sbinfo;
12914 + sb = inode->i_sb;
12915 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
12917 + sbinfo = au_sbi(sb);
12918 + pos = inode->i_ino;
12919 + pos *= sizeof(igen);
12920 + igen = inode->i_generation + 1;
12921 + sz = xino_fwrite(sbinfo->si_xigen, &igen, sizeof(igen), &pos);
12922 + if (sz == sizeof(igen))
12923 + return; /* success */
12925 + if (unlikely(sz >= 0))
12926 + AuIOErr("xigen error (%zd)\n", sz);
12929 +int au_xigen_new(struct inode *inode)
12934 + struct super_block *sb;
12935 + struct au_sbinfo *sbinfo;
12936 + struct file *file;
12939 + /* todo: dirty, at mount time */
12940 + if (inode->i_ino == AUFS_ROOT_INO)
12942 + sb = inode->i_sb;
12943 + SiMustAnyLock(sb);
12944 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
12948 + pos = inode->i_ino;
12949 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
12950 + AuIOErr1("too large i%lld\n", pos);
12953 + pos *= sizeof(inode->i_generation);
12956 + sbinfo = au_sbi(sb);
12957 + file = sbinfo->si_xigen;
12960 + if (vfsub_f_size_read(file)
12961 + < pos + sizeof(inode->i_generation)) {
12962 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
12963 + sz = xino_fwrite(file, &inode->i_generation,
12964 + sizeof(inode->i_generation), &pos);
12966 + sz = xino_fread(file, &inode->i_generation,
12967 + sizeof(inode->i_generation), &pos);
12968 + if (sz == sizeof(inode->i_generation))
12969 + goto out; /* success */
12972 + if (unlikely(sz >= 0)) {
12974 + AuIOErr("xigen error (%zd)\n", sz);
12981 +int au_xigen_set(struct super_block *sb, struct path *path)
12984 + struct au_sbinfo *sbinfo;
12985 + struct file *file;
12987 + SiMustWriteLock(sb);
12989 + sbinfo = au_sbi(sb);
12990 + file = au_xino_create2(sb, path, sbinfo->si_xigen);
12991 + err = PTR_ERR(file);
12992 + if (IS_ERR(file))
12995 + if (sbinfo->si_xigen)
12996 + fput(sbinfo->si_xigen);
12997 + sbinfo->si_xigen = file;
13004 +void au_xigen_clr(struct super_block *sb)
13006 + struct au_sbinfo *sbinfo;
13008 + SiMustWriteLock(sb);
13010 + sbinfo = au_sbi(sb);
13011 + if (sbinfo->si_xigen) {
13012 + fput(sbinfo->si_xigen);
13013 + sbinfo->si_xigen = NULL;
13017 +/* ---------------------------------------------------------------------- */
13019 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
13022 + struct dentry *dentry, *d;
13023 + struct inode *inode;
13024 + unsigned int sigen;
13027 + inode = ilookup(sb, ino);
13031 + dentry = ERR_PTR(-ESTALE);
13032 + sigen = au_sigen(sb);
13033 + if (unlikely(au_is_bad_inode(inode)
13034 + || IS_DEADDIR(inode)
13035 + || sigen != au_iigen(inode, NULL)))
13039 + if (!dir_ino || S_ISDIR(inode->i_mode))
13040 + dentry = d_find_alias(inode);
13042 + spin_lock(&inode->i_lock);
13043 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
13044 + spin_lock(&d->d_lock);
13045 + if (!au_test_anon(d)
13046 + && d_inode(d->d_parent)->i_ino == dir_ino) {
13047 + dentry = dget_dlock(d);
13048 + spin_unlock(&d->d_lock);
13051 + spin_unlock(&d->d_lock);
13053 + spin_unlock(&inode->i_lock);
13055 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
13056 + /* need to refresh */
13064 + AuTraceErrPtr(dentry);
13068 +/* ---------------------------------------------------------------------- */
13070 +/* todo: dirty? */
13071 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
13073 +struct au_compare_mnt_args {
13075 + struct super_block *sb;
13078 + struct vfsmount *mnt;
13081 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
13083 + struct au_compare_mnt_args *a = arg;
13085 + if (mnt->mnt_sb != a->sb)
13087 + a->mnt = mntget(mnt);
13091 +static struct vfsmount *au_mnt_get(struct super_block *sb)
13094 + struct path root;
13095 + struct au_compare_mnt_args args = {
13099 + get_fs_root(current->fs, &root);
13101 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
13102 + rcu_read_unlock();
13105 + AuDebugOn(!args.mnt);
13109 +struct au_nfsd_si_lock {
13110 + unsigned int sigen;
13111 + aufs_bindex_t bindex, br_id;
13112 + unsigned char force_lock;
13115 +static int si_nfsd_read_lock(struct super_block *sb,
13116 + struct au_nfsd_si_lock *nsi_lock)
13119 + aufs_bindex_t bindex;
13121 + si_read_lock(sb, AuLock_FLUSH);
13123 + /* branch id may be wrapped around */
13125 + bindex = au_br_index(sb, nsi_lock->br_id);
13126 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
13127 + goto out; /* success */
13131 + if (!nsi_lock->force_lock)
13132 + si_read_unlock(sb);
13135 + nsi_lock->bindex = bindex;
13139 +struct find_name_by_ino {
13140 + struct dir_context ctx;
13141 + int called, found;
13148 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
13149 + loff_t offset, u64 ino, unsigned int d_type)
13151 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
13155 + if (a->ino != ino)
13158 + memcpy(a->name, name, namelen);
13159 + a->namelen = namelen;
13164 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
13165 + struct au_nfsd_si_lock *nsi_lock)
13167 + struct dentry *dentry, *parent;
13168 + struct file *file;
13169 + struct inode *dir;
13170 + struct find_name_by_ino arg = {
13172 + .actor = find_name_by_ino
13177 + parent = path->dentry;
13179 + si_read_unlock(parent->d_sb);
13180 + file = vfsub_dentry_open(path, au_dir_roflags);
13181 + dentry = (void *)file;
13182 + if (IS_ERR(file))
13185 + dentry = ERR_PTR(-ENOMEM);
13186 + arg.name = (void *)__get_free_page(GFP_NOFS);
13187 + if (unlikely(!arg.name))
13194 + err = vfsub_iterate_dir(file, &arg.ctx);
13195 + } while (!err && !arg.found && arg.called);
13196 + dentry = ERR_PTR(err);
13197 + if (unlikely(err))
13199 + /* instead of ENOENT */
13200 + dentry = ERR_PTR(-ESTALE);
13204 + /* do not call vfsub_lkup_one() */
13205 + dir = d_inode(parent);
13206 + dentry = vfsub_lookup_one_len_unlocked(arg.name, path, arg.namelen);
13207 + AuTraceErrPtr(dentry);
13208 + if (IS_ERR(dentry))
13210 + AuDebugOn(au_test_anon(dentry));
13211 + if (unlikely(d_really_is_negative(dentry))) {
13213 + dentry = ERR_PTR(-ENOENT);
13217 + free_page((unsigned long)arg.name);
13221 + if (unlikely(nsi_lock
13222 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
13223 + if (!IS_ERR(dentry)) {
13225 + dentry = ERR_PTR(-ESTALE);
13227 + AuTraceErrPtr(dentry);
13231 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
13233 + struct au_nfsd_si_lock *nsi_lock)
13235 + struct dentry *dentry;
13236 + struct path path;
13238 + if (dir_ino != AUFS_ROOT_INO) {
13239 + path.dentry = decode_by_ino(sb, dir_ino, 0);
13240 + dentry = path.dentry;
13241 + if (!path.dentry || IS_ERR(path.dentry))
13243 + AuDebugOn(au_test_anon(path.dentry));
13245 + path.dentry = dget(sb->s_root);
13247 + path.mnt = au_mnt_get(sb);
13248 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
13252 + AuTraceErrPtr(dentry);
13256 +/* ---------------------------------------------------------------------- */
13258 +static int h_acceptable(void *expv, struct dentry *dentry)
13263 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
13264 + char *buf, int len, struct super_block *sb)
13268 + struct path path;
13270 + p = d_path(h_rootpath, buf, len);
13275 + path.mnt = h_rootpath->mnt;
13276 + path.dentry = h_parent;
13277 + p = d_path(&path, buf, len);
13283 + path.mnt = au_mnt_get(sb);
13284 + path.dentry = sb->s_root;
13285 + p = d_path(&path, buf, len - strlen(p));
13286 + mntput(path.mnt);
13290 + p[strlen(p)] = '/';
13293 + AuTraceErrPtr(p);
13298 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
13299 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
13301 + struct dentry *dentry, *h_parent, *root;
13302 + struct super_block *h_sb;
13303 + char *pathname, *p;
13304 + struct vfsmount *h_mnt;
13305 + struct au_branch *br;
13307 + struct path path;
13309 + br = au_sbr(sb, nsi_lock->bindex);
13310 + h_mnt = au_br_mnt(br);
13311 + h_sb = h_mnt->mnt_sb;
13312 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
13314 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
13315 + fh_len - Fh_tail, fh[Fh_h_type],
13316 + h_acceptable, /*context*/NULL);
13318 + dentry = h_parent;
13319 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
13320 + AuWarn1("%s decode_fh failed, %ld\n",
13321 + au_sbtype(h_sb), PTR_ERR(h_parent));
13325 + if (unlikely(au_test_anon(h_parent))) {
13326 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
13327 + au_sbtype(h_sb));
13328 + goto out_h_parent;
13331 + dentry = ERR_PTR(-ENOMEM);
13332 + pathname = (void *)__get_free_page(GFP_NOFS);
13333 + if (unlikely(!pathname))
13334 + goto out_h_parent;
13336 + root = sb->s_root;
13337 + path.mnt = h_mnt;
13338 + di_read_lock_parent(root, !AuLock_IR);
13339 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
13340 + di_read_unlock(root, !AuLock_IR);
13341 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
13342 + dentry = (void *)p;
13344 + goto out_pathname;
13346 + si_read_unlock(sb);
13347 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
13348 + dentry = ERR_PTR(err);
13349 + if (unlikely(err))
13352 + dentry = ERR_PTR(-ENOENT);
13353 + AuDebugOn(au_test_anon(path.dentry));
13354 + if (unlikely(d_really_is_negative(path.dentry)))
13357 + if (ino != d_inode(path.dentry)->i_ino)
13358 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
13360 + dentry = dget(path.dentry);
13365 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
13366 + if (!IS_ERR(dentry)) {
13368 + dentry = ERR_PTR(-ESTALE);
13371 + free_page((unsigned long)pathname);
13375 + AuTraceErrPtr(dentry);
13379 +/* ---------------------------------------------------------------------- */
13381 +static struct dentry *
13382 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
13385 + struct dentry *dentry;
13386 + __u32 *fh = fid->raw;
13387 + struct au_branch *br;
13388 + ino_t ino, dir_ino;
13389 + struct au_nfsd_si_lock nsi_lock = {
13393 + dentry = ERR_PTR(-ESTALE);
13394 + /* it should never happen, but the file handle is unreliable */
13395 + if (unlikely(fh_len < Fh_tail))
13397 + nsi_lock.sigen = fh[Fh_sigen];
13398 + nsi_lock.br_id = fh[Fh_br_id];
13400 + /* branch id may be wrapped around */
13402 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
13404 + nsi_lock.force_lock = 1;
13406 + /* is this inode still cached? */
13407 + ino = decode_ino(fh + Fh_ino);
13408 + /* it should never happen */
13409 + if (unlikely(ino == AUFS_ROOT_INO))
13412 + dir_ino = decode_ino(fh + Fh_dir_ino);
13413 + dentry = decode_by_ino(sb, ino, dir_ino);
13414 + if (IS_ERR(dentry))
13419 + /* is the parent dir cached? */
13420 + br = au_sbr(sb, nsi_lock.bindex);
13421 + au_lcnt_inc(&br->br_nfiles);
13422 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
13423 + if (IS_ERR(dentry))
13428 + /* lookup path */
13429 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
13430 + if (IS_ERR(dentry))
13432 + if (unlikely(!dentry))
13433 + /* todo?: make it ESTALE */
13437 + if (!au_digen_test(dentry, au_sigen(sb))
13438 + && d_inode(dentry)->i_generation == fh[Fh_igen])
13439 + goto out_unlock; /* success */
13442 + dentry = ERR_PTR(-ESTALE);
13445 + au_lcnt_dec(&br->br_nfiles);
13446 + si_read_unlock(sb);
13448 + AuTraceErrPtr(dentry);
13452 +#if 0 /* reserved for future use */
13453 +/* support subtreecheck option */
13454 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
13455 + int fh_len, int fh_type)
13457 + struct dentry *parent;
13458 + __u32 *fh = fid->raw;
13461 + dir_ino = decode_ino(fh + Fh_dir_ino);
13462 + parent = decode_by_ino(sb, dir_ino, 0);
13463 + if (IS_ERR(parent))
13466 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
13467 + dir_ino, fh, fh_len);
13470 + AuTraceErrPtr(parent);
13475 +/* ---------------------------------------------------------------------- */
13477 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
13478 + struct inode *dir)
13481 + aufs_bindex_t bindex;
13482 + struct super_block *sb, *h_sb;
13483 + struct dentry *dentry, *parent, *h_parent;
13484 + struct inode *h_dir;
13485 + struct au_branch *br;
13488 + if (unlikely(*max_len <= Fh_tail)) {
13489 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
13493 + err = FILEID_ROOT;
13494 + if (inode->i_ino == AUFS_ROOT_INO) {
13495 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
13500 + sb = inode->i_sb;
13501 + err = si_read_lock(sb, AuLock_FLUSH);
13502 + if (unlikely(err))
13505 +#ifdef CONFIG_AUFS_DEBUG
13506 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
13507 + AuWarn1("NFS-exporting requires xino\n");
13511 + ii_read_lock_child(inode);
13512 + bindex = au_ibtop(inode);
13514 + dentry = d_find_any_alias(inode);
13515 + if (unlikely(!dentry))
13517 + AuDebugOn(au_test_anon(dentry));
13518 + parent = dget_parent(dentry);
13520 + if (unlikely(!parent))
13522 + if (d_really_is_positive(parent))
13523 + dir = d_inode(parent);
13526 + ii_read_lock_parent(dir);
13527 + h_dir = au_h_iptr(dir, bindex);
13528 + ii_read_unlock(dir);
13529 + if (unlikely(!h_dir))
13531 + h_parent = d_find_any_alias(h_dir);
13532 + if (unlikely(!h_parent))
13533 + goto out_hparent;
13536 + br = au_sbr(sb, bindex);
13537 + h_sb = au_br_sb(br);
13538 + if (unlikely(!h_sb->s_export_op)) {
13539 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
13540 + goto out_hparent;
13543 + fh[Fh_br_id] = br->br_id;
13544 + fh[Fh_sigen] = au_sigen(sb);
13545 + encode_ino(fh + Fh_ino, inode->i_ino);
13546 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
13547 + fh[Fh_igen] = inode->i_generation;
13549 + *max_len -= Fh_tail;
13550 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
13552 + /*connectable or subtreecheck*/0);
13553 + err = fh[Fh_h_type];
13554 + *max_len += Fh_tail;
13555 + /* todo: macros? */
13556 + if (err != FILEID_INVALID)
13559 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
13566 + ii_read_unlock(inode);
13567 + si_read_unlock(sb);
13569 + if (unlikely(err < 0))
13570 + err = FILEID_INVALID;
13574 +/* ---------------------------------------------------------------------- */
13576 +static int aufs_commit_metadata(struct inode *inode)
13579 + aufs_bindex_t bindex;
13580 + struct super_block *sb;
13581 + struct inode *h_inode;
13582 + int (*f)(struct inode *inode);
13584 + sb = inode->i_sb;
13585 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13586 + ii_write_lock_child(inode);
13587 + bindex = au_ibtop(inode);
13588 + AuDebugOn(bindex < 0);
13589 + h_inode = au_h_iptr(inode, bindex);
13591 + f = h_inode->i_sb->s_export_op->commit_metadata;
13593 + err = f(h_inode);
13595 + err = sync_inode_metadata(h_inode, /*wait*/1);
13597 + au_cpup_attr_timesizes(inode);
13598 + ii_write_unlock(inode);
13599 + si_read_unlock(sb);
13603 +/* ---------------------------------------------------------------------- */
13605 +static struct export_operations aufs_export_op = {
13606 + .fh_to_dentry = aufs_fh_to_dentry,
13607 + /* .fh_to_parent = aufs_fh_to_parent, */
13608 + .encode_fh = aufs_encode_fh,
13609 + .commit_metadata = aufs_commit_metadata
13612 +void au_export_init(struct super_block *sb)
13614 + struct au_sbinfo *sbinfo;
13617 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
13618 + && IS_MODULE(CONFIG_EXPORTFS),
13619 + AUFS_NAME ": unsupported configuration "
13620 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
13622 + sb->s_export_op = &aufs_export_op;
13623 + sbinfo = au_sbi(sb);
13624 + sbinfo->si_xigen = NULL;
13625 + get_random_bytes(&u, sizeof(u));
13626 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
13627 + atomic_set(&sbinfo->si_xigen_next, u);
13629 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
13630 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
13631 +++ linux/fs/aufs/fhsm.c 2022-11-05 23:02:18.962555950 +0100
13633 +// SPDX-License-Identifier: GPL-2.0
13635 + * Copyright (C) 2011-2022 Junjiro R. Okajima
13637 + * This program is free software; you can redistribute it and/or modify
13638 + * it under the terms of the GNU General Public License as published by
13639 + * the Free Software Foundation; either version 2 of the License, or
13640 + * (at your option) any later version.
13642 + * This program is distributed in the hope that it will be useful,
13643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13645 + * GNU General Public License for more details.
13647 + * You should have received a copy of the GNU General Public License
13648 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13652 + * File-based Hierarchy Storage Management
13655 +#include <linux/anon_inodes.h>
13656 +#include <linux/poll.h>
13657 +#include <linux/seq_file.h>
13658 +#include <linux/statfs.h>
13661 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
13663 + struct au_sbinfo *sbinfo;
13664 + struct au_fhsm *fhsm;
13666 + SiMustAnyLock(sb);
13668 + sbinfo = au_sbi(sb);
13669 + fhsm = &sbinfo->si_fhsm;
13670 + AuDebugOn(!fhsm);
13671 + return fhsm->fhsm_bottom;
13674 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
13676 + struct au_sbinfo *sbinfo;
13677 + struct au_fhsm *fhsm;
13679 + SiMustWriteLock(sb);
13681 + sbinfo = au_sbi(sb);
13682 + fhsm = &sbinfo->si_fhsm;
13683 + AuDebugOn(!fhsm);
13684 + fhsm->fhsm_bottom = bindex;
13687 +/* ---------------------------------------------------------------------- */
13689 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
13691 + struct au_br_fhsm *bf;
13693 + bf = br->br_fhsm;
13694 + MtxMustLock(&bf->bf_lock);
13696 + return !bf->bf_readable
13697 + || time_after(jiffies,
13698 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
13701 +/* ---------------------------------------------------------------------- */
13703 +static void au_fhsm_notify(struct super_block *sb, int val)
13705 + struct au_sbinfo *sbinfo;
13706 + struct au_fhsm *fhsm;
13708 + SiMustAnyLock(sb);
13710 + sbinfo = au_sbi(sb);
13711 + fhsm = &sbinfo->si_fhsm;
13712 + if (au_fhsm_pid(fhsm)
13713 + && atomic_read(&fhsm->fhsm_readable) != -1) {
13714 + atomic_set(&fhsm->fhsm_readable, val);
13716 + wake_up(&fhsm->fhsm_wqh);
13720 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
13721 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
13724 + struct au_branch *br;
13725 + struct au_br_fhsm *bf;
13727 + br = au_sbr(sb, bindex);
13728 + AuDebugOn(au_br_rdonly(br));
13729 + bf = br->br_fhsm;
13733 + mutex_lock(&bf->bf_lock);
13735 + MtxMustLock(&bf->bf_lock);
13737 + /* sb->s_root for NFS is unreliable */
13738 + err = au_br_stfs(br, &bf->bf_stfs);
13739 + if (unlikely(err)) {
13740 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
13744 + bf->bf_jiffy = jiffies;
13745 + bf->bf_readable = 1;
13747 + au_fhsm_notify(sb, /*val*/1);
13749 + *rstfs = bf->bf_stfs;
13753 + mutex_unlock(&bf->bf_lock);
13754 + au_fhsm_notify(sb, /*val*/1);
13759 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
13762 + struct au_sbinfo *sbinfo;
13763 + struct au_fhsm *fhsm;
13764 + struct au_branch *br;
13765 + struct au_br_fhsm *bf;
13767 + AuDbg("b%d, force %d\n", bindex, force);
13768 + SiMustAnyLock(sb);
13770 + sbinfo = au_sbi(sb);
13771 + fhsm = &sbinfo->si_fhsm;
13772 + if (!au_ftest_si(sbinfo, FHSM)
13773 + || fhsm->fhsm_bottom == bindex)
13776 + br = au_sbr(sb, bindex);
13777 + bf = br->br_fhsm;
13779 + mutex_lock(&bf->bf_lock);
13781 + || au_fhsm_pid(fhsm)
13782 + || au_fhsm_test_jiffy(sbinfo, br))
13783 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
13785 + mutex_unlock(&bf->bf_lock);
13788 +void au_fhsm_wrote_all(struct super_block *sb, int force)
13790 + aufs_bindex_t bindex, bbot;
13791 + struct au_branch *br;
13793 + /* exclude the bottom */
13794 + bbot = au_fhsm_bottom(sb);
13795 + for (bindex = 0; bindex < bbot; bindex++) {
13796 + br = au_sbr(sb, bindex);
13797 + if (au_br_fhsm(br->br_perm))
13798 + au_fhsm_wrote(sb, bindex, force);
13802 +/* ---------------------------------------------------------------------- */
13804 +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait)
13807 + struct au_sbinfo *sbinfo;
13808 + struct au_fhsm *fhsm;
13811 + sbinfo = file->private_data;
13812 + fhsm = &sbinfo->si_fhsm;
13813 + poll_wait(file, &fhsm->fhsm_wqh, wait);
13814 + if (atomic_read(&fhsm->fhsm_readable))
13815 + mask = EPOLLIN /* | EPOLLRDNORM */;
13818 + AuDbg("mask 0x%x\n", mask);
13822 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
13823 + struct aufs_stfs *stfs, __s16 brid)
13827 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
13829 + err = __put_user(brid, &stbr->brid);
13830 + if (unlikely(err))
13836 +static ssize_t au_fhsm_do_read(struct super_block *sb,
13837 + struct aufs_stbr __user *stbr, size_t count)
13841 + aufs_bindex_t bindex, bbot;
13842 + struct au_branch *br;
13843 + struct au_br_fhsm *bf;
13845 + /* except the bottom branch */
13848 + bbot = au_fhsm_bottom(sb);
13849 + for (bindex = 0; !err && bindex < bbot; bindex++) {
13850 + br = au_sbr(sb, bindex);
13851 + if (!au_br_fhsm(br->br_perm))
13854 + bf = br->br_fhsm;
13855 + mutex_lock(&bf->bf_lock);
13856 + if (bf->bf_readable) {
13858 + if (count >= sizeof(*stbr))
13859 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
13862 + bf->bf_readable = 0;
13863 + count -= sizeof(*stbr);
13867 + mutex_unlock(&bf->bf_lock);
13870 + err = sizeof(*stbr) * nstbr;
13875 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
13880 + aufs_bindex_t nfhsm, bindex, bbot;
13881 + struct au_sbinfo *sbinfo;
13882 + struct au_fhsm *fhsm;
13883 + struct au_branch *br;
13884 + struct super_block *sb;
13887 + sbinfo = file->private_data;
13888 + fhsm = &sbinfo->si_fhsm;
13890 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
13891 + if (!atomic_read(&fhsm->fhsm_readable)) {
13892 + if (vfsub_file_flags(file) & O_NONBLOCK)
13895 + err = wait_event_interruptible_locked_irq
13897 + atomic_read(&fhsm->fhsm_readable));
13899 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
13900 + if (unlikely(err))
13903 + /* sb may already be dead */
13904 + au_rw_read_lock(&sbinfo->si_rwsem);
13905 + readable = atomic_read(&fhsm->fhsm_readable);
13906 + if (readable > 0) {
13907 + sb = sbinfo->si_sb;
13909 + /* exclude the bottom branch */
13911 + bbot = au_fhsm_bottom(sb);
13912 + for (bindex = 0; bindex < bbot; bindex++) {
13913 + br = au_sbr(sb, bindex);
13914 + if (au_br_fhsm(br->br_perm))
13918 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
13919 + atomic_set(&fhsm->fhsm_readable, 0);
13920 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
13924 + au_rw_read_unlock(&sbinfo->si_rwsem);
13932 +static int au_fhsm_release(struct inode *inode, struct file *file)
13934 + struct au_sbinfo *sbinfo;
13935 + struct au_fhsm *fhsm;
13937 + /* sb may already be dead */
13938 + sbinfo = file->private_data;
13939 + fhsm = &sbinfo->si_fhsm;
13940 + spin_lock(&fhsm->fhsm_spin);
13941 + fhsm->fhsm_pid = 0;
13942 + spin_unlock(&fhsm->fhsm_spin);
13943 + kobject_put(&sbinfo->si_kobj);
13948 +static const struct file_operations au_fhsm_fops = {
13949 + .owner = THIS_MODULE,
13950 + .llseek = noop_llseek,
13951 + .read = au_fhsm_read,
13952 + .poll = au_fhsm_poll,
13953 + .release = au_fhsm_release
13956 +int au_fhsm_fd(struct super_block *sb, int oflags)
13959 + struct au_sbinfo *sbinfo;
13960 + struct au_fhsm *fhsm;
13963 + if (unlikely(!capable(CAP_SYS_ADMIN)))
13967 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
13971 + sbinfo = au_sbi(sb);
13972 + fhsm = &sbinfo->si_fhsm;
13973 + spin_lock(&fhsm->fhsm_spin);
13974 + if (!fhsm->fhsm_pid)
13975 + fhsm->fhsm_pid = current->pid;
13978 + spin_unlock(&fhsm->fhsm_spin);
13979 + if (unlikely(err))
13982 + oflags |= O_RDONLY;
13983 + /* oflags |= FMODE_NONOTIFY; */
13984 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
13986 + if (unlikely(fd < 0))
13989 + /* succeed regardless 'fhsm' status */
13990 + kobject_get(&sbinfo->si_kobj);
13991 + si_noflush_read_lock(sb);
13992 + if (au_ftest_si(sbinfo, FHSM))
13993 + au_fhsm_wrote_all(sb, /*force*/0);
13994 + si_read_unlock(sb);
13995 + goto out; /* success */
13998 + spin_lock(&fhsm->fhsm_spin);
13999 + fhsm->fhsm_pid = 0;
14000 + spin_unlock(&fhsm->fhsm_spin);
14006 +/* ---------------------------------------------------------------------- */
14008 +int au_fhsm_br_alloc(struct au_branch *br)
14013 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
14015 + au_br_fhsm_init(br->br_fhsm);
14022 +/* ---------------------------------------------------------------------- */
14024 +void au_fhsm_fin(struct super_block *sb)
14026 + au_fhsm_notify(sb, /*val*/-1);
14029 +void au_fhsm_init(struct au_sbinfo *sbinfo)
14031 + struct au_fhsm *fhsm;
14033 + fhsm = &sbinfo->si_fhsm;
14034 + spin_lock_init(&fhsm->fhsm_spin);
14035 + init_waitqueue_head(&fhsm->fhsm_wqh);
14036 + atomic_set(&fhsm->fhsm_readable, 0);
14037 + fhsm->fhsm_expire
14038 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
14039 + fhsm->fhsm_bottom = -1;
14042 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
14044 + sbinfo->si_fhsm.fhsm_expire
14045 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
14048 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
14052 + if (!au_ftest_si(sbinfo, FHSM))
14055 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
14056 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
14057 + seq_printf(seq, ",fhsm_sec=%u", u);
14059 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
14060 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
14061 +++ linux/fs/aufs/file.c 2022-12-17 09:21:34.799855195 +0100
14063 +// SPDX-License-Identifier: GPL-2.0
14065 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14067 + * This program is free software; you can redistribute it and/or modify
14068 + * it under the terms of the GNU General Public License as published by
14069 + * the Free Software Foundation; either version 2 of the License, or
14070 + * (at your option) any later version.
14072 + * This program is distributed in the hope that it will be useful,
14073 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14074 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14075 + * GNU General Public License for more details.
14077 + * You should have received a copy of the GNU General Public License
14078 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14082 + * handling file/dir, and address_space operation
14085 +#ifdef CONFIG_AUFS_DEBUG
14086 +#include <linux/migrate.h>
14088 +#include <linux/pagemap.h>
14091 +/* drop flags for writing */
14092 +unsigned int au_file_roflags(unsigned int flags)
14094 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
14095 + flags |= O_RDONLY | O_NOATIME;
14099 +/* common functions to regular file and dir */
14100 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
14101 + struct file *file, int force_wr)
14103 + struct file *h_file;
14104 + struct dentry *h_dentry;
14105 + struct inode *h_inode;
14106 + struct super_block *sb;
14107 + struct au_branch *br;
14108 + struct path h_path;
14111 + /* a race condition can happen between open and unlink/rmdir */
14112 + h_file = ERR_PTR(-ENOENT);
14113 + h_dentry = au_h_dptr(dentry, bindex);
14114 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
14116 + h_inode = d_inode(h_dentry);
14117 + spin_lock(&h_dentry->d_lock);
14118 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
14119 + /* || !d_inode(dentry)->i_nlink */
14121 + spin_unlock(&h_dentry->d_lock);
14122 + if (unlikely(err))
14125 + sb = dentry->d_sb;
14126 + br = au_sbr(sb, bindex);
14127 + err = au_br_test_oflag(flags, br);
14128 + h_file = ERR_PTR(err);
14129 + if (unlikely(err))
14132 + /* drop flags for writing */
14133 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
14134 + if (force_wr && !(flags & O_WRONLY))
14136 + flags = au_file_roflags(flags);
14138 + h_file = ERR_PTR(-EROFS);
14139 + flags = au_file_roflags(flags);
14140 + if (unlikely(vfsub_native_ro(h_inode)
14141 + || IS_APPEND(h_inode)))
14143 + flags &= ~O_ACCMODE;
14144 + flags |= O_WRONLY;
14147 + flags &= ~O_CREAT;
14148 + au_lcnt_inc(&br->br_nfiles);
14149 + h_path.dentry = h_dentry;
14150 + h_path.mnt = au_br_mnt(br);
14151 + h_file = vfsub_dentry_open(&h_path, flags);
14152 + if (IS_ERR(h_file))
14155 + if (flags & __FMODE_EXEC) {
14156 + err = deny_write_access(h_file);
14157 + if (unlikely(err)) {
14159 + h_file = ERR_PTR(err);
14163 + fsnotify_open(h_file);
14164 + goto out; /* success */
14167 + au_lcnt_dec(&br->br_nfiles);
14172 +static int au_cmoo(struct dentry *dentry)
14174 + int err, cmoo, matched;
14175 + unsigned int udba;
14176 + struct path h_path;
14177 + struct au_pin pin;
14178 + struct au_cp_generic cpg = {
14179 + .dentry = dentry,
14184 + .flags = AuCpup_DTIME | AuCpup_HOPEN
14186 + struct inode *delegated;
14187 + struct super_block *sb;
14188 + struct au_sbinfo *sbinfo;
14189 + struct au_fhsm *fhsm;
14191 + struct au_branch *br;
14192 + struct dentry *parent;
14193 + struct au_hinode *hdir;
14195 + DiMustWriteLock(dentry);
14196 + IiMustWriteLock(d_inode(dentry));
14199 + if (IS_ROOT(dentry))
14201 + cpg.bsrc = au_dbtop(dentry);
14205 + sb = dentry->d_sb;
14206 + sbinfo = au_sbi(sb);
14207 + fhsm = &sbinfo->si_fhsm;
14208 + pid = au_fhsm_pid(fhsm);
14211 + && (current->pid == pid
14212 + || rcu_dereference(current->real_parent)->pid == pid));
14213 + rcu_read_unlock();
14217 + br = au_sbr(sb, cpg.bsrc);
14218 + cmoo = au_br_cmoo(br->br_perm);
14221 + if (!d_is_reg(dentry))
14222 + cmoo &= AuBrAttr_COO_ALL;
14226 + parent = dget_parent(dentry);
14227 + di_write_lock_parent(parent);
14228 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
14230 + if (unlikely(err < 0)) {
14231 + err = 0; /* there is no upper writable branch */
14234 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
14236 + /* do not respect the coo attrib for the target branch */
14237 + err = au_cpup_dirs(dentry, cpg.bdst);
14238 + if (unlikely(err))
14241 + di_downgrade_lock(parent, AuLock_IR);
14242 + udba = au_opt_udba(sb);
14243 + err = au_pin(&pin, dentry, cpg.bdst, udba,
14244 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14245 + if (unlikely(err))
14248 + err = au_sio_cpup_simple(&cpg);
14250 + if (unlikely(err))
14252 + if (!(cmoo & AuBrWAttr_MOO))
14253 + goto out_parent; /* success */
14255 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
14256 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14257 + if (unlikely(err))
14260 + h_path.mnt = au_br_mnt(br);
14261 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
14262 + hdir = au_hi(d_inode(parent), cpg.bsrc);
14263 + delegated = NULL;
14264 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
14266 + /* todo: keep h_dentry or not? */
14267 + if (unlikely(err == -EWOULDBLOCK)) {
14268 + pr_warn("cannot retry for NFSv4 delegation"
14269 + " for an internal unlink\n");
14272 + if (unlikely(err)) {
14273 + pr_err("unlink %pd after coo failed (%d), ignored\n",
14277 + goto out_parent; /* success */
14280 + di_downgrade_lock(parent, AuLock_IR);
14282 + di_read_unlock(parent, AuLock_IR);
14289 +int au_do_open(struct file *file, struct au_do_open_args *args)
14291 + int err, aopen = args->aopen;
14292 + struct dentry *dentry;
14293 + struct au_finfo *finfo;
14296 + err = au_finfo_init(file, args->fidir);
14299 + err = au_finfo_init(file, args->fidir);
14302 + if (unlikely(err))
14305 + dentry = file->f_path.dentry;
14306 + AuDebugOn(IS_ERR_OR_NULL(dentry));
14307 + di_write_lock_child(dentry);
14308 + err = au_cmoo(dentry);
14311 + err = args->open(file, vfsub_file_flags(file),
14312 + au_di(dentry)->di_htmpfile);
14313 + di_write_unlock(dentry);
14315 + di_downgrade_lock(dentry, AuLock_IR);
14317 + err = args->open(file, vfsub_file_flags(file),
14320 + di_read_unlock(dentry, AuLock_IR);
14324 + finfo = au_fi(file);
14326 + finfo->fi_file = file;
14327 + au_hbl_add(&finfo->fi_hlist,
14328 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
14331 + fi_write_unlock(file);
14334 + fi_write_unlock(file);
14337 + if (unlikely(err)) {
14338 + finfo->fi_hdir = NULL;
14339 + au_finfo_fin(file);
14347 +int au_reopen_nondir(struct file *file)
14350 + aufs_bindex_t btop;
14351 + struct dentry *dentry;
14352 + struct au_branch *br;
14353 + struct file *h_file, *h_file_tmp;
14355 + dentry = file->f_path.dentry;
14356 + btop = au_dbtop(dentry);
14357 + br = au_sbr(dentry->d_sb, btop);
14358 + h_file_tmp = NULL;
14359 + if (au_fbtop(file) == btop) {
14360 + h_file = au_hf_top(file);
14361 + if (file->f_mode == h_file->f_mode)
14362 + return 0; /* success */
14363 + h_file_tmp = h_file;
14364 + get_file(h_file_tmp);
14365 + au_lcnt_inc(&br->br_nfiles);
14366 + au_set_h_fptr(file, btop, NULL);
14368 + AuDebugOn(au_fi(file)->fi_hdir);
14371 + * file exists on both of rw and ro
14372 + * open --> dbtop and fbtop are both 0
14373 + * prepend a branch as rw, "rw" become ro
14375 + * delete the top branch, "rw" becomes rw again
14376 + * --> dbtop is 1, fbtop is still 0
14377 + * write --> fbtop is 0 but dbtop is 1
14379 + /* AuDebugOn(au_fbtop(file) < btop); */
14381 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
14382 + file, /*force_wr*/0);
14383 + err = PTR_ERR(h_file);
14384 + if (IS_ERR(h_file)) {
14385 + if (h_file_tmp) {
14387 + au_set_h_fptr(file, btop, h_file_tmp);
14388 + h_file_tmp = NULL;
14390 + goto out; /* todo: close all? */
14394 + au_set_fbtop(file, btop);
14395 + au_set_h_fptr(file, btop, h_file);
14396 + au_update_figen(file);
14397 + /* todo: necessary? */
14398 + /* file->f_ra = h_file->f_ra; */
14401 + if (h_file_tmp) {
14402 + fput(h_file_tmp);
14403 + au_lcnt_dec(&br->br_nfiles);
14408 +/* ---------------------------------------------------------------------- */
14410 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
14411 + struct dentry *hi_wh)
14414 + aufs_bindex_t btop;
14415 + struct au_dinfo *dinfo;
14416 + struct dentry *h_dentry;
14417 + struct au_hdentry *hdp;
14419 + dinfo = au_di(file->f_path.dentry);
14420 + AuRwMustWriteLock(&dinfo->di_rwsem);
14422 + btop = dinfo->di_btop;
14423 + dinfo->di_btop = btgt;
14424 + hdp = au_hdentry(dinfo, btgt);
14425 + h_dentry = hdp->hd_dentry;
14426 + hdp->hd_dentry = hi_wh;
14427 + err = au_reopen_nondir(file);
14428 + hdp->hd_dentry = h_dentry;
14429 + dinfo->di_btop = btop;
14434 +static int au_ready_to_write_wh(struct file *file, loff_t len,
14435 + aufs_bindex_t bcpup, struct au_pin *pin)
14438 + struct inode *inode, *h_inode;
14439 + struct dentry *h_dentry, *hi_wh;
14440 + struct au_cp_generic cpg = {
14441 + .dentry = file->f_path.dentry,
14448 + au_update_dbtop(cpg.dentry);
14449 + inode = d_inode(cpg.dentry);
14451 + if (au_dbtop(cpg.dentry) <= bcpup
14452 + && au_dbbot(cpg.dentry) >= bcpup) {
14453 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
14454 + if (h_dentry && d_is_positive(h_dentry))
14455 + h_inode = d_inode(h_dentry);
14457 + hi_wh = au_hi_wh(inode, bcpup);
14458 + if (!hi_wh && !h_inode)
14459 + err = au_sio_cpup_wh(&cpg, file);
14461 + /* already copied-up after unlink */
14462 + err = au_reopen_wh(file, bcpup, hi_wh);
14465 + && (inode->i_nlink > 1
14466 + || (inode->i_state & I_LINKABLE))
14467 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
14468 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
14474 + * prepare the @file for writing.
14476 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
14479 + aufs_bindex_t dbtop;
14480 + struct dentry *parent;
14481 + struct inode *inode;
14482 + struct super_block *sb;
14483 + struct file *h_file;
14484 + struct au_cp_generic cpg = {
14485 + .dentry = file->f_path.dentry,
14490 + .flags = AuCpup_DTIME
14493 + sb = cpg.dentry->d_sb;
14494 + inode = d_inode(cpg.dentry);
14495 + cpg.bsrc = au_fbtop(file);
14496 + err = au_test_ro(sb, cpg.bsrc, inode);
14497 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
14498 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
14503 + /* need to cpup or reopen */
14504 + parent = dget_parent(cpg.dentry);
14505 + di_write_lock_parent(parent);
14506 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14508 + if (unlikely(err < 0))
14512 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
14513 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
14514 + if (unlikely(err))
14518 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14519 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14520 + if (unlikely(err))
14523 + dbtop = au_dbtop(cpg.dentry);
14524 + if (dbtop <= cpg.bdst)
14525 + cpg.bsrc = cpg.bdst;
14527 + if (dbtop <= cpg.bdst /* just reopen */
14528 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
14530 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
14531 + if (IS_ERR(h_file))
14532 + err = PTR_ERR(h_file);
14534 + di_downgrade_lock(parent, AuLock_IR);
14535 + if (dbtop > cpg.bdst)
14536 + err = au_sio_cpup_simple(&cpg);
14538 + err = au_reopen_nondir(file);
14539 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
14541 + } else { /* copyup as wh and reopen */
14543 + * since writable hfsplus branch is not supported,
14544 + * h_open_pre/post() are unnecessary.
14546 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
14547 + di_downgrade_lock(parent, AuLock_IR);
14551 + au_pin_set_parent_lflag(pin, /*lflag*/0);
14552 + goto out_dput; /* success */
14558 + di_downgrade_lock(parent, AuLock_IR);
14560 + di_read_unlock(parent, AuLock_IR);
14567 +/* ---------------------------------------------------------------------- */
14569 +int au_do_flush(struct file *file, fl_owner_t id,
14570 + int (*flush)(struct file *file, fl_owner_t id))
14573 + struct super_block *sb;
14574 + struct inode *inode;
14576 + inode = file_inode(file);
14577 + sb = inode->i_sb;
14578 + si_noflush_read_lock(sb);
14579 + fi_read_lock(file);
14580 + ii_read_lock_child(inode);
14582 + err = flush(file, id);
14583 + au_cpup_attr_timesizes(inode);
14585 + ii_read_unlock(inode);
14586 + fi_read_unlock(file);
14587 + si_read_unlock(sb);
14591 +/* ---------------------------------------------------------------------- */
14593 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
14596 + struct au_pin pin;
14597 + struct au_finfo *finfo;
14598 + struct dentry *parent, *hi_wh;
14599 + struct inode *inode;
14600 + struct super_block *sb;
14601 + struct au_cp_generic cpg = {
14602 + .dentry = file->f_path.dentry,
14607 + .flags = AuCpup_DTIME
14610 + FiMustWriteLock(file);
14613 + finfo = au_fi(file);
14614 + sb = cpg.dentry->d_sb;
14615 + inode = d_inode(cpg.dentry);
14616 + cpg.bdst = au_ibtop(inode);
14617 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
14620 + parent = dget_parent(cpg.dentry);
14621 + if (au_test_ro(sb, cpg.bdst, inode)) {
14622 + di_read_lock_parent(parent, !AuLock_IR);
14623 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
14625 + di_read_unlock(parent, !AuLock_IR);
14626 + if (unlikely(err < 0))
14631 + di_read_lock_parent(parent, AuLock_IR);
14632 + hi_wh = au_hi_wh(inode, cpg.bdst);
14633 + if (!S_ISDIR(inode->i_mode)
14634 + && au_opt_test(au_mntflags(sb), PLINK)
14635 + && au_plink_test(inode)
14636 + && !d_unhashed(cpg.dentry)
14637 + && cpg.bdst < au_dbtop(cpg.dentry)) {
14638 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
14639 + if (unlikely(err))
14642 + /* always superio. */
14643 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
14644 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
14646 + err = au_sio_cpup_simple(&cpg);
14649 + } else if (hi_wh) {
14650 + /* already copied-up after unlink */
14651 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
14652 + *need_reopen = 0;
14656 + di_read_unlock(parent, AuLock_IR);
14663 +static void au_do_refresh_dir(struct file *file)
14665 + aufs_bindex_t bindex, bbot, new_bindex, brid;
14666 + struct au_hfile *p, tmp, *q;
14667 + struct au_finfo *finfo;
14668 + struct super_block *sb;
14669 + struct au_fidir *fidir;
14671 + FiMustWriteLock(file);
14673 + sb = file->f_path.dentry->d_sb;
14674 + finfo = au_fi(file);
14675 + fidir = finfo->fi_hdir;
14676 + AuDebugOn(!fidir);
14677 + p = fidir->fd_hfile + finfo->fi_btop;
14678 + brid = p->hf_br->br_id;
14679 + bbot = fidir->fd_bbot;
14680 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
14684 + new_bindex = au_br_index(sb, p->hf_br->br_id);
14685 + if (new_bindex == bindex)
14687 + if (new_bindex < 0) {
14688 + au_set_h_fptr(file, bindex, NULL);
14692 + /* swap two lower inode, and loop again */
14693 + q = fidir->fd_hfile + new_bindex;
14697 + if (tmp.hf_file) {
14703 + p = fidir->fd_hfile;
14704 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
14705 + bbot = au_sbbot(sb);
14706 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
14707 + finfo->fi_btop++, p++)
14708 + if (p->hf_file) {
14709 + if (file_inode(p->hf_file))
14711 + au_hfput(p, /*execed*/0);
14714 + bbot = au_br_index(sb, brid);
14715 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
14716 + finfo->fi_btop++, p++)
14718 + au_hfput(p, /*execed*/0);
14719 + bbot = au_sbbot(sb);
14722 + p = fidir->fd_hfile + bbot;
14723 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
14724 + fidir->fd_bbot--, p--)
14725 + if (p->hf_file) {
14726 + if (file_inode(p->hf_file))
14728 + au_hfput(p, /*execed*/0);
14730 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
14734 + * after branch manipulating, refresh the file.
14736 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
14738 + int err, need_reopen, nbr;
14739 + aufs_bindex_t bbot, bindex;
14740 + struct dentry *dentry;
14741 + struct super_block *sb;
14742 + struct au_finfo *finfo;
14743 + struct au_hfile *hfile;
14745 + dentry = file->f_path.dentry;
14746 + sb = dentry->d_sb;
14747 + nbr = au_sbbot(sb) + 1;
14748 + finfo = au_fi(file);
14749 + if (!finfo->fi_hdir) {
14750 + hfile = &finfo->fi_htop;
14751 + AuDebugOn(!hfile->hf_file);
14752 + bindex = au_br_index(sb, hfile->hf_br->br_id);
14753 + AuDebugOn(bindex < 0);
14754 + if (bindex != finfo->fi_btop)
14755 + au_set_fbtop(file, bindex);
14757 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
14758 + if (unlikely(err))
14760 + au_do_refresh_dir(file);
14765 + if (!au_test_mmapped(file))
14766 + err = au_file_refresh_by_inode(file, &need_reopen);
14767 + if (finfo->fi_hdir)
14768 + /* harmless if err */
14769 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
14770 + if (!err && need_reopen && !d_unlinked(dentry))
14771 + err = reopen(file);
14773 + au_update_figen(file);
14774 + goto out; /* success */
14777 + /* error, close all lower files */
14778 + if (finfo->fi_hdir) {
14779 + bbot = au_fbbot_dir(file);
14780 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
14781 + au_set_h_fptr(file, bindex, NULL);
14788 +/* common function to regular file and dir */
14789 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
14790 + int wlock, unsigned int fi_lsc)
14793 + unsigned int sigen, figen;
14794 + aufs_bindex_t btop;
14795 + unsigned char pseudo_link;
14796 + struct dentry *dentry;
14797 + struct inode *inode;
14800 + dentry = file->f_path.dentry;
14801 + inode = d_inode(dentry);
14802 + sigen = au_sigen(dentry->d_sb);
14803 + fi_write_lock_nested(file, fi_lsc);
14804 + figen = au_figen(file);
14806 + di_write_lock_child(dentry);
14808 + di_write_lock_child2(dentry);
14809 + btop = au_dbtop(dentry);
14810 + pseudo_link = (btop != au_ibtop(inode));
14811 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
14813 + di_downgrade_lock(dentry, AuLock_IR);
14814 + fi_downgrade_lock(file);
14816 + goto out; /* success */
14819 + AuDbg("sigen %d, figen %d\n", sigen, figen);
14820 + if (au_digen_test(dentry, sigen)) {
14821 + err = au_reval_dpath(dentry, sigen);
14822 + AuDebugOn(!err && au_digen_test(dentry, sigen));
14826 + err = refresh_file(file, reopen);
14829 + di_downgrade_lock(dentry, AuLock_IR);
14830 + fi_downgrade_lock(file);
14833 + di_write_unlock(dentry);
14834 + fi_write_unlock(file);
14841 +/* ---------------------------------------------------------------------- */
14843 +/* cf. aufs_nopage() */
14844 +/* for madvise(2) */
14845 +static int aufs_read_folio(struct file *file __maybe_unused, struct folio *folio)
14847 + folio_unlock(folio);
14851 +/* it will never be called, but necessary to support O_DIRECT */
14852 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
14853 +{ BUG(); return 0; }
14855 +/* they will never be called. */
14856 +#ifdef CONFIG_AUFS_DEBUG
14857 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
14858 + loff_t pos, unsigned len,
14859 + struct page **pagep, void **fsdata)
14860 +{ AuUnsupport(); return 0; }
14861 +static int aufs_write_end(struct file *file, struct address_space *mapping,
14862 + loff_t pos, unsigned len, unsigned copied,
14863 + struct page *page, void *fsdata)
14864 +{ AuUnsupport(); return 0; }
14865 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
14866 +{ AuUnsupport(); return 0; }
14868 +static bool aufs_dirty_folio(struct address_space *mapping, struct folio *folio)
14869 +{ AuUnsupport(); return true; }
14870 +static void aufs_invalidate_folio(struct folio *folio, size_t offset, size_t len)
14871 +{ AuUnsupport(); }
14872 +static bool aufs_release_folio(struct folio *folio, gfp_t gfp)
14873 +{ AuUnsupport(); return true; }
14874 +#if 0 /* called by memory compaction regardless file */
14875 +static int aufs_migrate_folio(struct address_space *mapping, struct folio *dst,
14876 + struct folio *src, enum migrate_mode mode)
14877 +{ AuUnsupport(); return 0; }
14879 +static int aufs_launder_folio(struct folio *folio)
14880 +{ AuUnsupport(); return 0; }
14881 +static bool aufs_is_partially_uptodate(struct folio *folio, size_t from,
14883 +{ AuUnsupport(); return true; }
14884 +static void aufs_is_dirty_writeback(struct folio *folio, bool *dirty,
14886 +{ AuUnsupport(); }
14887 +static int aufs_error_remove_page(struct address_space *mapping,
14888 + struct page *page)
14889 +{ AuUnsupport(); return 0; }
14890 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
14892 +{ AuUnsupport(); return 0; }
14893 +static void aufs_swap_deactivate(struct file *file)
14894 +{ AuUnsupport(); }
14895 +static int aufs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
14896 +{ AuUnsupport(); return 0; }
14897 +#endif /* CONFIG_AUFS_DEBUG */
14899 +const struct address_space_operations aufs_aop = {
14900 + .read_folio = aufs_read_folio,
14901 + .direct_IO = aufs_direct_IO,
14902 +#ifdef CONFIG_AUFS_DEBUG
14903 + .writepage = aufs_writepage,
14904 + /* no writepages, because of writepage */
14905 + .dirty_folio = aufs_dirty_folio,
14906 + /* no readpages, because of readpage */
14907 + .write_begin = aufs_write_begin,
14908 + .write_end = aufs_write_end,
14909 + /* no bmap, no block device */
14910 + .invalidate_folio = aufs_invalidate_folio,
14911 + .release_folio = aufs_release_folio,
14912 + /* is fallback_migrate_page ok? */
14913 + /* .migrate_folio = aufs_migrate_folio, */
14914 + .launder_folio = aufs_launder_folio,
14915 + .is_partially_uptodate = aufs_is_partially_uptodate,
14916 + .is_dirty_writeback = aufs_is_dirty_writeback,
14917 + .error_remove_page = aufs_error_remove_page,
14918 + .swap_activate = aufs_swap_activate,
14919 + .swap_deactivate = aufs_swap_deactivate,
14920 + .swap_rw = aufs_swap_rw
14921 +#endif /* CONFIG_AUFS_DEBUG */
14923 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
14924 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
14925 +++ linux/fs/aufs/file.h 2022-11-05 23:02:18.965889284 +0100
14927 +/* SPDX-License-Identifier: GPL-2.0 */
14929 + * Copyright (C) 2005-2022 Junjiro R. Okajima
14931 + * This program is free software; you can redistribute it and/or modify
14932 + * it under the terms of the GNU General Public License as published by
14933 + * the Free Software Foundation; either version 2 of the License, or
14934 + * (at your option) any later version.
14936 + * This program is distributed in the hope that it will be useful,
14937 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14938 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14939 + * GNU General Public License for more details.
14941 + * You should have received a copy of the GNU General Public License
14942 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14946 + * file operations
14949 +#ifndef __AUFS_FILE_H__
14950 +#define __AUFS_FILE_H__
14954 +#include <linux/file.h>
14955 +#include <linux/fs.h>
14956 +#include <linux/mm_types.h>
14957 +#include <linux/poll.h>
14958 +#include "rwsem.h"
14962 + struct file *hf_file;
14963 + struct au_branch *hf_br;
14968 + aufs_bindex_t fd_bbot;
14969 + aufs_bindex_t fd_nent;
14970 + struct au_vdir *fd_vdir_cache;
14971 + struct au_hfile fd_hfile[];
14974 +static inline int au_fidir_sz(int nent)
14976 + AuDebugOn(nent < 0);
14977 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
14981 + atomic_t fi_generation;
14983 + struct au_rwsem fi_rwsem;
14984 + aufs_bindex_t fi_btop;
14986 + /* do not union them */
14987 + struct { /* for non-dir */
14988 + struct au_hfile fi_htop;
14989 + atomic_t fi_mmapped;
14991 + struct au_fidir *fi_hdir; /* for dir only */
14993 + struct hlist_bl_node fi_hlist;
14994 + struct file *fi_file; /* very ugly */
14995 + struct rcu_head rcu;
14996 +} ____cacheline_aligned_in_smp;
14998 +/* ---------------------------------------------------------------------- */
15001 +extern const struct address_space_operations aufs_aop;
15002 +unsigned int au_file_roflags(unsigned int flags);
15003 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
15004 + struct file *file, int force_wr);
15005 +struct au_do_open_args {
15007 + int (*open)(struct file *file, int flags,
15008 + struct file *h_file);
15009 + struct au_fidir *fidir;
15010 + struct file *h_file;
15012 +int au_do_open(struct file *file, struct au_do_open_args *args);
15013 +int au_reopen_nondir(struct file *file);
15015 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
15016 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
15017 + int wlock, unsigned int fi_lsc);
15018 +int au_do_flush(struct file *file, fl_owner_t id,
15019 + int (*flush)(struct file *file, fl_owner_t id));
15022 +#ifdef CONFIG_AUFS_POLL
15023 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt);
15026 +#ifdef CONFIG_AUFS_BR_HFSPLUS
15028 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15030 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15031 + struct file *h_file);
15033 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
15034 + aufs_bindex_t bindex, int force_wr)
15035 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
15036 + struct file *h_file);
15040 +extern const struct file_operations aufs_file_fop;
15041 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
15042 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
15043 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc);
15046 +void au_hfput(struct au_hfile *hf, int execed);
15047 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
15048 + struct file *h_file);
15050 +void au_update_figen(struct file *file);
15051 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
15052 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
15054 +void au_fi_init_once(void *_fi);
15055 +void au_finfo_fin(struct file *file);
15056 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
15059 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
15060 +#ifdef CONFIG_COMPAT
15061 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
15062 + unsigned long arg);
15063 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
15064 + unsigned long arg);
15067 +/* ---------------------------------------------------------------------- */
15069 +static inline struct au_finfo *au_fi(struct file *file)
15071 + return file->private_data;
15074 +/* ---------------------------------------------------------------------- */
15076 +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem)
15077 +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem)
15078 +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem)
15079 +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem)
15081 +#define fi_read_trylock_nested(f) \
15082 + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem)
15083 +#define fi_write_trylock_nested(f) \
15084 + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem)
15087 +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem)
15088 +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem)
15089 +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem)
15091 +/* lock subclass for finfo */
15097 +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc)
15099 + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15102 +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc)
15104 + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc);
15108 + * fi_read_lock_1, fi_write_lock_1,
15109 + * fi_read_lock_2, fi_write_lock_2
15111 +#define AuReadLockFunc(name) \
15112 +static inline void fi_read_lock_##name(struct file *f) \
15113 +{ fi_read_lock_nested(f, AuLsc_FI_##name); }
15115 +#define AuWriteLockFunc(name) \
15116 +static inline void fi_write_lock_##name(struct file *f) \
15117 +{ fi_write_lock_nested(f, AuLsc_FI_##name); }
15119 +#define AuRWLockFuncs(name) \
15120 + AuReadLockFunc(name) \
15121 + AuWriteLockFunc(name)
15126 +#undef AuReadLockFunc
15127 +#undef AuWriteLockFunc
15128 +#undef AuRWLockFuncs
15130 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
15131 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
15132 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
15134 +/* ---------------------------------------------------------------------- */
15136 +/* todo: hard/soft set? */
15137 +static inline aufs_bindex_t au_fbtop(struct file *file)
15139 + FiMustAnyLock(file);
15140 + return au_fi(file)->fi_btop;
15143 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
15145 + FiMustAnyLock(file);
15146 + AuDebugOn(!au_fi(file)->fi_hdir);
15147 + return au_fi(file)->fi_hdir->fd_bbot;
15150 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
15152 + FiMustAnyLock(file);
15153 + AuDebugOn(!au_fi(file)->fi_hdir);
15154 + return au_fi(file)->fi_hdir->fd_vdir_cache;
15157 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
15159 + FiMustWriteLock(file);
15160 + au_fi(file)->fi_btop = bindex;
15163 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
15165 + FiMustWriteLock(file);
15166 + AuDebugOn(!au_fi(file)->fi_hdir);
15167 + au_fi(file)->fi_hdir->fd_bbot = bindex;
15170 +static inline void au_set_fvdir_cache(struct file *file,
15171 + struct au_vdir *vdir_cache)
15173 + FiMustWriteLock(file);
15174 + AuDebugOn(!au_fi(file)->fi_hdir);
15175 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
15178 +static inline struct file *au_hf_top(struct file *file)
15180 + FiMustAnyLock(file);
15181 + AuDebugOn(au_fi(file)->fi_hdir);
15182 + return au_fi(file)->fi_htop.hf_file;
15185 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
15187 + FiMustAnyLock(file);
15188 + AuDebugOn(!au_fi(file)->fi_hdir);
15189 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
15192 +/* todo: memory barrier? */
15193 +static inline unsigned int au_figen(struct file *f)
15195 + return atomic_read(&au_fi(f)->fi_generation);
15198 +static inline void au_set_mmapped(struct file *f)
15200 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
15202 + pr_warn("fi_mmapped wrapped around\n");
15203 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
15207 +static inline void au_unset_mmapped(struct file *f)
15209 + atomic_dec(&au_fi(f)->fi_mmapped);
15212 +static inline int au_test_mmapped(struct file *f)
15214 + return atomic_read(&au_fi(f)->fi_mmapped);
15217 +/* customize vma->vm_file */
15219 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
15220 + struct file *file)
15224 + f = vma->vm_file;
15226 + vma->vm_file = file;
15231 +#define AuDbgVmRegion(file, vma) do {} while (0)
15233 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15234 + struct file *file)
15236 + au_do_vm_file_reset(vma, file);
15239 +#define AuDbgVmRegion(file, vma) \
15240 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
15242 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
15243 + struct file *file)
15247 + au_do_vm_file_reset(vma, file);
15248 + f = vma->vm_region->vm_file;
15250 + vma->vm_region->vm_file = file;
15253 +#endif /* CONFIG_MMU */
15255 +/* handle vma->vm_prfile */
15256 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
15257 + struct file *file)
15260 + vma->vm_prfile = file;
15261 +#ifndef CONFIG_MMU
15263 + vma->vm_region->vm_prfile = file;
15267 +#endif /* __KERNEL__ */
15268 +#endif /* __AUFS_FILE_H__ */
15269 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
15270 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
15271 +++ linux/fs/aufs/finfo.c 2022-11-05 23:02:18.965889284 +0100
15273 +// SPDX-License-Identifier: GPL-2.0
15275 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15277 + * This program is free software; you can redistribute it and/or modify
15278 + * it under the terms of the GNU General Public License as published by
15279 + * the Free Software Foundation; either version 2 of the License, or
15280 + * (at your option) any later version.
15282 + * This program is distributed in the hope that it will be useful,
15283 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15284 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15285 + * GNU General Public License for more details.
15287 + * You should have received a copy of the GNU General Public License
15288 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15292 + * file private data
15297 +void au_hfput(struct au_hfile *hf, int execed)
15300 + allow_write_access(hf->hf_file);
15301 + fput(hf->hf_file);
15302 + hf->hf_file = NULL;
15303 + au_lcnt_dec(&hf->hf_br->br_nfiles);
15304 + hf->hf_br = NULL;
15307 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
15309 + struct au_finfo *finfo = au_fi(file);
15310 + struct au_hfile *hf;
15311 + struct au_fidir *fidir;
15313 + fidir = finfo->fi_hdir;
15315 + AuDebugOn(finfo->fi_btop != bindex);
15316 + hf = &finfo->fi_htop;
15318 + hf = fidir->fd_hfile + bindex;
15320 + if (hf && hf->hf_file)
15321 + au_hfput(hf, vfsub_file_execed(file));
15323 + FiMustWriteLock(file);
15324 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
15325 + hf->hf_file = val;
15326 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
15330 +void au_update_figen(struct file *file)
15332 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
15333 + /* smp_mb(); */ /* atomic_set */
15336 +/* ---------------------------------------------------------------------- */
15338 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
15340 + struct au_fidir *fidir;
15343 + nbr = au_sbbot(sb) + 1;
15345 + nbr = 2; /* initial allocate for 2 branches */
15346 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
15348 + fidir->fd_bbot = -1;
15349 + fidir->fd_nent = nbr;
15355 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
15358 + struct au_fidir *fidir, *p;
15360 + AuRwMustWriteLock(&finfo->fi_rwsem);
15361 + fidir = finfo->fi_hdir;
15362 + AuDebugOn(!fidir);
15365 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
15366 + GFP_NOFS, may_shrink);
15368 + p->fd_nent = nbr;
15369 + finfo->fi_hdir = p;
15376 +/* ---------------------------------------------------------------------- */
15378 +void au_finfo_fin(struct file *file)
15380 + struct au_finfo *finfo;
15382 + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles);
15384 + finfo = au_fi(file);
15385 + AuDebugOn(finfo->fi_hdir);
15386 + AuRwDestroy(&finfo->fi_rwsem);
15387 + au_cache_free_finfo(finfo);
15390 +void au_fi_init_once(void *_finfo)
15392 + struct au_finfo *finfo = _finfo;
15394 + au_rw_init(&finfo->fi_rwsem);
15397 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
15400 + struct au_finfo *finfo;
15401 + struct dentry *dentry;
15404 + dentry = file->f_path.dentry;
15405 + finfo = au_cache_alloc_finfo();
15406 + if (unlikely(!finfo))
15410 + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles);
15411 + au_rw_write_lock(&finfo->fi_rwsem);
15412 + finfo->fi_btop = -1;
15413 + finfo->fi_hdir = fidir;
15414 + atomic_set(&finfo->fi_generation, au_digen(dentry));
15415 + /* smp_mb(); */ /* atomic_set */
15417 + file->private_data = finfo;
15422 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
15423 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
15424 +++ linux/fs/aufs/f_op.c 2023-02-20 21:05:51.959693785 +0100
15426 +// SPDX-License-Identifier: GPL-2.0
15428 + * Copyright (C) 2005-2022 Junjiro R. Okajima
15430 + * This program is free software; you can redistribute it and/or modify
15431 + * it under the terms of the GNU General Public License as published by
15432 + * the Free Software Foundation; either version 2 of the License, or
15433 + * (at your option) any later version.
15435 + * This program is distributed in the hope that it will be useful,
15436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15438 + * GNU General Public License for more details.
15440 + * You should have received a copy of the GNU General Public License
15441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15445 + * file and vm operations
15448 +#include <linux/aio.h>
15449 +#include <linux/fs_stack.h>
15450 +#include <linux/mman.h>
15451 +#include <linux/security.h>
15454 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
15457 + aufs_bindex_t bindex;
15458 + struct dentry *dentry, *h_dentry;
15459 + struct au_finfo *finfo;
15460 + struct inode *h_inode;
15462 + FiMustWriteLock(file);
15465 + dentry = file->f_path.dentry;
15466 + AuDebugOn(IS_ERR_OR_NULL(dentry));
15467 + finfo = au_fi(file);
15468 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
15469 + atomic_set(&finfo->fi_mmapped, 0);
15470 + bindex = au_dbtop(dentry);
15472 + h_dentry = au_h_dptr(dentry, bindex);
15473 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15474 + if (unlikely(err))
15476 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
15477 + if (IS_ERR(h_file)) {
15478 + err = PTR_ERR(h_file);
15482 + h_dentry = h_file->f_path.dentry;
15483 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
15484 + if (unlikely(err))
15486 + /* br ref is already inc-ed */
15489 + if (flags & __O_TMPFILE) {
15490 + AuDebugOn(!h_file);
15491 + AuDebugOn(h_file != au_di(dentry)->di_htmpfile);
15492 + au_di(dentry)->di_htmpfile = NULL;
15494 + if (!(flags & O_EXCL)) {
15495 + h_inode = file_inode(h_file);
15496 + spin_lock(&h_inode->i_lock);
15497 + h_inode->i_state |= I_LINKABLE;
15498 + spin_unlock(&h_inode->i_lock);
15501 + au_set_fbtop(file, bindex);
15502 + au_set_h_fptr(file, bindex, h_file);
15503 + au_update_figen(file);
15504 + /* todo: necessary? */
15505 + /* file->f_ra = h_file->f_ra; */
15511 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
15512 + struct file *file)
15515 + struct super_block *sb;
15516 + struct au_do_open_args args = {
15517 + .open = au_do_open_nondir
15520 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
15521 + file, vfsub_file_flags(file), file->f_mode);
15523 + sb = file->f_path.dentry->d_sb;
15524 + si_read_lock(sb, AuLock_FLUSH);
15525 + err = au_do_open(file, &args);
15526 + si_read_unlock(sb);
15530 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
15532 + struct au_finfo *finfo;
15533 + aufs_bindex_t bindex;
15535 + finfo = au_fi(file);
15536 + au_hbl_del(&finfo->fi_hlist,
15537 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
15538 + bindex = finfo->fi_btop;
15540 + au_set_h_fptr(file, bindex, NULL);
15542 + au_finfo_fin(file);
15546 +/* ---------------------------------------------------------------------- */
15548 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
15551 + struct file *h_file;
15554 + h_file = au_hf_top(file);
15556 + err = vfsub_flush(h_file, id);
15560 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
15562 + return au_do_flush(file, id, au_do_flush_nondir);
15565 +/* ---------------------------------------------------------------------- */
15567 + * read and write functions acquire [fdi]_rwsem once, but release before
15568 + * mmap_sem. This is because to stop a race condition between mmap(2).
15569 + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping
15570 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
15571 + * read functions after [fdi]_rwsem are released, but it should be harmless.
15574 +/* Callers should call au_read_post() or fput() in the end */
15575 +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc)
15577 + struct file *h_file;
15580 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc);
15582 + di_read_unlock(file->f_path.dentry, AuLock_IR);
15583 + h_file = au_hf_top(file);
15584 + get_file(h_file);
15586 + fi_read_unlock(file);
15588 + h_file = ERR_PTR(err);
15593 +static void au_read_post(struct inode *inode, struct file *h_file)
15595 + /* update without lock, I don't think it a problem */
15596 + fsstack_copy_attr_atime(inode, file_inode(h_file));
15600 +struct au_write_pre {
15602 + unsigned int lsc;
15606 + aufs_bindex_t btop;
15610 + * return with iinfo is write-locked
15611 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
15614 +static struct file *au_write_pre(struct file *file, int do_ready,
15615 + struct au_write_pre *wpre)
15617 + struct file *h_file;
15618 + struct dentry *dentry;
15620 + unsigned int lsc;
15621 + struct au_pin pin;
15626 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc);
15627 + h_file = ERR_PTR(err);
15628 + if (unlikely(err))
15631 + dentry = file->f_path.dentry;
15633 + err = au_ready_to_write(file, -1, &pin);
15634 + if (unlikely(err)) {
15635 + h_file = ERR_PTR(err);
15636 + di_write_unlock(dentry);
15641 + di_downgrade_lock(dentry, /*flags*/0);
15643 + wpre->btop = au_fbtop(file);
15644 + h_file = au_hf_top(file);
15645 + get_file(h_file);
15647 + wpre->blks = file_inode(h_file)->i_blocks;
15650 + di_read_unlock(dentry, /*flags*/0);
15653 + fi_write_unlock(file);
15658 +static void au_write_post(struct inode *inode, struct file *h_file,
15659 + struct au_write_pre *wpre, ssize_t written)
15661 + struct inode *h_inode;
15663 + au_cpup_attr_timesizes(inode);
15664 + AuDebugOn(au_ibtop(inode) != wpre->btop);
15665 + h_inode = file_inode(h_file);
15666 + inode->i_mode = h_inode->i_mode;
15667 + ii_write_unlock(inode);
15668 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
15670 + au_fhsm_wrote(inode->i_sb, wpre->btop,
15671 + /*force*/h_inode->i_blocks > wpre->blks);
15676 + * todo: very ugly
15677 + * it locks both of i_mutex and si_rwsem for read in safe.
15678 + * if the plink maintenance mode continues forever (that is the problem),
15679 + * may loop forever.
15681 +static void au_mtx_and_read_lock(struct inode *inode)
15684 + struct super_block *sb = inode->i_sb;
15687 + inode_lock(inode);
15688 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15691 + inode_unlock(inode);
15692 + si_read_lock(sb, AuLock_NOPLMW);
15693 + si_read_unlock(sb);
15697 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
15698 + struct iov_iter *iov_iter)
15701 + struct file *file;
15702 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
15704 + err = security_file_permission(h_file, rw);
15705 + if (unlikely(err))
15708 + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */
15710 + if (rw == MAY_READ)
15711 + iter = h_file->f_op->read_iter;
15712 + else if (rw == MAY_WRITE)
15713 + iter = h_file->f_op->write_iter;
15715 + file = kio->ki_filp;
15716 + kio->ki_filp = h_file;
15719 + err = iter(kio, iov_iter);
15722 + /* currently there is no such fs */
15724 + kio->ki_filp = file;
15730 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15733 + struct file *file, *h_file;
15734 + struct inode *inode;
15735 + struct super_block *sb;
15737 + file = kio->ki_filp;
15738 + inode = file_inode(file);
15739 + sb = inode->i_sb;
15740 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15742 + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0);
15743 + err = PTR_ERR(h_file);
15744 + if (IS_ERR(h_file))
15747 + if (au_test_loopback_kthread()) {
15748 + au_warn_loopback(h_file->f_path.dentry->d_sb);
15749 + if (file->f_mapping != h_file->f_mapping) {
15750 + file->f_mapping = h_file->f_mapping;
15751 + smp_mb(); /* unnecessary? */
15754 + fi_read_unlock(file);
15756 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
15757 + /* todo: necessary? */
15758 + /* file->f_ra = h_file->f_ra; */
15759 + au_read_post(inode, h_file);
15762 + si_read_unlock(sb);
15766 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
15769 + struct au_write_pre wpre;
15770 + struct inode *inode;
15771 + struct file *file, *h_file;
15773 + file = kio->ki_filp;
15774 + inode = file_inode(file);
15775 + au_mtx_and_read_lock(inode);
15778 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15779 + err = PTR_ERR(h_file);
15780 + if (IS_ERR(h_file))
15783 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
15784 + au_write_post(inode, h_file, &wpre, err);
15787 + si_read_unlock(inode->i_sb);
15788 + inode_unlock(inode);
15793 + * We may be able to remove aufs_splice_{read,write}() since almost all FSes
15794 + * don't have their own .splice_{read,write} implimentations, and they use
15795 + * generic_file_splice_read() and iter_file_splice_write() who can act like the
15796 + * simple converters to f_op->iter_read() and ->iter_write().
15797 + * But we keep our own implementations because some non-mainlined FSes may have
15798 + * their own .splice_{read,write} implimentations and aufs doesn't want to take
15799 + * away an opportunity to co-work with aufs from them.
15801 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
15802 + struct pipe_inode_info *pipe, size_t len,
15803 + unsigned int flags)
15806 + struct file *h_file;
15807 + struct inode *inode;
15808 + struct super_block *sb;
15810 + inode = file_inode(file);
15811 + sb = inode->i_sb;
15812 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
15814 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
15815 + err = PTR_ERR(h_file);
15816 + if (IS_ERR(h_file))
15819 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
15820 + /* todo: necessary? */
15821 + /* file->f_ra = h_file->f_ra; */
15822 + au_read_post(inode, h_file);
15825 + si_read_unlock(sb);
15830 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
15831 + size_t len, unsigned int flags)
15834 + struct au_write_pre wpre;
15835 + struct inode *inode;
15836 + struct file *h_file;
15838 + inode = file_inode(file);
15839 + au_mtx_and_read_lock(inode);
15842 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15843 + err = PTR_ERR(h_file);
15844 + if (IS_ERR(h_file))
15847 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
15848 + au_write_post(inode, h_file, &wpre, err);
15851 + si_read_unlock(inode->i_sb);
15852 + inode_unlock(inode);
15856 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
15860 + struct au_write_pre wpre;
15861 + struct inode *inode;
15862 + struct file *h_file;
15864 + inode = file_inode(file);
15865 + au_mtx_and_read_lock(inode);
15868 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
15869 + err = PTR_ERR(h_file);
15870 + if (IS_ERR(h_file))
15874 + err = vfs_fallocate(h_file, mode, offset, len);
15877 + * we don't need to call file_modifed() here since au_write_post()
15878 + * is equivalent and copies-up all timestamps and permission bits.
15880 + au_write_post(inode, h_file, &wpre, /*written*/1);
15883 + si_read_unlock(inode->i_sb);
15884 + inode_unlock(inode);
15888 +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos,
15889 + struct file *dst, loff_t dst_pos,
15890 + size_t len, unsigned int flags)
15893 + struct au_write_pre wpre;
15894 + enum { SRC, DST };
15896 + struct inode *inode;
15897 + struct file *h_file;
15898 + struct super_block *h_sb;
15900 +#define a_src a[SRC]
15901 +#define a_dst a[DST]
15904 + a_src.inode = file_inode(src);
15905 + if (unlikely(!S_ISREG(a_src.inode->i_mode)))
15907 + a_dst.inode = file_inode(dst);
15908 + if (unlikely(!S_ISREG(a_dst.inode->i_mode)))
15911 + au_mtx_and_read_lock(a_dst.inode);
15913 + * in order to match the order in di_write_lock2_{child,parent}(),
15914 + * use f_path.dentry for this comparison.
15916 + if (src->f_path.dentry < dst->f_path.dentry) {
15917 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1);
15918 + err = PTR_ERR(a_src.h_file);
15919 + if (IS_ERR(a_src.h_file))
15922 + wpre.lsc = AuLsc_FI_2;
15923 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15924 + err = PTR_ERR(a_dst.h_file);
15925 + if (IS_ERR(a_dst.h_file)) {
15926 + au_read_post(a_src.inode, a_src.h_file);
15930 + wpre.lsc = AuLsc_FI_1;
15931 + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre);
15932 + err = PTR_ERR(a_dst.h_file);
15933 + if (IS_ERR(a_dst.h_file))
15936 + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2);
15937 + err = PTR_ERR(a_src.h_file);
15938 + if (IS_ERR(a_src.h_file)) {
15939 + au_write_post(a_dst.inode, a_dst.h_file, &wpre,
15946 + a_src.h_sb = file_inode(a_src.h_file)->i_sb;
15947 + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb;
15948 + if (unlikely(a_src.h_sb != a_dst.h_sb)) {
15954 + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file,
15955 + dst_pos, len, flags);
15958 + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err);
15959 + fi_read_unlock(src);
15960 + au_read_post(a_src.inode, a_src.h_file);
15962 + si_read_unlock(a_dst.inode->i_sb);
15963 + inode_unlock(a_dst.inode);
15970 +/* ---------------------------------------------------------------------- */
15973 + * The locking order around current->mmap_sem.
15974 + * - in most and regular cases
15975 + * file I/O syscall -- aufs_read() or something
15976 + * -- si_rwsem for read -- mmap_sem
15977 + * (Note that [fdi]i_rwsem are released before mmap_sem).
15979 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
15980 + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for
15981 + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held
15982 + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
15983 + * It means that when aufs acquires si_rwsem for write, the process should never
15984 + * acquire mmap_sem.
15986 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
15987 + * problem either since any directory is not able to be mmap-ed.
15988 + * The similar scenario is applied to aufs_readlink() too.
15991 +#if 0 /* stop calling security_file_mmap() */
15992 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
15993 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
15995 +static unsigned long au_arch_prot_conv(unsigned long flags)
15997 + /* currently ppc64 only */
15998 +#ifdef CONFIG_PPC64
15999 + /* cf. linux/arch/powerpc/include/asm/mman.h */
16000 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
16001 + return AuConv_VM_PROT(flags, SAO);
16003 + AuDebugOn(arch_calc_vm_prot_bits(-1));
16008 +static unsigned long au_prot_conv(unsigned long flags)
16010 + return AuConv_VM_PROT(flags, READ)
16011 + | AuConv_VM_PROT(flags, WRITE)
16012 + | AuConv_VM_PROT(flags, EXEC)
16013 + | au_arch_prot_conv(flags);
16016 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
16017 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
16019 +static unsigned long au_flag_conv(unsigned long flags)
16021 + return AuConv_VM_MAP(flags, GROWSDOWN)
16022 + | AuConv_VM_MAP(flags, DENYWRITE)
16023 + | AuConv_VM_MAP(flags, LOCKED);
16027 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
16030 + const unsigned char wlock
16031 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
16032 + struct super_block *sb;
16033 + struct file *h_file;
16034 + struct inode *inode;
16036 + AuDbgVmRegion(file, vma);
16038 + inode = file_inode(file);
16039 + sb = inode->i_sb;
16041 + si_read_lock(sb, AuLock_NOPLMW);
16043 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
16045 + err = PTR_ERR(h_file);
16046 + if (IS_ERR(h_file))
16050 + au_set_mmapped(file);
16051 + au_vm_file_reset(vma, h_file);
16053 + * we cannot call security_mmap_file() here since it may acquire
16054 + * mmap_sem or i_mutex.
16056 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
16057 + * au_flag_conv(vma->vm_flags));
16060 + err = call_mmap(h_file, vma);
16062 + au_vm_prfile_set(vma, file);
16063 + fsstack_copy_attr_atime(inode, file_inode(h_file));
16064 + goto out_fput; /* success */
16066 + au_unset_mmapped(file);
16067 + au_vm_file_reset(vma, file);
16071 + ii_write_unlock(inode);
16076 + si_read_unlock(sb);
16082 +/* ---------------------------------------------------------------------- */
16084 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
16088 + struct au_write_pre wpre;
16089 + struct inode *inode;
16090 + struct file *h_file;
16092 + err = 0; /* -EBADF; */ /* posix? */
16093 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
16096 + inode = file_inode(file);
16097 + au_mtx_and_read_lock(inode);
16100 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
16101 + err = PTR_ERR(h_file);
16102 + if (IS_ERR(h_file))
16105 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
16106 + au_write_post(inode, h_file, &wpre, /*written*/0);
16109 + si_read_unlock(inode->i_sb);
16110 + inode_unlock(inode);
16115 +static int aufs_fasync(int fd, struct file *file, int flag)
16118 + struct file *h_file;
16119 + struct super_block *sb;
16121 + sb = file->f_path.dentry->d_sb;
16122 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16124 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16125 + err = PTR_ERR(h_file);
16126 + if (IS_ERR(h_file))
16129 + if (h_file->f_op->fasync)
16130 + err = h_file->f_op->fasync(fd, h_file, flag);
16131 + fput(h_file); /* instead of au_read_post() */
16134 + si_read_unlock(sb);
16138 +static int aufs_setfl(struct file *file, unsigned long arg)
16141 + struct file *h_file;
16142 + struct super_block *sb;
16144 + sb = file->f_path.dentry->d_sb;
16145 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
16147 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
16148 + err = PTR_ERR(h_file);
16149 + if (IS_ERR(h_file))
16152 + /* stop calling h_file->fasync */
16153 + arg |= vfsub_file_flags(file) & FASYNC;
16154 + err = setfl(/*unused fd*/-1, h_file, arg);
16155 + fput(h_file); /* instead of au_read_post() */
16158 + si_read_unlock(sb);
16162 +/* ---------------------------------------------------------------------- */
16164 +/* no one supports this operation, currently */
16165 +#if 0 /* reserved for future use */
16166 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
16167 + size_t len, loff_t *pos, int more)
16172 +/* ---------------------------------------------------------------------- */
16174 +const struct file_operations aufs_file_fop = {
16175 + .owner = THIS_MODULE,
16177 + .llseek = default_llseek,
16179 + .read_iter = aufs_read_iter,
16180 + .write_iter = aufs_write_iter,
16182 +#ifdef CONFIG_AUFS_POLL
16183 + .poll = aufs_poll,
16185 + .unlocked_ioctl = aufs_ioctl_nondir,
16186 +#ifdef CONFIG_COMPAT
16187 + .compat_ioctl = aufs_compat_ioctl_nondir,
16189 + .mmap = aufs_mmap,
16190 + .open = aufs_open_nondir,
16191 + .flush = aufs_flush_nondir,
16192 + .release = aufs_release_nondir,
16193 + .fsync = aufs_fsync_nondir,
16194 + .fasync = aufs_fasync,
16195 + /* .sendpage = aufs_sendpage, */
16196 + .setfl = aufs_setfl,
16197 + .splice_write = aufs_splice_write,
16198 + .splice_read = aufs_splice_read,
16199 +#if 0 /* reserved for future use */
16200 + .aio_splice_write = aufs_aio_splice_write,
16201 + .aio_splice_read = aufs_aio_splice_read,
16203 + .fallocate = aufs_fallocate,
16204 + .copy_file_range = aufs_copy_file_range
16206 diff -urN /usr/share/empty/fs/aufs/fsctx.c linux/fs/aufs/fsctx.c
16207 --- /usr/share/empty/fs/aufs/fsctx.c 1970-01-01 01:00:00.000000000 +0100
16208 +++ linux/fs/aufs/fsctx.c 2022-11-05 23:02:18.965889284 +0100
16210 +// SPDX-License-Identifier: GPL-2.0
16212 + * Copyright (C) 2022 Junjiro R. Okajima
16214 + * This program is free software; you can redistribute it and/or modify
16215 + * it under the terms of the GNU General Public License as published by
16216 + * the Free Software Foundation; either version 2 of the License, or
16217 + * (at your option) any later version.
16219 + * This program is distributed in the hope that it will be useful,
16220 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16221 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16222 + * GNU General Public License for more details.
16224 + * You should have received a copy of the GNU General Public License
16225 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16229 + * fs context, aka new mount api
16232 +#include <linux/fs_context.h>
16235 +struct au_fsctx_opts {
16236 + aufs_bindex_t bindex;
16237 + unsigned char skipped;
16238 + struct au_opt *opt, *opt_tail;
16239 + struct super_block *sb;
16240 + struct au_sbinfo *sbinfo;
16241 + struct au_opts opts;
16244 +/* stop extra interpretation of errno in mount(8), and strange error messages */
16245 +static int cvt_err(int err)
16259 +static int au_fsctx_reconfigure(struct fs_context *fc)
16262 + unsigned int mntflags;
16263 + struct dentry *root;
16264 + struct super_block *sb;
16265 + struct inode *inode;
16266 + struct au_fsctx_opts *a = fc->fs_private;
16268 + AuDbg("fc %p\n", fc);
16272 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16274 + di_write_lock_child(root);
16275 + err = au_opts_verify(sb, fc->sb_flags, /*pending*/0);
16276 + aufs_write_unlock(root);
16279 + inode = d_inode(root);
16280 + inode_lock(inode);
16281 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16282 + if (unlikely(err))
16284 + di_write_lock_child(root);
16286 + /* au_opts_remount() may return an error */
16287 + err = au_opts_remount(sb, &a->opts);
16289 + if (au_ftest_opts(a->opts.flags, REFRESH))
16290 + au_remount_refresh(sb, au_ftest_opts(a->opts.flags,
16293 + if (au_ftest_opts(a->opts.flags, REFRESH_DYAOP)) {
16294 + mntflags = au_mntflags(sb);
16295 + do_dx = !!au_opt_test(mntflags, DIO);
16296 + au_dy_arefresh(do_dx);
16299 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
16300 + aufs_write_unlock(root);
16303 + inode_unlock(inode);
16304 + err = cvt_err(err);
16310 +/* ---------------------------------------------------------------------- */
16312 +static int au_fsctx_fill_super(struct super_block *sb, struct fs_context *fc)
16315 + struct au_fsctx_opts *a = fc->fs_private;
16316 + struct au_sbinfo *sbinfo = a->sbinfo;
16317 + struct dentry *root;
16318 + struct inode *inode;
16320 + sbinfo->si_sb = sb;
16321 + sb->s_fs_info = sbinfo;
16322 + kobject_get(&sbinfo->si_kobj);
16324 + __si_write_lock(sb);
16326 + au_sbilist_add(sb);
16328 + /* all timestamps always follow the ones on the branch */
16329 + sb->s_flags |= SB_NOATIME | SB_NODIRATIME;
16330 + sb->s_flags |= SB_I_VERSION; /* do we really need this? */
16331 + sb->s_op = &aufs_sop;
16332 + sb->s_d_op = &aufs_dop;
16333 + sb->s_magic = AUFS_SUPER_MAGIC;
16334 + sb->s_maxbytes = 0;
16335 + sb->s_stack_depth = 1;
16336 + au_export_init(sb);
16337 + au_xattr_init(sb);
16339 + err = au_alloc_root(sb);
16340 + if (unlikely(err)) {
16341 + si_write_unlock(sb);
16344 + root = sb->s_root;
16345 + inode = d_inode(root);
16346 + ii_write_lock_parent(inode);
16347 + aufs_write_unlock(root);
16349 + /* lock vfs_inode first, then aufs. */
16350 + inode_lock(inode);
16351 + aufs_write_lock(root);
16352 + err = au_opts_mount(sb, &a->opts);
16354 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
16355 + sb->s_d_op = &aufs_dop_noreval;
16356 + /* infofc(fc, "%ps", sb->s_d_op); */
16357 + pr_info("%ps\n", sb->s_d_op);
16358 + au_refresh_dop(root, /*force_reval*/0);
16359 + sbinfo->si_iop_array = aufs_iop_nogetattr;
16360 + au_refresh_iop(inode, /*force_getattr*/0);
16362 + aufs_write_unlock(root);
16363 + inode_unlock(inode);
16365 + goto out; /* success */
16368 + sb->s_root = NULL;
16371 + if (unlikely(err))
16372 + kobject_put(&sbinfo->si_kobj);
16374 + err = cvt_err(err);
16379 +static int au_fsctx_get_tree(struct fs_context *fc)
16383 + AuDbg("fc %p\n", fc);
16384 + err = get_tree_nodev(fc, au_fsctx_fill_super);
16390 +/* ---------------------------------------------------------------------- */
16392 +static void au_fsctx_dump(struct au_opts *opts)
16394 +#ifdef CONFIG_AUFS_DEBUG
16395 + /* reduce stack space */
16397 + struct au_opt_add *add;
16398 + struct au_opt_del *del;
16399 + struct au_opt_mod *mod;
16400 + struct au_opt_xino *xino;
16401 + struct au_opt_xino_itrunc *xino_itrunc;
16402 + struct au_opt_wbr_create *create;
16404 + struct au_opt *opt;
16407 + while (opt->type != Opt_tail) {
16408 + switch (opt->type) {
16410 + u.add = &opt->add;
16411 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
16412 + u.add->bindex, u.add->pathname, u.add->perm,
16413 + u.add->path.dentry);
16418 + u.del = &opt->del;
16419 + AuDbg("del {%s, %p}\n",
16420 + u.del->pathname, u.del->h_path.dentry);
16425 + u.mod = &opt->mod;
16426 + AuDbg("mod {%s, 0x%x, %p}\n",
16427 + u.mod->path, u.mod->perm, u.mod->h_root);
16430 + u.add = &opt->add;
16431 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
16432 + u.add->bindex, u.add->pathname, u.add->perm,
16433 + u.add->path.dentry);
16435 + case Opt_prepend:
16436 + u.add = &opt->add;
16437 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
16438 + u.add->bindex, u.add->pathname, u.add->perm,
16439 + u.add->path.dentry);
16443 + AuDbg("dirwh %d\n", opt->dirwh);
16445 + case Opt_rdcache:
16446 + AuDbg("rdcache %d\n", opt->rdcache);
16449 + AuDbg("rdblk %d\n", opt->rdblk);
16452 + AuDbg("rdhash %u\n", opt->rdhash);
16456 + u.xino = &opt->xino;
16457 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
16460 +#define au_fsctx_TF(name) \
16461 + case Opt_##name: \
16465 + AuLabel(no##name); \
16468 + /* simple true/false flag */
16469 + au_fsctx_TF(trunc_xino);
16470 + au_fsctx_TF(trunc_xib);
16471 + au_fsctx_TF(dirperm1);
16472 + au_fsctx_TF(plink);
16473 + au_fsctx_TF(shwh);
16474 + au_fsctx_TF(dio);
16475 + au_fsctx_TF(warn_perm);
16476 + au_fsctx_TF(verbose);
16477 + au_fsctx_TF(sum);
16478 + au_fsctx_TF(dirren);
16479 + au_fsctx_TF(acl);
16480 +#undef au_fsctx_TF
16482 + case Opt_trunc_xino_path:
16484 + case Opt_itrunc_xino:
16485 + u.xino_itrunc = &opt->xino_itrunc;
16486 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
16492 + case Opt_list_plink:
16493 + AuLabel(list_plink);
16496 + AuDbg("udba %d, %s\n",
16497 + opt->udba, au_optstr_udba(opt->udba));
16499 + case Opt_diropq_a:
16500 + AuLabel(diropq_a);
16502 + case Opt_diropq_w:
16503 + AuLabel(diropq_w);
16508 + case Opt_wbr_create:
16509 + u.create = &opt->wbr_create;
16510 + AuDbg("create %d, %s\n", u.create->wbr_create,
16511 + au_optstr_wbr_create(u.create->wbr_create));
16512 + switch (u.create->wbr_create) {
16513 + case AuWbrCreate_MFSV:
16515 + case AuWbrCreate_PMFSV:
16516 + AuDbg("%d sec\n", u.create->mfs_second);
16518 + case AuWbrCreate_MFSRR:
16520 + case AuWbrCreate_TDMFS:
16521 + AuDbg("%llu watermark\n",
16522 + u.create->mfsrr_watermark);
16524 + case AuWbrCreate_MFSRRV:
16526 + case AuWbrCreate_TDMFSV:
16528 + case AuWbrCreate_PMFSRRV:
16529 + AuDbg("%llu watermark, %d sec\n",
16530 + u.create->mfsrr_watermark,
16531 + u.create->mfs_second);
16535 + case Opt_wbr_copyup:
16536 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
16537 + au_optstr_wbr_copyup(opt->wbr_copyup));
16539 + case Opt_fhsm_sec:
16540 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
16544 + AuDbg("type %d\n", opt->type);
16552 +/* ---------------------------------------------------------------------- */
16555 + * For conditionally compiled mount options.
16556 + * Instead of fsparam_flag_no(), use this macro to distinguish ignore_silent.
16558 +#define au_ignore_flag(name, action) \
16559 + fsparam_flag(name, action), \
16560 + fsparam_flag("no" name, Opt_ignore_silent)
16562 +const struct fs_parameter_spec aufs_fsctx_paramspec[] = {
16563 + fsparam_string("br", Opt_br),
16565 + /* "add=%d:%s" or "ins=%d:%s" */
16566 + fsparam_string("add", Opt_add),
16567 + fsparam_string("ins", Opt_add),
16568 + fsparam_path("append", Opt_append),
16569 + fsparam_path("prepend", Opt_prepend),
16571 + fsparam_path("del", Opt_del),
16572 + /* fsparam_s32("idel", Opt_idel), */
16573 + fsparam_path("mod", Opt_mod),
16574 + /* fsparam_string("imod", Opt_imod), */
16576 + fsparam_s32("dirwh", Opt_dirwh),
16578 + fsparam_path("xino", Opt_xino),
16579 + fsparam_flag("noxino", Opt_noxino),
16580 + fsparam_flag_no("trunc_xino", Opt_trunc_xino),
16581 + /* "trunc_xino_v=%d:%d" */
16582 + /* fsparam_string("trunc_xino_v", Opt_trunc_xino_v), */
16583 + fsparam_path("trunc_xino", Opt_trunc_xino_path),
16584 + fsparam_s32("itrunc_xino", Opt_itrunc_xino),
16585 + /* fsparam_path("zxino", Opt_zxino), */
16586 + fsparam_flag_no("trunc_xib", Opt_trunc_xib),
16588 +#ifdef CONFIG_PROC_FS
16589 + fsparam_flag_no("plink", Opt_plink),
16591 + au_ignore_flag("plink", Opt_ignore),
16594 +#ifdef CONFIG_AUFS_DEBUG
16595 + fsparam_flag("list_plink", Opt_list_plink),
16598 + fsparam_string("udba", Opt_udba),
16600 + fsparam_flag_no("dio", Opt_dio),
16602 +#ifdef CONFIG_AUFS_DIRREN
16603 + fsparam_flag_no("dirren", Opt_dirren),
16605 + au_ignore_flag("dirren", Opt_ignore),
16608 +#ifdef CONFIG_AUFS_FHSM
16609 + fsparam_s32("fhsm_sec", Opt_fhsm_sec),
16611 + fsparam_s32("fhsm_sec", Opt_ignore),
16614 + /* always | a | whiteouted | w */
16615 + fsparam_string("diropq", Opt_diropq),
16617 + fsparam_flag_no("warn_perm", Opt_warn_perm),
16619 +#ifdef CONFIG_AUFS_SHWH
16620 + fsparam_flag_no("shwh", Opt_shwh),
16622 + au_ignore_flag("shwh", Opt_err),
16625 + fsparam_flag_no("dirperm1", Opt_dirperm1),
16627 + fsparam_flag_no("verbose", Opt_verbose),
16628 + fsparam_flag("v", Opt_verbose),
16629 + fsparam_flag("quiet", Opt_noverbose),
16630 + fsparam_flag("q", Opt_noverbose),
16631 + /* user-space may handle this */
16632 + fsparam_flag("silent", Opt_noverbose),
16634 + fsparam_flag_no("sum", Opt_sum),
16635 + fsparam_flag("wsum", Opt_wsum),
16637 + fsparam_s32("rdcache", Opt_rdcache),
16638 + /* "def" or s32 */
16639 + fsparam_string("rdblk", Opt_rdblk),
16640 + /* "def" or s32 */
16641 + fsparam_string("rdhash", Opt_rdhash),
16643 + fsparam_string("create", Opt_wbr_create),
16644 + fsparam_string("create_policy", Opt_wbr_create),
16645 + fsparam_string("cpup", Opt_wbr_copyup),
16646 + fsparam_string("copyup", Opt_wbr_copyup),
16647 + fsparam_string("copyup_policy", Opt_wbr_copyup),
16649 + /* generic VFS flag */
16650 +#ifdef CONFIG_FS_POSIX_ACL
16651 + fsparam_flag_no("acl", Opt_acl),
16653 + au_ignore_flag("acl", Opt_ignore),
16656 + /* internal use for the scripts */
16657 + fsparam_string("si", Opt_ignore_silent),
16659 + /* obsoleted, keep them temporary */
16660 + fsparam_flag("nodlgt", Opt_ignore_silent),
16661 + fsparam_flag("clean_plink", Opt_ignore),
16662 + fsparam_string("dirs", Opt_br),
16663 + fsparam_u32("debug", Opt_ignore),
16664 + /* "whiteout" or "all" */
16665 + fsparam_string("delete", Opt_ignore),
16666 + fsparam_string("imap", Opt_ignore),
16668 + /* temporary workaround, due to old mount(8)? */
16669 + fsparam_flag("relatime", Opt_ignore_silent),
16674 +static int au_fsctx_parse_do_add(struct fs_context *fc, struct au_opt *opt,
16675 + char *brspec, size_t speclen,
16676 + aufs_bindex_t bindex)
16681 + AuDbg("brspec %s\n", brspec);
16685 + speclen = strlen(brspec);
16686 + /* will be freed by au_fsctx_free() */
16687 + p = kmemdup_nul(brspec, speclen, GFP_NOFS);
16688 + if (unlikely(!p)) {
16689 + errorfc(fc, "failed in %s", brspec);
16692 + err = au_opt_add(opt, p, fc->sb_flags, bindex);
16699 +static int au_fsctx_parse_br(struct fs_context *fc, char *brspec)
16703 + struct au_fsctx_opts *a = fc->fs_private;
16704 + struct au_opt *opt = a->opt;
16705 + aufs_bindex_t bindex = a->bindex;
16707 + AuDbg("brspec %s\n", brspec);
16710 + while ((p = strsep(&brspec, ":")) && *p) {
16711 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, bindex);
16713 + if (unlikely(err))
16717 + if (unlikely(opt > a->opt_tail)) {
16723 + opt->type = Opt_tail;
16726 + a->bindex = bindex;
16733 +static int au_fsctx_parse_add(struct fs_context *fc, char *addspec)
16737 + struct au_fsctx_opts *a = fc->fs_private;
16738 + struct au_opt *opt = a->opt;
16741 + p = strchr(addspec, ':');
16742 + if (unlikely(!p)) {
16743 + errorfc(fc, "bad arg in %s", addspec);
16747 + err = kstrtoint(addspec, 0, &n);
16748 + if (unlikely(err)) {
16749 + errorfc(fc, "bad integer in %s", addspec);
16752 + AuDbg("n %d\n", n);
16753 + err = au_fsctx_parse_do_add(fc, opt, p, /*len*/0, n);
16760 +static int au_fsctx_parse_del(struct fs_context *fc, struct au_opt_del *del,
16761 + struct fs_parameter *param)
16766 + /* will be freed by au_fsctx_free() */
16767 + del->pathname = kmemdup_nul(param->string, param->size, GFP_NOFS);
16768 + if (unlikely(!del->pathname))
16770 + AuDbg("del %s\n", del->pathname);
16771 + err = vfsub_kern_path(del->pathname, AuOpt_LkupDirFlags, &del->h_path);
16772 + if (unlikely(err))
16773 + errorfc(fc, "lookup failed %s (%d)", del->pathname, err);
16780 +#if 0 /* reserved for future use */
16781 +static int au_fsctx_parse_idel(struct fs_context *fc, struct au_opt_del *del,
16782 + aufs_bindex_t bindex)
16785 + struct super_block *sb;
16786 + struct dentry *root;
16787 + struct au_fsctx_opts *a = fc->fs_private;
16793 + root = sb->s_root;
16794 + aufs_read_lock(root, AuLock_FLUSH);
16795 + if (bindex < 0 || au_sbbot(sb) < bindex) {
16796 + errorfc(fc, "out of bounds, %d", bindex);
16801 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
16802 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
16805 + aufs_read_unlock(root, !AuLock_IR);
16811 +static int au_fsctx_parse_mod(struct fs_context *fc, struct au_opt_mod *mod,
16812 + struct fs_parameter *param)
16815 + struct path path;
16819 + /* will be freed by au_fsctx_free() */
16820 + mod->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16821 + if (unlikely(!mod->path))
16825 + p = strchr(mod->path, '=');
16826 + if (unlikely(!p)) {
16827 + errorfc(fc, "no permission %s", mod->path);
16832 + err = vfsub_kern_path(mod->path, AuOpt_LkupDirFlags, &path);
16833 + if (unlikely(err)) {
16834 + errorfc(fc, "lookup failed %s (%d)", mod->path, err);
16838 + mod->perm = au_br_perm_val(p);
16839 + AuDbg("mod path %s, perm 0x%x, %s", mod->path, mod->perm, p);
16840 + mod->h_root = dget(path.dentry);
16848 +#if 0 /* reserved for future use */
16849 +static int au_fsctx_parse_imod(struct fs_context *fc, struct au_opt_mod *mod,
16854 + struct super_block *sb;
16855 + struct dentry *root;
16856 + struct au_fsctx_opts *a = fc->fs_private;
16862 + p = strchr(ibrspec, ':');
16863 + if (unlikely(!p)) {
16864 + errorfc(fc, "no index, %s", ibrspec);
16868 + err = kstrtoint(ibrspec, 0, &n);
16869 + if (unlikely(err)) {
16870 + errorfc(fc, "bad integer in %s", ibrspec);
16873 + AuDbg("n %d\n", n);
16875 + root = sb->s_root;
16876 + aufs_read_lock(root, AuLock_FLUSH);
16877 + if (n < 0 || au_sbbot(sb) < n) {
16878 + errorfc(fc, "out of bounds, %d", bindex);
16883 + mod->perm = au_br_perm_val(p);
16884 + AuDbg("mod path %s, perm 0x%x, %s\n",
16885 + mod->path, mod->perm, p);
16886 + mod->h_root = dget(au_h_dptr(root, bindex));
16889 + aufs_read_unlock(root, !AuLock_IR);
16896 +static int au_fsctx_parse_xino(struct fs_context *fc,
16897 + struct au_opt_xino *xino,
16898 + struct fs_parameter *param)
16901 + struct au_fsctx_opts *a = fc->fs_private;
16904 + /* will be freed by au_opts_free() */
16905 + xino->path = kmemdup_nul(param->string, param->size, GFP_NOFS);
16906 + if (unlikely(!xino->path))
16908 + AuDbg("path %s\n", xino->path);
16910 + xino->file = au_xino_create(a->sb, xino->path, /*silent*/0,
16912 + err = PTR_ERR(xino->file);
16913 + if (IS_ERR(xino->file)) {
16914 + xino->file = NULL;
16919 + if (unlikely(a->sb && xino->file->f_path.dentry->d_sb == a->sb)) {
16921 + errorfc(fc, "%s must be outside", xino->path);
16930 +int au_fsctx_parse_xino_itrunc_path(struct fs_context *fc,
16931 + struct au_opt_xino_itrunc *xino_itrunc,
16935 + aufs_bindex_t bbot, bindex;
16936 + struct path path;
16937 + struct dentry *root;
16938 + struct au_fsctx_opts *a = fc->fs_private;
16940 + AuDebugOn(!a->sb);
16942 + err = vfsub_kern_path(pathname, AuOpt_LkupDirFlags, &path);
16943 + if (unlikely(err)) {
16944 + errorfc(fc, "lookup failed %s (%d)", pathname, err);
16948 + xino_itrunc->bindex = -1;
16949 + root = a->sb->s_root;
16950 + aufs_read_lock(root, AuLock_FLUSH);
16951 + bbot = au_sbbot(a->sb);
16952 + for (bindex = 0; bindex <= bbot; bindex++) {
16953 + if (au_h_dptr(root, bindex) == path.dentry) {
16954 + xino_itrunc->bindex = bindex;
16958 + aufs_read_unlock(root, !AuLock_IR);
16961 + if (unlikely(xino_itrunc->bindex < 0)) {
16963 + errorfc(fc, "no such branch %s", pathname);
16971 +static int au_fsctx_parse_xino_itrunc(struct fs_context *fc,
16972 + struct au_opt_xino_itrunc *xino_itrunc,
16973 + unsigned int bindex)
16976 + aufs_bindex_t bbot;
16977 + struct super_block *sb;
16978 + struct au_fsctx_opts *a = fc->fs_private;
16984 + si_noflush_read_lock(sb);
16985 + bbot = au_sbbot(sb);
16986 + si_read_unlock(sb);
16987 + if (bindex <= bbot)
16988 + xino_itrunc->bindex = bindex;
16991 + errorfc(fc, "out of bounds, %u", bindex);
16998 +static int au_fsctx_parse_param(struct fs_context *fc, struct fs_parameter *param)
17001 + struct fs_parse_result result;
17002 + struct au_fsctx_opts *a = fc->fs_private;
17003 + struct au_opt *opt = a->opt;
17005 + AuDbg("fc %p, param {key %s, string %s}\n",
17006 + fc, param->key, param->string);
17007 + err = fs_parse(fc, aufs_fsctx_paramspec, param, &result);
17008 + if (unlikely(err < 0))
17011 + AuDbg("token %d, res{negated %d, uint64 %llu}\n",
17012 + token, result.negated, result.uint_64);
17018 + err = au_fsctx_parse_br(fc, param->string);
17021 + err = au_fsctx_parse_add(fc, param->string);
17024 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17025 + /*dummy bindex*/1);
17027 + case Opt_prepend:
17028 + err = au_fsctx_parse_do_add(fc, opt, param->string, param->size,
17033 + err = au_fsctx_parse_del(fc, &opt->del, param);
17035 +#if 0 /* reserved for future use */
17042 + del->pathname = "(indexed)";
17043 + err = au_opts_parse_idel(fc, &opt->del, result.uint_32);
17048 + err = au_fsctx_parse_mod(fc, &opt->mod, param);
17050 +#ifdef IMOD /* reserved for future use */
17057 + u.mod->path = "(indexed)";
17058 + err = au_opts_parse_imod(fc, &opt->mod, param->string);
17063 + err = au_fsctx_parse_xino(fc, &opt->xino, param);
17065 + case Opt_trunc_xino_path:
17067 + errorfc(fc, "no such branch %s", param->string);
17070 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17074 + case Opt_trunc_xino_v:
17080 + err = au_fsctx_parse_xino_itrunc_path(fc, &opt->xino_itrunc,
17084 + case Opt_itrunc_xino:
17086 + errorfc(fc, "out of bounds %s", param->string);
17089 + err = au_fsctx_parse_xino_itrunc(fc, &opt->xino_itrunc,
17095 + opt->dirwh = result.int_32;
17098 + case Opt_rdcache:
17099 + if (unlikely(result.int_32 > AUFS_RDCACHE_MAX)) {
17100 + errorfc(fc, "rdcache must be smaller than %d",
17101 + AUFS_RDCACHE_MAX);
17105 + opt->rdcache = result.int_32;
17110 + opt->rdblk = AUFS_RDBLK_DEF;
17111 + if (!strcmp(param->string, "def"))
17114 + err = kstrtoint(param->string, 0, &result.int_32);
17115 + if (unlikely(err)) {
17116 + errorfc(fc, "bad value in %s", param->key);
17120 + if (unlikely(result.int_32 < 0
17121 + || result.int_32 > KMALLOC_MAX_SIZE)) {
17122 + errorfc(fc, "bad value in %s", param->key);
17125 + if (unlikely(result.int_32 && result.int_32 < NAME_MAX)) {
17126 + errorfc(fc, "rdblk must be larger than %d", NAME_MAX);
17130 + opt->rdblk = result.int_32;
17135 + opt->rdhash = AUFS_RDHASH_DEF;
17136 + if (!strcmp(param->string, "def"))
17139 + err = kstrtoint(param->string, 0, &result.int_32);
17140 + if (unlikely(err)) {
17141 + errorfc(fc, "bad value in %s", param->key);
17144 + /* how about zero? */
17145 + if (result.int_32 < 0
17146 + || result.int_32 * sizeof(struct hlist_head)
17147 + > KMALLOC_MAX_SIZE) {
17149 + errorfc(fc, "bad integer in %s", param->key);
17152 + opt->rdhash = result.int_32;
17157 + * As other options, fs/aufs/opts.c can handle these strings by
17158 + * match_token(). But "diropq=" is deprecated now and will
17159 + * never have other value. So simple strcmp() is enough here.
17161 + if (!strcmp(param->string, "a") ||
17162 + !strcmp(param->string, "always")) {
17164 + opt->type = Opt_diropq_a;
17165 + } else if (!strcmp(param->string, "w") ||
17166 + !strcmp(param->string, "whiteouted")) {
17168 + opt->type = Opt_diropq_w;
17170 + errorfc(fc, "unknown value %s", param->string);
17174 + opt->udba = au_udba_val(param->string);
17175 + if (opt->udba >= 0)
17178 + errorf(fc, "wrong value, %s", param->string);
17181 + case Opt_wbr_create:
17182 + opt->wbr_create.wbr_create
17183 + = au_wbr_create_val(param->string, &opt->wbr_create);
17184 + if (opt->wbr_create.wbr_create >= 0)
17187 + errorf(fc, "wrong value, %s", param->key);
17190 + case Opt_wbr_copyup:
17191 + opt->wbr_copyup = au_wbr_copyup_val(param->string);
17192 + if (opt->wbr_copyup >= 0)
17195 + errorfc(fc, "wrong value, %s", param->key);
17198 + case Opt_fhsm_sec:
17199 + if (unlikely(result.int_32 < 0)) {
17200 + errorfc(fc, "bad integer in %s\n", param->key);
17205 + opt->fhsm_second = result.int_32;
17207 + warnfc(fc, "ignored %s %s", param->key, param->string);
17210 + /* simple true/false flag */
17211 +#define au_fsctx_TF(name) \
17212 + case Opt_##name: \
17214 + opt->tf = !result.negated; \
17216 + au_fsctx_TF(trunc_xino);
17217 + au_fsctx_TF(trunc_xib);
17218 + au_fsctx_TF(dirperm1);
17219 + au_fsctx_TF(plink);
17220 + au_fsctx_TF(shwh);
17221 + au_fsctx_TF(dio);
17222 + au_fsctx_TF(warn_perm);
17223 + au_fsctx_TF(verbose);
17224 + au_fsctx_TF(sum);
17225 + au_fsctx_TF(dirren);
17226 + au_fsctx_TF(acl);
17227 +#undef au_fsctx_TF
17229 + case Opt_noverbose:
17231 + opt->type = Opt_verbose;
17237 + case Opt_list_plink:
17244 + warnfc(fc, "ignored %s", param->key);
17246 + case Opt_ignore_silent:
17255 + if (unlikely(err))
17263 + case Opt_noverbose:
17268 + opt->type = token;
17272 + if (unlikely(opt > a->opt_tail)) {
17276 + opt->type = Opt_tail;
17284 + * these options accept both 'name=val' and 'name:val' form.
17285 + * some accept optional '=' in its value.
17286 + * eg. br:/br1=rw:/br2=ro and br=/br1=rw:/br2=ro
17288 +static inline unsigned int is_colonopt(char *str)
17290 +#define do_test(name) \
17291 + if (!strncmp(str, name ":", sizeof(name))) \
17292 + return sizeof(name) - 1
17296 + do_test("append");
17297 + do_test("prepend");
17299 + /* do_test("idel"); */
17301 + /* do_test("imod"); */
17307 +static int au_fsctx_parse_monolithic(struct fs_context *fc, void *data)
17312 + struct au_fsctx_opts *a = fc->fs_private;
17315 + AuDbg("str %s\n", str);
17317 + u = is_colonopt(str);
17320 + str = strchr(str, ',');
17326 + AuDbg("str %s\n", str);
17328 + err = generic_parse_monolithic(fc, str);
17330 + au_fsctx_dump(&a->opts);
17335 +/* ---------------------------------------------------------------------- */
17337 +static void au_fsctx_opts_free(struct au_opts *opts)
17339 + struct au_opt *opt;
17342 + while (opt->type != Opt_tail) {
17343 + switch (opt->type) {
17348 + case Opt_prepend:
17349 + kfree(opt->add.pathname);
17350 + path_put(&opt->add.path);
17353 + kfree(opt->del.pathname);
17356 + path_put(&opt->del.h_path);
17359 + kfree(opt->mod.path);
17362 + dput(opt->mod.h_root);
17365 + kfree(opt->xino.path);
17366 + fput(opt->xino.file);
17373 +static void au_fsctx_free(struct fs_context *fc)
17375 + struct au_fsctx_opts *a = fc->fs_private;
17377 + /* fs_type=%p, root=%pD */
17378 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17379 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17381 + kobject_put(&a->sbinfo->si_kobj);
17382 + au_fsctx_opts_free(&a->opts);
17383 + free_page((unsigned long)a->opts.opt);
17387 +static const struct fs_context_operations au_fsctx_ops = {
17388 + .free = au_fsctx_free,
17389 + .parse_param = au_fsctx_parse_param,
17390 + .parse_monolithic = au_fsctx_parse_monolithic,
17391 + .get_tree = au_fsctx_get_tree,
17392 + .reconfigure = au_fsctx_reconfigure
17394 + * nfs4 requires ->dup()? No.
17395 + * I don't know what is this ->dup() for.
17399 +int aufs_fsctx_init(struct fs_context *fc)
17402 + struct au_fsctx_opts *a;
17404 + /* fs_type=%p, root=%pD */
17405 + AuDbg("fc %p{sb_flags 0x%x, sb_flags_mask 0x%x, purpose %u\n",
17406 + fc, fc->sb_flags, fc->sb_flags_mask, fc->purpose);
17408 + /* they will be freed by au_fsctx_free() */
17410 + a = kzalloc(sizeof(*a), GFP_NOFS);
17411 + if (unlikely(!a))
17414 + a->opts.opt = (void *)__get_free_page(GFP_NOFS);
17415 + if (unlikely(!a->opts.opt))
17417 + a->opt = a->opts.opt;
17418 + a->opt->type = Opt_tail;
17419 + a->opts.max_opt = PAGE_SIZE / sizeof(*a->opts.opt);
17420 + a->opt_tail = a->opt + a->opts.max_opt - 1;
17421 + a->opts.sb_flags = fc->sb_flags;
17425 + AuDebugOn(fc->purpose != FS_CONTEXT_FOR_RECONFIGURE);
17426 + a->opts.flags = AuOpts_REMOUNT;
17427 + a->sb = fc->root->d_sb;
17428 + a->sbinfo = au_sbi(a->sb);
17429 + kobject_get(&a->sbinfo->si_kobj);
17431 + a->sbinfo = au_si_alloc(a->sb);
17432 + AuDebugOn(!a->sbinfo);
17433 + err = PTR_ERR(a->sbinfo);
17434 + if (IS_ERR(a->sbinfo))
17436 + au_rw_write_unlock(&a->sbinfo->si_rwsem);
17440 + fc->fs_private = a;
17441 + fc->ops = &au_fsctx_ops;
17442 + goto out; /* success */
17445 + free_page((unsigned long)a->opts.opt);
17452 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
17453 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
17454 +++ linux/fs/aufs/fstype.h 2022-11-05 23:02:18.965889284 +0100
17456 +/* SPDX-License-Identifier: GPL-2.0 */
17458 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17460 + * This program is free software; you can redistribute it and/or modify
17461 + * it under the terms of the GNU General Public License as published by
17462 + * the Free Software Foundation; either version 2 of the License, or
17463 + * (at your option) any later version.
17465 + * This program is distributed in the hope that it will be useful,
17466 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17467 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17468 + * GNU General Public License for more details.
17470 + * You should have received a copy of the GNU General Public License
17471 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17475 + * judging filesystem type
17478 +#ifndef __AUFS_FSTYPE_H__
17479 +#define __AUFS_FSTYPE_H__
17483 +#include <linux/fs.h>
17484 +#include <linux/magic.h>
17485 +#include <linux/nfs_fs.h>
17486 +#include <linux/romfs_fs.h>
17488 +static inline int au_test_aufs(struct super_block *sb)
17490 + return sb->s_magic == AUFS_SUPER_MAGIC;
17493 +static inline const char *au_sbtype(struct super_block *sb)
17495 + return sb->s_type->name;
17498 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
17500 +#if IS_ENABLED(CONFIG_ISO9660_FS)
17501 + return sb->s_magic == ISOFS_SUPER_MAGIC;
17507 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
17509 +#if IS_ENABLED(CONFIG_ROMFS_FS)
17510 + return sb->s_magic == ROMFS_MAGIC;
17516 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
17518 +#if IS_ENABLED(CONFIG_CRAMFS)
17519 + return sb->s_magic == CRAMFS_MAGIC;
17524 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
17526 +#if IS_ENABLED(CONFIG_NFS_FS)
17527 + return sb->s_magic == NFS_SUPER_MAGIC;
17533 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
17535 +#if IS_ENABLED(CONFIG_FUSE_FS)
17536 + return sb->s_magic == FUSE_SUPER_MAGIC;
17542 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
17544 +#if IS_ENABLED(CONFIG_XFS_FS)
17545 + return sb->s_magic == XFS_SB_MAGIC;
17551 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
17553 +#ifdef CONFIG_TMPFS
17554 + return sb->s_magic == TMPFS_MAGIC;
17560 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
17562 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
17563 + return !strcmp(au_sbtype(sb), "ecryptfs");
17569 +static inline int au_test_ramfs(struct super_block *sb)
17571 + return sb->s_magic == RAMFS_MAGIC;
17574 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
17576 +#if IS_ENABLED(CONFIG_UBIFS_FS)
17577 + return sb->s_magic == UBIFS_SUPER_MAGIC;
17583 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
17585 +#ifdef CONFIG_PROC_FS
17586 + return sb->s_magic == PROC_SUPER_MAGIC;
17592 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
17594 +#ifdef CONFIG_SYSFS
17595 + return sb->s_magic == SYSFS_MAGIC;
17601 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
17603 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
17604 + return sb->s_magic == CONFIGFS_MAGIC;
17610 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
17612 +#if IS_ENABLED(CONFIG_MINIX_FS)
17613 + return sb->s_magic == MINIX3_SUPER_MAGIC
17614 + || sb->s_magic == MINIX2_SUPER_MAGIC
17615 + || sb->s_magic == MINIX2_SUPER_MAGIC2
17616 + || sb->s_magic == MINIX_SUPER_MAGIC
17617 + || sb->s_magic == MINIX_SUPER_MAGIC2;
17623 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
17625 +#if IS_ENABLED(CONFIG_FAT_FS)
17626 + return sb->s_magic == MSDOS_SUPER_MAGIC;
17632 +static inline int au_test_msdos(struct super_block *sb)
17634 + return au_test_fat(sb);
17637 +static inline int au_test_vfat(struct super_block *sb)
17639 + return au_test_fat(sb);
17642 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
17644 +#ifdef CONFIG_SECURITYFS
17645 + return sb->s_magic == SECURITYFS_MAGIC;
17651 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
17653 +#if IS_ENABLED(CONFIG_SQUASHFS)
17654 + return sb->s_magic == SQUASHFS_MAGIC;
17660 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
17662 +#if IS_ENABLED(CONFIG_BTRFS_FS)
17663 + return sb->s_magic == BTRFS_SUPER_MAGIC;
17669 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
17671 +#if IS_ENABLED(CONFIG_XENFS)
17672 + return sb->s_magic == XENFS_SUPER_MAGIC;
17678 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
17680 +#ifdef CONFIG_DEBUG_FS
17681 + return sb->s_magic == DEBUGFS_MAGIC;
17687 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
17689 +#if IS_ENABLED(CONFIG_NILFS)
17690 + return sb->s_magic == NILFS_SUPER_MAGIC;
17696 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
17698 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
17699 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
17705 +/* ---------------------------------------------------------------------- */
17707 + * they can't be an aufs branch.
17709 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
17712 +#ifndef CONFIG_AUFS_BR_RAMFS
17713 + au_test_ramfs(sb) ||
17715 + au_test_procfs(sb)
17716 + || au_test_sysfs(sb)
17717 + || au_test_configfs(sb)
17718 + || au_test_debugfs(sb)
17719 + || au_test_securityfs(sb)
17720 + || au_test_xenfs(sb)
17721 + || au_test_ecryptfs(sb)
17722 + /* || !strcmp(au_sbtype(sb), "unionfs") */
17723 + || au_test_aufs(sb); /* will be supported in next version */
17726 +static inline int au_test_fs_remote(struct super_block *sb)
17728 + return !au_test_tmpfs(sb)
17729 +#ifdef CONFIG_AUFS_BR_RAMFS
17730 + && !au_test_ramfs(sb)
17732 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
17735 +/* ---------------------------------------------------------------------- */
17738 + * Note: these functions (below) are created after reading ->getattr() in all
17739 + * filesystems under linux/fs. it means we have to do so in every update...
17743 + * some filesystems require getattr to refresh the inode attributes before
17745 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
17746 + * and leave the work for d_revalidate()
17748 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
17750 + return au_test_nfs(sb)
17751 + || au_test_fuse(sb)
17752 + /* || au_test_btrfs(sb) */ /* untested */
17757 + * filesystems which don't maintain i_size or i_blocks.
17759 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
17761 + return au_test_xfs(sb)
17762 + || au_test_btrfs(sb)
17763 + || au_test_ubifs(sb)
17764 + || au_test_hfsplus(sb) /* maintained, but incorrect */
17765 + /* || au_test_minix(sb) */ /* untested */
17770 + * filesystems which don't store the correct value in some of their inode
17773 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
17775 + return au_test_fs_bad_iattr_size(sb)
17776 + || au_test_fat(sb)
17777 + || au_test_msdos(sb)
17778 + || au_test_vfat(sb);
17781 +/* they don't check i_nlink in link(2) */
17782 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
17784 + return au_test_tmpfs(sb)
17785 +#ifdef CONFIG_AUFS_BR_RAMFS
17786 + || au_test_ramfs(sb)
17788 + || au_test_ubifs(sb)
17789 + || au_test_hfsplus(sb);
17793 + * filesystems which sets S_NOATIME and S_NOCMTIME.
17795 +static inline int au_test_fs_notime(struct super_block *sb)
17797 + return au_test_nfs(sb)
17798 + || au_test_fuse(sb)
17799 + || au_test_ubifs(sb)
17803 +/* temporary support for i#1 in cramfs */
17804 +static inline int au_test_fs_unique_ino(struct inode *inode)
17806 + if (au_test_cramfs(inode->i_sb))
17807 + return inode->i_ino != 1;
17811 +/* ---------------------------------------------------------------------- */
17814 + * the filesystem where the xino files placed must support i/o after unlink and
17815 + * maintain i_size and i_blocks.
17817 +static inline int au_test_fs_bad_xino(struct super_block *sb)
17819 + return au_test_fs_remote(sb)
17820 + || au_test_fs_bad_iattr_size(sb)
17821 + /* don't want unnecessary work for xino */
17822 + || au_test_aufs(sb)
17823 + || au_test_ecryptfs(sb)
17824 + || au_test_nilfs(sb);
17827 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
17829 + return au_test_tmpfs(sb)
17830 + || au_test_ramfs(sb);
17834 + * test if the @sb is real-readonly.
17836 +static inline int au_test_fs_rr(struct super_block *sb)
17838 + return au_test_squashfs(sb)
17839 + || au_test_iso9660(sb)
17840 + || au_test_cramfs(sb)
17841 + || au_test_romfs(sb);
17845 + * test if the @inode is nfs with 'noacl' option
17846 + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.'
17848 +static inline int au_test_nfs_noacl(struct inode *inode)
17850 + return au_test_nfs(inode->i_sb)
17851 + /* && IS_POSIXACL(inode) */
17852 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
17855 +#endif /* __KERNEL__ */
17856 +#endif /* __AUFS_FSTYPE_H__ */
17857 diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h
17858 --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100
17859 +++ linux/fs/aufs/hbl.h 2022-11-05 23:02:18.965889284 +0100
17861 +/* SPDX-License-Identifier: GPL-2.0 */
17863 + * Copyright (C) 2017-2022 Junjiro R. Okajima
17865 + * This program is free software; you can redistribute it and/or modify
17866 + * it under the terms of the GNU General Public License as published by
17867 + * the Free Software Foundation; either version 2 of the License, or
17868 + * (at your option) any later version.
17870 + * This program is distributed in the hope that it will be useful,
17871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17873 + * GNU General Public License for more details.
17875 + * You should have received a copy of the GNU General Public License
17876 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17880 + * helpers for hlist_bl.h
17883 +#ifndef __AUFS_HBL_H__
17884 +#define __AUFS_HBL_H__
17888 +#include <linux/list_bl.h>
17890 +static inline void au_hbl_add(struct hlist_bl_node *node,
17891 + struct hlist_bl_head *hbl)
17893 + hlist_bl_lock(hbl);
17894 + hlist_bl_add_head(node, hbl);
17895 + hlist_bl_unlock(hbl);
17898 +static inline void au_hbl_del(struct hlist_bl_node *node,
17899 + struct hlist_bl_head *hbl)
17901 + hlist_bl_lock(hbl);
17902 + hlist_bl_del(node);
17903 + hlist_bl_unlock(hbl);
17906 +#define au_hbl_for_each(pos, head) \
17907 + for (pos = hlist_bl_first(head); \
17911 +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl)
17913 + unsigned long cnt;
17914 + struct hlist_bl_node *pos;
17917 + hlist_bl_lock(hbl);
17918 + au_hbl_for_each(pos, hbl)
17920 + hlist_bl_unlock(hbl);
17924 +#endif /* __KERNEL__ */
17925 +#endif /* __AUFS_HBL_H__ */
17926 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
17927 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
17928 +++ linux/fs/aufs/hfsnotify.c 2022-11-05 23:02:18.965889284 +0100
17930 +// SPDX-License-Identifier: GPL-2.0
17932 + * Copyright (C) 2005-2022 Junjiro R. Okajima
17934 + * This program is free software; you can redistribute it and/or modify
17935 + * it under the terms of the GNU General Public License as published by
17936 + * the Free Software Foundation; either version 2 of the License, or
17937 + * (at your option) any later version.
17939 + * This program is distributed in the hope that it will be useful,
17940 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17941 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17942 + * GNU General Public License for more details.
17944 + * You should have received a copy of the GNU General Public License
17945 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17949 + * fsnotify for the lower directories
17954 +/* FS_IN_IGNORED is unnecessary */
17955 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
17956 + | FS_CREATE | FS_EVENT_ON_CHILD);
17957 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
17958 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
17960 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
17962 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
17964 + /* AuDbg("here\n"); */
17965 + au_cache_free_hnotify(hn);
17966 + smp_mb__before_atomic(); /* for atomic64_dec */
17967 + if (atomic64_dec_and_test(&au_hfsn_ifree))
17968 + wake_up(&au_hfsn_wq);
17971 +static int au_hfsn_alloc(struct au_hinode *hinode)
17974 + struct au_hnotify *hn;
17975 + struct super_block *sb;
17976 + struct au_branch *br;
17977 + struct fsnotify_mark *mark;
17978 + aufs_bindex_t bindex;
17980 + hn = hinode->hi_notify;
17981 + sb = hn->hn_aufs_inode->i_sb;
17982 + bindex = au_br_index(sb, hinode->hi_id);
17983 + br = au_sbr(sb, bindex);
17984 + AuDebugOn(!br->br_hfsn);
17986 + mark = &hn->hn_mark;
17987 + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group);
17988 + mark->mask = AuHfsnMask;
17990 + * by udba rename or rmdir, aufs assign a new inode to the known
17991 + * h_inode, so specify 1 to allow dups.
17994 + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1);
18000 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
18002 + struct fsnotify_mark *mark;
18003 + unsigned long long ull;
18004 + struct fsnotify_group *group;
18006 + ull = atomic64_inc_return(&au_hfsn_ifree);
18009 + mark = &hn->hn_mark;
18010 + spin_lock(&mark->lock);
18011 + group = mark->group;
18012 + fsnotify_get_group(group);
18013 + spin_unlock(&mark->lock);
18015 + fsnotify_destroy_mark(mark, group);
18016 + fsnotify_put_mark(mark);
18017 + fsnotify_put_group(group);
18020 + /* free hn by myself */
18024 +/* ---------------------------------------------------------------------- */
18026 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
18028 + struct fsnotify_mark *mark;
18030 + mark = &hinode->hi_notify->hn_mark;
18031 + spin_lock(&mark->lock);
18033 + AuDebugOn(mark->mask & AuHfsnMask);
18034 + mark->mask |= AuHfsnMask;
18036 + AuDebugOn(!(mark->mask & AuHfsnMask));
18037 + mark->mask &= ~AuHfsnMask;
18039 + spin_unlock(&mark->lock);
18040 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
18043 +/* ---------------------------------------------------------------------- */
18045 +/* #define AuDbgHnotify */
18046 +#ifdef AuDbgHnotify
18047 +static char *au_hfsn_name(u32 mask)
18049 +#ifdef CONFIG_AUFS_DEBUG
18050 +#define test_ret(flag) \
18052 + if (mask & flag) \
18055 + test_ret(FS_ACCESS);
18056 + test_ret(FS_MODIFY);
18057 + test_ret(FS_ATTRIB);
18058 + test_ret(FS_CLOSE_WRITE);
18059 + test_ret(FS_CLOSE_NOWRITE);
18060 + test_ret(FS_OPEN);
18061 + test_ret(FS_MOVED_FROM);
18062 + test_ret(FS_MOVED_TO);
18063 + test_ret(FS_CREATE);
18064 + test_ret(FS_DELETE);
18065 + test_ret(FS_DELETE_SELF);
18066 + test_ret(FS_MOVE_SELF);
18067 + test_ret(FS_UNMOUNT);
18068 + test_ret(FS_Q_OVERFLOW);
18069 + test_ret(FS_IN_IGNORED);
18070 + test_ret(FS_ISDIR);
18071 + test_ret(FS_IN_ONESHOT);
18072 + test_ret(FS_EVENT_ON_CHILD);
18081 +/* ---------------------------------------------------------------------- */
18083 +static void au_hfsn_free_group(struct fsnotify_group *group)
18085 + struct au_br_hfsnotify *hfsn = group->private;
18087 + /* AuDbg("here\n"); */
18088 + au_kfree_try_rcu(hfsn);
18091 +static int au_hfsn_handle_event(struct fsnotify_group *group,
18092 + u32 mask, const void *data, int data_type,
18093 + struct inode *dir,
18094 + const struct qstr *file_name, u32 cookie,
18095 + struct fsnotify_iter_info *iter_info)
18098 + struct au_hnotify *hnotify;
18099 + struct inode *h_dir, *h_inode;
18100 + struct fsnotify_mark *inode_mark;
18102 + AuDebugOn(!(data_type == FSNOTIFY_EVENT_INODE
18103 + || data_type == FSNOTIFY_EVENT_DENTRY));
18106 + /* if FS_UNMOUNT happens, there must be another bug */
18107 + AuDebugOn(mask & FS_UNMOUNT);
18108 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
18113 +#ifdef AuDbgHnotify
18115 + if (1 || file_name.len != sizeof(AUFS_XINO_FNAME) - 1
18116 + || strncmp(file_name.name, AUFS_XINO_FNAME, file_name.len)) {
18117 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
18118 + h_dir->i_ino, mask, au_hfsn_name(mask),
18119 + AuLNPair(file_name), h_inode ? h_inode->i_ino : 0);
18120 + /* WARN_ON(1); */
18125 + inode_mark = fsnotify_iter_inode_mark(iter_info);
18126 + AuDebugOn(!inode_mark);
18127 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
18128 + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode);
18134 +static struct fsnotify_ops au_hfsn_ops = {
18135 + .handle_event = au_hfsn_handle_event,
18136 + .free_group_priv = au_hfsn_free_group,
18137 + .free_mark = au_hfsn_free_mark
18140 +/* ---------------------------------------------------------------------- */
18142 +static void au_hfsn_fin_br(struct au_branch *br)
18144 + struct au_br_hfsnotify *hfsn;
18146 + hfsn = br->br_hfsn;
18149 + fsnotify_put_group(hfsn->hfsn_group);
18154 +static int au_hfsn_init_br(struct au_branch *br, int perm)
18157 + struct fsnotify_group *group;
18158 + struct au_br_hfsnotify *hfsn;
18161 + br->br_hfsn = NULL;
18162 + if (!au_br_hnotifyable(perm))
18166 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
18167 + if (unlikely(!hfsn))
18171 + group = fsnotify_alloc_group(&au_hfsn_ops,
18172 + /*flags - not for userspace*/0);
18173 + if (IS_ERR(group)) {
18174 + err = PTR_ERR(group);
18175 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
18179 + group->private = hfsn;
18180 + hfsn->hfsn_group = group;
18181 + br->br_hfsn = hfsn;
18182 + goto out; /* success */
18185 + au_kfree_try_rcu(hfsn);
18190 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
18195 + if (!br->br_hfsn)
18196 + err = au_hfsn_init_br(br, perm);
18201 +/* ---------------------------------------------------------------------- */
18203 +static void au_hfsn_fin(void)
18205 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
18206 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
18209 +const struct au_hnotify_op au_hnotify_op = {
18210 + .ctl = au_hfsn_ctl,
18211 + .alloc = au_hfsn_alloc,
18212 + .free = au_hfsn_free,
18214 + .fin = au_hfsn_fin,
18216 + .reset_br = au_hfsn_reset_br,
18217 + .fin_br = au_hfsn_fin_br,
18218 + .init_br = au_hfsn_init_br
18220 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
18221 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
18222 +++ linux/fs/aufs/hfsplus.c 2022-11-05 23:02:18.965889284 +0100
18224 +// SPDX-License-Identifier: GPL-2.0
18226 + * Copyright (C) 2010-2022 Junjiro R. Okajima
18228 + * This program is free software; you can redistribute it and/or modify
18229 + * it under the terms of the GNU General Public License as published by
18230 + * the Free Software Foundation; either version 2 of the License, or
18231 + * (at your option) any later version.
18233 + * This program is distributed in the hope that it will be useful,
18234 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18235 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18236 + * GNU General Public License for more details.
18238 + * You should have received a copy of the GNU General Public License
18239 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18243 + * special support for filesystems which acquires an inode mutex
18244 + * at final closing a file, eg, hfsplus.
18246 + * This trick is very simple and stupid, just to open the file before really
18247 + * necessary open to tell hfsplus that this is not the final closing.
18248 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
18249 + * and au_h_open_post() after releasing it.
18254 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
18257 + struct file *h_file;
18258 + struct dentry *h_dentry;
18260 + h_dentry = au_h_dptr(dentry, bindex);
18261 + AuDebugOn(!h_dentry);
18262 + AuDebugOn(d_is_negative(h_dentry));
18265 + if (au_test_hfsplus(h_dentry->d_sb)
18266 + && d_is_reg(h_dentry))
18267 + h_file = au_h_open(dentry, bindex,
18268 + O_RDONLY | O_NOATIME | O_LARGEFILE,
18269 + /*file*/NULL, force_wr);
18273 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
18274 + struct file *h_file)
18276 + struct au_branch *br;
18280 + br = au_sbr(dentry->d_sb, bindex);
18281 + au_lcnt_dec(&br->br_nfiles);
18284 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
18285 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
18286 +++ linux/fs/aufs/hnotify.c 2022-11-05 23:02:18.965889284 +0100
18288 +// SPDX-License-Identifier: GPL-2.0
18290 + * Copyright (C) 2005-2022 Junjiro R. Okajima
18292 + * This program is free software; you can redistribute it and/or modify
18293 + * it under the terms of the GNU General Public License as published by
18294 + * the Free Software Foundation; either version 2 of the License, or
18295 + * (at your option) any later version.
18297 + * This program is distributed in the hope that it will be useful,
18298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18300 + * GNU General Public License for more details.
18302 + * You should have received a copy of the GNU General Public License
18303 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18307 + * abstraction to notify the direct changes on lower directories
18310 +/* #include <linux/iversion.h> */
18313 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
18316 + struct au_hnotify *hn;
18319 + hn = au_cache_alloc_hnotify();
18321 + hn->hn_aufs_inode = inode;
18322 + hinode->hi_notify = hn;
18323 + err = au_hnotify_op.alloc(hinode);
18325 + if (unlikely(err)) {
18326 + hinode->hi_notify = NULL;
18327 + au_cache_free_hnotify(hn);
18329 + * The upper dir was removed by udba, but the same named
18330 + * dir left. In this case, aufs assigns a new inode
18331 + * number and set the monitor again.
18332 + * For the lower dir, the old monitor is still left.
18334 + if (err == -EEXIST)
18343 +void au_hn_free(struct au_hinode *hinode)
18345 + struct au_hnotify *hn;
18347 + hn = hinode->hi_notify;
18349 + hinode->hi_notify = NULL;
18350 + if (au_hnotify_op.free(hinode, hn))
18351 + au_cache_free_hnotify(hn);
18355 +/* ---------------------------------------------------------------------- */
18357 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
18359 + if (hinode->hi_notify)
18360 + au_hnotify_op.ctl(hinode, do_set);
18363 +void au_hn_reset(struct inode *inode, unsigned int flags)
18365 + aufs_bindex_t bindex, bbot;
18366 + struct inode *hi;
18367 + struct dentry *iwhdentry;
18369 + bbot = au_ibbot(inode);
18370 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
18371 + hi = au_h_iptr(inode, bindex);
18375 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
18376 + iwhdentry = au_hi_wh(inode, bindex);
18380 + au_set_h_iptr(inode, bindex, NULL, 0);
18381 + au_set_h_iptr(inode, bindex, au_igrab(hi),
18382 + flags & ~AuHi_XINO);
18385 + /* inode_unlock(hi); */
18389 +/* ---------------------------------------------------------------------- */
18391 +static int hn_xino(struct inode *inode, struct inode *h_inode)
18394 + aufs_bindex_t bindex, bbot, bfound, btop;
18395 + struct inode *h_i;
18398 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18399 + pr_warn("branch root dir was changed\n");
18404 + bbot = au_ibbot(inode);
18405 + btop = au_ibtop(inode);
18406 +#if 0 /* reserved for future use */
18407 + if (bindex == bbot) {
18408 + /* keep this ino in rename case */
18412 + for (bindex = btop; bindex <= bbot; bindex++)
18413 + if (au_h_iptr(inode, bindex) == h_inode) {
18420 + for (bindex = btop; bindex <= bbot; bindex++) {
18421 + h_i = au_h_iptr(inode, bindex);
18425 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
18426 + /* ignore this error */
18427 + /* bad action? */
18430 + /* children inode number will be broken */
18437 +static int hn_gen_tree(struct dentry *dentry)
18439 + int err, i, j, ndentry;
18440 + struct au_dcsub_pages dpages;
18441 + struct au_dpage *dpage;
18442 + struct dentry **dentries;
18444 + err = au_dpages_init(&dpages, GFP_NOFS);
18445 + if (unlikely(err))
18447 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
18448 + if (unlikely(err))
18451 + for (i = 0; i < dpages.ndpage; i++) {
18452 + dpage = dpages.dpages + i;
18453 + dentries = dpage->dentries;
18454 + ndentry = dpage->ndentry;
18455 + for (j = 0; j < ndentry; j++) {
18456 + struct dentry *d;
18463 + if (d_really_is_positive(d))
18464 + /* todo: reset children xino?
18465 + cached children only? */
18466 + au_iigen_dec(d_inode(d));
18471 + au_dpages_free(&dpages);
18477 + * return 0 if processed.
18479 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
18480 + const unsigned int isdir)
18483 + struct dentry *d;
18484 + struct qstr *dname;
18487 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18488 + pr_warn("branch root dir was changed\n");
18494 + AuDebugOn(!name);
18495 + au_iigen_dec(inode);
18496 + spin_lock(&inode->i_lock);
18497 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
18498 + spin_lock(&d->d_lock);
18499 + dname = &d->d_name;
18500 + if (dname->len != nlen
18501 + && memcmp(dname->name, name, nlen)) {
18502 + spin_unlock(&d->d_lock);
18507 + spin_unlock(&d->d_lock);
18510 + spin_unlock(&inode->i_lock);
18512 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
18513 + d = d_find_any_alias(inode);
18515 + au_iigen_dec(inode);
18519 + spin_lock(&d->d_lock);
18520 + dname = &d->d_name;
18521 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
18522 + spin_unlock(&d->d_lock);
18523 + err = hn_gen_tree(d);
18524 + spin_lock(&d->d_lock);
18526 + spin_unlock(&d->d_lock);
18535 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
18539 + if (IS_ROOT(dentry)) {
18540 + pr_warn("branch root dir was changed\n");
18546 + au_digen_dec(dentry);
18547 + if (d_really_is_positive(dentry))
18548 + au_iigen_dec(d_inode(dentry));
18550 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
18551 + if (d_really_is_positive(dentry))
18552 + err = hn_gen_tree(dentry);
18559 +/* ---------------------------------------------------------------------- */
18561 +/* hnotify job flags */
18562 +#define AuHnJob_XINO0 1
18563 +#define AuHnJob_GEN (1 << 1)
18564 +#define AuHnJob_DIRENT (1 << 2)
18565 +#define AuHnJob_ISDIR (1 << 3)
18566 +#define AuHnJob_TRYXINO0 (1 << 4)
18567 +#define AuHnJob_MNTPNT (1 << 5)
18568 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
18569 +#define au_fset_hnjob(flags, name) \
18570 + do { (flags) |= AuHnJob_##name; } while (0)
18571 +#define au_fclr_hnjob(flags, name) \
18572 + do { (flags) &= ~AuHnJob_##name; } while (0)
18580 +struct au_hnotify_args {
18581 + struct inode *h_dir, *dir, *h_child_inode;
18583 + unsigned int flags[AuHnLast];
18584 + unsigned int h_child_nlen;
18585 + char h_child_name[];
18588 +struct hn_job_args {
18589 + unsigned int flags;
18590 + struct inode *inode, *h_inode, *dir, *h_dir;
18591 + struct dentry *dentry;
18596 +static int hn_job(struct hn_job_args *a)
18598 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
18602 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
18603 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18605 + if (au_ftest_hnjob(a->flags, TRYXINO0)
18608 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
18609 + if (!a->h_inode->i_nlink
18610 + && !(a->h_inode->i_state & I_LINKABLE))
18611 + hn_xino(a->inode, a->h_inode); /* ignore this error */
18612 + inode_unlock_shared(a->h_inode);
18615 + /* make the generation obsolete */
18616 + if (au_ftest_hnjob(a->flags, GEN)) {
18619 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
18621 + if (e && a->dentry)
18622 + hn_gen_by_name(a->dentry, isdir);
18623 + /* ignore this error */
18626 + /* make dir entries obsolete */
18627 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
18628 + struct au_vdir *vdir;
18630 + vdir = au_ivdir(a->inode);
18632 + vdir->vd_jiffy = 0;
18633 + /* IMustLock(a->inode); */
18634 + /* inode_inc_iversion(a->inode); */
18637 + /* can do nothing but warn */
18638 + if (au_ftest_hnjob(a->flags, MNTPNT)
18640 + && d_mountpoint(a->dentry))
18641 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
18646 +/* ---------------------------------------------------------------------- */
18648 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
18649 + struct inode *dir)
18651 + struct dentry *dentry, *d, *parent;
18652 + struct qstr *dname;
18654 + parent = d_find_any_alias(dir);
18659 + spin_lock(&parent->d_lock);
18660 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
18661 + /* AuDbg("%pd\n", d); */
18662 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
18663 + dname = &d->d_name;
18664 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
18665 + goto cont_unlock;
18669 + goto cont_unlock;
18670 + if (au_dcount(d) > 0) {
18671 + dentry = dget_dlock(d);
18672 + spin_unlock(&d->d_lock);
18677 + spin_unlock(&d->d_lock);
18679 + spin_unlock(&parent->d_lock);
18683 + di_write_lock_child(dentry);
18688 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
18689 + aufs_bindex_t bindex, ino_t h_ino)
18691 + struct inode *inode;
18696 + err = au_xino_read(sb, bindex, h_ino, &ino);
18698 + inode = ilookup(sb, ino);
18702 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
18703 + pr_warn("wrong root branch\n");
18709 + ii_write_lock_child(inode);
18715 +static void au_hn_bh(void *_args)
18717 + struct au_hnotify_args *a = _args;
18718 + struct super_block *sb;
18719 + aufs_bindex_t bindex, bbot, bfound;
18720 + unsigned char xino, try_iput;
18722 + struct inode *inode;
18724 + struct hn_job_args args;
18725 + struct dentry *dentry;
18726 + struct au_sbinfo *sbinfo;
18728 + AuDebugOn(!_args);
18729 + AuDebugOn(!a->h_dir);
18730 + AuDebugOn(!a->dir);
18731 + AuDebugOn(!a->mask);
18732 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
18733 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
18734 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
18739 + * do not lock a->dir->i_mutex here
18740 + * because of d_revalidate() may cause a deadlock.
18742 + sb = a->dir->i_sb;
18744 + sbinfo = au_sbi(sb);
18745 + AuDebugOn(!sbinfo);
18746 + si_write_lock(sb, AuLock_NOPLMW);
18748 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
18749 + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) {
18750 + case FS_MOVED_FROM:
18751 + case FS_MOVED_TO:
18752 + AuWarn1("DIRREN with UDBA may not work correctly "
18753 + "for the direct rename(2)\n");
18756 + ii_read_lock_parent(a->dir);
18758 + bbot = au_ibbot(a->dir);
18759 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
18760 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
18764 + ii_read_unlock(a->dir);
18765 + if (unlikely(bfound < 0))
18768 + xino = !!au_opt_test(au_mntflags(sb), XINO);
18770 + if (a->h_child_inode)
18771 + h_ino = a->h_child_inode->i_ino;
18773 + if (a->h_child_nlen
18774 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
18775 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
18776 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
18779 + if (dentry && d_really_is_positive(dentry))
18780 + inode = d_inode(dentry);
18781 + if (xino && !inode && h_ino
18782 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
18783 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
18784 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
18785 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
18789 + args.flags = a->flags[AuHn_CHILD];
18790 + args.dentry = dentry;
18791 + args.inode = inode;
18792 + args.h_inode = a->h_child_inode;
18793 + args.dir = a->dir;
18794 + args.h_dir = a->h_dir;
18795 + args.h_name = a->h_child_name;
18796 + args.h_nlen = a->h_child_nlen;
18797 + err = hn_job(&args);
18799 + if (au_di(dentry))
18800 + di_write_unlock(dentry);
18803 + if (inode && try_iput) {
18804 + ii_write_unlock(inode);
18808 + ii_write_lock_parent(a->dir);
18809 + args.flags = a->flags[AuHn_PARENT];
18810 + args.dentry = NULL;
18811 + args.inode = a->dir;
18812 + args.h_inode = a->h_dir;
18814 + args.h_dir = NULL;
18815 + args.h_name = NULL;
18817 + err = hn_job(&args);
18818 + ii_write_unlock(a->dir);
18821 + iput(a->h_child_inode);
18824 + si_write_unlock(sb);
18825 + au_nwt_done(&sbinfo->si_nowait);
18829 +/* ---------------------------------------------------------------------- */
18831 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
18832 + const struct qstr *h_child_qstr, struct inode *h_child_inode)
18835 + unsigned int flags[AuHnLast], f;
18836 + unsigned char isdir, isroot, wh;
18837 + struct inode *dir;
18838 + struct au_hnotify_args *args;
18839 + char *p, *h_child_name;
18842 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
18843 + dir = igrab(hnotify->hn_aufs_inode);
18847 + isroot = (dir->i_ino == AUFS_ROOT_INO);
18849 + h_child_name = (void *)h_child_qstr->name;
18850 + len = h_child_qstr->len;
18851 + if (h_child_name) {
18852 + if (len > AUFS_WH_PFX_LEN
18853 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
18854 + h_child_name += AUFS_WH_PFX_LEN;
18855 + len -= AUFS_WH_PFX_LEN;
18861 + if (h_child_inode)
18862 + isdir = !!S_ISDIR(h_child_inode->i_mode);
18863 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
18864 + flags[AuHn_CHILD] = 0;
18866 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
18867 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
18868 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
18869 + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) {
18870 + case FS_MOVED_FROM:
18871 + case FS_MOVED_TO:
18872 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
18873 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18876 + AuDebugOn(!h_child_name);
18881 + * aufs never be able to get this child inode.
18882 + * revalidation should be in d_revalidate()
18883 + * by checking i_nlink, i_generation or d_unhashed().
18885 + AuDebugOn(!h_child_name);
18886 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
18887 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
18895 + h_child_inode = NULL;
18898 + /* iput() and kfree() will be called in au_hnotify() */
18899 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
18900 + if (unlikely(!args)) {
18901 + AuErr1("no memory\n");
18905 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
18906 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
18907 + args->mask = mask;
18909 + args->h_dir = igrab(h_dir);
18910 + if (h_child_inode)
18911 + h_child_inode = igrab(h_child_inode); /* can be NULL */
18912 + args->h_child_inode = h_child_inode;
18913 + args->h_child_nlen = len;
18915 + p = (void *)args;
18916 + p += sizeof(*args);
18917 + memcpy(p, h_child_name, len);
18921 + /* NFS fires the event for silly-renamed one from kworker */
18923 + if (!dir->i_nlink
18924 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
18926 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
18927 + if (unlikely(err)) {
18928 + pr_err("wkq %d\n", err);
18929 + iput(args->h_child_inode);
18930 + iput(args->h_dir);
18932 + au_kfree_rcu(args);
18939 +/* ---------------------------------------------------------------------- */
18941 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
18945 + AuDebugOn(!(udba & AuOptMask_UDBA));
18948 + if (au_hnotify_op.reset_br)
18949 + err = au_hnotify_op.reset_br(udba, br, perm);
18954 +int au_hnotify_init_br(struct au_branch *br, int perm)
18959 + if (au_hnotify_op.init_br)
18960 + err = au_hnotify_op.init_br(br, perm);
18965 +void au_hnotify_fin_br(struct au_branch *br)
18967 + if (au_hnotify_op.fin_br)
18968 + au_hnotify_op.fin_br(br);
18971 +static void au_hn_destroy_cache(void)
18973 + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]);
18974 + au_cache[AuCache_HNOTIFY] = NULL;
18977 +int __init au_hnotify_init(void)
18982 + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify);
18983 + if (au_cache[AuCache_HNOTIFY]) {
18985 + if (au_hnotify_op.init)
18986 + err = au_hnotify_op.init();
18987 + if (unlikely(err))
18988 + au_hn_destroy_cache();
18994 +void au_hnotify_fin(void)
18996 + if (au_hnotify_op.fin)
18997 + au_hnotify_op.fin();
18999 + /* cf. au_cache_fin() */
19000 + if (au_cache[AuCache_HNOTIFY])
19001 + au_hn_destroy_cache();
19003 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
19004 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
19005 +++ linux/fs/aufs/iinfo.c 2022-11-05 23:02:18.965889284 +0100
19007 +// SPDX-License-Identifier: GPL-2.0
19009 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19011 + * This program is free software; you can redistribute it and/or modify
19012 + * it under the terms of the GNU General Public License as published by
19013 + * the Free Software Foundation; either version 2 of the License, or
19014 + * (at your option) any later version.
19016 + * This program is distributed in the hope that it will be useful,
19017 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19018 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19019 + * GNU General Public License for more details.
19021 + * You should have received a copy of the GNU General Public License
19022 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19026 + * inode private data
19031 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19033 + struct inode *h_inode;
19034 + struct au_hinode *hinode;
19036 + IiMustAnyLock(inode);
19038 + hinode = au_hinode(au_ii(inode), bindex);
19039 + h_inode = hinode->hi_inode;
19040 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19044 +/* todo: hard/soft set? */
19045 +void au_hiput(struct au_hinode *hinode)
19047 + au_hn_free(hinode);
19048 + dput(hinode->hi_whdentry);
19049 + iput(hinode->hi_inode);
19052 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19054 + unsigned int flags;
19055 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19058 + if (au_opt_test(mnt_flags, XINO))
19059 + au_fset_hi(flags, XINO);
19060 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19061 + au_fset_hi(flags, HNOTIFY);
19065 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19066 + struct inode *h_inode, unsigned int flags)
19068 + struct au_hinode *hinode;
19069 + struct inode *hi;
19070 + struct au_iinfo *iinfo = au_ii(inode);
19072 + IiMustWriteLock(inode);
19074 + hinode = au_hinode(iinfo, bindex);
19075 + hi = hinode->hi_inode;
19076 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19079 + au_hiput(hinode);
19080 + hinode->hi_inode = h_inode;
19083 + struct super_block *sb = inode->i_sb;
19084 + struct au_branch *br;
19086 + AuDebugOn(inode->i_mode
19087 + && (h_inode->i_mode & S_IFMT)
19088 + != (inode->i_mode & S_IFMT));
19089 + if (bindex == iinfo->ii_btop)
19090 + au_cpup_igen(inode, h_inode);
19091 + br = au_sbr(sb, bindex);
19092 + hinode->hi_id = br->br_id;
19093 + if (au_ftest_hi(flags, XINO)) {
19094 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19096 + if (unlikely(err))
19097 + AuIOErr1("failed au_xino_write() %d\n", err);
19100 + if (au_ftest_hi(flags, HNOTIFY)
19101 + && au_br_hnotifyable(br->br_perm)) {
19102 + err = au_hn_alloc(hinode, inode);
19103 + if (unlikely(err))
19104 + AuIOErr1("au_hn_alloc() %d\n", err);
19109 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19110 + struct dentry *h_wh)
19112 + struct au_hinode *hinode;
19114 + IiMustWriteLock(inode);
19116 + hinode = au_hinode(au_ii(inode), bindex);
19117 + AuDebugOn(hinode->hi_whdentry);
19118 + hinode->hi_whdentry = h_wh;
19121 +void au_update_iigen(struct inode *inode, int half)
19123 + struct au_iinfo *iinfo;
19124 + struct au_iigen *iigen;
19125 + unsigned int sigen;
19127 + sigen = au_sigen(inode->i_sb);
19128 + iinfo = au_ii(inode);
19129 + iigen = &iinfo->ii_generation;
19130 + spin_lock(&iigen->ig_spin);
19131 + iigen->ig_generation = sigen;
19133 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19135 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19136 + spin_unlock(&iigen->ig_spin);
19139 +/* it may be called at remount time, too */
19140 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19142 + struct au_iinfo *iinfo;
19143 + aufs_bindex_t bindex, bbot;
19145 + AuDebugOn(au_is_bad_inode(inode));
19146 + IiMustWriteLock(inode);
19148 + iinfo = au_ii(inode);
19149 + if (do_put_zero && iinfo->ii_btop >= 0) {
19150 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19152 + struct inode *h_i;
19154 + h_i = au_hinode(iinfo, bindex)->hi_inode;
19157 + && !(h_i->i_state & I_LINKABLE))
19158 + au_set_h_iptr(inode, bindex, NULL, 0);
19162 + iinfo->ii_btop = -1;
19163 + iinfo->ii_bbot = -1;
19164 + bbot = au_sbbot(inode->i_sb);
19165 + for (bindex = 0; bindex <= bbot; bindex++)
19166 + if (au_hinode(iinfo, bindex)->hi_inode) {
19167 + iinfo->ii_btop = bindex;
19170 + if (iinfo->ii_btop >= 0)
19171 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
19172 + if (au_hinode(iinfo, bindex)->hi_inode) {
19173 + iinfo->ii_bbot = bindex;
19176 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
19179 +/* ---------------------------------------------------------------------- */
19181 +void au_icntnr_init_once(void *_c)
19183 + struct au_icntnr *c = _c;
19184 + struct au_iinfo *iinfo = &c->iinfo;
19186 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19187 + au_rw_init(&iinfo->ii_rwsem);
19188 + inode_init_once(&c->vfs_inode);
19191 +void au_hinode_init(struct au_hinode *hinode)
19193 + hinode->hi_inode = NULL;
19194 + hinode->hi_id = -1;
19195 + au_hn_init(hinode);
19196 + hinode->hi_whdentry = NULL;
19199 +int au_iinfo_init(struct inode *inode)
19201 + struct au_iinfo *iinfo;
19202 + struct super_block *sb;
19203 + struct au_hinode *hi;
19206 + sb = inode->i_sb;
19207 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19208 + nbr = au_sbbot(sb) + 1;
19209 + if (unlikely(nbr <= 0))
19211 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19213 + au_lcnt_inc(&au_sbi(sb)->si_ninodes);
19215 + iinfo->ii_hinode = hi;
19216 + for (i = 0; i < nbr; i++, hi++)
19217 + au_hinode_init(hi);
19219 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19220 + iinfo->ii_btop = -1;
19221 + iinfo->ii_bbot = -1;
19222 + iinfo->ii_vdir = NULL;
19228 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
19231 + struct au_hinode *hip;
19233 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19236 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
19239 + iinfo->ii_hinode = hip;
19240 + i = iinfo->ii_bbot + 1;
19242 + for (; i < nbr; i++, hip++)
19243 + au_hinode_init(hip);
19250 +void au_iinfo_fin(struct inode *inode)
19252 + struct au_iinfo *iinfo;
19253 + struct au_hinode *hi;
19254 + struct super_block *sb;
19255 + aufs_bindex_t bindex, bbot;
19256 + const unsigned char unlinked = !inode->i_nlink;
19258 + AuDebugOn(au_is_bad_inode(inode));
19260 + sb = inode->i_sb;
19261 + au_lcnt_dec(&au_sbi(sb)->si_ninodes);
19262 + if (si_pid_test(sb))
19263 + au_xino_delete_inode(inode, unlinked);
19266 + * it is safe to hide the dependency between sbinfo and
19270 + si_noflush_read_lock(sb);
19271 + au_xino_delete_inode(inode, unlinked);
19272 + si_read_unlock(sb);
19276 + iinfo = au_ii(inode);
19277 + if (iinfo->ii_vdir)
19278 + au_vdir_free(iinfo->ii_vdir);
19280 + bindex = iinfo->ii_btop;
19281 + if (bindex >= 0) {
19282 + hi = au_hinode(iinfo, bindex);
19283 + bbot = iinfo->ii_bbot;
19284 + while (bindex++ <= bbot) {
19285 + if (hi->hi_inode)
19290 + au_kfree_rcu(iinfo->ii_hinode);
19291 + AuRwDestroy(&iinfo->ii_rwsem);
19293 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
19294 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19295 +++ linux/fs/aufs/inode.c 2023-08-28 12:34:39.956636132 +0200
19297 +// SPDX-License-Identifier: GPL-2.0
19299 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19301 + * This program is free software; you can redistribute it and/or modify
19302 + * it under the terms of the GNU General Public License as published by
19303 + * the Free Software Foundation; either version 2 of the License, or
19304 + * (at your option) any later version.
19306 + * This program is distributed in the hope that it will be useful,
19307 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19308 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19309 + * GNU General Public License for more details.
19311 + * You should have received a copy of the GNU General Public License
19312 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19316 + * inode functions
19319 +#include <linux/iversion.h>
19322 +struct inode *au_igrab(struct inode *inode)
19325 + AuDebugOn(!atomic_read(&inode->i_count));
19331 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19333 + au_cpup_attr_all(inode, /*force*/0);
19334 + au_update_iigen(inode, /*half*/1);
19336 + inode_inc_iversion(inode);
19339 +static int au_ii_refresh(struct inode *inode, int *update)
19343 + aufs_bindex_t bindex, new_bindex;
19344 + struct super_block *sb;
19345 + struct au_iinfo *iinfo;
19346 + struct au_hinode *p, *q, tmp;
19348 + AuDebugOn(au_is_bad_inode(inode));
19349 + IiMustWriteLock(inode);
19352 + sb = inode->i_sb;
19353 + nbr = au_sbbot(sb) + 1;
19354 + type = inode->i_mode & S_IFMT;
19355 + iinfo = au_ii(inode);
19356 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
19357 + if (unlikely(err))
19360 + AuDebugOn(iinfo->ii_btop < 0);
19361 + p = au_hinode(iinfo, iinfo->ii_btop);
19362 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
19364 + if (!p->hi_inode)
19367 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19368 + new_bindex = au_br_index(sb, p->hi_id);
19369 + if (new_bindex == bindex)
19372 + if (new_bindex < 0) {
19375 + p->hi_inode = NULL;
19379 + if (new_bindex < iinfo->ii_btop)
19380 + iinfo->ii_btop = new_bindex;
19381 + if (iinfo->ii_bbot < new_bindex)
19382 + iinfo->ii_bbot = new_bindex;
19383 + /* swap two lower inode, and loop again */
19384 + q = au_hinode(iinfo, new_bindex);
19388 + if (tmp.hi_inode) {
19393 + au_update_ibrange(inode, /*do_put_zero*/0);
19394 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
19395 + e = au_dy_irefresh(inode);
19396 + if (unlikely(e && !err))
19404 +void au_refresh_iop(struct inode *inode, int force_getattr)
19407 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19408 + const struct inode_operations *iop
19409 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19411 + if (inode->i_op == iop)
19414 + switch (inode->i_mode & S_IFMT) {
19416 + type = AuIop_DIR;
19419 + type = AuIop_SYMLINK;
19422 + type = AuIop_OTHER;
19426 + inode->i_op = iop + type;
19427 + /* unnecessary smp_wmb() */
19430 +int au_refresh_hinode_self(struct inode *inode)
19434 + err = au_ii_refresh(inode, &update);
19436 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19442 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19444 + int err, e, update;
19445 + unsigned int flags;
19447 + aufs_bindex_t bindex, bbot;
19448 + unsigned char isdir;
19449 + struct au_hinode *p;
19450 + struct au_iinfo *iinfo;
19452 + err = au_ii_refresh(inode, &update);
19453 + if (unlikely(err))
19457 + iinfo = au_ii(inode);
19458 + p = au_hinode(iinfo, iinfo->ii_btop);
19459 + mode = (inode->i_mode & S_IFMT);
19460 + isdir = S_ISDIR(mode);
19461 + flags = au_hi_flags(inode, isdir);
19462 + bbot = au_dbbot(dentry);
19463 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
19464 + struct inode *h_i, *h_inode;
19465 + struct dentry *h_d;
19467 + h_d = au_h_dptr(dentry, bindex);
19468 + if (!h_d || d_is_negative(h_d))
19471 + h_inode = d_inode(h_d);
19472 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19473 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
19474 + h_i = au_h_iptr(inode, bindex);
19476 + if (h_i == h_inode)
19482 + if (bindex < iinfo->ii_btop)
19483 + iinfo->ii_btop = bindex;
19484 + if (iinfo->ii_bbot < bindex)
19485 + iinfo->ii_bbot = bindex;
19486 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19489 + au_update_ibrange(inode, /*do_put_zero*/0);
19490 + e = au_dy_irefresh(inode);
19491 + if (unlikely(e && !err))
19494 + au_refresh_hinode_attr(inode, update && isdir);
19501 +static int set_inode(struct inode *inode, struct dentry *dentry)
19504 + unsigned int flags;
19506 + aufs_bindex_t bindex, btop, btail;
19507 + unsigned char isdir;
19508 + struct dentry *h_dentry;
19509 + struct inode *h_inode;
19510 + struct au_iinfo *iinfo;
19511 + const struct inode_operations *iop;
19513 + IiMustWriteLock(inode);
19517 + iop = au_sbi(inode->i_sb)->si_iop_array;
19518 + btop = au_dbtop(dentry);
19519 + h_dentry = au_h_dptr(dentry, btop);
19520 + h_inode = d_inode(h_dentry);
19521 + mode = h_inode->i_mode;
19522 + switch (mode & S_IFMT) {
19524 + btail = au_dbtail(dentry);
19525 + inode->i_op = iop + AuIop_OTHER;
19526 + inode->i_fop = &aufs_file_fop;
19527 + err = au_dy_iaop(inode, btop, h_inode);
19528 + if (unlikely(err))
19533 + btail = au_dbtaildir(dentry);
19534 + inode->i_op = iop + AuIop_DIR;
19535 + inode->i_fop = &aufs_dir_fop;
19538 + btail = au_dbtail(dentry);
19539 + inode->i_op = iop + AuIop_SYMLINK;
19545 + btail = au_dbtail(dentry);
19546 + inode->i_op = iop + AuIop_OTHER;
19547 + init_special_inode(inode, mode, h_inode->i_rdev);
19550 + AuIOErr("Unknown file type 0%o\n", mode);
19555 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19556 + flags = au_hi_flags(inode, isdir);
19557 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19558 + && au_ftest_hi(flags, HNOTIFY)
19559 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19560 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19561 + au_fclr_hi(flags, HNOTIFY);
19562 + iinfo = au_ii(inode);
19563 + iinfo->ii_btop = btop;
19564 + iinfo->ii_bbot = btail;
19565 + for (bindex = btop; bindex <= btail; bindex++) {
19566 + h_dentry = au_h_dptr(dentry, bindex);
19568 + au_set_h_iptr(inode, bindex,
19569 + au_igrab(d_inode(h_dentry)), flags);
19571 + au_cpup_attr_all(inode, /*force*/1);
19573 + * to force calling aufs_get_inode_acl() every time,
19574 + * do not call cache_no_acl() for aufs inode.
19582 + * successful returns with iinfo write_locked
19584 + * zero: success, matched
19585 + * plus: no error, but unmatched
19587 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19590 + unsigned int gen, igflags;
19591 + aufs_bindex_t bindex, bbot;
19592 + struct inode *h_inode, *h_dinode;
19593 + struct dentry *h_dentry;
19596 + * before this function, if aufs got any iinfo lock, it must be only
19597 + * one, the parent dir.
19598 + * it can happen by UDBA and the obsoleted inode number.
19601 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19605 + ii_write_lock_new_child(inode);
19606 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
19607 + h_dinode = d_inode(h_dentry);
19608 + bbot = au_ibbot(inode);
19609 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
19610 + h_inode = au_h_iptr(inode, bindex);
19611 + if (!h_inode || h_inode != h_dinode)
19615 + gen = au_iigen(inode, &igflags);
19616 + if (gen == au_digen(dentry)
19617 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19620 + /* fully refresh inode using dentry */
19621 + err = au_refresh_hinode(inode, dentry);
19623 + au_update_iigen(inode, /*half*/0);
19627 + if (unlikely(err))
19628 + ii_write_unlock(inode);
19633 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19634 + unsigned int d_type, ino_t *ino)
19637 + const int isnondir = d_type != DT_DIR;
19639 + /* prevent hardlinked inode number from race condition */
19641 + err = au_xinondir_enter(sb, bindex, h_ino, &idx);
19642 + if (unlikely(err))
19646 + err = au_xino_read(sb, bindex, h_ino, ino);
19647 + if (unlikely(err))
19648 + goto out_xinondir;
19652 + *ino = au_xino_new_ino(sb);
19653 + if (unlikely(!*ino))
19654 + goto out_xinondir;
19655 + err = au_xino_write(sb, bindex, h_ino, *ino);
19656 + if (unlikely(err))
19657 + goto out_xinondir;
19661 + if (isnondir && idx >= 0)
19662 + au_xinondir_leave(sb, bindex, h_ino, idx);
19667 +/* successful returns with iinfo write_locked */
19668 +/* todo: return with unlocked? */
19669 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19671 + struct inode *inode, *h_inode;
19672 + struct dentry *h_dentry;
19673 + struct super_block *sb;
19674 + ino_t h_ino, ino;
19675 + int err, idx, hlinked;
19676 + aufs_bindex_t btop;
19678 + sb = dentry->d_sb;
19679 + btop = au_dbtop(dentry);
19680 + h_dentry = au_h_dptr(dentry, btop);
19681 + h_inode = d_inode(h_dentry);
19682 + h_ino = h_inode->i_ino;
19683 + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1;
19687 + * stop 'race'-ing between hardlinks under different
19691 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19692 + inode = ERR_PTR(err);
19693 + if (unlikely(err))
19697 + err = au_xino_read(sb, btop, h_ino, &ino);
19698 + inode = ERR_PTR(err);
19699 + if (unlikely(err))
19700 + goto out_xinondir;
19703 + ino = au_xino_new_ino(sb);
19704 + if (unlikely(!ino)) {
19705 + inode = ERR_PTR(-EIO);
19706 + goto out_xinondir;
19710 + AuDbg("i%lu\n", (unsigned long)ino);
19711 + inode = au_iget_locked(sb, ino);
19712 + err = PTR_ERR(inode);
19713 + if (IS_ERR(inode))
19714 + goto out_xinondir;
19716 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19717 + if (inode->i_state & I_NEW) {
19718 + ii_write_lock_new_child(inode);
19719 + err = set_inode(inode, dentry);
19721 + unlock_new_inode(inode);
19722 + goto out_xinondir; /* success */
19726 + * iget_failed() calls iput(), but we need to call
19727 + * ii_write_unlock() after iget_failed(). so dirty hack for
19730 + atomic_inc(&inode->i_count);
19731 + iget_failed(inode);
19732 + ii_write_unlock(inode);
19733 + au_xino_write(sb, btop, h_ino, /*ino*/0);
19734 + /* ignore this error */
19736 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19738 + * horrible race condition between lookup, readdir and copyup
19739 + * (or something).
19741 + if (hlinked && idx >= 0)
19742 + au_xinondir_leave(sb, btop, h_ino, idx);
19743 + err = reval_inode(inode, dentry);
19744 + if (unlikely(err < 0)) {
19749 + goto out; /* success */
19750 + else if (hlinked && idx >= 0) {
19751 + err = au_xinondir_enter(sb, btop, h_ino, &idx);
19752 + if (unlikely(err)) {
19754 + inode = ERR_PTR(err);
19760 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19761 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19762 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19763 + btop, au_sbtype(h_dentry->d_sb), dentry,
19764 + (unsigned long)h_ino, (unsigned long)ino);
19766 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
19769 + if (hlinked && idx >= 0)
19770 + au_xinondir_leave(sb, btop, h_ino, idx);
19776 + inode = ERR_PTR(err);
19778 + if (hlinked && idx >= 0)
19779 + au_xinondir_leave(sb, btop, h_ino, idx);
19784 +/* ---------------------------------------------------------------------- */
19786 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19787 + struct inode *inode)
19790 + struct inode *hi;
19792 + err = au_br_rdonly(au_sbr(sb, bindex));
19794 + /* pseudo-link after flushed may happen out of bounds */
19797 + && au_ibtop(inode) <= bindex
19798 + && bindex <= au_ibbot(inode)) {
19800 + * permission check is unnecessary since vfsub routine
19801 + * will be called later
19803 + hi = au_h_iptr(inode, bindex);
19805 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19811 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19814 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19816 + return inode_permission(h_idmap, h_inode, mask);
19819 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19822 + if (au_test_nfs(h_inode->i_sb)
19823 + && (mask & MAY_WRITE)
19824 + && S_ISDIR(h_inode->i_mode))
19825 + mask |= MAY_READ; /* force permission check */
19826 + return au_test_h_perm(h_idmap, h_inode, mask);
19828 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
19829 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19830 +++ linux/fs/aufs/inode.h 2023-08-28 12:34:39.956636132 +0200
19832 +/* SPDX-License-Identifier: GPL-2.0 */
19834 + * Copyright (C) 2005-2022 Junjiro R. Okajima
19836 + * This program is free software; you can redistribute it and/or modify
19837 + * it under the terms of the GNU General Public License as published by
19838 + * the Free Software Foundation; either version 2 of the License, or
19839 + * (at your option) any later version.
19841 + * This program is distributed in the hope that it will be useful,
19842 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19843 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19844 + * GNU General Public License for more details.
19846 + * You should have received a copy of the GNU General Public License
19847 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19851 + * inode operations
19854 +#ifndef __AUFS_INODE_H__
19855 +#define __AUFS_INODE_H__
19859 +#include <linux/fsnotify.h>
19860 +#include "rwsem.h"
19864 +struct au_hnotify {
19865 +#ifdef CONFIG_AUFS_HNOTIFY
19866 +#ifdef CONFIG_AUFS_HFSNOTIFY
19867 + /* never use fsnotify_add_vfsmount_mark() */
19868 + struct fsnotify_mark hn_mark;
19870 + struct inode *hn_aufs_inode; /* no get/put */
19871 + struct rcu_head rcu;
19873 +} ____cacheline_aligned_in_smp;
19875 +struct au_hinode {
19876 + struct inode *hi_inode;
19877 + aufs_bindex_t hi_id;
19878 +#ifdef CONFIG_AUFS_HNOTIFY
19879 + struct au_hnotify *hi_notify;
19882 + /* reference to the copied-up whiteout with get/put */
19883 + struct dentry *hi_whdentry;
19887 +#define AuIG_HALF_REFRESHED 1
19888 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19889 +#define au_ig_fset(flags, name) \
19890 + do { (flags) |= AuIG_##name; } while (0)
19891 +#define au_ig_fclr(flags, name) \
19892 + do { (flags) &= ~AuIG_##name; } while (0)
19895 + spinlock_t ig_spin;
19896 + __u32 ig_generation, ig_flags;
19901 + struct au_iigen ii_generation;
19902 + struct super_block *ii_hsb1; /* no get/put */
19904 + struct au_rwsem ii_rwsem;
19905 + aufs_bindex_t ii_btop, ii_bbot;
19907 + struct au_hinode *ii_hinode;
19908 + struct au_vdir *ii_vdir;
19911 +struct au_icntnr {
19912 + struct au_iinfo iinfo;
19913 + struct inode vfs_inode;
19914 + struct hlist_bl_node plink;
19915 + struct rcu_head rcu;
19916 +} ____cacheline_aligned_in_smp;
19918 +/* au_pin flags */
19919 +#define AuPin_DI_LOCKED 1
19920 +#define AuPin_MNT_WRITE (1 << 1)
19921 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19922 +#define au_fset_pin(flags, name) \
19923 + do { (flags) |= AuPin_##name; } while (0)
19924 +#define au_fclr_pin(flags, name) \
19925 + do { (flags) &= ~AuPin_##name; } while (0)
19929 + struct dentry *dentry;
19930 + unsigned int udba;
19931 + unsigned char lsc_di, lsc_hi, flags;
19932 + aufs_bindex_t bindex;
19935 + struct dentry *parent;
19936 + struct au_hinode *hdir;
19937 + struct vfsmount *h_mnt;
19939 + /* temporary unlock/relock for copyup */
19940 + struct dentry *h_dentry, *h_parent;
19941 + struct au_branch *br;
19942 + struct task_struct *task;
19945 +void au_pin_hdir_unlock(struct au_pin *p);
19946 +int au_pin_hdir_lock(struct au_pin *p);
19947 +int au_pin_hdir_relock(struct au_pin *p);
19948 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19949 +void au_pin_hdir_release(struct au_pin *p);
19951 +/* ---------------------------------------------------------------------- */
19953 +static inline struct au_iinfo *au_ii(struct inode *inode)
19955 + BUG_ON(is_bad_inode(inode));
19956 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19959 +/* ---------------------------------------------------------------------- */
19962 +struct inode *au_igrab(struct inode *inode);
19963 +void au_refresh_iop(struct inode *inode, int force_getattr);
19964 +int au_refresh_hinode_self(struct inode *inode);
19965 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
19966 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19967 + unsigned int d_type, ino_t *ino);
19968 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
19969 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19970 + struct inode *inode);
19971 +int au_test_h_perm(struct mnt_idmap *h_idmap, struct inode *h_inode,
19973 +int au_test_h_perm_sio(struct mnt_idmap *h_idmap, struct inode *h_inode,
19976 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
19977 + ino_t h_ino, unsigned int d_type, ino_t *ino)
19979 +#ifdef CONFIG_AUFS_SHWH
19980 + return au_ino(sb, bindex, h_ino, d_type, ino);
19993 +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */
19994 + aufs_iop_nogetattr[AuIop_Last];
19996 +/* au_wr_dir flags */
19997 +#define AuWrDir_ADD_ENTRY 1
19998 +#define AuWrDir_ISDIR (1 << 1)
19999 +#define AuWrDir_TMPFILE (1 << 2)
20000 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
20001 +#define au_fset_wrdir(flags, name) \
20002 + do { (flags) |= AuWrDir_##name; } while (0)
20003 +#define au_fclr_wrdir(flags, name) \
20004 + do { (flags) &= ~AuWrDir_##name; } while (0)
20006 +struct au_wr_dir_args {
20007 + aufs_bindex_t force_btgt;
20008 + unsigned char flags;
20010 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20011 + struct au_wr_dir_args *args);
20013 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
20014 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
20015 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
20016 + unsigned int udba, unsigned char flags);
20017 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
20018 + unsigned int udba, unsigned char flags) __must_check;
20019 +int au_do_pin(struct au_pin *pin) __must_check;
20020 +void au_unpin(struct au_pin *pin);
20021 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20023 +#define AuIcpup_DID_CPUP 1
20024 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20025 +#define au_fset_icpup(flags, name) \
20026 + do { (flags) |= AuIcpup_##name; } while (0)
20027 +#define au_fclr_icpup(flags, name) \
20028 + do { (flags) &= ~AuIcpup_##name; } while (0)
20030 +struct au_icpup_args {
20031 + unsigned char flags;
20032 + unsigned char pin_flags;
20033 + aufs_bindex_t btgt;
20034 + unsigned int udba;
20035 + struct au_pin pin;
20036 + struct path h_path;
20037 + struct inode *h_inode;
20040 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20041 + struct au_icpup_args *a);
20043 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
20044 + struct path *h_path, int locked);
20047 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20048 + struct dentry *h_parent, int isdir);
20049 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
20050 + struct dentry *dentry, umode_t mode, dev_t dev);
20051 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
20052 + struct dentry *dentry, const char *symname);
20053 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
20054 + struct dentry *dentry, umode_t mode, bool want_excl);
20055 +struct vfsub_aopen_args;
20056 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20057 + struct vfsub_aopen_args *args);
20058 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
20059 + struct file *file, umode_t mode);
20060 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20061 + struct dentry *dentry);
20062 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
20063 + struct dentry *dentry, umode_t mode);
20066 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20067 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20068 + struct dentry *h_parent, int isdir);
20069 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20070 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20073 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20074 +int aufs_rename(struct mnt_idmap *idmap,
20075 + struct inode *_src_dir, struct dentry *_src_dentry,
20076 + struct inode *_dst_dir, struct dentry *_dst_dentry,
20077 + unsigned int _flags);
20080 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20081 +void au_hiput(struct au_hinode *hinode);
20082 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20083 + struct dentry *h_wh);
20084 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20086 +/* hinode flags */
20087 +#define AuHi_XINO 1
20088 +#define AuHi_HNOTIFY (1 << 1)
20089 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20090 +#define au_fset_hi(flags, name) \
20091 + do { (flags) |= AuHi_##name; } while (0)
20092 +#define au_fclr_hi(flags, name) \
20093 + do { (flags) &= ~AuHi_##name; } while (0)
20095 +#ifndef CONFIG_AUFS_HNOTIFY
20096 +#undef AuHi_HNOTIFY
20097 +#define AuHi_HNOTIFY 0
20100 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20101 + struct inode *h_inode, unsigned int flags);
20103 +void au_update_iigen(struct inode *inode, int half);
20104 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20106 +void au_icntnr_init_once(void *_c);
20107 +void au_hinode_init(struct au_hinode *hinode);
20108 +int au_iinfo_init(struct inode *inode);
20109 +void au_iinfo_fin(struct inode *inode);
20110 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
20112 +#ifdef CONFIG_PROC_FS
20114 +int au_plink_maint(struct super_block *sb, int flags);
20116 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20117 +int au_plink_maint_enter(struct super_block *sb);
20118 +#ifdef CONFIG_AUFS_DEBUG
20119 +void au_plink_list(struct super_block *sb);
20121 +AuStubVoid(au_plink_list, struct super_block *sb)
20123 +int au_plink_test(struct inode *inode);
20124 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20125 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20126 + struct dentry *h_dentry);
20127 +void au_plink_put(struct super_block *sb, int verbose);
20128 +void au_plink_clean(struct super_block *sb, int verbose);
20129 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20131 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20132 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20133 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20134 +AuStubVoid(au_plink_list, struct super_block *sb);
20135 +AuStubInt0(au_plink_test, struct inode *inode);
20136 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20137 + struct inode *inode, aufs_bindex_t bindex);
20138 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20139 + struct dentry *h_dentry);
20140 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20141 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20142 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20143 +#endif /* CONFIG_PROC_FS */
20145 +#ifdef CONFIG_AUFS_XATTR
20147 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
20148 + unsigned int verbose);
20149 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20150 +void au_xattr_init(struct super_block *sb);
20152 +AuStubInt0(au_cpup_xattr, struct path *h_dst, struct path *h_src,
20153 + int ignore_flags, unsigned int verbose);
20154 +AuStubVoid(au_xattr_init, struct super_block *sb);
20157 +#ifdef CONFIG_FS_POSIX_ACL
20158 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu);
20159 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
20160 + struct dentry *dentry, int type);
20161 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
20162 + struct posix_acl *acl, int type);
20165 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20171 +struct au_sxattr {
20175 + const char *name;
20176 + const void *value;
20181 + struct posix_acl *acl;
20186 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
20187 + struct au_sxattr *arg);
20190 +/* ---------------------------------------------------------------------- */
20192 +/* lock subclass for iinfo */
20194 + AuLsc_II_CHILD, /* child first */
20195 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20196 + AuLsc_II_CHILD3, /* copyup dirs */
20197 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20198 + AuLsc_II_PARENT2,
20199 + AuLsc_II_PARENT3, /* copyup dirs */
20200 + AuLsc_II_NEW_CHILD
20204 + * ii_read_lock_child, ii_write_lock_child,
20205 + * ii_read_lock_child2, ii_write_lock_child2,
20206 + * ii_read_lock_child3, ii_write_lock_child3,
20207 + * ii_read_lock_parent, ii_write_lock_parent,
20208 + * ii_read_lock_parent2, ii_write_lock_parent2,
20209 + * ii_read_lock_parent3, ii_write_lock_parent3,
20210 + * ii_read_lock_new_child, ii_write_lock_new_child,
20212 +#define AuReadLockFunc(name, lsc) \
20213 +static inline void ii_read_lock_##name(struct inode *i) \
20215 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20218 +#define AuWriteLockFunc(name, lsc) \
20219 +static inline void ii_write_lock_##name(struct inode *i) \
20221 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20224 +#define AuRWLockFuncs(name, lsc) \
20225 + AuReadLockFunc(name, lsc) \
20226 + AuWriteLockFunc(name, lsc)
20228 +AuRWLockFuncs(child, CHILD);
20229 +AuRWLockFuncs(child2, CHILD2);
20230 +AuRWLockFuncs(child3, CHILD3);
20231 +AuRWLockFuncs(parent, PARENT);
20232 +AuRWLockFuncs(parent2, PARENT2);
20233 +AuRWLockFuncs(parent3, PARENT3);
20234 +AuRWLockFuncs(new_child, NEW_CHILD);
20236 +#undef AuReadLockFunc
20237 +#undef AuWriteLockFunc
20238 +#undef AuRWLockFuncs
20240 +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem)
20241 +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem)
20242 +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem)
20244 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20245 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20246 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20248 +/* ---------------------------------------------------------------------- */
20250 +static inline void au_icntnr_init(struct au_icntnr *c)
20252 +#ifdef CONFIG_AUFS_DEBUG
20253 + c->vfs_inode.i_mode = 0;
20257 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20259 + unsigned int gen;
20260 + struct au_iinfo *iinfo;
20261 + struct au_iigen *iigen;
20263 + iinfo = au_ii(inode);
20264 + iigen = &iinfo->ii_generation;
20265 + spin_lock(&iigen->ig_spin);
20267 + *igflags = iigen->ig_flags;
20268 + gen = iigen->ig_generation;
20269 + spin_unlock(&iigen->ig_spin);
20274 +/* tiny test for inode number */
20275 +/* tmpfs generation is too rough */
20276 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20278 + struct au_iinfo *iinfo;
20280 + iinfo = au_ii(inode);
20281 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20282 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20283 + && iinfo->ii_higen == h_inode->i_generation);
20286 +static inline void au_iigen_dec(struct inode *inode)
20288 + struct au_iinfo *iinfo;
20289 + struct au_iigen *iigen;
20291 + iinfo = au_ii(inode);
20292 + iigen = &iinfo->ii_generation;
20293 + spin_lock(&iigen->ig_spin);
20294 + iigen->ig_generation--;
20295 + spin_unlock(&iigen->ig_spin);
20298 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20303 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20309 +/* ---------------------------------------------------------------------- */
20311 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
20312 + aufs_bindex_t bindex)
20314 + return iinfo->ii_hinode + bindex;
20317 +static inline int au_is_bad_inode(struct inode *inode)
20319 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
20322 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20323 + aufs_bindex_t bindex)
20325 + IiMustAnyLock(inode);
20326 + return au_hinode(au_ii(inode), bindex)->hi_id;
20329 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
20331 + IiMustAnyLock(inode);
20332 + return au_ii(inode)->ii_btop;
20335 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
20337 + IiMustAnyLock(inode);
20338 + return au_ii(inode)->ii_bbot;
20341 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20343 + IiMustAnyLock(inode);
20344 + return au_ii(inode)->ii_vdir;
20347 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20349 + IiMustAnyLock(inode);
20350 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
20353 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
20355 + IiMustWriteLock(inode);
20356 + au_ii(inode)->ii_btop = bindex;
20359 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
20361 + IiMustWriteLock(inode);
20362 + au_ii(inode)->ii_bbot = bindex;
20365 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20367 + IiMustWriteLock(inode);
20368 + au_ii(inode)->ii_vdir = vdir;
20371 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20373 + IiMustAnyLock(inode);
20374 + return au_hinode(au_ii(inode), bindex);
20377 +/* ---------------------------------------------------------------------- */
20379 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20382 + return pin->parent;
20386 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20388 + if (pin && pin->hdir)
20389 + return pin->hdir->hi_inode;
20393 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20396 + return pin->hdir;
20400 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20403 + pin->dentry = dentry;
20406 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20407 + unsigned char lflag)
20411 + au_fset_pin(pin->flags, DI_LOCKED);
20413 + au_fclr_pin(pin->flags, DI_LOCKED);
20417 +#if 0 /* reserved */
20418 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20421 + dput(pin->parent);
20422 + pin->parent = dget(parent);
20427 +/* ---------------------------------------------------------------------- */
20430 +#ifdef CONFIG_AUFS_HNOTIFY
20431 +struct au_hnotify_op {
20432 + void (*ctl)(struct au_hinode *hinode, int do_set);
20433 + int (*alloc)(struct au_hinode *hinode);
20436 + * if it returns true, the caller should free hinode->hi_notify,
20437 + * otherwise ->free() frees it.
20439 + int (*free)(struct au_hinode *hinode,
20440 + struct au_hnotify *hn) __must_check;
20442 + void (*fin)(void);
20443 + int (*init)(void);
20445 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20446 + void (*fin_br)(struct au_branch *br);
20447 + int (*init_br)(struct au_branch *br, int perm);
20451 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20452 +void au_hn_free(struct au_hinode *hinode);
20453 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20454 +void au_hn_reset(struct inode *inode, unsigned int flags);
20455 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20456 + const struct qstr *h_child_qstr, struct inode *h_child_inode);
20457 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20458 +int au_hnotify_init_br(struct au_branch *br, int perm);
20459 +void au_hnotify_fin_br(struct au_branch *br);
20460 +int __init au_hnotify_init(void);
20461 +void au_hnotify_fin(void);
20464 +extern const struct au_hnotify_op au_hnotify_op;
20467 +void au_hn_init(struct au_hinode *hinode)
20469 + hinode->hi_notify = NULL;
20472 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20474 + return hinode->hi_notify;
20478 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20479 + struct au_hinode *hinode __maybe_unused,
20480 + struct inode *inode __maybe_unused)
20481 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20482 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20483 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20484 + int do_set __maybe_unused)
20485 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20486 + unsigned int flags __maybe_unused)
20487 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20488 + struct au_branch *br __maybe_unused,
20489 + int perm __maybe_unused)
20490 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20491 + int perm __maybe_unused)
20492 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20493 +AuStubInt0(__init au_hnotify_init, void)
20494 +AuStubVoid(au_hnotify_fin, void)
20495 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20496 +#endif /* CONFIG_AUFS_HNOTIFY */
20498 +static inline void au_hn_suspend(struct au_hinode *hdir)
20500 + au_hn_ctl(hdir, /*do_set*/0);
20503 +static inline void au_hn_resume(struct au_hinode *hdir)
20505 + au_hn_ctl(hdir, /*do_set*/1);
20508 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
20510 + inode_lock(hdir->hi_inode);
20511 + au_hn_suspend(hdir);
20514 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
20515 + unsigned int sc __maybe_unused)
20517 + inode_lock_nested(hdir->hi_inode, sc);
20518 + au_hn_suspend(hdir);
20521 +#if 0 /* unused */
20522 +#include "vfsub.h"
20523 +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir,
20526 + inode_lock_shared_nested(hdir->hi_inode, sc);
20527 + au_hn_suspend(hdir);
20531 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
20533 + au_hn_resume(hdir);
20534 + inode_unlock(hdir->hi_inode);
20537 +#endif /* __KERNEL__ */
20538 +#endif /* __AUFS_INODE_H__ */
20539 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
20540 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20541 +++ linux/fs/aufs/ioctl.c 2022-11-05 23:02:18.965889284 +0100
20543 +// SPDX-License-Identifier: GPL-2.0
20545 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20547 + * This program is free software; you can redistribute it and/or modify
20548 + * it under the terms of the GNU General Public License as published by
20549 + * the Free Software Foundation; either version 2 of the License, or
20550 + * (at your option) any later version.
20552 + * This program is distributed in the hope that it will be useful,
20553 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20554 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20555 + * GNU General Public License for more details.
20557 + * You should have received a copy of the GNU General Public License
20558 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20563 + * plink-management and readdir in userspace.
20564 + * assist the pathconf(3) wrapper library.
20566 + * File-based Hierarchical Storage Management.
20569 +#include <linux/compat.h>
20570 +#include <linux/file.h>
20573 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20576 + aufs_bindex_t wbi, bindex, bbot;
20577 + struct file *h_file;
20578 + struct super_block *sb;
20579 + struct dentry *root;
20580 + struct au_branch *br;
20581 + struct aufs_wbr_fd wbrfd = {
20582 + .oflags = au_dir_roflags,
20585 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20586 + | O_NOATIME | O_CLOEXEC;
20588 + AuDebugOn(wbrfd.oflags & ~valid);
20591 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20592 + if (unlikely(err)) {
20598 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20599 + wbrfd.oflags |= au_dir_roflags;
20600 + AuDbg("0%o\n", wbrfd.oflags);
20601 + if (unlikely(wbrfd.oflags & ~valid))
20605 + fd = get_unused_fd_flags(0);
20607 + if (unlikely(fd < 0))
20610 + h_file = ERR_PTR(-EINVAL);
20613 + sb = path->dentry->d_sb;
20614 + root = sb->s_root;
20615 + aufs_read_lock(root, AuLock_IR);
20616 + bbot = au_sbbot(sb);
20617 + if (wbrfd.brid >= 0) {
20618 + wbi = au_br_index(sb, wbrfd.brid);
20619 + if (unlikely(wbi < 0 || wbi > bbot))
20623 + h_file = ERR_PTR(-ENOENT);
20624 + br = au_sbr(sb, wbi);
20625 + if (!au_br_writable(br->br_perm)) {
20629 + bindex = wbi + 1;
20631 + for (; bindex <= bbot; bindex++) {
20632 + br = au_sbr(sb, bindex);
20633 + if (au_br_writable(br->br_perm)) {
20635 + br = au_sbr(sb, wbi);
20640 + AuDbg("wbi %d\n", wbi);
20642 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20646 + aufs_read_unlock(root, AuLock_IR);
20647 + err = PTR_ERR(h_file);
20648 + if (IS_ERR(h_file))
20651 + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */
20652 + fd_install(fd, h_file);
20654 + goto out; /* success */
20657 + put_unused_fd(fd);
20663 +/* ---------------------------------------------------------------------- */
20665 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20668 + struct dentry *dentry;
20671 + case AUFS_CTL_RDU:
20672 + case AUFS_CTL_RDU_INO:
20673 + err = au_rdu_ioctl(file, cmd, arg);
20676 + case AUFS_CTL_WBR_FD:
20677 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20680 + case AUFS_CTL_IBUSY:
20681 + err = au_ibusy_ioctl(file, arg);
20684 + case AUFS_CTL_BRINFO:
20685 + err = au_brinfo_ioctl(file, arg);
20688 + case AUFS_CTL_FHSM_FD:
20689 + dentry = file->f_path.dentry;
20690 + if (IS_ROOT(dentry))
20691 + err = au_fhsm_fd(dentry->d_sb, arg);
20697 + /* do not call the lower */
20698 + AuDbg("0x%x\n", cmd);
20706 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20711 + case AUFS_CTL_MVDOWN:
20712 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20715 + case AUFS_CTL_WBR_FD:
20716 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20720 + /* do not call the lower */
20721 + AuDbg("0x%x\n", cmd);
20729 +#ifdef CONFIG_COMPAT
20730 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20731 + unsigned long arg)
20736 + case AUFS_CTL_RDU:
20737 + case AUFS_CTL_RDU_INO:
20738 + err = au_rdu_compat_ioctl(file, cmd, arg);
20741 + case AUFS_CTL_IBUSY:
20742 + err = au_ibusy_compat_ioctl(file, arg);
20745 + case AUFS_CTL_BRINFO:
20746 + err = au_brinfo_compat_ioctl(file, arg);
20750 + err = aufs_ioctl_dir(file, cmd, arg);
20757 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20758 + unsigned long arg)
20760 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20763 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
20764 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
20765 +++ linux/fs/aufs/i_op_add.c 2023-08-28 12:34:39.956636132 +0200
20767 +// SPDX-License-Identifier: GPL-2.0
20769 + * Copyright (C) 2005-2022 Junjiro R. Okajima
20771 + * This program is free software; you can redistribute it and/or modify
20772 + * it under the terms of the GNU General Public License as published by
20773 + * the Free Software Foundation; either version 2 of the License, or
20774 + * (at your option) any later version.
20776 + * This program is distributed in the hope that it will be useful,
20777 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20778 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20779 + * GNU General Public License for more details.
20781 + * You should have received a copy of the GNU General Public License
20782 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20786 + * inode operations (add entry)
20789 +#include <linux/iversion.h>
20793 + * final procedure of adding a new entry, except link(2).
20794 + * remove whiteout, instantiate, copyup the parent dir's times and size
20795 + * and update version.
20796 + * if it failed, re-create the removed whiteout.
20798 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
20799 + struct dentry *wh_dentry, struct dentry *dentry)
20802 + aufs_bindex_t bwh;
20803 + struct path h_path;
20804 + struct super_block *sb;
20805 + struct inode *inode, *h_dir;
20806 + struct dentry *wh;
20811 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
20812 + IMustLock(h_dir);
20813 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
20814 + bwh = au_dbwh(dentry);
20815 + h_path.dentry = wh_dentry;
20816 + h_path.mnt = au_sbr_mnt(sb, bindex);
20817 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
20819 + if (unlikely(err))
20823 + inode = au_new_inode(dentry, /*must_new*/1);
20824 + if (!IS_ERR(inode)) {
20825 + d_instantiate(dentry, inode);
20826 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
20828 + au_dir_ts(dir, bindex);
20829 + inode_inc_iversion(dir);
20830 + au_fhsm_wrote(sb, bindex, /*force*/0);
20831 + return 0; /* success */
20834 + err = PTR_ERR(inode);
20839 + /* dir inode is locked */
20840 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
20841 + rerr = PTR_ERR(wh);
20842 + if (IS_ERR(wh)) {
20843 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
20844 + dentry, err, rerr);
20853 +static int au_d_may_add(struct dentry *dentry)
20858 + if (unlikely(d_unhashed(dentry)))
20860 + if (unlikely(d_really_is_positive(dentry)))
20866 + * simple tests for the adding inode operations.
20867 + * following the checks in vfs, plus the parent-child relationship.
20869 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20870 + struct dentry *h_parent, int isdir)
20874 + struct dentry *h_dentry;
20875 + struct inode *h_inode;
20877 + err = -ENAMETOOLONG;
20878 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20881 + h_dentry = au_h_dptr(dentry, bindex);
20882 + if (d_really_is_negative(dentry)) {
20884 + if (unlikely(d_is_positive(h_dentry)))
20887 + /* rename(2) case */
20889 + if (unlikely(d_is_negative(h_dentry)))
20891 + h_inode = d_inode(h_dentry);
20892 + if (unlikely(!h_inode->i_nlink))
20895 + h_mode = h_inode->i_mode;
20898 + if (unlikely(S_ISDIR(h_mode)))
20900 + } else if (unlikely(!S_ISDIR(h_mode))) {
20907 + /* expected parent dir is locked */
20908 + if (unlikely(h_parent != h_dentry->d_parent))
20917 + * initial procedure of adding a new entry.
20918 + * prepare writable branch and the parent dir, lock it,
20919 + * and lookup whiteout for the new entry.
20921 +static struct dentry*
20922 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
20923 + struct dentry *src_dentry, struct au_pin *pin,
20924 + struct au_wr_dir_args *wr_dir_args)
20926 + struct dentry *wh_dentry, *h_parent;
20927 + struct super_block *sb;
20928 + struct au_branch *br;
20930 + unsigned int udba;
20931 + aufs_bindex_t bcpup;
20933 + AuDbg("%pd\n", dentry);
20935 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
20937 + wh_dentry = ERR_PTR(err);
20938 + if (unlikely(err < 0))
20941 + sb = dentry->d_sb;
20942 + udba = au_opt_udba(sb);
20943 + err = au_pin(pin, dentry, bcpup, udba,
20944 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20945 + wh_dentry = ERR_PTR(err);
20946 + if (unlikely(err))
20949 + h_parent = au_pinned_h_parent(pin);
20950 + if (udba != AuOpt_UDBA_NONE
20951 + && au_dbtop(dentry) == bcpup)
20952 + err = au_may_add(dentry, bcpup, h_parent,
20953 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
20954 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
20955 + err = -ENAMETOOLONG;
20956 + wh_dentry = ERR_PTR(err);
20957 + if (unlikely(err))
20960 + br = au_sbr(sb, bcpup);
20962 + struct path tmp = {
20963 + .dentry = h_parent,
20964 + .mnt = au_br_mnt(br)
20966 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
20969 + wh_dentry = NULL;
20970 + if (bcpup != au_dbwh(dentry))
20971 + goto out; /* success */
20974 + * ENAMETOOLONG here means that if we allowed create such name, then it
20975 + * would not be able to removed in the future. So we don't allow such
20976 + * name here and we don't handle ENAMETOOLONG differently here.
20978 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
20981 + if (IS_ERR(wh_dentry))
20984 + return wh_dentry;
20987 +/* ---------------------------------------------------------------------- */
20989 +enum { Mknod, Symlink, Creat };
20990 +struct simple_arg {
20997 + struct vfsub_aopen_args *aopen;
21000 + const char *symname;
21009 +static int add_simple(struct inode *dir, struct dentry *dentry,
21010 + struct simple_arg *arg)
21013 + aufs_bindex_t btop;
21014 + unsigned char created;
21015 + const unsigned char try_aopen
21016 + = (arg->type == Creat && arg->u.c.try_aopen);
21017 + struct vfsub_aopen_args *aopen = arg->u.c.aopen;
21018 + struct dentry *wh_dentry, *parent;
21019 + struct inode *h_dir;
21020 + struct super_block *sb;
21021 + struct au_branch *br;
21022 + /* to reduce stack size */
21024 + struct au_dtime dt;
21025 + struct au_pin pin;
21026 + struct path h_path;
21027 + struct au_wr_dir_args wr_dir_args;
21030 + AuDbg("%pd\n", dentry);
21034 + a = kmalloc(sizeof(*a), GFP_NOFS);
21035 + if (unlikely(!a))
21037 + a->wr_dir_args.force_btgt = -1;
21038 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
21040 + parent = dentry->d_parent; /* dir inode is locked */
21041 + if (!try_aopen) {
21042 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21043 + if (unlikely(err))
21046 + err = au_d_may_add(dentry);
21047 + if (unlikely(err))
21050 + di_write_lock_parent(parent);
21051 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21052 + &a->pin, &a->wr_dir_args);
21053 + err = PTR_ERR(wh_dentry);
21054 + if (IS_ERR(wh_dentry))
21057 + btop = au_dbtop(dentry);
21058 + sb = dentry->d_sb;
21059 + br = au_sbr(sb, btop);
21060 + a->h_path.dentry = au_h_dptr(dentry, btop);
21061 + a->h_path.mnt = au_br_mnt(br);
21062 + h_dir = au_pinned_h_dir(&a->pin);
21063 + switch (arg->type) {
21065 + if (!try_aopen || !h_dir->i_op->atomic_open) {
21066 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
21067 + arg->u.c.want_excl);
21069 + if (!err && try_aopen)
21070 + aopen->file->f_mode |= FMODE_CREATED;
21073 + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen);
21074 + AuDbg("err %d\n", err);
21075 + AuDbgFile(aopen->file);
21076 + created = err >= 0
21077 + && !!(aopen->file->f_mode & FMODE_CREATED);
21081 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
21085 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
21092 + if (unlikely(err < 0))
21095 + err = epilog(dir, btop, wh_dentry, dentry);
21097 + goto out_unpin; /* success */
21100 + if (created /* && d_is_positive(a->h_path.dentry) */) {
21101 + /* no delegation since it is just created */
21102 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
21105 + AuIOErr("%pd revert failure(%d, %d)\n",
21106 + dentry, err, rerr);
21109 + au_dtime_revert(&a->dt);
21111 + if (try_aopen && h_dir->i_op->atomic_open
21112 + && (aopen->file->f_mode & FMODE_OPENED))
21113 + /* aopen->file is still opened */
21114 + au_lcnt_dec(&aopen->br->br_nfiles);
21117 + au_unpin(&a->pin);
21121 + di_write_unlock(parent);
21123 + if (unlikely(err)) {
21124 + au_update_dbtop(dentry);
21128 + aufs_read_unlock(dentry, AuLock_DW);
21135 +int aufs_mknod(struct mnt_idmap *idmap, struct inode *dir,
21136 + struct dentry *dentry, umode_t mode, dev_t dev)
21138 + struct simple_arg arg = {
21145 + return add_simple(dir, dentry, &arg);
21148 +int aufs_symlink(struct mnt_idmap *idmap, struct inode *dir,
21149 + struct dentry *dentry, const char *symname)
21151 + struct simple_arg arg = {
21153 + .u.s.symname = symname
21155 + return add_simple(dir, dentry, &arg);
21158 +int aufs_create(struct mnt_idmap *idmap, struct inode *dir,
21159 + struct dentry *dentry, umode_t mode, bool want_excl)
21161 + struct simple_arg arg = {
21165 + .want_excl = want_excl
21168 + return add_simple(dir, dentry, &arg);
21171 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
21172 + struct vfsub_aopen_args *aopen_args)
21174 + struct simple_arg arg = {
21177 + .mode = aopen_args->create_mode,
21178 + .want_excl = aopen_args->open_flag & O_EXCL,
21179 + .try_aopen = true,
21180 + .aopen = aopen_args
21183 + return add_simple(dir, dentry, &arg);
21186 +int aufs_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
21187 + struct file *file, umode_t mode)
21190 + aufs_bindex_t bindex;
21191 + struct path h_ppath;
21192 + struct super_block *sb;
21193 + struct au_branch *br;
21194 + struct dentry *dentry, *parent, *h_parent, *h_dentry;
21195 + struct inode *h_dir, *inode;
21196 + struct vfsmount *h_mnt;
21197 + struct mnt_idmap *h_idmap;
21198 + struct file *h_file;
21199 + struct au_wr_dir_args wr_dir_args = {
21200 + .force_btgt = -1,
21201 + .flags = AuWrDir_TMPFILE
21204 + /* copy-up may happen */
21209 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21210 + if (unlikely(err))
21213 + dentry = file->f_path.dentry;
21214 + err = au_di_init(dentry);
21215 + if (unlikely(err))
21219 + parent = d_find_any_alias(dir);
21220 + AuDebugOn(!parent);
21221 + di_write_lock_parent(parent);
21222 + if (unlikely(d_inode(parent) != dir))
21225 + err = au_digen_test(parent, au_sigen(sb));
21226 + if (unlikely(err))
21229 + bindex = au_dbtop(parent);
21230 + au_set_dbtop(dentry, bindex);
21231 + au_set_dbbot(dentry, bindex);
21232 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
21234 + if (unlikely(err < 0))
21237 + err = -EOPNOTSUPP;
21238 + h_dir = au_h_iptr(dir, bindex);
21239 + if (unlikely(!h_dir->i_op->tmpfile))
21242 + br = au_sbr(sb, bindex);
21243 + h_mnt = au_br_mnt(br);
21244 + err = vfsub_mnt_want_write(h_mnt);
21245 + if (unlikely(err))
21248 + h_idmap = mnt_idmap(h_mnt);
21249 + h_parent = au_h_dptr(parent, bindex);
21250 + h_ppath.mnt = h_mnt;
21251 + h_ppath.dentry = h_parent;
21252 + h_file = vfs_tmpfile_open(h_idmap, &h_ppath, mode, /*open_flag*/0,
21254 + if (IS_ERR(h_file)) {
21255 + err = PTR_ERR(h_file);
21260 + h_dentry = h_file->f_path.dentry;
21261 + au_set_dbtop(dentry, bindex);
21262 + au_set_dbbot(dentry, bindex);
21263 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
21264 + inode = au_new_inode(dentry, /*must_new*/1);
21265 + if (IS_ERR(inode)) {
21266 + err = PTR_ERR(inode);
21267 + au_set_h_dptr(dentry, bindex, NULL);
21268 + au_set_dbtop(dentry, -1);
21269 + au_set_dbbot(dentry, -1);
21273 + if (!inode->i_nlink)
21274 + set_nlink(inode, 1);
21275 + d_tmpfile(file, inode);
21276 + au_di(dentry)->di_tmpfile = 1;
21277 + get_file(h_file);
21278 + au_di(dentry)->di_htmpfile = h_file;
21280 + /* update without i_mutex */
21281 + if (au_ibtop(dir) == au_dbtop(dentry))
21282 + au_cpup_attr_timesizes(dir);
21287 + vfsub_mnt_drop_write(h_mnt);
21289 + di_write_unlock(parent);
21291 + di_write_unlock(dentry);
21296 + au_di(dentry)->di_htmpfile = NULL;
21297 + au_di_fin(dentry);
21298 + dentry->d_fsdata = NULL;
21300 + si_read_unlock(sb);
21301 + if (!err && h_file) {
21303 + err = finish_open_simple(file, err);
21305 + au_lcnt_inc(&br->br_nfiles);
21308 + au_di(dentry)->di_htmpfile = NULL;
21309 + au_di_fin(dentry);
21310 + dentry->d_fsdata = NULL;
21314 + inode_unlock(dir);
21319 +/* ---------------------------------------------------------------------- */
21321 +struct au_link_args {
21322 + aufs_bindex_t bdst, bsrc;
21323 + struct au_pin pin;
21324 + struct path h_path;
21325 + struct dentry *src_parent, *parent;
21328 +static int au_cpup_before_link(struct dentry *src_dentry,
21329 + struct au_link_args *a)
21332 + struct dentry *h_src_dentry;
21333 + struct au_cp_generic cpg = {
21334 + .dentry = src_dentry,
21339 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
21342 + di_read_lock_parent(a->src_parent, AuLock_IR);
21343 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
21344 + if (unlikely(err))
21347 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
21348 + err = au_pin(&a->pin, src_dentry, a->bdst,
21349 + au_opt_udba(src_dentry->d_sb),
21350 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21351 + if (unlikely(err))
21354 + err = au_sio_cpup_simple(&cpg);
21355 + au_unpin(&a->pin);
21358 + di_read_unlock(a->src_parent, AuLock_IR);
21362 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
21363 + struct au_link_args *a)
21366 + unsigned char plink;
21367 + aufs_bindex_t bbot;
21368 + struct dentry *h_src_dentry;
21369 + struct inode *h_inode, *inode, *delegated;
21370 + struct super_block *sb;
21371 + struct file *h_file;
21375 + sb = src_dentry->d_sb;
21376 + inode = d_inode(src_dentry);
21377 + if (au_ibtop(inode) <= a->bdst)
21378 + h_inode = au_h_iptr(inode, a->bdst);
21379 + if (!h_inode || !h_inode->i_nlink) {
21380 + /* copyup src_dentry as the name of dentry. */
21381 + bbot = au_dbbot(dentry);
21382 + if (bbot < a->bsrc)
21383 + au_set_dbbot(dentry, a->bsrc);
21384 + au_set_h_dptr(dentry, a->bsrc,
21385 + dget(au_h_dptr(src_dentry, a->bsrc)));
21386 + dget(a->h_path.dentry);
21387 + au_set_h_dptr(dentry, a->bdst, NULL);
21388 + AuDbg("temporary d_inode...\n");
21389 + spin_lock(&dentry->d_lock);
21390 + dentry->d_inode = d_inode(src_dentry); /* tmp */
21391 + spin_unlock(&dentry->d_lock);
21392 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
21393 + if (IS_ERR(h_file))
21394 + err = PTR_ERR(h_file);
21396 + struct au_cp_generic cpg = {
21397 + .dentry = dentry,
21402 + .flags = AuCpup_KEEPLINO
21404 + err = au_sio_cpup_simple(&cpg);
21405 + au_h_open_post(dentry, a->bsrc, h_file);
21407 + dput(a->h_path.dentry);
21408 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21410 + au_set_h_dptr(dentry, a->bdst,
21411 + a->h_path.dentry);
21413 + spin_lock(&dentry->d_lock);
21414 + dentry->d_inode = NULL; /* restore */
21415 + spin_unlock(&dentry->d_lock);
21416 + AuDbg("temporary d_inode...done\n");
21417 + au_set_h_dptr(dentry, a->bsrc, NULL);
21418 + au_set_dbbot(dentry, bbot);
21420 + /* the inode of src_dentry already exists on a.bdst branch */
21421 + h_src_dentry = d_find_alias(h_inode);
21422 + if (!h_src_dentry && au_plink_test(inode)) {
21424 + h_src_dentry = au_plink_lkup(inode, a->bdst);
21425 + err = PTR_ERR(h_src_dentry);
21426 + if (IS_ERR(h_src_dentry))
21429 + if (unlikely(d_is_negative(h_src_dentry))) {
21430 + dput(h_src_dentry);
21431 + h_src_dentry = NULL;
21435 + if (h_src_dentry) {
21436 + delegated = NULL;
21437 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21438 + &a->h_path, &delegated);
21439 + if (unlikely(err == -EWOULDBLOCK)) {
21440 + pr_warn("cannot retry for NFSv4 delegation"
21441 + " for an internal link\n");
21444 + dput(h_src_dentry);
21446 + AuIOErr("no dentry found for hi%lu on b%d\n",
21447 + h_inode->i_ino, a->bdst);
21452 + if (!err && !plink)
21453 + au_plink_append(inode, a->bdst, a->h_path.dentry);
21460 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
21461 + struct dentry *dentry)
21464 + struct au_dtime dt;
21465 + struct au_link_args *a;
21466 + struct dentry *wh_dentry, *h_src_dentry;
21467 + struct inode *inode, *delegated;
21468 + struct super_block *sb;
21469 + struct au_wr_dir_args wr_dir_args = {
21470 + /* .force_btgt = -1, */
21471 + .flags = AuWrDir_ADD_ENTRY
21475 + inode = d_inode(src_dentry);
21476 + IMustLock(inode);
21479 + a = kzalloc(sizeof(*a), GFP_NOFS);
21480 + if (unlikely(!a))
21483 + a->parent = dentry->d_parent; /* dir inode is locked */
21484 + err = aufs_read_and_write_lock2(dentry, src_dentry,
21485 + AuLock_NOPLM | AuLock_GEN);
21486 + if (unlikely(err))
21488 + err = au_d_linkable(src_dentry);
21489 + if (unlikely(err))
21491 + err = au_d_may_add(dentry);
21492 + if (unlikely(err))
21495 + a->src_parent = dget_parent(src_dentry);
21496 + wr_dir_args.force_btgt = au_ibtop(inode);
21498 + di_write_lock_parent(a->parent);
21499 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
21500 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
21502 + err = PTR_ERR(wh_dentry);
21503 + if (IS_ERR(wh_dentry))
21507 + sb = dentry->d_sb;
21508 + a->bdst = au_dbtop(dentry);
21509 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
21510 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
21511 + a->bsrc = au_ibtop(inode);
21512 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21513 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
21514 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
21515 + if (!h_src_dentry) {
21516 + a->bsrc = au_dbtop(src_dentry);
21517 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
21518 + AuDebugOn(!h_src_dentry);
21519 + } else if (IS_ERR(h_src_dentry)) {
21520 + err = PTR_ERR(h_src_dentry);
21525 + * aufs doesn't touch the credential so
21526 + * security_dentry_create_files_as() is unnecessary.
21528 + if (au_opt_test(au_mntflags(sb), PLINK)) {
21529 + if (a->bdst < a->bsrc
21530 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
21531 + err = au_cpup_or_link(src_dentry, dentry, a);
21533 + delegated = NULL;
21534 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
21535 + &a->h_path, &delegated);
21536 + if (unlikely(err == -EWOULDBLOCK)) {
21537 + pr_warn("cannot retry for NFSv4 delegation"
21538 + " for an internal link\n");
21542 + dput(h_src_dentry);
21545 + * copyup src_dentry to the branch we process,
21546 + * and then link(2) to it.
21548 + dput(h_src_dentry);
21549 + if (a->bdst < a->bsrc
21550 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
21551 + au_unpin(&a->pin);
21552 + di_write_unlock(a->parent);
21553 + err = au_cpup_before_link(src_dentry, a);
21554 + di_write_lock_parent(a->parent);
21556 + err = au_pin(&a->pin, dentry, a->bdst,
21558 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21559 + if (unlikely(err))
21563 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
21565 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
21566 + delegated = NULL;
21567 + err = vfsub_link(h_src_dentry,
21568 + au_pinned_h_dir(&a->pin),
21569 + &a->h_path, &delegated);
21570 + if (unlikely(err == -EWOULDBLOCK)) {
21571 + pr_warn("cannot retry"
21572 + " for NFSv4 delegation"
21573 + " for an internal link\n");
21579 + if (unlikely(err))
21583 + a->h_path.dentry = wh_dentry;
21584 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
21586 + if (unlikely(err))
21590 + au_dir_ts(dir, a->bdst);
21591 + inode_inc_iversion(dir);
21592 + inc_nlink(inode);
21593 + inode->i_ctime = dir->i_ctime;
21594 + d_instantiate(dentry, au_igrab(inode));
21595 + if (d_unhashed(a->h_path.dentry))
21596 + /* some filesystem calls d_drop() */
21598 + /* some filesystems consume an inode even hardlink */
21599 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
21600 + goto out_unpin; /* success */
21603 + /* no delegation since it is just created */
21604 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
21605 + /*delegated*/NULL, /*force*/0);
21606 + if (unlikely(rerr)) {
21607 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
21610 + au_dtime_revert(&dt);
21612 + au_unpin(&a->pin);
21616 + di_write_unlock(a->parent);
21617 + dput(a->src_parent);
21619 + if (unlikely(err)) {
21620 + au_update_dbtop(dentry);
21623 + aufs_read_and_write_unlock2(dentry, src_dentry);
21631 +int aufs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
21632 + struct dentry *dentry, umode_t mode)
21635 + aufs_bindex_t bindex;
21636 + unsigned char diropq;
21637 + struct path h_path;
21638 + struct dentry *wh_dentry, *parent, *opq_dentry;
21639 + struct inode *h_inode;
21640 + struct super_block *sb;
21642 + struct au_pin pin;
21643 + struct au_dtime dt;
21644 + } *a; /* reduce the stack usage */
21645 + struct au_wr_dir_args wr_dir_args = {
21646 + .force_btgt = -1,
21647 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
21653 + a = kmalloc(sizeof(*a), GFP_NOFS);
21654 + if (unlikely(!a))
21657 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
21658 + if (unlikely(err))
21660 + err = au_d_may_add(dentry);
21661 + if (unlikely(err))
21664 + parent = dentry->d_parent; /* dir inode is locked */
21665 + di_write_lock_parent(parent);
21666 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
21667 + &a->pin, &wr_dir_args);
21668 + err = PTR_ERR(wh_dentry);
21669 + if (IS_ERR(wh_dentry))
21672 + sb = dentry->d_sb;
21673 + bindex = au_dbtop(dentry);
21674 + h_path.dentry = au_h_dptr(dentry, bindex);
21675 + h_path.mnt = au_sbr_mnt(sb, bindex);
21676 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
21677 + if (unlikely(err))
21680 + /* make the dir opaque */
21682 + h_inode = d_inode(h_path.dentry);
21684 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
21685 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21686 + opq_dentry = au_diropq_create(dentry, bindex);
21687 + inode_unlock(h_inode);
21688 + err = PTR_ERR(opq_dentry);
21689 + if (IS_ERR(opq_dentry))
21691 + dput(opq_dentry);
21695 + err = epilog(dir, bindex, wh_dentry, dentry);
21698 + goto out_unpin; /* success */
21703 + AuLabel(revert opq);
21704 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21705 + rerr = au_diropq_remove(dentry, bindex);
21706 + inode_unlock(h_inode);
21708 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
21709 + dentry, err, rerr);
21715 + AuLabel(revert dir);
21716 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
21718 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
21719 + dentry, err, rerr);
21722 + au_dtime_revert(&a->dt);
21724 + au_unpin(&a->pin);
21727 + di_write_unlock(parent);
21729 + if (unlikely(err)) {
21730 + au_update_dbtop(dentry);
21733 + aufs_read_unlock(dentry, AuLock_DW);
21739 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
21740 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
21741 +++ linux/fs/aufs/i_op.c 2023-08-28 12:34:39.956636132 +0200
21743 +// SPDX-License-Identifier: GPL-2.0
21745 + * Copyright (C) 2005-2022 Junjiro R. Okajima
21747 + * This program is free software; you can redistribute it and/or modify
21748 + * it under the terms of the GNU General Public License as published by
21749 + * the Free Software Foundation; either version 2 of the License, or
21750 + * (at your option) any later version.
21752 + * This program is distributed in the hope that it will be useful,
21753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21755 + * GNU General Public License for more details.
21757 + * You should have received a copy of the GNU General Public License
21758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21762 + * inode operations (except add/del/rename)
21765 +#include <linux/device_cgroup.h>
21766 +#include <linux/filelock.h>
21767 +#include <linux/fs_stack.h>
21768 +#include <linux/iversion.h>
21769 +#include <linux/security.h>
21772 +static int h_permission(struct inode *h_inode, int mask,
21773 + struct path *h_path, int brperm)
21776 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21777 + struct mnt_idmap *h_idmap;
21780 + if (write_mask && IS_IMMUTABLE(h_inode))
21784 + if (((mask & MAY_EXEC)
21785 + && S_ISREG(h_inode->i_mode)
21786 + && (path_noexec(h_path)
21787 + || !(h_inode->i_mode & 0111))))
21791 + * - skip the lower fs test in the case of write to ro branch.
21792 + * - nfs dir permission write check is optimized, but a policy for
21793 + * link/rename requires a real check.
21794 + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.'
21795 + * in this case, generic_permission() returns -EOPNOTSUPP.
21797 + h_idmap = mnt_idmap(h_path->mnt);
21798 + if ((write_mask && !au_br_writable(brperm))
21799 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
21800 + && write_mask && !(mask & MAY_READ))
21801 + || !h_inode->i_op->permission) {
21802 + /* AuLabel(generic_permission); */
21803 + /* AuDbg("get_inode_acl %ps\n",
21804 + h_inode->i_op->get_inode_acl); */
21805 + err = generic_permission(h_idmap, h_inode, mask);
21806 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
21807 + err = h_inode->i_op->permission(h_idmap, h_inode,
21811 + /* AuLabel(h_inode->permission); */
21812 + err = h_inode->i_op->permission(h_idmap, h_inode, mask);
21817 + err = devcgroup_inode_permission(h_inode, mask);
21819 + err = security_inode_permission(h_inode, mask);
21825 +static int aufs_permission(struct mnt_idmap *idmap, struct inode *inode,
21829 + aufs_bindex_t bindex, bbot;
21830 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
21831 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
21832 + struct inode *h_inode;
21833 + struct super_block *sb;
21834 + struct au_branch *br;
21836 + /* todo: support rcu-walk? */
21837 + if (mask & MAY_NOT_BLOCK)
21840 + sb = inode->i_sb;
21841 + si_read_lock(sb, AuLock_FLUSH);
21842 + ii_read_lock_child(inode);
21843 +#if 0 /* reserved for future use */
21845 + * This test may be rather 'too much' since the test is essentially done
21846 + * in the aufs_lookup(). Theoretically it is possible that the inode
21847 + * generation doesn't match to the superblock's here. But it isn't a
21848 + * big deal I suppose.
21850 + err = au_iigen_test(inode, au_sigen(sb));
21851 + if (unlikely(err))
21857 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
21858 + err = au_busy_or_stale();
21859 + h_inode = au_h_iptr(inode, au_ibtop(inode));
21860 + if (unlikely(!h_inode
21861 + || (h_inode->i_mode & S_IFMT)
21862 + != (inode->i_mode & S_IFMT)))
21866 + bindex = au_ibtop(inode);
21867 + br = au_sbr(sb, bindex);
21868 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
21871 + && !special_file(h_inode->i_mode)) {
21872 + /* test whether the upper writable branch exists */
21874 + for (; bindex >= 0; bindex--)
21875 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
21883 + /* non-write to dir */
21885 + bbot = au_ibbot(inode);
21886 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
21887 + h_inode = au_h_iptr(inode, bindex);
21889 + err = au_busy_or_stale();
21890 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
21893 + br = au_sbr(sb, bindex);
21894 + err = h_permission(h_inode, mask, &br->br_path,
21900 + ii_read_unlock(inode);
21901 + si_read_unlock(sb);
21905 +/* ---------------------------------------------------------------------- */
21907 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
21908 + unsigned int flags)
21910 + struct dentry *ret, *parent;
21911 + struct inode *inode;
21912 + struct super_block *sb;
21913 + int err, npositive;
21917 + /* todo: support rcu-walk? */
21918 + ret = ERR_PTR(-ECHILD);
21919 + if (flags & LOOKUP_RCU)
21922 + ret = ERR_PTR(-ENAMETOOLONG);
21923 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
21927 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
21928 + ret = ERR_PTR(err);
21929 + if (unlikely(err))
21932 + err = au_di_init(dentry);
21933 + ret = ERR_PTR(err);
21934 + if (unlikely(err))
21938 + npositive = 0; /* suppress a warning */
21939 + parent = dentry->d_parent; /* dir inode is locked */
21940 + di_read_lock_parent(parent, AuLock_IR);
21941 + err = au_alive_dir(parent);
21943 + err = au_digen_test(parent, au_sigen(sb));
21945 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
21946 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
21947 + AuLkup_ALLOW_NEG);
21950 + di_read_unlock(parent, AuLock_IR);
21951 + ret = ERR_PTR(err);
21952 + if (unlikely(err < 0))
21956 + inode = au_new_inode(dentry, /*must_new*/0);
21957 + if (IS_ERR(inode)) {
21958 + ret = (void *)inode;
21965 + atomic_inc(&inode->i_count);
21966 + ret = d_splice_alias(inode, dentry);
21967 +#if 0 /* reserved for future use */
21968 + if (unlikely(d_need_lookup(dentry))) {
21969 + spin_lock(&dentry->d_lock);
21970 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
21971 + spin_unlock(&dentry->d_lock);
21975 + if (!IS_ERR(ret)) {
21977 + if (ret && ret != dentry)
21978 + ii_write_unlock(inode);
21980 + ii_write_unlock(inode);
21987 + di_write_unlock(dentry);
21989 + si_read_unlock(sb);
21994 +/* ---------------------------------------------------------------------- */
21997 + * very dirty and complicated aufs ->atomic_open().
21998 + * aufs_atomic_open()
21999 + * + au_aopen_or_create()
22001 + * + vfsub_atomic_open()
22002 + * + branch fs ->atomic_open()
22003 + * may call the actual 'open' for h_file
22004 + * + inc br_nfiles only if opened
22005 + * + au_aopen_no_open() or au_aopen_do_open()
22007 + * au_aopen_do_open()
22008 + * + finish_open()
22009 + * + au_do_aopen()
22010 + * + au_do_open() the body of all 'open'
22011 + * + au_do_open_nondir()
22012 + * set the passed h_file
22014 + * au_aopen_no_open()
22015 + * + finish_no_open()
22018 +struct aopen_node {
22019 + struct hlist_bl_node hblist;
22020 + struct file *file, *h_file;
22023 +static int au_do_aopen(struct inode *inode, struct file *file)
22025 + struct hlist_bl_head *aopen;
22026 + struct hlist_bl_node *pos;
22027 + struct aopen_node *node;
22028 + struct au_do_open_args args = {
22030 + .open = au_do_open_nondir
22033 + aopen = &au_sbi(inode->i_sb)->si_aopen;
22034 + hlist_bl_lock(aopen);
22035 + hlist_bl_for_each_entry(node, pos, aopen, hblist)
22036 + if (node->file == file) {
22037 + args.h_file = node->h_file;
22040 + hlist_bl_unlock(aopen);
22041 + /* AuDebugOn(!args.h_file); */
22043 + return au_do_open(file, &args);
22046 +static int au_aopen_do_open(struct file *file, struct dentry *dentry,
22047 + struct aopen_node *aopen_node)
22050 + struct hlist_bl_head *aopen;
22053 + aopen = &au_sbi(dentry->d_sb)->si_aopen;
22054 + au_hbl_add(&aopen_node->hblist, aopen);
22055 + err = finish_open(file, dentry, au_do_aopen);
22056 + au_hbl_del(&aopen_node->hblist, aopen);
22057 + /* AuDbgFile(file); */
22058 + AuDbg("%pd%s%s\n", dentry,
22059 + (file->f_mode & FMODE_CREATED) ? " created" : "",
22060 + (file->f_mode & FMODE_OPENED) ? " opened" : "");
22066 +static int au_aopen_no_open(struct file *file, struct dentry *dentry)
22072 + err = finish_no_open(file, dentry);
22078 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
22079 + struct file *file, unsigned int open_flag,
22080 + umode_t create_mode)
22082 + int err, did_open;
22083 + unsigned int lkup_flags;
22084 + aufs_bindex_t bindex;
22085 + struct super_block *sb;
22086 + struct dentry *parent, *d;
22087 + struct vfsub_aopen_args args = {
22088 + .open_flag = open_flag,
22089 + .create_mode = create_mode
22091 + struct aopen_node aopen_node = {
22096 + AuDbg("open_flag 0%o\n", open_flag);
22097 + AuDbgDentry(dentry);
22100 + if (!au_di(dentry)) {
22101 + lkup_flags = LOOKUP_OPEN;
22102 + if (open_flag & O_CREAT)
22103 + lkup_flags |= LOOKUP_CREATE;
22104 + d = aufs_lookup(dir, dentry, lkup_flags);
22106 + err = PTR_ERR(d);
22111 + * obsoleted dentry found.
22112 + * another error will be returned later.
22118 + AuDbgDentry(dentry);
22121 + if (d_is_positive(dentry)
22122 + || d_unhashed(dentry)
22123 + || d_unlinked(dentry)
22124 + || !(open_flag & O_CREAT)) {
22125 + err = au_aopen_no_open(file, dentry);
22126 + goto out; /* success */
22129 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
22130 + if (unlikely(err))
22133 + sb = dentry->d_sb;
22134 + parent = dentry->d_parent; /* dir is locked */
22135 + di_write_lock_parent(parent);
22136 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
22137 + if (unlikely(err < 0))
22140 + AuDbgDentry(dentry);
22141 + if (d_is_positive(dentry)) {
22142 + err = au_aopen_no_open(file, dentry);
22143 + goto out_parent; /* success */
22146 + args.file = alloc_empty_file(file->f_flags, current_cred());
22147 + err = PTR_ERR(args.file);
22148 + if (IS_ERR(args.file))
22151 + bindex = au_dbtop(dentry);
22152 + err = au_aopen_or_create(dir, dentry, &args);
22154 + AuDbgFile(args.file);
22155 + file->f_mode = args.file->f_mode & ~FMODE_OPENED;
22156 + did_open = !!(args.file->f_mode & FMODE_OPENED);
22159 + args.file = NULL;
22161 + di_write_unlock(parent);
22162 + di_write_unlock(dentry);
22163 + if (unlikely(err < 0)) {
22170 + err = au_aopen_no_open(file, dentry);
22172 + aopen_node.h_file = args.file;
22173 + err = au_aopen_do_open(file, dentry, &aopen_node);
22175 + if (unlikely(err < 0)) {
22179 + au_lcnt_dec(&args.br->br_nfiles);
22181 + goto out_sb; /* success */
22184 + di_write_unlock(parent);
22185 + di_write_unlock(dentry);
22187 + si_read_unlock(sb);
22195 +/* ---------------------------------------------------------------------- */
22197 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
22198 + const unsigned char add_entry, aufs_bindex_t bcpup,
22199 + aufs_bindex_t btop)
22202 + struct dentry *h_parent;
22203 + struct inode *h_dir;
22206 + IMustLock(d_inode(parent));
22208 + di_write_lock_parent(parent);
22211 + if (!au_h_dptr(parent, bcpup)) {
22212 + if (btop > bcpup)
22213 + err = au_cpup_dirs(dentry, bcpup);
22214 + else if (btop < bcpup)
22215 + err = au_cpdown_dirs(dentry, bcpup);
22219 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
22220 + h_parent = au_h_dptr(parent, bcpup);
22221 + h_dir = d_inode(h_parent);
22222 + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT);
22223 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
22224 + /* todo: no unlock here */
22225 + inode_unlock_shared(h_dir);
22227 + AuDbg("bcpup %d\n", bcpup);
22229 + if (d_really_is_negative(dentry))
22230 + au_set_h_dptr(dentry, btop, NULL);
22231 + au_update_dbrange(dentry, /*do_put_zero*/0);
22236 + di_write_unlock(parent);
22238 + err = bcpup; /* success */
22245 + * decide the branch and the parent dir where we will create a new entry.
22246 + * returns new bindex or an error.
22247 + * copyup the parent dir if needed.
22249 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
22250 + struct au_wr_dir_args *args)
22253 + unsigned int flags;
22254 + aufs_bindex_t bcpup, btop, src_btop;
22255 + const unsigned char add_entry
22256 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
22257 + | au_ftest_wrdir(args->flags, TMPFILE);
22258 + struct super_block *sb;
22259 + struct dentry *parent;
22260 + struct au_sbinfo *sbinfo;
22262 + sb = dentry->d_sb;
22263 + sbinfo = au_sbi(sb);
22264 + parent = dget_parent(dentry);
22265 + btop = au_dbtop(dentry);
22267 + if (args->force_btgt < 0) {
22268 + if (src_dentry) {
22269 + src_btop = au_dbtop(src_dentry);
22270 + if (src_btop < btop)
22271 + bcpup = src_btop;
22272 + } else if (add_entry) {
22274 + if (au_ftest_wrdir(args->flags, ISDIR))
22275 + au_fset_wbr(flags, DIR);
22276 + err = AuWbrCreate(sbinfo, dentry, flags);
22280 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
22282 + err = AuWbrCopyup(sbinfo, dentry);
22284 + if (!IS_ROOT(dentry)) {
22285 + di_read_lock_parent(parent, !AuLock_IR);
22286 + err = AuWbrCopyup(sbinfo, dentry);
22287 + di_read_unlock(parent, !AuLock_IR);
22289 + err = AuWbrCopyup(sbinfo, dentry);
22292 + if (unlikely(err < 0))
22296 + bcpup = args->force_btgt;
22297 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
22300 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
22302 + if (bcpup == btop)
22303 + goto out; /* success */
22305 + /* copyup the new parent into the branch we process */
22306 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
22308 + if (d_really_is_negative(dentry)) {
22309 + au_set_h_dptr(dentry, btop, NULL);
22310 + au_set_dbtop(dentry, bcpup);
22311 + au_set_dbbot(dentry, bcpup);
22313 + AuDebugOn(add_entry
22314 + && !au_ftest_wrdir(args->flags, TMPFILE)
22315 + && !au_h_dptr(dentry, bcpup));
22323 +/* ---------------------------------------------------------------------- */
22325 +void au_pin_hdir_unlock(struct au_pin *p)
22328 + au_hn_inode_unlock(p->hdir);
22331 +int au_pin_hdir_lock(struct au_pin *p)
22339 + /* even if an error happens later, keep this lock */
22340 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
22343 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
22348 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
22349 + p->h_parent, p->br);
22355 +int au_pin_hdir_relock(struct au_pin *p)
22358 + struct inode *h_i;
22359 + struct dentry *h_d[] = {
22364 + err = au_pin_hdir_lock(p);
22365 + if (unlikely(err))
22368 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
22371 + if (d_is_positive(h_d[i])) {
22372 + h_i = d_inode(h_d[i]);
22373 + err = !h_i->i_nlink;
22381 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
22383 + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task);
22386 +void au_pin_hdir_acquire_nest(struct au_pin *p)
22389 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
22390 + p->lsc_hi, 0, NULL, _RET_IP_);
22391 + au_pin_hdir_set_owner(p, current);
22395 +void au_pin_hdir_release(struct au_pin *p)
22398 + au_pin_hdir_set_owner(p, p->task);
22399 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_);
22403 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
22405 + if (pin && pin->parent)
22406 + return au_h_dptr(pin->parent, pin->bindex);
22410 +void au_unpin(struct au_pin *p)
22413 + au_pin_hdir_unlock(p);
22414 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
22415 + vfsub_mnt_drop_write(p->h_mnt);
22419 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22420 + di_read_unlock(p->parent, AuLock_IR);
22421 + iput(p->hdir->hi_inode);
22423 + p->parent = NULL;
22426 + /* do not clear p->task */
22429 +int au_do_pin(struct au_pin *p)
22432 + struct super_block *sb;
22433 + struct inode *h_dir;
22436 + sb = p->dentry->d_sb;
22437 + p->br = au_sbr(sb, p->bindex);
22438 + if (IS_ROOT(p->dentry)) {
22439 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22440 + p->h_mnt = au_br_mnt(p->br);
22441 + err = vfsub_mnt_want_write(p->h_mnt);
22442 + if (unlikely(err)) {
22443 + au_fclr_pin(p->flags, MNT_WRITE);
22450 + p->h_dentry = NULL;
22451 + if (p->bindex <= au_dbbot(p->dentry))
22452 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
22454 + p->parent = dget_parent(p->dentry);
22455 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22456 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
22459 + p->h_parent = au_h_dptr(p->parent, p->bindex);
22460 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
22462 + h_dir = p->hdir->hi_inode;
22466 + * if DI_LOCKED is not set, then p->parent may be different
22467 + * and h_parent can be NULL.
22469 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
22471 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22472 + di_read_unlock(p->parent, AuLock_IR);
22474 + p->parent = NULL;
22478 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
22479 + p->h_mnt = au_br_mnt(p->br);
22480 + err = vfsub_mnt_want_write(p->h_mnt);
22481 + if (unlikely(err)) {
22482 + au_fclr_pin(p->flags, MNT_WRITE);
22483 + if (!au_ftest_pin(p->flags, DI_LOCKED))
22484 + di_read_unlock(p->parent, AuLock_IR);
22486 + p->parent = NULL;
22492 + err = au_pin_hdir_lock(p);
22494 + goto out; /* success */
22499 + pr_err("err %d\n", err);
22500 + err = au_busy_or_stale();
22505 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
22506 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
22507 + unsigned int udba, unsigned char flags)
22509 + p->dentry = dentry;
22511 + p->lsc_di = lsc_di;
22512 + p->lsc_hi = lsc_hi;
22513 + p->flags = flags;
22514 + p->bindex = bindex;
22516 + p->parent = NULL;
22520 + p->h_dentry = NULL;
22521 + p->h_parent = NULL;
22523 + p->task = current;
22526 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
22527 + unsigned int udba, unsigned char flags)
22529 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
22531 + return au_do_pin(pin);
22534 +/* ---------------------------------------------------------------------- */
22537 + * ->setattr() and ->getattr() are called in various cases.
22538 + * chmod, stat: dentry is revalidated.
22539 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
22541 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
22543 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
22544 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
22547 + struct dentry *parent;
22550 + if (au_digen_test(dentry, sigen)) {
22551 + parent = dget_parent(dentry);
22552 + di_read_lock_parent(parent, AuLock_IR);
22553 + err = au_refresh_dentry(dentry, parent);
22554 + di_read_unlock(parent, AuLock_IR);
22562 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
22563 + struct au_icpup_args *a)
22567 + aufs_bindex_t btop, ibtop;
22568 + struct dentry *hi_wh, *parent;
22569 + struct inode *inode;
22570 + struct au_wr_dir_args wr_dir_args = {
22571 + .force_btgt = -1,
22575 + if (d_is_dir(dentry))
22576 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
22577 + /* plink or hi_wh() case */
22578 + btop = au_dbtop(dentry);
22579 + inode = d_inode(dentry);
22580 + ibtop = au_ibtop(inode);
22581 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
22582 + wr_dir_args.force_btgt = ibtop;
22583 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
22584 + if (unlikely(err < 0))
22588 + au_fset_icpup(a->flags, DID_CPUP);
22591 + a->pin_flags = AuPin_MNT_WRITE;
22593 + if (!IS_ROOT(dentry)) {
22594 + au_fset_pin(a->pin_flags, DI_LOCKED);
22595 + parent = dget_parent(dentry);
22596 + di_write_lock_parent(parent);
22599 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
22600 + if (unlikely(err))
22604 + a->h_path.dentry = au_h_dptr(dentry, btop);
22605 + a->h_inode = d_inode(a->h_path.dentry);
22606 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
22607 + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD);
22608 + if (ia->ia_size < i_size_read(a->h_inode))
22609 + sz = ia->ia_size;
22610 + inode_unlock_shared(a->h_inode);
22614 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
22615 + hi_wh = au_hi_wh(inode, a->btgt);
22617 + struct au_cp_generic cpg = {
22618 + .dentry = dentry,
22624 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
22625 + if (unlikely(err))
22627 + hi_wh = au_hi_wh(inode, a->btgt);
22628 + /* todo: revalidate hi_wh? */
22633 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
22634 + di_downgrade_lock(parent, AuLock_IR);
22638 + if (!au_ftest_icpup(a->flags, DID_CPUP))
22639 + goto out; /* success */
22641 + if (!d_unhashed(dentry)) {
22642 + struct au_cp_generic cpg = {
22643 + .dentry = dentry,
22648 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22650 + err = au_sio_cpup_simple(&cpg);
22652 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22653 + } else if (!hi_wh)
22654 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
22656 + a->h_path.dentry = hi_wh; /* do not dget here */
22659 + a->h_inode = d_inode(a->h_path.dentry);
22661 + goto out; /* success */
22662 + au_unpin(&a->pin);
22665 + di_write_unlock(parent);
22670 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22674 +static int aufs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
22675 + struct iattr *ia)
22678 + struct inode *inode, *delegated;
22679 + struct super_block *sb;
22680 + struct file *file;
22681 + struct au_icpup_args *a;
22682 + struct mnt_idmap *h_idmap;
22684 + inode = d_inode(dentry);
22685 + IMustLock(inode);
22687 + err = setattr_prepare(idmap, dentry, ia);
22688 + if (unlikely(err))
22692 + a = kzalloc(sizeof(*a), GFP_NOFS);
22693 + if (unlikely(!a))
22696 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
22697 + ia->ia_valid &= ~ATTR_MODE;
22700 + sb = dentry->d_sb;
22701 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22702 + if (unlikely(err))
22705 + if (ia->ia_valid & ATTR_FILE) {
22706 + /* currently ftruncate(2) only */
22707 + AuDebugOn(!d_is_reg(dentry));
22708 + file = ia->ia_file;
22709 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1,
22711 + if (unlikely(err))
22713 + ia->ia_file = au_hf_top(file);
22714 + a->udba = AuOpt_UDBA_NONE;
22716 + /* fchmod() doesn't pass ia_file */
22717 + a->udba = au_opt_udba(sb);
22718 + di_write_lock_child(dentry);
22719 + /* no d_unlinked(), to set UDBA_NONE for root */
22720 + if (d_unhashed(dentry))
22721 + a->udba = AuOpt_UDBA_NONE;
22722 + if (a->udba != AuOpt_UDBA_NONE) {
22723 + AuDebugOn(IS_ROOT(dentry));
22724 + err = au_reval_for_attr(dentry, au_sigen(sb));
22725 + if (unlikely(err))
22730 + err = au_pin_and_icpup(dentry, ia, a);
22731 + if (unlikely(err < 0))
22733 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
22734 + ia->ia_file = NULL;
22735 + ia->ia_valid &= ~ATTR_FILE;
22738 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
22739 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
22740 + == (ATTR_MODE | ATTR_CTIME)) {
22741 + err = security_path_chmod(&a->h_path, ia->ia_mode);
22742 + if (unlikely(err))
22744 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
22745 + && (ia->ia_valid & ATTR_CTIME)) {
22746 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
22747 + if (unlikely(err))
22751 + if (ia->ia_valid & ATTR_SIZE) {
22754 + if (ia->ia_size < i_size_read(inode))
22756 + truncate_setsize(inode, ia->ia_size);
22759 + if (ia->ia_valid & ATTR_FILE)
22761 + inode_unlock(a->h_inode);
22762 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
22763 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
22765 + delegated = NULL;
22767 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
22769 + err = break_deleg_wait(&delegated);
22777 + * regardless aufs 'acl' option setting.
22778 + * why don't all acl-aware fs call this func from their ->setattr()?
22780 + if (!err && (ia->ia_valid & ATTR_MODE)) {
22781 + h_idmap = mnt_idmap(a->h_path.mnt);
22782 + err = vfsub_acl_chmod(h_idmap, a->h_path.dentry, ia->ia_mode);
22785 + au_cpup_attr_changeable(inode);
22788 + inode_unlock(a->h_inode);
22789 + au_unpin(&a->pin);
22790 + if (unlikely(err))
22791 + au_update_dbtop(dentry);
22793 + di_write_unlock(dentry);
22795 + fi_write_unlock(file);
22796 + ia->ia_file = file;
22797 + ia->ia_valid |= ATTR_FILE;
22800 + si_read_unlock(sb);
22808 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
22809 +static int au_h_path_to_set_attr(struct dentry *dentry,
22810 + struct au_icpup_args *a, struct path *h_path)
22813 + struct super_block *sb;
22815 + sb = dentry->d_sb;
22816 + a->udba = au_opt_udba(sb);
22817 + /* no d_unlinked(), to set UDBA_NONE for root */
22818 + if (d_unhashed(dentry))
22819 + a->udba = AuOpt_UDBA_NONE;
22820 + if (a->udba != AuOpt_UDBA_NONE) {
22821 + AuDebugOn(IS_ROOT(dentry));
22822 + err = au_reval_for_attr(dentry, au_sigen(sb));
22823 + if (unlikely(err))
22826 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
22827 + if (unlikely(err < 0))
22830 + h_path->dentry = a->h_path.dentry;
22831 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
22837 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
22838 + struct au_sxattr *arg)
22841 + struct path h_path;
22842 + struct super_block *sb;
22843 + struct au_icpup_args *a;
22844 + struct inode *h_inode;
22845 + struct mnt_idmap *h_idmap;
22847 + IMustLock(inode);
22850 + a = kzalloc(sizeof(*a), GFP_NOFS);
22851 + if (unlikely(!a))
22854 + sb = dentry->d_sb;
22855 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
22856 + if (unlikely(err))
22859 + h_path.dentry = NULL; /* silence gcc */
22860 + di_write_lock_child(dentry);
22861 + err = au_h_path_to_set_attr(dentry, a, &h_path);
22862 + if (unlikely(err))
22864 + h_idmap = mnt_idmap(h_path.mnt);
22866 + inode_unlock(a->h_inode);
22867 + switch (arg->type) {
22868 + case AU_XATTR_SET:
22869 + AuDebugOn(d_is_negative(h_path.dentry));
22870 + err = vfsub_setxattr(h_idmap, h_path.dentry,
22871 + arg->u.set.name, arg->u.set.value,
22872 + arg->u.set.size, arg->u.set.flags);
22875 + err = -EOPNOTSUPP;
22876 + h_inode = d_inode(h_path.dentry);
22877 + if (h_inode->i_op->set_acl) {
22878 + /* this will call posix_acl_update_mode */
22879 + err = h_inode->i_op->set_acl(h_idmap, h_path.dentry,
22880 + arg->u.acl_set.acl,
22881 + arg->u.acl_set.type);
22886 + au_cpup_attr_timesizes(inode);
22888 + au_unpin(&a->pin);
22889 + if (unlikely(err))
22890 + au_update_dbtop(dentry);
22893 + di_write_unlock(dentry);
22894 + si_read_unlock(sb);
22903 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
22904 + unsigned int nlink)
22908 + inode->i_mode = st->mode;
22909 + /* don't i_[ug]id_write() here */
22910 + inode->i_uid = st->uid;
22911 + inode->i_gid = st->gid;
22912 + inode->i_atime = st->atime;
22913 + inode->i_mtime = st->mtime;
22914 + inode->i_ctime = st->ctime;
22916 + au_cpup_attr_nlink(inode, /*force*/0);
22917 + if (S_ISDIR(inode->i_mode)) {
22918 + n = inode->i_nlink;
22921 + smp_mb(); /* for i_nlink */
22922 + /* 0 can happen */
22923 + set_nlink(inode, n);
22926 + spin_lock(&inode->i_lock);
22927 + inode->i_blocks = st->blocks;
22928 + i_size_write(inode, st->size);
22929 + spin_unlock(&inode->i_lock);
22933 + * common routine for aufs_getattr() and au_getxattr().
22934 + * returns zero or negative (an error).
22935 + * @dentry will be read-locked in success.
22937 +int au_h_path_getattr(struct dentry *dentry, struct inode *inode, int force,
22938 + struct path *h_path, int locked)
22941 + unsigned int mnt_flags, sigen;
22942 + unsigned char udba_none;
22943 + aufs_bindex_t bindex;
22944 + struct super_block *sb, *h_sb;
22946 + h_path->mnt = NULL;
22947 + h_path->dentry = NULL;
22950 + sb = dentry->d_sb;
22951 + mnt_flags = au_mntflags(sb);
22952 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
22954 + if (unlikely(locked))
22955 + goto body; /* skip locking dinfo */
22957 + /* support fstat(2) */
22958 + if (!d_unlinked(dentry) && !udba_none) {
22959 + sigen = au_sigen(sb);
22960 + err = au_digen_test(dentry, sigen);
22962 + di_read_lock_child(dentry, AuLock_IR);
22963 + err = au_dbrange_test(dentry);
22964 + if (unlikely(err)) {
22965 + di_read_unlock(dentry, AuLock_IR);
22969 + AuDebugOn(IS_ROOT(dentry));
22970 + di_write_lock_child(dentry);
22971 + err = au_dbrange_test(dentry);
22973 + err = au_reval_for_attr(dentry, sigen);
22975 + di_downgrade_lock(dentry, AuLock_IR);
22977 + di_write_unlock(dentry);
22982 + di_read_lock_child(dentry, AuLock_IR);
22986 + inode = d_inode(dentry);
22987 + if (unlikely(!inode))
22990 + bindex = au_ibtop(inode);
22991 + h_path->mnt = au_sbr_mnt(sb, bindex);
22992 + h_sb = h_path->mnt->mnt_sb;
22994 + && !au_test_fs_bad_iattr(h_sb)
22996 + goto out; /* success */
22998 + if (au_dbtop(dentry) == bindex)
22999 + h_path->dentry = au_h_dptr(dentry, bindex);
23000 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
23001 + h_path->dentry = au_plink_lkup(inode, bindex);
23002 + if (IS_ERR(h_path->dentry))
23003 + /* pretending success */
23004 + h_path->dentry = NULL;
23006 + dput(h_path->dentry);
23013 +static int aufs_getattr(struct mnt_idmap *idmap, const struct path *path,
23014 + struct kstat *st, u32 request, unsigned int query)
23017 + unsigned char positive;
23018 + struct path h_path;
23019 + struct dentry *dentry;
23020 + struct inode *inode;
23021 + struct super_block *sb;
23023 + dentry = path->dentry;
23024 + inode = d_inode(dentry);
23025 + sb = dentry->d_sb;
23026 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
23027 + if (unlikely(err))
23029 + err = au_h_path_getattr(dentry, /*inode*/NULL, /*force*/0, &h_path,
23031 + if (unlikely(err))
23033 + if (unlikely(!h_path.dentry))
23034 + /* illegally overlapped or something */
23035 + goto out_fill; /* pretending success */
23037 + positive = d_is_positive(h_path.dentry);
23039 + /* no vfsub version */
23040 + err = vfs_getattr(&h_path, st, request, query);
23043 + au_refresh_iattr(inode, st,
23044 + d_inode(h_path.dentry)->i_nlink);
23045 + goto out_fill; /* success */
23051 + generic_fillattr(idmap, inode, st);
23053 + di_read_unlock(dentry, AuLock_IR);
23055 + si_read_unlock(sb);
23061 +/* ---------------------------------------------------------------------- */
23063 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
23064 + struct delayed_call *done)
23067 + struct dentry *h_dentry;
23068 + struct inode *h_inode;
23070 + aufs_bindex_t bindex;
23072 + ret = NULL; /* suppress a warning */
23077 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
23078 + if (unlikely(err))
23081 + err = au_d_hashed_positive(dentry);
23082 + if (unlikely(err))
23086 + inode = d_inode(dentry);
23087 + bindex = au_ibtop(inode);
23088 + h_inode = au_h_iptr(inode, bindex);
23089 + if (unlikely(!h_inode->i_op->get_link))
23094 + if (au_dbtop(dentry) <= bindex) {
23095 + h_dentry = au_h_dptr(dentry, bindex);
23100 + h_dentry = d_find_any_alias(h_inode);
23101 + if (IS_ERR(h_dentry)) {
23102 + err = PTR_ERR(h_dentry);
23106 + if (unlikely(!h_dentry))
23110 + AuDbg("%ps\n", h_inode->i_op->get_link);
23111 + AuDbgDentry(h_dentry);
23112 + ret = vfs_get_link(h_dentry, done);
23115 + err = PTR_ERR(ret);
23118 + aufs_read_unlock(dentry, AuLock_IR);
23120 + if (unlikely(err))
23121 + ret = ERR_PTR(err);
23122 + AuTraceErrPtr(ret);
23126 +/* ---------------------------------------------------------------------- */
23128 +static int au_is_special(struct inode *inode)
23130 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
23133 +static int aufs_update_time(struct inode *inode, struct timespec64 *ts,
23137 + aufs_bindex_t bindex;
23138 + struct super_block *sb;
23139 + struct inode *h_inode;
23140 + struct vfsmount *h_mnt;
23142 + sb = inode->i_sb;
23143 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
23144 + "unexpected s_flags 0x%lx", sb->s_flags);
23146 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
23148 + si_read_lock(sb, AuLock_FLUSH);
23149 + ii_write_lock_child(inode);
23152 + bindex = au_ibtop(inode);
23153 + h_inode = au_h_iptr(inode, bindex);
23154 + if (!au_test_ro(sb, bindex, inode)) {
23155 + h_mnt = au_sbr_mnt(sb, bindex);
23156 + err = vfsub_mnt_want_write(h_mnt);
23158 + err = vfsub_update_time(h_inode, ts, flags);
23159 + vfsub_mnt_drop_write(h_mnt);
23161 + } else if (au_is_special(h_inode)) {
23163 + * Never copy-up here.
23164 + * These special files may already be opened and used for
23165 + * communicating. If we copied it up, then the communication
23166 + * would be corrupted.
23168 + AuWarn1("timestamps for i%lu are ignored "
23169 + "since it is on readonly branch (hi%lu).\n",
23170 + inode->i_ino, h_inode->i_ino);
23171 + } else if (flags & ~S_ATIME) {
23173 + AuIOErr1("unexpected flags 0x%x\n", flags);
23178 + au_cpup_attr_timesizes(inode);
23179 + ii_write_unlock(inode);
23180 + si_read_unlock(sb);
23183 + if (!err && (flags & S_VERSION))
23184 + inode_inc_iversion(inode);
23189 +/* ---------------------------------------------------------------------- */
23191 +/* no getattr version will be set by module.c:aufs_init() */
23192 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
23194 + [AuIop_SYMLINK] = {
23195 + .permission = aufs_permission,
23196 +#ifdef CONFIG_FS_POSIX_ACL
23197 + .get_inode_acl = aufs_get_inode_acl,
23198 + .get_acl = aufs_get_acl,
23199 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
23202 + .setattr = aufs_setattr,
23203 + .getattr = aufs_getattr,
23205 +#ifdef CONFIG_AUFS_XATTR
23206 + .listxattr = aufs_listxattr,
23209 + .get_link = aufs_get_link
23211 + /* .update_time = aufs_update_time */
23214 + .create = aufs_create,
23215 + .lookup = aufs_lookup,
23216 + .link = aufs_link,
23217 + .unlink = aufs_unlink,
23218 + .symlink = aufs_symlink,
23219 + .mkdir = aufs_mkdir,
23220 + .rmdir = aufs_rmdir,
23221 + .mknod = aufs_mknod,
23222 + .rename = aufs_rename,
23224 + .permission = aufs_permission,
23225 +#ifdef CONFIG_FS_POSIX_ACL
23226 + .get_inode_acl = aufs_get_inode_acl,
23227 + .get_acl = aufs_get_acl,
23228 + .set_acl = aufs_set_acl,
23231 + .setattr = aufs_setattr,
23232 + .getattr = aufs_getattr,
23234 +#ifdef CONFIG_AUFS_XATTR
23235 + .listxattr = aufs_listxattr,
23238 + .update_time = aufs_update_time,
23239 + .atomic_open = aufs_atomic_open,
23240 + .tmpfile = aufs_tmpfile
23242 + [AuIop_OTHER] = {
23243 + .permission = aufs_permission,
23244 +#ifdef CONFIG_FS_POSIX_ACL
23245 + .get_inode_acl = aufs_get_inode_acl,
23246 + .get_acl = aufs_get_acl,
23247 + .set_acl = aufs_set_acl,
23250 + .setattr = aufs_setattr,
23251 + .getattr = aufs_getattr,
23253 +#ifdef CONFIG_AUFS_XATTR
23254 + .listxattr = aufs_listxattr,
23257 + .update_time = aufs_update_time
23260 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
23261 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
23262 +++ linux/fs/aufs/i_op_del.c 2023-08-28 12:34:39.956636132 +0200
23264 +// SPDX-License-Identifier: GPL-2.0
23266 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23268 + * This program is free software; you can redistribute it and/or modify
23269 + * it under the terms of the GNU General Public License as published by
23270 + * the Free Software Foundation; either version 2 of the License, or
23271 + * (at your option) any later version.
23273 + * This program is distributed in the hope that it will be useful,
23274 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23275 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23276 + * GNU General Public License for more details.
23278 + * You should have received a copy of the GNU General Public License
23279 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23283 + * inode operations (del entry)
23286 +#include <linux/iversion.h>
23290 + * decide if a new whiteout for @dentry is necessary or not.
23291 + * when it is necessary, prepare the parent dir for the upper branch whose
23292 + * branch index is @bcpup for creation. the actual creation of the whiteout will
23293 + * be done by caller.
23295 + * 0: wh is unnecessary
23296 + * plus: wh is necessary
23299 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
23301 + int need_wh, err;
23302 + aufs_bindex_t btop;
23303 + struct super_block *sb;
23305 + sb = dentry->d_sb;
23306 + btop = au_dbtop(dentry);
23307 + if (*bcpup < 0) {
23309 + if (au_test_ro(sb, btop, d_inode(dentry))) {
23310 + err = AuWbrCopyup(au_sbi(sb), dentry);
23312 + if (unlikely(err < 0))
23316 + AuDebugOn(btop < *bcpup
23317 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
23318 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
23320 + if (*bcpup != btop) {
23321 + err = au_cpup_dirs(dentry, *bcpup);
23322 + if (unlikely(err))
23326 + struct au_dinfo *dinfo, *tmp;
23328 + need_wh = -ENOMEM;
23329 + dinfo = au_di(dentry);
23330 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
23332 + au_di_cp(tmp, dinfo);
23333 + au_di_swap(tmp, dinfo);
23334 + /* returns the number of positive dentries */
23335 + need_wh = au_lkup_dentry(dentry, btop + 1,
23336 + /* AuLkup_IGNORE_PERM */ 0);
23337 + au_di_swap(tmp, dinfo);
23338 + au_rw_write_unlock(&tmp->di_rwsem);
23342 + AuDbg("need_wh %d\n", need_wh);
23350 + * simple tests for the del-entry operations.
23351 + * following the checks in vfs, plus the parent-child relationship.
23353 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
23354 + struct dentry *h_parent, int isdir)
23358 + struct dentry *h_dentry, *h_latest;
23359 + struct inode *h_inode;
23360 + struct path h_ppath;
23361 + struct super_block *sb;
23362 + struct au_branch *br;
23363 + struct mnt_idmap *h_idmap;
23365 + h_dentry = au_h_dptr(dentry, bindex);
23366 + if (d_really_is_positive(dentry)) {
23368 + if (unlikely(d_is_negative(h_dentry)))
23370 + h_inode = d_inode(h_dentry);
23371 + if (unlikely(!h_inode->i_nlink))
23374 + h_mode = h_inode->i_mode;
23377 + if (unlikely(S_ISDIR(h_mode)))
23379 + } else if (unlikely(!S_ISDIR(h_mode))) {
23384 + /* rename(2) case */
23386 + if (unlikely(d_is_positive(h_dentry)))
23391 + /* expected parent dir is locked */
23392 + if (unlikely(h_parent != h_dentry->d_parent))
23397 + * rmdir a dir may break the consistency on some filesystem.
23398 + * let's try heavy test.
23401 + sb = dentry->d_sb;
23402 + br = au_sbr(sb, bindex);
23403 + h_idmap = au_br_idmap(br);
23404 + if (unlikely(!au_opt_test(au_mntflags(sb), DIRPERM1)
23405 + && au_test_h_perm(h_idmap, d_inode(h_parent),
23406 + MAY_EXEC | MAY_WRITE)))
23409 + h_ppath.dentry = h_parent;
23410 + h_ppath.mnt = au_br_mnt(br);
23411 + h_latest = au_sio_lkup_one(h_idmap, &dentry->d_name, &h_ppath);
23413 + if (IS_ERR(h_latest))
23415 + if (h_latest == h_dentry)
23424 + * decide the branch where we operate for @dentry. the branch index will be set
23425 + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent
23426 + * dir for reverting.
23427 + * when a new whiteout is necessary, create it.
23429 +static struct dentry*
23430 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
23431 + struct au_dtime *dt, struct au_pin *pin)
23433 + struct dentry *wh_dentry;
23434 + struct super_block *sb;
23435 + struct path h_path;
23436 + int err, need_wh;
23437 + unsigned int udba;
23438 + aufs_bindex_t bcpup;
23440 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
23441 + wh_dentry = ERR_PTR(need_wh);
23442 + if (unlikely(need_wh < 0))
23445 + sb = dentry->d_sb;
23446 + udba = au_opt_udba(sb);
23448 + err = au_pin(pin, dentry, bcpup, udba,
23449 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
23450 + wh_dentry = ERR_PTR(err);
23451 + if (unlikely(err))
23454 + h_path.dentry = au_pinned_h_parent(pin);
23455 + if (udba != AuOpt_UDBA_NONE
23456 + && au_dbtop(dentry) == bcpup) {
23457 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
23458 + wh_dentry = ERR_PTR(err);
23459 + if (unlikely(err))
23463 + h_path.mnt = au_sbr_mnt(sb, bcpup);
23464 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
23465 + wh_dentry = NULL;
23467 + goto out; /* success, no need to create whiteout */
23469 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
23470 + if (IS_ERR(wh_dentry))
23473 + /* returns with the parent is locked and wh_dentry is dget-ed */
23474 + goto out; /* success */
23479 + return wh_dentry;
23483 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
23484 + * in order to be revertible and save time for removing many child whiteouts
23486 + * returns 1 when there are too many child whiteout and caller should remove
23487 + * them asynchronously. returns 0 when the number of children is enough small to
23488 + * remove now or the branch fs is a remote fs.
23489 + * otherwise return an error.
23491 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
23492 + struct au_nhash *whlist, struct inode *dir)
23494 + int rmdir_later, err, dirwh;
23495 + struct dentry *h_dentry;
23496 + struct super_block *sb;
23497 + struct inode *inode;
23499 + sb = dentry->d_sb;
23500 + SiMustAnyLock(sb);
23501 + h_dentry = au_h_dptr(dentry, bindex);
23502 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
23503 + if (unlikely(err))
23506 + /* stop monitoring */
23507 + inode = d_inode(dentry);
23508 + au_hn_free(au_hi(inode, bindex));
23510 + if (!au_test_fs_remote(h_dentry->d_sb)) {
23511 + dirwh = au_sbi(sb)->si_dirwh;
23512 + rmdir_later = (dirwh <= 1);
23513 + if (!rmdir_later)
23514 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
23517 + return rmdir_later;
23520 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
23521 + if (unlikely(err)) {
23522 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
23523 + h_dentry, bindex, err);
23533 + * final procedure for deleting a entry.
23534 + * maintain dentry and iattr.
23536 +static void epilog(struct inode *dir, struct dentry *dentry,
23537 + aufs_bindex_t bindex)
23539 + struct inode *inode;
23541 + inode = d_inode(dentry);
23543 + inode->i_ctime = dir->i_ctime;
23545 + au_dir_ts(dir, bindex);
23546 + inode_inc_iversion(dir);
23550 + * when an error happened, remove the created whiteout and revert everything.
23552 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
23553 + aufs_bindex_t bwh, struct dentry *wh_dentry,
23554 + struct dentry *dentry, struct au_dtime *dt)
23557 + struct path h_path = {
23558 + .dentry = wh_dentry,
23559 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
23562 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
23564 + au_set_dbwh(dentry, bwh);
23565 + au_dtime_revert(dt);
23569 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
23573 +/* ---------------------------------------------------------------------- */
23575 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
23578 + aufs_bindex_t bwh, bindex, btop;
23579 + struct inode *inode, *h_dir, *delegated;
23580 + struct dentry *parent, *wh_dentry;
23581 + /* to reduce stack size */
23583 + struct au_dtime dt;
23584 + struct au_pin pin;
23585 + struct path h_path;
23591 + a = kmalloc(sizeof(*a), GFP_NOFS);
23592 + if (unlikely(!a))
23595 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
23596 + if (unlikely(err))
23598 + err = au_d_hashed_positive(dentry);
23599 + if (unlikely(err))
23601 + inode = d_inode(dentry);
23602 + IMustLock(inode);
23604 + if (unlikely(d_is_dir(dentry)))
23605 + goto out_unlock; /* possible? */
23607 + btop = au_dbtop(dentry);
23608 + bwh = au_dbwh(dentry);
23610 + parent = dentry->d_parent; /* dir inode is locked */
23611 + di_write_lock_parent(parent);
23612 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
23614 + err = PTR_ERR(wh_dentry);
23615 + if (IS_ERR(wh_dentry))
23618 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
23619 + a->h_path.dentry = au_h_dptr(dentry, btop);
23620 + dget(a->h_path.dentry);
23621 + if (bindex == btop) {
23622 + h_dir = au_pinned_h_dir(&a->pin);
23623 + delegated = NULL;
23624 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
23625 + if (unlikely(err == -EWOULDBLOCK)) {
23626 + pr_warn("cannot retry for NFSv4 delegation"
23627 + " for an internal unlink\n");
23631 + /* dir inode is locked */
23632 + h_dir = d_inode(wh_dentry->d_parent);
23633 + IMustLock(h_dir);
23638 + vfsub_drop_nlink(inode);
23639 + epilog(dir, dentry, bindex);
23641 + /* update target timestamps */
23642 + if (bindex == btop) {
23643 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
23645 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
23647 + /* todo: this timestamp may be reverted later */
23648 + inode->i_ctime = h_dir->i_ctime;
23649 + goto out_unpin; /* success */
23656 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23663 + au_unpin(&a->pin);
23665 + dput(a->h_path.dentry);
23667 + di_write_unlock(parent);
23669 + aufs_read_unlock(dentry, AuLock_DW);
23676 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
23678 + int err, rmdir_later;
23679 + aufs_bindex_t bwh, bindex, btop;
23680 + struct inode *inode;
23681 + struct dentry *parent, *wh_dentry, *h_dentry;
23682 + struct au_whtmp_rmdir *args;
23683 + /* to reduce stack size */
23685 + struct au_dtime dt;
23686 + struct au_pin pin;
23692 + a = kmalloc(sizeof(*a), GFP_NOFS);
23693 + if (unlikely(!a))
23696 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
23697 + if (unlikely(err))
23699 + err = au_alive_dir(dentry);
23700 + if (unlikely(err))
23702 + inode = d_inode(dentry);
23703 + IMustLock(inode);
23705 + if (unlikely(!d_is_dir(dentry)))
23706 + goto out_unlock; /* possible? */
23709 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
23710 + if (unlikely(!args))
23713 + parent = dentry->d_parent; /* dir inode is locked */
23714 + di_write_lock_parent(parent);
23715 + err = au_test_empty(dentry, &args->whlist);
23716 + if (unlikely(err))
23719 + btop = au_dbtop(dentry);
23720 + bwh = au_dbwh(dentry);
23722 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
23724 + err = PTR_ERR(wh_dentry);
23725 + if (IS_ERR(wh_dentry))
23728 + h_dentry = au_h_dptr(dentry, btop);
23731 + if (bindex == btop) {
23732 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
23734 + rmdir_later = err;
23738 + /* stop monitoring */
23739 + au_hn_free(au_hi(inode, btop));
23741 + /* dir inode is locked */
23742 + IMustLock(d_inode(wh_dentry->d_parent));
23747 + vfsub_dead_dir(inode);
23748 + au_set_dbdiropq(dentry, -1);
23749 + epilog(dir, dentry, bindex);
23751 + if (rmdir_later) {
23752 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
23756 + goto out_unpin; /* success */
23764 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
23771 + au_unpin(&a->pin);
23775 + di_write_unlock(parent);
23777 + au_whtmp_rmdir_free(args);
23779 + aufs_read_unlock(dentry, AuLock_DW);
23786 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
23787 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
23788 +++ linux/fs/aufs/i_op_ren.c 2023-08-28 12:34:39.956636132 +0200
23790 +// SPDX-License-Identifier: GPL-2.0
23792 + * Copyright (C) 2005-2022 Junjiro R. Okajima
23794 + * This program is free software; you can redistribute it and/or modify
23795 + * it under the terms of the GNU General Public License as published by
23796 + * the Free Software Foundation; either version 2 of the License, or
23797 + * (at your option) any later version.
23799 + * This program is distributed in the hope that it will be useful,
23800 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23801 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23802 + * GNU General Public License for more details.
23804 + * You should have received a copy of the GNU General Public License
23805 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23809 + * inode operation (rename entry)
23810 + * todo: this is crazy monster
23813 +#include <linux/iversion.h>
23816 +enum { AuSRC, AuDST, AuSrcDst };
23817 +enum { AuPARENT, AuCHILD, AuParentChild };
23819 +#define AuRen_ISDIR_SRC 1
23820 +#define AuRen_ISDIR_DST (1 << 1)
23821 +#define AuRen_ISSAMEDIR (1 << 2)
23822 +#define AuRen_WHSRC (1 << 3)
23823 +#define AuRen_WHDST (1 << 4)
23824 +#define AuRen_MNT_WRITE (1 << 5)
23825 +#define AuRen_DT_DSTDIR (1 << 6)
23826 +#define AuRen_DIROPQ_SRC (1 << 7)
23827 +#define AuRen_DIROPQ_DST (1 << 8)
23828 +#define AuRen_DIRREN (1 << 9)
23829 +#define AuRen_DROPPED_SRC (1 << 10)
23830 +#define AuRen_DROPPED_DST (1 << 11)
23831 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
23832 +#define au_fset_ren(flags, name) \
23833 + do { (flags) |= AuRen_##name; } while (0)
23834 +#define au_fclr_ren(flags, name) \
23835 + do { (flags) &= ~AuRen_##name; } while (0)
23837 +#ifndef CONFIG_AUFS_DIRREN
23838 +#undef AuRen_DIRREN
23839 +#define AuRen_DIRREN 0
23842 +struct au_ren_args {
23844 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
23846 + struct inode *dir, *inode;
23847 + struct au_hinode *hdir, *hinode;
23848 + struct au_dtime dt[AuParentChild];
23849 + aufs_bindex_t btop, bdiropq;
23852 +#define src_dentry sd[AuSRC].dentry
23853 +#define src_dir sd[AuSRC].dir
23854 +#define src_inode sd[AuSRC].inode
23855 +#define src_h_dentry sd[AuSRC].h_dentry
23856 +#define src_parent sd[AuSRC].parent
23857 +#define src_h_parent sd[AuSRC].h_parent
23858 +#define src_wh_dentry sd[AuSRC].wh_dentry
23859 +#define src_hdir sd[AuSRC].hdir
23860 +#define src_hinode sd[AuSRC].hinode
23861 +#define src_h_dir sd[AuSRC].hdir->hi_inode
23862 +#define src_dt sd[AuSRC].dt
23863 +#define src_btop sd[AuSRC].btop
23864 +#define src_bdiropq sd[AuSRC].bdiropq
23866 +#define dst_dentry sd[AuDST].dentry
23867 +#define dst_dir sd[AuDST].dir
23868 +#define dst_inode sd[AuDST].inode
23869 +#define dst_h_dentry sd[AuDST].h_dentry
23870 +#define dst_parent sd[AuDST].parent
23871 +#define dst_h_parent sd[AuDST].h_parent
23872 +#define dst_wh_dentry sd[AuDST].wh_dentry
23873 +#define dst_hdir sd[AuDST].hdir
23874 +#define dst_hinode sd[AuDST].hinode
23875 +#define dst_h_dir sd[AuDST].hdir->hi_inode
23876 +#define dst_dt sd[AuDST].dt
23877 +#define dst_btop sd[AuDST].btop
23878 +#define dst_bdiropq sd[AuDST].bdiropq
23880 + struct dentry *h_trap;
23881 + struct au_branch *br;
23882 + struct path h_path;
23883 + struct au_nhash whlist;
23884 + aufs_bindex_t btgt, src_bwh;
23887 + unsigned short auren_flags;
23888 + unsigned char flags; /* syscall parameter */
23889 + unsigned char exchange;
23892 + struct au_whtmp_rmdir *thargs;
23893 + struct dentry *h_dst;
23894 + struct au_hinode *h_root;
23897 +/* ---------------------------------------------------------------------- */
23900 + * functions for reverting.
23901 + * when an error happened in a single rename systemcall, we should revert
23902 + * everything as if nothing happened.
23903 + * we don't need to revert the copied-up/down the parent dir since they are
23907 +#define RevertFailure(fmt, ...) do { \
23908 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
23909 + ##__VA_ARGS__, err, rerr); \
23913 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
23916 + struct dentry *d;
23917 +#define src_or_dst(member) a->sd[idx].member
23919 + d = src_or_dst(dentry); /* {src,dst}_dentry */
23920 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
23921 + rerr = au_diropq_remove(d, a->btgt);
23922 + au_hn_inode_unlock(src_or_dst(hinode));
23923 + au_set_dbdiropq(d, src_or_dst(bdiropq));
23925 + RevertFailure("remove diropq %pd", d);
23927 +#undef src_or_dst_
23930 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
23932 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
23933 + au_ren_do_rev_diropq(err, a, AuSRC);
23934 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
23935 + au_ren_do_rev_diropq(err, a, AuDST);
23938 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
23941 + struct inode *delegated;
23942 + struct path h_ppath = {
23943 + .dentry = a->src_h_parent,
23944 + .mnt = a->h_path.mnt
23947 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, &h_ppath);
23948 + rerr = PTR_ERR(a->h_path.dentry);
23949 + if (IS_ERR(a->h_path.dentry)) {
23950 + RevertFailure("lkup one %pd", a->src_dentry);
23954 + delegated = NULL;
23955 + rerr = vfsub_rename(a->dst_h_dir,
23956 + au_h_dptr(a->src_dentry, a->btgt),
23957 + a->src_h_dir, &a->h_path, &delegated, a->flags);
23958 + if (unlikely(rerr == -EWOULDBLOCK)) {
23959 + pr_warn("cannot retry for NFSv4 delegation"
23960 + " for an internal rename\n");
23963 + d_drop(a->h_path.dentry);
23964 + dput(a->h_path.dentry);
23965 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
23967 + RevertFailure("rename %pd", a->src_dentry);
23970 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
23973 + struct inode *delegated;
23974 + struct path h_ppath = {
23975 + .dentry = a->dst_h_parent,
23976 + .mnt = a->h_path.mnt
23979 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, &h_ppath);
23980 + rerr = PTR_ERR(a->h_path.dentry);
23981 + if (IS_ERR(a->h_path.dentry)) {
23982 + RevertFailure("lkup one %pd", a->dst_dentry);
23985 + if (d_is_positive(a->h_path.dentry)) {
23986 + d_drop(a->h_path.dentry);
23987 + dput(a->h_path.dentry);
23991 + delegated = NULL;
23992 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
23993 + &delegated, a->flags);
23994 + if (unlikely(rerr == -EWOULDBLOCK)) {
23995 + pr_warn("cannot retry for NFSv4 delegation"
23996 + " for an internal rename\n");
23999 + d_drop(a->h_path.dentry);
24000 + dput(a->h_path.dentry);
24002 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
24004 + RevertFailure("rename %pd", a->h_dst);
24007 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
24011 + a->h_path.dentry = a->src_wh_dentry;
24012 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
24013 + au_set_dbwh(a->src_dentry, a->src_bwh);
24015 + RevertFailure("unlink %pd", a->src_wh_dentry);
24017 +#undef RevertFailure
24019 +/* ---------------------------------------------------------------------- */
24022 + * when we have to copyup the renaming entry, do it with the rename-target name
24023 + * in order to minimize the cost (the later actual rename is unnecessary).
24024 + * otherwise rename it on the target branch.
24026 +static int au_ren_or_cpup(struct au_ren_args *a)
24029 + struct dentry *d;
24030 + struct inode *delegated;
24032 + d = a->src_dentry;
24033 + if (au_dbtop(d) == a->btgt) {
24034 + a->h_path.dentry = a->dst_h_dentry;
24035 + AuDebugOn(au_dbtop(d) != a->btgt);
24036 + delegated = NULL;
24037 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
24038 + a->dst_h_dir, &a->h_path, &delegated,
24040 + if (unlikely(err == -EWOULDBLOCK)) {
24041 + pr_warn("cannot retry for NFSv4 delegation"
24042 + " for an internal rename\n");
24048 + if (!err && a->h_dst)
24049 + /* it will be set to dinfo later */
24055 +/* cf. aufs_rmdir() */
24056 +static int au_ren_del_whtmp(struct au_ren_args *a)
24059 + struct inode *dir;
24061 + dir = a->dst_dir;
24062 + SiMustAnyLock(dir->i_sb);
24063 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
24064 + au_sbi(dir->i_sb)->si_dirwh)
24065 + || au_test_fs_remote(a->h_dst->d_sb)) {
24066 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
24067 + if (unlikely(err))
24068 + pr_warn("failed removing whtmp dir %pd (%d), "
24069 + "ignored.\n", a->h_dst, err);
24071 + au_nhash_wh_free(&a->thargs->whlist);
24072 + a->thargs->whlist = a->whlist;
24073 + a->whlist.nh_num = 0;
24074 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
24076 + a->thargs = NULL;
24082 +/* make it 'opaque' dir. */
24083 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
24086 + struct dentry *d, *diropq;
24087 +#define src_or_dst(member) a->sd[idx].member
24090 + d = src_or_dst(dentry); /* {src,dst}_dentry */
24091 + src_or_dst(bdiropq) = au_dbdiropq(d);
24092 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
24093 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
24094 + diropq = au_diropq_create(d, a->btgt);
24095 + au_hn_inode_unlock(src_or_dst(hinode));
24096 + if (IS_ERR(diropq))
24097 + err = PTR_ERR(diropq);
24101 +#undef src_or_dst_
24105 +static int au_ren_diropq(struct au_ren_args *a)
24108 + unsigned char always;
24109 + struct dentry *d;
24112 + d = a->dst_dentry; /* already renamed on the branch */
24113 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
24114 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24115 + && !au_ftest_ren(a->auren_flags, DIRREN)
24116 + && a->btgt != au_dbdiropq(a->src_dentry)
24117 + && (a->dst_wh_dentry
24118 + || a->btgt <= au_dbdiropq(d)
24119 + /* hide the lower to keep xino */
24120 + /* the lowers may not be a dir, but we hide them anyway */
24121 + || a->btgt < au_dbbot(d)
24124 + err = au_ren_do_diropq(a, AuSRC);
24125 + if (unlikely(err))
24127 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
24129 + if (!a->exchange)
24130 + goto out; /* success */
24132 + d = a->src_dentry; /* already renamed on the branch */
24133 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24134 + && a->btgt != au_dbdiropq(a->dst_dentry)
24135 + && (a->btgt < au_dbdiropq(d)
24136 + || a->btgt < au_dbbot(d)
24138 + AuDbgDentry(a->src_dentry);
24139 + AuDbgDentry(a->dst_dentry);
24140 + err = au_ren_do_diropq(a, AuDST);
24141 + if (unlikely(err))
24142 + goto out_rev_src;
24143 + au_fset_ren(a->auren_flags, DIROPQ_DST);
24145 + goto out; /* success */
24148 + AuDbg("err %d, reverting src\n", err);
24149 + au_ren_rev_diropq(err, a);
24154 +static int do_rename(struct au_ren_args *a)
24157 + struct dentry *d, *h_d;
24159 + if (!a->exchange) {
24160 + /* prepare workqueue args for asynchronous rmdir */
24161 + h_d = a->dst_h_dentry;
24162 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
24163 + /* && !au_ftest_ren(a->auren_flags, DIRREN) */
24164 + && d_is_positive(h_d)) {
24166 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
24168 + if (unlikely(!a->thargs))
24170 + a->h_dst = dget(h_d);
24173 + /* create whiteout for src_dentry */
24174 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
24175 + a->src_bwh = au_dbwh(a->src_dentry);
24176 + AuDebugOn(a->src_bwh >= 0);
24177 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
24178 + a->src_h_parent);
24179 + err = PTR_ERR(a->src_wh_dentry);
24180 + if (IS_ERR(a->src_wh_dentry))
24184 + /* lookup whiteout for dentry */
24185 + if (au_ftest_ren(a->auren_flags, WHDST)) {
24186 + h_d = au_wh_lkup(a->dst_h_parent,
24187 + &a->dst_dentry->d_name, a->br);
24188 + err = PTR_ERR(h_d);
24191 + if (d_is_negative(h_d))
24194 + a->dst_wh_dentry = h_d;
24197 + /* rename dentry to tmpwh */
24199 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
24200 + if (unlikely(err))
24203 + d = a->dst_dentry;
24204 + au_set_h_dptr(d, a->btgt, NULL);
24205 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
24206 + if (unlikely(err))
24208 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
24212 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
24213 +#if 0 /* debugging */
24214 + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN)
24215 + && d_is_positive(a->dst_h_dentry)
24216 + && a->src_btop != a->btgt);
24219 + /* rename by vfs_rename or cpup */
24220 + err = au_ren_or_cpup(a);
24221 + if (unlikely(err))
24222 + /* leave the copied-up one */
24225 + /* make dir opaque */
24226 + err = au_ren_diropq(a);
24227 + if (unlikely(err))
24230 + /* update target timestamps */
24231 + if (a->exchange) {
24232 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
24233 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
24234 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24235 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24237 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
24238 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
24239 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
24240 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
24242 + if (!a->exchange) {
24243 + /* remove whiteout for dentry */
24244 + if (a->dst_wh_dentry) {
24245 + a->h_path.dentry = a->dst_wh_dentry;
24246 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
24248 + if (unlikely(err))
24252 + /* remove whtmp */
24254 + au_ren_del_whtmp(a); /* ignore this error */
24256 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
24259 + goto out_success;
24262 + au_ren_rev_diropq(err, a);
24264 + au_ren_rev_rename(err, a);
24268 + au_ren_rev_whtmp(err, a);
24270 + dput(a->dst_wh_dentry);
24271 + a->dst_wh_dentry = NULL;
24273 + if (a->src_wh_dentry)
24274 + au_ren_rev_whsrc(err, a);
24276 + dput(a->src_wh_dentry);
24277 + dput(a->dst_wh_dentry);
24281 + au_whtmp_rmdir_free(a->thargs);
24282 + a->thargs = NULL;
24288 +/* ---------------------------------------------------------------------- */
24291 + * test if @dentry dir can be rename destination or not.
24292 + * success means, it is a logically empty dir.
24294 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
24296 + return au_test_empty(dentry, whlist);
24300 + * test if @a->src_dentry dir can be rename source or not.
24301 + * if it can, return 0.
24303 + * - it is a logically empty dir.
24304 + * - or, it exists on writable branch and has no children including whiteouts
24305 + * on the lower branch unless DIRREN is on.
24307 +static int may_rename_srcdir(struct au_ren_args *a)
24310 + unsigned int rdhash;
24311 + aufs_bindex_t btop, btgt;
24312 + struct dentry *dentry;
24313 + struct super_block *sb;
24314 + struct au_sbinfo *sbinfo;
24316 + dentry = a->src_dentry;
24317 + sb = dentry->d_sb;
24318 + sbinfo = au_sbi(sb);
24319 + if (au_opt_test(sbinfo->si_mntflags, DIRREN))
24320 + au_fset_ren(a->auren_flags, DIRREN);
24323 + btop = au_dbtop(dentry);
24324 + if (btop != btgt) {
24325 + struct au_nhash whlist;
24327 + SiMustAnyLock(sb);
24328 + rdhash = sbinfo->si_rdhash;
24330 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
24332 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
24333 + if (unlikely(err))
24335 + err = au_test_empty(dentry, &whlist);
24336 + au_nhash_wh_free(&whlist);
24340 + if (btop == au_dbtaildir(dentry))
24341 + return 0; /* success */
24343 + err = au_test_empty_lower(dentry);
24346 + if (err == -ENOTEMPTY) {
24347 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24350 + AuWarn1("renaming dir who has child(ren) on multiple "
24351 + "branches, is not supported\n");
24358 +/* side effect: sets whlist and h_dentry */
24359 +static int au_ren_may_dir(struct au_ren_args *a)
24362 + unsigned int rdhash;
24363 + struct dentry *d;
24365 + d = a->dst_dentry;
24366 + SiMustAnyLock(d->d_sb);
24369 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
24370 + rdhash = au_sbi(d->d_sb)->si_rdhash;
24372 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
24373 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
24374 + if (unlikely(err))
24377 + if (!a->exchange) {
24378 + au_set_dbtop(d, a->dst_btop);
24379 + err = may_rename_dstdir(d, &a->whlist);
24380 + au_set_dbtop(d, a->btgt);
24382 + err = may_rename_srcdir(a);
24384 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
24385 + if (unlikely(err))
24388 + d = a->src_dentry;
24389 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
24390 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24391 + err = may_rename_srcdir(a);
24392 + if (unlikely(err)) {
24393 + au_nhash_wh_free(&a->whlist);
24394 + a->whlist.nh_num = 0;
24401 +/* ---------------------------------------------------------------------- */
24404 + * simple tests for rename.
24405 + * following the checks in vfs, plus the parent-child relationship.
24407 +static int au_may_ren(struct au_ren_args *a)
24410 + struct inode *h_inode;
24412 + if (a->src_btop == a->btgt) {
24413 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
24414 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
24415 + if (unlikely(err))
24418 + if (unlikely(a->src_h_dentry == a->h_trap))
24423 + if (a->dst_btop != a->btgt)
24426 + err = -ENOTEMPTY;
24427 + if (unlikely(a->dst_h_dentry == a->h_trap))
24431 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
24432 + if (d_really_is_negative(a->dst_dentry)) {
24433 + if (d_is_negative(a->dst_h_dentry))
24434 + err = au_may_add(a->dst_dentry, a->btgt,
24435 + a->dst_h_parent, isdir);
24437 + if (unlikely(d_is_negative(a->dst_h_dentry)))
24439 + h_inode = d_inode(a->dst_h_dentry);
24440 + if (h_inode->i_nlink)
24441 + err = au_may_del(a->dst_dentry, a->btgt,
24442 + a->dst_h_parent, isdir);
24446 + if (unlikely(err == -ENOENT || err == -EEXIST))
24452 +/* ---------------------------------------------------------------------- */
24457 + * - src_dir and dir by lock_rename()
24458 + * - inode if exists
24461 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
24463 + * + di_write_lock2_child()
24464 + * + di_write_lock_child()
24465 + * + ii_write_lock_child()
24466 + * + di_write_lock_child2()
24467 + * + ii_write_lock_child2()
24468 + * + src_parent and parent
24469 + * + di_write_lock_parent()
24470 + * + ii_write_lock_parent()
24471 + * + di_write_lock_parent2()
24472 + * + ii_write_lock_parent2()
24473 + * + lower src_dir and dir by vfsub_lock_rename()
24474 + * + verify the every relationships between child and parent. if any
24475 + * of them failed, unlock all and return -EBUSY.
24477 +static void au_ren_unlock(struct au_ren_args *a)
24479 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
24480 + a->dst_h_parent, a->dst_hdir);
24481 + if (au_ftest_ren(a->auren_flags, DIRREN)
24483 + au_hn_inode_unlock(a->h_root);
24484 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
24485 + vfsub_mnt_drop_write(au_br_mnt(a->br));
24488 +static int au_ren_lock(struct au_ren_args *a)
24491 + unsigned int udba;
24494 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
24495 + a->src_hdir = au_hi(a->src_dir, a->btgt);
24496 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
24497 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
24499 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
24500 + if (unlikely(err))
24502 + au_fset_ren(a->auren_flags, MNT_WRITE);
24503 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24504 + struct dentry *root;
24505 + struct inode *dir;
24508 + * sbinfo is already locked, so this ii_read_lock is
24509 + * unnecessary. but our debugging feature checks it.
24511 + root = a->src_inode->i_sb->s_root;
24512 + if (root != a->src_parent && root != a->dst_parent) {
24513 + dir = d_inode(root);
24514 + ii_read_lock_parent3(dir);
24515 + a->h_root = au_hi(dir, a->btgt);
24516 + ii_read_unlock(dir);
24517 + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3);
24520 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
24521 + a->dst_h_parent, a->dst_hdir);
24522 + udba = au_opt_udba(a->src_dentry->d_sb);
24523 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
24524 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
24525 + err = au_busy_or_stale();
24526 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
24527 + err = au_h_verify(a->src_h_dentry, udba,
24528 + d_inode(a->src_h_parent), a->src_h_parent,
24530 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
24531 + err = au_h_verify(a->dst_h_dentry, udba,
24532 + d_inode(a->dst_h_parent), a->dst_h_parent,
24535 + goto out; /* success */
24537 + err = au_busy_or_stale();
24538 + au_ren_unlock(a);
24544 +/* ---------------------------------------------------------------------- */
24546 +static void au_ren_refresh_dir(struct au_ren_args *a)
24548 + struct inode *dir;
24550 + dir = a->dst_dir;
24551 + inode_inc_iversion(dir);
24552 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
24553 + /* is this updating defined in POSIX? */
24554 + au_cpup_attr_timesizes(a->src_inode);
24555 + au_cpup_attr_nlink(dir, /*force*/1);
24557 + au_dir_ts(dir, a->btgt);
24559 + if (a->exchange) {
24560 + dir = a->src_dir;
24561 + inode_inc_iversion(dir);
24562 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24563 + /* is this updating defined in POSIX? */
24564 + au_cpup_attr_timesizes(a->dst_inode);
24565 + au_cpup_attr_nlink(dir, /*force*/1);
24567 + au_dir_ts(dir, a->btgt);
24570 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
24573 + dir = a->src_dir;
24574 + inode_inc_iversion(dir);
24575 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
24576 + au_cpup_attr_nlink(dir, /*force*/1);
24577 + au_dir_ts(dir, a->btgt);
24580 +static void au_ren_refresh(struct au_ren_args *a)
24582 + aufs_bindex_t bbot, bindex;
24583 + struct dentry *d, *h_d;
24584 + struct inode *i, *h_i;
24585 + struct super_block *sb;
24587 + d = a->dst_dentry;
24590 + /* already dget-ed by au_ren_or_cpup() */
24591 + au_set_h_dptr(d, a->btgt, a->h_dst);
24593 + i = a->dst_inode;
24595 + if (!a->exchange) {
24596 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
24597 + vfsub_drop_nlink(i);
24599 + vfsub_dead_dir(i);
24600 + au_cpup_attr_timesizes(i);
24602 + au_update_dbrange(d, /*do_put_zero*/1);
24604 + au_cpup_attr_nlink(i, /*force*/1);
24607 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
24608 + au_set_h_dptr(d, bindex, NULL);
24609 + bbot = au_dbbot(d);
24610 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
24611 + au_set_h_dptr(d, bindex, NULL);
24612 + au_update_dbrange(d, /*do_put_zero*/0);
24616 + || au_ftest_ren(a->auren_flags, DIRREN)) {
24617 + d_drop(a->src_dentry);
24618 + if (au_ftest_ren(a->auren_flags, DIRREN))
24619 + au_set_dbwh(a->src_dentry, -1);
24623 + d = a->src_dentry;
24624 + au_set_dbwh(d, -1);
24625 + bbot = au_dbbot(d);
24626 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24627 + h_d = au_h_dptr(d, bindex);
24629 + au_set_h_dptr(d, bindex, NULL);
24631 + au_set_dbbot(d, a->btgt);
24634 + i = a->src_inode;
24635 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
24636 + return; /* success */
24638 + bbot = au_ibbot(i);
24639 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
24640 + h_i = au_h_iptr(i, bindex);
24642 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
24643 + /* ignore this error */
24644 + au_set_h_iptr(i, bindex, NULL, 0);
24647 + au_set_ibbot(i, a->btgt);
24650 +/* ---------------------------------------------------------------------- */
24652 +/* mainly for link(2) and rename(2) */
24653 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
24655 + aufs_bindex_t bdiropq, bwh;
24656 + struct dentry *parent;
24657 + struct au_branch *br;
24659 + parent = dentry->d_parent;
24660 + IMustLock(d_inode(parent)); /* dir is locked */
24662 + bdiropq = au_dbdiropq(parent);
24663 + bwh = au_dbwh(dentry);
24664 + br = au_sbr(dentry->d_sb, btgt);
24665 + if (au_br_rdonly(br)
24666 + || (0 <= bdiropq && bdiropq < btgt)
24667 + || (0 <= bwh && bwh < btgt))
24670 + AuDbg("btgt %d\n", btgt);
24674 +/* sets src_btop, dst_btop and btgt */
24675 +static int au_ren_wbr(struct au_ren_args *a)
24678 + struct au_wr_dir_args wr_dir_args = {
24679 + /* .force_btgt = -1, */
24680 + .flags = AuWrDir_ADD_ENTRY
24683 + a->src_btop = au_dbtop(a->src_dentry);
24684 + a->dst_btop = au_dbtop(a->dst_dentry);
24685 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
24686 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
24687 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
24688 + wr_dir_args.force_btgt = a->src_btop;
24689 + if (a->dst_inode && a->dst_btop < a->src_btop)
24690 + wr_dir_args.force_btgt = a->dst_btop;
24691 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
24692 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
24695 + au_update_dbtop(a->dst_dentry);
24700 +static void au_ren_dt(struct au_ren_args *a)
24702 + a->h_path.dentry = a->src_h_parent;
24703 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
24704 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
24705 + a->h_path.dentry = a->dst_h_parent;
24706 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
24709 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
24710 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
24714 + a->h_path.dentry = a->src_h_dentry;
24715 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
24716 + if (d_is_positive(a->dst_h_dentry)) {
24717 + au_fset_ren(a->auren_flags, DT_DSTDIR);
24718 + a->h_path.dentry = a->dst_h_dentry;
24719 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
24723 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
24725 + struct dentry *h_d;
24726 + struct inode *h_inode;
24728 + au_dtime_revert(a->src_dt + AuPARENT);
24729 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
24730 + au_dtime_revert(a->dst_dt + AuPARENT);
24732 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
24733 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
24734 + h_inode = d_inode(h_d);
24735 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24736 + au_dtime_revert(a->src_dt + AuCHILD);
24737 + inode_unlock(h_inode);
24739 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
24740 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
24741 + h_inode = d_inode(h_d);
24742 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
24743 + au_dtime_revert(a->dst_dt + AuCHILD);
24744 + inode_unlock(h_inode);
24749 +/* ---------------------------------------------------------------------- */
24751 +int aufs_rename(struct mnt_idmap *idmap,
24752 + struct inode *_src_dir, struct dentry *_src_dentry,
24753 + struct inode *_dst_dir, struct dentry *_dst_dentry,
24754 + unsigned int _flags)
24756 + int err, lock_flags;
24758 + /* reduce stack space */
24759 + struct au_ren_args *a;
24760 + struct au_pin pin;
24762 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
24763 + IMustLock(_src_dir);
24764 + IMustLock(_dst_dir);
24767 + if (unlikely(_flags & RENAME_WHITEOUT))
24771 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
24772 + a = kzalloc(sizeof(*a), GFP_NOFS);
24773 + if (unlikely(!a))
24776 + a->flags = _flags;
24777 + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8)
24778 + && RENAME_EXCHANGE > U8_MAX);
24779 + a->exchange = _flags & RENAME_EXCHANGE;
24780 + a->src_dir = _src_dir;
24781 + a->src_dentry = _src_dentry;
24782 + a->src_inode = NULL;
24783 + if (d_really_is_positive(a->src_dentry))
24784 + a->src_inode = d_inode(a->src_dentry);
24785 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
24786 + a->dst_dir = _dst_dir;
24787 + a->dst_dentry = _dst_dentry;
24788 + a->dst_inode = NULL;
24789 + if (d_really_is_positive(a->dst_dentry))
24790 + a->dst_inode = d_inode(a->dst_dentry);
24791 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
24792 + if (a->dst_inode) {
24794 + * if EXCHANGE && src is non-dir && dst is dir,
24795 + * dst is not locked.
24797 + /* IMustLock(a->dst_inode); */
24798 + au_igrab(a->dst_inode);
24802 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
24803 + if (d_is_dir(a->src_dentry)) {
24804 + au_fset_ren(a->auren_flags, ISDIR_SRC);
24805 + if (unlikely(!a->exchange
24806 + && d_really_is_positive(a->dst_dentry)
24807 + && !d_is_dir(a->dst_dentry)))
24809 + lock_flags |= AuLock_DIRS;
24811 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
24812 + au_fset_ren(a->auren_flags, ISDIR_DST);
24813 + if (unlikely(!a->exchange
24814 + && d_really_is_positive(a->src_dentry)
24815 + && !d_is_dir(a->src_dentry)))
24817 + lock_flags |= AuLock_DIRS;
24819 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
24821 + if (unlikely(err))
24824 + err = au_d_hashed_positive(a->src_dentry);
24825 + if (unlikely(err))
24828 + if (a->dst_inode) {
24830 + * If it is a dir, VFS unhash it before this
24831 + * function. It means we cannot rely upon d_unhashed().
24833 + if (unlikely(!a->dst_inode->i_nlink))
24835 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
24836 + err = au_d_hashed_positive(a->dst_dentry);
24837 + if (unlikely(err && !a->exchange))
24839 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
24841 + } else if (unlikely(d_unhashed(a->dst_dentry)))
24845 + * is it possible?
24846 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
24847 + * there may exist a problem somewhere else.
24850 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
24853 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
24854 + di_write_lock_parent(a->dst_parent);
24856 + /* which branch we process */
24857 + err = au_ren_wbr(a);
24858 + if (unlikely(err < 0))
24860 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
24861 + a->h_path.mnt = au_br_mnt(a->br);
24863 + /* are they available to be renamed */
24864 + err = au_ren_may_dir(a);
24865 + if (unlikely(err))
24866 + goto out_children;
24868 + /* prepare the writable parent dir on the same branch */
24869 + if (a->dst_btop == a->btgt) {
24870 + au_fset_ren(a->auren_flags, WHDST);
24872 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
24873 + if (unlikely(err))
24874 + goto out_children;
24878 + if (!a->exchange) {
24879 + if (a->src_dir != a->dst_dir) {
24881 + * this temporary unlock is safe,
24882 + * because both dir->i_mutex are locked.
24884 + di_write_unlock(a->dst_parent);
24885 + di_write_lock_parent(a->src_parent);
24886 + err = au_wr_dir_need_wh(a->src_dentry,
24887 + au_ftest_ren(a->auren_flags,
24890 + di_write_unlock(a->src_parent);
24891 + di_write_lock2_parent(a->src_parent, a->dst_parent,
24893 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
24895 + err = au_wr_dir_need_wh(a->src_dentry,
24896 + au_ftest_ren(a->auren_flags,
24900 + if (unlikely(err < 0))
24901 + goto out_children;
24903 + au_fset_ren(a->auren_flags, WHSRC);
24906 + if (a->src_btop != a->btgt) {
24907 + err = au_pin(&pin, a->src_dentry, a->btgt,
24908 + au_opt_udba(a->src_dentry->d_sb),
24909 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24911 + struct au_cp_generic cpg = {
24912 + .dentry = a->src_dentry,
24914 + .bsrc = a->src_btop,
24917 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24919 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
24920 + err = au_sio_cpup_simple(&cpg);
24923 + if (unlikely(err))
24924 + goto out_children;
24925 + a->src_btop = a->btgt;
24926 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
24927 + if (!a->exchange)
24928 + au_fset_ren(a->auren_flags, WHSRC);
24932 + if (a->exchange && a->dst_inode
24933 + && a->dst_btop != a->btgt) {
24934 + err = au_pin(&pin, a->dst_dentry, a->btgt,
24935 + au_opt_udba(a->dst_dentry->d_sb),
24936 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
24938 + struct au_cp_generic cpg = {
24939 + .dentry = a->dst_dentry,
24941 + .bsrc = a->dst_btop,
24944 + .flags = AuCpup_DTIME | AuCpup_HOPEN
24946 + err = au_sio_cpup_simple(&cpg);
24949 + if (unlikely(err))
24950 + goto out_children;
24951 + a->dst_btop = a->btgt;
24952 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
24955 + /* lock them all */
24956 + err = au_ren_lock(a);
24957 + if (unlikely(err))
24958 + /* leave the copied-up one */
24959 + goto out_children;
24961 + if (!a->exchange) {
24962 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
24963 + err = au_may_ren(a);
24964 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
24965 + err = -ENAMETOOLONG;
24966 + if (unlikely(err))
24970 + /* store timestamps to be revertible */
24973 + /* store dirren info */
24974 + if (au_ftest_ren(a->auren_flags, DIRREN)) {
24975 + err = au_dr_rename(a->src_dentry, a->btgt,
24976 + &a->dst_dentry->d_name, &rev);
24978 + if (unlikely(err))
24983 + err = do_rename(a);
24984 + if (unlikely(err))
24987 + if (au_ftest_ren(a->auren_flags, DIRREN))
24988 + au_dr_rename_fin(a->src_dentry, a->btgt, rev);
24990 + /* update dir attributes */
24991 + au_ren_refresh_dir(a);
24993 + /* dput/iput all lower dentries */
24994 + au_ren_refresh(a);
24996 + goto out_hdir; /* success */
24999 + if (au_ftest_ren(a->auren_flags, DIRREN))
25000 + au_dr_rename_rev(a->src_dentry, a->btgt, rev);
25002 + au_ren_rev_dt(err, a);
25004 + au_ren_unlock(a);
25006 + au_nhash_wh_free(&a->whlist);
25007 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
25008 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
25009 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
25010 + au_set_dbtop(a->dst_dentry, a->dst_btop);
25014 + if (d_unhashed(a->src_dentry))
25015 + au_fset_ren(a->auren_flags, DROPPED_SRC);
25016 + if (d_unhashed(a->dst_dentry))
25017 + au_fset_ren(a->auren_flags, DROPPED_DST);
25018 + if (!a->exchange)
25019 + d_move(a->src_dentry, a->dst_dentry);
25021 + d_exchange(a->src_dentry, a->dst_dentry);
25022 + if (au_ftest_ren(a->auren_flags, DROPPED_DST))
25023 + d_drop(a->dst_dentry);
25025 + if (au_ftest_ren(a->auren_flags, DROPPED_SRC))
25026 + d_drop(a->src_dentry);
25028 + au_update_dbtop(a->dst_dentry);
25029 + if (!a->dst_inode)
25030 + d_drop(a->dst_dentry);
25032 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
25033 + di_write_unlock(a->dst_parent);
25035 + di_write_unlock2(a->src_parent, a->dst_parent);
25037 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
25039 + iput(a->dst_inode);
25041 + au_whtmp_rmdir_free(a->thargs);
25047 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
25048 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
25049 +++ linux/fs/aufs/Kconfig 2022-11-05 23:02:18.959222617 +0100
25051 +# SPDX-License-Identifier: GPL-2.0
25053 + tristate "Aufs (Advanced multi layered unification filesystem) support"
25055 + Aufs is a stackable unification filesystem such as Unionfs,
25056 + which unifies several directories and provides a merged single
25058 + In the early days, aufs was entirely re-designed and
25059 + re-implemented Unionfs Version 1.x series. Introducing many
25060 + original ideas, approaches and improvements, it becomes totally
25061 + different from Unionfs while keeping the basic features.
25065 + prompt "Maximum number of branches"
25066 + default AUFS_BRANCH_MAX_127
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.
25071 +config AUFS_BRANCH_MAX_127
25074 + Specifies the maximum number of branches (or member directories)
25075 + in a single aufs. The larger value consumes more system
25076 + resources and has a minor impact to performance.
25077 +config AUFS_BRANCH_MAX_511
25080 + Specifies the maximum number of branches (or member directories)
25081 + in a single aufs. The larger value consumes more system
25082 + resources and has a minor impact to performance.
25083 +config AUFS_BRANCH_MAX_1023
25086 + Specifies the maximum number of branches (or member directories)
25087 + in a single aufs. The larger value consumes more system
25088 + resources and has a minor impact to performance.
25089 +config AUFS_BRANCH_MAX_32767
25092 + Specifies the maximum number of branches (or member directories)
25093 + in a single aufs. The larger value consumes more system
25094 + resources and has a minor impact to performance.
25097 +config AUFS_SBILIST
25099 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
25102 + Automatic configuration for internal use.
25103 + When aufs supports Magic SysRq or /proc, enabled automatically.
25105 +config AUFS_HNOTIFY
25106 + bool "Detect direct branch access (bypassing aufs)"
25108 + If you want to modify files on branches directly, eg. bypassing aufs,
25109 + and want aufs to detect the changes of them fully, then enable this
25110 + option and use 'udba=notify' mount option.
25111 + Currently there is only one available configuration, "fsnotify".
25112 + It will have a negative impact to the performance.
25113 + See detail in aufs.5.
25116 + prompt "method" if AUFS_HNOTIFY
25117 + default AUFS_HFSNOTIFY
25118 +config AUFS_HFSNOTIFY
25123 +config AUFS_EXPORT
25124 + bool "NFS-exportable aufs"
25125 + depends on EXPORTFS
25127 + If you want to export your mounted aufs via NFS, then enable this
25128 + option. There are several requirements for this configuration.
25129 + See detail in aufs.5.
25131 +config AUFS_INO_T_64
25133 + depends on AUFS_EXPORT
25134 + depends on 64BIT && !(ALPHA || S390)
25137 + Automatic configuration for internal use.
25138 + /* typedef unsigned long/int __kernel_ino_t */
25139 + /* alpha and s390x are int */
25142 + bool "support for XATTR/EA (including Security Labels)"
25144 + If your branch fs supports XATTR/EA and you want to make them
25145 + available in aufs too, then enable this opsion and specify the
25146 + branch attributes for EA.
25147 + See detail in aufs.5.
25150 + bool "File-based Hierarchical Storage Management"
25152 + Hierarchical Storage Management (or HSM) is a well-known feature
25153 + in the storage world. Aufs provides this feature as file-based.
25154 + with multiple branches.
25155 + These multiple branches are prioritized, ie. the topmost one
25156 + should be the fastest drive and be used heavily.
25159 + bool "Readdir in userspace"
25161 + Aufs has two methods to provide a merged view for a directory,
25162 + by a user-space library and by kernel-space natively. The latter
25163 + is always enabled but sometimes large and slow.
25164 + If you enable this option, install the library in aufs2-util
25165 + package, and set some environment variables for your readdir(3),
25166 + then the work will be handled in user-space which generally
25167 + shows better performance in most cases.
25168 + See detail in aufs.5.
25170 +config AUFS_DIRREN
25171 + bool "Workaround for rename(2)-ing a directory"
25173 + By default, aufs returns EXDEV error in renameing a dir who has
25174 + his child on the lower branch, since it is a bad idea to issue
25175 + rename(2) internally for every lower branch. But user may not
25176 + accept this behaviour. So here is a workaround to allow such
25177 + rename(2) and store some extra information on the writable
25178 + branch. Obviously this costs high (and I don't like it).
25179 + To use this feature, you need to enable this configuration AND
25180 + to specify the mount option `dirren.'
25181 + See details in aufs.5 and the design documents.
25184 + bool "Show whiteouts"
25186 + If you want to make the whiteouts in aufs visible, then enable
25187 + this option and specify 'shwh' mount option. Although it may
25188 + sounds like philosophy or something, but in technically it
25189 + simply shows the name of whiteout with keeping its behaviour.
25191 +config AUFS_BR_RAMFS
25192 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
25194 + If you want to use ramfs as an aufs branch fs, then enable this
25195 + option. Generally tmpfs is recommended.
25196 + Aufs prohibited them to be a branch fs by default, because
25197 + initramfs becomes unusable after switch_root or something
25198 + generally. If you sets initramfs as an aufs branch and boot your
25199 + system by switch_root, you will meet a problem easily since the
25200 + files in initramfs may be inaccessible.
25201 + Unless you are going to use ramfs as an aufs branch fs without
25202 + switch_root or something, leave it N.
25204 +config AUFS_BR_FUSE
25205 + bool "Fuse fs as an aufs branch"
25206 + depends on FUSE_FS
25209 + If you want to use fuse-based userspace filesystem as an aufs
25210 + branch fs, then enable this option.
25211 + It implements the internal poll(2) operation which is
25212 + implemented by fuse only (curretnly).
25217 + Automatic configuration for internal use.
25219 +config AUFS_BR_HFSPLUS
25220 + bool "Hfsplus as an aufs branch"
25221 + depends on HFSPLUS_FS
25224 + If you want to use hfsplus fs as an aufs branch fs, then enable
25225 + this option. This option introduces a small overhead at
25226 + copying-up a file on hfsplus.
25228 +config AUFS_BDEV_LOOP
25230 + depends on BLK_DEV_LOOP
25233 + Automatic configuration for internal use.
25234 + Convert =[ym] into =y.
25237 + bool "Debug aufs"
25239 + Enable this to compile aufs internal debug code.
25240 + It will have a negative impact to the performance.
25242 +config AUFS_MAGIC_SYSRQ
25244 + depends on AUFS_DEBUG && MAGIC_SYSRQ
25247 + Automatic configuration for internal use.
25248 + When aufs supports Magic SysRq, enabled automatically.
25250 diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h
25251 --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100
25252 +++ linux/fs/aufs/lcnt.h 2022-11-05 23:02:18.965889284 +0100
25254 +/* SPDX-License-Identifier: GPL-2.0 */
25256 + * Copyright (C) 2018-2022 Junjiro R. Okajima
25258 + * This program is free software; you can redistribute it and/or modify
25259 + * it under the terms of the GNU General Public License as published by
25260 + * the Free Software Foundation; either version 2 of the License, or
25261 + * (at your option) any later version.
25263 + * This program is distributed in the hope that it will be useful,
25264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25266 + * GNU General Public License for more details.
25268 + * You should have received a copy of the GNU General Public License
25269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25273 + * simple long counter wrapper
25276 +#ifndef __AUFS_LCNT_H__
25277 +#define __AUFS_LCNT_H__
25281 +#include "debug.h"
25283 +#define AuLCntATOMIC 1
25284 +#define AuLCntPCPUCNT 2
25286 + * why does percpu_refcount require extra synchronize_rcu()s in
25287 + * au_br_do_free()
25289 +#define AuLCntPCPUREF 3
25291 +/* #define AuLCntChosen AuLCntATOMIC */
25292 +#define AuLCntChosen AuLCntPCPUCNT
25293 +/* #define AuLCntChosen AuLCntPCPUREF */
25295 +#if AuLCntChosen == AuLCntATOMIC
25296 +#include <linux/atomic.h>
25298 +typedef atomic_long_t au_lcnt_t;
25300 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25302 + atomic_long_set(cnt, 0);
25306 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25311 +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused,
25312 + int do_sync __maybe_unused)
25317 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25319 + atomic_long_inc(cnt);
25322 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25324 + atomic_long_dec(cnt);
25327 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25329 + return atomic_long_read(cnt);
25333 +#if AuLCntChosen == AuLCntPCPUCNT
25334 +#include <linux/percpu_counter.h>
25336 +typedef struct percpu_counter au_lcnt_t;
25338 +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused)
25340 + return percpu_counter_init(cnt, 0, GFP_NOFS);
25343 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25348 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused)
25350 + percpu_counter_destroy(cnt);
25353 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25355 + percpu_counter_inc(cnt);
25358 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25360 + percpu_counter_dec(cnt);
25363 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused)
25367 + n = percpu_counter_sum(cnt);
25369 + if (LONG_MAX != LLONG_MAX
25371 + AuWarn1("%s\n", "wrap-around");
25377 +#if AuLCntChosen == AuLCntPCPUREF
25378 +#include <linux/percpu-refcount.h>
25380 +typedef struct percpu_ref au_lcnt_t;
25382 +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release)
25385 + release = percpu_ref_exit;
25386 + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS);
25389 +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused)
25391 + synchronize_rcu();
25394 +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync)
25396 + percpu_ref_kill(cnt);
25398 + au_lcnt_wait_for_fin(cnt);
25401 +static inline void au_lcnt_inc(au_lcnt_t *cnt)
25403 + percpu_ref_get(cnt);
25406 +static inline void au_lcnt_dec(au_lcnt_t *cnt)
25408 + percpu_ref_put(cnt);
25412 + * avoid calling this func as possible.
25414 +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev)
25418 + percpu_ref_switch_to_atomic_sync(cnt);
25419 + l = atomic_long_read(&cnt->count);
25421 + percpu_ref_switch_to_percpu(cnt);
25423 + /* percpu_ref is initialized by 1 instead of 0 */
25428 +#ifdef CONFIG_AUFS_DEBUG
25429 +#define AuLCntZero(val) do { \
25432 + AuDbg("%s = %ld\n", #val, l); \
25435 +#define AuLCntZero(val) do {} while (0)
25438 +#endif /* __KERNEL__ */
25439 +#endif /* __AUFS_LCNT_H__ */
25440 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
25441 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
25442 +++ linux/fs/aufs/loop.c 2022-11-05 23:02:18.965889284 +0100
25444 +// SPDX-License-Identifier: GPL-2.0
25446 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25448 + * This program is free software; you can redistribute it and/or modify
25449 + * it under the terms of the GNU General Public License as published by
25450 + * the Free Software Foundation; either version 2 of the License, or
25451 + * (at your option) any later version.
25453 + * This program is distributed in the hope that it will be useful,
25454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25456 + * GNU General Public License for more details.
25458 + * You should have received a copy of the GNU General Public License
25459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25463 + * support for loopback block device as a branch
25468 +/* added into drivers/block/loop.c */
25469 +static struct file *(*backing_file_func)(struct super_block *sb);
25472 + * test if two lower dentries have overlapping branches.
25474 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
25476 + struct super_block *h_sb;
25477 + struct file *backing_file;
25479 + if (unlikely(!backing_file_func)) {
25480 + /* don't load "loop" module here */
25481 + backing_file_func = symbol_get(loop_backing_file);
25482 + if (unlikely(!backing_file_func))
25483 + /* "loop" module is not loaded */
25487 + h_sb = h_adding->d_sb;
25488 + backing_file = backing_file_func(h_sb);
25489 + if (!backing_file)
25492 + h_adding = backing_file->f_path.dentry;
25494 + * h_adding can be local NFS.
25495 + * in this case aufs cannot detect the loop.
25497 + if (unlikely(h_adding->d_sb == sb))
25499 + return !!au_test_subdir(h_adding, sb->s_root);
25502 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
25503 +int au_test_loopback_kthread(void)
25506 + struct task_struct *tsk = current;
25507 + char c, comm[sizeof(tsk->comm)];
25510 + if (tsk->flags & PF_KTHREAD) {
25511 + get_task_comm(comm, tsk);
25513 + ret = ('0' <= c && c <= '9'
25514 + && !strncmp(comm, "loop", 4));
25520 +/* ---------------------------------------------------------------------- */
25522 +#define au_warn_loopback_step 16
25523 +static int au_warn_loopback_nelem = au_warn_loopback_step;
25524 +static unsigned long *au_warn_loopback_array;
25526 +void au_warn_loopback(struct super_block *h_sb)
25528 + int i, new_nelem;
25529 + unsigned long *a, magic;
25530 + static DEFINE_SPINLOCK(spin);
25532 + magic = h_sb->s_magic;
25533 + spin_lock(&spin);
25534 + a = au_warn_loopback_array;
25535 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
25536 + if (a[i] == magic) {
25537 + spin_unlock(&spin);
25541 + /* h_sb is new to us, print it */
25542 + if (i < au_warn_loopback_nelem) {
25547 + /* expand the array */
25548 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
25549 + a = au_kzrealloc(au_warn_loopback_array,
25550 + au_warn_loopback_nelem * sizeof(unsigned long),
25551 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
25552 + /*may_shrink*/0);
25554 + au_warn_loopback_nelem = new_nelem;
25555 + au_warn_loopback_array = a;
25560 + spin_unlock(&spin);
25561 + AuWarn1("realloc failed, ignored\n");
25565 + spin_unlock(&spin);
25566 + pr_warn("you may want to try another patch for loopback file "
25567 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
25570 +int au_loopback_init(void)
25573 + struct super_block *sb __maybe_unused;
25575 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array));
25578 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
25579 + sizeof(unsigned long), GFP_NOFS);
25580 + if (unlikely(!au_warn_loopback_array))
25586 +void au_loopback_fin(void)
25588 + if (backing_file_func)
25589 + symbol_put(loop_backing_file);
25590 + au_kfree_try_rcu(au_warn_loopback_array);
25592 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
25593 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
25594 +++ linux/fs/aufs/loop.h 2022-11-05 23:02:18.965889284 +0100
25596 +/* SPDX-License-Identifier: GPL-2.0 */
25598 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25600 + * This program is free software; you can redistribute it and/or modify
25601 + * it under the terms of the GNU General Public License as published by
25602 + * the Free Software Foundation; either version 2 of the License, or
25603 + * (at your option) any later version.
25605 + * This program is distributed in the hope that it will be useful,
25606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25608 + * GNU General Public License for more details.
25610 + * You should have received a copy of the GNU General Public License
25611 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25615 + * support for loopback mount as a branch
25618 +#ifndef __AUFS_LOOP_H__
25619 +#define __AUFS_LOOP_H__
25624 +struct super_block;
25626 +#ifdef CONFIG_AUFS_BDEV_LOOP
25627 +/* drivers/block/loop.c */
25628 +struct file *loop_backing_file(struct super_block *sb);
25631 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
25632 +int au_test_loopback_kthread(void);
25633 +void au_warn_loopback(struct super_block *h_sb);
25635 +int au_loopback_init(void);
25636 +void au_loopback_fin(void);
25638 +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
25640 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
25641 + struct dentry *h_adding)
25642 +AuStubInt0(au_test_loopback_kthread, void)
25643 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
25645 +AuStubInt0(au_loopback_init, void)
25646 +AuStubVoid(au_loopback_fin, void)
25647 +#endif /* BLK_DEV_LOOP */
25649 +#endif /* __KERNEL__ */
25650 +#endif /* __AUFS_LOOP_H__ */
25651 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
25652 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
25653 +++ linux/fs/aufs/magic.mk 2022-11-05 23:02:18.965889284 +0100
25655 +# SPDX-License-Identifier: GPL-2.0
25657 +# defined in ${srctree}/fs/fuse/inode.c
25659 +ifdef CONFIG_FUSE_FS
25660 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
25663 +# defined in ${srctree}/fs/xfs/xfs_sb.h
25665 +ifdef CONFIG_XFS_FS
25666 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
25669 +# defined in ${srctree}/fs/configfs/mount.c
25671 +ifdef CONFIG_CONFIGFS_FS
25672 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
25675 +# defined in ${srctree}/fs/ubifs/ubifs.h
25677 +ifdef CONFIG_UBIFS_FS
25678 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
25681 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
25683 +ifdef CONFIG_HFSPLUS_FS
25684 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
25686 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
25687 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
25688 +++ linux/fs/aufs/Makefile 2022-11-05 23:02:18.959222617 +0100
25690 +# SPDX-License-Identifier: GPL-2.0
25692 +include ${src}/magic.mk
25693 +ifeq (${CONFIG_AUFS_FS},m)
25694 +include ${src}/conf.mk
25696 +-include ${src}/priv_def.mk
25698 +# cf. include/linux/kernel.h
25700 +ccflags-y += -DDEBUG
25701 +# sparse requires the full pathname
25703 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
25705 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
25708 +obj-$(CONFIG_AUFS_FS) += aufs.o
25709 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o fsctx.o \
25710 + wkq.o vfsub.o dcsub.o \
25711 + cpup.o whout.o wbr_policy.o \
25712 + dinfo.o dentry.o \
25714 + finfo.o file.o f_op.o \
25716 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
25720 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
25721 +aufs-$(CONFIG_SYSFS) += sysfs.o
25722 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
25723 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
25724 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
25725 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
25726 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
25727 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
25728 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
25729 +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o
25730 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
25731 +aufs-$(CONFIG_AUFS_POLL) += poll.o
25732 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
25733 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
25734 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
25735 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
25736 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
25737 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
25738 +++ linux/fs/aufs/module.c 2022-11-05 23:02:18.965889284 +0100
25740 +// SPDX-License-Identifier: GPL-2.0
25742 + * Copyright (C) 2005-2022 Junjiro R. Okajima
25744 + * This program is free software; you can redistribute it and/or modify
25745 + * it under the terms of the GNU General Public License as published by
25746 + * the Free Software Foundation; either version 2 of the License, or
25747 + * (at your option) any later version.
25749 + * This program is distributed in the hope that it will be useful,
25750 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25751 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25752 + * GNU General Public License for more details.
25754 + * You should have received a copy of the GNU General Public License
25755 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25759 + * module global variables and operations
25762 +#include <linux/module.h>
25763 +#include <linux/seq_file.h>
25766 +/* shrinkable realloc */
25767 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
25775 +#if 0 /* unused */
25782 + AuDebugOn(!new_sz);
25785 + diff = au_kmidx_sub(sz, new_sz);
25791 + /* expand or SLOB */
25792 + p = krealloc(p, new_sz, gfp);
25793 + else if (new_sz < sz && may_shrink) {
25797 + q = kmalloc(new_sz, gfp);
25800 + memcpy(q, p, new_sz);
25801 + au_kfree_try_rcu(p);
25812 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
25815 + p = au_krealloc(p, new_sz, gfp, may_shrink);
25816 + if (p && new_sz > nused)
25817 + memset(p + nused, 0, new_sz - nused);
25821 +/* ---------------------------------------------------------------------- */
25825 +struct kmem_cache *au_cache[AuCache_Last];
25827 +static void au_cache_fin(void)
25832 + * Make sure all delayed rcu free inodes are flushed before we
25837 + /* excluding AuCache_HNOTIFY */
25838 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
25839 + for (i = 0; i < AuCache_HNOTIFY; i++) {
25840 + kmem_cache_destroy(au_cache[i]);
25841 + au_cache[i] = NULL;
25845 +static int __init au_cache_init(void)
25847 + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
25848 + if (au_cache[AuCache_DINFO])
25849 + /* SLAB_DESTROY_BY_RCU */
25850 + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
25851 + au_icntnr_init_once);
25852 + if (au_cache[AuCache_ICNTNR])
25853 + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo,
25854 + au_fi_init_once);
25855 + if (au_cache[AuCache_FINFO])
25856 + au_cache[AuCache_VDIR] = AuCache(au_vdir);
25857 + if (au_cache[AuCache_VDIR])
25858 + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
25859 + if (au_cache[AuCache_DEHSTR])
25866 +/* ---------------------------------------------------------------------- */
25868 +int au_dir_roflags;
25870 +#ifdef CONFIG_AUFS_SBILIST
25872 + * iterate_supers_type() doesn't protect us from
25873 + * remounting (branch management)
25875 +struct hlist_bl_head au_sbilist;
25879 + * functions for module interface.
25881 +MODULE_LICENSE("GPL");
25882 +/* MODULE_LICENSE("GPL v2"); */
25883 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
25884 +MODULE_DESCRIPTION(AUFS_NAME
25885 + " -- Advanced multi layered unification filesystem");
25886 +MODULE_VERSION(AUFS_VERSION);
25887 +MODULE_ALIAS_FS(AUFS_NAME);
25889 +/* this module parameter has no meaning when SYSFS is disabled */
25890 +int sysaufs_brs = 1;
25891 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
25892 +module_param_named(brs, sysaufs_brs, int, 0444);
25894 +/* this module parameter has no meaning when USER_NS is disabled */
25896 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
25897 +module_param_named(allow_userns, au_userns, bool, 0444);
25899 +/* ---------------------------------------------------------------------- */
25901 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
25903 +int au_seq_path(struct seq_file *seq, struct path *path)
25907 + err = seq_path(seq, path, au_esc_chars);
25916 +/* ---------------------------------------------------------------------- */
25918 +static int __init aufs_init(void)
25923 + p = au_esc_chars;
25924 + for (i = 1; i <= ' '; i++)
25930 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
25932 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
25933 + for (i = 0; i < AuIop_Last; i++)
25934 + aufs_iop_nogetattr[i].getattr = NULL;
25936 + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */
25938 + au_sbilist_init();
25939 + sysaufs_brs_init();
25942 + err = sysaufs_init();
25943 + if (unlikely(err))
25945 + err = dbgaufs_init();
25946 + if (unlikely(err))
25947 + goto out_sysaufs;
25948 + err = au_procfs_init();
25949 + if (unlikely(err))
25950 + goto out_dbgaufs;
25951 + err = au_wkq_init();
25952 + if (unlikely(err))
25954 + err = au_loopback_init();
25955 + if (unlikely(err))
25957 + err = au_hnotify_init();
25958 + if (unlikely(err))
25959 + goto out_loopback;
25960 + err = au_sysrq_init();
25961 + if (unlikely(err))
25963 + err = au_cache_init();
25964 + if (unlikely(err))
25967 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
25968 + err = register_filesystem(&aufs_fs_type);
25969 + if (unlikely(err))
25972 + /* since we define pr_fmt, call printk directly */
25973 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
25974 + goto out; /* success */
25981 + au_hnotify_fin();
25983 + au_loopback_fin();
25997 +static void __exit aufs_exit(void)
25999 + unregister_filesystem(&aufs_fs_type);
26002 + au_hnotify_fin();
26003 + au_loopback_fin();
26011 +module_init(aufs_init);
26012 +module_exit(aufs_exit);
26013 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
26014 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
26015 +++ linux/fs/aufs/module.h 2022-11-05 23:02:18.969222617 +0100
26017 +/* SPDX-License-Identifier: GPL-2.0 */
26019 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26021 + * This program is free software; you can redistribute it and/or modify
26022 + * it under the terms of the GNU General Public License as published by
26023 + * the Free Software Foundation; either version 2 of the License, or
26024 + * (at your option) any later version.
26026 + * This program is distributed in the hope that it will be useful,
26027 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26028 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26029 + * GNU General Public License for more details.
26031 + * You should have received a copy of the GNU General Public License
26032 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26036 + * module initialization and module-global
26039 +#ifndef __AUFS_MODULE_H__
26040 +#define __AUFS_MODULE_H__
26044 +#include <linux/slab.h>
26045 +#include "debug.h"
26046 +#include "dentry.h"
26049 +#include "inode.h"
26054 +/* module parameters */
26055 +extern int sysaufs_brs;
26056 +extern bool au_userns;
26058 +/* ---------------------------------------------------------------------- */
26060 +extern int au_dir_roflags;
26062 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
26063 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
26067 + * Comparing the size of the object with sizeof(struct rcu_head)
26068 + * case 1: object is always larger
26069 + * --> au_kfree_rcu() or au_kfree_do_rcu()
26070 + * case 2: object is always smaller
26071 + * --> au_kfree_small()
26072 + * case 3: object can be any size
26073 + * --> au_kfree_try_rcu()
26076 +static inline void au_kfree_do_rcu(const void *p)
26079 + struct rcu_head rcu;
26080 + } *a = (void *)p;
26082 + kfree_rcu(a, rcu);
26085 +#define au_kfree_rcu(_p) do { \
26086 + typeof(_p) p = (_p); \
26087 + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \
26089 + au_kfree_do_rcu(p); \
26092 +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head))
26093 +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p)))
26095 +static inline void au_kfree_try_rcu(const void *p)
26099 + if (au_kfree_sz_test(p))
26100 + au_kfree_do_rcu(p);
26105 +static inline void au_kfree_small(const void *p)
26109 + AuDebugOn(au_kfree_sz_test(p));
26113 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
26115 +#ifndef CONFIG_SLOB
26116 + return __kmalloc_index(sz, false) - __kmalloc_index(new_sz, false);
26118 + return -1; /* SLOB is untested */
26122 +int au_seq_path(struct seq_file *seq, struct path *path);
26124 +#ifdef CONFIG_PROC_FS
26126 +int __init au_procfs_init(void);
26127 +void au_procfs_fin(void);
26129 +AuStubInt0(au_procfs_init, void);
26130 +AuStubVoid(au_procfs_fin, void);
26133 +/* ---------------------------------------------------------------------- */
26142 + AuCache_HNOTIFY, /* must be last */
26146 +extern struct kmem_cache *au_cache[AuCache_Last];
26148 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
26149 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
26150 +#define AuCacheCtor(type, ctor) \
26151 + kmem_cache_create(#type, sizeof(struct type), \
26152 + __alignof__(struct type), AuCacheFlags, ctor)
26154 +#define AuCacheFuncAlloc(name, index) \
26155 + static inline struct au_##name *au_cache_alloc_##name(void) \
26156 + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); }
26158 +#define AuCacheFuncs(name, index) \
26159 + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \
26160 + { kmem_cache_free(au_cache[AuCache_##index], p); } \
26162 + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \
26163 + { void *p = rcu; \
26164 + p -= offsetof(struct au_##name, rcu); \
26165 + kmem_cache_free(au_cache[AuCache_##index], p); } \
26166 + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \
26167 + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \
26168 + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \
26170 + static inline void au_cache_free_##name(struct au_##name *p) \
26171 + { /* au_cache_free_##name##_norcu(p); */ \
26172 + au_cache_free_##name##_rcu(p); }
26174 +AuCacheFuncs(dinfo, DINFO);
26175 +AuCacheFuncAlloc(dinfo, DINFO);
26177 +AuCacheFuncs(icntnr, ICNTNR);
26178 +static inline struct au_icntnr *au_cache_alloc_icntnr(struct super_block *sb)
26179 +{ return alloc_inode_sb(sb, au_cache[AuCache_ICNTNR], GFP_NOFS); }
26181 +AuCacheFuncs(finfo, FINFO);
26182 +AuCacheFuncAlloc(finfo, FINFO);
26184 +AuCacheFuncs(vdir, VDIR);
26185 +AuCacheFuncAlloc(vdir, VDIR);
26187 +AuCacheFuncs(vdir_dehstr, DEHSTR);
26188 +AuCacheFuncAlloc(vdir_dehstr, DEHSTR);
26190 +#ifdef CONFIG_AUFS_HNOTIFY
26191 +AuCacheFuncs(hnotify, HNOTIFY);
26192 +AuCacheFuncAlloc(hnotify, HNOTIFY);
26195 +#endif /* __KERNEL__ */
26196 +#endif /* __AUFS_MODULE_H__ */
26197 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
26198 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
26199 +++ linux/fs/aufs/mvdown.c 2022-11-05 23:02:18.969222617 +0100
26201 +// SPDX-License-Identifier: GPL-2.0
26203 + * Copyright (C) 2011-2022 Junjiro R. Okajima
26205 + * This program is free software; you can redistribute it and/or modify
26206 + * it under the terms of the GNU General Public License as published by
26207 + * the Free Software Foundation; either version 2 of the License, or
26208 + * (at your option) any later version.
26210 + * This program is distributed in the hope that it will be useful,
26211 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26212 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26213 + * GNU General Public License for more details.
26215 + * You should have received a copy of the GNU General Public License
26216 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26220 + * move-down, opposite of copy-up
26225 +struct au_mvd_args {
26227 + struct super_block *h_sb;
26228 + struct dentry *h_parent;
26229 + struct au_hinode *hdir;
26230 + struct inode *h_dir, *h_inode;
26231 + struct au_pin pin;
26232 + } info[AUFS_MVDOWN_NARRAY];
26234 + struct aufs_mvdown mvdown;
26235 + struct dentry *dentry, *parent;
26236 + struct inode *inode, *dir;
26237 + struct super_block *sb;
26238 + aufs_bindex_t bopq, bwh, bfound;
26239 + unsigned char rename_lock;
26242 +#define mvd_errno mvdown.au_errno
26243 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
26244 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
26245 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
26246 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
26248 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
26249 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
26250 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
26251 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
26252 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
26253 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
26255 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
26256 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
26257 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
26258 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
26259 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
26260 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
26262 +#define AU_MVD_PR(flag, ...) do { \
26264 + pr_err(__VA_ARGS__); \
26267 +static int find_lower_writable(struct au_mvd_args *a)
26269 + struct super_block *sb;
26270 + aufs_bindex_t bindex, bbot;
26271 + struct au_branch *br;
26274 + bindex = a->mvd_bsrc;
26275 + bbot = au_sbbot(sb);
26276 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
26277 + for (bindex++; bindex <= bbot; bindex++) {
26278 + br = au_sbr(sb, bindex);
26279 + if (au_br_fhsm(br->br_perm)
26280 + && !sb_rdonly(au_br_sb(br)))
26283 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
26284 + for (bindex++; bindex <= bbot; bindex++) {
26285 + br = au_sbr(sb, bindex);
26286 + if (!au_br_rdonly(br))
26290 + for (bindex++; bindex <= bbot; bindex++) {
26291 + br = au_sbr(sb, bindex);
26292 + if (!sb_rdonly(au_br_sb(br))) {
26293 + if (au_br_rdonly(br))
26295 + |= AUFS_MVDOWN_ROLOWER_R;
26303 +/* make the parent dir on bdst */
26304 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
26309 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
26310 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
26311 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
26312 + a->mvd_h_dst_parent = NULL;
26313 + if (au_dbbot(a->parent) >= a->mvd_bdst)
26314 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26315 + if (!a->mvd_h_dst_parent) {
26316 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
26317 + if (unlikely(err)) {
26318 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
26321 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
26329 +/* lock them all */
26330 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
26333 + struct dentry *h_trap;
26335 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
26336 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
26337 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
26338 + au_opt_udba(a->sb),
26339 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26341 + if (unlikely(err)) {
26342 + AU_MVD_PR(dmsg, "pin_dst failed\n");
26346 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
26347 + a->rename_lock = 0;
26348 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26349 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
26350 + au_opt_udba(a->sb),
26351 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26352 + err = au_do_pin(&a->mvd_pin_src);
26354 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26355 + if (unlikely(err)) {
26356 + AU_MVD_PR(dmsg, "pin_src failed\n");
26359 + goto out; /* success */
26362 + a->rename_lock = 1;
26363 + au_pin_hdir_unlock(&a->mvd_pin_dst);
26364 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
26365 + au_opt_udba(a->sb),
26366 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
26368 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
26369 + if (unlikely(err)) {
26370 + AU_MVD_PR(dmsg, "pin_src failed\n");
26371 + au_pin_hdir_lock(&a->mvd_pin_dst);
26374 + au_pin_hdir_unlock(&a->mvd_pin_src);
26375 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26376 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26378 + err = (h_trap != a->mvd_h_src_parent);
26380 + err = (h_trap != a->mvd_h_dst_parent);
26382 + BUG_ON(err); /* it should never happen */
26383 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
26386 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26387 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26388 + au_pin_hdir_lock(&a->mvd_pin_src);
26389 + au_unpin(&a->mvd_pin_src);
26390 + au_pin_hdir_lock(&a->mvd_pin_dst);
26393 + goto out; /* success */
26396 + au_unpin(&a->mvd_pin_dst);
26402 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
26404 + if (!a->rename_lock)
26405 + au_unpin(&a->mvd_pin_src);
26407 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
26408 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
26409 + au_pin_hdir_lock(&a->mvd_pin_src);
26410 + au_unpin(&a->mvd_pin_src);
26411 + au_pin_hdir_lock(&a->mvd_pin_dst);
26413 + au_unpin(&a->mvd_pin_dst);
26416 +/* copy-down the file */
26417 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
26420 + struct au_cp_generic cpg = {
26421 + .dentry = a->dentry,
26422 + .bdst = a->mvd_bdst,
26423 + .bsrc = a->mvd_bsrc,
26425 + .pin = &a->mvd_pin_dst,
26426 + .flags = AuCpup_DTIME | AuCpup_HOPEN
26429 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
26430 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26431 + au_fset_cpup(cpg.flags, OVERWRITE);
26432 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
26433 + au_fset_cpup(cpg.flags, RWDST);
26434 + err = au_sio_cpdown_simple(&cpg);
26435 + if (unlikely(err))
26436 + AU_MVD_PR(dmsg, "cpdown failed\n");
26443 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
26446 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
26449 + struct path h_path;
26450 + struct au_branch *br;
26451 + struct inode *delegated;
26453 + br = au_sbr(a->sb, a->mvd_bdst);
26454 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
26455 + err = PTR_ERR(h_path.dentry);
26456 + if (IS_ERR(h_path.dentry)) {
26457 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
26462 + if (d_is_positive(h_path.dentry)) {
26463 + h_path.mnt = au_br_mnt(br);
26464 + delegated = NULL;
26465 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
26466 + &delegated, /*force*/0);
26467 + if (unlikely(err == -EWOULDBLOCK)) {
26468 + pr_warn("cannot retry for NFSv4 delegation"
26469 + " for an internal unlink\n");
26472 + if (unlikely(err))
26473 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
26475 + dput(h_path.dentry);
26483 + * unlink the topmost h_dentry
26485 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
26488 + struct path h_path;
26489 + struct inode *delegated;
26491 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
26492 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
26493 + delegated = NULL;
26494 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
26495 + if (unlikely(err == -EWOULDBLOCK)) {
26496 + pr_warn("cannot retry for NFSv4 delegation"
26497 + " for an internal unlink\n");
26500 + if (unlikely(err))
26501 + AU_MVD_PR(dmsg, "unlink failed\n");
26507 +/* Since mvdown succeeded, we ignore an error of this function */
26508 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
26511 + struct au_branch *br;
26513 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
26514 + br = au_sbr(a->sb, a->mvd_bsrc);
26515 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
26517 + br = au_sbr(a->sb, a->mvd_bdst);
26518 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
26519 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
26522 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
26524 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
26528 + * copy-down the file and unlink the bsrc file.
26529 + * - unlink the bdst whout if exist
26530 + * - copy-down the file (with whtmp name and rename)
26531 + * - unlink the bsrc file
26533 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
26537 + err = au_do_mkdir(dmsg, a);
26539 + err = au_do_lock(dmsg, a);
26540 + if (unlikely(err))
26544 + * do not revert the activities we made on bdst since they should be
26545 + * harmless in aufs.
26548 + err = au_do_cpdown(dmsg, a);
26550 + err = au_do_unlink_wh(dmsg, a);
26551 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
26552 + err = au_do_unlink(dmsg, a);
26553 + if (unlikely(err))
26556 + AuDbg("%pd2, 0x%x, %d --> %d\n",
26557 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
26558 + if (find_lower_writable(a) < 0)
26559 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
26561 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
26562 + au_do_stfs(dmsg, a);
26564 + /* maintain internal array */
26565 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
26566 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
26567 + au_set_dbtop(a->dentry, a->mvd_bdst);
26568 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
26569 + au_set_ibtop(a->inode, a->mvd_bdst);
26571 + /* hide the lower */
26572 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
26573 + au_set_dbbot(a->dentry, a->mvd_bsrc);
26574 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
26575 + au_set_ibbot(a->inode, a->mvd_bsrc);
26577 + if (au_dbbot(a->dentry) < a->mvd_bdst)
26578 + au_set_dbbot(a->dentry, a->mvd_bdst);
26579 + if (au_ibbot(a->inode) < a->mvd_bdst)
26580 + au_set_ibbot(a->inode, a->mvd_bdst);
26583 + au_do_unlock(dmsg, a);
26589 +/* ---------------------------------------------------------------------- */
26591 +/* make sure the file is idle */
26592 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
26594 + int err, plinked;
26597 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
26598 + if (au_dbtop(a->dentry) == a->mvd_bsrc
26599 + && au_dcount(a->dentry) == 1
26600 + && atomic_read(&a->inode->i_count) == 1
26601 + /* && a->mvd_h_src_inode->i_nlink == 1 */
26602 + && (!plinked || !au_plink_test(a->inode))
26603 + && a->inode->i_nlink == 1)
26608 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
26609 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
26610 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
26611 + a->mvd_h_src_inode->i_nlink,
26612 + plinked, plinked ? au_plink_test(a->inode) : 0);
26619 +/* make sure the parent dir is fine */
26620 +static int au_mvd_args_parent(const unsigned char dmsg,
26621 + struct au_mvd_args *a)
26624 + aufs_bindex_t bindex;
26627 + if (unlikely(au_alive_dir(a->parent))) {
26629 + AU_MVD_PR(dmsg, "parent dir is dead\n");
26633 + a->bopq = au_dbdiropq(a->parent);
26634 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
26635 + AuDbg("b%d\n", bindex);
26636 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
26637 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
26639 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
26640 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
26641 + a->bopq, a->mvd_bdst);
26649 +static int au_mvd_args_intermediate(const unsigned char dmsg,
26650 + struct au_mvd_args *a)
26653 + struct au_dinfo *dinfo, *tmp;
26655 + /* lookup the next lower positive entry */
26657 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
26658 + if (unlikely(!tmp))
26663 + dinfo = au_di(a->dentry);
26664 + au_di_cp(tmp, dinfo);
26665 + au_di_swap(tmp, dinfo);
26667 + /* returns the number of positive dentries */
26668 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
26669 + /* AuLkup_IGNORE_PERM */ 0);
26671 + a->bwh = au_dbwh(a->dentry);
26672 + else if (err > 0)
26673 + a->bfound = au_dbtop(a->dentry);
26675 + au_di_swap(tmp, dinfo);
26676 + au_rw_write_unlock(&tmp->di_rwsem);
26678 + if (unlikely(err < 0))
26679 + AU_MVD_PR(dmsg, "failed look-up lower\n");
26682 + * here, we have these cases.
26684 + * no positive dentry under bsrc. there are more sub-cases.
26686 + * there no whiteout, we can safely move-down.
26689 + * bsrc < bwh && bwh < bdst
26690 + * there is a whiteout on RO branch. cannot proceed.
26692 + * there is a whiteout on the RW target branch. it should
26695 + * there is a whiteout somewhere unrelated branch.
26696 + * -1 < bfound && bfound <= bsrc
26699 + * found, but it is on RO branch between bsrc and bdst. cannot
26702 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
26705 + * found, after we create the file on bdst, it will be hidden.
26708 + AuDebugOn(a->bfound == -1
26710 + && a->bwh <= a->mvd_bsrc);
26711 + AuDebugOn(-1 < a->bfound
26712 + && a->bfound <= a->mvd_bsrc);
26715 + if (a->bfound == -1
26716 + && a->mvd_bsrc < a->bwh
26718 + && a->bwh < a->mvd_bdst) {
26719 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
26720 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
26721 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
26723 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
26724 + a->mvd_errno = EAU_MVDOWN_UPPER;
26725 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
26726 + a->mvd_bdst, a->bfound);
26730 + err = 0; /* success */
26737 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
26742 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
26743 + && a->bfound == a->mvd_bdst)
26749 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
26752 + struct au_branch *br;
26755 + if (unlikely(S_ISDIR(a->inode->i_mode)))
26759 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
26760 + a->mvd_bsrc = au_ibtop(a->inode);
26762 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
26763 + if (unlikely(a->mvd_bsrc < 0
26764 + || (a->mvd_bsrc < au_dbtop(a->dentry)
26765 + || au_dbbot(a->dentry) < a->mvd_bsrc
26766 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
26767 + || (a->mvd_bsrc < au_ibtop(a->inode)
26768 + || au_ibbot(a->inode) < a->mvd_bsrc
26769 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
26770 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
26771 + AU_MVD_PR(dmsg, "no upper\n");
26775 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
26776 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26777 + AU_MVD_PR(dmsg, "on the bottom\n");
26780 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
26781 + br = au_sbr(a->sb, a->mvd_bsrc);
26782 + err = au_br_rdonly(br);
26783 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
26784 + if (unlikely(err))
26786 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
26787 + || IS_APPEND(a->mvd_h_src_inode))) {
26789 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
26795 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
26796 + a->mvd_bdst = find_lower_writable(a);
26797 + if (unlikely(a->mvd_bdst < 0)) {
26798 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
26799 + AU_MVD_PR(dmsg, "no writable lower branch\n");
26803 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
26804 + if (unlikely(a->mvd_bdst < 0
26805 + || au_sbbot(a->sb) < a->mvd_bdst)) {
26806 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
26807 + AU_MVD_PR(dmsg, "no lower brid\n");
26812 + err = au_mvd_args_busy(dmsg, a);
26814 + err = au_mvd_args_parent(dmsg, a);
26816 + err = au_mvd_args_intermediate(dmsg, a);
26818 + err = au_mvd_args_exist(dmsg, a);
26820 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
26827 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
26830 + unsigned char dmsg;
26831 + struct au_mvd_args *args;
26832 + struct inode *inode;
26834 + inode = d_inode(dentry);
26836 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26840 + args = kmalloc(sizeof(*args), GFP_NOFS);
26841 + if (unlikely(!args))
26844 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
26846 + /* VERIFY_WRITE */
26847 + err = !access_ok(uarg, sizeof(*uarg));
26848 + if (unlikely(err)) {
26853 + AuDbg("flags 0x%x\n", args->mvdown.flags);
26854 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
26855 + args->mvdown.au_errno = 0;
26856 + args->dentry = dentry;
26857 + args->inode = inode;
26858 + args->sb = dentry->d_sb;
26861 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
26862 + args->parent = dget_parent(dentry);
26863 + args->dir = d_inode(args->parent);
26864 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
26865 + dput(args->parent);
26866 + if (unlikely(args->parent != dentry->d_parent)) {
26867 + AU_MVD_PR(dmsg, "parent dir is moved\n");
26871 + inode_lock_nested(inode, I_MUTEX_CHILD);
26872 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
26873 + if (unlikely(err))
26876 + di_write_lock_parent(args->parent);
26877 + err = au_mvd_args(dmsg, args);
26878 + if (unlikely(err))
26881 + err = au_do_mvdown(dmsg, args);
26882 + if (unlikely(err))
26885 + au_cpup_attr_timesizes(args->dir);
26886 + au_cpup_attr_timesizes(inode);
26887 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
26888 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
26889 + /* au_digen_dec(dentry); */
26892 + di_write_unlock(args->parent);
26893 + aufs_read_unlock(dentry, AuLock_DW);
26895 + inode_unlock(inode);
26897 + inode_unlock(args->dir);
26899 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
26902 + au_kfree_rcu(args);
26907 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
26908 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
26909 +++ linux/fs/aufs/opts.c 2022-11-05 23:02:18.969222617 +0100
26911 +// SPDX-License-Identifier: GPL-2.0
26913 + * Copyright (C) 2005-2022 Junjiro R. Okajima
26915 + * This program is free software; you can redistribute it and/or modify
26916 + * it under the terms of the GNU General Public License as published by
26917 + * the Free Software Foundation; either version 2 of the License, or
26918 + * (at your option) any later version.
26920 + * This program is distributed in the hope that it will be useful,
26921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26923 + * GNU General Public License for more details.
26925 + * You should have received a copy of the GNU General Public License
26926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26930 + * mount options/flags
26933 +#include <linux/types.h> /* a distribution requires */
26934 +#include <linux/parser.h>
26937 +/* ---------------------------------------------------------------------- */
26939 +static const char *au_parser_pattern(int val, match_table_t tbl)
26941 + struct match_token *p;
26944 + while (p->pattern) {
26945 + if (p->token == val)
26946 + return p->pattern;
26953 +static const char *au_optstr(int *val, match_table_t tbl)
26955 + struct match_token *p;
26962 + while (p->pattern) {
26964 + && (v & p->token) == p->token) {
26965 + *val &= ~p->token;
26966 + return p->pattern;
26975 +/* ---------------------------------------------------------------------- */
26977 +static match_table_t brperm = {
26978 + {AuBrPerm_RO, AUFS_BRPERM_RO},
26979 + {AuBrPerm_RR, AUFS_BRPERM_RR},
26980 + {AuBrPerm_RW, AUFS_BRPERM_RW},
26984 +static match_table_t brattr = {
26986 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
26987 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
26988 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
26989 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
26990 +#ifdef CONFIG_AUFS_FHSM
26991 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
26993 +#ifdef CONFIG_AUFS_XATTR
26994 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
26995 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
26996 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
26997 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
26998 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
26999 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
27002 + /* ro/rr branch */
27003 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
27006 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
27007 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
27012 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
27019 + p = strchr(str, '+');
27022 + v = match_token(str, table, args);
27024 + if (v & AuBrAttr_CMOO_Mask)
27025 + attr &= ~AuBrAttr_CMOO_Mask;
27030 + pr_warn("ignored branch attribute %s\n", str);
27040 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
27048 + p = au_optstr(&perm, brattr);
27051 + memcpy(q, p, sz + 1);
27057 + p = au_optstr(&perm, brattr);
27061 + memcpy(q, p, sz + 1);
27067 + return q - str->a;
27070 +int au_br_perm_val(char *perm)
27072 + int val, bad, sz;
27074 + substring_t args[MAX_OPT_ARGS];
27075 + au_br_perm_str_t attr;
27077 + p = strchr(perm, '+');
27080 + val = match_token(perm, brperm, args);
27084 + pr_warn("ignored branch permission %s\n", perm);
27085 + val = AuBrPerm_RO;
27091 + val |= br_attr_val(p + 1, brattr, args);
27094 + switch (val & AuBrPerm_Mask) {
27095 + case AuBrPerm_RO:
27096 + case AuBrPerm_RR:
27097 + bad = val & AuBrWAttr_Mask;
27098 + val &= ~AuBrWAttr_Mask;
27100 + case AuBrPerm_RW:
27101 + bad = val & AuBrRAttr_Mask;
27102 + val &= ~AuBrRAttr_Mask;
27107 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
27108 + * does not treat it as an error, just warning.
27109 + * this is a tiny guard for the user operation.
27111 + if (val & AuBrAttr_UNPIN) {
27112 + bad |= AuBrAttr_UNPIN;
27113 + val &= ~AuBrAttr_UNPIN;
27116 + if (unlikely(bad)) {
27117 + sz = au_do_optstr_br_attr(&attr, bad);
27119 + pr_warn("ignored branch attribute %s\n", attr.a);
27126 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
27128 + au_br_perm_str_t attr;
27134 + p = au_optstr(&perm, brperm);
27135 + AuDebugOn(!p || !*p);
27137 + memcpy(q, p, sz + 1);
27140 + sz = au_do_optstr_br_attr(&attr, perm);
27143 + memcpy(q, attr.a, sz + 1);
27146 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
27149 +/* ---------------------------------------------------------------------- */
27151 +static match_table_t udbalevel = {
27152 + {AuOpt_UDBA_REVAL, "reval"},
27153 + {AuOpt_UDBA_NONE, "none"},
27154 +#ifdef CONFIG_AUFS_HNOTIFY
27155 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
27156 +#ifdef CONFIG_AUFS_HFSNOTIFY
27157 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
27163 +int au_udba_val(char *str)
27165 + substring_t args[MAX_OPT_ARGS];
27167 + return match_token(str, udbalevel, args);
27170 +const char *au_optstr_udba(int udba)
27172 + return au_parser_pattern(udba, udbalevel);
27175 +/* ---------------------------------------------------------------------- */
27177 +static match_table_t au_wbr_create_policy = {
27178 + {AuWbrCreate_TDP, "tdp"},
27179 + {AuWbrCreate_TDP, "top-down-parent"},
27180 + {AuWbrCreate_RR, "rr"},
27181 + {AuWbrCreate_RR, "round-robin"},
27182 + {AuWbrCreate_MFS, "mfs"},
27183 + {AuWbrCreate_MFS, "most-free-space"},
27184 + {AuWbrCreate_MFSV, "mfs:%d"},
27185 + {AuWbrCreate_MFSV, "most-free-space:%d"},
27187 + /* top-down regardless the parent, and then mfs */
27188 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
27189 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
27191 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
27192 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
27193 + {AuWbrCreate_PMFS, "pmfs"},
27194 + {AuWbrCreate_PMFSV, "pmfs:%d"},
27195 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
27196 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
27201 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
27202 + struct au_opt_wbr_create *create)
27205 + unsigned long long ull;
27208 + if (!match_u64(arg, &ull))
27209 + create->mfsrr_watermark = ull;
27211 + pr_err("bad integer in %s\n", str);
27218 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
27219 + struct au_opt_wbr_create *create)
27224 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
27225 + create->mfs_second = n;
27227 + pr_err("bad integer in %s\n", str);
27234 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
27237 + substring_t args[MAX_OPT_ARGS];
27239 + err = match_token(str, au_wbr_create_policy, args);
27240 + create->wbr_create = err;
27242 + case AuWbrCreate_MFSRRV:
27243 + case AuWbrCreate_TDMFSV:
27244 + case AuWbrCreate_PMFSRRV:
27245 + e = au_wbr_mfs_wmark(&args[0], str, create);
27247 + e = au_wbr_mfs_sec(&args[1], str, create);
27251 + case AuWbrCreate_MFSRR:
27252 + case AuWbrCreate_TDMFS:
27253 + case AuWbrCreate_PMFSRR:
27254 + e = au_wbr_mfs_wmark(&args[0], str, create);
27255 + if (unlikely(e)) {
27260 + case AuWbrCreate_MFS:
27261 + case AuWbrCreate_PMFS:
27262 + create->mfs_second = AUFS_MFS_DEF_SEC;
27264 + case AuWbrCreate_MFSV:
27265 + case AuWbrCreate_PMFSV:
27266 + e = au_wbr_mfs_sec(&args[0], str, create);
27275 +const char *au_optstr_wbr_create(int wbr_create)
27277 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
27280 +static match_table_t au_wbr_copyup_policy = {
27281 + {AuWbrCopyup_TDP, "tdp"},
27282 + {AuWbrCopyup_TDP, "top-down-parent"},
27283 + {AuWbrCopyup_BUP, "bup"},
27284 + {AuWbrCopyup_BUP, "bottom-up-parent"},
27285 + {AuWbrCopyup_BU, "bu"},
27286 + {AuWbrCopyup_BU, "bottom-up"},
27290 +int au_wbr_copyup_val(char *str)
27292 + substring_t args[MAX_OPT_ARGS];
27294 + return match_token(str, au_wbr_copyup_policy, args);
27297 +const char *au_optstr_wbr_copyup(int wbr_copyup)
27299 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
27302 +/* ---------------------------------------------------------------------- */
27304 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
27305 + aufs_bindex_t bindex)
27308 + struct au_opt_add *add = &opt->add;
27311 + add->bindex = bindex;
27312 + add->perm = AuBrPerm_RO;
27313 + add->pathname = opt_str;
27314 + p = strchr(opt_str, '=');
27318 + add->perm = au_br_perm_val(p);
27321 + err = vfsub_kern_path(add->pathname, AuOpt_LkupDirFlags, &add->path);
27324 + add->perm = AuBrPerm_RO;
27325 + if (au_test_fs_rr(add->path.dentry->d_sb))
27326 + add->perm = AuBrPerm_RR;
27327 + else if (!bindex && !(sb_flags & SB_RDONLY))
27328 + add->perm = AuBrPerm_RW;
27330 + opt->type = Opt_add;
27333 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
27340 +static int au_opt_wbr_create(struct super_block *sb,
27341 + struct au_opt_wbr_create *create)
27344 + struct au_sbinfo *sbinfo;
27346 + SiMustWriteLock(sb);
27348 + err = 1; /* handled */
27349 + sbinfo = au_sbi(sb);
27350 + if (sbinfo->si_wbr_create_ops->fin) {
27351 + err = sbinfo->si_wbr_create_ops->fin(sb);
27356 + sbinfo->si_wbr_create = create->wbr_create;
27357 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
27358 + switch (create->wbr_create) {
27359 + case AuWbrCreate_MFSRRV:
27360 + case AuWbrCreate_MFSRR:
27361 + case AuWbrCreate_TDMFS:
27362 + case AuWbrCreate_TDMFSV:
27363 + case AuWbrCreate_PMFSRR:
27364 + case AuWbrCreate_PMFSRRV:
27365 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
27367 + case AuWbrCreate_MFS:
27368 + case AuWbrCreate_MFSV:
27369 + case AuWbrCreate_PMFS:
27370 + case AuWbrCreate_PMFSV:
27371 + sbinfo->si_wbr_mfs.mfs_expire
27372 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
27376 + if (sbinfo->si_wbr_create_ops->init)
27377 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
27384 + * plus: processed without an error
27385 + * zero: unprocessed
27387 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
27388 + struct au_opts *opts)
27391 + struct au_sbinfo *sbinfo;
27393 + SiMustWriteLock(sb);
27395 + err = 1; /* handled */
27396 + sbinfo = au_sbi(sb);
27397 + switch (opt->type) {
27399 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27400 + sbinfo->si_mntflags |= opt->udba;
27401 + opts->given_udba |= opt->udba;
27406 + au_opt_set(sbinfo->si_mntflags, PLINK);
27408 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27409 + au_plink_put(sb, /*verbose*/1);
27410 + au_opt_clr(sbinfo->si_mntflags, PLINK);
27413 + case Opt_list_plink:
27414 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27415 + au_plink_list(sb);
27420 + au_opt_set(sbinfo->si_mntflags, DIO);
27421 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27423 + au_opt_clr(sbinfo->si_mntflags, DIO);
27424 + au_fset_opts(opts->flags, REFRESH_DYAOP);
27428 + case Opt_fhsm_sec:
27429 + au_fhsm_set(sbinfo, opt->fhsm_second);
27432 + case Opt_diropq_a:
27433 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27435 + case Opt_diropq_w:
27436 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
27439 + case Opt_warn_perm:
27441 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
27443 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
27446 + case Opt_verbose:
27448 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
27450 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
27455 + au_opt_set(sbinfo->si_mntflags, SUM);
27457 + au_opt_clr(sbinfo->si_mntflags, SUM);
27458 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
27462 + au_opt_clr(sbinfo->si_mntflags, SUM);
27463 + au_opt_set(sbinfo->si_mntflags, SUM_W);
27466 + case Opt_wbr_create:
27467 + err = au_opt_wbr_create(sb, &opt->wbr_create);
27469 + case Opt_wbr_copyup:
27470 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
27471 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
27475 + sbinfo->si_dirwh = opt->dirwh;
27478 + case Opt_rdcache:
27479 + sbinfo->si_rdcache
27480 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
27483 + sbinfo->si_rdblk = opt->rdblk;
27486 + sbinfo->si_rdhash = opt->rdhash;
27491 + au_opt_set(sbinfo->si_mntflags, SHWH);
27493 + au_opt_clr(sbinfo->si_mntflags, SHWH);
27496 + case Opt_dirperm1:
27498 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
27500 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
27503 + case Opt_trunc_xino:
27505 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
27507 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
27510 + case Opt_trunc_xino_path:
27511 + case Opt_itrunc_xino:
27512 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex,
27518 + case Opt_trunc_xib:
27520 + au_fset_opts(opts->flags, TRUNC_XIB);
27522 + au_fclr_opts(opts->flags, TRUNC_XIB);
27528 + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27529 + err = au_dr_opt_set(sb);
27534 + au_opt_set(sbinfo->si_mntflags, DIRREN);
27536 + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) {
27537 + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags,
27543 + au_opt_clr(sbinfo->si_mntflags, DIRREN);
27549 + sb->s_flags |= SB_POSIXACL;
27551 + sb->s_flags &= ~SB_POSIXACL;
27563 + * returns tri-state.
27564 + * plus: processed without an error
27565 + * zero: unprocessed
27568 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
27569 + struct au_opts *opts)
27571 + int err, do_refresh;
27574 + switch (opt->type) {
27576 + opt->add.bindex = au_sbbot(sb) + 1;
27577 + if (opt->add.bindex < 0)
27578 + opt->add.bindex = 0;
27580 + /* Always goto add, not fallthrough */
27581 + case Opt_prepend:
27582 + opt->add.bindex = 0;
27584 + add: /* indented label */
27586 + err = au_br_add(sb, &opt->add,
27587 + au_ftest_opts(opts->flags, REMOUNT));
27590 + au_fset_opts(opts->flags, REFRESH);
27596 + err = au_br_del(sb, &opt->del,
27597 + au_ftest_opts(opts->flags, REMOUNT));
27600 + au_fset_opts(opts->flags, TRUNC_XIB);
27601 + au_fset_opts(opts->flags, REFRESH);
27607 + err = au_br_mod(sb, &opt->mod,
27608 + au_ftest_opts(opts->flags, REMOUNT),
27613 + au_fset_opts(opts->flags, REFRESH);
27620 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
27621 + struct au_opt_xino **opt_xino,
27622 + struct au_opts *opts)
27627 + switch (opt->type) {
27629 + err = au_xino_set(sb, &opt->xino,
27630 + !!au_ftest_opts(opts->flags, REMOUNT));
27632 + *opt_xino = &opt->xino;
27636 + *opt_xino = (void *)-1;
27643 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
27644 + unsigned int pending)
27647 + aufs_bindex_t bindex, bbot;
27648 + unsigned char do_plink, skip, do_free, can_no_dreval;
27649 + struct au_branch *br;
27650 + struct au_wbr *wbr;
27651 + struct dentry *root, *dentry;
27652 + struct inode *dir, *h_dir;
27653 + struct au_sbinfo *sbinfo;
27654 + struct au_hinode *hdir;
27656 + SiMustAnyLock(sb);
27658 + sbinfo = au_sbi(sb);
27659 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
27661 + if (!(sb_flags & SB_RDONLY)) {
27662 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
27663 + pr_warn("first branch should be rw\n");
27664 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
27665 + pr_warn_once("shwh should be used with ro\n");
27668 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
27669 + && !au_opt_test(sbinfo->si_mntflags, XINO))
27670 + pr_warn_once("udba=*notify requires xino\n");
27672 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
27673 + pr_warn_once("dirperm1 breaks the protection"
27674 + " by the permission bits on the lower branch\n");
27678 + root = sb->s_root;
27679 + dir = d_inode(root);
27680 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
27681 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
27683 + bbot = au_sbbot(sb);
27684 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
27686 + h_dir = au_h_iptr(dir, bindex);
27687 + br = au_sbr(sb, bindex);
27689 + if ((br->br_perm & AuBrAttr_ICEX)
27690 + && !h_dir->i_op->listxattr)
27691 + br->br_perm &= ~AuBrAttr_ICEX;
27692 +#if 0 /* untested */
27693 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
27694 + && (au_br_sb(br)->s_flags & SB_NOSEC))
27695 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
27699 + wbr = br->br_wbr;
27701 + wbr_wh_read_lock(wbr);
27703 + if (!au_br_writable(br->br_perm)) {
27706 + || (!wbr->wbr_whbase
27707 + && !wbr->wbr_plink
27708 + && !wbr->wbr_orph));
27709 + } else if (!au_br_wh_linkable(br->br_perm)) {
27710 + /* skip = (!br->br_whbase && !br->br_orph); */
27711 + skip = (!wbr || !wbr->wbr_whbase);
27712 + if (skip && wbr) {
27714 + skip = !!wbr->wbr_plink;
27716 + skip = !wbr->wbr_plink;
27719 + /* skip = (br->br_whbase && br->br_ohph); */
27720 + skip = (wbr && wbr->wbr_whbase);
27723 + skip = !!wbr->wbr_plink;
27725 + skip = !wbr->wbr_plink;
27729 + wbr_wh_read_unlock(wbr);
27731 + if (can_no_dreval) {
27732 + dentry = br->br_path.dentry;
27733 + spin_lock(&dentry->d_lock);
27734 + if (dentry->d_flags &
27735 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
27736 + can_no_dreval = 0;
27737 + spin_unlock(&dentry->d_lock);
27740 + if (au_br_fhsm(br->br_perm)) {
27742 + AuDebugOn(!br->br_fhsm);
27748 + hdir = au_hi(dir, bindex);
27749 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
27751 + wbr_wh_write_lock(wbr);
27752 + err = au_wh_init(br, sb);
27754 + wbr_wh_write_unlock(wbr);
27755 + au_hn_inode_unlock(hdir);
27757 + if (!err && do_free) {
27758 + au_kfree_rcu(wbr);
27759 + br->br_wbr = NULL;
27763 + if (can_no_dreval)
27764 + au_fset_si(sbinfo, NO_DREVAL);
27766 + au_fclr_si(sbinfo, NO_DREVAL);
27769 + au_fset_si(sbinfo, FHSM);
27770 + for (bindex = bbot; bindex >= 0; bindex--) {
27771 + br = au_sbr(sb, bindex);
27772 + if (au_br_fhsm(br->br_perm)) {
27773 + au_fhsm_set_bottom(sb, bindex);
27778 + au_fclr_si(sbinfo, FHSM);
27779 + au_fhsm_set_bottom(sb, -1);
27785 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
27788 + unsigned int tmp;
27789 + aufs_bindex_t bindex, bbot;
27790 + struct au_opt *opt;
27791 + struct au_opt_xino *opt_xino, xino;
27792 + struct au_sbinfo *sbinfo;
27793 + struct au_branch *br;
27794 + struct inode *dir;
27796 + SiMustWriteLock(sb);
27801 + while (err >= 0 && opt->type != Opt_tail)
27802 + err = au_opt_simple(sb, opt++, opts);
27805 + else if (unlikely(err < 0))
27808 + /* disable xino and udba temporary */
27809 + sbinfo = au_sbi(sb);
27810 + tmp = sbinfo->si_mntflags;
27811 + au_opt_clr(sbinfo->si_mntflags, XINO);
27812 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
27815 + while (err >= 0 && opt->type != Opt_tail)
27816 + err = au_opt_br(sb, opt++, opts);
27819 + else if (unlikely(err < 0))
27822 + bbot = au_sbbot(sb);
27823 + if (unlikely(bbot < 0)) {
27825 + pr_err("no branches\n");
27829 + if (au_opt_test(tmp, XINO))
27830 + au_opt_set(sbinfo->si_mntflags, XINO);
27832 + while (!err && opt->type != Opt_tail)
27833 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
27834 + if (unlikely(err))
27837 + err = au_opts_verify(sb, sb->s_flags, tmp);
27838 + if (unlikely(err))
27841 + /* restore xino */
27842 + if (au_opt_test(tmp, XINO) && !opt_xino) {
27843 + xino.file = au_xino_def(sb);
27844 + err = PTR_ERR(xino.file);
27845 + if (IS_ERR(xino.file))
27848 + err = au_xino_set(sb, &xino, /*remount*/0);
27850 + if (unlikely(err))
27854 + /* restore udba */
27855 + tmp &= AuOptMask_UDBA;
27856 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
27857 + sbinfo->si_mntflags |= tmp;
27858 + bbot = au_sbbot(sb);
27859 + for (bindex = 0; bindex <= bbot; bindex++) {
27860 + br = au_sbr(sb, bindex);
27861 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
27862 + if (unlikely(err))
27863 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27865 + /* go on even if err */
27867 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
27868 + dir = d_inode(sb->s_root);
27869 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
27876 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
27879 + unsigned char no_dreval;
27880 + struct inode *dir;
27881 + struct au_opt_xino *opt_xino;
27882 + struct au_opt *opt;
27883 + struct au_sbinfo *sbinfo;
27885 + SiMustWriteLock(sb);
27887 + err = au_dr_opt_flush(sb);
27888 + if (unlikely(err))
27890 + au_fset_opts(opts->flags, DR_FLUSHED);
27892 + dir = d_inode(sb->s_root);
27893 + sbinfo = au_sbi(sb);
27896 + while (err >= 0 && opt->type != Opt_tail) {
27897 + err = au_opt_simple(sb, opt, opts);
27899 + err = au_opt_br(sb, opt, opts);
27901 + err = au_opt_xino(sb, opt, &opt_xino, opts);
27907 + /* go on even err */
27909 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
27910 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
27911 + if (unlikely(rerr && !err))
27914 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
27915 + au_fset_opts(opts->flags, REFRESH_IDOP);
27917 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
27918 + rerr = au_xib_trunc(sb);
27919 + if (unlikely(rerr && !err))
27923 + /* will be handled by the caller */
27924 + if (!au_ftest_opts(opts->flags, REFRESH)
27925 + && (opts->given_udba
27926 + || au_opt_test(sbinfo->si_mntflags, XINO)
27927 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
27929 + au_fset_opts(opts->flags, REFRESH);
27931 + AuDbg("status 0x%x\n", opts->flags);
27937 +/* ---------------------------------------------------------------------- */
27939 +unsigned int au_opt_udba(struct super_block *sb)
27941 + return au_mntflags(sb) & AuOptMask_UDBA;
27943 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
27944 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
27945 +++ linux/fs/aufs/opts.h 2022-11-05 23:02:18.969222617 +0100
27947 +/* SPDX-License-Identifier: GPL-2.0 */
27949 + * Copyright (C) 2005-2022 Junjiro R. Okajima
27951 + * This program is free software; you can redistribute it and/or modify
27952 + * it under the terms of the GNU General Public License as published by
27953 + * the Free Software Foundation; either version 2 of the License, or
27954 + * (at your option) any later version.
27956 + * This program is distributed in the hope that it will be useful,
27957 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27958 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27959 + * GNU General Public License for more details.
27961 + * You should have received a copy of the GNU General Public License
27962 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27966 + * mount options/flags
27969 +#ifndef __AUFS_OPTS_H__
27970 +#define __AUFS_OPTS_H__
27974 +#include <linux/fs_parser.h>
27975 +#include <linux/namei.h>
27976 +#include <linux/path.h>
27980 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
27981 + Opt_idel, Opt_imod,
27982 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
27983 + Opt_xino, Opt_noxino,
27984 + Opt_trunc_xino, Opt_trunc_xino_v,
27985 + Opt_trunc_xino_path, Opt_itrunc_xino,
27988 + Opt_plink, Opt_list_plink,
27991 + Opt_diropq, Opt_diropq_a, Opt_diropq_w,
27993 + Opt_wbr_copyup, Opt_wbr_create,
27995 + Opt_verbose, Opt_noverbose,
27996 + Opt_sum, Opt_wsum,
28000 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
28003 +/* ---------------------------------------------------------------------- */
28006 +#define AuOpt_XINO 1 /* external inode number bitmap
28007 + and translation table */
28008 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
28009 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
28010 +#define AuOpt_UDBA_REVAL (1 << 3)
28011 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
28012 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
28013 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
28014 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
28016 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
28017 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
28018 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
28019 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
28020 +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */
28021 +#define AuOpt_DIO (1 << 14) /* direct io */
28022 +#define AuOpt_DIRREN (1 << 15) /* directory rename */
28024 +#ifndef CONFIG_AUFS_HNOTIFY
28025 +#undef AuOpt_UDBA_HNOTIFY
28026 +#define AuOpt_UDBA_HNOTIFY 0
28028 +#ifndef CONFIG_AUFS_DIRREN
28029 +#undef AuOpt_DIRREN
28030 +#define AuOpt_DIRREN 0
28032 +#ifndef CONFIG_AUFS_SHWH
28034 +#define AuOpt_SHWH 0
28037 +#define AuOpt_Def (AuOpt_XINO \
28038 + | AuOpt_UDBA_REVAL \
28040 + /* | AuOpt_DIRPERM1 */ \
28041 + | AuOpt_WARN_PERM)
28042 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
28043 + | AuOpt_UDBA_REVAL \
28044 + | AuOpt_UDBA_HNOTIFY)
28046 +#define AuOpt_LkupDirFlags (LOOKUP_FOLLOW | LOOKUP_DIRECTORY)
28048 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
28049 +#define au_opt_set(flags, name) do { \
28050 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
28051 + ((flags) |= AuOpt_##name); \
28053 +#define au_opt_set_udba(flags, name) do { \
28054 + (flags) &= ~AuOptMask_UDBA; \
28055 + ((flags) |= AuOpt_##name); \
28057 +#define au_opt_clr(flags, name) do { \
28058 + ((flags) &= ~AuOpt_##name); \
28061 +static inline unsigned int au_opts_plink(unsigned int mntflags)
28063 +#ifdef CONFIG_PROC_FS
28066 + return mntflags & ~AuOpt_PLINK;
28070 +/* ---------------------------------------------------------------------- */
28072 +/* policies to select one among multiple writable branches */
28074 + AuWbrCreate_TDP, /* top down parent */
28075 + AuWbrCreate_RR, /* round robin */
28076 + AuWbrCreate_MFS, /* most free space */
28077 + AuWbrCreate_MFSV, /* mfs with seconds */
28078 + AuWbrCreate_MFSRR, /* mfs then rr */
28079 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
28080 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
28081 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
28082 + AuWbrCreate_PMFS, /* parent and mfs */
28083 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
28084 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
28085 + AuWbrCreate_PMFSRRV, /* plus seconds */
28087 + AuWbrCreate_Def = AuWbrCreate_TDP
28091 + AuWbrCopyup_TDP, /* top down parent */
28092 + AuWbrCopyup_BUP, /* bottom up parent */
28093 + AuWbrCopyup_BU, /* bottom up */
28095 + AuWbrCopyup_Def = AuWbrCopyup_TDP
28098 +/* ---------------------------------------------------------------------- */
28102 +struct au_opt_add {
28103 + aufs_bindex_t bindex;
28106 + struct path path;
28109 +struct au_opt_del {
28111 + struct path h_path;
28114 +struct au_opt_mod {
28117 + struct dentry *h_root;
28120 +struct au_opt_xino {
28122 + struct file *file;
28125 +struct au_opt_xino_itrunc {
28126 + aufs_bindex_t bindex;
28129 +struct au_opt_wbr_create {
28132 + unsigned long long mfsrr_watermark;
28138 + struct au_opt_xino xino;
28139 + struct au_opt_xino_itrunc xino_itrunc;
28140 + struct au_opt_add add;
28141 + struct au_opt_del del;
28142 + struct au_opt_mod mod;
28145 + unsigned int rdblk;
28146 + unsigned int rdhash;
28148 + struct au_opt_wbr_create wbr_create;
28150 + unsigned int fhsm_second;
28151 + bool tf; /* generic flag, true or false */
28156 +#define AuOpts_REMOUNT 1
28157 +#define AuOpts_REFRESH (1 << 1)
28158 +#define AuOpts_TRUNC_XIB (1 << 2)
28159 +#define AuOpts_REFRESH_DYAOP (1 << 3)
28160 +#define AuOpts_REFRESH_IDOP (1 << 4)
28161 +#define AuOpts_DR_FLUSHED (1 << 5)
28162 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
28163 +#define au_fset_opts(flags, name) \
28164 + do { (flags) |= AuOpts_##name; } while (0)
28165 +#define au_fclr_opts(flags, name) \
28166 + do { (flags) &= ~AuOpts_##name; } while (0)
28168 +#ifndef CONFIG_AUFS_DIRREN
28169 +#undef AuOpts_DR_FLUSHED
28170 +#define AuOpts_DR_FLUSHED 0
28174 + struct au_opt *opt;
28177 + unsigned int given_udba;
28178 + unsigned int flags;
28179 + unsigned long sb_flags;
28182 +/* ---------------------------------------------------------------------- */
28185 +int au_br_perm_val(char *perm);
28186 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
28187 +int au_udba_val(char *str);
28188 +const char *au_optstr_udba(int udba);
28189 +int au_wbr_create_val(char *str, struct au_opt_wbr_create *create);
28190 +const char *au_optstr_wbr_create(int wbr_create);
28191 +int au_wbr_copyup_val(char *str);
28192 +const char *au_optstr_wbr_copyup(int wbr_copyup);
28194 +int au_opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
28195 + aufs_bindex_t bindex);
28196 +struct super_block;
28197 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
28198 + unsigned int pending);
28199 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
28200 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
28202 +unsigned int au_opt_udba(struct super_block *sb);
28205 +int aufs_fsctx_init(struct fs_context *fc);
28206 +extern const struct fs_parameter_spec aufs_fsctx_paramspec[];
28208 +#endif /* __KERNEL__ */
28209 +#endif /* __AUFS_OPTS_H__ */
28210 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
28211 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
28212 +++ linux/fs/aufs/plink.c 2022-11-05 23:02:18.969222617 +0100
28214 +// SPDX-License-Identifier: GPL-2.0
28216 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28218 + * This program is free software; you can redistribute it and/or modify
28219 + * it under the terms of the GNU General Public License as published by
28220 + * the Free Software Foundation; either version 2 of the License, or
28221 + * (at your option) any later version.
28223 + * This program is distributed in the hope that it will be useful,
28224 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28225 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28226 + * GNU General Public License for more details.
28228 + * You should have received a copy of the GNU General Public License
28229 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28239 + * the pseudo-link maintenance mode.
28240 + * during a user process maintains the pseudo-links,
28241 + * prohibit adding a new plink and branch manipulation.
28245 + * For entry functions which will handle plink, and i_mutex is already held
28247 + * They cannot wait and should return an error at once.
28248 + * Callers has to check the error.
28250 + * For entry functions which will handle plink, but i_mutex is not held
28252 + * They can wait the plink maintenance mode to finish.
28254 + * They behave like F_SETLK and F_SETLKW.
28255 + * If the caller never handle plink, then both flags are unnecessary.
28258 +int au_plink_maint(struct super_block *sb, int flags)
28262 + struct task_struct *parent, *prev;
28263 + struct au_sbinfo *sbi;
28265 + SiMustAnyLock(sb);
28268 + if (!au_opt_test(au_mntflags(sb), PLINK))
28271 + sbi = au_sbi(sb);
28272 + pid = sbi->si_plink_maint_pid;
28273 + if (!pid || pid == current->pid)
28276 + /* todo: it highly depends upon /sbin/mount.aufs */
28278 + parent = current;
28282 + parent = rcu_dereference(parent->real_parent);
28283 + if (parent == prev)
28285 + ppid = task_pid_vnr(parent);
28286 + if (pid == ppid) {
28287 + rcu_read_unlock();
28292 + rcu_read_unlock();
28294 + if (au_ftest_lock(flags, NOPLMW)) {
28295 + /* if there is no i_mutex lock in VFS, we don't need to wait */
28296 + /* AuDebugOn(!lockdep_depth(current)); */
28297 + while (sbi->si_plink_maint_pid) {
28298 + si_read_unlock(sb);
28299 + /* gave up wake_up_bit() */
28300 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
28302 + if (au_ftest_lock(flags, FLUSH))
28303 + au_nwt_flush(&sbi->si_nowait);
28304 + si_noflush_read_lock(sb);
28306 + } else if (au_ftest_lock(flags, NOPLM)) {
28307 + AuDbg("ppid %d, pid %d\n", ppid, pid);
28315 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
28317 + spin_lock(&sbinfo->si_plink_maint_lock);
28318 + sbinfo->si_plink_maint_pid = 0;
28319 + spin_unlock(&sbinfo->si_plink_maint_lock);
28320 + wake_up_all(&sbinfo->si_plink_wq);
28323 +int au_plink_maint_enter(struct super_block *sb)
28326 + struct au_sbinfo *sbinfo;
28329 + sbinfo = au_sbi(sb);
28330 + /* make sure i am the only one in this fs */
28331 + si_write_lock(sb, AuLock_FLUSH);
28332 + if (au_opt_test(au_mntflags(sb), PLINK)) {
28333 + spin_lock(&sbinfo->si_plink_maint_lock);
28334 + if (!sbinfo->si_plink_maint_pid)
28335 + sbinfo->si_plink_maint_pid = current->pid;
28338 + spin_unlock(&sbinfo->si_plink_maint_lock);
28340 + si_write_unlock(sb);
28345 +/* ---------------------------------------------------------------------- */
28347 +#ifdef CONFIG_AUFS_DEBUG
28348 +void au_plink_list(struct super_block *sb)
28351 + struct au_sbinfo *sbinfo;
28352 + struct hlist_bl_head *hbl;
28353 + struct hlist_bl_node *pos;
28354 + struct au_icntnr *icntnr;
28356 + SiMustAnyLock(sb);
28358 + sbinfo = au_sbi(sb);
28359 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28360 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28362 + for (i = 0; i < AuPlink_NHASH; i++) {
28363 + hbl = sbinfo->si_plink + i;
28364 + hlist_bl_lock(hbl);
28365 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28366 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
28367 + hlist_bl_unlock(hbl);
28372 +/* is the inode pseudo-linked? */
28373 +int au_plink_test(struct inode *inode)
28376 + struct au_sbinfo *sbinfo;
28377 + struct hlist_bl_head *hbl;
28378 + struct hlist_bl_node *pos;
28379 + struct au_icntnr *icntnr;
28381 + sbinfo = au_sbi(inode->i_sb);
28382 + AuRwMustAnyLock(&sbinfo->si_rwsem);
28383 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
28384 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28387 + i = au_plink_hash(inode->i_ino);
28388 + hbl = sbinfo->si_plink + i;
28389 + hlist_bl_lock(hbl);
28390 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink)
28391 + if (&icntnr->vfs_inode == inode) {
28395 + hlist_bl_unlock(hbl);
28399 +/* ---------------------------------------------------------------------- */
28402 + * generate a name for plink.
28403 + * the file will be stored under AUFS_WH_PLINKDIR.
28405 +/* 20 is max digits length of ulong 64 */
28406 +#define PLINK_NAME_LEN ((20 + 1) * 2)
28408 +static int plink_name(char *name, int len, struct inode *inode,
28409 + aufs_bindex_t bindex)
28412 + struct inode *h_inode;
28414 + h_inode = au_h_iptr(inode, bindex);
28415 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
28419 +struct au_do_plink_lkup_args {
28420 + struct dentry **errp;
28421 + struct qstr *tgtname;
28422 + struct path *h_ppath;
28425 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
28426 + struct path *h_ppath)
28428 + struct dentry *h_dentry;
28429 + struct inode *h_inode;
28431 + h_inode = d_inode(h_ppath->dentry);
28432 + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2);
28433 + h_dentry = vfsub_lkup_one(tgtname, h_ppath);
28434 + inode_unlock_shared(h_inode);
28439 +static void au_call_do_plink_lkup(void *args)
28441 + struct au_do_plink_lkup_args *a = args;
28442 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_ppath);
28445 +/* lookup the plink-ed @inode under the branch at @bindex */
28446 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
28448 + struct dentry *h_dentry;
28449 + struct au_branch *br;
28450 + struct path h_ppath;
28452 + char a[PLINK_NAME_LEN];
28453 + struct qstr tgtname = QSTR_INIT(a, 0);
28455 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
28457 + br = au_sbr(inode->i_sb, bindex);
28458 + h_ppath.dentry = br->br_wbr->wbr_plink;
28459 + h_ppath.mnt = au_br_mnt(br);
28460 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28462 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28463 + struct au_do_plink_lkup_args args = {
28464 + .errp = &h_dentry,
28465 + .tgtname = &tgtname,
28466 + .h_ppath = &h_ppath
28469 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
28470 + if (unlikely(wkq_err))
28471 + h_dentry = ERR_PTR(wkq_err);
28473 + h_dentry = au_do_plink_lkup(&tgtname, &h_ppath);
28478 +/* create a pseudo-link */
28479 +static int do_whplink(struct qstr *tgt, struct path *h_ppath,
28480 + struct dentry *h_dentry)
28483 + struct path h_path;
28484 + struct inode *h_dir, *delegated;
28486 + h_dir = d_inode(h_ppath->dentry);
28487 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
28488 + h_path.mnt = h_ppath->mnt;
28490 + h_path.dentry = vfsub_lkup_one(tgt, h_ppath);
28491 + err = PTR_ERR(h_path.dentry);
28492 + if (IS_ERR(h_path.dentry))
28496 + /* wh.plink dir is not monitored */
28497 + /* todo: is it really safe? */
28498 + if (d_is_positive(h_path.dentry)
28499 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
28500 + delegated = NULL;
28501 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
28502 + if (unlikely(err == -EWOULDBLOCK)) {
28503 + pr_warn("cannot retry for NFSv4 delegation"
28504 + " for an internal unlink\n");
28507 + dput(h_path.dentry);
28508 + h_path.dentry = NULL;
28512 + if (!err && d_is_negative(h_path.dentry)) {
28513 + delegated = NULL;
28514 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
28515 + if (unlikely(err == -EWOULDBLOCK)) {
28516 + pr_warn("cannot retry for NFSv4 delegation"
28517 + " for an internal link\n");
28521 + dput(h_path.dentry);
28524 + inode_unlock(h_dir);
28528 +struct do_whplink_args {
28530 + struct qstr *tgt;
28531 + struct path *h_ppath;
28532 + struct dentry *h_dentry;
28535 +static void call_do_whplink(void *args)
28537 + struct do_whplink_args *a = args;
28538 + *a->errp = do_whplink(a->tgt, a->h_ppath, a->h_dentry);
28541 +static int whplink(struct dentry *h_dentry, struct inode *inode,
28542 + aufs_bindex_t bindex)
28544 + int err, wkq_err;
28545 + struct au_branch *br;
28546 + struct au_wbr *wbr;
28547 + struct path h_ppath;
28548 + char a[PLINK_NAME_LEN];
28549 + struct qstr tgtname = QSTR_INIT(a, 0);
28551 + br = au_sbr(inode->i_sb, bindex);
28552 + wbr = br->br_wbr;
28553 + h_ppath.dentry = wbr->wbr_plink;
28554 + h_ppath.mnt = au_br_mnt(br);
28555 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
28557 + /* always superio. */
28558 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
28559 + struct do_whplink_args args = {
28562 + .h_ppath = &h_ppath,
28563 + .h_dentry = h_dentry
28565 + wkq_err = au_wkq_wait(call_do_whplink, &args);
28566 + if (unlikely(wkq_err))
28569 + err = do_whplink(&tgtname, &h_ppath, h_dentry);
28575 + * create a new pseudo-link for @h_dentry on @bindex.
28576 + * the linked inode is held in aufs @inode.
28578 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
28579 + struct dentry *h_dentry)
28581 + struct super_block *sb;
28582 + struct au_sbinfo *sbinfo;
28583 + struct hlist_bl_head *hbl;
28584 + struct hlist_bl_node *pos;
28585 + struct au_icntnr *icntnr;
28586 + int found, err, cnt, i;
28588 + sb = inode->i_sb;
28589 + sbinfo = au_sbi(sb);
28590 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28591 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28593 + found = au_plink_test(inode);
28597 + i = au_plink_hash(inode->i_ino);
28598 + hbl = sbinfo->si_plink + i;
28601 + hlist_bl_lock(hbl);
28602 + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) {
28603 + if (&icntnr->vfs_inode == inode) {
28609 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
28610 + hlist_bl_add_head(&icntnr->plink, hbl);
28612 + hlist_bl_unlock(hbl);
28614 + cnt = au_hbl_count(hbl);
28615 +#define msg "unexpectedly unbalanced or too many pseudo-links"
28616 + if (cnt > AUFS_PLINK_WARN)
28617 + AuWarn1(msg ", %d\n", cnt);
28619 + err = whplink(h_dentry, inode, bindex);
28620 + if (unlikely(err)) {
28621 + pr_warn("err %d, damaged pseudo link.\n", err);
28622 + au_hbl_del(&icntnr->plink, hbl);
28623 + iput(&icntnr->vfs_inode);
28626 + iput(&icntnr->vfs_inode);
28629 +/* free all plinks */
28630 +void au_plink_put(struct super_block *sb, int verbose)
28633 + struct au_sbinfo *sbinfo;
28634 + struct hlist_bl_head *hbl;
28635 + struct hlist_bl_node *pos, *tmp;
28636 + struct au_icntnr *icntnr;
28638 + SiMustWriteLock(sb);
28640 + sbinfo = au_sbi(sb);
28641 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28642 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28644 + /* no spin_lock since sbinfo is write-locked */
28646 + for (i = 0; i < AuPlink_NHASH; i++) {
28647 + hbl = sbinfo->si_plink + i;
28648 + if (!warned && verbose && !hlist_bl_empty(hbl)) {
28649 + pr_warn("pseudo-link is not flushed");
28652 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink)
28653 + iput(&icntnr->vfs_inode);
28654 + INIT_HLIST_BL_HEAD(hbl);
28658 +void au_plink_clean(struct super_block *sb, int verbose)
28660 + struct dentry *root;
28662 + root = sb->s_root;
28663 + aufs_write_lock(root);
28664 + if (au_opt_test(au_mntflags(sb), PLINK))
28665 + au_plink_put(sb, verbose);
28666 + aufs_write_unlock(root);
28669 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
28672 + aufs_bindex_t btop, bbot, bindex;
28675 + btop = au_ibtop(inode);
28676 + bbot = au_ibbot(inode);
28678 + for (bindex = btop; bindex <= bbot; bindex++) {
28679 + if (!au_h_iptr(inode, bindex)
28680 + || au_ii_br_id(inode, bindex) != br_id)
28682 + au_set_h_iptr(inode, bindex, NULL, 0);
28687 + for (bindex = btop; bindex <= bbot; bindex++)
28688 + if (au_h_iptr(inode, bindex)) {
28698 +/* free the plinks on a branch specified by @br_id */
28699 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
28701 + struct au_sbinfo *sbinfo;
28702 + struct hlist_bl_head *hbl;
28703 + struct hlist_bl_node *pos, *tmp;
28704 + struct au_icntnr *icntnr;
28705 + struct inode *inode;
28708 + SiMustWriteLock(sb);
28710 + sbinfo = au_sbi(sb);
28711 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
28712 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
28714 + /* no bit_lock since sbinfo is write-locked */
28715 + for (i = 0; i < AuPlink_NHASH; i++) {
28716 + hbl = sbinfo->si_plink + i;
28717 + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) {
28718 + inode = au_igrab(&icntnr->vfs_inode);
28719 + ii_write_lock_child(inode);
28720 + do_put = au_plink_do_half_refresh(inode, br_id);
28722 + hlist_bl_del(&icntnr->plink);
28725 + ii_write_unlock(inode);
28730 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
28731 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
28732 +++ linux/fs/aufs/poll.c 2022-11-05 23:02:18.969222617 +0100
28734 +// SPDX-License-Identifier: GPL-2.0
28736 + * Copyright (C) 2005-2022 Junjiro R. Okajima
28738 + * This program is free software; you can redistribute it and/or modify
28739 + * it under the terms of the GNU General Public License as published by
28740 + * the Free Software Foundation; either version 2 of the License, or
28741 + * (at your option) any later version.
28743 + * This program is distributed in the hope that it will be useful,
28744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28746 + * GNU General Public License for more details.
28748 + * You should have received a copy of the GNU General Public License
28749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28754 + * There is only one filesystem which implements ->poll operation, currently.
28759 +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt)
28762 + struct file *h_file;
28763 + struct super_block *sb;
28765 + /* We should pretend an error happened. */
28766 + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */;
28767 + sb = file->f_path.dentry->d_sb;
28768 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
28770 + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0);
28771 + if (IS_ERR(h_file)) {
28772 + AuDbg("h_file %ld\n", PTR_ERR(h_file));
28776 + mask = vfs_poll(h_file, pt);
28777 + fput(h_file); /* instead of au_read_post() */
28780 + si_read_unlock(sb);
28781 + if (mask & EPOLLERR)
28782 + AuDbg("mask 0x%x\n", mask);
28785 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
28786 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
28787 +++ linux/fs/aufs/posix_acl.c 2023-08-28 12:34:39.959969465 +0200
28789 +// SPDX-License-Identifier: GPL-2.0
28791 + * Copyright (C) 2014-2022 Junjiro R. Okajima
28793 + * This program is free software; you can redistribute it and/or modify
28794 + * it under the terms of the GNU General Public License as published by
28795 + * the Free Software Foundation; either version 2 of the License, or
28796 + * (at your option) any later version.
28798 + * This program is distributed in the hope that it will be useful,
28799 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28800 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28801 + * GNU General Public License for more details.
28803 + * You should have received a copy of the GNU General Public License
28804 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28808 + * posix acl operations
28811 +#include <linux/fs.h>
28814 +struct posix_acl *aufs_get_inode_acl(struct inode *inode, int type, bool rcu)
28816 + struct posix_acl *acl;
28818 + aufs_bindex_t bindex;
28819 + struct inode *h_inode;
28820 + struct super_block *sb;
28822 + acl = ERR_PTR(-ECHILD);
28827 + sb = inode->i_sb;
28828 + si_read_lock(sb, AuLock_FLUSH);
28829 + ii_read_lock_child(inode);
28830 + if (!(sb->s_flags & SB_POSIXACL))
28833 + bindex = au_ibtop(inode);
28834 + h_inode = au_h_iptr(inode, bindex);
28835 + if (unlikely(!h_inode
28836 + || ((h_inode->i_mode & S_IFMT)
28837 + != (inode->i_mode & S_IFMT)))) {
28838 + err = au_busy_or_stale();
28839 + acl = ERR_PTR(err);
28843 + /* always topmost only */
28844 + acl = get_inode_acl(h_inode, type);
28846 + forget_cached_acl(inode, type);
28848 + set_cached_acl(inode, type, acl);
28851 + ii_read_unlock(inode);
28852 + si_read_unlock(sb);
28855 + AuTraceErrPtr(acl);
28859 +struct posix_acl *aufs_get_acl(struct mnt_idmap *idmap,
28860 + struct dentry *dentry, int type)
28862 + struct posix_acl *acl;
28863 + struct inode *inode;
28865 + inode = d_inode(dentry);
28866 + acl = aufs_get_inode_acl(inode, type, /*rcu*/false);
28871 +int aufs_set_acl(struct mnt_idmap *idmap, struct dentry *dentry,
28872 + struct posix_acl *acl, int type)
28876 + struct inode *inode;
28877 + struct au_sxattr arg = {
28878 + .type = AU_ACL_SET,
28885 + inode = d_inode(dentry);
28886 + IMustLock(inode);
28888 + ssz = au_sxattr(dentry, inode, &arg);
28889 + /* forget even it if succeeds since the branch might set differently */
28890 + forget_cached_acl(inode, type);
28897 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
28898 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
28899 +++ linux/fs/aufs/procfs.c 2022-11-05 23:02:18.969222617 +0100
28901 +// SPDX-License-Identifier: GPL-2.0
28903 + * Copyright (C) 2010-2022 Junjiro R. Okajima
28905 + * This program is free software; you can redistribute it and/or modify
28906 + * it under the terms of the GNU General Public License as published by
28907 + * the Free Software Foundation; either version 2 of the License, or
28908 + * (at your option) any later version.
28910 + * This program is distributed in the hope that it will be useful,
28911 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28912 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28913 + * GNU General Public License for more details.
28915 + * You should have received a copy of the GNU General Public License
28916 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28920 + * procfs interfaces
28923 +#include <linux/proc_fs.h>
28926 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
28928 + struct au_sbinfo *sbinfo;
28930 + sbinfo = file->private_data;
28932 + au_plink_maint_leave(sbinfo);
28933 + kobject_put(&sbinfo->si_kobj);
28939 +static void au_procfs_plm_write_clean(struct file *file)
28941 + struct au_sbinfo *sbinfo;
28943 + sbinfo = file->private_data;
28945 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
28948 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
28951 + struct super_block *sb;
28952 + struct au_sbinfo *sbinfo;
28953 + struct hlist_bl_node *pos;
28956 + if (unlikely(file->private_data))
28960 + /* don't use au_sbilist_lock() here */
28961 + hlist_bl_lock(&au_sbilist);
28962 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
28963 + if (id == sysaufs_si_id(sbinfo)) {
28964 + if (kobject_get_unless_zero(&sbinfo->si_kobj))
28965 + sb = sbinfo->si_sb;
28968 + hlist_bl_unlock(&au_sbilist);
28971 + if (unlikely(!sb))
28974 + err = au_plink_maint_enter(sb);
28976 + /* keep kobject_get() */
28977 + file->private_data = sbinfo;
28979 + kobject_put(&sbinfo->si_kobj);
28985 + * Accept a valid "si=xxxx" only.
28986 + * Once it is accepted successfully, accept "clean" too.
28988 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
28989 + size_t count, loff_t *ppos)
28992 + unsigned long id;
28993 + /* last newline is allowed */
28994 + char buf[3 + sizeof(unsigned long) * 2 + 1];
28997 + if (unlikely(!capable(CAP_SYS_ADMIN)))
29001 + if (unlikely(count > sizeof(buf)))
29004 + err = copy_from_user(buf, ubuf, count);
29005 + if (unlikely(err)) {
29012 + if (!strcmp("clean", buf)) {
29013 + au_procfs_plm_write_clean(file);
29014 + goto out_success;
29015 + } else if (unlikely(strncmp("si=", buf, 3)))
29018 + err = kstrtoul(buf + 3, 16, &id);
29019 + if (unlikely(err))
29022 + err = au_procfs_plm_write_si(file, id);
29023 + if (unlikely(err))
29027 + err = count; /* success */
29032 +static const struct proc_ops au_procfs_plm_op = {
29033 + .proc_write = au_procfs_plm_write,
29034 + .proc_release = au_procfs_plm_release
29037 +/* ---------------------------------------------------------------------- */
29039 +static struct proc_dir_entry *au_procfs_dir;
29041 +void au_procfs_fin(void)
29043 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
29044 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29047 +int __init au_procfs_init(void)
29050 + struct proc_dir_entry *entry;
29053 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
29054 + if (unlikely(!au_procfs_dir))
29057 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200,
29058 + au_procfs_dir, &au_procfs_plm_op);
29059 + if (unlikely(!entry))
29063 + goto out; /* success */
29067 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
29071 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
29072 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
29073 +++ linux/fs/aufs/rdu.c 2022-12-17 09:21:34.799855195 +0100
29075 +// SPDX-License-Identifier: GPL-2.0
29077 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29079 + * This program is free software; you can redistribute it and/or modify
29080 + * it under the terms of the GNU General Public License as published by
29081 + * the Free Software Foundation; either version 2 of the License, or
29082 + * (at your option) any later version.
29084 + * This program is distributed in the hope that it will be useful,
29085 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29086 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29087 + * GNU General Public License for more details.
29089 + * You should have received a copy of the GNU General Public License
29090 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29094 + * readdir in userspace.
29097 +#include <linux/compat.h>
29098 +#include <linux/fs_stack.h>
29099 +#include <linux/security.h>
29102 +/* bits for struct aufs_rdu.flags */
29103 +#define AuRdu_CALLED 1
29104 +#define AuRdu_CONT (1 << 1)
29105 +#define AuRdu_FULL (1 << 2)
29106 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
29107 +#define au_fset_rdu(flags, name) \
29108 + do { (flags) |= AuRdu_##name; } while (0)
29109 +#define au_fclr_rdu(flags, name) \
29110 + do { (flags) &= ~AuRdu_##name; } while (0)
29112 +struct au_rdu_arg {
29113 + struct dir_context ctx;
29114 + struct aufs_rdu *rdu;
29115 + union au_rdu_ent_ul ent;
29116 + unsigned long end;
29118 + struct super_block *sb;
29122 +static bool au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
29123 + loff_t offset, u64 h_ino, unsigned int d_type)
29126 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
29127 + struct aufs_rdu *rdu = arg->rdu;
29128 + struct au_rdu_ent ent;
29132 + au_fset_rdu(rdu->cookie.flags, CALLED);
29133 + len = au_rdu_len(nlen);
29134 + if (arg->ent.ul + len < arg->end) {
29136 + ent.bindex = rdu->cookie.bindex;
29137 + ent.type = d_type;
29139 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29140 + ent.type = DT_UNKNOWN;
29142 + /* unnecessary to support mmap_sem since this is a dir */
29144 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
29146 + if (copy_to_user(arg->ent.e->name, name, nlen))
29148 + /* the terminating NULL */
29149 + if (__put_user(0, arg->ent.e->name + nlen))
29152 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
29153 + arg->ent.ul += len;
29157 + au_fset_rdu(rdu->cookie.flags, FULL);
29159 + rdu->tail = arg->ent;
29163 + /* AuTraceErr(err); */
29167 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
29171 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
29173 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
29174 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
29176 + if (unlikely(offset != cookie->h_pos))
29182 + au_fclr_rdu(cookie->flags, CALLED);
29184 + err = vfsub_iterate_dir(h_file, &arg->ctx);
29188 + && au_ftest_rdu(cookie->flags, CALLED)
29189 + && !au_ftest_rdu(cookie->flags, FULL));
29190 + cookie->h_pos = h_file->f_pos;
29197 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
29200 + aufs_bindex_t bbot;
29201 + struct au_rdu_arg arg = {
29203 + .actor = au_rdu_fill
29206 + struct dentry *dentry;
29207 + struct inode *inode;
29208 + struct file *h_file;
29209 + struct au_rdu_cookie *cookie = &rdu->cookie;
29211 + /* VERIFY_WRITE */
29212 + err = !access_ok(rdu->ent.e, rdu->sz);
29213 + if (unlikely(err)) {
29219 + rdu->tail = rdu->ent;
29222 + arg.ent = rdu->ent;
29223 + arg.end = arg.ent.ul;
29224 + arg.end += rdu->sz;
29227 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
29230 + err = security_file_permission(file, MAY_READ);
29232 + if (unlikely(err))
29235 + dentry = file->f_path.dentry;
29236 + inode = d_inode(dentry);
29237 + inode_lock_shared(inode);
29239 + arg.sb = inode->i_sb;
29240 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
29241 + if (unlikely(err))
29243 + err = au_alive_dir(dentry);
29244 + if (unlikely(err))
29246 + /* todo: reval? */
29247 + fi_read_lock(file);
29250 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
29251 + && cookie->generation != au_figen(file)))
29256 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
29258 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
29260 + bbot = au_fbtop(file);
29261 + if (cookie->bindex < bbot)
29262 + cookie->bindex = bbot;
29263 + bbot = au_fbbot_dir(file);
29264 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
29265 + for (; !err && cookie->bindex <= bbot;
29266 + cookie->bindex++, cookie->h_pos = 0) {
29267 + h_file = au_hf_dir(file, cookie->bindex);
29271 + au_fclr_rdu(cookie->flags, FULL);
29272 + err = au_rdu_do(h_file, &arg);
29274 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
29277 + AuDbg("rent %llu\n", rdu->rent);
29279 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
29280 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
29281 + au_fset_rdu(cookie->flags, CONT);
29282 + cookie->generation = au_figen(file);
29285 + ii_read_lock_child(inode);
29286 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
29287 + ii_read_unlock(inode);
29290 + fi_read_unlock(file);
29292 + si_read_unlock(arg.sb);
29294 + inode_unlock_shared(inode);
29300 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
29304 + unsigned long long nent;
29305 + union au_rdu_ent_ul *u;
29306 + struct au_rdu_ent ent;
29307 + struct super_block *sb;
29310 + nent = rdu->nent;
29312 + sb = file->f_path.dentry->d_sb;
29313 + si_read_lock(sb, AuLock_FLUSH);
29314 + while (nent-- > 0) {
29315 + /* unnecessary to support mmap_sem since this is a dir */
29316 + err = copy_from_user(&ent, u->e, sizeof(ent));
29318 + /* VERIFY_WRITE */
29319 + err = !access_ok(&u->e->ino, sizeof(ino));
29320 + if (unlikely(err)) {
29326 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
29328 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
29330 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
29332 + if (unlikely(err)) {
29337 + err = __put_user(ino, &u->e->ino);
29338 + if (unlikely(err)) {
29343 + u->ul += au_rdu_len(ent.nlen);
29345 + si_read_unlock(sb);
29350 +/* ---------------------------------------------------------------------- */
29352 +static int au_rdu_verify(struct aufs_rdu *rdu)
29354 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
29355 + "%llu, b%d, 0x%x, g%u}\n",
29356 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
29358 + rdu->rent, rdu->shwh, rdu->full,
29359 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
29360 + rdu->cookie.generation);
29362 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
29366 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
29370 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29373 + struct aufs_rdu rdu;
29374 + void __user *p = (void __user *)arg;
29376 + err = copy_from_user(&rdu, p, sizeof(rdu));
29377 + if (unlikely(err)) {
29382 + err = au_rdu_verify(&rdu);
29383 + if (unlikely(err))
29387 + case AUFS_CTL_RDU:
29388 + err = au_rdu(file, &rdu);
29389 + if (unlikely(err))
29392 + e = copy_to_user(p, &rdu, sizeof(rdu));
29393 + if (unlikely(e)) {
29398 + case AUFS_CTL_RDU_INO:
29399 + err = au_rdu_ino(file, &rdu);
29403 + /* err = -ENOTTY; */
29412 +#ifdef CONFIG_COMPAT
29413 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29416 + struct aufs_rdu rdu;
29417 + void __user *p = compat_ptr(arg);
29419 + /* todo: get_user()? */
29420 + err = copy_from_user(&rdu, p, sizeof(rdu));
29421 + if (unlikely(err)) {
29426 + rdu.ent.e = compat_ptr(rdu.ent.ul);
29427 + err = au_rdu_verify(&rdu);
29428 + if (unlikely(err))
29432 + case AUFS_CTL_RDU:
29433 + err = au_rdu(file, &rdu);
29434 + if (unlikely(err))
29437 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
29438 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
29439 + e = copy_to_user(p, &rdu, sizeof(rdu));
29440 + if (unlikely(e)) {
29445 + case AUFS_CTL_RDU_INO:
29446 + err = au_rdu_ino(file, &rdu);
29450 + /* err = -ENOTTY; */
29459 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
29460 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
29461 +++ linux/fs/aufs/rwsem.h 2022-11-05 23:02:18.969222617 +0100
29463 +/* SPDX-License-Identifier: GPL-2.0 */
29465 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29467 + * This program is free software; you can redistribute it and/or modify
29468 + * it under the terms of the GNU General Public License as published by
29469 + * the Free Software Foundation; either version 2 of the License, or
29470 + * (at your option) any later version.
29472 + * This program is distributed in the hope that it will be useful,
29473 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29474 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29475 + * GNU General Public License for more details.
29477 + * You should have received a copy of the GNU General Public License
29478 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29482 + * simple read-write semaphore wrappers
29485 +#ifndef __AUFS_RWSEM_H__
29486 +#define __AUFS_RWSEM_H__
29490 +#include "debug.h"
29492 +/* in the future, the name 'au_rwsem' will be totally gone */
29493 +#define au_rwsem rw_semaphore
29495 +/* to debug easier, do not make them inlined functions */
29496 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw))
29498 +#ifdef CONFIG_LOCKDEP
29499 +/* rwsem_is_locked() is unusable */
29500 +#define AuRwMustReadLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29501 + && !lockdep_recursing(current) \
29503 + && !lockdep_is_held_type(rw, 1))
29504 +#define AuRwMustWriteLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29505 + && !lockdep_recursing(current) \
29507 + && !lockdep_is_held_type(rw, 0))
29508 +#define AuRwMustAnyLock(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29509 + && !lockdep_recursing(current) \
29511 + && !lockdep_is_held(rw))
29512 +#define AuRwDestroy(rw) AuDebugOn(IS_ENABLED(CONFIG_LOCKDEP) \
29513 + && !lockdep_recursing(current) \
29515 + && lockdep_is_held(rw))
29517 +#define AuRwMustReadLock(rw) do {} while (0)
29518 +#define AuRwMustWriteLock(rw) do {} while (0)
29519 +#define AuRwMustAnyLock(rw) do {} while (0)
29520 +#define AuRwDestroy(rw) do {} while (0)
29523 +#define au_rw_init(rw) init_rwsem(rw)
29525 +#define au_rw_init_wlock(rw) do { \
29526 + au_rw_init(rw); \
29527 + down_write(rw); \
29530 +#define au_rw_init_wlock_nested(rw, lsc) do { \
29531 + au_rw_init(rw); \
29532 + down_write_nested(rw, lsc); \
29535 +#define au_rw_read_lock(rw) down_read(rw)
29536 +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc)
29537 +#define au_rw_read_unlock(rw) up_read(rw)
29538 +#define au_rw_dgrade_lock(rw) downgrade_write(rw)
29539 +#define au_rw_write_lock(rw) down_write(rw)
29540 +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc)
29541 +#define au_rw_write_unlock(rw) up_write(rw)
29542 +/* why is not _nested version defined? */
29543 +#define au_rw_read_trylock(rw) down_read_trylock(rw)
29544 +#define au_rw_write_trylock(rw) down_write_trylock(rw)
29546 +#endif /* __KERNEL__ */
29547 +#endif /* __AUFS_RWSEM_H__ */
29548 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
29549 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
29550 +++ linux/fs/aufs/sbinfo.c 2022-11-05 23:02:18.969222617 +0100
29552 +// SPDX-License-Identifier: GPL-2.0
29554 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29556 + * This program is free software; you can redistribute it and/or modify
29557 + * it under the terms of the GNU General Public License as published by
29558 + * the Free Software Foundation; either version 2 of the License, or
29559 + * (at your option) any later version.
29561 + * This program is distributed in the hope that it will be useful,
29562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29564 + * GNU General Public License for more details.
29566 + * You should have received a copy of the GNU General Public License
29567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29571 + * superblock private data
29574 +#include <linux/iversion.h>
29578 + * they are necessary regardless sysfs is disabled.
29580 +void au_si_free(struct kobject *kobj)
29583 + struct au_sbinfo *sbinfo;
29584 + char *locked __maybe_unused; /* debug only */
29586 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29587 + for (i = 0; i < AuPlink_NHASH; i++)
29588 + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i));
29589 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
29591 + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0));
29592 + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0);
29593 + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0));
29594 + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0);
29596 + dbgaufs_si_fin(sbinfo);
29597 + au_rw_write_lock(&sbinfo->si_rwsem);
29598 + au_br_free(sbinfo);
29599 + au_rw_write_unlock(&sbinfo->si_rwsem);
29601 + au_kfree_try_rcu(sbinfo->si_branch);
29602 + mutex_destroy(&sbinfo->si_xib_mtx);
29603 + AuRwDestroy(&sbinfo->si_rwsem);
29605 + au_lcnt_wait_for_fin(&sbinfo->si_ninodes);
29606 + /* si_nfiles is waited too */
29607 + au_kfree_rcu(sbinfo);
29610 +struct au_sbinfo *au_si_alloc(struct super_block *sb)
29612 + struct au_sbinfo *sbinfo;
29616 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
29617 + if (unlikely(!sbinfo))
29620 + /* will be reallocated separately */
29621 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
29622 + if (unlikely(!sbinfo->si_branch))
29625 + err = sysaufs_si_init(sbinfo);
29627 + dbgaufs_si_null(sbinfo);
29628 + err = dbgaufs_si_init(sbinfo);
29629 + if (unlikely(err))
29630 + kobject_put(&sbinfo->si_kobj);
29632 + if (unlikely(err))
29635 + au_nwt_init(&sbinfo->si_nowait);
29636 + au_rw_init_wlock(&sbinfo->si_rwsem);
29638 + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL);
29639 + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL);
29641 + sbinfo->si_bbot = -1;
29642 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
29644 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
29645 + sbinfo->si_wbr_create = AuWbrCreate_Def;
29646 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
29647 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
29649 + au_fhsm_init(sbinfo);
29651 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
29653 + sbinfo->si_xino_jiffy = jiffies;
29654 + sbinfo->si_xino_expire
29655 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
29656 + mutex_init(&sbinfo->si_xib_mtx);
29657 + /* leave si_xib_last_pindex and si_xib_next_bit */
29659 + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen);
29661 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
29662 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
29663 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
29664 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
29666 + for (i = 0; i < AuPlink_NHASH; i++)
29667 + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i);
29668 + init_waitqueue_head(&sbinfo->si_plink_wq);
29669 + spin_lock_init(&sbinfo->si_plink_maint_lock);
29671 + INIT_HLIST_BL_HEAD(&sbinfo->si_files);
29673 + /* with getattr by default */
29674 + sbinfo->si_iop_array = aufs_iop;
29676 + /* leave other members for sysaufs and si_mnt. */
29677 + sbinfo->si_sb = sb;
29679 + sb->s_fs_info = sbinfo;
29682 + return sbinfo; /* success */
29685 + au_kfree_try_rcu(sbinfo->si_branch);
29687 + au_kfree_rcu(sbinfo);
29689 + return ERR_PTR(err);
29692 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
29695 + struct au_branch **brp;
29697 + AuRwMustWriteLock(&sbinfo->si_rwsem);
29700 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
29701 + if (unlikely(!sz))
29702 + sz = sizeof(*brp);
29703 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
29706 + sbinfo->si_branch = brp;
29713 +/* ---------------------------------------------------------------------- */
29715 +unsigned int au_sigen_inc(struct super_block *sb)
29717 + unsigned int gen;
29718 + struct inode *inode;
29720 + SiMustWriteLock(sb);
29722 + gen = ++au_sbi(sb)->si_generation;
29723 + au_update_digen(sb->s_root);
29724 + inode = d_inode(sb->s_root);
29725 + au_update_iigen(inode, /*half*/0);
29726 + inode_inc_iversion(inode);
29730 +aufs_bindex_t au_new_br_id(struct super_block *sb)
29732 + aufs_bindex_t br_id;
29734 + struct au_sbinfo *sbinfo;
29736 + SiMustWriteLock(sb);
29738 + sbinfo = au_sbi(sb);
29739 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
29740 + br_id = ++sbinfo->si_last_br_id;
29741 + AuDebugOn(br_id < 0);
29742 + if (br_id && au_br_index(sb, br_id) < 0)
29749 +/* ---------------------------------------------------------------------- */
29751 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
29752 +int si_read_lock(struct super_block *sb, int flags)
29757 + if (au_ftest_lock(flags, FLUSH))
29758 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29760 + si_noflush_read_lock(sb);
29761 + err = au_plink_maint(sb, flags);
29762 + if (unlikely(err))
29763 + si_read_unlock(sb);
29768 +int si_write_lock(struct super_block *sb, int flags)
29772 + if (au_ftest_lock(flags, FLUSH))
29773 + au_nwt_flush(&au_sbi(sb)->si_nowait);
29775 + si_noflush_write_lock(sb);
29776 + err = au_plink_maint(sb, flags);
29777 + if (unlikely(err))
29778 + si_write_unlock(sb);
29783 +/* dentry and super_block lock. call at entry point */
29784 +int aufs_read_lock(struct dentry *dentry, int flags)
29787 + struct super_block *sb;
29789 + sb = dentry->d_sb;
29790 + err = si_read_lock(sb, flags);
29791 + if (unlikely(err))
29794 + if (au_ftest_lock(flags, DW))
29795 + di_write_lock_child(dentry);
29797 + di_read_lock_child(dentry, flags);
29799 + if (au_ftest_lock(flags, GEN)) {
29800 + err = au_digen_test(dentry, au_sigen(sb));
29801 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
29802 + AuDebugOn(!err && au_dbrange_test(dentry));
29804 + err = au_dbrange_test(dentry);
29805 + if (unlikely(err))
29806 + aufs_read_unlock(dentry, flags);
29813 +void aufs_read_unlock(struct dentry *dentry, int flags)
29815 + if (au_ftest_lock(flags, DW))
29816 + di_write_unlock(dentry);
29818 + di_read_unlock(dentry, flags);
29819 + si_read_unlock(dentry->d_sb);
29822 +void aufs_write_lock(struct dentry *dentry)
29824 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
29825 + di_write_lock_child(dentry);
29828 +void aufs_write_unlock(struct dentry *dentry)
29830 + di_write_unlock(dentry);
29831 + si_write_unlock(dentry->d_sb);
29834 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
29837 + unsigned int sigen;
29838 + struct super_block *sb;
29841 + err = si_read_lock(sb, flags);
29842 + if (unlikely(err))
29845 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
29847 + if (au_ftest_lock(flags, GEN)) {
29848 + sigen = au_sigen(sb);
29849 + err = au_digen_test(d1, sigen);
29850 + AuDebugOn(!err && au_dbrange_test(d1));
29852 + err = au_digen_test(d2, sigen);
29853 + AuDebugOn(!err && au_dbrange_test(d2));
29855 + if (unlikely(err))
29856 + aufs_read_and_write_unlock2(d1, d2);
29863 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
29865 + di_write_unlock2(d1, d2);
29866 + si_read_unlock(d1->d_sb);
29868 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
29869 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
29870 +++ linux/fs/aufs/super.c 2022-11-05 23:02:18.969222617 +0100
29872 +// SPDX-License-Identifier: GPL-2.0
29874 + * Copyright (C) 2005-2022 Junjiro R. Okajima
29876 + * This program is free software; you can redistribute it and/or modify
29877 + * it under the terms of the GNU General Public License as published by
29878 + * the Free Software Foundation; either version 2 of the License, or
29879 + * (at your option) any later version.
29881 + * This program is distributed in the hope that it will be useful,
29882 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29883 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29884 + * GNU General Public License for more details.
29886 + * You should have received a copy of the GNU General Public License
29887 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29891 + * mount and super_block operations
29894 +#include <linux/iversion.h>
29895 +#include <linux/mm.h>
29896 +#include <linux/seq_file.h>
29897 +#include <linux/statfs.h>
29898 +#include <linux/vmalloc.h>
29902 + * super_operations
29904 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
29906 + struct au_icntnr *c;
29908 + c = au_cache_alloc_icntnr(sb);
29910 + au_icntnr_init(c);
29911 + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */
29912 + c->iinfo.ii_hinode = NULL;
29913 + return &c->vfs_inode;
29918 +static void aufs_destroy_inode(struct inode *inode)
29920 + if (!au_is_bad_inode(inode))
29921 + au_iinfo_fin(inode);
29924 +static void aufs_free_inode(struct inode *inode)
29926 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
29929 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
29931 + struct inode *inode;
29934 + inode = iget_locked(sb, ino);
29935 + if (unlikely(!inode)) {
29936 + inode = ERR_PTR(-ENOMEM);
29939 + if (!(inode->i_state & I_NEW))
29942 + err = au_xigen_new(inode);
29944 + err = au_iinfo_init(inode);
29946 + inode_inc_iversion(inode);
29948 + iget_failed(inode);
29949 + inode = ERR_PTR(err);
29953 + /* never return NULL */
29954 + AuDebugOn(!inode);
29955 + AuTraceErrPtr(inode);
29959 +/* lock free root dinfo */
29960 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
29963 + aufs_bindex_t bindex, bbot;
29964 + struct path path;
29965 + struct au_hdentry *hdp;
29966 + struct au_branch *br;
29967 + au_br_perm_str_t perm;
29970 + bbot = au_sbbot(sb);
29972 + hdp = au_hdentry(au_di(sb->s_root), bindex);
29973 + for (; !err && bindex <= bbot; bindex++, hdp++) {
29974 + br = au_sbr(sb, bindex);
29975 + path.mnt = au_br_mnt(br);
29976 + path.dentry = hdp->hd_dentry;
29977 + err = au_seq_path(seq, &path);
29979 + au_optstr_br_perm(&perm, br->br_perm);
29980 + seq_printf(seq, "=%s", perm.a);
29981 + if (bindex != bbot)
29982 + seq_putc(seq, ':');
29985 + if (unlikely(err || seq_has_overflowed(seq)))
29991 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
29992 + const char *append)
29997 + while (*pat != ':')
30000 + strcpy(p, append);
30001 + AuDebugOn(strlen(fmt) >= len);
30004 +static void au_show_wbr_create(struct seq_file *m, int v,
30005 + struct au_sbinfo *sbinfo)
30009 + struct au_wbr_mfs *mfs;
30011 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30013 + seq_puts(m, ",create=");
30014 + pat = au_optstr_wbr_create(v);
30015 + mfs = &sbinfo->si_wbr_mfs;
30017 + case AuWbrCreate_TDP:
30018 + case AuWbrCreate_RR:
30019 + case AuWbrCreate_MFS:
30020 + case AuWbrCreate_PMFS:
30021 + seq_puts(m, pat);
30023 + case AuWbrCreate_MFSRR:
30024 + case AuWbrCreate_TDMFS:
30025 + case AuWbrCreate_PMFSRR:
30026 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
30027 + seq_printf(m, fmt, mfs->mfsrr_watermark);
30029 + case AuWbrCreate_MFSV:
30030 + case AuWbrCreate_PMFSV:
30031 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
30032 + seq_printf(m, fmt,
30033 + jiffies_to_msecs(mfs->mfs_expire)
30036 + case AuWbrCreate_MFSRRV:
30037 + case AuWbrCreate_TDMFSV:
30038 + case AuWbrCreate_PMFSRRV:
30039 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
30040 + seq_printf(m, fmt, mfs->mfsrr_watermark,
30041 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
30048 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
30050 +#ifdef CONFIG_SYSFS
30054 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
30055 + aufs_bindex_t bindex, brid;
30056 + struct qstr *name;
30058 + struct dentry *d, *h_root;
30059 + struct au_branch *br;
30061 + AuRwMustAnyLock(&sbinfo->si_rwsem);
30064 + f = au_sbi(sb)->si_xib;
30068 + /* stop printing the default xino path on the first writable branch */
30070 + bindex = au_xi_root(sb, f->f_path.dentry);
30071 + if (bindex >= 0) {
30072 + br = au_sbr_sb(sb, bindex);
30073 + h_root = au_br_dentry(br);
30076 + d = f->f_path.dentry;
30077 + name = &d->d_name;
30078 + /* safe ->d_parent because the file is unlinked */
30079 + if (d->d_parent == h_root
30080 + && name->len == len
30081 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
30084 + seq_puts(seq, ",xino=");
30085 + err = au_xino_path(seq, f);
30092 +/* seq_file will re-call me in case of too long string */
30093 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
30096 + unsigned int mnt_flags, v;
30097 + struct super_block *sb;
30098 + struct au_sbinfo *sbinfo;
30100 +#define AuBool(name, str) do { \
30101 + v = au_opt_test(mnt_flags, name); \
30102 + if (v != au_opt_test(AuOpt_Def, name)) \
30103 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
30106 +#define AuStr(name, str) do { \
30107 + v = mnt_flags & AuOptMask_##name; \
30108 + if (v != (AuOpt_Def & AuOptMask_##name)) \
30109 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
30112 +#define AuUInt(name, str, val) do { \
30113 + if (val != AUFS_##name##_DEF) \
30114 + seq_printf(m, "," #str "=%u", val); \
30117 + sb = dentry->d_sb;
30118 + if (sb->s_flags & SB_POSIXACL)
30119 + seq_puts(m, ",acl");
30120 +#if 0 /* reserved for future use */
30121 + if (sb->s_flags & SB_I_VERSION)
30122 + seq_puts(m, ",i_version");
30125 + /* lock free root dinfo */
30126 + si_noflush_read_lock(sb);
30127 + sbinfo = au_sbi(sb);
30128 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
30130 + mnt_flags = au_mntflags(sb);
30131 + if (au_opt_test(mnt_flags, XINO)) {
30132 + err = au_show_xino(m, sb);
30133 + if (unlikely(err))
30136 + seq_puts(m, ",noxino");
30138 + AuBool(TRUNC_XINO, trunc_xino);
30139 + AuStr(UDBA, udba);
30140 + AuBool(SHWH, shwh);
30141 + AuBool(PLINK, plink);
30142 + AuBool(DIO, dio);
30143 + AuBool(DIRPERM1, dirperm1);
30145 + v = sbinfo->si_wbr_create;
30146 + if (v != AuWbrCreate_Def)
30147 + au_show_wbr_create(m, v, sbinfo);
30149 + v = sbinfo->si_wbr_copyup;
30150 + if (v != AuWbrCopyup_Def)
30151 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
30153 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
30154 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
30155 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
30157 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
30159 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
30160 + AuUInt(RDCACHE, rdcache, v);
30162 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
30163 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
30165 + au_fhsm_show(m, sbinfo);
30167 + AuBool(DIRREN, dirren);
30168 + AuBool(SUM, sum);
30169 + /* AuBool(SUM_W, wsum); */
30170 + AuBool(WARN_PERM, warn_perm);
30171 + AuBool(VERBOSE, verbose);
30174 + /* be sure to print "br:" last */
30175 + if (!sysaufs_brs) {
30176 + seq_puts(m, ",br:");
30177 + au_show_brs(m, sb);
30179 + si_read_unlock(sb);
30187 +/* ---------------------------------------------------------------------- */
30189 +/* sum mode which returns the summation for statfs(2) */
30191 +static u64 au_add_till_max(u64 a, u64 b)
30199 + return ULLONG_MAX;
30202 +static u64 au_mul_till_max(u64 a, long mul)
30210 + return ULLONG_MAX;
30213 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
30216 + long bsize, factor;
30217 + u64 blocks, bfree, bavail, files, ffree;
30218 + aufs_bindex_t bbot, bindex, i;
30219 + unsigned char shared;
30220 + struct path h_path;
30221 + struct super_block *h_sb;
30224 + bsize = LONG_MAX;
30230 + bbot = au_sbbot(sb);
30231 + for (bindex = 0; bindex <= bbot; bindex++) {
30232 + h_path.mnt = au_sbr_mnt(sb, bindex);
30233 + h_sb = h_path.mnt->mnt_sb;
30235 + for (i = 0; !shared && i < bindex; i++)
30236 + shared = (au_sbr_sb(sb, i) == h_sb);
30240 + /* sb->s_root for NFS is unreliable */
30241 + h_path.dentry = h_path.mnt->mnt_root;
30242 + err = vfs_statfs(&h_path, buf);
30243 + if (unlikely(err))
30246 + if (bsize > buf->f_bsize) {
30248 + * we will reduce bsize, so we have to expand blocks
30249 + * etc. to match them again
30251 + factor = (bsize / buf->f_bsize);
30252 + blocks = au_mul_till_max(blocks, factor);
30253 + bfree = au_mul_till_max(bfree, factor);
30254 + bavail = au_mul_till_max(bavail, factor);
30255 + bsize = buf->f_bsize;
30258 + factor = (buf->f_bsize / bsize);
30259 + blocks = au_add_till_max(blocks,
30260 + au_mul_till_max(buf->f_blocks, factor));
30261 + bfree = au_add_till_max(bfree,
30262 + au_mul_till_max(buf->f_bfree, factor));
30263 + bavail = au_add_till_max(bavail,
30264 + au_mul_till_max(buf->f_bavail, factor));
30265 + files = au_add_till_max(files, buf->f_files);
30266 + ffree = au_add_till_max(ffree, buf->f_ffree);
30269 + buf->f_bsize = bsize;
30270 + buf->f_blocks = blocks;
30271 + buf->f_bfree = bfree;
30272 + buf->f_bavail = bavail;
30273 + buf->f_files = files;
30274 + buf->f_ffree = ffree;
30275 + buf->f_frsize = 0;
30281 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
30284 + struct path h_path;
30285 + struct super_block *sb;
30287 + /* lock free root dinfo */
30288 + sb = dentry->d_sb;
30289 + si_noflush_read_lock(sb);
30290 + if (!au_opt_test(au_mntflags(sb), SUM)) {
30291 + /* sb->s_root for NFS is unreliable */
30292 + h_path.mnt = au_sbr_mnt(sb, 0);
30293 + h_path.dentry = h_path.mnt->mnt_root;
30294 + err = vfs_statfs(&h_path, buf);
30296 + err = au_statfs_sum(sb, buf);
30297 + si_read_unlock(sb);
30300 + buf->f_type = AUFS_SUPER_MAGIC;
30301 + buf->f_namelen = AUFS_MAX_NAMELEN;
30302 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
30304 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
30309 +/* ---------------------------------------------------------------------- */
30311 +static int aufs_sync_fs(struct super_block *sb, int wait)
30314 + aufs_bindex_t bbot, bindex;
30315 + struct au_branch *br;
30316 + struct super_block *h_sb;
30319 + si_noflush_read_lock(sb);
30320 + bbot = au_sbbot(sb);
30321 + for (bindex = 0; bindex <= bbot; bindex++) {
30322 + br = au_sbr(sb, bindex);
30323 + if (!au_br_writable(br->br_perm))
30326 + h_sb = au_sbr_sb(sb, bindex);
30327 + e = vfsub_sync_filesystem(h_sb);
30328 + if (unlikely(e && !err))
30330 + /* go on even if an error happens */
30332 + si_read_unlock(sb);
30337 +/* ---------------------------------------------------------------------- */
30339 +/* final actions when unmounting a file system */
30340 +static void aufs_put_super(struct super_block *sb)
30342 + struct au_sbinfo *sbinfo;
30344 + sbinfo = au_sbi(sb);
30346 + kobject_put(&sbinfo->si_kobj);
30349 +/* ---------------------------------------------------------------------- */
30351 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
30352 + struct super_block *sb, void *arg)
30355 + unsigned long long n, sz;
30362 + if (*hint > ULLONG_MAX / sizeof(array)) {
30363 + array = ERR_PTR(-EMFILE);
30364 + pr_err("hint %llu\n", *hint);
30368 + sz = sizeof(array) * *hint;
30369 + array = kzalloc(sz, GFP_NOFS);
30370 + if (unlikely(!array))
30371 + array = vzalloc(sz);
30372 + if (unlikely(!array)) {
30373 + array = ERR_PTR(-ENOMEM);
30377 + n = cb(sb, array, *hint, arg);
30378 + AuDebugOn(n > *hint);
30385 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
30386 + unsigned long long max __maybe_unused,
30389 + unsigned long long n;
30390 + struct inode **p, *inode;
30391 + struct list_head *head;
30396 + spin_lock(&sb->s_inode_list_lock);
30397 + list_for_each_entry(inode, head, i_sb_list) {
30398 + if (!au_is_bad_inode(inode)
30399 + && au_ii(inode)->ii_btop >= 0) {
30400 + spin_lock(&inode->i_lock);
30401 + if (atomic_read(&inode->i_count)) {
30405 + AuDebugOn(n > max);
30407 + spin_unlock(&inode->i_lock);
30410 + spin_unlock(&sb->s_inode_list_lock);
30415 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
30417 + struct au_sbinfo *sbi;
30419 + sbi = au_sbi(sb);
30420 + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1);
30421 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
30424 +void au_iarray_free(struct inode **a, unsigned long long max)
30426 + unsigned long long ull;
30428 + for (ull = 0; ull < max; ull++)
30433 +/* ---------------------------------------------------------------------- */
30436 + * refresh dentry and inode at remount time.
30438 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
30439 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
30440 + struct dentry *parent)
30444 + di_write_lock_child(dentry);
30445 + di_read_lock_parent(parent, AuLock_IR);
30446 + err = au_refresh_dentry(dentry, parent);
30447 + if (!err && dir_flags)
30448 + au_hn_reset(d_inode(dentry), dir_flags);
30449 + di_read_unlock(parent, AuLock_IR);
30450 + di_write_unlock(dentry);
30455 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
30456 + struct au_sbinfo *sbinfo,
30457 + const unsigned int dir_flags, unsigned int do_idop)
30460 + struct dentry *parent;
30463 + parent = dget_parent(dentry);
30464 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
30465 + if (d_really_is_positive(dentry)) {
30466 + if (!d_is_dir(dentry))
30467 + err = au_do_refresh(dentry, /*dir_flags*/0,
30470 + err = au_do_refresh(dentry, dir_flags, parent);
30471 + if (unlikely(err))
30472 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
30475 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
30476 + AuDbgDentry(dentry);
30482 + au_refresh_dop(dentry, /*force_reval*/0);
30484 + au_refresh_dop(dentry, /*force_reval*/1);
30490 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
30492 + int err, i, j, ndentry, e;
30493 + unsigned int sigen;
30494 + struct au_dcsub_pages dpages;
30495 + struct au_dpage *dpage;
30496 + struct dentry **dentries, *d;
30497 + struct au_sbinfo *sbinfo;
30498 + struct dentry *root = sb->s_root;
30499 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
30502 + au_refresh_dop(root, /*force_reval*/0);
30504 + err = au_dpages_init(&dpages, GFP_NOFS);
30505 + if (unlikely(err))
30507 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
30508 + if (unlikely(err))
30511 + sigen = au_sigen(sb);
30512 + sbinfo = au_sbi(sb);
30513 + for (i = 0; i < dpages.ndpage; i++) {
30514 + dpage = dpages.dpages + i;
30515 + dentries = dpage->dentries;
30516 + ndentry = dpage->ndentry;
30517 + for (j = 0; j < ndentry; j++) {
30519 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
30521 + if (unlikely(e && !err))
30523 + /* go on even err */
30528 + au_dpages_free(&dpages);
30533 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
30536 + unsigned int sigen;
30537 + unsigned long long max, ull;
30538 + struct inode *inode, **array;
30540 + array = au_iarray_alloc(sb, &max);
30541 + err = PTR_ERR(array);
30542 + if (IS_ERR(array))
30546 + sigen = au_sigen(sb);
30547 + for (ull = 0; ull < max; ull++) {
30548 + inode = array[ull];
30549 + if (unlikely(!inode))
30553 + ii_write_lock_child(inode);
30554 + if (au_iigen(inode, NULL) != sigen) {
30555 + e = au_refresh_hinode_self(inode);
30556 + if (unlikely(e)) {
30557 + au_refresh_iop(inode, /*force_getattr*/1);
30558 + pr_err("error %d, i%lu\n", e, inode->i_ino);
30561 + /* go on even if err */
30564 + if (!e && do_idop)
30565 + au_refresh_iop(inode, /*force_getattr*/0);
30566 + ii_write_unlock(inode);
30569 + au_iarray_free(array, max);
30575 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
30578 + unsigned int udba;
30579 + aufs_bindex_t bindex, bbot;
30580 + struct dentry *root;
30581 + struct inode *inode;
30582 + struct au_branch *br;
30583 + struct au_sbinfo *sbi;
30585 + au_sigen_inc(sb);
30586 + sbi = au_sbi(sb);
30587 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
30589 + root = sb->s_root;
30590 + DiMustNoWaiters(root);
30591 + inode = d_inode(root);
30592 + IiMustNoWaiters(inode);
30594 + udba = au_opt_udba(sb);
30595 + bbot = au_sbbot(sb);
30596 + for (bindex = 0; bindex <= bbot; bindex++) {
30597 + br = au_sbr(sb, bindex);
30598 + err = au_hnotify_reset_br(udba, br, br->br_perm);
30599 + if (unlikely(err))
30600 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
30602 + /* go on even if err */
30604 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
30607 + if (au_ftest_si(sbi, NO_DREVAL)) {
30608 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
30609 + sb->s_d_op = &aufs_dop_noreval;
30610 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
30611 + sbi->si_iop_array = aufs_iop_nogetattr;
30613 + AuDebugOn(sb->s_d_op == &aufs_dop);
30614 + sb->s_d_op = &aufs_dop;
30615 + AuDebugOn(sbi->si_iop_array == aufs_iop);
30616 + sbi->si_iop_array = aufs_iop;
30618 + pr_info("reset to %ps and %ps\n",
30619 + sb->s_d_op, sbi->si_iop_array);
30622 + di_write_unlock(root);
30623 + err = au_refresh_d(sb, do_idop);
30624 + e = au_refresh_i(sb, do_idop);
30625 + if (unlikely(e && !err))
30627 + /* aufs_write_lock() calls ..._child() */
30628 + di_write_lock_child(root);
30630 + au_cpup_attr_all(inode, /*force*/1);
30632 + if (unlikely(err))
30633 + AuIOErr("refresh failed, ignored, %d\n", err);
30636 +const struct super_operations aufs_sop = {
30637 + .alloc_inode = aufs_alloc_inode,
30638 + .destroy_inode = aufs_destroy_inode,
30639 + .free_inode = aufs_free_inode,
30640 + /* always deleting, no clearing */
30641 + .drop_inode = generic_delete_inode,
30642 + .show_options = aufs_show_options,
30643 + .statfs = aufs_statfs,
30644 + .put_super = aufs_put_super,
30645 + .sync_fs = aufs_sync_fs
30648 +/* ---------------------------------------------------------------------- */
30650 +int au_alloc_root(struct super_block *sb)
30653 + struct inode *inode;
30654 + struct dentry *root;
30657 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
30658 + err = PTR_ERR(inode);
30659 + if (IS_ERR(inode))
30662 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
30663 + inode->i_fop = &aufs_dir_fop;
30664 + inode->i_mode = S_IFDIR;
30665 + set_nlink(inode, 2);
30666 + unlock_new_inode(inode);
30668 + root = d_make_root(inode);
30669 + if (unlikely(!root))
30671 + err = PTR_ERR(root);
30672 + if (IS_ERR(root))
30675 + err = au_di_init(root);
30677 + sb->s_root = root;
30678 + return 0; /* success */
30686 +/* ---------------------------------------------------------------------- */
30688 +static void aufs_kill_sb(struct super_block *sb)
30690 + struct au_sbinfo *sbinfo;
30691 + struct dentry *root;
30693 + sbinfo = au_sbi(sb);
30697 + au_sbilist_del(sb);
30699 + root = sb->s_root;
30701 + aufs_write_lock(root);
30703 + __si_write_lock(sb);
30706 + if (sbinfo->si_wbr_create_ops->fin)
30707 + sbinfo->si_wbr_create_ops->fin(sb);
30708 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
30709 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
30710 + au_remount_refresh(sb, /*do_idop*/0);
30712 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
30713 + au_plink_put(sb, /*verbose*/1);
30716 + au_dr_opt_flush(sb);
30719 + aufs_write_unlock(root);
30721 + __si_write_unlock(sb);
30723 + sbinfo->si_sb = NULL;
30724 + au_nwt_flush(&sbinfo->si_nowait);
30727 + kill_anon_super(sb);
30730 +struct file_system_type aufs_fs_type = {
30731 + .name = AUFS_FSTYPE,
30732 + /* a race between rename and others */
30733 + .fs_flags = FS_RENAME_DOES_D_MOVE
30735 + /*| FS_ALLOW_IDMAP*/
30737 + .init_fs_context = aufs_fsctx_init,
30738 + .parameters = aufs_fsctx_paramspec,
30739 + .kill_sb = aufs_kill_sb,
30740 + /* no need to __module_get() and module_put(). */
30741 + .owner = THIS_MODULE,
30743 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
30744 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
30745 +++ linux/fs/aufs/super.h 2022-11-05 23:02:18.969222617 +0100
30747 +/* SPDX-License-Identifier: GPL-2.0 */
30749 + * Copyright (C) 2005-2022 Junjiro R. Okajima
30751 + * This program is free software; you can redistribute it and/or modify
30752 + * it under the terms of the GNU General Public License as published by
30753 + * the Free Software Foundation; either version 2 of the License, or
30754 + * (at your option) any later version.
30756 + * This program is distributed in the hope that it will be useful,
30757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30759 + * GNU General Public License for more details.
30761 + * You should have received a copy of the GNU General Public License
30762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30766 + * super_block operations
30769 +#ifndef __AUFS_SUPER_H__
30770 +#define __AUFS_SUPER_H__
30774 +#include <linux/fs.h>
30775 +#include <linux/kobject.h>
30778 +#include "rwsem.h"
30781 +/* policies to select one among multiple writable branches */
30782 +struct au_wbr_copyup_operations {
30783 + int (*copyup)(struct dentry *dentry);
30786 +#define AuWbr_DIR 1 /* target is a dir */
30787 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
30789 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
30790 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
30791 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
30793 +struct au_wbr_create_operations {
30794 + int (*create)(struct dentry *dentry, unsigned int flags);
30795 + int (*init)(struct super_block *sb);
30796 + int (*fin)(struct super_block *sb);
30799 +struct au_wbr_mfs {
30800 + struct mutex mfs_lock; /* protect this structure */
30801 + unsigned long mfs_jiffy;
30802 + unsigned long mfs_expire;
30803 + aufs_bindex_t mfs_bindex;
30805 + unsigned long long mfsrr_bytes;
30806 + unsigned long long mfsrr_watermark;
30809 +#define AuPlink_NHASH 100
30810 +static inline int au_plink_hash(ino_t ino)
30812 + return ino % AuPlink_NHASH;
30815 +/* File-based Hierarchical Storage Management */
30817 +#ifdef CONFIG_AUFS_FHSM
30818 + /* allow only one process who can receive the notification */
30819 + spinlock_t fhsm_spin;
30821 + wait_queue_head_t fhsm_wqh;
30822 + atomic_t fhsm_readable;
30824 + /* these are protected by si_rwsem */
30825 + unsigned long fhsm_expire;
30826 + aufs_bindex_t fhsm_bottom;
30831 +struct au_sbinfo {
30832 + /* nowait tasks in the system-wide workqueue */
30833 + struct au_nowait_tasks si_nowait;
30836 + * tried sb->s_umount, but failed due to the dependency between i_mutex.
30837 + * rwsem for au_sbinfo is necessary.
30839 + struct au_rwsem si_rwsem;
30842 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
30845 + au_lcnt_t si_ninodes, si_nfiles;
30847 + /* branch management */
30848 + unsigned int si_generation;
30850 + /* see AuSi_ flags */
30851 + unsigned char au_si_status;
30853 + aufs_bindex_t si_bbot;
30855 + /* dirty trick to keep br_id plus */
30856 + unsigned int si_last_br_id :
30857 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
30858 + struct au_branch **si_branch;
30860 + /* policy to select a writable branch */
30861 + unsigned char si_wbr_copyup;
30862 + unsigned char si_wbr_create;
30863 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
30864 + struct au_wbr_create_operations *si_wbr_create_ops;
30866 + /* round robin */
30867 + atomic_t si_wbr_rr_next;
30869 + /* most free space */
30870 + struct au_wbr_mfs si_wbr_mfs;
30872 + /* File-based Hierarchical Storage Management */
30873 + struct au_fhsm si_fhsm;
30875 + /* mount flags */
30876 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
30877 + unsigned int si_mntflags;
30879 + /* external inode number (bitmap and translation table) */
30880 + loff_t si_ximaxent; /* max entries in a xino */
30882 + struct file *si_xib;
30883 + struct mutex si_xib_mtx; /* protect xib members */
30884 + unsigned long *si_xib_buf;
30885 + unsigned long si_xib_last_pindex;
30886 + int si_xib_next_bit;
30888 + unsigned long si_xino_jiffy;
30889 + unsigned long si_xino_expire;
30890 + /* reserved for future use */
30891 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
30893 +#ifdef CONFIG_AUFS_EXPORT
30894 + /* i_generation */
30895 + /* todo: make xigen file an array to support many inode numbers */
30896 + struct file *si_xigen;
30897 + atomic_t si_xigen_next;
30900 + /* dirty trick to support atomic_open */
30901 + struct hlist_bl_head si_aopen;
30903 + /* vdir parameters */
30904 + unsigned long si_rdcache; /* max cache time in jiffies */
30905 + unsigned int si_rdblk; /* deblk size */
30906 + unsigned int si_rdhash; /* hash size */
30909 + * If the number of whiteouts are larger than si_dirwh, leave all of
30910 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
30911 + * future fsck.aufs or kernel thread will remove them later.
30912 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
30914 + unsigned int si_dirwh;
30916 + /* pseudo_link list */
30917 + struct hlist_bl_head si_plink[AuPlink_NHASH];
30918 + wait_queue_head_t si_plink_wq;
30919 + spinlock_t si_plink_maint_lock;
30920 + pid_t si_plink_maint_pid;
30923 + struct hlist_bl_head si_files;
30925 + /* with/without getattr, brother of sb->s_d_op */
30926 + const struct inode_operations *si_iop_array;
30929 + * sysfs and lifetime management.
30930 + * this is not a small structure and it may be a waste of memory in case
30931 + * of sysfs is disabled, particularly when many aufs-es are mounted.
30932 + * but using sysfs is majority.
30934 + struct kobject si_kobj;
30935 +#ifdef CONFIG_DEBUG_FS
30936 + struct dentry *si_dbgaufs;
30937 + struct dentry *si_dbgaufs_plink;
30938 + struct dentry *si_dbgaufs_xib;
30939 +#ifdef CONFIG_AUFS_EXPORT
30940 + struct dentry *si_dbgaufs_xigen;
30944 +#ifdef CONFIG_AUFS_SBILIST
30945 + struct hlist_bl_node si_list;
30948 + /* dirty, necessary for unmounting, sysfs and sysrq */
30949 + struct super_block *si_sb;
30952 +/* sbinfo status flags */
30954 + * set true when refresh_dirs() failed at remount time.
30955 + * then try refreshing dirs at access time again.
30956 + * if it is false, refreshing dirs at access time is unnecessary
30958 +#define AuSi_FAILED_REFRESH_DIR 1
30959 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
30960 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
30962 +#ifndef CONFIG_AUFS_FHSM
30964 +#define AuSi_FHSM 0
30967 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
30968 + unsigned int flag)
30970 + AuRwMustAnyLock(&sbi->si_rwsem);
30971 + return sbi->au_si_status & flag;
30973 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
30974 +#define au_fset_si(sbinfo, name) do { \
30975 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30976 + (sbinfo)->au_si_status |= AuSi_##name; \
30978 +#define au_fclr_si(sbinfo, name) do { \
30979 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
30980 + (sbinfo)->au_si_status &= ~AuSi_##name; \
30983 +/* ---------------------------------------------------------------------- */
30985 +/* policy to select one among writable branches */
30986 +#define AuWbrCopyup(sbinfo, ...) \
30987 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
30988 +#define AuWbrCreate(sbinfo, ...) \
30989 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
30991 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
30992 +#define AuLock_DW 1 /* write-lock dentry */
30993 +#define AuLock_IR (1 << 1) /* read-lock inode */
30994 +#define AuLock_IW (1 << 2) /* write-lock inode */
30995 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
30996 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
30997 + /* except RENAME_EXCHANGE */
30998 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
30999 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
31000 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
31001 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
31002 +#define au_fset_lock(flags, name) \
31003 + do { (flags) |= AuLock_##name; } while (0)
31004 +#define au_fclr_lock(flags, name) \
31005 + do { (flags) &= ~AuLock_##name; } while (0)
31007 +/* ---------------------------------------------------------------------- */
31010 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
31012 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
31013 + unsigned long long max, void *arg);
31014 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
31015 + struct super_block *sb, void *arg);
31016 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
31017 +void au_iarray_free(struct inode **a, unsigned long long max);
31019 +void au_remount_refresh(struct super_block *sb, unsigned int do_idop);
31020 +extern const struct super_operations aufs_sop;
31021 +int au_alloc_root(struct super_block *sb);
31022 +extern struct file_system_type aufs_fs_type;
31025 +void au_si_free(struct kobject *kobj);
31026 +struct au_sbinfo *au_si_alloc(struct super_block *sb);
31027 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
31029 +unsigned int au_sigen_inc(struct super_block *sb);
31030 +aufs_bindex_t au_new_br_id(struct super_block *sb);
31032 +int si_read_lock(struct super_block *sb, int flags);
31033 +int si_write_lock(struct super_block *sb, int flags);
31034 +int aufs_read_lock(struct dentry *dentry, int flags);
31035 +void aufs_read_unlock(struct dentry *dentry, int flags);
31036 +void aufs_write_lock(struct dentry *dentry);
31037 +void aufs_write_unlock(struct dentry *dentry);
31038 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
31039 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
31041 +/* wbr_policy.c */
31042 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
31043 +extern struct au_wbr_create_operations au_wbr_create_ops[];
31044 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
31045 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
31046 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
31049 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
31051 +#ifdef CONFIG_AUFS_FHSM
31054 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
31058 + spin_lock(&fhsm->fhsm_spin);
31059 + pid = fhsm->fhsm_pid;
31060 + spin_unlock(&fhsm->fhsm_spin);
31065 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
31066 +void au_fhsm_wrote_all(struct super_block *sb, int force);
31067 +int au_fhsm_fd(struct super_block *sb, int oflags);
31068 +int au_fhsm_br_alloc(struct au_branch *br);
31069 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
31070 +void au_fhsm_fin(struct super_block *sb);
31071 +void au_fhsm_init(struct au_sbinfo *sbinfo);
31072 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
31073 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
31075 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
31077 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
31078 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
31079 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
31080 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
31081 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
31082 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
31083 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
31084 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
31085 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
31088 +/* ---------------------------------------------------------------------- */
31090 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
31092 + return sb->s_fs_info;
31095 +/* ---------------------------------------------------------------------- */
31097 +#ifdef CONFIG_AUFS_EXPORT
31098 +int au_test_nfsd(void);
31099 +void au_export_init(struct super_block *sb);
31100 +void au_xigen_inc(struct inode *inode);
31101 +int au_xigen_new(struct inode *inode);
31102 +int au_xigen_set(struct super_block *sb, struct path *path);
31103 +void au_xigen_clr(struct super_block *sb);
31105 +static inline int au_busy_or_stale(void)
31107 + if (!au_test_nfsd())
31112 +AuStubInt0(au_test_nfsd, void)
31113 +AuStubVoid(au_export_init, struct super_block *sb)
31114 +AuStubVoid(au_xigen_inc, struct inode *inode)
31115 +AuStubInt0(au_xigen_new, struct inode *inode)
31116 +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path)
31117 +AuStubVoid(au_xigen_clr, struct super_block *sb)
31118 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
31119 +#endif /* CONFIG_AUFS_EXPORT */
31121 +/* ---------------------------------------------------------------------- */
31123 +#ifdef CONFIG_AUFS_SBILIST
31125 +extern struct hlist_bl_head au_sbilist;
31127 +static inline void au_sbilist_init(void)
31129 + INIT_HLIST_BL_HEAD(&au_sbilist);
31132 +static inline void au_sbilist_add(struct super_block *sb)
31134 + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist);
31137 +static inline void au_sbilist_del(struct super_block *sb)
31139 + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist);
31142 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
31143 +static inline void au_sbilist_lock(void)
31145 + hlist_bl_lock(&au_sbilist);
31148 +static inline void au_sbilist_unlock(void)
31150 + hlist_bl_unlock(&au_sbilist);
31152 +#define AuGFP_SBILIST GFP_ATOMIC
31154 +AuStubVoid(au_sbilist_lock, void)
31155 +AuStubVoid(au_sbilist_unlock, void)
31156 +#define AuGFP_SBILIST GFP_NOFS
31157 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
31159 +AuStubVoid(au_sbilist_init, void)
31160 +AuStubVoid(au_sbilist_add, struct super_block *sb)
31161 +AuStubVoid(au_sbilist_del, struct super_block *sb)
31162 +AuStubVoid(au_sbilist_lock, void)
31163 +AuStubVoid(au_sbilist_unlock, void)
31164 +#define AuGFP_SBILIST GFP_NOFS
31167 +/* ---------------------------------------------------------------------- */
31169 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
31172 + * This function is a dynamic '__init' function actually,
31173 + * so the tiny check for si_rwsem is unnecessary.
31175 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
31176 +#ifdef CONFIG_DEBUG_FS
31177 + sbinfo->si_dbgaufs = NULL;
31178 + sbinfo->si_dbgaufs_plink = NULL;
31179 + sbinfo->si_dbgaufs_xib = NULL;
31180 +#ifdef CONFIG_AUFS_EXPORT
31181 + sbinfo->si_dbgaufs_xigen = NULL;
31186 +/* ---------------------------------------------------------------------- */
31188 +/* current->atomic_flags */
31189 +/* this value should never corrupt the ones defined in linux/sched.h */
31190 +#define PFA_AUFS 0x10
31192 +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */
31193 +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */
31194 +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */
31196 +static inline int si_pid_test(struct super_block *sb)
31198 + return !!task_test_aufs(current);
31201 +static inline void si_pid_clr(struct super_block *sb)
31203 + AuDebugOn(!task_test_aufs(current));
31204 + task_clear_aufs(current);
31207 +static inline void si_pid_set(struct super_block *sb)
31209 + AuDebugOn(task_test_aufs(current));
31210 + task_set_aufs(current);
31213 +/* ---------------------------------------------------------------------- */
31215 +/* lock superblock. mainly for entry point functions */
31216 +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem)
31217 +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem)
31218 +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem)
31219 +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem)
31221 +#define __si_read_trylock_nested(sb) \
31222 + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem)
31223 +#define __si_write_trylock_nested(sb) \
31224 + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem)
31227 +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem)
31228 +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem)
31229 +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem)
31231 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
31232 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
31233 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
31235 +static inline void si_noflush_read_lock(struct super_block *sb)
31237 + __si_read_lock(sb);
31241 +static inline int si_noflush_read_trylock(struct super_block *sb)
31245 + locked = __si_read_trylock(sb);
31251 +static inline void si_noflush_write_lock(struct super_block *sb)
31253 + __si_write_lock(sb);
31257 +static inline int si_noflush_write_trylock(struct super_block *sb)
31261 + locked = __si_write_trylock(sb);
31267 +#if 0 /* reserved */
31268 +static inline int si_read_trylock(struct super_block *sb, int flags)
31270 + if (au_ftest_lock(flags, FLUSH))
31271 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31272 + return si_noflush_read_trylock(sb);
31276 +static inline void si_read_unlock(struct super_block *sb)
31279 + __si_read_unlock(sb);
31282 +#if 0 /* reserved */
31283 +static inline int si_write_trylock(struct super_block *sb, int flags)
31285 + if (au_ftest_lock(flags, FLUSH))
31286 + au_nwt_flush(&au_sbi(sb)->si_nowait);
31287 + return si_noflush_write_trylock(sb);
31291 +static inline void si_write_unlock(struct super_block *sb)
31294 + __si_write_unlock(sb);
31297 +#if 0 /* reserved */
31298 +static inline void si_downgrade_lock(struct super_block *sb)
31300 + __si_downgrade_lock(sb);
31304 +/* ---------------------------------------------------------------------- */
31306 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
31308 + SiMustAnyLock(sb);
31309 + return au_sbi(sb)->si_bbot;
31312 +static inline unsigned int au_mntflags(struct super_block *sb)
31314 + SiMustAnyLock(sb);
31315 + return au_sbi(sb)->si_mntflags;
31318 +static inline unsigned int au_sigen(struct super_block *sb)
31320 + SiMustAnyLock(sb);
31321 + return au_sbi(sb)->si_generation;
31324 +static inline struct au_branch *au_sbr(struct super_block *sb,
31325 + aufs_bindex_t bindex)
31327 + SiMustAnyLock(sb);
31328 + return au_sbi(sb)->si_branch[0 + bindex];
31331 +static inline loff_t au_xi_maxent(struct super_block *sb)
31333 + SiMustAnyLock(sb);
31334 + return au_sbi(sb)->si_ximaxent;
31337 +#endif /* __KERNEL__ */
31338 +#endif /* __AUFS_SUPER_H__ */
31339 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
31340 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
31341 +++ linux/fs/aufs/sysaufs.c 2022-11-05 23:02:18.969222617 +0100
31343 +// SPDX-License-Identifier: GPL-2.0
31345 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31347 + * This program is free software; you can redistribute it and/or modify
31348 + * it under the terms of the GNU General Public License as published by
31349 + * the Free Software Foundation; either version 2 of the License, or
31350 + * (at your option) any later version.
31352 + * This program is distributed in the hope that it will be useful,
31353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31355 + * GNU General Public License for more details.
31357 + * You should have received a copy of the GNU General Public License
31358 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31362 + * sysfs interface and lifetime management
31363 + * they are necessary regardless sysfs is disabled.
31366 +#include <linux/random.h>
31369 +unsigned long sysaufs_si_mask;
31370 +struct kset *sysaufs_kset;
31372 +#define AuSiAttr(_name) { \
31373 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
31374 + .show = sysaufs_si_##_name, \
31377 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
31378 +struct attribute *sysaufs_si_attrs[] = {
31379 + &sysaufs_si_attr_xi_path.attr,
31382 +ATTRIBUTE_GROUPS(sysaufs_si);
31384 +static const struct sysfs_ops au_sbi_ops = {
31385 + .show = sysaufs_si_show
31388 +static struct kobj_type au_sbi_ktype = {
31389 + .release = au_si_free,
31390 + .sysfs_ops = &au_sbi_ops,
31391 + .default_groups = sysaufs_si_groups
31394 +/* ---------------------------------------------------------------------- */
31396 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
31400 + sbinfo->si_kobj.kset = sysaufs_kset;
31401 + /* cf. sysaufs_name() */
31402 + err = kobject_init_and_add
31403 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
31404 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
31409 +void sysaufs_fin(void)
31411 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31412 + kset_unregister(sysaufs_kset);
31415 +int __init sysaufs_init(void)
31420 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
31421 + } while (!sysaufs_si_mask);
31424 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
31425 + if (unlikely(!sysaufs_kset))
31427 + err = PTR_ERR(sysaufs_kset);
31428 + if (IS_ERR(sysaufs_kset))
31430 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
31431 + if (unlikely(err))
31432 + kset_unregister(sysaufs_kset);
31437 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
31438 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
31439 +++ linux/fs/aufs/sysaufs.h 2022-11-05 23:02:18.969222617 +0100
31441 +/* SPDX-License-Identifier: GPL-2.0 */
31443 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31445 + * This program is free software; you can redistribute it and/or modify
31446 + * it under the terms of the GNU General Public License as published by
31447 + * the Free Software Foundation; either version 2 of the License, or
31448 + * (at your option) any later version.
31450 + * This program is distributed in the hope that it will be useful,
31451 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31452 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31453 + * GNU General Public License for more details.
31455 + * You should have received a copy of the GNU General Public License
31456 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31460 + * sysfs interface and mount lifetime management
31463 +#ifndef __SYSAUFS_H__
31464 +#define __SYSAUFS_H__
31468 +#include <linux/sysfs.h>
31469 +#include "module.h"
31471 +struct super_block;
31474 +struct sysaufs_si_attr {
31475 + struct attribute attr;
31476 + int (*show)(struct seq_file *seq, struct super_block *sb);
31479 +/* ---------------------------------------------------------------------- */
31482 +extern unsigned long sysaufs_si_mask;
31483 +extern struct kset *sysaufs_kset;
31484 +extern struct attribute *sysaufs_si_attrs[];
31485 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
31486 +int __init sysaufs_init(void);
31487 +void sysaufs_fin(void);
31489 +/* ---------------------------------------------------------------------- */
31491 +/* some people doesn't like to show a pointer in kernel */
31492 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
31494 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
31497 +#define SysaufsSiNamePrefix "si_"
31498 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
31499 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
31501 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
31502 + sysaufs_si_id(sbinfo));
31506 +#ifdef CONFIG_SYSFS
31508 +extern struct attribute_group *sysaufs_attr_group;
31510 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
31511 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31513 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
31514 +#ifdef CONFIG_COMPAT
31515 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
31518 +void sysaufs_br_init(struct au_branch *br);
31519 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
31520 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
31522 +#define sysaufs_brs_init() do {} while (0)
31525 +#define sysaufs_attr_group NULL
31527 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
31528 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
31529 + struct attribute *attr, char *buf)
31530 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
31531 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
31532 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
31534 +static inline void sysaufs_brs_init(void)
31539 +#endif /* CONFIG_SYSFS */
31541 +#endif /* __KERNEL__ */
31542 +#endif /* __SYSAUFS_H__ */
31543 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
31544 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
31545 +++ linux/fs/aufs/sysfs.c 2022-11-05 23:02:18.969222617 +0100
31547 +// SPDX-License-Identifier: GPL-2.0
31549 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31551 + * This program is free software; you can redistribute it and/or modify
31552 + * it under the terms of the GNU General Public License as published by
31553 + * the Free Software Foundation; either version 2 of the License, or
31554 + * (at your option) any later version.
31556 + * This program is distributed in the hope that it will be useful,
31557 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31558 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31559 + * GNU General Public License for more details.
31561 + * You should have received a copy of the GNU General Public License
31562 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31566 + * sysfs interface
31569 +#include <linux/compat.h>
31570 +#include <linux/seq_file.h>
31573 +#ifdef CONFIG_AUFS_FS_MODULE
31574 +/* this entry violates the "one line per file" policy of sysfs */
31575 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
31579 + static char *conf =
31580 +/* this file is generated at compiling */
31581 +#include "conf.str"
31584 + err = snprintf(buf, PAGE_SIZE, conf);
31585 + if (unlikely(err >= PAGE_SIZE))
31590 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
31593 +static struct attribute *au_attr[] = {
31594 +#ifdef CONFIG_AUFS_FS_MODULE
31595 + &au_config_attr.attr,
31597 + NULL, /* need to NULL terminate the list of attributes */
31600 +static struct attribute_group sysaufs_attr_group_body = {
31604 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
31606 +/* ---------------------------------------------------------------------- */
31608 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
31612 + SiMustAnyLock(sb);
31615 + if (au_opt_test(au_mntflags(sb), XINO)) {
31616 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
31617 + seq_putc(seq, '\n');
31623 + * the lifetime of branch is independent from the entry under sysfs.
31624 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
31627 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
31628 + aufs_bindex_t bindex, int idx)
31631 + struct path path;
31632 + struct dentry *root;
31633 + struct au_branch *br;
31634 + au_br_perm_str_t perm;
31636 + AuDbg("b%d\n", bindex);
31639 + root = sb->s_root;
31640 + di_read_lock_parent(root, !AuLock_IR);
31641 + br = au_sbr(sb, bindex);
31644 + case AuBrSysfs_BR:
31645 + path.mnt = au_br_mnt(br);
31646 + path.dentry = au_h_dptr(root, bindex);
31647 + err = au_seq_path(seq, &path);
31649 + au_optstr_br_perm(&perm, br->br_perm);
31650 + seq_printf(seq, "=%s\n", perm.a);
31653 + case AuBrSysfs_BRID:
31654 + seq_printf(seq, "%d\n", br->br_id);
31657 + di_read_unlock(root, !AuLock_IR);
31658 + if (unlikely(err || seq_has_overflowed(seq)))
31664 +/* ---------------------------------------------------------------------- */
31666 +static struct seq_file *au_seq(char *p, ssize_t len)
31668 + struct seq_file *seq;
31670 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
31672 + /* mutex_init(&seq.lock); */
31675 + return seq; /* success */
31678 + seq = ERR_PTR(-ENOMEM);
31682 +#define SysaufsBr_PREFIX "br"
31683 +#define SysaufsBrid_PREFIX "brid"
31685 +/* todo: file size may exceed PAGE_SIZE */
31686 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
31692 + aufs_bindex_t bbot;
31693 + struct au_sbinfo *sbinfo;
31694 + struct super_block *sb;
31695 + struct seq_file *seq;
31697 + struct attribute **cattr;
31699 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
31700 + sb = sbinfo->si_sb;
31703 + * prevent a race condition between sysfs and aufs.
31704 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
31705 + * prohibits maintaining the sysfs entries.
31706 + * hew we acquire read lock after sysfs_get_active_two().
31707 + * on the other hand, the remount process may maintain the sysfs/aufs
31708 + * entries after acquiring write lock.
31709 + * it can cause a deadlock.
31710 + * simply we gave up processing read here.
31713 + if (unlikely(!si_noflush_read_trylock(sb)))
31716 + seq = au_seq(buf, PAGE_SIZE);
31717 + err = PTR_ERR(seq);
31721 + name = (void *)attr->name;
31722 + cattr = sysaufs_si_attrs;
31724 + if (!strcmp(name, (*cattr)->name)) {
31725 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
31732 + if (!strncmp(name, SysaufsBrid_PREFIX,
31733 + sizeof(SysaufsBrid_PREFIX) - 1)) {
31734 + idx = AuBrSysfs_BRID;
31735 + name += sizeof(SysaufsBrid_PREFIX) - 1;
31736 + } else if (!strncmp(name, SysaufsBr_PREFIX,
31737 + sizeof(SysaufsBr_PREFIX) - 1)) {
31738 + idx = AuBrSysfs_BR;
31739 + name += sizeof(SysaufsBr_PREFIX) - 1;
31743 + err = kstrtol(name, 10, &l);
31745 + bbot = au_sbbot(sb);
31747 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
31754 + err = seq->count;
31755 + /* sysfs limit */
31756 + if (unlikely(err == PAGE_SIZE))
31759 + au_kfree_rcu(seq);
31761 + si_read_unlock(sb);
31766 +/* ---------------------------------------------------------------------- */
31768 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
31772 + aufs_bindex_t bindex, bbot;
31775 + struct seq_file *seq;
31776 + struct au_branch *br;
31778 + si_read_lock(sb, AuLock_FLUSH);
31779 + bbot = au_sbbot(sb);
31785 + buf = (void *)__get_free_page(GFP_NOFS);
31786 + if (unlikely(!buf))
31789 + seq = au_seq(buf, PAGE_SIZE);
31790 + err = PTR_ERR(seq);
31794 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
31795 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
31796 + /* VERIFY_WRITE */
31797 + err = !access_ok(arg, sizeof(*arg));
31798 + if (unlikely(err))
31801 + br = au_sbr(sb, bindex);
31802 + brid = br->br_id;
31803 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
31804 + err = __put_user(brid, &arg->id);
31805 + if (unlikely(err))
31808 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
31809 + err = __put_user(br->br_perm, &arg->perm);
31810 + if (unlikely(err))
31813 + err = au_seq_path(seq, &br->br_path);
31814 + if (unlikely(err))
31816 + seq_putc(seq, '\0');
31817 + if (!seq_has_overflowed(seq)) {
31818 + err = copy_to_user(arg->path, seq->buf, seq->count);
31820 + if (unlikely(err))
31827 + if (unlikely(err))
31831 + au_kfree_rcu(seq);
31833 + free_page((unsigned long)buf);
31835 + si_read_unlock(sb);
31839 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
31841 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
31844 +#ifdef CONFIG_COMPAT
31845 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
31847 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
31851 +/* ---------------------------------------------------------------------- */
31853 +void sysaufs_br_init(struct au_branch *br)
31856 + struct au_brsysfs *br_sysfs;
31857 + struct attribute *attr;
31859 + br_sysfs = br->br_sysfs;
31860 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31861 + attr = &br_sysfs->attr;
31862 + sysfs_attr_init(attr);
31863 + attr->name = br_sysfs->name;
31864 + attr->mode = 0444;
31869 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
31871 + struct au_branch *br;
31872 + struct kobject *kobj;
31873 + struct au_brsysfs *br_sysfs;
31875 + aufs_bindex_t bbot;
31877 + if (!sysaufs_brs)
31880 + kobj = &au_sbi(sb)->si_kobj;
31881 + bbot = au_sbbot(sb);
31882 + for (; bindex <= bbot; bindex++) {
31883 + br = au_sbr(sb, bindex);
31884 + br_sysfs = br->br_sysfs;
31885 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31886 + sysfs_remove_file(kobj, &br_sysfs->attr);
31892 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
31895 + aufs_bindex_t bbot;
31896 + struct kobject *kobj;
31897 + struct au_branch *br;
31898 + struct au_brsysfs *br_sysfs;
31900 + if (!sysaufs_brs)
31903 + kobj = &au_sbi(sb)->si_kobj;
31904 + bbot = au_sbbot(sb);
31905 + for (; bindex <= bbot; bindex++) {
31906 + br = au_sbr(sb, bindex);
31907 + br_sysfs = br->br_sysfs;
31908 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
31909 + SysaufsBr_PREFIX "%d", bindex);
31910 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
31911 + SysaufsBrid_PREFIX "%d", bindex);
31912 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
31913 + err = sysfs_create_file(kobj, &br_sysfs->attr);
31914 + if (unlikely(err))
31915 + pr_warn("failed %s under sysfs(%d)\n",
31916 + br_sysfs->name, err);
31921 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
31922 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
31923 +++ linux/fs/aufs/sysrq.c 2022-11-05 23:02:18.969222617 +0100
31925 +// SPDX-License-Identifier: GPL-2.0
31927 + * Copyright (C) 2005-2022 Junjiro R. Okajima
31929 + * This program is free software; you can redistribute it and/or modify
31930 + * it under the terms of the GNU General Public License as published by
31931 + * the Free Software Foundation; either version 2 of the License, or
31932 + * (at your option) any later version.
31934 + * This program is distributed in the hope that it will be useful,
31935 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31936 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31937 + * GNU General Public License for more details.
31939 + * You should have received a copy of the GNU General Public License
31940 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31944 + * magic sysrq handler
31947 +/* #include <linux/sysrq.h> */
31948 +#include <linux/writeback.h>
31951 +/* ---------------------------------------------------------------------- */
31953 +static void sysrq_sb(struct super_block *sb)
31956 + struct au_sbinfo *sbinfo;
31957 + struct file *file;
31958 + struct hlist_bl_head *files;
31959 + struct hlist_bl_node *pos;
31960 + struct au_finfo *finfo;
31963 + plevel = au_plevel;
31964 + au_plevel = KERN_WARNING;
31966 + /* since we define pr_fmt, call printk directly */
31967 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
31969 + sbinfo = au_sbi(sb);
31970 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
31971 + pr("superblock\n");
31974 +#if 0 /* reserved */
31976 + int err, i, j, ndentry;
31977 + struct au_dcsub_pages dpages;
31978 + struct au_dpage *dpage;
31980 + err = au_dpages_init(&dpages, GFP_ATOMIC);
31981 + if (unlikely(err))
31983 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
31985 + for (i = 0; i < dpages.ndpage; i++) {
31986 + dpage = dpages.dpages + i;
31987 + ndentry = dpage->ndentry;
31988 + for (j = 0; j < ndentry; j++)
31989 + au_dpri_dentry(dpage->dentries[j]);
31991 + au_dpages_free(&dpages);
31995 + pr("isolated inode\n");
31996 + spin_lock(&sb->s_inode_list_lock);
31997 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
31998 + spin_lock(&i->i_lock);
31999 + if (hlist_empty(&i->i_dentry))
32000 + au_dpri_inode(i);
32001 + spin_unlock(&i->i_lock);
32003 + spin_unlock(&sb->s_inode_list_lock);
32006 + files = &au_sbi(sb)->si_files;
32007 + hlist_bl_lock(files);
32008 + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) {
32011 + file = finfo->fi_file;
32012 + mode = file_inode(file)->i_mode;
32013 + if (!special_file(mode))
32014 + au_dpri_file(file);
32016 + hlist_bl_unlock(files);
32020 + au_plevel = plevel;
32023 +/* ---------------------------------------------------------------------- */
32025 +/* module parameter */
32026 +static char *aufs_sysrq_key = "a";
32027 +module_param_named(sysrq, aufs_sysrq_key, charp, 0444);
32028 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
32030 +static void au_sysrq(int key __maybe_unused)
32032 + struct au_sbinfo *sbinfo;
32033 + struct hlist_bl_node *pos;
32036 + au_sbilist_lock();
32037 + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list)
32038 + sysrq_sb(sbinfo->si_sb);
32039 + au_sbilist_unlock();
32043 +static struct sysrq_key_op au_sysrq_op = {
32044 + .handler = au_sysrq,
32045 + .help_msg = "Aufs",
32046 + .action_msg = "Aufs",
32047 + .enable_mask = SYSRQ_ENABLE_DUMP
32050 +/* ---------------------------------------------------------------------- */
32052 +int __init au_sysrq_init(void)
32058 + key = *aufs_sysrq_key;
32059 + if ('a' <= key && key <= 'z')
32060 + err = register_sysrq_key(key, &au_sysrq_op);
32061 + if (unlikely(err))
32062 + pr_err("err %d, sysrq=%c\n", err, key);
32066 +void au_sysrq_fin(void)
32070 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
32071 + if (unlikely(err))
32072 + pr_err("err %d (ignored)\n", err);
32074 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
32075 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
32076 +++ linux/fs/aufs/vdir.c 2022-12-17 09:21:34.799855195 +0100
32078 +// SPDX-License-Identifier: GPL-2.0
32080 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32082 + * This program is free software; you can redistribute it and/or modify
32083 + * it under the terms of the GNU General Public License as published by
32084 + * the Free Software Foundation; either version 2 of the License, or
32085 + * (at your option) any later version.
32087 + * This program is distributed in the hope that it will be useful,
32088 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32089 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32090 + * GNU General Public License for more details.
32092 + * You should have received a copy of the GNU General Public License
32093 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32097 + * virtual or vertical directory
32100 +#include <linux/iversion.h>
32103 +static unsigned int calc_size(int nlen)
32105 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
32108 +static int set_deblk_end(union au_vdir_deblk_p *p,
32109 + union au_vdir_deblk_p *deblk_end)
32111 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
32112 + p->de->de_str.len = 0;
32116 + return -1; /* error */
32119 +/* returns true or false */
32120 +static int is_deblk_end(union au_vdir_deblk_p *p,
32121 + union au_vdir_deblk_p *deblk_end)
32123 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
32124 + return !p->de->de_str.len;
32128 +static unsigned char *last_deblk(struct au_vdir *vdir)
32130 + return vdir->vd_deblk[vdir->vd_nblk - 1];
32133 +/* ---------------------------------------------------------------------- */
32135 +/* estimate the appropriate size for name hash table */
32136 +unsigned int au_rdhash_est(loff_t sz)
32144 + if (sz < AUFS_RDHASH_DEF)
32145 + n = AUFS_RDHASH_DEF;
32146 + /* pr_info("n %u\n", n); */
32151 + * the allocated memory has to be freed by
32152 + * au_nhash_wh_free() or au_nhash_de_free().
32154 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
32156 + struct hlist_head *head;
32160 + sz = sizeof(*nhash->nh_head) * num_hash;
32161 + head = kmalloc(sz, gfp);
32163 + nhash->nh_num = num_hash;
32164 + nhash->nh_head = head;
32165 + for (u = 0; u < num_hash; u++)
32166 + INIT_HLIST_HEAD(head++);
32167 + return 0; /* success */
32173 +static void nhash_count(struct hlist_head *head)
32175 +#if 0 /* debugging */
32177 + struct hlist_node *pos;
32180 + hlist_for_each(pos, head)
32182 + pr_info("%lu\n", n);
32186 +static void au_nhash_wh_do_free(struct hlist_head *head)
32188 + struct au_vdir_wh *pos;
32189 + struct hlist_node *node;
32191 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
32192 + au_kfree_rcu(pos);
32195 +static void au_nhash_de_do_free(struct hlist_head *head)
32197 + struct au_vdir_dehstr *pos;
32198 + struct hlist_node *node;
32200 + hlist_for_each_entry_safe(pos, node, head, hash)
32201 + au_cache_free_vdir_dehstr(pos);
32204 +static void au_nhash_do_free(struct au_nhash *nhash,
32205 + void (*free)(struct hlist_head *head))
32208 + struct hlist_head *head;
32210 + n = nhash->nh_num;
32214 + head = nhash->nh_head;
32215 + while (n-- > 0) {
32216 + nhash_count(head);
32219 + au_kfree_try_rcu(nhash->nh_head);
32222 +void au_nhash_wh_free(struct au_nhash *whlist)
32224 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
32227 +static void au_nhash_de_free(struct au_nhash *delist)
32229 + au_nhash_do_free(delist, au_nhash_de_do_free);
32232 +/* ---------------------------------------------------------------------- */
32234 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
32238 + unsigned int u, n;
32239 + struct hlist_head *head;
32240 + struct au_vdir_wh *pos;
32243 + n = whlist->nh_num;
32244 + head = whlist->nh_head;
32245 + for (u = 0; u < n; u++, head++)
32246 + hlist_for_each_entry(pos, head, wh_hash)
32247 + if (pos->wh_bindex == btgt && ++num > limit)
32252 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
32253 + unsigned char *name,
32254 + unsigned int len)
32257 + /* const unsigned int magic_bit = 12; */
32259 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
32266 + /* v = hash_long(v, magic_bit); */
32267 + v %= nhash->nh_num;
32268 + return nhash->nh_head + v;
32271 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
32274 + return str->len == nlen && !memcmp(str->name, name, nlen);
32277 +/* returns found or not */
32278 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
32280 + struct hlist_head *head;
32281 + struct au_vdir_wh *pos;
32282 + struct au_vdir_destr *str;
32284 + head = au_name_hash(whlist, name, nlen);
32285 + hlist_for_each_entry(pos, head, wh_hash) {
32286 + str = &pos->wh_str;
32287 + AuDbg("%.*s\n", str->len, str->name);
32288 + if (au_nhash_test_name(str, name, nlen))
32294 +/* returns found(true) or not */
32295 +static int test_known(struct au_nhash *delist, char *name, int nlen)
32297 + struct hlist_head *head;
32298 + struct au_vdir_dehstr *pos;
32299 + struct au_vdir_destr *str;
32301 + head = au_name_hash(delist, name, nlen);
32302 + hlist_for_each_entry(pos, head, hash) {
32304 + AuDbg("%.*s\n", str->len, str->name);
32305 + if (au_nhash_test_name(str, name, nlen))
32311 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
32312 + unsigned char d_type)
32314 +#ifdef CONFIG_AUFS_SHWH
32315 + wh->wh_ino = ino;
32316 + wh->wh_type = d_type;
32320 +/* ---------------------------------------------------------------------- */
32322 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
32323 + unsigned int d_type, aufs_bindex_t bindex,
32324 + unsigned char shwh)
32327 + struct au_vdir_destr *str;
32328 + struct au_vdir_wh *wh;
32330 + AuDbg("%.*s\n", nlen, name);
32331 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
32334 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
32335 + if (unlikely(!wh))
32339 + wh->wh_bindex = bindex;
32341 + au_shwh_init_wh(wh, ino, d_type);
32342 + str = &wh->wh_str;
32344 + memcpy(str->name, name, nlen);
32345 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
32352 +static int append_deblk(struct au_vdir *vdir)
32355 + unsigned long ul;
32356 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32357 + union au_vdir_deblk_p p, deblk_end;
32358 + unsigned char **o;
32361 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
32362 + GFP_NOFS, /*may_shrink*/0);
32363 + if (unlikely(!o))
32366 + vdir->vd_deblk = o;
32367 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
32369 + ul = vdir->vd_nblk++;
32370 + vdir->vd_deblk[ul] = p.deblk;
32371 + vdir->vd_last.ul = ul;
32372 + vdir->vd_last.p.deblk = p.deblk;
32373 + deblk_end.deblk = p.deblk + deblk_sz;
32374 + err = set_deblk_end(&p, &deblk_end);
32381 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
32382 + unsigned int d_type, struct au_nhash *delist)
32386 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
32387 + union au_vdir_deblk_p p, *room, deblk_end;
32388 + struct au_vdir_dehstr *dehstr;
32390 + p.deblk = last_deblk(vdir);
32391 + deblk_end.deblk = p.deblk + deblk_sz;
32392 + room = &vdir->vd_last.p;
32393 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
32394 + || !is_deblk_end(room, &deblk_end));
32396 + sz = calc_size(nlen);
32397 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
32398 + err = append_deblk(vdir);
32399 + if (unlikely(err))
32402 + p.deblk = last_deblk(vdir);
32403 + deblk_end.deblk = p.deblk + deblk_sz;
32405 + AuDebugOn(room->deblk != p.deblk);
32409 + dehstr = au_cache_alloc_vdir_dehstr();
32410 + if (unlikely(!dehstr))
32413 + dehstr->str = &room->de->de_str;
32414 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
32415 + room->de->de_ino = ino;
32416 + room->de->de_type = d_type;
32417 + room->de->de_str.len = nlen;
32418 + memcpy(room->de->de_str.name, name, nlen);
32421 + room->deblk += sz;
32422 + if (unlikely(set_deblk_end(room, &deblk_end)))
32423 + err = append_deblk(vdir);
32430 +/* ---------------------------------------------------------------------- */
32432 +void au_vdir_free(struct au_vdir *vdir)
32434 + unsigned char **deblk;
32436 + deblk = vdir->vd_deblk;
32437 + while (vdir->vd_nblk--)
32438 + au_kfree_try_rcu(*deblk++);
32439 + au_kfree_try_rcu(vdir->vd_deblk);
32440 + au_cache_free_vdir(vdir);
32443 +static struct au_vdir *alloc_vdir(struct file *file)
32445 + struct au_vdir *vdir;
32446 + struct super_block *sb;
32449 + sb = file->f_path.dentry->d_sb;
32450 + SiMustAnyLock(sb);
32453 + vdir = au_cache_alloc_vdir();
32454 + if (unlikely(!vdir))
32457 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
32458 + if (unlikely(!vdir->vd_deblk))
32461 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
32462 + if (!vdir->vd_deblk_sz) {
32463 + /* estimate the appropriate size for deblk */
32464 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
32465 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
32467 + vdir->vd_nblk = 0;
32468 + vdir->vd_version = 0;
32469 + vdir->vd_jiffy = 0;
32470 + err = append_deblk(vdir);
32472 + return vdir; /* success */
32474 + au_kfree_try_rcu(vdir->vd_deblk);
32477 + au_cache_free_vdir(vdir);
32479 + vdir = ERR_PTR(err);
32483 +static int reinit_vdir(struct au_vdir *vdir)
32486 + union au_vdir_deblk_p p, deblk_end;
32488 + while (vdir->vd_nblk > 1) {
32489 + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]);
32490 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
32493 + p.deblk = vdir->vd_deblk[0];
32494 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
32495 + err = set_deblk_end(&p, &deblk_end);
32496 + /* keep vd_dblk_sz */
32497 + vdir->vd_last.ul = 0;
32498 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32499 + vdir->vd_version = 0;
32500 + vdir->vd_jiffy = 0;
32505 +/* ---------------------------------------------------------------------- */
32507 +#define AuFillVdir_CALLED 1
32508 +#define AuFillVdir_WHABLE (1 << 1)
32509 +#define AuFillVdir_SHWH (1 << 2)
32510 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
32511 +#define au_fset_fillvdir(flags, name) \
32512 + do { (flags) |= AuFillVdir_##name; } while (0)
32513 +#define au_fclr_fillvdir(flags, name) \
32514 + do { (flags) &= ~AuFillVdir_##name; } while (0)
32516 +#ifndef CONFIG_AUFS_SHWH
32517 +#undef AuFillVdir_SHWH
32518 +#define AuFillVdir_SHWH 0
32521 +struct fillvdir_arg {
32522 + struct dir_context ctx;
32523 + struct file *file;
32524 + struct au_vdir *vdir;
32525 + struct au_nhash delist;
32526 + struct au_nhash whlist;
32527 + aufs_bindex_t bindex;
32528 + unsigned int flags;
32532 +static bool fillvdir(struct dir_context *ctx, const char *__name, int nlen,
32533 + loff_t offset __maybe_unused, u64 h_ino,
32534 + unsigned int d_type)
32536 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
32537 + char *name = (void *)__name;
32538 + struct super_block *sb;
32540 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
32543 + sb = arg->file->f_path.dentry->d_sb;
32544 + au_fset_fillvdir(arg->flags, CALLED);
32546 + if (nlen <= AUFS_WH_PFX_LEN
32547 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
32548 + if (test_known(&arg->delist, name, nlen)
32549 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
32550 + goto out; /* already exists or whiteouted */
32552 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
32554 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
32555 + d_type = DT_UNKNOWN;
32556 + arg->err = append_de(arg->vdir, name, nlen, ino,
32557 + d_type, &arg->delist);
32559 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
32560 + name += AUFS_WH_PFX_LEN;
32561 + nlen -= AUFS_WH_PFX_LEN;
32562 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
32563 + goto out; /* already whiteouted */
32565 + ino = 0; /* just to suppress a warning */
32567 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
32570 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
32571 + d_type = DT_UNKNOWN;
32572 + arg->err = au_nhash_append_wh
32573 + (&arg->whlist, name, nlen, ino, d_type,
32574 + arg->bindex, shwh);
32580 + arg->vdir->vd_jiffy = jiffies;
32582 + AuTraceErr(arg->err);
32583 + return !arg->err;
32586 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
32587 + struct au_nhash *whlist, struct au_nhash *delist)
32589 +#ifdef CONFIG_AUFS_SHWH
32591 + unsigned int nh, u;
32592 + struct hlist_head *head;
32593 + struct au_vdir_wh *pos;
32594 + struct hlist_node *n;
32596 + struct au_vdir_destr *destr;
32598 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
32601 + o = p = (void *)__get_free_page(GFP_NOFS);
32602 + if (unlikely(!p))
32606 + nh = whlist->nh_num;
32607 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32608 + p += AUFS_WH_PFX_LEN;
32609 + for (u = 0; u < nh; u++) {
32610 + head = whlist->nh_head + u;
32611 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
32612 + destr = &pos->wh_str;
32613 + memcpy(p, destr->name, destr->len);
32614 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
32615 + pos->wh_ino, pos->wh_type, delist);
32616 + if (unlikely(err))
32621 + free_page((unsigned long)o);
32631 +static int au_do_read_vdir(struct fillvdir_arg *arg)
32634 + unsigned int rdhash;
32636 + aufs_bindex_t bbot, bindex, btop;
32637 + unsigned char shwh;
32638 + struct file *hf, *file;
32639 + struct super_block *sb;
32641 + file = arg->file;
32642 + sb = file->f_path.dentry->d_sb;
32643 + SiMustAnyLock(sb);
32645 + rdhash = au_sbi(sb)->si_rdhash;
32647 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
32648 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
32649 + if (unlikely(err))
32651 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
32652 + if (unlikely(err))
32658 + if (au_opt_test(au_mntflags(sb), SHWH)) {
32660 + au_fset_fillvdir(arg->flags, SHWH);
32662 + btop = au_fbtop(file);
32663 + bbot = au_fbbot_dir(file);
32664 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
32665 + hf = au_hf_dir(file, bindex);
32669 + offset = vfsub_llseek(hf, 0, SEEK_SET);
32671 + if (unlikely(offset))
32674 + arg->bindex = bindex;
32675 + au_fclr_fillvdir(arg->flags, WHABLE);
32677 + || (bindex != bbot
32678 + && au_br_whable(au_sbr_perm(sb, bindex))))
32679 + au_fset_fillvdir(arg->flags, WHABLE);
32682 + au_fclr_fillvdir(arg->flags, CALLED);
32684 + err = vfsub_iterate_dir(hf, &arg->ctx);
32687 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
32690 + * dir_relax() may be good for concurrency, but aufs should not
32691 + * use it since it will cause a lockdep problem.
32695 + if (!err && shwh)
32696 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
32698 + au_nhash_wh_free(&arg->whlist);
32701 + au_nhash_de_free(&arg->delist);
32706 +static int read_vdir(struct file *file, int may_read)
32709 + unsigned long expire;
32710 + unsigned char do_read;
32711 + struct fillvdir_arg arg = {
32713 + .actor = fillvdir
32716 + struct inode *inode;
32717 + struct au_vdir *vdir, *allocated;
32720 + inode = file_inode(file);
32721 + IMustLock(inode);
32722 + IiMustWriteLock(inode);
32723 + SiMustAnyLock(inode->i_sb);
32725 + allocated = NULL;
32727 + expire = au_sbi(inode->i_sb)->si_rdcache;
32728 + vdir = au_ivdir(inode);
32731 + vdir = alloc_vdir(file);
32732 + err = PTR_ERR(vdir);
32733 + if (IS_ERR(vdir))
32736 + allocated = vdir;
32737 + } else if (may_read
32738 + && (!inode_eq_iversion(inode, vdir->vd_version)
32739 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
32741 + err = reinit_vdir(vdir);
32742 + if (unlikely(err))
32747 + return 0; /* success */
32751 + err = au_do_read_vdir(&arg);
32753 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
32754 + vdir->vd_version = inode_query_iversion(inode);
32755 + vdir->vd_last.ul = 0;
32756 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
32758 + au_set_ivdir(inode, allocated);
32759 + } else if (allocated)
32760 + au_vdir_free(allocated);
32766 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
32769 + unsigned long ul, n;
32770 + const unsigned int deblk_sz = src->vd_deblk_sz;
32772 + AuDebugOn(tgt->vd_nblk != 1);
32775 + if (tgt->vd_nblk < src->vd_nblk) {
32776 + unsigned char **p;
32778 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
32779 + GFP_NOFS, /*may_shrink*/0);
32780 + if (unlikely(!p))
32782 + tgt->vd_deblk = p;
32785 + if (tgt->vd_deblk_sz != deblk_sz) {
32786 + unsigned char *p;
32788 + tgt->vd_deblk_sz = deblk_sz;
32789 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
32790 + /*may_shrink*/1);
32791 + if (unlikely(!p))
32793 + tgt->vd_deblk[0] = p;
32795 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
32796 + tgt->vd_version = src->vd_version;
32797 + tgt->vd_jiffy = src->vd_jiffy;
32799 + n = src->vd_nblk;
32800 + for (ul = 1; ul < n; ul++) {
32801 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
32803 + if (unlikely(!tgt->vd_deblk[ul]))
32807 + tgt->vd_nblk = n;
32808 + tgt->vd_last.ul = tgt->vd_last.ul;
32809 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
32810 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
32811 + - src->vd_deblk[src->vd_last.ul];
32813 + return 0; /* success */
32816 + rerr = reinit_vdir(tgt);
32821 +int au_vdir_init(struct file *file)
32824 + struct inode *inode;
32825 + struct au_vdir *vdir_cache, *allocated;
32827 + /* test file->f_pos here instead of ctx->pos */
32828 + err = read_vdir(file, !file->f_pos);
32829 + if (unlikely(err))
32832 + allocated = NULL;
32833 + vdir_cache = au_fvdir_cache(file);
32834 + if (!vdir_cache) {
32835 + vdir_cache = alloc_vdir(file);
32836 + err = PTR_ERR(vdir_cache);
32837 + if (IS_ERR(vdir_cache))
32839 + allocated = vdir_cache;
32840 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
32841 + /* test file->f_pos here instead of ctx->pos */
32842 + err = reinit_vdir(vdir_cache);
32843 + if (unlikely(err))
32846 + return 0; /* success */
32848 + inode = file_inode(file);
32849 + err = copy_vdir(vdir_cache, au_ivdir(inode));
32851 + file->f_version = inode_query_iversion(inode);
32853 + au_set_fvdir_cache(file, allocated);
32854 + } else if (allocated)
32855 + au_vdir_free(allocated);
32861 +static loff_t calc_offset(struct au_vdir *vdir)
32864 + union au_vdir_deblk_p p;
32866 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
32867 + offset = vdir->vd_last.p.deblk - p.deblk;
32868 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
32872 +/* returns true or false */
32873 +static int seek_vdir(struct file *file, struct dir_context *ctx)
32876 + unsigned int deblk_sz;
32877 + unsigned long ul, n;
32879 + union au_vdir_deblk_p p, deblk_end;
32880 + struct au_vdir *vdir_cache;
32883 + vdir_cache = au_fvdir_cache(file);
32884 + offset = calc_offset(vdir_cache);
32885 + AuDbg("offset %lld\n", offset);
32886 + if (ctx->pos == offset)
32889 + vdir_cache->vd_last.ul = 0;
32890 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
32895 + deblk_sz = vdir_cache->vd_deblk_sz;
32896 + ul = div64_u64(ctx->pos, deblk_sz);
32897 + AuDbg("ul %lu\n", ul);
32898 + if (ul >= vdir_cache->vd_nblk)
32901 + n = vdir_cache->vd_nblk;
32902 + for (; ul < n; ul++) {
32903 + p.deblk = vdir_cache->vd_deblk[ul];
32904 + deblk_end.deblk = p.deblk + deblk_sz;
32906 + offset *= deblk_sz;
32907 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
32910 + l = calc_size(p.de->de_str.len);
32914 + if (!is_deblk_end(&p, &deblk_end)) {
32916 + vdir_cache->vd_last.ul = ul;
32917 + vdir_cache->vd_last.p = p;
32925 + AuDbg("valid %d\n", !valid);
32929 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
32931 + unsigned int l, deblk_sz;
32932 + union au_vdir_deblk_p deblk_end;
32933 + struct au_vdir *vdir_cache;
32934 + struct au_vdir_de *de;
32936 + if (!seek_vdir(file, ctx))
32939 + vdir_cache = au_fvdir_cache(file);
32940 + deblk_sz = vdir_cache->vd_deblk_sz;
32942 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32943 + deblk_end.deblk += deblk_sz;
32944 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
32945 + de = vdir_cache->vd_last.p.de;
32946 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
32947 + de->de_str.len, de->de_str.name, ctx->pos,
32948 + (unsigned long)de->de_ino, de->de_type);
32949 + if (unlikely(!dir_emit(ctx, de->de_str.name,
32950 + de->de_str.len, de->de_ino,
32952 + /* todo: ignore the error caused by udba? */
32953 + /* return err; */
32957 + l = calc_size(de->de_str.len);
32958 + vdir_cache->vd_last.p.deblk += l;
32961 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
32962 + vdir_cache->vd_last.ul++;
32963 + vdir_cache->vd_last.p.deblk
32964 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
32965 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
32974 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
32975 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
32976 +++ linux/fs/aufs/vfsub.c 2023-08-28 12:34:39.999969465 +0200
32978 +// SPDX-License-Identifier: GPL-2.0
32980 + * Copyright (C) 2005-2022 Junjiro R. Okajima
32982 + * This program is free software; you can redistribute it and/or modify
32983 + * it under the terms of the GNU General Public License as published by
32984 + * the Free Software Foundation; either version 2 of the License, or
32985 + * (at your option) any later version.
32987 + * This program is distributed in the hope that it will be useful,
32988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32990 + * GNU General Public License for more details.
32992 + * You should have received a copy of the GNU General Public License
32993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32997 + * sub-routines for VFS
33000 +#include <linux/mnt_namespace.h>
33001 +#include <linux/nsproxy.h>
33002 +#include <linux/security.h>
33003 +#include <linux/splice.h>
33006 +#ifdef CONFIG_AUFS_BR_FUSE
33007 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
33009 + if (!au_test_fuse(h_sb) || !au_userns)
33012 + return is_current_mnt_ns(mnt) ? 0 : -EACCES;
33016 +int vfsub_sync_filesystem(struct super_block *h_sb)
33021 + down_read(&h_sb->s_umount);
33022 + err = sync_filesystem(h_sb);
33023 + up_read(&h_sb->s_umount);
33029 +/* ---------------------------------------------------------------------- */
33031 +int vfsub_update_h_iattr(struct path *h_path, int *did)
33035 + struct super_block *h_sb;
33038 + * Always needs h_path->mnt for LSM or FUSE branch.
33040 + AuDebugOn(!h_path->mnt);
33042 + /* for remote fs, leave work for its getattr or d_revalidate */
33043 + /* for bad i_attr fs, handle them in aufs_getattr() */
33044 + /* still some fs may acquire i_mutex. we need to skip them */
33048 + h_sb = h_path->dentry->d_sb;
33049 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
33051 + err = vfsub_getattr(h_path, &st);
33056 +/* ---------------------------------------------------------------------- */
33058 +struct file *vfsub_dentry_open(struct path *path, int flags)
33060 + return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
33064 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
33066 + struct file *file;
33069 + file = filp_open(path,
33070 + oflags /* | __FMODE_NONOTIFY */,
33073 + if (IS_ERR(file))
33075 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33082 + * Ideally this function should call VFS:do_last() in order to keep all its
33083 + * checkings. But it is very hard for aufs to regenerate several VFS internal
33084 + * structure such as nameidata. This is a second (or third) best approach.
33085 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
33087 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
33088 + struct vfsub_aopen_args *args)
33091 + struct au_branch *br = args->br;
33092 + struct file *file = args->file;
33093 + /* copied from linux/fs/namei.c:atomic_open() */
33094 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
33097 + AuDebugOn(!dir->i_op->atomic_open);
33099 + err = au_br_test_oflag(args->open_flag, br);
33100 + if (unlikely(err))
33103 + au_lcnt_inc(&br->br_nfiles);
33104 + file->f_path.dentry = DENTRY_NOT_SET;
33105 + file->f_path.mnt = au_br_mnt(br);
33106 + AuDbg("%ps\n", dir->i_op->atomic_open);
33107 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
33108 + args->create_mode);
33109 + if (unlikely(err < 0)) {
33110 + au_lcnt_dec(&br->br_nfiles);
33114 + /* temporary workaround for nfsv4 branch */
33115 + if (au_test_nfs(dir->i_sb))
33116 + nfs_mark_for_revalidate(dir);
33118 + if (file->f_mode & FMODE_CREATED)
33119 + fsnotify_create(dir, dentry);
33120 + if (!(file->f_mode & FMODE_OPENED)) {
33121 + au_lcnt_dec(&br->br_nfiles);
33125 + /* todo: call VFS:may_open() here */
33126 + /* todo: ima_file_check() too? */
33127 + if (!err && (args->open_flag & __FMODE_EXEC))
33128 + err = deny_write_access(file);
33130 + fsnotify_open(file);
33132 + au_lcnt_dec(&br->br_nfiles);
33133 + /* note that the file is created and still opened */
33139 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
33143 + err = kern_path(name, flags, path);
33144 + if (!err && d_is_positive(path->dentry))
33145 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33149 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
33150 + struct path *ppath, int len)
33152 + struct path path;
33154 + path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
33155 + if (IS_ERR(path.dentry))
33157 + if (d_is_positive(path.dentry)) {
33158 + path.mnt = ppath->mnt;
33159 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33163 + AuTraceErrPtr(path.dentry);
33164 + return path.dentry;
33167 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
33170 + struct path path;
33172 + /* VFS checks it too, but by WARN_ON_ONCE() */
33173 + IMustLock(d_inode(ppath->dentry));
33175 + path.dentry = lookup_one_len(name, ppath->dentry, len);
33176 + if (IS_ERR(path.dentry))
33178 + if (d_is_positive(path.dentry)) {
33179 + path.mnt = ppath->mnt;
33180 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
33184 + AuTraceErrPtr(path.dentry);
33185 + return path.dentry;
33188 +void vfsub_call_lkup_one(void *args)
33190 + struct vfsub_lkup_one_args *a = args;
33191 + *a->errp = vfsub_lkup_one(a->name, a->ppath);
33194 +/* ---------------------------------------------------------------------- */
33196 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
33197 + struct dentry *d2, struct au_hinode *hdir2)
33199 + struct dentry *d;
33202 + d = lock_rename(d1, d2);
33204 + au_hn_suspend(hdir1);
33205 + if (hdir1 != hdir2)
33206 + au_hn_suspend(hdir2);
33211 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
33212 + struct dentry *d2, struct au_hinode *hdir2)
33214 + au_hn_resume(hdir1);
33215 + if (hdir1 != hdir2)
33216 + au_hn_resume(hdir2);
33218 + unlock_rename(d1, d2);
33222 +/* ---------------------------------------------------------------------- */
33224 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
33227 + struct dentry *d;
33228 + struct mnt_idmap *idmap;
33232 + d = path->dentry;
33233 + path->dentry = d->d_parent;
33234 + err = security_path_mknod(path, d, mode, 0);
33235 + path->dentry = d;
33236 + if (unlikely(err))
33238 + idmap = mnt_idmap(path->mnt);
33241 + err = vfs_create(idmap, dir, path->dentry, mode, want_excl);
33244 + struct path tmp = *path;
33247 + vfsub_update_h_iattr(&tmp, &did);
33249 + tmp.dentry = path->dentry->d_parent;
33250 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33259 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
33262 + struct dentry *d;
33263 + struct mnt_idmap *idmap;
33267 + d = path->dentry;
33268 + path->dentry = d->d_parent;
33269 + err = security_path_symlink(path, d, symname);
33270 + path->dentry = d;
33271 + if (unlikely(err))
33273 + idmap = mnt_idmap(path->mnt);
33276 + err = vfs_symlink(idmap, dir, path->dentry, symname);
33279 + struct path tmp = *path;
33282 + vfsub_update_h_iattr(&tmp, &did);
33284 + tmp.dentry = path->dentry->d_parent;
33285 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33294 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
33297 + struct dentry *d;
33298 + struct mnt_idmap *idmap;
33302 + d = path->dentry;
33303 + path->dentry = d->d_parent;
33304 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
33305 + path->dentry = d;
33306 + if (unlikely(err))
33308 + idmap = mnt_idmap(path->mnt);
33311 + err = vfs_mknod(idmap, dir, path->dentry, mode, dev);
33314 + struct path tmp = *path;
33317 + vfsub_update_h_iattr(&tmp, &did);
33319 + tmp.dentry = path->dentry->d_parent;
33320 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33329 +static int au_test_nlink(struct inode *inode)
33331 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
33333 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
33334 + || inode->i_nlink < link_max)
33339 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
33340 + struct inode **delegated_inode)
33343 + struct dentry *d;
33344 + struct mnt_idmap *idmap;
33348 + err = au_test_nlink(d_inode(src_dentry));
33349 + if (unlikely(err))
33352 + /* we don't call may_linkat() */
33353 + d = path->dentry;
33354 + path->dentry = d->d_parent;
33355 + err = security_path_link(src_dentry, path, d);
33356 + path->dentry = d;
33357 + if (unlikely(err))
33359 + idmap = mnt_idmap(path->mnt);
33362 + err = vfs_link(src_dentry, idmap, dir, path->dentry, delegated_inode);
33365 + struct path tmp = *path;
33368 + /* fuse has different memory inode for the same inumber */
33369 + vfsub_update_h_iattr(&tmp, &did);
33371 + tmp.dentry = path->dentry->d_parent;
33372 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33373 + tmp.dentry = src_dentry;
33374 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33383 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
33384 + struct inode *dir, struct path *path,
33385 + struct inode **delegated_inode, unsigned int flags)
33388 + struct renamedata rd;
33389 + struct path tmp = {
33392 + struct dentry *d;
33395 + IMustLock(src_dir);
33397 + d = path->dentry;
33398 + path->dentry = d->d_parent;
33399 + tmp.dentry = src_dentry->d_parent;
33400 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
33401 + path->dentry = d;
33402 + if (unlikely(err))
33405 + rd.old_mnt_idmap = mnt_idmap(path->mnt);
33406 + rd.old_dir = src_dir;
33407 + rd.old_dentry = src_dentry;
33408 + rd.new_mnt_idmap = rd.old_mnt_idmap;
33409 + rd.new_dir = dir;
33410 + rd.new_dentry = path->dentry;
33411 + rd.delegated_inode = delegated_inode;
33412 + rd.flags = flags;
33414 + err = vfs_rename(&rd);
33419 + tmp.dentry = d->d_parent;
33420 + vfsub_update_h_iattr(&tmp, &did);
33422 + tmp.dentry = src_dentry;
33423 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33424 + tmp.dentry = src_dentry->d_parent;
33425 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33434 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
33437 + struct dentry *d;
33438 + struct mnt_idmap *idmap;
33442 + d = path->dentry;
33443 + path->dentry = d->d_parent;
33444 + err = security_path_mkdir(path, d, mode);
33445 + path->dentry = d;
33446 + if (unlikely(err))
33448 + idmap = mnt_idmap(path->mnt);
33451 + err = vfs_mkdir(idmap, dir, path->dentry, mode);
33454 + struct path tmp = *path;
33457 + vfsub_update_h_iattr(&tmp, &did);
33459 + tmp.dentry = path->dentry->d_parent;
33460 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
33469 +int vfsub_rmdir(struct inode *dir, struct path *path)
33472 + struct dentry *d;
33473 + struct mnt_idmap *idmap;
33477 + d = path->dentry;
33478 + path->dentry = d->d_parent;
33479 + err = security_path_rmdir(path, d);
33480 + path->dentry = d;
33481 + if (unlikely(err))
33483 + idmap = mnt_idmap(path->mnt);
33486 + err = vfs_rmdir(idmap, dir, path->dentry);
33489 + struct path tmp = {
33490 + .dentry = path->dentry->d_parent,
33494 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33501 +/* ---------------------------------------------------------------------- */
33503 +/* todo: support mmap_sem? */
33504 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
33510 + err = vfs_read(file, ubuf, count, ppos);
33513 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33517 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
33523 + err = kernel_read(file, kbuf, count, ppos);
33527 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33531 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
33537 + err = vfs_write(file, ubuf, count, ppos);
33540 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33544 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
33549 + err = kernel_write(file, kbuf, count, ppos);
33552 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33556 +int vfsub_flush(struct file *file, fl_owner_t id)
33561 + if (file->f_op->flush) {
33562 + if (!au_test_nfs(file->f_path.dentry->d_sb))
33563 + err = file->f_op->flush(file, id);
33566 + err = file->f_op->flush(file, id);
33570 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
33576 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
33580 + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
33583 + err = iterate_dir(file, ctx);
33586 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
33591 +long vfsub_splice_to(struct file *in, loff_t *ppos,
33592 + struct pipe_inode_info *pipe, size_t len,
33593 + unsigned int flags)
33598 + err = do_splice_to(in, ppos, pipe, len, flags);
33600 + file_accessed(in);
33602 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
33606 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
33607 + loff_t *ppos, size_t len, unsigned int flags)
33612 + err = do_splice_from(pipe, out, ppos, len, flags);
33615 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
33619 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
33623 + /* file can be NULL */
33625 + err = vfs_fsync(file, datasync);
33629 + AuDebugOn(!file);
33630 + path = &file->f_path;
33632 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
33637 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
33638 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
33639 + struct file *h_file)
33642 + struct inode *h_inode;
33643 + struct super_block *h_sb;
33644 + struct mnt_idmap *h_idmap;
33647 + err = vfsub_truncate(h_path, length);
33651 + h_inode = d_inode(h_path->dentry);
33652 + h_sb = h_inode->i_sb;
33654 + sb_start_write(h_sb);
33656 + err = security_file_truncate(h_file);
33658 + h_idmap = mnt_idmap(h_path->mnt);
33660 + err = do_truncate(h_idmap, h_path->dentry, length, attr,
33665 + sb_end_write(h_sb);
33672 +/* ---------------------------------------------------------------------- */
33674 +struct au_vfsub_mkdir_args {
33676 + struct inode *dir;
33677 + struct path *path;
33681 +static void au_call_vfsub_mkdir(void *args)
33683 + struct au_vfsub_mkdir_args *a = args;
33684 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
33687 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
33689 + int err, do_sio, wkq_err;
33690 + struct mnt_idmap *idmap;
33692 + idmap = mnt_idmap(path->mnt);
33693 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33696 + err = vfsub_mkdir(dir, path, mode);
33699 + struct au_vfsub_mkdir_args args = {
33705 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
33706 + if (unlikely(wkq_err))
33713 +struct au_vfsub_rmdir_args {
33715 + struct inode *dir;
33716 + struct path *path;
33719 +static void au_call_vfsub_rmdir(void *args)
33721 + struct au_vfsub_rmdir_args *a = args;
33722 + *a->errp = vfsub_rmdir(a->dir, a->path);
33725 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
33727 + int err, do_sio, wkq_err;
33728 + struct mnt_idmap *idmap;
33730 + idmap = mnt_idmap(path->mnt);
33731 + do_sio = au_test_h_perm_sio(idmap, dir, MAY_EXEC | MAY_WRITE);
33734 + err = vfsub_rmdir(dir, path);
33737 + struct au_vfsub_rmdir_args args = {
33742 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
33743 + if (unlikely(wkq_err))
33750 +/* ---------------------------------------------------------------------- */
33752 +struct notify_change_args {
33754 + struct path *path;
33755 + struct iattr *ia;
33756 + struct inode **delegated_inode;
33759 +static void call_notify_change(void *args)
33761 + struct notify_change_args *a = args;
33762 + struct inode *h_inode;
33763 + struct mnt_idmap *idmap;
33765 + h_inode = d_inode(a->path->dentry);
33766 + IMustLock(h_inode);
33768 + *a->errp = -EPERM;
33769 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
33770 + idmap = mnt_idmap(a->path->mnt);
33772 + *a->errp = notify_change(idmap, a->path->dentry, a->ia,
33773 + a->delegated_inode);
33776 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
33778 + AuTraceErr(*a->errp);
33781 +int vfsub_notify_change(struct path *path, struct iattr *ia,
33782 + struct inode **delegated_inode)
33785 + struct notify_change_args args = {
33789 + .delegated_inode = delegated_inode
33792 + call_notify_change(&args);
33797 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
33798 + struct inode **delegated_inode)
33800 + int err, wkq_err;
33801 + struct notify_change_args args = {
33805 + .delegated_inode = delegated_inode
33808 + wkq_err = au_wkq_wait(call_notify_change, &args);
33809 + if (unlikely(wkq_err))
33815 +/* ---------------------------------------------------------------------- */
33817 +struct unlink_args {
33819 + struct inode *dir;
33820 + struct path *path;
33821 + struct inode **delegated_inode;
33824 +static void call_unlink(void *args)
33826 + struct unlink_args *a = args;
33827 + struct dentry *d = a->path->dentry;
33828 + struct inode *h_inode;
33829 + struct mnt_idmap *idmap;
33830 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
33831 + && au_dcount(d) == 1);
33833 + IMustLock(a->dir);
33835 + a->path->dentry = d->d_parent;
33836 + *a->errp = security_path_unlink(a->path, d);
33837 + a->path->dentry = d;
33838 + if (unlikely(*a->errp))
33841 + if (!stop_sillyrename)
33844 + if (d_is_positive(d)) {
33845 + h_inode = d_inode(d);
33849 + idmap = mnt_idmap(a->path->mnt);
33851 + *a->errp = vfs_unlink(idmap, a->dir, d, a->delegated_inode);
33854 + struct path tmp = {
33855 + .dentry = d->d_parent,
33856 + .mnt = a->path->mnt
33858 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
33861 + if (!stop_sillyrename)
33866 + AuTraceErr(*a->errp);
33870 + * @dir: must be locked.
33871 + * @dentry: target dentry.
33873 +int vfsub_unlink(struct inode *dir, struct path *path,
33874 + struct inode **delegated_inode, int force)
33877 + struct unlink_args args = {
33881 + .delegated_inode = delegated_inode
33885 + call_unlink(&args);
33889 + wkq_err = au_wkq_wait(call_unlink, &args);
33890 + if (unlikely(wkq_err))
33896 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
33897 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
33898 +++ linux/fs/aufs/vfsub.h 2023-08-28 12:34:39.999969465 +0200
33900 +/* SPDX-License-Identifier: GPL-2.0 */
33902 + * Copyright (C) 2005-2022 Junjiro R. Okajima
33904 + * This program is free software; you can redistribute it and/or modify
33905 + * it under the terms of the GNU General Public License as published by
33906 + * the Free Software Foundation; either version 2 of the License, or
33907 + * (at your option) any later version.
33909 + * This program is distributed in the hope that it will be useful,
33910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33912 + * GNU General Public License for more details.
33914 + * You should have received a copy of the GNU General Public License
33915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33919 + * sub-routines for VFS
33922 +#ifndef __AUFS_VFSUB_H__
33923 +#define __AUFS_VFSUB_H__
33927 +#include <linux/fs.h>
33928 +#include <linux/mount.h>
33929 +#include <linux/posix_acl.h>
33930 +#include <linux/xattr.h>
33931 +#include "debug.h"
33933 +/* copied from linux/fs/internal.h */
33934 +/* todo: BAD approach!! */
33935 +extern void __mnt_drop_write(struct vfsmount *);
33936 +extern struct file *alloc_empty_file(int, const struct cred *);
33938 +/* ---------------------------------------------------------------------- */
33940 +/* lock subclass for lower inode */
33941 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
33942 +/* reduce? gave up. */
33944 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
33945 + AuLsc_I_PARENT, /* lower inode, parent first */
33946 + AuLsc_I_PARENT2, /* copyup dirs */
33947 + AuLsc_I_PARENT3, /* copyup wh */
33953 +/* to debug easier, do not make them inlined functions */
33954 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
33955 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
33957 +/* ---------------------------------------------------------------------- */
33959 +static inline void vfsub_drop_nlink(struct inode *inode)
33961 + AuDebugOn(!inode->i_nlink);
33962 + drop_nlink(inode);
33965 +static inline void vfsub_dead_dir(struct inode *inode)
33967 + AuDebugOn(!S_ISDIR(inode->i_mode));
33968 + inode->i_flags |= S_DEAD;
33969 + clear_nlink(inode);
33972 +static inline int vfsub_native_ro(struct inode *inode)
33974 + return sb_rdonly(inode->i_sb)
33975 + || IS_RDONLY(inode)
33976 + /* || IS_APPEND(inode) */
33977 + || IS_IMMUTABLE(inode);
33980 +#ifdef CONFIG_AUFS_BR_FUSE
33981 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
33983 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
33986 +int vfsub_sync_filesystem(struct super_block *h_sb);
33988 +/* ---------------------------------------------------------------------- */
33990 +int vfsub_update_h_iattr(struct path *h_path, int *did);
33991 +struct file *vfsub_dentry_open(struct path *path, int flags);
33992 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
33994 +struct vfsub_aopen_args {
33995 + struct file *file;
33996 + unsigned int open_flag;
33997 + umode_t create_mode;
33998 + struct au_branch *br;
34000 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
34001 + struct vfsub_aopen_args *args);
34002 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
34004 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
34005 + struct path *ppath, int len);
34006 +struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
34009 +struct vfsub_lkup_one_args {
34010 + struct dentry **errp;
34011 + struct qstr *name;
34012 + struct path *ppath;
34015 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
34016 + struct path *ppath)
34018 + return vfsub_lookup_one_len(name->name, ppath, name->len);
34021 +void vfsub_call_lkup_one(void *args);
34023 +/* ---------------------------------------------------------------------- */
34025 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
34030 + err = mnt_want_write(mnt);
34035 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
34038 + mnt_drop_write(mnt);
34042 +#if 0 /* reserved */
34043 +static inline void vfsub_mnt_drop_write_file(struct file *file)
34046 + mnt_drop_write_file(file);
34051 +/* ---------------------------------------------------------------------- */
34054 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
34055 + struct dentry *d2, struct au_hinode *hdir2);
34056 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
34057 + struct dentry *d2, struct au_hinode *hdir2);
34059 +int vfsub_create(struct inode *dir, struct path *path, int mode,
34061 +int vfsub_symlink(struct inode *dir, struct path *path,
34062 + const char *symname);
34063 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
34064 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
34065 + struct path *path, struct inode **delegated_inode);
34066 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
34067 + struct inode *hdir, struct path *path,
34068 + struct inode **delegated_inode, unsigned int flags);
34069 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
34070 +int vfsub_rmdir(struct inode *dir, struct path *path);
34072 +/* ---------------------------------------------------------------------- */
34074 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
34076 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
34078 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
34080 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
34082 +int vfsub_flush(struct file *file, fl_owner_t id);
34083 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
34085 +static inline loff_t vfsub_f_size_read(struct file *file)
34087 + return i_size_read(file_inode(file));
34090 +static inline unsigned int vfsub_file_flags(struct file *file)
34092 + unsigned int flags;
34094 + spin_lock(&file->f_lock);
34095 + flags = file->f_flags;
34096 + spin_unlock(&file->f_lock);
34101 +static inline int vfsub_file_execed(struct file *file)
34103 + /* todo: direct access f_flags */
34104 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
34107 +#if 0 /* reserved */
34108 +static inline void vfsub_file_accessed(struct file *h_file)
34110 + file_accessed(h_file);
34111 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
34115 +#if 0 /* reserved */
34116 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
34117 + struct dentry *h_dentry)
34119 + struct path h_path = {
34120 + .dentry = h_dentry,
34123 + touch_atime(&h_path);
34124 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
34128 +static inline int vfsub_update_time(struct inode *h_inode,
34129 + struct timespec64 *ts, int flags)
34131 + return inode_update_time(h_inode, ts, flags);
34132 + /* no vfsub_update_h_iattr() since we don't have struct path */
34135 +#ifdef CONFIG_FS_POSIX_ACL
34136 +static inline int vfsub_acl_chmod(struct mnt_idmap *h_idmap,
34137 + struct dentry *h_dentry, umode_t h_mode)
34141 + err = posix_acl_chmod(h_idmap, h_dentry, h_mode);
34142 + if (err == -EOPNOTSUPP)
34147 +AuStubInt0(vfsub_acl_chmod, struct mnt_idmap *h_idmap,
34148 + struct dentry *h_dentry, umode_t h_mode);
34151 +long vfsub_splice_to(struct file *in, loff_t *ppos,
34152 + struct pipe_inode_info *pipe, size_t len,
34153 + unsigned int flags);
34154 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
34155 + loff_t *ppos, size_t len, unsigned int flags);
34157 +static inline long vfsub_truncate(struct path *path, loff_t length)
34162 + err = vfs_truncate(path, length);
34167 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
34168 + struct file *h_file);
34169 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
34172 + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
34175 +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
34181 + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
34187 +/* copy_file_range(2) is a systemcall */
34188 +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
34189 + struct file *dst, loff_t dst_pos,
34190 + size_t len, unsigned int flags)
34195 + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
34201 +/* ---------------------------------------------------------------------- */
34203 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
34208 + err = vfs_llseek(file, offset, origin);
34213 +/* ---------------------------------------------------------------------- */
34215 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
34216 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
34217 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
34218 + struct inode **delegated_inode);
34219 +int vfsub_notify_change(struct path *path, struct iattr *ia,
34220 + struct inode **delegated_inode);
34221 +int vfsub_unlink(struct inode *dir, struct path *path,
34222 + struct inode **delegated_inode, int force);
34224 +static inline int vfsub_getattr(const struct path *path, struct kstat *st)
34226 + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
34229 +/* ---------------------------------------------------------------------- */
34231 +static inline int vfsub_setxattr(struct mnt_idmap *idmap,
34232 + struct dentry *dentry, const char *name,
34233 + const void *value, size_t size, int flags)
34238 + err = vfs_setxattr(idmap, dentry, name, value, size, flags);
34244 +static inline int vfsub_removexattr(struct mnt_idmap *idmap,
34245 + struct dentry *dentry, const char *name)
34250 + err = vfs_removexattr(idmap, dentry, name);
34256 +#ifdef CONFIG_FS_POSIX_ACL
34257 +static inline int vfsub_set_acl(struct mnt_idmap *idmap,
34258 + struct dentry *dentry, const char *name,
34259 + struct posix_acl *acl)
34264 + err = vfs_set_acl(idmap, dentry, name, acl);
34270 +static inline int vfsub_remove_acl(struct mnt_idmap *idmap,
34271 + struct dentry *dentry, const char *name)
34276 + err = vfs_remove_acl(idmap, dentry, name);
34282 +AuStubInt0(vfsub_set_acl, struct mnt_idmap *idmap, struct dentry *dentry,
34283 + const char *name, struct posix_acl *acl);
34284 +AuStubInt0(vfsub_remove_acl, struct mnt_idmap *idmap,
34285 + struct dentry *dentry, const char *name);
34288 +#endif /* __KERNEL__ */
34289 +#endif /* __AUFS_VFSUB_H__ */
34290 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
34291 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
34292 +++ linux/fs/aufs/wbr_policy.c 2022-11-05 23:02:18.969222617 +0100
34294 +// SPDX-License-Identifier: GPL-2.0
34296 + * Copyright (C) 2005-2022 Junjiro R. Okajima
34298 + * This program is free software; you can redistribute it and/or modify
34299 + * it under the terms of the GNU General Public License as published by
34300 + * the Free Software Foundation; either version 2 of the License, or
34301 + * (at your option) any later version.
34303 + * This program is distributed in the hope that it will be useful,
34304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34306 + * GNU General Public License for more details.
34308 + * You should have received a copy of the GNU General Public License
34309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34313 + * policies for selecting one among multiple writable branches
34316 +#include <linux/statfs.h>
34319 +/* subset of cpup_attr() */
34320 +static noinline_for_stack
34321 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
34325 + struct inode *h_isrc;
34327 + h_isrc = d_inode(h_src);
34328 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
34329 + ia.ia_mode = h_isrc->i_mode;
34330 + ia.ia_uid = h_isrc->i_uid;
34331 + ia.ia_gid = h_isrc->i_gid;
34332 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
34333 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
34334 + /* no delegation since it is just created */
34335 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34337 + /* is this nfs only? */
34338 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
34339 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
34340 + ia.ia_mode = h_isrc->i_mode;
34341 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
34347 +#define AuCpdown_PARENT_OPQ 1
34348 +#define AuCpdown_WHED (1 << 1)
34349 +#define AuCpdown_MADE_DIR (1 << 2)
34350 +#define AuCpdown_DIROPQ (1 << 3)
34351 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
34352 +#define au_fset_cpdown(flags, name) \
34353 + do { (flags) |= AuCpdown_##name; } while (0)
34354 +#define au_fclr_cpdown(flags, name) \
34355 + do { (flags) &= ~AuCpdown_##name; } while (0)
34357 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
34358 + unsigned int *flags)
34361 + struct dentry *opq_dentry;
34363 + opq_dentry = au_diropq_create(dentry, bdst);
34364 + err = PTR_ERR(opq_dentry);
34365 + if (IS_ERR(opq_dentry))
34367 + dput(opq_dentry);
34368 + au_fset_cpdown(*flags, DIROPQ);
34374 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
34375 + struct inode *dir, aufs_bindex_t bdst)
34378 + struct path h_path;
34379 + struct au_branch *br;
34381 + br = au_sbr(dentry->d_sb, bdst);
34382 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
34383 + err = PTR_ERR(h_path.dentry);
34384 + if (IS_ERR(h_path.dentry))
34388 + if (d_is_positive(h_path.dentry)) {
34389 + h_path.mnt = au_br_mnt(br);
34390 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
34393 + dput(h_path.dentry);
34399 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
34400 + struct au_pin *pin,
34401 + struct dentry *h_parent, void *arg)
34404 + aufs_bindex_t bopq, btop;
34405 + struct path h_path;
34406 + struct dentry *parent;
34407 + struct inode *h_dir, *h_inode, *inode, *dir;
34408 + unsigned int *flags = arg;
34410 + btop = au_dbtop(dentry);
34411 + /* dentry is di-locked */
34412 + parent = dget_parent(dentry);
34413 + dir = d_inode(parent);
34414 + h_dir = d_inode(h_parent);
34415 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
34416 + IMustLock(h_dir);
34418 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
34419 + if (unlikely(err < 0))
34421 + h_path.dentry = au_h_dptr(dentry, bdst);
34422 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
34423 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755);
34424 + if (unlikely(err))
34426 + au_fset_cpdown(*flags, MADE_DIR);
34428 + bopq = au_dbdiropq(dentry);
34429 + au_fclr_cpdown(*flags, WHED);
34430 + au_fclr_cpdown(*flags, DIROPQ);
34431 + if (au_dbwh(dentry) == bdst)
34432 + au_fset_cpdown(*flags, WHED);
34433 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
34434 + au_fset_cpdown(*flags, PARENT_OPQ);
34435 + h_inode = d_inode(h_path.dentry);
34436 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34437 + if (au_ftest_cpdown(*flags, WHED)) {
34438 + err = au_cpdown_dir_opq(dentry, bdst, flags);
34439 + if (unlikely(err)) {
34440 + inode_unlock(h_inode);
34445 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
34446 + inode_unlock(h_inode);
34447 + if (unlikely(err))
34450 + if (au_ftest_cpdown(*flags, WHED)) {
34451 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
34452 + if (unlikely(err))
34456 + inode = d_inode(dentry);
34457 + if (au_ibbot(inode) < bdst)
34458 + au_set_ibbot(inode, bdst);
34459 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
34460 + au_hi_flags(inode, /*isdir*/1));
34461 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
34462 + goto out; /* success */
34466 + if (au_ftest_cpdown(*flags, DIROPQ)) {
34467 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
34468 + rerr = au_diropq_remove(dentry, bdst);
34469 + inode_unlock(h_inode);
34470 + if (unlikely(rerr)) {
34471 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
34472 + dentry, bdst, rerr);
34478 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
34479 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
34480 + if (unlikely(rerr)) {
34481 + AuIOErr("failed removing %pd b%d (%d)\n",
34482 + dentry, bdst, rerr);
34487 + au_set_h_dptr(dentry, bdst, NULL);
34488 + if (au_dbbot(dentry) == bdst)
34489 + au_update_dbbot(dentry);
34495 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
34498 + unsigned int flags;
34501 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
34506 +/* ---------------------------------------------------------------------- */
34508 +/* policies for create */
34510 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
34512 + int err, i, j, ndentry;
34513 + aufs_bindex_t bopq;
34514 + struct au_dcsub_pages dpages;
34515 + struct au_dpage *dpage;
34516 + struct dentry **dentries, *parent, *d;
34518 + err = au_dpages_init(&dpages, GFP_NOFS);
34519 + if (unlikely(err))
34521 + parent = dget_parent(dentry);
34522 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
34523 + if (unlikely(err))
34527 + for (i = 0; i < dpages.ndpage; i++) {
34528 + dpage = dpages.dpages + i;
34529 + dentries = dpage->dentries;
34530 + ndentry = dpage->ndentry;
34531 + for (j = 0; j < ndentry; j++) {
34533 + di_read_lock_parent2(d, !AuLock_IR);
34534 + bopq = au_dbdiropq(d);
34535 + di_read_unlock(d, !AuLock_IR);
34536 + if (bopq >= 0 && bopq < err)
34543 + au_dpages_free(&dpages);
34548 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
34550 + for (; bindex >= 0; bindex--)
34551 + if (!au_br_rdonly(au_sbr(sb, bindex)))
34556 +/* top down parent */
34557 +static int au_wbr_create_tdp(struct dentry *dentry,
34558 + unsigned int flags __maybe_unused)
34561 + aufs_bindex_t btop, bindex;
34562 + struct super_block *sb;
34563 + struct dentry *parent, *h_parent;
34565 + sb = dentry->d_sb;
34566 + btop = au_dbtop(dentry);
34568 + if (!au_br_rdonly(au_sbr(sb, btop)))
34572 + parent = dget_parent(dentry);
34573 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
34574 + h_parent = au_h_dptr(parent, bindex);
34575 + if (!h_parent || d_is_negative(h_parent))
34578 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
34585 + /* bottom up here */
34586 + if (unlikely(err < 0)) {
34587 + err = au_wbr_bu(sb, btop - 1);
34589 + err = au_wbr_nonopq(dentry, err);
34593 + AuDbg("b%d\n", err);
34597 +/* ---------------------------------------------------------------------- */
34599 +/* an exception for the policy other than tdp */
34600 +static int au_wbr_create_exp(struct dentry *dentry)
34603 + aufs_bindex_t bwh, bdiropq;
34604 + struct dentry *parent;
34607 + bwh = au_dbwh(dentry);
34608 + parent = dget_parent(dentry);
34609 + bdiropq = au_dbdiropq(parent);
34611 + if (bdiropq >= 0)
34612 + err = min(bdiropq, bwh);
34615 + AuDbg("%d\n", err);
34616 + } else if (bdiropq >= 0) {
34618 + AuDbg("%d\n", err);
34623 + err = au_wbr_nonopq(dentry, err);
34625 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
34628 + AuDbg("%d\n", err);
34632 +/* ---------------------------------------------------------------------- */
34635 +static int au_wbr_create_init_rr(struct super_block *sb)
34639 + err = au_wbr_bu(sb, au_sbbot(sb));
34640 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
34643 + AuDbg("b%d\n", err);
34647 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
34651 + aufs_bindex_t bindex, bbot;
34652 + struct super_block *sb;
34655 + err = au_wbr_create_exp(dentry);
34659 + sb = dentry->d_sb;
34660 + next = &au_sbi(sb)->si_wbr_rr_next;
34661 + bbot = au_sbbot(sb);
34663 + for (bindex = 0; bindex <= bbot; bindex++) {
34664 + if (!au_ftest_wbr(flags, DIR)) {
34665 + err = atomic_dec_return(next) + 1;
34666 + /* modulo for 0 is meaningless */
34667 + if (unlikely(!err))
34668 + err = atomic_dec_return(next) + 1;
34670 + err = atomic_read(next);
34671 + AuDbg("%d\n", err);
34674 + AuDbg("%d\n", err);
34675 + if (!au_br_rdonly(au_sbr(sb, err)))
34681 + err = au_wbr_nonopq(dentry, err);
34684 + AuDbg("%d\n", err);
34688 +/* ---------------------------------------------------------------------- */
34690 +/* most free space */
34691 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
34693 + struct super_block *sb;
34694 + struct au_branch *br;
34695 + struct au_wbr_mfs *mfs;
34696 + struct dentry *h_parent;
34697 + aufs_bindex_t bindex, bbot;
34699 + unsigned long long b, bavail;
34700 + struct path h_path;
34701 + /* reduce the stack usage */
34702 + struct kstatfs *st;
34704 + st = kmalloc(sizeof(*st), GFP_NOFS);
34705 + if (unlikely(!st)) {
34706 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
34711 + sb = dentry->d_sb;
34712 + mfs = &au_sbi(sb)->si_wbr_mfs;
34713 + MtxMustLock(&mfs->mfs_lock);
34714 + mfs->mfs_bindex = -EROFS;
34715 + mfs->mfsrr_bytes = 0;
34718 + bbot = au_sbbot(sb);
34720 + bindex = au_dbtop(parent);
34721 + bbot = au_dbtaildir(parent);
34724 + for (; bindex <= bbot; bindex++) {
34726 + h_parent = au_h_dptr(parent, bindex);
34727 + if (!h_parent || d_is_negative(h_parent))
34730 + br = au_sbr(sb, bindex);
34731 + if (au_br_rdonly(br))
34734 + /* sb->s_root for NFS is unreliable */
34735 + h_path.mnt = au_br_mnt(br);
34736 + h_path.dentry = h_path.mnt->mnt_root;
34737 + err = vfs_statfs(&h_path, st);
34738 + if (unlikely(err)) {
34739 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
34743 + /* when the available size is equal, select the lower one */
34744 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
34745 + || sizeof(b) < sizeof(st->f_bsize));
34746 + b = st->f_bavail * st->f_bsize;
34747 + br->br_wbr->wbr_bytes = b;
34748 + if (b >= bavail) {
34750 + mfs->mfs_bindex = bindex;
34751 + mfs->mfs_jiffy = jiffies;
34755 + mfs->mfsrr_bytes = bavail;
34756 + AuDbg("b%d\n", mfs->mfs_bindex);
34757 + au_kfree_rcu(st);
34760 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
34763 + struct dentry *parent;
34764 + struct super_block *sb;
34765 + struct au_wbr_mfs *mfs;
34767 + err = au_wbr_create_exp(dentry);
34771 + sb = dentry->d_sb;
34773 + if (au_ftest_wbr(flags, PARENT))
34774 + parent = dget_parent(dentry);
34775 + mfs = &au_sbi(sb)->si_wbr_mfs;
34776 + mutex_lock(&mfs->mfs_lock);
34777 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34778 + || mfs->mfs_bindex < 0
34779 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
34780 + au_mfs(dentry, parent);
34781 + mutex_unlock(&mfs->mfs_lock);
34782 + err = mfs->mfs_bindex;
34786 + err = au_wbr_nonopq(dentry, err);
34789 + AuDbg("b%d\n", err);
34793 +static int au_wbr_create_init_mfs(struct super_block *sb)
34795 + struct au_wbr_mfs *mfs;
34797 + mfs = &au_sbi(sb)->si_wbr_mfs;
34798 + mutex_init(&mfs->mfs_lock);
34799 + mfs->mfs_jiffy = 0;
34800 + mfs->mfs_bindex = -EROFS;
34805 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
34807 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
34811 +/* ---------------------------------------------------------------------- */
34813 +/* top down regardless parent, and then mfs */
34814 +static int au_wbr_create_tdmfs(struct dentry *dentry,
34815 + unsigned int flags __maybe_unused)
34818 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
34819 + unsigned long long watermark;
34820 + struct super_block *sb;
34821 + struct au_wbr_mfs *mfs;
34822 + struct au_branch *br;
34823 + struct dentry *parent;
34825 + sb = dentry->d_sb;
34826 + mfs = &au_sbi(sb)->si_wbr_mfs;
34827 + mutex_lock(&mfs->mfs_lock);
34828 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
34829 + || mfs->mfs_bindex < 0)
34830 + au_mfs(dentry, /*parent*/NULL);
34831 + watermark = mfs->mfsrr_watermark;
34832 + bmfs = mfs->mfs_bindex;
34833 + mutex_unlock(&mfs->mfs_lock);
34835 + /* another style of au_wbr_create_exp() */
34836 + bwh = au_dbwh(dentry);
34837 + parent = dget_parent(dentry);
34838 + btail = au_dbtaildir(parent);
34839 + if (bwh >= 0 && bwh < btail)
34842 + err = au_wbr_nonopq(dentry, btail);
34843 + if (unlikely(err < 0))
34847 + for (bindex = 0; bindex <= btail; bindex++) {
34848 + br = au_sbr(sb, bindex);
34849 + if (au_br_rdonly(br))
34851 + if (br->br_wbr->wbr_bytes > watermark) {
34862 + AuDbg("b%d\n", err);
34866 +/* ---------------------------------------------------------------------- */
34868 +/* most free space and then round robin */
34869 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
34872 + struct au_wbr_mfs *mfs;
34874 + err = au_wbr_create_mfs(dentry, flags);
34876 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
34877 + mutex_lock(&mfs->mfs_lock);
34878 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
34879 + err = au_wbr_create_rr(dentry, flags);
34880 + mutex_unlock(&mfs->mfs_lock);
34883 + AuDbg("b%d\n", err);
34887 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
34891 + au_wbr_create_init_mfs(sb); /* ignore */
34892 + err = au_wbr_create_init_rr(sb);
34897 +/* ---------------------------------------------------------------------- */
34899 +/* top down parent and most free space */
34900 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
34903 + unsigned long long b;
34904 + aufs_bindex_t bindex, btop, bbot;
34905 + struct super_block *sb;
34906 + struct dentry *parent, *h_parent;
34907 + struct au_branch *br;
34909 + err = au_wbr_create_tdp(dentry, flags);
34910 + if (unlikely(err < 0))
34912 + parent = dget_parent(dentry);
34913 + btop = au_dbtop(parent);
34914 + bbot = au_dbtaildir(parent);
34915 + if (btop == bbot)
34916 + goto out_parent; /* success */
34918 + e2 = au_wbr_create_mfs(dentry, flags);
34920 + goto out_parent; /* success */
34922 + /* when the available size is equal, select upper one */
34923 + sb = dentry->d_sb;
34924 + br = au_sbr(sb, err);
34925 + b = br->br_wbr->wbr_bytes;
34926 + AuDbg("b%d, %llu\n", err, b);
34928 + for (bindex = btop; bindex <= bbot; bindex++) {
34929 + h_parent = au_h_dptr(parent, bindex);
34930 + if (!h_parent || d_is_negative(h_parent))
34933 + br = au_sbr(sb, bindex);
34934 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
34935 + b = br->br_wbr->wbr_bytes;
34937 + AuDbg("b%d, %llu\n", err, b);
34942 + err = au_wbr_nonopq(dentry, err);
34947 + AuDbg("b%d\n", err);
34951 +/* ---------------------------------------------------------------------- */
34954 + * - top down parent
34955 + * - most free space with parent
34956 + * - most free space round-robin regardless parent
34958 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
34961 + unsigned long long watermark;
34962 + struct super_block *sb;
34963 + struct au_branch *br;
34964 + struct au_wbr_mfs *mfs;
34966 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
34967 + if (unlikely(err < 0))
34970 + sb = dentry->d_sb;
34971 + br = au_sbr(sb, err);
34972 + mfs = &au_sbi(sb)->si_wbr_mfs;
34973 + mutex_lock(&mfs->mfs_lock);
34974 + watermark = mfs->mfsrr_watermark;
34975 + mutex_unlock(&mfs->mfs_lock);
34976 + if (br->br_wbr->wbr_bytes < watermark)
34977 + /* regardless the parent dir */
34978 + err = au_wbr_create_mfsrr(dentry, flags);
34981 + AuDbg("b%d\n", err);
34985 +/* ---------------------------------------------------------------------- */
34987 +/* policies for copyup */
34989 +/* top down parent */
34990 +static int au_wbr_copyup_tdp(struct dentry *dentry)
34992 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
34995 +/* bottom up parent */
34996 +static int au_wbr_copyup_bup(struct dentry *dentry)
34999 + aufs_bindex_t bindex, btop;
35000 + struct dentry *parent, *h_parent;
35001 + struct super_block *sb;
35004 + sb = dentry->d_sb;
35005 + parent = dget_parent(dentry);
35006 + btop = au_dbtop(parent);
35007 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
35008 + h_parent = au_h_dptr(parent, bindex);
35009 + if (!h_parent || d_is_negative(h_parent))
35012 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
35019 + /* bottom up here */
35020 + if (unlikely(err < 0))
35021 + err = au_wbr_bu(sb, btop - 1);
35023 + AuDbg("b%d\n", err);
35028 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
35032 + err = au_wbr_bu(dentry->d_sb, btop);
35033 + AuDbg("b%d\n", err);
35035 + err = au_wbr_nonopq(dentry, err);
35037 + AuDbg("b%d\n", err);
35041 +static int au_wbr_copyup_bu(struct dentry *dentry)
35044 + aufs_bindex_t btop;
35046 + btop = au_dbtop(dentry);
35047 + err = au_wbr_do_copyup_bu(dentry, btop);
35051 +/* ---------------------------------------------------------------------- */
35053 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
35054 + [AuWbrCopyup_TDP] = {
35055 + .copyup = au_wbr_copyup_tdp
35057 + [AuWbrCopyup_BUP] = {
35058 + .copyup = au_wbr_copyup_bup
35060 + [AuWbrCopyup_BU] = {
35061 + .copyup = au_wbr_copyup_bu
35065 +struct au_wbr_create_operations au_wbr_create_ops[] = {
35066 + [AuWbrCreate_TDP] = {
35067 + .create = au_wbr_create_tdp
35069 + [AuWbrCreate_RR] = {
35070 + .create = au_wbr_create_rr,
35071 + .init = au_wbr_create_init_rr
35073 + [AuWbrCreate_MFS] = {
35074 + .create = au_wbr_create_mfs,
35075 + .init = au_wbr_create_init_mfs,
35076 + .fin = au_wbr_create_fin_mfs
35078 + [AuWbrCreate_MFSV] = {
35079 + .create = au_wbr_create_mfs,
35080 + .init = au_wbr_create_init_mfs,
35081 + .fin = au_wbr_create_fin_mfs
35083 + [AuWbrCreate_MFSRR] = {
35084 + .create = au_wbr_create_mfsrr,
35085 + .init = au_wbr_create_init_mfsrr,
35086 + .fin = au_wbr_create_fin_mfs
35088 + [AuWbrCreate_MFSRRV] = {
35089 + .create = au_wbr_create_mfsrr,
35090 + .init = au_wbr_create_init_mfsrr,
35091 + .fin = au_wbr_create_fin_mfs
35093 + [AuWbrCreate_TDMFS] = {
35094 + .create = au_wbr_create_tdmfs,
35095 + .init = au_wbr_create_init_mfs,
35096 + .fin = au_wbr_create_fin_mfs
35098 + [AuWbrCreate_TDMFSV] = {
35099 + .create = au_wbr_create_tdmfs,
35100 + .init = au_wbr_create_init_mfs,
35101 + .fin = au_wbr_create_fin_mfs
35103 + [AuWbrCreate_PMFS] = {
35104 + .create = au_wbr_create_pmfs,
35105 + .init = au_wbr_create_init_mfs,
35106 + .fin = au_wbr_create_fin_mfs
35108 + [AuWbrCreate_PMFSV] = {
35109 + .create = au_wbr_create_pmfs,
35110 + .init = au_wbr_create_init_mfs,
35111 + .fin = au_wbr_create_fin_mfs
35113 + [AuWbrCreate_PMFSRR] = {
35114 + .create = au_wbr_create_pmfsrr,
35115 + .init = au_wbr_create_init_mfsrr,
35116 + .fin = au_wbr_create_fin_mfs
35118 + [AuWbrCreate_PMFSRRV] = {
35119 + .create = au_wbr_create_pmfsrr,
35120 + .init = au_wbr_create_init_mfsrr,
35121 + .fin = au_wbr_create_fin_mfs
35124 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
35125 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
35126 +++ linux/fs/aufs/whout.c 2023-08-28 12:34:39.999969465 +0200
35128 +// SPDX-License-Identifier: GPL-2.0
35130 + * Copyright (C) 2005-2022 Junjiro R. Okajima
35132 + * This program is free software; you can redistribute it and/or modify
35133 + * it under the terms of the GNU General Public License as published by
35134 + * the Free Software Foundation; either version 2 of the License, or
35135 + * (at your option) any later version.
35137 + * This program is distributed in the hope that it will be useful,
35138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35140 + * GNU General Public License for more details.
35142 + * You should have received a copy of the GNU General Public License
35143 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35147 + * whiteout for logical deletion and opaque directory
35152 +#define WH_MASK 0444
35155 + * If a directory contains this file, then it is opaque. We start with the
35156 + * .wh. flag so that it is blocked by lookup.
35158 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
35159 + sizeof(AUFS_WH_DIROPQ) - 1);
35162 + * generate whiteout name, which is NOT terminated by NULL.
35163 + * @name: original d_name.name
35164 + * @len: original d_name.len
35165 + * @wh: whiteout qstr
35166 + * returns zero when succeeds, otherwise error.
35167 + * succeeded value as wh->name should be freed by kfree().
35169 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
35173 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
35174 + return -ENAMETOOLONG;
35176 + wh->len = name->len + AUFS_WH_PFX_LEN;
35177 + p = kmalloc(wh->len, GFP_NOFS);
35180 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35181 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
35188 +/* ---------------------------------------------------------------------- */
35191 + * test if the @wh_name exists under @h_ppath.
35192 + * @try_sio specifies the necessary of super-io.
35194 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
35195 + struct qstr *wh_name, int try_sio)
35198 + struct dentry *wh_dentry;
35201 + wh_dentry = vfsub_lkup_one(wh_name, h_ppath);
35203 + wh_dentry = au_sio_lkup_one(h_idmap, wh_name, h_ppath);
35204 + err = PTR_ERR(wh_dentry);
35205 + if (IS_ERR(wh_dentry)) {
35206 + if (err == -ENAMETOOLONG)
35212 + if (d_is_negative(wh_dentry))
35213 + goto out_wh; /* success */
35216 + if (d_is_reg(wh_dentry))
35217 + goto out_wh; /* success */
35220 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
35221 + wh_dentry, d_inode(wh_dentry)->i_mode);
35230 + * test if the @h_path->dentry sets opaque or not.
35232 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path)
35235 + struct inode *h_dir;
35237 + h_dir = d_inode(h_path->dentry);
35238 + err = au_wh_test(h_idmap, h_path, &diropq_name,
35239 + au_test_h_perm_sio(h_idmap, h_dir, MAY_EXEC));
35244 + * returns a negative dentry whose name is unique and temporary.
35246 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
35247 + struct qstr *prefix)
35249 + struct dentry *dentry;
35251 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
35253 + /* strict atomic_t is unnecessary here */
35254 + static unsigned short cnt;
35256 + struct path h_ppath;
35257 + struct mnt_idmap *h_idmap;
35259 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
35262 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
35263 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
35264 + dentry = ERR_PTR(-ENAMETOOLONG);
35265 + if (unlikely(qs.len > NAME_MAX))
35267 + dentry = ERR_PTR(-ENOMEM);
35268 + name = kmalloc(qs.len + 1, GFP_NOFS);
35269 + if (unlikely(!name))
35273 + /* doubly whiteout-ed */
35274 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
35275 + p = name + AUFS_WH_PFX_LEN * 2;
35276 + memcpy(p, prefix->name, prefix->len);
35277 + p += prefix->len;
35279 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
35281 + h_ppath.dentry = h_parent;
35282 + h_ppath.mnt = au_br_mnt(br);
35283 + h_idmap = au_br_idmap(br);
35285 + for (i = 0; i < 3; i++) {
35286 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
35287 + dentry = au_sio_lkup_one(h_idmap, &qs, &h_ppath);
35288 + if (IS_ERR(dentry) || d_is_negative(dentry))
35292 + /* pr_warn("could not get random name\n"); */
35293 + dentry = ERR_PTR(-EEXIST);
35294 + AuDbg("%.*s\n", AuLNPair(&qs));
35298 + if (name != defname)
35299 + au_kfree_try_rcu(name);
35301 + AuTraceErrPtr(dentry);
35306 + * rename the @h_dentry on @br to the whiteouted temporary name.
35308 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
35311 + struct path h_path = {
35312 + .mnt = au_br_mnt(br)
35314 + struct inode *h_dir, *delegated;
35315 + struct dentry *h_parent;
35317 + h_parent = h_dentry->d_parent; /* dir inode is locked */
35318 + h_dir = d_inode(h_parent);
35319 + IMustLock(h_dir);
35321 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
35322 + err = PTR_ERR(h_path.dentry);
35323 + if (IS_ERR(h_path.dentry))
35326 + /* under the same dir, no need to lock_rename() */
35327 + delegated = NULL;
35328 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
35331 + if (unlikely(err == -EWOULDBLOCK)) {
35332 + pr_warn("cannot retry for NFSv4 delegation"
35333 + " for an internal rename\n");
35336 + dput(h_path.dentry);
35343 +/* ---------------------------------------------------------------------- */
35345 + * functions for removing a whiteout
35348 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
35351 + struct inode *delegated;
35354 + * forces superio when the dir has a sticky bit.
35355 + * this may be a violation of unix fs semantics.
35357 + force = (h_dir->i_mode & S_ISVTX)
35358 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
35359 + delegated = NULL;
35360 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
35361 + if (unlikely(err == -EWOULDBLOCK)) {
35362 + pr_warn("cannot retry for NFSv4 delegation"
35363 + " for an internal unlink\n");
35369 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
35370 + struct dentry *dentry)
35374 + err = do_unlink_wh(h_dir, h_path);
35375 + if (!err && dentry)
35376 + au_set_dbwh(dentry, -1);
35381 +static int unlink_wh_name(struct path *h_ppath, struct qstr *wh)
35384 + struct path h_path;
35387 + h_path.dentry = vfsub_lkup_one(wh, h_ppath);
35388 + if (IS_ERR(h_path.dentry))
35389 + err = PTR_ERR(h_path.dentry);
35391 + if (d_is_reg(h_path.dentry)) {
35392 + h_path.mnt = h_ppath->mnt;
35393 + err = do_unlink_wh(d_inode(h_ppath->dentry), &h_path);
35395 + dput(h_path.dentry);
35401 +/* ---------------------------------------------------------------------- */
35403 + * initialize/clean whiteout for a branch
35406 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
35410 + struct inode *delegated;
35412 + if (d_is_negative(whpath->dentry))
35416 + err = vfsub_rmdir(h_dir, whpath);
35418 + delegated = NULL;
35419 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
35420 + if (unlikely(err == -EWOULDBLOCK)) {
35421 + pr_warn("cannot retry for NFSv4 delegation"
35422 + " for an internal unlink\n");
35426 + if (unlikely(err))
35427 + pr_warn("failed removing %pd (%d), ignored.\n",
35428 + whpath->dentry, err);
35431 +static int test_linkable(struct dentry *h_root)
35433 + struct inode *h_dir = d_inode(h_root);
35435 + if (h_dir->i_op->link)
35438 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
35439 + h_root, au_sbtype(h_root->d_sb));
35440 + return -ENOSYS; /* the branch doesn't have its ->link() */
35443 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
35444 +static int au_whdir(struct inode *h_dir, struct path *path)
35449 + if (d_is_negative(path->dentry)) {
35452 + if (au_test_nfs(path->dentry->d_sb))
35454 + err = vfsub_mkdir(h_dir, path, mode);
35455 + } else if (d_is_dir(path->dentry))
35458 + pr_err("unknown %pd exists\n", path->dentry);
35463 +struct au_wh_base {
35464 + const struct qstr *name;
35465 + struct dentry *dentry;
35468 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
35469 + struct path *h_path)
35471 + h_path->dentry = base[AuBrWh_BASE].dentry;
35472 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35473 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35474 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35475 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35476 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35480 + * returns tri-state,
35481 + * minus: error, caller should print the message
35483 + * plus: error, caller should NOT print the message
35485 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
35486 + int do_plink, struct au_wh_base base[],
35487 + struct path *h_path)
35490 + struct inode *h_dir;
35492 + h_dir = d_inode(h_root);
35493 + h_path->dentry = base[AuBrWh_BASE].dentry;
35494 + au_wh_clean(h_dir, h_path, /*isdir*/0);
35495 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35497 + err = test_linkable(h_root);
35498 + if (unlikely(err)) {
35503 + err = au_whdir(h_dir, h_path);
35504 + if (unlikely(err))
35506 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35508 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35509 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35510 + err = au_whdir(h_dir, h_path);
35511 + if (unlikely(err))
35513 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35520 + * for the moment, aufs supports the branch filesystem which does not support
35521 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
35522 + * copyup failed. finally, such filesystem will not be used as the writable
35525 + * returns tri-state, see above.
35527 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
35528 + int do_plink, struct au_wh_base base[],
35529 + struct path *h_path)
35532 + struct inode *h_dir;
35534 + WbrWhMustWriteLock(wbr);
35536 + err = test_linkable(h_root);
35537 + if (unlikely(err)) {
35543 + * todo: should this create be done in /sbin/mount.aufs helper?
35546 + h_dir = d_inode(h_root);
35547 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
35548 + h_path->dentry = base[AuBrWh_BASE].dentry;
35549 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
35550 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
35553 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
35554 + if (unlikely(err))
35557 + h_path->dentry = base[AuBrWh_PLINK].dentry;
35559 + err = au_whdir(h_dir, h_path);
35560 + if (unlikely(err))
35562 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
35564 + au_wh_clean(h_dir, h_path, /*isdir*/1);
35565 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
35567 + h_path->dentry = base[AuBrWh_ORPH].dentry;
35568 + err = au_whdir(h_dir, h_path);
35569 + if (unlikely(err))
35571 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
35578 + * initialize the whiteout base file/dir for @br.
35580 +int au_wh_init(struct au_branch *br, struct super_block *sb)
35583 + const unsigned char do_plink
35584 + = !!au_opt_test(au_mntflags(sb), PLINK);
35585 + struct inode *h_dir;
35586 + struct path path = br->br_path;
35587 + struct dentry *h_root = path.dentry;
35588 + struct au_wbr *wbr = br->br_wbr;
35589 + static const struct qstr base_name[] = {
35590 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
35591 + sizeof(AUFS_BASE_NAME) - 1),
35592 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
35593 + sizeof(AUFS_PLINKDIR_NAME) - 1),
35594 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
35595 + sizeof(AUFS_ORPHDIR_NAME) - 1)
35597 + struct au_wh_base base[] = {
35598 + [AuBrWh_BASE] = {
35599 + .name = base_name + AuBrWh_BASE,
35602 + [AuBrWh_PLINK] = {
35603 + .name = base_name + AuBrWh_PLINK,
35606 + [AuBrWh_ORPH] = {
35607 + .name = base_name + AuBrWh_ORPH,
35613 + WbrWhMustWriteLock(wbr);
35615 + for (i = 0; i < AuBrWh_Last; i++) {
35616 + /* doubly whiteouted */
35617 + struct dentry *d;
35619 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
35620 + err = PTR_ERR(d);
35624 + base[i].dentry = d;
35626 + && wbr->wbr_wh[i]
35627 + && wbr->wbr_wh[i] != base[i].dentry);
35631 + for (i = 0; i < AuBrWh_Last; i++) {
35632 + dput(wbr->wbr_wh[i]);
35633 + wbr->wbr_wh[i] = NULL;
35637 + if (!au_br_writable(br->br_perm)) {
35638 + h_dir = d_inode(h_root);
35639 + au_wh_init_ro(h_dir, base, &path);
35640 + } else if (!au_br_wh_linkable(br->br_perm)) {
35641 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
35647 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
35653 + goto out; /* success */
35656 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
35657 + err, h_root, au_sbtype(h_root->d_sb));
35659 + for (i = 0; i < AuBrWh_Last; i++)
35660 + dput(base[i].dentry);
35664 +/* ---------------------------------------------------------------------- */
35666 + * whiteouts are all hard-linked usually.
35667 + * when its link count reaches a ceiling, we create a new whiteout base
35668 + * asynchronously.
35671 +struct reinit_br_wh {
35672 + struct super_block *sb;
35673 + struct au_branch *br;
35676 +static void reinit_br_wh(void *arg)
35679 + aufs_bindex_t bindex;
35680 + struct path h_path;
35681 + struct reinit_br_wh *a = arg;
35682 + struct au_wbr *wbr;
35683 + struct inode *dir, *delegated;
35684 + struct dentry *h_root;
35685 + struct au_hinode *hdir;
35688 + wbr = a->br->br_wbr;
35689 + /* big aufs lock */
35690 + si_noflush_write_lock(a->sb);
35691 + if (!au_br_writable(a->br->br_perm))
35693 + bindex = au_br_index(a->sb, a->br->br_id);
35694 + if (unlikely(bindex < 0))
35697 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
35698 + dir = d_inode(a->sb->s_root);
35699 + hdir = au_hi(dir, bindex);
35700 + h_root = au_h_dptr(a->sb->s_root, bindex);
35701 + AuDebugOn(h_root != au_br_dentry(a->br));
35703 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
35704 + wbr_wh_write_lock(wbr);
35705 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
35708 + h_path.dentry = wbr->wbr_whbase;
35709 + h_path.mnt = au_br_mnt(a->br);
35710 + delegated = NULL;
35711 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
35713 + if (unlikely(err == -EWOULDBLOCK)) {
35714 + pr_warn("cannot retry for NFSv4 delegation"
35715 + " for an internal unlink\n");
35719 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
35722 + dput(wbr->wbr_whbase);
35723 + wbr->wbr_whbase = NULL;
35725 + err = au_wh_init(a->br, a->sb);
35726 + wbr_wh_write_unlock(wbr);
35727 + au_hn_inode_unlock(hdir);
35728 + di_read_unlock(a->sb->s_root, AuLock_IR);
35730 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
35734 + atomic_dec(&wbr->wbr_wh_running);
35735 + au_lcnt_dec(&a->br->br_count);
35736 + si_write_unlock(a->sb);
35737 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
35739 + if (unlikely(err))
35740 + AuIOErr("err %d\n", err);
35743 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
35745 + int do_dec, wkq_err;
35746 + struct reinit_br_wh *arg;
35749 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
35752 + /* ignore ENOMEM */
35753 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
35756 + * dec(wh_running), kfree(arg) and dec(br_count)
35757 + * in reinit function
35761 + au_lcnt_inc(&br->br_count);
35762 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
35763 + if (unlikely(wkq_err)) {
35764 + atomic_dec(&br->br_wbr->wbr_wh_running);
35765 + au_lcnt_dec(&br->br_count);
35766 + au_kfree_rcu(arg);
35773 + atomic_dec(&br->br_wbr->wbr_wh_running);
35776 +/* ---------------------------------------------------------------------- */
35779 + * create the whiteout @wh.
35781 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
35782 + struct dentry *wh)
35785 + struct path h_path = {
35788 + struct au_branch *br;
35789 + struct au_wbr *wbr;
35790 + struct dentry *h_parent;
35791 + struct inode *h_dir, *delegated;
35793 + h_parent = wh->d_parent; /* dir inode is locked */
35794 + h_dir = d_inode(h_parent);
35795 + IMustLock(h_dir);
35797 + br = au_sbr(sb, bindex);
35798 + h_path.mnt = au_br_mnt(br);
35799 + wbr = br->br_wbr;
35800 + wbr_wh_read_lock(wbr);
35801 + if (wbr->wbr_whbase) {
35802 + delegated = NULL;
35803 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
35804 + if (unlikely(err == -EWOULDBLOCK)) {
35805 + pr_warn("cannot retry for NFSv4 delegation"
35806 + " for an internal link\n");
35809 + if (!err || err != -EMLINK)
35812 + /* link count full. re-initialize br_whbase. */
35813 + kick_reinit_br_wh(sb, br);
35816 + /* return this error in this context */
35817 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
35819 + au_fhsm_wrote(sb, bindex, /*force*/0);
35822 + wbr_wh_read_unlock(wbr);
35826 +/* ---------------------------------------------------------------------- */
35829 + * create or remove the diropq.
35831 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
35832 + unsigned int flags)
35834 + struct dentry *opq_dentry;
35835 + struct super_block *sb;
35836 + struct au_branch *br;
35837 + struct path h_path;
35840 + sb = dentry->d_sb;
35841 + br = au_sbr(sb, bindex);
35842 + h_path.dentry = au_h_dptr(dentry, bindex);
35843 + h_path.mnt = au_br_mnt(br);
35844 + opq_dentry = vfsub_lkup_one(&diropq_name, &h_path);
35845 + if (IS_ERR(opq_dentry))
35848 + if (au_ftest_diropq(flags, CREATE)) {
35849 + err = link_or_create_wh(sb, bindex, opq_dentry);
35851 + au_set_dbdiropq(dentry, bindex);
35852 + goto out; /* success */
35855 + h_path.dentry = opq_dentry;
35856 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &h_path);
35858 + au_set_dbdiropq(dentry, -1);
35860 + dput(opq_dentry);
35861 + opq_dentry = ERR_PTR(err);
35864 + return opq_dentry;
35867 +struct do_diropq_args {
35868 + struct dentry **errp;
35869 + struct dentry *dentry;
35870 + aufs_bindex_t bindex;
35871 + unsigned int flags;
35874 +static void call_do_diropq(void *args)
35876 + struct do_diropq_args *a = args;
35877 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
35880 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
35881 + unsigned int flags)
35883 + struct dentry *diropq, *h_dentry;
35884 + struct mnt_idmap *h_idmap;
35886 + h_idmap = au_sbr_idmap(dentry->d_sb, bindex);
35887 + h_dentry = au_h_dptr(dentry, bindex);
35888 + if (!au_test_h_perm_sio(h_idmap, d_inode(h_dentry),
35889 + MAY_EXEC | MAY_WRITE))
35890 + diropq = do_diropq(dentry, bindex, flags);
35893 + struct do_diropq_args args = {
35895 + .dentry = dentry,
35896 + .bindex = bindex,
35900 + wkq_err = au_wkq_wait(call_do_diropq, &args);
35901 + if (unlikely(wkq_err))
35902 + diropq = ERR_PTR(wkq_err);
35908 +/* ---------------------------------------------------------------------- */
35911 + * lookup whiteout dentry.
35912 + * @h_parent: lower parent dentry which must exist and be locked
35913 + * @base_name: name of dentry which will be whiteouted
35914 + * returns dentry for whiteout.
35916 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
35917 + struct au_branch *br)
35920 + struct qstr wh_name;
35921 + struct dentry *wh_dentry;
35922 + struct path h_path;
35924 + err = au_wh_name_alloc(&wh_name, base_name);
35925 + wh_dentry = ERR_PTR(err);
35927 + h_path.dentry = h_parent;
35928 + h_path.mnt = au_br_mnt(br);
35929 + wh_dentry = vfsub_lkup_one(&wh_name, &h_path);
35930 + au_kfree_try_rcu(wh_name.name);
35932 + return wh_dentry;
35936 + * link/create a whiteout for @dentry on @bindex.
35938 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
35939 + struct dentry *h_parent)
35941 + struct dentry *wh_dentry;
35942 + struct super_block *sb;
35945 + sb = dentry->d_sb;
35946 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
35947 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
35948 + err = link_or_create_wh(sb, bindex, wh_dentry);
35950 + au_set_dbwh(dentry, bindex);
35951 + au_fhsm_wrote(sb, bindex, /*force*/0);
35954 + wh_dentry = ERR_PTR(err);
35958 + return wh_dentry;
35961 +/* ---------------------------------------------------------------------- */
35963 +/* Delete all whiteouts in this directory on branch bindex. */
35964 +static int del_wh_children(struct path *h_path, struct au_nhash *whlist,
35965 + aufs_bindex_t bindex)
35968 + unsigned long ul, n;
35969 + struct qstr wh_name;
35971 + struct hlist_head *head;
35972 + struct au_vdir_wh *pos;
35973 + struct au_vdir_destr *str;
35976 + p = (void *)__get_free_page(GFP_NOFS);
35977 + wh_name.name = p;
35978 + if (unlikely(!wh_name.name))
35982 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
35983 + p += AUFS_WH_PFX_LEN;
35984 + n = whlist->nh_num;
35985 + head = whlist->nh_head;
35986 + for (ul = 0; !err && ul < n; ul++, head++) {
35987 + hlist_for_each_entry(pos, head, wh_hash) {
35988 + if (pos->wh_bindex != bindex)
35991 + str = &pos->wh_str;
35992 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
35993 + memcpy(p, str->name, str->len);
35994 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
35995 + err = unlink_wh_name(h_path, &wh_name);
36000 + AuIOErr("whiteout name too long %.*s\n",
36001 + str->len, str->name);
36006 + free_page((unsigned long)wh_name.name);
36012 +struct del_wh_children_args {
36014 + struct path *h_path;
36015 + struct au_nhash *whlist;
36016 + aufs_bindex_t bindex;
36019 +static void call_del_wh_children(void *args)
36021 + struct del_wh_children_args *a = args;
36022 + *a->errp = del_wh_children(a->h_path, a->whlist, a->bindex);
36025 +/* ---------------------------------------------------------------------- */
36027 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
36029 + struct au_whtmp_rmdir *whtmp;
36031 + unsigned int rdhash;
36033 + SiMustAnyLock(sb);
36035 + whtmp = kzalloc(sizeof(*whtmp), gfp);
36036 + if (unlikely(!whtmp)) {
36037 + whtmp = ERR_PTR(-ENOMEM);
36041 + /* no estimation for dir size */
36042 + rdhash = au_sbi(sb)->si_rdhash;
36044 + rdhash = AUFS_RDHASH_DEF;
36045 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
36046 + if (unlikely(err)) {
36047 + au_kfree_rcu(whtmp);
36048 + whtmp = ERR_PTR(err);
36055 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
36058 + au_lcnt_dec(&whtmp->br->br_count);
36059 + dput(whtmp->wh_dentry);
36060 + iput(whtmp->dir);
36061 + au_nhash_wh_free(&whtmp->whlist);
36062 + au_kfree_rcu(whtmp);
36066 + * rmdir the whiteouted temporary named dir @h_dentry.
36067 + * @whlist: whiteouted children.
36069 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36070 + struct dentry *wh_dentry, struct au_nhash *whlist)
36073 + unsigned int h_nlink;
36074 + struct path wh_path;
36075 + struct inode *wh_inode, *h_dir;
36076 + struct au_branch *br;
36077 + struct mnt_idmap *h_idmap;
36079 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
36080 + IMustLock(h_dir);
36082 + br = au_sbr(dir->i_sb, bindex);
36083 + wh_path.dentry = wh_dentry;
36084 + wh_path.mnt = au_br_mnt(br);
36085 + h_idmap = au_br_idmap(br);
36086 + wh_inode = d_inode(wh_dentry);
36087 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
36090 + * someone else might change some whiteouts while we were sleeping.
36091 + * it means this whlist may have an obsoleted entry.
36093 + if (!au_test_h_perm_sio(h_idmap, wh_inode, MAY_EXEC | MAY_WRITE))
36094 + err = del_wh_children(&wh_path, whlist, bindex);
36097 + struct del_wh_children_args args = {
36099 + .h_path = &wh_path,
36100 + .whlist = whlist,
36104 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
36105 + if (unlikely(wkq_err))
36108 + inode_unlock(wh_inode);
36111 + h_nlink = h_dir->i_nlink;
36112 + err = vfsub_rmdir(h_dir, &wh_path);
36113 + /* some fs doesn't change the parent nlink in some cases */
36114 + h_nlink -= h_dir->i_nlink;
36118 + if (au_ibtop(dir) == bindex) {
36119 + /* todo: dir->i_mutex is necessary */
36120 + au_cpup_attr_timesizes(dir);
36122 + vfsub_drop_nlink(dir);
36124 + return 0; /* success */
36127 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
36131 +static void call_rmdir_whtmp(void *args)
36134 + aufs_bindex_t bindex;
36135 + struct au_whtmp_rmdir *a = args;
36136 + struct super_block *sb;
36137 + struct dentry *h_parent;
36138 + struct inode *h_dir;
36139 + struct au_hinode *hdir;
36141 + /* rmdir by nfsd may cause deadlock with this i_mutex */
36142 + /* inode_lock(a->dir); */
36144 + sb = a->dir->i_sb;
36145 + si_read_lock(sb, !AuLock_FLUSH);
36146 + if (!au_br_writable(a->br->br_perm))
36148 + bindex = au_br_index(sb, a->br->br_id);
36149 + if (unlikely(bindex < 0))
36153 + ii_write_lock_parent(a->dir);
36154 + h_parent = dget_parent(a->wh_dentry);
36155 + h_dir = d_inode(h_parent);
36156 + hdir = au_hi(a->dir, bindex);
36157 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
36158 + if (unlikely(err))
36160 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
36161 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
36164 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
36165 + au_hn_inode_unlock(hdir);
36166 + vfsub_mnt_drop_write(au_br_mnt(a->br));
36170 + ii_write_unlock(a->dir);
36172 + /* inode_unlock(a->dir); */
36173 + au_whtmp_rmdir_free(a);
36174 + si_read_unlock(sb);
36175 + au_nwt_done(&au_sbi(sb)->si_nowait);
36176 + if (unlikely(err))
36177 + AuIOErr("err %d\n", err);
36180 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36181 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
36184 + struct super_block *sb;
36188 + /* all post-process will be done in do_rmdir_whtmp(). */
36190 + args->dir = au_igrab(dir);
36191 + args->br = au_sbr(sb, bindex);
36192 + au_lcnt_inc(&args->br->br_count);
36193 + args->wh_dentry = dget(wh_dentry);
36194 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
36195 + if (unlikely(wkq_err)) {
36196 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
36197 + au_whtmp_rmdir_free(args);
36200 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
36201 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
36202 +++ linux/fs/aufs/whout.h 2023-08-28 12:34:39.999969465 +0200
36204 +/* SPDX-License-Identifier: GPL-2.0 */
36206 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36208 + * This program is free software; you can redistribute it and/or modify
36209 + * it under the terms of the GNU General Public License as published by
36210 + * the Free Software Foundation; either version 2 of the License, or
36211 + * (at your option) any later version.
36213 + * This program is distributed in the hope that it will be useful,
36214 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36215 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36216 + * GNU General Public License for more details.
36218 + * You should have received a copy of the GNU General Public License
36219 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36223 + * whiteout for logical deletion and opaque directory
36226 +#ifndef __AUFS_WHOUT_H__
36227 +#define __AUFS_WHOUT_H__
36234 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
36235 +int au_wh_test(struct mnt_idmap *h_idmap, struct path *h_ppath,
36236 + struct qstr *wh_name, int try_sio);
36237 +int au_diropq_test(struct mnt_idmap *h_idmap, struct path *h_path);
36239 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
36240 + struct qstr *prefix);
36241 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
36242 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
36243 + struct dentry *dentry);
36244 +int au_wh_init(struct au_branch *br, struct super_block *sb);
36246 +/* diropq flags */
36247 +#define AuDiropq_CREATE 1
36248 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
36249 +#define au_fset_diropq(flags, name) \
36250 + do { (flags) |= AuDiropq_##name; } while (0)
36251 +#define au_fclr_diropq(flags, name) \
36252 + do { (flags) &= ~AuDiropq_##name; } while (0)
36254 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
36255 + unsigned int flags);
36256 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
36257 + struct au_branch *br);
36258 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
36259 + struct dentry *h_parent);
36261 +/* real rmdir for the whiteout-ed dir */
36262 +struct au_whtmp_rmdir {
36263 + struct inode *dir;
36264 + struct au_branch *br;
36265 + struct dentry *wh_dentry;
36266 + struct au_nhash whlist;
36269 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
36270 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
36271 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
36272 + struct dentry *wh_dentry, struct au_nhash *whlist);
36273 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
36274 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
36276 +/* ---------------------------------------------------------------------- */
36278 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
36279 + aufs_bindex_t bindex)
36281 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
36284 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
36286 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
36289 +#endif /* __KERNEL__ */
36290 +#endif /* __AUFS_WHOUT_H__ */
36291 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
36292 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
36293 +++ linux/fs/aufs/wkq.c 2022-11-05 23:02:18.972555950 +0100
36295 +// SPDX-License-Identifier: GPL-2.0
36297 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36299 + * This program is free software; you can redistribute it and/or modify
36300 + * it under the terms of the GNU General Public License as published by
36301 + * the Free Software Foundation; either version 2 of the License, or
36302 + * (at your option) any later version.
36304 + * This program is distributed in the hope that it will be useful,
36305 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36306 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36307 + * GNU General Public License for more details.
36309 + * You should have received a copy of the GNU General Public License
36310 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36314 + * workqueue for asynchronous/super-io operations
36315 + * todo: try new credential scheme
36318 +#include <linux/module.h>
36321 +/* internal workqueue named AUFS_WKQ_NAME */
36323 +static struct workqueue_struct *au_wkq;
36325 +struct au_wkinfo {
36326 + struct work_struct wk;
36327 + struct kobject *kobj;
36329 + unsigned int flags; /* see wkq.h */
36331 + au_wkq_func_t func;
36334 +#ifdef CONFIG_LOCKDEP
36336 + struct held_lock **hlock;
36339 + struct completion *comp;
36342 +/* ---------------------------------------------------------------------- */
36344 + * Aufs passes some operations to the workqueue such as the internal copyup.
36345 + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the
36346 + * job run by workqueue depends upon the locks acquired in the other task.
36347 + * Delegating a small operation to the workqueue, aufs passes its lockdep
36348 + * information too. And the job in the workqueue restores the info in order to
36349 + * pretend as if it acquired those locks. This is just to make LOCKDEP work
36350 + * correctly and expectedly.
36353 +#ifndef CONFIG_LOCKDEP
36354 +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo);
36355 +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo);
36356 +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo);
36357 +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo);
36358 +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo);
36360 +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo)
36362 + wkinfo->hlock = NULL;
36363 + wkinfo->dont_check = 0;
36370 +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name)
36372 + static DEFINE_SPINLOCK(spin);
36375 + struct lock_class_key *key;
36377 + { .name = "&sbinfo->si_rwsem" },
36378 + { .name = "&finfo->fi_rwsem" },
36379 + { .name = "&dinfo->di_rwsem" },
36380 + { .name = "&iinfo->ii_rwsem" }
36385 + /* lockless read from 'set.' see below */
36386 + if (set == ARRAY_SIZE(a)) {
36387 + for (i = 0; i < ARRAY_SIZE(a); i++)
36388 + if (a[i].key == key)
36393 + spin_lock(&spin);
36395 + for (i = 0; i < ARRAY_SIZE(a); i++)
36396 + if (a[i].key == key) {
36397 + spin_unlock(&spin);
36400 + for (i = 0; i < ARRAY_SIZE(a); i++) {
36402 + if (unlikely(a[i].key == key)) { /* rare but possible */
36403 + spin_unlock(&spin);
36408 + if (strstr(a[i].name, name)) {
36410 + * the order of these three lines is important for the
36411 + * lockless read above.
36414 + spin_unlock(&spin);
36416 + /* AuDbg("%d, %s\n", set, name); */
36420 + spin_unlock(&spin);
36429 +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo)
36432 + struct task_struct *curr;
36433 + struct held_lock **hl, *held_locks, *p;
36437 + wkinfo->dont_check = lockdep_recursing(curr);
36438 + if (wkinfo->dont_check)
36440 + n = curr->lockdep_depth;
36445 + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS);
36446 + if (unlikely(!wkinfo->hlock))
36450 +#if 0 /* left for debugging */
36451 + if (0 && au_debug_test())
36452 + lockdep_print_held_locks(curr);
36454 + held_locks = curr->held_locks;
36455 + hl = wkinfo->hlock;
36457 + p = held_locks++;
36458 + if (au_wkq_lockdep_test(p->instance->key, p->instance->name))
36467 +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo)
36469 + au_kfree_try_rcu(wkinfo->hlock);
36472 +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo)
36474 + struct held_lock *p, **hl = wkinfo->hlock;
36477 + if (wkinfo->dont_check)
36481 + while ((p = *hl++)) { /* assignment */
36482 + subclass = lockdep_hlock_class(p)->subclass;
36483 + /* AuDbg("%s, %d\n", p->instance->name, subclass); */
36485 + rwsem_acquire_read(p->instance, subclass, 0,
36486 + /*p->acquire_ip*/_RET_IP_);
36488 + rwsem_acquire(p->instance, subclass, 0,
36489 + /*p->acquire_ip*/_RET_IP_);
36493 +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo)
36495 + struct held_lock *p, **hl = wkinfo->hlock;
36497 + if (wkinfo->dont_check)
36501 + while ((p = *hl++)) /* assignment */
36502 + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_);
36506 +static void wkq_func(struct work_struct *wk)
36508 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
36510 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
36511 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
36513 + au_wkq_lockdep_pre(wkinfo);
36514 + wkinfo->func(wkinfo->args);
36515 + au_wkq_lockdep_post(wkinfo);
36516 + if (au_ftest_wkq(wkinfo->flags, WAIT))
36517 + complete(wkinfo->comp);
36519 + kobject_put(wkinfo->kobj);
36520 + module_put(THIS_MODULE); /* todo: ?? */
36521 + au_kfree_rcu(wkinfo);
36526 + * Since struct completion is large, try allocating it dynamically.
36528 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
36530 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
36532 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
36534 + init_completion(*comp);
36535 + wkinfo->comp = *comp;
36541 +static void au_wkq_comp_free(struct completion *comp)
36543 + au_kfree_rcu(comp);
36546 +static void au_wkq_run(struct au_wkinfo *wkinfo)
36548 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
36549 + if (au_wkq_test()) {
36550 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
36551 + " due to a dead dir by UDBA,"
36552 + " or async xino write?\n");
36553 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
36556 + au_dbg_verify_kthread();
36558 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
36559 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
36560 + queue_work(au_wkq, &wkinfo->wk);
36562 + INIT_WORK(&wkinfo->wk, wkq_func);
36563 + schedule_work(&wkinfo->wk);
36568 + * Be careful. It is easy to make deadlock happen.
36569 + * processA: lock, wkq and wait
36570 + * processB: wkq and wait, lock in wkq
36573 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
36576 + AuWkqCompDeclare(comp);
36577 + struct au_wkinfo wkinfo = {
36583 + err = au_wkq_comp_alloc(&wkinfo, &comp);
36584 + if (unlikely(err))
36586 + err = au_wkq_lockdep_alloc(&wkinfo);
36587 + if (unlikely(err))
36590 + au_wkq_run(&wkinfo);
36591 + /* no timeout, no interrupt */
36592 + wait_for_completion(wkinfo.comp);
36594 + au_wkq_lockdep_free(&wkinfo);
36597 + au_wkq_comp_free(comp);
36599 + destroy_work_on_stack(&wkinfo.wk);
36604 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
36605 + * problem in a concurrent umounting.
36607 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36608 + unsigned int flags)
36611 + struct au_wkinfo *wkinfo;
36613 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
36616 + * wkq_func() must free this wkinfo.
36617 + * it highly depends upon the implementation of workqueue.
36620 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
36622 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
36623 + wkinfo->flags = flags & ~AuWkq_WAIT;
36624 + wkinfo->func = func;
36625 + wkinfo->args = args;
36626 + wkinfo->comp = NULL;
36627 + au_wkq_lockdep_init(wkinfo);
36628 + kobject_get(wkinfo->kobj);
36629 + __module_get(THIS_MODULE); /* todo: ?? */
36631 + au_wkq_run(wkinfo);
36634 + au_nwt_done(&au_sbi(sb)->si_nowait);
36640 +/* ---------------------------------------------------------------------- */
36642 +void au_nwt_init(struct au_nowait_tasks *nwt)
36644 + atomic_set(&nwt->nw_len, 0);
36645 + /* smp_mb(); */ /* atomic_set */
36646 + init_waitqueue_head(&nwt->nw_wq);
36649 +void au_wkq_fin(void)
36651 + destroy_workqueue(au_wkq);
36654 +int __init au_wkq_init(void)
36659 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
36660 + if (IS_ERR(au_wkq))
36661 + err = PTR_ERR(au_wkq);
36662 + else if (!au_wkq)
36667 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
36668 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
36669 +++ linux/fs/aufs/wkq.h 2022-11-05 23:02:18.972555950 +0100
36671 +/* SPDX-License-Identifier: GPL-2.0 */
36673 + * Copyright (C) 2005-2022 Junjiro R. Okajima
36675 + * This program is free software; you can redistribute it and/or modify
36676 + * it under the terms of the GNU General Public License as published by
36677 + * the Free Software Foundation; either version 2 of the License, or
36678 + * (at your option) any later version.
36680 + * This program is distributed in the hope that it will be useful,
36681 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36682 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36683 + * GNU General Public License for more details.
36685 + * You should have received a copy of the GNU General Public License
36686 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36690 + * workqueue for asynchronous/super-io operations
36691 + * todo: try new credentials management scheme
36694 +#ifndef __AUFS_WKQ_H__
36695 +#define __AUFS_WKQ_H__
36699 +#include <linux/wait.h>
36701 +struct super_block;
36703 +/* ---------------------------------------------------------------------- */
36706 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36708 +struct au_nowait_tasks {
36710 + wait_queue_head_t nw_wq;
36713 +/* ---------------------------------------------------------------------- */
36715 +typedef void (*au_wkq_func_t)(void *args);
36718 +#define AuWkq_WAIT 1
36719 +#define AuWkq_NEST (1 << 1)
36720 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
36721 +#define au_fset_wkq(flags, name) \
36722 + do { (flags) |= AuWkq_##name; } while (0)
36723 +#define au_fclr_wkq(flags, name) \
36724 + do { (flags) &= ~AuWkq_##name; } while (0)
36727 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
36728 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
36729 + unsigned int flags);
36730 +void au_nwt_init(struct au_nowait_tasks *nwt);
36731 +int __init au_wkq_init(void);
36732 +void au_wkq_fin(void);
36734 +/* ---------------------------------------------------------------------- */
36736 +static inline int au_wkq_test(void)
36738 + return current->flags & PF_WQ_WORKER;
36741 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
36743 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
36746 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
36748 + if (atomic_dec_and_test(&nwt->nw_len))
36749 + wake_up_all(&nwt->nw_wq);
36752 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
36754 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
36758 +#endif /* __KERNEL__ */
36759 +#endif /* __AUFS_WKQ_H__ */
36760 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
36761 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
36762 +++ linux/fs/aufs/xattr.c 2023-08-28 12:34:39.999969465 +0200
36764 +// SPDX-License-Identifier: GPL-2.0
36766 + * Copyright (C) 2014-2022 Junjiro R. Okajima
36768 + * This program is free software; you can redistribute it and/or modify
36769 + * it under the terms of the GNU General Public License as published by
36770 + * the Free Software Foundation; either version 2 of the License, or
36771 + * (at your option) any later version.
36773 + * This program is distributed in the hope that it will be useful,
36774 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
36775 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36776 + * GNU General Public License for more details.
36778 + * You should have received a copy of the GNU General Public License
36779 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
36783 + * handling xattr functions
36786 +#include <linux/fs.h>
36787 +#include <linux/xattr.h>
36790 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
36792 + if (!ignore_flags)
36800 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
36805 +#define cmp(brattr, prefix) do { \
36806 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
36807 + XATTR_##prefix##_PREFIX_LEN)) { \
36808 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
36814 + cmp(SEC, SECURITY);
36815 + cmp(SYS, SYSTEM);
36816 + cmp(TR, TRUSTED);
36820 + if (ignore_flags & AuBrAttr_ICEX_OTH)
36827 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
36829 +static int au_do_cpup_xattr(struct path *h_dst, struct path *h_src,
36830 + char *name, char **buf, unsigned int ignore_flags,
36831 + unsigned int verbose)
36835 + struct inode *h_idst;
36836 + struct dentry *h_dst_dentry, *h_src_dentry;
36837 + struct mnt_idmap *h_dst_idmap, *h_src_idmap;
36838 + struct posix_acl *acl;
36840 + is_acl = !!is_posix_acl_xattr(name);
36841 + h_src_idmap = mnt_idmap(h_src->mnt);
36842 + h_src_dentry = h_src->dentry;
36844 + acl = vfs_get_acl(h_src_idmap, h_src_dentry, name);
36846 + if (unlikely(IS_ERR(acl))) {
36847 + err = PTR_ERR(acl);
36848 + if (err == -ENODATA)
36850 + else if (err == -EOPNOTSUPP
36851 + && au_test_nfs_noacl(d_inode(h_src_dentry)))
36853 + else if (verbose || au_debug_test())
36854 + pr_err("%s, err %d\n", name, err);
36858 + ssz = vfs_getxattr_alloc(h_src_idmap, h_src_dentry, name, buf,
36860 + if (unlikely(ssz <= 0)) {
36862 + if (err == -ENODATA)
36864 + else if (err == -EOPNOTSUPP
36865 + && (ignore_flags & au_xattr_out_of_list))
36867 + else if (err && (verbose || au_debug_test()))
36868 + pr_err("%s, err %d\n", name, err);
36873 + /* unlock it temporary */
36874 + h_dst_idmap = mnt_idmap(h_dst->mnt);
36875 + h_dst_dentry = h_dst->dentry;
36876 + h_idst = d_inode(h_dst_dentry);
36877 + inode_unlock(h_idst);
36879 + err = vfsub_set_acl(h_dst_idmap, h_dst_dentry, name, acl);
36880 + posix_acl_release(acl);
36882 + err = vfsub_setxattr(h_dst_idmap, h_dst_dentry, name, *buf,
36883 + ssz, /*flags*/0);
36884 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36885 + if (unlikely(err)) {
36886 + if (verbose || au_debug_test())
36887 + pr_err("%s, err %d\n", name, err);
36888 + err = au_xattr_ignore(err, name, ignore_flags);
36895 +int au_cpup_xattr(struct path *h_dst, struct path *h_src, int ignore_flags,
36896 + unsigned int verbose)
36898 + int err, unlocked;
36900 + struct dentry *h_dst_dentry, *h_src_dentry;
36901 + struct inode *h_isrc, *h_idst;
36902 + char *value, *p, *o, *e;
36904 + /* try stopping to update the source inode while we are referencing */
36905 + /* there should not be the parent-child relationship between them */
36906 + h_dst_dentry = h_dst->dentry;
36907 + h_idst = d_inode(h_dst_dentry);
36908 + h_src_dentry = h_src->dentry;
36909 + h_isrc = d_inode(h_src_dentry);
36910 + inode_unlock(h_idst);
36911 + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD);
36912 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
36915 + /* some filesystems don't list POSIX ACL, for example tmpfs */
36916 + ssz = vfs_listxattr(h_src_dentry, NULL, 0);
36918 + if (unlikely(err < 0)) {
36920 + if (err == -ENODATA
36921 + || err == -EOPNOTSUPP)
36922 + err = 0; /* ignore */
36931 + p = kmalloc(ssz, GFP_NOFS);
36933 + if (unlikely(!p))
36935 + err = vfs_listxattr(h_src_dentry, p, ssz);
36937 + inode_unlock_shared(h_isrc);
36939 + AuDbg("err %d, ssz %zd\n", err, ssz);
36940 + if (unlikely(err < 0))
36946 + ignore_flags |= au_xattr_out_of_list;
36947 + while (!err && p < e) {
36948 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
36950 + p += strlen(p) + 1;
36952 + au_kfree_try_rcu(value);
36955 + au_kfree_try_rcu(o);
36958 + inode_unlock_shared(h_isrc);
36963 +/* ---------------------------------------------------------------------- */
36965 +static int au_smack_reentering(struct super_block *sb)
36967 +#if IS_ENABLED(CONFIG_SECURITY_SMACK) || IS_ENABLED(CONFIG_SECURITY_SELINUX)
36969 + * as a part of lookup, smack_d_instantiate() is called, and it calls
36970 + * i_op->getxattr(). ouch.
36972 + return si_pid_test(sb);
36983 +struct au_lgxattr {
36991 + const char *name;
36998 +static ssize_t au_lgxattr(struct dentry *dentry, struct inode *inode,
36999 + struct au_lgxattr *arg)
37003 + struct path h_path;
37004 + struct super_block *sb;
37006 + sb = dentry->d_sb;
37007 + reenter = au_smack_reentering(sb);
37009 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
37010 + if (unlikely(err))
37013 + err = au_h_path_getattr(dentry, inode, /*force*/1, &h_path, reenter);
37014 + if (unlikely(err))
37016 + if (unlikely(!h_path.dentry))
37017 + /* illegally overlapped or something */
37018 + goto out_di; /* pretending success */
37020 + /* always topmost entry only */
37021 + switch (arg->type) {
37022 + case AU_XATTR_LIST:
37023 + err = vfs_listxattr(h_path.dentry,
37024 + arg->u.list.list, arg->u.list.size);
37026 + case AU_XATTR_GET:
37027 + AuDebugOn(d_is_negative(h_path.dentry));
37028 + err = vfs_getxattr(mnt_idmap(h_path.mnt), h_path.dentry,
37029 + arg->u.get.name, arg->u.get.value,
37030 + arg->u.get.size);
37036 + di_read_unlock(dentry, AuLock_IR);
37039 + si_read_unlock(sb);
37045 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
37047 + struct au_lgxattr arg = {
37048 + .type = AU_XATTR_LIST,
37055 + return au_lgxattr(dentry, /*inode*/NULL, &arg);
37058 +static ssize_t au_getxattr(struct dentry *dentry, struct inode *inode,
37059 + const char *name, void *value, size_t size)
37061 + struct au_lgxattr arg = {
37062 + .type = AU_XATTR_GET,
37070 + return au_lgxattr(dentry, inode, &arg);
37073 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
37074 + const char *name, const void *value, size_t size,
37077 + struct au_sxattr arg = {
37078 + .type = AU_XATTR_SET,
37087 + return au_sxattr(dentry, inode, &arg);
37090 +/* ---------------------------------------------------------------------- */
37092 +static int au_xattr_get(const struct xattr_handler *handler,
37093 + struct dentry *dentry, struct inode *inode,
37094 + const char *name, void *buffer, size_t size)
37096 + return au_getxattr(dentry, inode, name, buffer, size);
37099 +static int au_xattr_set(const struct xattr_handler *handler,
37100 + struct mnt_idmap *idmap,
37101 + struct dentry *dentry, struct inode *inode,
37102 + const char *name, const void *value, size_t size,
37105 + return au_setxattr(dentry, inode, name, value, size, flags);
37108 +static const struct xattr_handler au_xattr_handler = {
37111 + .get = au_xattr_get,
37112 + .set = au_xattr_set
37115 +static const struct xattr_handler *au_xattr_handlers[] = {
37116 + &au_xattr_handler, /* must be last */
37120 +void au_xattr_init(struct super_block *sb)
37122 + sb->s_xattr = au_xattr_handlers;
37124 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
37125 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
37126 +++ linux/fs/aufs/xino.c 2023-08-28 12:34:39.999969465 +0200
37128 +// SPDX-License-Identifier: GPL-2.0
37130 + * Copyright (C) 2005-2022 Junjiro R. Okajima
37132 + * This program is free software; you can redistribute it and/or modify
37133 + * it under the terms of the GNU General Public License as published by
37134 + * the Free Software Foundation; either version 2 of the License, or
37135 + * (at your option) any later version.
37137 + * This program is distributed in the hope that it will be useful,
37138 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
37139 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37140 + * GNU General Public License for more details.
37142 + * You should have received a copy of the GNU General Public License
37143 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
37147 + * external inode number translation table and bitmap
37149 + * things to consider
37151 + * + au_xino object
37152 + * + XINO files (xino, xib, xigen)
37153 + * + dynamic debugfs entries (xiN)
37154 + * + static debugfs entries (xib, xigen)
37155 + * + static sysfs entry (xi_path)
37156 + * - several entry points to handle them.
37157 + * + mount(2) without xino option (default)
37158 + * + mount(2) with xino option
37159 + * + mount(2) with noxino option
37161 + * + remount with add/del branches
37162 + * + remount with xino/noxino options
37165 +#include <linux/seq_file.h>
37166 +#include <linux/statfs.h>
37169 +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop,
37170 + aufs_bindex_t bbot,
37171 + struct super_block *h_sb)
37173 + /* todo: try binary-search if the branches are many */
37174 + for (; btop <= bbot; btop++)
37175 + if (h_sb == au_sbr_sb(sb, btop))
37181 + * find another branch who is on the same filesystem of the specified
37182 + * branch{@btgt}. search until @bbot.
37184 +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
37185 + aufs_bindex_t bbot)
37187 + aufs_bindex_t bindex;
37188 + struct super_block *tgt_sb;
37190 + tgt_sb = au_sbr_sb(sb, btgt);
37191 + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb);
37193 + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb);
37198 +/* ---------------------------------------------------------------------- */
37201 + * stop unnecessary notify events at creating xino files
37204 +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry)
37206 + aufs_bindex_t bfound, bindex, bbot;
37207 + struct dentry *parent;
37208 + struct au_branch *br;
37211 + parent = dentry->d_parent; /* safe d_parent access */
37212 + bbot = au_sbbot(sb);
37213 + for (bindex = 0; bindex <= bbot; bindex++) {
37214 + br = au_sbr(sb, bindex);
37215 + if (au_br_dentry(br) == parent) {
37221 + AuDbg("bfound b%d\n", bfound);
37225 +struct au_xino_lock_dir {
37226 + struct au_hinode *hdir;
37227 + struct dentry *parent;
37228 + struct inode *dir;
37231 +static struct dentry *au_dget_parent_lock(struct dentry *dentry,
37232 + unsigned int lsc)
37234 + struct dentry *parent;
37235 + struct inode *dir;
37237 + parent = dget_parent(dentry);
37238 + dir = d_inode(parent);
37239 + inode_lock_nested(dir, lsc);
37240 +#if 0 /* it should not happen */
37241 + spin_lock(&dentry->d_lock);
37242 + if (unlikely(dentry->d_parent != parent)) {
37243 + spin_unlock(&dentry->d_lock);
37244 + inode_unlock(dir);
37249 + spin_unlock(&dentry->d_lock);
37256 +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath,
37257 + struct au_xino_lock_dir *ldir)
37259 + aufs_bindex_t bindex;
37261 + ldir->hdir = NULL;
37262 + bindex = au_xi_root(sb, xipath->dentry);
37263 + if (bindex >= 0) {
37264 + /* rw branch root */
37265 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
37266 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
37269 + ldir->parent = au_dget_parent_lock(xipath->dentry,
37271 + ldir->dir = d_inode(ldir->parent);
37275 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
37278 + au_hn_inode_unlock(ldir->hdir);
37280 + inode_unlock(ldir->dir);
37281 + dput(ldir->parent);
37285 +/* ---------------------------------------------------------------------- */
37288 + * create and set a new xino file
37290 +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent,
37293 + struct file *file;
37294 + struct dentry *h_parent, *d;
37295 + struct inode *h_dir, *inode;
37297 + static DEFINE_MUTEX(mtx);
37300 + * at mount-time, and the xino file is the default path,
37301 + * hnotify is disabled so we have no notify events to ignore.
37302 + * when a user specified the xino, we cannot get au_hdir to be ignored.
37305 + mutex_lock(&mtx);
37306 + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37307 + /* | __FMODE_NONOTIFY */,
37309 + if (IS_ERR(file)) {
37311 + mutex_unlock(&mtx);
37313 + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file));
37317 + /* keep file count */
37319 + d = file->f_path.dentry;
37320 + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT);
37322 + mutex_unlock(&mtx);
37323 + /* mnt_want_write() is unnecessary here */
37324 + h_dir = d_inode(h_parent);
37325 + inode = file_inode(file);
37326 + /* no delegation since it is just created */
37327 + if (inode->i_nlink)
37328 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
37330 + inode_unlock(h_dir);
37332 + if (unlikely(err)) {
37334 + pr_err("unlink %s(%d)\n", fpath, err);
37339 + if (unlikely(sb && sb == d->d_sb)) {
37341 + pr_err("%s must be outside\n", fpath);
37344 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
37346 + pr_err("xino doesn't support %s(%s)\n",
37347 + fpath, au_sbtype(d->d_sb));
37350 + return file; /* success */
37354 + file = ERR_PTR(err);
37359 + * create a new xinofile at the same place/path as @base.
37361 +struct file *au_xino_create2(struct super_block *sb, struct path *base,
37362 + struct file *copy_src)
37364 + struct file *file;
37365 + struct dentry *dentry;
37366 + struct inode *dir, *delegated;
37367 + struct qstr *name;
37368 + struct path ppath, path;
37369 + int err, do_unlock;
37370 + struct au_xino_lock_dir ldir;
37373 + au_xino_lock_dir(sb, base, &ldir);
37374 + dentry = base->dentry;
37375 + ppath.dentry = dentry->d_parent; /* dir inode is locked */
37376 + ppath.mnt = base->mnt;
37377 + dir = d_inode(ppath.dentry);
37380 + name = &dentry->d_name;
37381 + path.dentry = vfsub_lookup_one_len(name->name, &ppath, name->len);
37382 + if (IS_ERR(path.dentry)) {
37383 + file = (void *)path.dentry;
37384 + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry));
37388 + /* no need to mnt_want_write() since we call dentry_open() later */
37389 + err = vfs_create(mnt_idmap(base->mnt), dir, path.dentry, 0666, NULL);
37390 + if (unlikely(err)) {
37391 + file = ERR_PTR(err);
37392 + pr_err("%pd create err %d\n", dentry, err);
37396 + path.mnt = base->mnt;
37397 + file = vfsub_dentry_open(&path,
37398 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
37399 + /* | __FMODE_NONOTIFY */);
37400 + if (IS_ERR(file)) {
37401 + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file));
37405 + delegated = NULL;
37406 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
37407 + au_xino_unlock_dir(&ldir);
37409 + if (unlikely(err == -EWOULDBLOCK)) {
37410 + pr_warn("cannot retry for NFSv4 delegation"
37411 + " for an internal unlink\n");
37414 + if (unlikely(err)) {
37415 + pr_err("%pd unlink err %d\n", dentry, err);
37420 + /* no one can touch copy_src xino */
37421 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
37422 + if (unlikely(err)) {
37423 + pr_err("%pd copy err %d\n", dentry, err);
37427 + goto out_dput; /* success */
37431 + file = ERR_PTR(err);
37433 + dput(path.dentry);
37436 + au_xino_unlock_dir(&ldir);
37440 +struct file *au_xino_file1(struct au_xino *xi)
37442 + struct file *file;
37443 + unsigned int u, nfile;
37446 + nfile = xi->xi_nfile;
37447 + for (u = 0; u < nfile; u++) {
37448 + file = xi->xi_file[u];
37456 +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file)
37467 + if (idx < xi->xi_nfile) {
37468 + f = xi->xi_file[idx];
37472 + p = au_kzrealloc(xi->xi_file,
37473 + sizeof(*xi->xi_file) * xi->xi_nfile,
37474 + sizeof(*xi->xi_file) * (idx + 1),
37475 + GFP_NOFS, /*may_shrink*/0);
37477 + MtxMustLock(&xi->xi_mtx);
37479 + xi->xi_nfile = idx + 1;
37487 + xi->xi_file[idx] = file;
37494 + * if @xinew->xi is not set, then create new xigen file.
37496 +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew)
37498 + struct file *file;
37501 + SiMustAnyLock(sb);
37503 + file = au_xino_create2(sb, xinew->base, xinew->copy_src);
37504 + if (IS_ERR(file)) {
37505 + err = PTR_ERR(file);
37506 + pr_err("%s[%d], err %d\n",
37507 + xinew->xi ? "xino" : "xigen",
37508 + xinew->idx, err);
37513 + err = au_xino_file_set(xinew->xi, xinew->idx, file);
37516 + /* todo: make xigen file an array */
37517 + /* err = au_xigen_file_set(sb, xinew->idx, file); */
37520 + if (unlikely(err))
37521 + file = ERR_PTR(err);
37527 +/* ---------------------------------------------------------------------- */
37530 + * truncate xino files
37532 +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex,
37533 + int idx, struct kstatfs *st)
37537 + struct file *file, *new_xino;
37538 + struct au_xi_new xinew = {
37543 + xinew.xi = au_sbr(sb, bindex)->br_xino;
37544 + file = au_xino_file(xinew.xi, idx);
37548 + xinew.base = &file->f_path;
37549 + err = vfs_statfs(xinew.base, st);
37550 + if (unlikely(err)) {
37551 + AuErr1("statfs err %d, ignored\n", err);
37556 + blocks = file_inode(file)->i_blocks;
37557 + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37558 + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks);
37560 + xinew.copy_src = file;
37561 + new_xino = au_xi_new(sb, &xinew);
37562 + if (IS_ERR(new_xino)) {
37563 + err = PTR_ERR(new_xino);
37564 + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err);
37568 + err = vfs_statfs(&new_xino->f_path, st);
37570 + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n",
37571 + bindex, idx, (u64)file_inode(new_xino)->i_blocks,
37572 + st->f_bfree, st->f_blocks);
37574 + AuErr1("statfs err %d, ignored\n", err);
37582 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin)
37585 + unsigned long jiffy;
37586 + aufs_bindex_t bbot;
37587 + struct kstatfs *st;
37588 + struct au_branch *br;
37589 + struct au_xino *xi;
37592 + st = kmalloc(sizeof(*st), GFP_NOFS);
37593 + if (unlikely(!st))
37597 + bbot = au_sbbot(sb);
37598 + if (unlikely(bindex < 0 || bbot < bindex))
37603 + br = au_sbr(sb, bindex);
37604 + xi = br->br_xino;
37605 + for (i = idx_begin; !err && i < xi->xi_nfile; i++)
37606 + err = au_xino_do_trunc(sb, bindex, i, st);
37608 + au_sbi(sb)->si_xino_jiffy = jiffy;
37611 + au_kfree_rcu(st);
37616 +struct xino_do_trunc_args {
37617 + struct super_block *sb;
37618 + struct au_branch *br;
37622 +static void xino_do_trunc(void *_args)
37624 + struct xino_do_trunc_args *args = _args;
37625 + struct super_block *sb;
37626 + struct au_branch *br;
37627 + struct inode *dir;
37629 + aufs_bindex_t bindex;
37633 + dir = d_inode(sb->s_root);
37637 + si_noflush_write_lock(sb);
37638 + ii_read_lock_parent(dir);
37639 + bindex = au_br_index(sb, br->br_id);
37640 + err = au_xino_trunc(sb, bindex, idx);
37641 + ii_read_unlock(dir);
37642 + if (unlikely(err))
37643 + pr_warn("err b%d, (%d)\n", bindex, err);
37644 + atomic_dec(&br->br_xino->xi_truncating);
37645 + au_lcnt_dec(&br->br_count);
37646 + si_write_unlock(sb);
37647 + au_nwt_done(&au_sbi(sb)->si_nowait);
37648 + au_kfree_rcu(args);
37652 + * returns the index in the xi_file array whose corresponding file is necessary
37653 + * to truncate, or -1 which means no need to truncate.
37655 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
37659 + struct kstatfs st;
37660 + struct au_sbinfo *sbinfo;
37661 + struct au_xino *xi;
37662 + struct file *file;
37664 + /* todo: si_xino_expire and the ratio should be customizable */
37665 + sbinfo = au_sbi(sb);
37666 + if (time_before(jiffies,
37667 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
37670 + /* truncation border */
37671 + xi = br->br_xino;
37672 + for (u = 0; u < xi->xi_nfile; u++) {
37673 + file = au_xino_file(xi, u);
37677 + err = vfs_statfs(&file->f_path, &st);
37678 + if (unlikely(err)) {
37679 + AuErr1("statfs err %d, ignored\n", err);
37682 + if (div64_u64(st.f_bfree * 100, st.f_blocks)
37683 + >= AUFS_XINO_DEF_TRUNC)
37690 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
37693 + struct xino_do_trunc_args *args;
37696 + idx = xino_trunc_test(sb, br);
37700 + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1)
37703 + /* lock and kfree() will be called in trunc_xino() */
37704 + args = kmalloc(sizeof(*args), GFP_NOFS);
37705 + if (unlikely(!args)) {
37706 + AuErr1("no memory\n");
37710 + au_lcnt_inc(&br->br_count);
37714 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
37716 + return; /* success */
37718 + pr_err("wkq %d\n", wkq_err);
37719 + au_lcnt_dec(&br->br_count);
37720 + au_kfree_rcu(args);
37723 + atomic_dec(&br->br_xino->xi_truncating);
37726 +/* ---------------------------------------------------------------------- */
37728 +struct au_xi_calc {
37733 +static void au_xi_calc(struct super_block *sb, ino_t h_ino,
37734 + struct au_xi_calc *calc)
37738 + maxent = au_xi_maxent(sb);
37739 + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos);
37740 + calc->pos *= sizeof(ino_t);
37743 +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br,
37744 + struct au_xi_calc *calc)
37747 + struct file *file;
37748 + struct au_xino *xi = br->br_xino;
37749 + struct au_xi_new xinew = {
37753 + SiMustAnyLock(sb);
37759 + mutex_lock(&xi->xi_mtx);
37760 + file = au_xino_file(xi, calc->idx);
37764 + file = au_xino_file(xi, /*idx*/-1);
37765 + AuDebugOn(!file);
37766 + xinew.idx = calc->idx;
37767 + xinew.base = &file->f_path;
37768 + /* xinew.copy_src = NULL; */
37769 + file = au_xi_new(sb, &xinew);
37770 + if (IS_ERR(file))
37771 + err = PTR_ERR(file);
37774 + mutex_unlock(&xi->xi_mtx);
37779 +struct au_xino_do_new_async_args {
37780 + struct super_block *sb;
37781 + struct au_branch *br;
37782 + struct au_xi_calc calc;
37786 +struct au_xi_writing {
37787 + struct hlist_bl_node node;
37788 + ino_t h_ino, ino;
37791 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37794 +static void au_xino_call_do_new_async(void *args)
37796 + struct au_xino_do_new_async_args *a = args;
37797 + struct au_branch *br;
37798 + struct super_block *sb;
37799 + struct au_sbinfo *sbi;
37800 + struct inode *root;
37801 + struct file *file;
37802 + struct au_xi_writing *del, *p;
37803 + struct hlist_bl_head *hbl;
37804 + struct hlist_bl_node *pos;
37809 + sbi = au_sbi(sb);
37810 + si_noflush_read_lock(sb);
37811 + root = d_inode(sb->s_root);
37812 + ii_read_lock_child(root);
37813 + err = au_xino_do_new_async(sb, br, &a->calc);
37814 + if (unlikely(err)) {
37815 + AuIOErr("err %d\n", err);
37819 + file = au_xino_file(br->br_xino, a->calc.idx);
37820 + AuDebugOn(!file);
37821 + err = au_xino_do_write(file, &a->calc, a->ino);
37822 + if (unlikely(err)) {
37823 + AuIOErr("err %d\n", err);
37828 + hbl = &br->br_xino->xi_writing;
37829 + hlist_bl_lock(hbl);
37830 + au_hbl_for_each(pos, hbl) {
37831 + p = container_of(pos, struct au_xi_writing, node);
37832 + if (p->ino == a->ino) {
37834 + hlist_bl_del(&p->node);
37838 + hlist_bl_unlock(hbl);
37839 + au_kfree_rcu(del);
37842 + au_lcnt_dec(&br->br_count);
37843 + ii_read_unlock(root);
37844 + si_read_unlock(sb);
37845 + au_nwt_done(&sbi->si_nowait);
37850 + * create a new xino file asynchronously
37852 +static int au_xino_new_async(struct super_block *sb, struct au_branch *br,
37853 + struct au_xi_calc *calc, ino_t ino)
37856 + struct au_xino_do_new_async_args *arg;
37859 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
37860 + if (unlikely(!arg))
37865 + arg->calc = *calc;
37867 + au_lcnt_inc(&br->br_count);
37868 + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST);
37869 + if (unlikely(err)) {
37870 + pr_err("wkq %d\n", err);
37871 + au_lcnt_dec(&br->br_count);
37872 + au_kfree_rcu(arg);
37880 + * read @ino from xinofile for the specified branch{@sb, @bindex}
37881 + * at the position of @h_ino.
37883 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37888 + struct au_xi_calc calc;
37889 + struct au_sbinfo *sbinfo;
37890 + struct file *file;
37891 + struct au_xino *xi;
37892 + struct hlist_bl_head *hbl;
37893 + struct hlist_bl_node *pos;
37894 + struct au_xi_writing *p;
37897 + if (!au_opt_test(au_mntflags(sb), XINO))
37898 + return 0; /* no xino */
37901 + au_xi_calc(sb, h_ino, &calc);
37902 + xi = au_sbr(sb, bindex)->br_xino;
37903 + file = au_xino_file(xi, calc.idx);
37905 + hbl = &xi->xi_writing;
37906 + hlist_bl_lock(hbl);
37907 + au_hbl_for_each(pos, hbl) {
37908 + p = container_of(pos, struct au_xi_writing, node);
37909 + if (p->h_ino == h_ino) {
37910 + AuDbg("hi%llu, i%llu, found\n",
37911 + (u64)p->h_ino, (u64)p->ino);
37916 + hlist_bl_unlock(hbl);
37918 + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino))
37919 + return 0; /* no xino */
37921 + sbinfo = au_sbi(sb);
37922 + sz = xino_fread(file, ino, sizeof(*ino), &calc.pos);
37923 + if (sz == sizeof(*ino))
37924 + return 0; /* success */
37927 + if (unlikely(sz >= 0)) {
37929 + AuIOErr("xino read error (%zd)\n", sz);
37934 +static int au_xino_do_write(struct file *file, struct au_xi_calc *calc,
37939 + sz = xino_fwrite(file, &ino, sizeof(ino), &calc->pos);
37940 + if (sz == sizeof(ino))
37941 + return 0; /* success */
37943 + AuIOErr("write failed (%zd)\n", sz);
37948 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
37949 + * at the position of @h_ino.
37950 + * even if @ino is zero, it is written to the xinofile and means no entry.
37951 + * if the size of the xino file on a specific filesystem exceeds the watermark,
37952 + * try truncating it.
37954 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
37958 + unsigned int mnt_flags;
37959 + struct au_xi_calc calc;
37960 + struct file *file;
37961 + struct au_branch *br;
37962 + struct au_xino *xi;
37963 + struct au_xi_writing *p;
37965 + SiMustAnyLock(sb);
37967 + mnt_flags = au_mntflags(sb);
37968 + if (!au_opt_test(mnt_flags, XINO))
37971 + au_xi_calc(sb, h_ino, &calc);
37972 + br = au_sbr(sb, bindex);
37973 + xi = br->br_xino;
37974 + file = au_xino_file(xi, calc.idx);
37976 + /* store the inum pair into the list */
37977 + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL);
37978 + p->h_ino = h_ino;
37980 + au_hbl_add(&p->node, &xi->xi_writing);
37982 + /* create and write a new xino file asynchronously */
37983 + err = au_xino_new_async(sb, br, &calc, ino);
37985 + return 0; /* success */
37989 + err = au_xino_do_write(file, &calc, ino);
37991 + br = au_sbr(sb, bindex);
37992 + if (au_opt_test(mnt_flags, TRUNC_XINO)
37993 + && au_test_fs_trunc_xino(au_br_sb(br)))
37994 + xino_try_trunc(sb, br);
37995 + return 0; /* success */
37999 + AuIOErr("write failed (%d)\n", err);
38003 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38006 +/* todo: unnecessary to support mmap_sem since kernel-space? */
38007 +ssize_t xino_fread(struct file *file, void *kbuf, size_t size, loff_t *pos)
38011 + const int prevent_endless = 10;
38015 + err = vfsub_read_k(file, kbuf, size, pos);
38016 + if (err == -EINTR
38017 + && !au_wkq_test()
38018 + && fatal_signal_pending(current)) {
38019 + err = xino_fread_wkq(file, kbuf, size, pos);
38020 + BUG_ON(err == -EINTR);
38022 + } while (i++ < prevent_endless
38023 + && (err == -EAGAIN || err == -EINTR));
38025 +#if 0 /* reserved for future use */
38027 + fsnotify_access(file->f_path.dentry);
38033 +struct xino_fread_args {
38035 + struct file *file;
38041 +static void call_xino_fread(void *args)
38043 + struct xino_fread_args *a = args;
38044 + *a->errp = xino_fread(a->file, a->buf, a->size, a->pos);
38047 +static ssize_t xino_fread_wkq(struct file *file, void *buf, size_t size,
38052 + struct xino_fread_args args = {
38060 + wkq_err = au_wkq_wait(call_xino_fread, &args);
38061 + if (unlikely(wkq_err))
38067 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38070 +static ssize_t do_xino_fwrite(struct file *file, void *kbuf, size_t size,
38075 + const int prevent_endless = 10;
38079 + err = vfsub_write_k(file, kbuf, size, pos);
38080 + if (err == -EINTR
38081 + && !au_wkq_test()
38082 + && fatal_signal_pending(current)) {
38083 + err = xino_fwrite_wkq(file, kbuf, size, pos);
38084 + BUG_ON(err == -EINTR);
38086 + } while (i++ < prevent_endless
38087 + && (err == -EAGAIN || err == -EINTR));
38089 +#if 0 /* reserved for future use */
38091 + fsnotify_modify(file->f_path.dentry);
38097 +struct do_xino_fwrite_args {
38099 + struct file *file;
38105 +static void call_do_xino_fwrite(void *args)
38107 + struct do_xino_fwrite_args *a = args;
38108 + *a->errp = do_xino_fwrite(a->file, a->buf, a->size, a->pos);
38111 +static ssize_t xino_fwrite_wkq(struct file *file, void *buf, size_t size,
38116 + struct do_xino_fwrite_args args = {
38125 + * it breaks RLIMIT_FSIZE and normal user's limit,
38126 + * users should care about quota and real 'filesystem full.'
38128 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
38129 + if (unlikely(wkq_err))
38135 +ssize_t xino_fwrite(struct file *file, void *buf, size_t size, loff_t *pos)
38139 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
38141 + err = do_xino_fwrite(file, buf, size, pos);
38145 + err = xino_fwrite_wkq(file, buf, size, pos);
38152 +/* ---------------------------------------------------------------------- */
38155 + * inode number bitmap
38157 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
38158 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
38162 + AuDebugOn(bit < 0 || page_bits <= bit);
38163 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
38167 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
38169 + AuDebugOn(ino < AUFS_FIRST_INO);
38170 + ino -= AUFS_FIRST_INO;
38171 + *pindex = ino / page_bits;
38172 + *bit = ino % page_bits;
38175 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
38180 + struct au_sbinfo *sbinfo;
38181 + struct file *xib;
38182 + unsigned long *p;
38184 + sbinfo = au_sbi(sb);
38185 + MtxMustLock(&sbinfo->si_xib_mtx);
38186 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
38187 + || !au_opt_test(sbinfo->si_mntflags, XINO));
38189 + if (pindex == sbinfo->si_xib_last_pindex)
38192 + xib = sbinfo->si_xib;
38193 + p = sbinfo->si_xib_buf;
38194 + pos = sbinfo->si_xib_last_pindex;
38195 + pos *= PAGE_SIZE;
38196 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38197 + if (unlikely(sz != PAGE_SIZE))
38201 + pos *= PAGE_SIZE;
38202 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
38203 + sz = xino_fread(xib, p, PAGE_SIZE, &pos);
38205 + memset(p, 0, PAGE_SIZE);
38206 + sz = xino_fwrite(xib, p, PAGE_SIZE, &pos);
38208 + if (sz == PAGE_SIZE) {
38209 + sbinfo->si_xib_last_pindex = pindex;
38210 + return 0; /* success */
38214 + AuIOErr1("write failed (%zd)\n", sz);
38221 +static void au_xib_clear_bit(struct inode *inode)
38224 + unsigned long pindex;
38225 + struct super_block *sb;
38226 + struct au_sbinfo *sbinfo;
38228 + AuDebugOn(inode->i_nlink);
38230 + sb = inode->i_sb;
38231 + xib_calc_bit(inode->i_ino, &pindex, &bit);
38232 + AuDebugOn(page_bits <= bit);
38233 + sbinfo = au_sbi(sb);
38234 + mutex_lock(&sbinfo->si_xib_mtx);
38235 + err = xib_pindex(sb, pindex);
38237 + clear_bit(bit, sbinfo->si_xib_buf);
38238 + sbinfo->si_xib_next_bit = bit;
38240 + mutex_unlock(&sbinfo->si_xib_mtx);
38243 +/* ---------------------------------------------------------------------- */
38246 + * truncate a xino bitmap file
38250 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
38254 + unsigned long pindex;
38255 + loff_t pos, pend;
38256 + struct au_sbinfo *sbinfo;
38258 + unsigned long *p;
38261 + sbinfo = au_sbi(sb);
38262 + MtxMustLock(&sbinfo->si_xib_mtx);
38263 + p = sbinfo->si_xib_buf;
38264 + pend = vfsub_f_size_read(file);
38266 + while (pos < pend) {
38267 + sz = xino_fread(file, page, PAGE_SIZE, &pos);
38269 + if (unlikely(sz <= 0))
38273 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
38274 + if (unlikely(*ino < AUFS_FIRST_INO))
38277 + xib_calc_bit(*ino, &pindex, &bit);
38278 + AuDebugOn(page_bits <= bit);
38279 + err = xib_pindex(sb, pindex);
38291 +static int xib_restore(struct super_block *sb)
38294 + unsigned int nfile;
38295 + aufs_bindex_t bindex, bbot;
38297 + struct au_branch *br;
38298 + struct au_xino *xi;
38299 + struct file *file;
38302 + page = (void *)__get_free_page(GFP_NOFS);
38303 + if (unlikely(!page))
38307 + bbot = au_sbbot(sb);
38308 + for (bindex = 0; !err && bindex <= bbot; bindex++)
38309 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) {
38310 + br = au_sbr(sb, bindex);
38311 + xi = br->br_xino;
38312 + nfile = xi->xi_nfile;
38313 + for (i = 0; i < nfile; i++) {
38314 + file = au_xino_file(xi, i);
38316 + err = do_xib_restore(sb, file, page);
38319 + AuDbg("skip shared b%d\n", bindex);
38320 + free_page((unsigned long)page);
38326 +int au_xib_trunc(struct super_block *sb)
38331 + struct au_sbinfo *sbinfo;
38332 + unsigned long *p;
38333 + struct file *file;
38335 + SiMustWriteLock(sb);
38338 + sbinfo = au_sbi(sb);
38339 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
38342 + file = sbinfo->si_xib;
38343 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
38346 + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL);
38347 + err = PTR_ERR(file);
38348 + if (IS_ERR(file))
38350 + fput(sbinfo->si_xib);
38351 + sbinfo->si_xib = file;
38353 + p = sbinfo->si_xib_buf;
38354 + memset(p, 0, PAGE_SIZE);
38356 + sz = xino_fwrite(sbinfo->si_xib, p, PAGE_SIZE, &pos);
38357 + if (unlikely(sz != PAGE_SIZE)) {
38359 + AuIOErr("err %d\n", err);
38365 + mutex_lock(&sbinfo->si_xib_mtx);
38366 + /* mnt_want_write() is unnecessary here */
38367 + err = xib_restore(sb);
38368 + mutex_unlock(&sbinfo->si_xib_mtx);
38374 +/* ---------------------------------------------------------------------- */
38376 +struct au_xino *au_xino_alloc(unsigned int nfile)
38378 + struct au_xino *xi;
38380 + xi = kzalloc(sizeof(*xi), GFP_NOFS);
38381 + if (unlikely(!xi))
38383 + xi->xi_nfile = nfile;
38384 + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS);
38385 + if (unlikely(!xi->xi_file))
38388 + xi->xi_nondir.total = 8; /* initial size */
38389 + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t),
38391 + if (unlikely(!xi->xi_nondir.array))
38394 + spin_lock_init(&xi->xi_nondir.spin);
38395 + init_waitqueue_head(&xi->xi_nondir.wqh);
38396 + mutex_init(&xi->xi_mtx);
38397 + INIT_HLIST_BL_HEAD(&xi->xi_writing);
38398 + atomic_set(&xi->xi_truncating, 0);
38399 + kref_init(&xi->xi_kref);
38400 + goto out; /* success */
38403 + au_kfree_try_rcu(xi->xi_file);
38405 + au_kfree_rcu(xi);
38411 +static int au_xino_init(struct au_branch *br, int idx, struct file *file)
38414 + struct au_xino *xi;
38417 + xi = au_xino_alloc(idx + 1);
38418 + if (unlikely(!xi)) {
38425 + xi->xi_file[idx] = file;
38426 + AuDebugOn(br->br_xino);
38427 + br->br_xino = xi;
38433 +static void au_xino_release(struct kref *kref)
38435 + struct au_xino *xi;
38437 + unsigned long ul;
38438 + struct hlist_bl_head *hbl;
38439 + struct hlist_bl_node *pos, *n;
38440 + struct au_xi_writing *p;
38442 + xi = container_of(kref, struct au_xino, xi_kref);
38443 + for (i = 0; i < xi->xi_nfile; i++)
38444 + if (xi->xi_file[i])
38445 + fput(xi->xi_file[i]);
38446 + for (i = xi->xi_nondir.total - 1; i >= 0; i--)
38447 + AuDebugOn(xi->xi_nondir.array[i]);
38448 + mutex_destroy(&xi->xi_mtx);
38449 + hbl = &xi->xi_writing;
38450 + ul = au_hbl_count(hbl);
38451 + if (unlikely(ul)) {
38452 + pr_warn("xi_writing %lu\n", ul);
38453 + hlist_bl_lock(hbl);
38454 + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) {
38455 + hlist_bl_del(&p->node);
38456 + /* kmemleak reported au_kfree_rcu() doesn't free it */
38459 + hlist_bl_unlock(hbl);
38461 + au_kfree_try_rcu(xi->xi_file);
38462 + au_kfree_try_rcu(xi->xi_nondir.array);
38463 + au_kfree_rcu(xi);
38466 +int au_xino_put(struct au_branch *br)
38469 + struct au_xino *xi;
38472 + xi = br->br_xino;
38474 + br->br_xino = NULL;
38475 + ret = kref_put(&xi->xi_kref, au_xino_release);
38481 +/* ---------------------------------------------------------------------- */
38484 + * xino mount option handlers
38488 +static void xino_clear_xib(struct super_block *sb)
38490 + struct au_sbinfo *sbinfo;
38492 + SiMustWriteLock(sb);
38494 + sbinfo = au_sbi(sb);
38495 + if (sbinfo->si_xib)
38496 + fput(sbinfo->si_xib);
38497 + sbinfo->si_xib = NULL;
38498 + if (sbinfo->si_xib_buf)
38499 + free_page((unsigned long)sbinfo->si_xib_buf);
38500 + sbinfo->si_xib_buf = NULL;
38503 +static int au_xino_set_xib(struct super_block *sb, struct path *path)
38507 + struct au_sbinfo *sbinfo;
38508 + struct file *file;
38509 + struct super_block *xi_sb;
38511 + SiMustWriteLock(sb);
38513 + sbinfo = au_sbi(sb);
38514 + file = au_xino_create2(sb, path, sbinfo->si_xib);
38515 + err = PTR_ERR(file);
38516 + if (IS_ERR(file))
38518 + if (sbinfo->si_xib)
38519 + fput(sbinfo->si_xib);
38520 + sbinfo->si_xib = file;
38521 + xi_sb = file_inode(file)->i_sb;
38522 + sbinfo->si_ximaxent = xi_sb->s_maxbytes;
38523 + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) {
38525 + pr_err("s_maxbytes(%llu) on %s is too small\n",
38526 + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb));
38529 + sbinfo->si_ximaxent /= sizeof(ino_t);
38532 + if (!sbinfo->si_xib_buf)
38533 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
38534 + if (unlikely(!sbinfo->si_xib_buf))
38537 + sbinfo->si_xib_last_pindex = 0;
38538 + sbinfo->si_xib_next_bit = 0;
38539 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
38541 + err = xino_fwrite(file, sbinfo->si_xib_buf, PAGE_SIZE, &pos);
38542 + if (unlikely(err != PAGE_SIZE))
38546 + goto out; /* success */
38549 + if (sbinfo->si_xib_buf)
38550 + free_page((unsigned long)sbinfo->si_xib_buf);
38551 + sbinfo->si_xib_buf = NULL;
38555 + fput(sbinfo->si_xib);
38556 + sbinfo->si_xib = NULL;
38562 +/* xino for each branch */
38563 +static void xino_clear_br(struct super_block *sb)
38565 + aufs_bindex_t bindex, bbot;
38566 + struct au_branch *br;
38568 + bbot = au_sbbot(sb);
38569 + for (bindex = 0; bindex <= bbot; bindex++) {
38570 + br = au_sbr(sb, bindex);
38576 +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br,
38577 + aufs_bindex_t bshared)
38579 + struct au_branch *brshared;
38581 + brshared = au_sbr(sb, bshared);
38582 + AuDebugOn(!brshared->br_xino);
38583 + AuDebugOn(!brshared->br_xino->xi_file);
38584 + if (br->br_xino != brshared->br_xino) {
38585 + au_xino_get(brshared);
38587 + br->br_xino = brshared->br_xino;
38591 +struct au_xino_do_set_br {
38592 + struct au_branch *br;
38594 + aufs_bindex_t bshared;
38597 +static int au_xino_do_set_br(struct super_block *sb, struct path *path,
38598 + struct au_xino_do_set_br *args)
38601 + struct au_xi_calc calc;
38602 + struct file *file;
38603 + struct au_branch *br;
38604 + struct au_xi_new xinew = {
38609 + xinew.xi = br->br_xino;
38610 + au_xi_calc(sb, args->h_ino, &calc);
38611 + xinew.copy_src = au_xino_file(xinew.xi, calc.idx);
38612 + if (args->bshared >= 0)
38613 + /* shared xino */
38614 + au_xino_set_br_shared(sb, br, args->bshared);
38615 + else if (!xinew.xi) {
38617 + err = au_xino_init(br, calc.idx, xinew.copy_src);
38618 + if (unlikely(err))
38622 + /* force re-creating */
38623 + xinew.xi = br->br_xino;
38624 + xinew.idx = calc.idx;
38625 + mutex_lock(&xinew.xi->xi_mtx);
38626 + file = au_xi_new(sb, &xinew);
38627 + mutex_unlock(&xinew.xi->xi_mtx);
38628 + err = PTR_ERR(file);
38629 + if (IS_ERR(file))
38631 + AuDebugOn(!file);
38633 + err = au_xino_do_write(file, &calc, AUFS_ROOT_INO);
38634 + if (unlikely(err))
38642 +static int au_xino_set_br(struct super_block *sb, struct path *path)
38645 + aufs_bindex_t bindex, bbot;
38646 + struct au_xino_do_set_br args;
38647 + struct inode *inode;
38649 + SiMustWriteLock(sb);
38651 + bbot = au_sbbot(sb);
38652 + inode = d_inode(sb->s_root);
38653 + for (bindex = 0; bindex <= bbot; bindex++) {
38654 + args.h_ino = au_h_iptr(inode, bindex)->i_ino;
38655 + args.br = au_sbr(sb, bindex);
38656 + args.bshared = is_sb_shared(sb, bindex, bindex - 1);
38657 + err = au_xino_do_set_br(sb, path, &args);
38658 + if (unlikely(err))
38666 +void au_xino_clr(struct super_block *sb)
38668 + struct au_sbinfo *sbinfo;
38670 + au_xigen_clr(sb);
38671 + xino_clear_xib(sb);
38672 + xino_clear_br(sb);
38673 + dbgaufs_brs_del(sb, 0);
38674 + sbinfo = au_sbi(sb);
38675 + /* lvalue, do not call au_mntflags() */
38676 + au_opt_clr(sbinfo->si_mntflags, XINO);
38679 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount)
38682 + struct dentry *dentry, *parent, *cur_dentry, *cur_parent;
38683 + struct qstr *dname, *cur_name;
38684 + struct file *cur_xino;
38685 + struct au_sbinfo *sbinfo;
38686 + struct path *path, *cur_path;
38688 + SiMustWriteLock(sb);
38691 + sbinfo = au_sbi(sb);
38692 + path = &xiopt->file->f_path;
38693 + dentry = path->dentry;
38694 + parent = dget_parent(dentry);
38697 + cur_xino = sbinfo->si_xib;
38699 + cur_path = &cur_xino->f_path;
38700 + cur_dentry = cur_path->dentry;
38701 + cur_parent = dget_parent(cur_dentry);
38702 + cur_name = &cur_dentry->d_name;
38703 + dname = &dentry->d_name;
38704 + skip = (cur_parent == parent
38705 + && au_qstreq(dname, cur_name));
38706 + dput(cur_parent);
38712 + au_opt_set(sbinfo->si_mntflags, XINO);
38713 + err = au_xino_set_xib(sb, path);
38714 + /* si_x{read,write} are set */
38716 + err = au_xigen_set(sb, path);
38718 + err = au_xino_set_br(sb, path);
38720 + dbgaufs_brs_add(sb, 0, /*topdown*/1);
38721 + goto out; /* success */
38725 + AuIOErr("failed setting xino(%d).\n", err);
38734 + * create a xinofile at the default place/path.
38736 +struct file *au_xino_def(struct super_block *sb)
38738 + struct file *file;
38740 + struct au_branch *br;
38741 + struct super_block *h_sb;
38742 + struct path path;
38743 + aufs_bindex_t bbot, bindex, bwr;
38746 + bbot = au_sbbot(sb);
38748 + for (bindex = 0; bindex <= bbot; bindex++) {
38749 + br = au_sbr(sb, bindex);
38750 + if (au_br_writable(br->br_perm)
38751 + && !au_test_fs_bad_xino(au_br_sb(br))) {
38758 + file = ERR_PTR(-ENOMEM);
38759 + page = (void *)__get_free_page(GFP_NOFS);
38760 + if (unlikely(!page))
38762 + path.mnt = au_br_mnt(br);
38763 + path.dentry = au_h_dptr(sb->s_root, bwr);
38764 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
38765 + file = (void *)p;
38766 + if (!IS_ERR(p)) {
38767 + strcat(p, "/" AUFS_XINO_FNAME);
38768 + AuDbg("%s\n", p);
38769 + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1);
38771 + free_page((unsigned long)page);
38773 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0,
38775 + if (IS_ERR(file))
38777 + h_sb = file->f_path.dentry->d_sb;
38778 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
38779 + pr_err("xino doesn't support %s(%s)\n",
38780 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
38782 + file = ERR_PTR(-EINVAL);
38790 +/* ---------------------------------------------------------------------- */
38793 + * initialize the xinofile for the specified branch @br
38794 + * at the place/path where @base_file indicates.
38795 + * test whether another branch is on the same filesystem or not,
38796 + * if found then share the xinofile with another branch.
38798 +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
38799 + struct path *base)
38802 + struct au_xino_do_set_br args = {
38807 + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb),
38809 + err = au_xino_do_set_br(sb, base, &args);
38810 + if (unlikely(err))
38816 +/* ---------------------------------------------------------------------- */
38819 + * get an unused inode number from bitmap
38821 +ino_t au_xino_new_ino(struct super_block *sb)
38824 + unsigned long *p, pindex, ul, pend;
38825 + struct au_sbinfo *sbinfo;
38826 + struct file *file;
38827 + int free_bit, err;
38829 + if (!au_opt_test(au_mntflags(sb), XINO))
38830 + return iunique(sb, AUFS_FIRST_INO);
38832 + sbinfo = au_sbi(sb);
38833 + mutex_lock(&sbinfo->si_xib_mtx);
38834 + p = sbinfo->si_xib_buf;
38835 + free_bit = sbinfo->si_xib_next_bit;
38836 + if (free_bit < page_bits && !test_bit(free_bit, p))
38837 + goto out; /* success */
38838 + free_bit = find_first_zero_bit(p, page_bits);
38839 + if (free_bit < page_bits)
38840 + goto out; /* success */
38842 + pindex = sbinfo->si_xib_last_pindex;
38843 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
38844 + err = xib_pindex(sb, ul);
38845 + if (unlikely(err))
38847 + free_bit = find_first_zero_bit(p, page_bits);
38848 + if (free_bit < page_bits)
38849 + goto out; /* success */
38852 + file = sbinfo->si_xib;
38853 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
38854 + for (ul = pindex + 1; ul <= pend; ul++) {
38855 + err = xib_pindex(sb, ul);
38856 + if (unlikely(err))
38858 + free_bit = find_first_zero_bit(p, page_bits);
38859 + if (free_bit < page_bits)
38860 + goto out; /* success */
38865 + set_bit(free_bit, p);
38866 + sbinfo->si_xib_next_bit = free_bit + 1;
38867 + pindex = sbinfo->si_xib_last_pindex;
38868 + mutex_unlock(&sbinfo->si_xib_mtx);
38869 + ino = xib_calc_ino(pindex, free_bit);
38870 + AuDbg("i%lu\n", (unsigned long)ino);
38873 + mutex_unlock(&sbinfo->si_xib_mtx);
38878 +/* for s_op->delete_inode() */
38879 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
38882 + unsigned int mnt_flags;
38883 + aufs_bindex_t bindex, bbot, bi;
38884 + unsigned char try_trunc;
38885 + struct au_iinfo *iinfo;
38886 + struct super_block *sb;
38887 + struct au_hinode *hi;
38888 + struct inode *h_inode;
38889 + struct au_branch *br;
38890 + struct au_xi_calc calc;
38891 + struct file *file;
38893 + AuDebugOn(au_is_bad_inode(inode));
38895 + sb = inode->i_sb;
38896 + mnt_flags = au_mntflags(sb);
38897 + if (!au_opt_test(mnt_flags, XINO)
38898 + || inode->i_ino == AUFS_ROOT_INO)
38902 + au_xigen_inc(inode);
38903 + au_xib_clear_bit(inode);
38906 + iinfo = au_ii(inode);
38907 + bindex = iinfo->ii_btop;
38911 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
38912 + hi = au_hinode(iinfo, bindex);
38913 + bbot = iinfo->ii_bbot;
38914 + for (; bindex <= bbot; bindex++, hi++) {
38915 + h_inode = hi->hi_inode;
38917 + || (!unlinked && h_inode->i_nlink))
38920 + /* inode may not be revalidated */
38921 + bi = au_br_index(sb, hi->hi_id);
38925 + br = au_sbr(sb, bi);
38926 + au_xi_calc(sb, h_inode->i_ino, &calc);
38927 + file = au_xino_file(br->br_xino, calc.idx);
38928 + if (IS_ERR_OR_NULL(file))
38931 + err = au_xino_do_write(file, &calc, /*ino*/0);
38932 + if (!err && try_trunc
38933 + && au_test_fs_trunc_xino(au_br_sb(br)))
38934 + xino_try_trunc(sb, br);
38938 +/* ---------------------------------------------------------------------- */
38940 +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino)
38942 + int found, total, i;
38945 + total = xi->xi_nondir.total;
38946 + for (i = 0; i < total; i++) {
38947 + if (xi->xi_nondir.array[i] != h_ino)
38956 +static int au_xinondir_expand(struct au_xino *xi)
38961 + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX);
38964 + sz = xi->xi_nondir.total * sizeof(ino_t);
38965 + if (unlikely(sz > KMALLOC_MAX_SIZE / 2))
38967 + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC,
38968 + /*may_shrink*/0);
38970 + xi->xi_nondir.array = p;
38971 + xi->xi_nondir.total <<= 1;
38972 + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total);
38980 +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex,
38981 + ino_t h_ino, int idx)
38983 + struct au_xino *xi;
38985 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
38986 + xi = au_sbr(sb, bindex)->br_xino;
38987 + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx);
38989 + spin_lock(&xi->xi_nondir.spin);
38990 + AuDebugOn(xi->xi_nondir.array[idx] != h_ino);
38991 + xi->xi_nondir.array[idx] = 0;
38992 + spin_unlock(&xi->xi_nondir.spin);
38993 + wake_up_all(&xi->xi_nondir.wqh);
38996 +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
38999 + int err, found, empty;
39000 + struct au_xino *xi;
39004 + if (!au_opt_test(au_mntflags(sb), XINO))
39005 + goto out; /* no xino */
39007 + xi = au_sbr(sb, bindex)->br_xino;
39010 + spin_lock(&xi->xi_nondir.spin);
39011 + found = au_xinondir_find(xi, h_ino);
39012 + if (found == -1) {
39013 + empty = au_xinondir_find(xi, /*h_ino*/0);
39014 + if (empty == -1) {
39015 + empty = xi->xi_nondir.total;
39016 + err = au_xinondir_expand(xi);
39017 + if (unlikely(err))
39020 + xi->xi_nondir.array[empty] = h_ino;
39023 + spin_unlock(&xi->xi_nondir.spin);
39024 + wait_event(xi->xi_nondir.wqh,
39025 + xi->xi_nondir.array[found] != h_ino);
39030 + spin_unlock(&xi->xi_nondir.spin);
39035 +/* ---------------------------------------------------------------------- */
39037 +int au_xino_path(struct seq_file *seq, struct file *file)
39041 + err = au_seq_path(seq, &file->f_path);
39042 + if (unlikely(err))
39045 +#define Deleted "\\040(deleted)"
39046 + seq->count -= sizeof(Deleted) - 1;
39047 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
39048 + sizeof(Deleted) - 1));
39054 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
39055 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
39056 +++ linux/include/uapi/linux/aufs_type.h 2023-08-28 12:34:41.669969465 +0200
39058 +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
39060 + * Copyright (C) 2005-2022 Junjiro R. Okajima
39062 + * This program is free software; you can redistribute it and/or modify
39063 + * it under the terms of the GNU General Public License as published by
39064 + * the Free Software Foundation; either version 2 of the License, or
39065 + * (at your option) any later version.
39067 + * This program is distributed in the hope that it will be useful,
39068 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39069 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39070 + * GNU General Public License for more details.
39072 + * You should have received a copy of the GNU General Public License
39073 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
39076 +#ifndef __AUFS_TYPE_H__
39077 +#define __AUFS_TYPE_H__
39079 +#define AUFS_NAME "aufs"
39083 + * define it before including all other headers.
39084 + * sched.h may use pr_* macros before defining "current", so define the
39085 + * no-current version first, and re-define later.
39087 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
39088 +#include <linux/sched.h>
39090 +#define pr_fmt(fmt) \
39091 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
39092 + (int)sizeof(current->comm), current->comm, current->pid
39093 +#include <linux/limits.h>
39095 +#include <stdint.h>
39096 +#include <sys/types.h>
39097 +#include <limits.h>
39098 +#endif /* __KERNEL__ */
39100 +#define AUFS_VERSION "6.x-rcN-20230828"
39102 +/* todo? move this to linux-2.6.19/include/magic.h */
39103 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
39105 +/* ---------------------------------------------------------------------- */
39108 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
39109 +typedef int8_t aufs_bindex_t;
39110 +#define AUFS_BRANCH_MAX 127
39112 +typedef int16_t aufs_bindex_t;
39113 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
39114 +#define AUFS_BRANCH_MAX 511
39115 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
39116 +#define AUFS_BRANCH_MAX 1023
39117 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
39118 +#define AUFS_BRANCH_MAX 32767
39122 +#ifndef AUFS_BRANCH_MAX
39123 +#error unknown CONFIG_AUFS_BRANCH_MAX value
39125 +#endif /* __KERNEL__ */
39127 +/* ---------------------------------------------------------------------- */
39129 +#define AUFS_FSTYPE AUFS_NAME
39131 +#define AUFS_ROOT_INO 2
39132 +#define AUFS_FIRST_INO 11
39134 +#define AUFS_WH_PFX ".wh."
39135 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
39136 +#define AUFS_WH_TMP_LEN 4
39137 +/* a limit for rmdir/rename a dir and copyup */
39138 +#define AUFS_MAX_NAMELEN (NAME_MAX \
39139 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
39141 + - AUFS_WH_TMP_LEN) /* hex */
39142 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
39143 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
39144 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
39145 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
39146 +#define AUFS_DIRWH_DEF 3
39147 +#define AUFS_RDCACHE_DEF 10 /* seconds */
39148 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
39149 +#define AUFS_RDBLK_DEF 512 /* bytes */
39150 +#define AUFS_RDHASH_DEF 32
39151 +#define AUFS_WKQ_NAME AUFS_NAME "d"
39152 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
39153 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
39154 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
39155 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
39157 +/* pseudo-link maintenace under /proc */
39158 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
39159 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
39160 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
39162 +/* dirren, renamed dir */
39163 +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr."
39164 +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino"
39165 +/* whiteouted doubly */
39166 +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX
39167 +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME
39169 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
39170 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
39172 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
39173 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
39174 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
39176 +/* doubly whiteouted */
39177 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
39178 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
39179 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
39181 +/* branch permissions and attributes */
39182 +#define AUFS_BRPERM_RW "rw"
39183 +#define AUFS_BRPERM_RO "ro"
39184 +#define AUFS_BRPERM_RR "rr"
39185 +#define AUFS_BRATTR_COO_REG "coo_reg"
39186 +#define AUFS_BRATTR_COO_ALL "coo_all"
39187 +#define AUFS_BRATTR_FHSM "fhsm"
39188 +#define AUFS_BRATTR_UNPIN "unpin"
39189 +#define AUFS_BRATTR_ICEX "icex"
39190 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
39191 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
39192 +#define AUFS_BRATTR_ICEX_TR "icextr"
39193 +#define AUFS_BRATTR_ICEX_USR "icexusr"
39194 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
39195 +#define AUFS_BRRATTR_WH "wh"
39196 +#define AUFS_BRWATTR_NLWH "nolwh"
39197 +#define AUFS_BRWATTR_MOO "moo"
39199 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
39200 +#define AuBrPerm_RO (1 << 1) /* readonly */
39201 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
39202 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
39204 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
39205 +#define AuBrAttr_COO_ALL (1 << 4)
39206 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
39208 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
39209 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
39210 + branch. meaningless since
39211 + linux-3.18-rc1 */
39213 +/* ignore error in copying XATTR */
39214 +#define AuBrAttr_ICEX_SEC (1 << 7)
39215 +#define AuBrAttr_ICEX_SYS (1 << 8)
39216 +#define AuBrAttr_ICEX_TR (1 << 9)
39217 +#define AuBrAttr_ICEX_USR (1 << 10)
39218 +#define AuBrAttr_ICEX_OTH (1 << 11)
39219 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
39220 + | AuBrAttr_ICEX_SYS \
39221 + | AuBrAttr_ICEX_TR \
39222 + | AuBrAttr_ICEX_USR \
39223 + | AuBrAttr_ICEX_OTH)
39225 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
39226 +#define AuBrRAttr_Mask AuBrRAttr_WH
39228 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
39229 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
39230 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
39232 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
39234 +/* #warning test userspace */
39236 +#ifndef CONFIG_AUFS_FHSM
39237 +#undef AuBrAttr_FHSM
39238 +#define AuBrAttr_FHSM 0
39240 +#ifndef CONFIG_AUFS_XATTR
39241 +#undef AuBrAttr_ICEX
39242 +#define AuBrAttr_ICEX 0
39243 +#undef AuBrAttr_ICEX_SEC
39244 +#define AuBrAttr_ICEX_SEC 0
39245 +#undef AuBrAttr_ICEX_SYS
39246 +#define AuBrAttr_ICEX_SYS 0
39247 +#undef AuBrAttr_ICEX_TR
39248 +#define AuBrAttr_ICEX_TR 0
39249 +#undef AuBrAttr_ICEX_USR
39250 +#define AuBrAttr_ICEX_USR 0
39251 +#undef AuBrAttr_ICEX_OTH
39252 +#define AuBrAttr_ICEX_OTH 0
39256 +/* the longest combination */
39257 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
39258 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
39259 + "+" AUFS_BRATTR_COO_REG \
39260 + "+" AUFS_BRATTR_FHSM \
39261 + "+" AUFS_BRATTR_UNPIN \
39262 + "+" AUFS_BRATTR_ICEX_SEC \
39263 + "+" AUFS_BRATTR_ICEX_SYS \
39264 + "+" AUFS_BRATTR_ICEX_USR \
39265 + "+" AUFS_BRATTR_ICEX_OTH \
39266 + "+" AUFS_BRWATTR_NLWH)
39269 + char a[AuBrPermStrSz];
39270 +} au_br_perm_str_t;
39272 +static inline int au_br_writable(int brperm)
39274 + return brperm & AuBrPerm_RW;
39277 +static inline int au_br_whable(int brperm)
39279 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
39282 +static inline int au_br_wh_linkable(int brperm)
39284 + return !(brperm & AuBrWAttr_NoLinkWH);
39287 +static inline int au_br_cmoo(int brperm)
39289 + return brperm & AuBrAttr_CMOO_Mask;
39292 +static inline int au_br_fhsm(int brperm)
39294 + return brperm & AuBrAttr_FHSM;
39297 +/* ---------------------------------------------------------------------- */
39301 + /* readdir in userspace */
39305 + AuCtl_WBR_FD, /* pathconf wrapper */
39306 + AuCtl_IBUSY, /* busy inode */
39307 + AuCtl_MVDOWN, /* move-down */
39308 + AuCtl_BR, /* info about branches */
39309 + AuCtl_FHSM_FD /* connection for fhsm */
39312 +/* borrowed from linux/include/linux/kernel.h */
39314 +#ifdef _GNU_SOURCE
39315 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
39317 +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
39319 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
39322 +/* borrowed from linux/include/linux/compiler-gcc3.h */
39324 +#define __aligned(x) __attribute__((aligned(x)))
39329 +#define __packed __attribute__((packed))
39333 +struct au_rdu_cookie {
39338 + uint32_t generation;
39341 +struct au_rdu_ent {
39350 +static inline int au_rdu_len(int nlen)
39352 + /* include the terminating NULL */
39353 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
39354 + sizeof(uint64_t));
39357 +union au_rdu_ent_ul {
39358 + struct au_rdu_ent __user *e;
39370 + uint64_t sz; /* AuCtl_RDU */
39371 + uint64_t nent; /* AuCtl_RDU_INO */
39373 + union au_rdu_ent_ul ent;
39374 + uint16_t verify[AufsCtlRduV_End];
39376 + /* input/output */
39380 + union au_rdu_ent_ul tail;
39381 + /* number of entries which were added in a single call */
39386 + struct au_rdu_cookie cookie;
39389 +/* ---------------------------------------------------------------------- */
39391 +/* dirren. the branch is identified by the filename who contains this */
39392 +struct au_drinfo {
39395 + uint8_t oldnamelen;
39396 + uint64_t _padding;
39398 + uint8_t oldname[];
39401 +struct au_drinfo_fdata {
39403 + struct au_drinfo drinfo;
39406 +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01)
39408 +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02)
39410 +/* ---------------------------------------------------------------------- */
39412 +struct aufs_wbr_fd {
39417 +/* ---------------------------------------------------------------------- */
39419 +struct aufs_ibusy {
39420 + uint64_t ino, h_ino;
39424 +/* ---------------------------------------------------------------------- */
39426 +/* error code for move-down */
39427 +/* the actual message strings are implemented in aufs-util.git */
39429 + EAU_MVDOWN_OPAQUE = 1,
39430 + EAU_MVDOWN_WHITEOUT,
39431 + EAU_MVDOWN_UPPER,
39432 + EAU_MVDOWN_BOTTOM,
39433 + EAU_MVDOWN_NOUPPER,
39434 + EAU_MVDOWN_NOLOWERBR,
39438 +/* flags for move-down */
39439 +#define AUFS_MVDOWN_DMSG 1
39440 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
39441 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
39442 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
39443 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
39444 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
39445 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
39446 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
39447 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
39448 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
39449 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
39450 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
39451 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
39453 +/* index for move-down */
39455 + AUFS_MVDOWN_UPPER,
39456 + AUFS_MVDOWN_LOWER,
39457 + AUFS_MVDOWN_NARRAY
39461 + * additional info of move-down
39462 + * number of free blocks and inodes.
39463 + * subset of struct kstatfs, but smaller and always 64bit.
39465 +struct aufs_stfs {
39466 + uint64_t f_blocks;
39467 + uint64_t f_bavail;
39468 + uint64_t f_files;
39469 + uint64_t f_ffree;
39472 +struct aufs_stbr {
39473 + int16_t brid; /* optional input */
39474 + int16_t bindex; /* output */
39475 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
39478 +struct aufs_mvdown {
39479 + uint32_t flags; /* input/output */
39480 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
39481 + int8_t au_errno; /* output */
39484 +/* ---------------------------------------------------------------------- */
39486 +union aufs_brinfo {
39487 + /* PATH_MAX may differ between kernel-space and user-space */
39488 + char _spacer[4096];
39496 +/* ---------------------------------------------------------------------- */
39498 +#define AuCtlType 'A'
39499 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
39500 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
39501 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
39502 + struct aufs_wbr_fd)
39503 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
39504 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
39505 + struct aufs_mvdown)
39506 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
39507 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
39509 +#endif /* __AUFS_TYPE_H__ */
39510 SPDX-License-Identifier: GPL-2.0
39511 aufs6.x-rcN loopback patch
39513 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39514 index 131294601819..56016fc9c9d8 100644
39515 --- a/drivers/block/loop.c
39516 +++ b/drivers/block/loop.c
39517 @@ -54,7 +54,7 @@ struct loop_device {
39519 char lo_file_name[LO_NAME_SIZE];
39521 - struct file * lo_backing_file;
39522 + struct file *lo_backing_file, *lo_backing_virt_file;
39523 struct block_device *lo_device;
39525 gfp_t old_gfp_mask;
39526 @@ -510,6 +510,15 @@ static inline void loop_update_dio(struct loop_device *lo)
39530 +static struct file *loop_real_file(struct file *file)
39532 + struct file *f = NULL;
39534 + if (file->f_path.dentry->d_sb->s_op->real_loop)
39535 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
39539 static void loop_reread_partitions(struct loop_device *lo)
39542 @@ -567,6 +576,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39544 struct file *file = fget(arg);
39545 struct file *old_file;
39546 + struct file *f, *virt_file = NULL, *old_virt_file;
39550 @@ -590,11 +600,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39551 if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
39554 + f = loop_real_file(file);
39556 + virt_file = file;
39561 error = loop_validate_file(file, bdev);
39565 old_file = lo->lo_backing_file;
39566 + old_virt_file = lo->lo_backing_virt_file;
39570 @@ -607,6 +625,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39571 blk_mq_freeze_queue(lo->lo_queue);
39572 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
39573 lo->lo_backing_file = file;
39574 + lo->lo_backing_virt_file = virt_file;
39575 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
39576 mapping_set_gfp_mask(file->f_mapping,
39577 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39578 @@ -629,6 +648,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39582 + if (old_virt_file)
39583 + fput(old_virt_file);
39585 loop_reread_partitions(lo);
39587 @@ -642,6 +663,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
39588 loop_global_unlock(lo, is_loop);
39596 @@ -1013,6 +1036,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39597 const struct loop_config *config)
39599 struct file *file = fget(config->fd);
39600 + struct file *f, *virt_file = NULL;
39601 struct inode *inode;
39602 struct address_space *mapping;
39604 @@ -1028,6 +1052,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39605 /* This is safe, since we have a reference from open(). */
39606 __module_get(THIS_MODULE);
39608 + f = loop_real_file(file);
39610 + virt_file = file;
39616 * If we don't hold exclusive handle for the device, upgrade to it
39617 * here to avoid changing device under exclusive owner.
39618 @@ -1091,6 +1122,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39619 lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
39620 lo->lo_device = bdev;
39621 lo->lo_backing_file = file;
39622 + lo->lo_backing_virt_file = virt_file;
39623 lo->old_gfp_mask = mapping_gfp_mask(mapping);
39624 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
39626 @@ -1146,6 +1178,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39627 bd_abort_claiming(bdev, loop_configure);
39632 /* This is safe: open() is still holding a reference. */
39633 module_put(THIS_MODULE);
39635 @@ -1154,6 +1188,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
39636 static void __loop_clr_fd(struct loop_device *lo, bool release)
39639 + struct file *virt_filp = lo->lo_backing_virt_file;
39640 gfp_t gfp = lo->old_gfp_mask;
39642 if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
39643 @@ -1170,6 +1205,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39644 spin_lock_irq(&lo->lo_lock);
39645 filp = lo->lo_backing_file;
39646 lo->lo_backing_file = NULL;
39647 + lo->lo_backing_virt_file = NULL;
39648 spin_unlock_irq(&lo->lo_lock);
39650 lo->lo_device = NULL;
39651 @@ -1232,6 +1268,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
39652 * fput can take open_mutex which is usually taken before lo_mutex.
39659 static int loop_clr_fd(struct loop_device *lo)
39660 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
39661 index 1ed300047a41..ea63191d6473 100644
39662 --- a/fs/aufs/f_op.c
39663 +++ b/fs/aufs/f_op.c
39664 @@ -309,7 +309,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
39665 if (IS_ERR(h_file))
39668 - if (au_test_loopback_kthread()) {
39669 + if (0 && au_test_loopback_kthread()) {
39670 au_warn_loopback(h_file->f_path.dentry->d_sb);
39671 if (file->f_mapping != h_file->f_mapping) {
39672 file->f_mapping = h_file->f_mapping;
39673 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
39674 index 58043e31e5f3..e2bfae6f9d59 100644
39675 --- a/fs/aufs/loop.c
39676 +++ b/fs/aufs/loop.c
39677 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
39678 symbol_put(loop_backing_file);
39679 au_kfree_try_rcu(au_warn_loopback_array);
39682 +/* ---------------------------------------------------------------------- */
39684 +/* support the loopback block device insude aufs */
39686 +struct file *aufs_real_loop(struct file *file)
39690 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
39691 + fi_read_lock(file);
39692 + f = au_hf_top(file);
39693 + fi_read_unlock(file);
39697 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
39698 index 03d4908a6c03..34d356e181d5 100644
39699 --- a/fs/aufs/loop.h
39700 +++ b/fs/aufs/loop.h
39701 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
39703 int au_loopback_init(void);
39704 void au_loopback_fin(void);
39706 +struct file *aufs_real_loop(struct file *file);
39708 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
39710 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
39712 AuStubInt0(au_loopback_init, void)
39713 AuStubVoid(au_loopback_fin, void)
39715 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
39716 #endif /* BLK_DEV_LOOP */
39718 #endif /* __KERNEL__ */
39719 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
39720 index 81922d4faf54..c8a62c267d72 100644
39721 --- a/fs/aufs/super.c
39722 +++ b/fs/aufs/super.c
39723 @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
39724 .show_options = aufs_show_options,
39725 .statfs = aufs_statfs,
39726 .put_super = aufs_put_super,
39727 - .sync_fs = aufs_sync_fs
39728 + .sync_fs = aufs_sync_fs,
39729 +#ifdef CONFIG_AUFS_BDEV_LOOP
39730 + .real_loop = aufs_real_loop
39734 /* ---------------------------------------------------------------------- */
39735 diff --git a/include/linux/fs.h b/include/linux/fs.h
39736 index 1e3054e5367d..2a780fcbdc75 100644
39737 --- a/include/linux/fs.h
39738 +++ b/include/linux/fs.h
39739 @@ -1934,6 +1934,10 @@ struct super_operations {
39740 struct shrink_control *);
39741 long (*free_cached_objects)(struct super_block *,
39742 struct shrink_control *);
39743 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
39745 + struct file *(*real_loop)(struct file *);